Skip to content
Snippets Groups Projects
Commit 0bb46aa8 authored by Oliver Herms's avatar Oliver Herms
Browse files

Added extended IP reachability TLV

parent 46da9c8b
No related branches found
No related tags found
No related merge requests found
package packet package packet
import (
"bytes"
"github.com/taktv6/tflow2/convert"
)
// ExtendedIPReachabilityTLVType is the type code of an Extended IP Reachability TLV
const ExtendedIPReachabilityTLVType = 135 const ExtendedIPReachabilityTLVType = 135
// ExtendedIPReachabilityTLV represents an Extended IP Reachability TLV
type ExtendedIPReachabilityTLV struct { type ExtendedIPReachabilityTLV struct {
TLVType uint8 TLVType uint8
TLVLength uint8 TLVLength uint8
ExtendedIPReachabilities []ExtendedIPReachability
}
// ExtendedIPReachability represents a single Extendend IP Reachability Information
type ExtendedIPReachability struct {
Metric uint32 Metric uint32
UDSubBitPfxLen uint8 UDSubBitPfxLen uint8
Address uint32 Address uint32
SubTLVType uint8 SubTLVs []TLV
SubTLVLength uint8 }
SubTLVs []interface{}
// Type gets the type of the TLV
func (e *ExtendedIPReachabilityTLV) Type() uint8 {
return e.TLVType
}
// Length gets the length of the TLV
func (e *ExtendedIPReachabilityTLV) Length() uint8 {
return e.TLVLength
}
// Value returns the TLV itself
func (e *ExtendedIPReachabilityTLV) Value() interface{} {
return e
}
// Serialize serializes an ExtendedIPReachabilityTLV
func (e *ExtendedIPReachabilityTLV) Serialize(buf *bytes.Buffer) {
buf.WriteByte(ExtendedIPReachabilityTLVType)
buf.WriteByte(e.TLVLength)
for _, extIPReach := range e.ExtendedIPReachabilities {
extIPReach.Serialize(buf)
}
}
// Serialize serializes an ExtendedIPReachability
func (e *ExtendedIPReachability) Serialize(buf *bytes.Buffer) {
if len(e.SubTLVs) != 0 {
e.setSFlag()
}
buf.Write(convert.Uint32Byte(e.Metric))
buf.WriteByte(e.UDSubBitPfxLen)
buf.Write(convert.Uint32Byte(e.Address))
for _, tlv := range e.SubTLVs {
tlv.Serialize(buf)
}
}
func (e *ExtendedIPReachability) setSFlag() {
sFlag := uint8(64)
e.UDSubBitPfxLen = e.UDSubBitPfxLen | sFlag
}
func (e *ExtendedIPReachability) getPfxLen() uint8 {
tmp := e.UDSubBitPfxLen
tmp = tmp << 2
tmp = tmp >> 2
return tmp
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment