Skip to content

Commit

Permalink
Fix how to get src, dst of SR Policy from state report
Browse files Browse the repository at this point in the history
  • Loading branch information
Motok1 committed Jun 12, 2024
1 parent b6397de commit e3c3416
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
22 changes: 16 additions & 6 deletions pkg/packet/pcep/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,12 +1263,13 @@ func NewAssociationObject(srcAddr netip.Addr, dstAddr netip.Addr, color uint32,
func (o *AssociationObject) Color() uint32 {
for _, tlv := range o.TLVs {
if t, ok := tlv.(*UndefinedTLV); ok {
if t.Type() == TLV_EXTENDED_ASSOCIATION_ID {
return uint32(binary.BigEndian.Uint32(t.Value[:4]))
} else if t.Type() == JUNIPER_SPEC_TLV_EXTENDED_ASSOCIATION_ID {
if t.Type() == JUNIPER_SPEC_TLV_EXTENDED_ASSOCIATION_ID {
return uint32(binary.BigEndian.Uint32(t.Value[:4]))
}
} else if t, ok := tlv.(*ExtendedAssociationID); ok {
return t.Color
}

}
return 0
}
Expand All @@ -1277,16 +1278,25 @@ func (o *AssociationObject) Color() uint32 {
func (o *AssociationObject) Preference() uint32 {
for _, tlv := range o.TLVs {
if t, ok := tlv.(*UndefinedTLV); ok {
if t.Type() == TLV_SRPOLICY_CPATH_PREFERENCE {
return uint32(binary.BigEndian.Uint32(t.Value))
} else if t.Type() == JUNIPER_SPEC_TLV_SRPOLICY_CPATH_PREFERENCE {
if t.Type() == JUNIPER_SPEC_TLV_SRPOLICY_CPATH_PREFERENCE {
return uint32(binary.BigEndian.Uint32(t.Value))
}
} else if t, ok := tlv.(*SRPolicyCandidatePathPreference); ok {
return t.Preference
}
}
return 0
}

func (o *AssociationObject) Endpoint() netip.Addr {
for _, tlv := range o.TLVs {
if t, ok := tlv.(*ExtendedAssociationID); ok {
return t.Endpoint
}
}
return netip.Addr{}
}

// VENDOR-INFORMATION Object (RFC7470 4)
const (
OT_VENDOR_SPECIFIC_CONSTRAINTS uint8 = 1
Expand Down
5 changes: 5 additions & 0 deletions pkg/packet/pcep/tlv.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,15 @@ func DecodeTLV(data []uint8) (TLVInterface, error) {
tlv = &SRPceCapability{}
case TLV_PATH_SETUP_TYPE:
tlv = &PathSetupType{}
case TLV_EXTENDED_ASSOCIATION_ID:
tlv = &ExtendedAssociationID{}
case TLV_PATH_SETUP_TYPE_CAPABILITY:
tlv = &PathSetupTypeCapability{}
case TLV_ASSOC_TYPE_LIST:
tlv = &AssocTypeList{}
case TLV_SRPOLICY_CPATH_PREFERENCE:
tlv = &SRPolicyCandidatePathPreference{}

default:
tlv = &UndefinedTLV{}
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,19 @@ func (ss *Session) RegisterSRPolicy(sr pcep.StateReport) {
}
} else {
// create
var src, dst netip.Addr
if src = sr.LspObject.SrcAddr; !src.IsValid() {
src = sr.AssociationObject.AssocSrc
}
if dst = sr.LspObject.DstAddr; !dst.IsValid() {
dst = sr.AssociationObject.Endpoint()
}
p := table.NewSRPolicy(
sr.LspObject.PlspID,
sr.LspObject.Name,
sr.EroObject.ToSegmentList(),
sr.LspObject.SrcAddr,
sr.LspObject.DstAddr,
src,
dst,
color,
preference,
lspID,
Expand Down

0 comments on commit e3c3416

Please sign in to comment.