Skip to content

Commit

Permalink
Update Pola Capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Motok1 committed Jun 10, 2024
1 parent 706fea3 commit 26d5e2b
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 29 deletions.
76 changes: 48 additions & 28 deletions pkg/packet/pcep/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
58 changes: 58 additions & 0 deletions pkg/packet/pcep/tlv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion pkg/server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26d5e2b

Please sign in to comment.