diff --git a/pkg/packet/pcep/capability.go b/pkg/packet/pcep/capability.go index 35517c7..1b4ff89 100644 --- a/pkg/packet/pcep/capability.go +++ b/pkg/packet/pcep/capability.go @@ -10,33 +10,53 @@ type CapabilityInterface interface { CapStrings() []string } -func PolaCapability() []CapabilityInterface { - return []CapabilityInterface{ - &StatefulPceCapability{ - LspUpdateCapability: true, - IncludeDBVersion: false, - LspInstantiationCapability: true, - TriggeredResync: false, - DeltaLspSyncCapability: false, - TriggeredInitialSync: false, - }, - &PathSetupTypeCapability{ - PathSetupTypes: Psts{PST_RSVP_TE, PST_SR_TE, PST_SRV6_TE}, - SubTLVs: []TLVInterface{ - &SRPceCapability{ - UnlimitedMSD: false, - SupportNAI: false, - MaximumSidDepth: uint8(16), - }, - }, - }, - &SRPceCapability{ - UnlimitedMSD: false, - SupportNAI: false, - MaximumSidDepth: uint8(16), - }, - &AssocTypeList{ - AssocTypes: []AssocType{AT_PATH_PROTECTION_ASSOCIATION, AT_SR_POLICY_ASSOCIATION}, - }, +func PolaCapability(caps []CapabilityInterface) []CapabilityInterface { + // return []CapabilityInterface{ + // &StatefulPceCapability{ + // LspUpdateCapability: true, + // IncludeDBVersion: false, + // LspInstantiationCapability: true, + // TriggeredResync: false, + // DeltaLspSyncCapability: false, + // TriggeredInitialSync: false, + // }, + // &PathSetupTypeCapability{ + // PathSetupTypes: Psts{PST_RSVP_TE, PST_SR_TE, PST_SRV6_TE}, + // SubTLVs: []TLVInterface{ + // &SRPceCapability{ + // UnlimitedMSD: false, + // SupportNAI: false, + // MaximumSidDepth: uint8(16), + // }, + // }, + // }, + // &SRPceCapability{ + // UnlimitedMSD: false, + // SupportNAI: false, + // MaximumSidDepth: uint8(16), + // }, + // &AssocTypeList{ + // AssocTypes: []AssocType{AT_PATH_PROTECTION_ASSOCIATION, AT_SR_POLICY_ASSOCIATION}, + // }, + // } + polaCaps := []CapabilityInterface{} + for _, cap := range caps { + switch tlv := cap.(type) { + case *StatefulPceCapability: + tlv = &StatefulPceCapability{ + LspUpdateCapability: true, + IncludeDBVersion: false, + LspInstantiationCapability: true, + TriggeredResync: false, + DeltaLspSyncCapability: false, + TriggeredInitialSync: false, + } + polaCaps = append(polaCaps, tlv) + case *LSPDBVersion: + continue + default: + polaCaps = append(polaCaps, tlv) + } } + return polaCaps } diff --git a/pkg/packet/pcep/tlv.go b/pkg/packet/pcep/tlv.go index 992f32a..3433e1f 100644 --- a/pkg/packet/pcep/tlv.go +++ b/pkg/packet/pcep/tlv.go @@ -78,6 +78,7 @@ const ( // PCEP TLV const ( TLV_STATEFUL_PCE_CAPABILITY_LENGTH uint16 = 4 + TLV_LSP_DB_VERSION_LENGTH uint16 = 8 TLV_SR_PCE_CAPABILITY_LENGTH uint16 = 4 TLV_PATH_SETUP_TYPE_LENGTH uint16 = 4 TLV_EXTENDED_ASSOCIATION_ID_IPV4_LENGTH uint16 = 8 @@ -173,9 +174,21 @@ func (tlv *StatefulPceCapability) CapStrings() []string { if tlv.LspUpdateCapability { ret = append(ret, "Update") } + if tlv.IncludeDBVersion { + ret = append(ret, "Include-DB-Ver") + } if tlv.LspInstantiationCapability { ret = append(ret, "Initiate") } + if tlv.TriggeredResync { + ret = append(ret, "Triggerd-Resync") + } + if tlv.DeltaLspSyncCapability { + ret = append(ret, "Delta-LSP-Sync") + } + if tlv.TriggeredInitialSync { + ret = append(ret, "Triggerd-init-sync") + } return ret } @@ -298,6 +311,49 @@ func (tlv *IPv6LspIdentifiers) Len() uint16 { return TL_LENGTH + TLV_IPV6_LSP_IDENTIFIERS_LENGTH } +type LSPDBVersion struct { + VersionNumber uint64 +} + +func (tlv *LSPDBVersion) DecodeFromBytes(data []uint8) error { + tlv.VersionNumber = binary.BigEndian.Uint64(data[4:12]) + return nil +} + +func (tlv *LSPDBVersion) Serialize() []uint8 { + buf := []uint8{} + + typ := make([]uint8, 2) + binary.BigEndian.PutUint16(typ, tlv.Type()) + buf = append(buf, typ...) + + length := make([]uint8, 2) + binary.BigEndian.PutUint16(length, TLV_LSP_DB_VERSION_LENGTH) + buf = append(buf, length...) + + val := make([]uint8, TLV_LSP_DB_VERSION_LENGTH) + binary.BigEndian.PutUint64(val, tlv.VersionNumber) + + buf = append(buf, val...) + return buf +} + +func (tlv *LSPDBVersion) MarshalLogObject(enc zapcore.ObjectEncoder) error { + return nil +} + +func (tlv *LSPDBVersion) Type() uint16 { + return TLV_LSP_DB_VERSION +} + +func (tlv *LSPDBVersion) Len() uint16 { + return TL_LENGTH + TLV_LSP_DB_VERSION_LENGTH +} + +func (tlv *LSPDBVersion) CapStrings() []string { + return []string{"LSP-DB-VERSION"} +} + type SRPceCapability struct { UnlimitedMSD bool SupportNAI bool @@ -812,6 +868,8 @@ func DecodeTLV(data []uint8) (TLVInterface, error) { tlv = &IPv4LspIdentifiers{} case TLV_IPV6_LSP_IDENTIFIERS: tlv = &IPv6LspIdentifiers{} + case TLV_LSP_DB_VERSION: + tlv = &LSPDBVersion{} case TLV_SR_PCE_CAPABILITY: tlv = &SRPceCapability{} case TLV_PATH_SETUP_TYPE: diff --git a/pkg/server/session.go b/pkg/server/session.go index d61f8d4..e2177e0 100644 --- a/pkg/server/session.go +++ b/pkg/server/session.go @@ -138,7 +138,8 @@ func (ss *Session) ReceiveOpen() error { if err != nil { return err } - ss.pccCapabilities = append(ss.pccCapabilities, openMessage.OpenObject.Caps...) + + ss.pccCapabilities = pcep.PolaCapability(openMessage.OpenObject.Caps) // pccType detection // * FRRouting cannot be detected from the open message, so it is treated as an RFC compliant