Skip to content

Commit

Permalink
Add LSP-ID as a member of SR Policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Motok1 committed Jun 8, 2024
1 parent 946196d commit 30c3edf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/pkg/table/sr_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type SRPolicy struct {
DstAddr netip.Addr
Color uint32
Preference uint32
LspID uint16
}

type Segment interface {
Expand Down
3 changes: 3 additions & 0 deletions pkg/packet/pcep/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ type LspObject struct {
SrcAddr netip.Addr
DstAddr netip.Addr
PlspID uint32
LspID uint16
OFlag uint8
AFlag bool
RFlag bool
Expand Down Expand Up @@ -513,10 +514,12 @@ func (o *LspObject) DecodeFromBytes(typ uint8, objectBody []uint8) error {
if t, ok := tlv.(*IPv4LspIdentifiers); ok {
o.SrcAddr = t.IPv4TunnelSenderAddress
o.DstAddr = t.IPv4TunnelEndpointAddress
o.LspID = t.LspID
}
if t, ok := tlv.(*IPv6LspIdentifiers); ok {
o.SrcAddr = t.IPv6TunnelSenderAddress
o.DstAddr = t.IPv6TunnelEndpointAddress
o.LspID = t.LspID
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/packet/pcep/tlv.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,17 @@ func (tlv *SymbolicPathName) Len() uint16 {
type IPv4LspIdentifiers struct {
IPv4TunnelSenderAddress netip.Addr
IPv4TunnelEndpointAddress netip.Addr
LspID uint16
TunnelID uint16
}

func (tlv *IPv4LspIdentifiers) DecodeFromBytes(data []uint8) error {
var ok bool
if tlv.IPv4TunnelSenderAddress, ok = netip.AddrFromSlice(data[12:16]); !ok {
tlv.IPv4TunnelSenderAddress, _ = netip.AddrFromSlice(data[4:8])
}
tlv.LspID = binary.BigEndian.Uint16(data[8:10])
tlv.TunnelID = binary.BigEndian.Uint16(data[10:12])
tlv.IPv4TunnelEndpointAddress, _ = netip.AddrFromSlice(data[16:20])
return nil
}
Expand All @@ -244,10 +248,14 @@ func (tlv *IPv4LspIdentifiers) Len() uint16 {
type IPv6LspIdentifiers struct {
IPv6TunnelSenderAddress netip.Addr
IPv6TunnelEndpointAddress netip.Addr
LspID uint16
TunnelID uint16
}

func (tlv *IPv6LspIdentifiers) DecodeFromBytes(data []uint8) error {
tlv.IPv6TunnelSenderAddress, _ = netip.AddrFromSlice(data[4:20])
tlv.LspID = binary.BigEndian.Uint16(data[20:22])
tlv.TunnelID = binary.BigEndian.Uint16(data[22:24])
tlv.IPv6TunnelEndpointAddress, _ = netip.AddrFromSlice(data[40:56])
return nil
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,11 @@ func (ss *Session) RegisterSRPolicy(srPolicy table.SRPolicy) {
ss.srPolicies = append(ss.srPolicies, srPolicy)
}

func (ss *Session) DeleteSRPolicy(plspID uint32) {
func (ss *Session) DeleteSRPolicy(sr pcep.StateReport) {
lspID := sr.LspObject.LspID
for i, v := range ss.srPolicies {
if v.PlspID == plspID {
// If the LSP ID is old, it is not the latest data update.
if v.PlspID == sr.LspObject.PlspID && v.LspID <= lspID {
ss.srPolicies[i] = ss.srPolicies[len(ss.srPolicies)-1]
ss.srPolicies = ss.srPolicies[:len(ss.srPolicies)-1]
break
Expand Down

0 comments on commit 30c3edf

Please sign in to comment.