Skip to content

Commit

Permalink
Add LspDelete function
Browse files Browse the repository at this point in the history
Signed-off-by: kanaya516 <abcs516tk1@gmail.com>
  • Loading branch information
kanaya516 authored and Motok1 committed Jun 8, 2024
1 parent ccd4d3c commit da7f478
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 19 deletions.
55 changes: 39 additions & 16 deletions pkg/packet/pcep/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,21 @@ type PCInitiateMessage struct {
}

func (m *PCInitiateMessage) Serialize() ([]uint8, error) {
eroObjectLength, err := m.EroObject.Len()
if err != nil {
return nil, err
var eroObjectLength uint16
var err error
if m.EroObject != nil {
eroObjectLength, err = m.EroObject.Len()
if err != nil {
return nil, err
}
}
endpointsObjectLength, err := m.EndpointsObject.Len()
if err != nil {
return nil, err

var endpointsObjectLength uint16
if m.EndpointsObject != nil {
endpointsObjectLength, err = m.EndpointsObject.Len()
if err != nil {
return nil, err
}
}
pcinitiateMessageLength := COMMON_HEADER_LENGTH +
m.SrpObject.Len() +
Expand All @@ -374,13 +382,20 @@ func (m *PCInitiateMessage) Serialize() ([]uint8, error) {

byteSrpObject := m.SrpObject.Serialize()
byteLspObject := m.LspObject.Serialize()
byteEndpointsObject, err := m.EndpointsObject.Serialize()
if err != nil {
return nil, err

byteEndpointsObject := []uint8{}
if m.EndpointsObject != nil {
byteEndpointsObject, err = m.EndpointsObject.Serialize()
if err != nil {
return nil, err
}
}
byteEroObject, err := m.EroObject.Serialize()
if err != nil {
return nil, err
byteEroObject := []uint8{}
if m.EroObject != nil {
byteEroObject, err = m.EroObject.Serialize()
if err != nil {
return nil, err
}
}

byteVendorInformationObject := []uint8{}
Expand Down Expand Up @@ -410,7 +425,7 @@ func (m *PCInitiateMessage) Serialize() ([]uint8, error) {
return bytePCInitiateMessage, nil
}

func NewPCInitiateMessage(srpID uint32, lspName string, segmentList []table.Segment, color uint32, preference uint32, srcAddr netip.Addr, dstAddr netip.Addr, opt ...Opt) (*PCInitiateMessage, error) {
func NewPCInitiateMessage(srpID uint32, lspName string, lspDelete bool, plspID uint32, segmentList []table.Segment, color uint32, preference uint32, srcAddr netip.Addr, dstAddr netip.Addr, opt ...Opt) (*PCInitiateMessage, error) {
opts := optParams{
pccType: RFC_COMPLIANT,
}
Expand All @@ -421,11 +436,19 @@ func NewPCInitiateMessage(srpID uint32, lspName string, segmentList []table.Segm

m := &PCInitiateMessage{}
var err error
if m.SrpObject, err = NewSrpObject(segmentList, srpID, false); err != nil {
if m.SrpObject, err = NewSrpObject(segmentList, srpID, lspDelete); err != nil {
return nil, err
}
if m.LspObject, err = NewLspObject(lspName, 0); err != nil { // PLSP-ID = 0
return nil, err

if lspDelete {
if m.LspObject, err = NewLspObject(lspName, plspID); err != nil {
return nil, err
}
return m, nil
} else {
if m.LspObject, err = NewLspObject(lspName, 0); err != nil {
return nil, err
}
}
if m.EndpointsObject, err = NewEndpointsObject(dstAddr, srcAddr); err != nil {
return nil, err
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 @@ -461,6 +461,9 @@ func NewSrpObject(segs []table.Segment, srpID uint32, isRemove bool) (*SrpObject
SrpID: srpID,
TLVs: []TLVInterface{},
}
if len(segs) == 0 {
return o, nil
}
if _, ok := segs[0].(table.SegmentSRMPLS); ok {
o.TLVs = append(o.TLVs, &PathSetupType{PathSetupType: PST_SR_TE})
} else if _, ok := segs[0].(table.SegmentSRv6); ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *APIServer) createSRPolicy(ctx context.Context, input *pb.CreateSRPolicy
}
} else {
// Initiate SR Policy
if err := pcepSession.SendPCInitiate(srPolicy); err != nil {
if err := pcepSession.RequestSRPolicyCreated(srPolicy); err != nil {
return &pb.RequestStatus{IsSuccess: false}, err
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func NewPce(o *PceOptions, logger *zap.Logger, tedElemsChan chan []table.TedElem
}
}
}()

serverError := <-errChan
return serverError
}
Expand Down
17 changes: 15 additions & 2 deletions pkg/server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,21 @@ func (ss *Session) handlePCRpt(length uint16) error {
return nil
}

func (ss *Session) SendPCInitiate(srPolicy table.SRPolicy) error {
pcinitiateMessage, err := pcep.NewPCInitiateMessage(ss.srpIDHead, srPolicy.Name, srPolicy.SegmentList, srPolicy.Color, srPolicy.Preference, srPolicy.SrcAddr, srPolicy.DstAddr, pcep.VendorSpecific(ss.pccType))
func (ss *Session) RequestAllSRPolicyDeleted() error {
var srPolicy table.SRPolicy
return ss.sendPCInitiate(srPolicy, true)
}

func (ss *Session) RequestSRPolicyDeleted(srPolicy table.SRPolicy) error {
return ss.sendPCInitiate(srPolicy, true)
}

func (ss *Session) RequestSRPolicyCreated(srPolicy table.SRPolicy) error {
return ss.sendPCInitiate(srPolicy, false)
}

func (ss *Session) sendPCInitiate(srPolicy table.SRPolicy, lspDelete bool) error {
pcinitiateMessage, err := pcep.NewPCInitiateMessage(ss.srpIDHead, srPolicy.Name, lspDelete, srPolicy.PlspID, srPolicy.SegmentList, srPolicy.Color, srPolicy.Preference, srPolicy.SrcAddr, srPolicy.DstAddr, pcep.VendorSpecific(ss.pccType))
if err != nil {
return err
}
Expand Down

0 comments on commit da7f478

Please sign in to comment.