Skip to content

Commit

Permalink
implement IPV6-LSP-IDENTIFIERS TLV
Browse files Browse the repository at this point in the history
  • Loading branch information
trustywolf committed Feb 17, 2023
1 parent 7db1528 commit c9c6429
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/packet/pcep/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ func (o *LspObject) DecodeFromBytes(objectBody []uint8) error {
o.SrcAddr = t.IPv4TunnelSenderAddress
o.DstAddr = t.IPv4TunnelEndpointAddress
}
if t, ok := tlv.(*IPv6LspIdentifiers); ok {
// TODO: Obtain true srcAddr
o.SrcAddr = t.IPv6TunnelSenderAddress
o.DstAddr = t.IPv6TunnelEndpointAddress
}
}
}
return nil
Expand Down Expand Up @@ -748,9 +753,16 @@ func (o *AssociationObject) DecodeFromBytes(objectBody []uint8) error {
o.RFlag = (objectBody[3] & 0x01) != 0
o.AssocType = uint16(binary.BigEndian.Uint16(objectBody[4:6]))
o.AssocId = uint16(binary.BigEndian.Uint16(objectBody[6:8]))
o.AssocSrc, _ = netip.AddrFromSlice(objectBody[8:12])
if len(objectBody) > 12 {
byteTlvs := objectBody[12:]
assocSrcBytes, _ := netip.AddrFromSlice(objectBody[8:12])
if assocSrcBytes.Is4() && assocSrcBytes.IsValid() {
o.AssocSrc = assocSrcBytes
} else if assocSrcBytes.Is6() && assocSrcBytes.IsValid() {
o.AssocSrc, _ = netip.AddrFromSlice(objectBody[8:24])
} else {
return errors.New("invalid association source address")
}
if len(objectBody) > 24 {
byteTlvs := objectBody[24:]
var err error
if o.Tlvs, err = DecodeTLVs(byteTlvs); err != nil {
return err
Expand Down
36 changes: 36 additions & 0 deletions pkg/packet/pcep/tlv.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const (
TLV_PATH_SETUP_TYPE_LENGTH uint16 = 4
TLV_EXTENDED_ASSOCIATION_ID_LENGTH uint16 = 8
TLV_IPV4_LSP_IDENTIFIERS_LENGTH uint16 = 16
TLV_IPV6_LSP_IDENTIFIERS_LENGTH uint16 = 52
TLV_SRPOLICY_CPATH_ID_LENGTH uint16 = 28
TLV_SRPOLICY_CPATH_PREFERENCE_LENGTH uint16 = 4
)
Expand Down Expand Up @@ -250,6 +251,37 @@ func (tlv *IPv4LspIdentifiers) GetByteLength() uint16 {
return TL_LENGTH + TLV_IPV4_LSP_IDENTIFIERS_LENGTH
}

type IPv6LspIdentifiers struct {
IPv6TunnelSenderAddress netip.Addr
IPv6TunnelEndpointAddress netip.Addr
}

func (tlv *IPv6LspIdentifiers) DecodeFromBytes(data []uint8) error {
tlv.IPv6TunnelSenderAddress, _ = netip.AddrFromSlice(data[4:20])
tlv.IPv6TunnelEndpointAddress, _ = netip.AddrFromSlice(data[40:56])
return nil
}

func (tlv *IPv6LspIdentifiers) Serialize() []uint8 {
return nil
}

func (tlv *IPv6LspIdentifiers) MarshalLogObject(enc zapcore.ObjectEncoder) error {
return nil
}

func (tlv *IPv6LspIdentifiers) Type() uint16 {
return TLV_IPV6_LSP_IDENTIFIERS
}

func (tlv *IPv6LspIdentifiers) Len() uint16 {
return TLV_IPV6_LSP_IDENTIFIERS_LENGTH
}

func (tlv *IPv6LspIdentifiers) GetByteLength() uint16 {
return TL_LENGTH + TLV_IPV6_LSP_IDENTIFIERS_LENGTH
}

type SrPceCapability struct {
UnlimitedMSD bool
SupportNAI bool
Expand Down Expand Up @@ -578,8 +610,12 @@ func DecodeTLV(data []uint8) (TlvInterface, error) {
case TLV_IPV4_LSP_IDENTIFIERS:
tlv = &IPv4LspIdentifiers{}

case TLV_IPV6_LSP_IDENTIFIERS:
tlv = &IPv6LspIdentifiers{}

case TLV_SR_PCE_CAPABILITY:
tlv = &SrPceCapability{}

case TLV_PATH_SETUP_TYPE:
tlv = &PathSetupType{}

Expand Down

0 comments on commit c9c6429

Please sign in to comment.