diff options
author | zvfvrv <franclombardo@gmail.com> | 2021-06-14 09:58:37 +0200 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2021-06-30 07:38:00 +0900 |
commit | 7f7a3c570b8b053cd323073a30455630bd983a56 (patch) | |
tree | a0bf8a63f464c226a840f8b7465de637fb53c254 /pkg/packet/bgp | |
parent | 92f37d65aa08d4e0cc19cfdedadfced586f0a7af (diff) |
wip SegmentTypeB without SRv6 Endpoint Behavior and Structure
Diffstat (limited to 'pkg/packet/bgp')
-rw-r--r-- | pkg/packet/bgp/sr_policy.go | 27 | ||||
-rw-r--r-- | pkg/packet/bgp/sr_policy_test.go | 30 |
2 files changed, 51 insertions, 6 deletions
diff --git a/pkg/packet/bgp/sr_policy.go b/pkg/packet/bgp/sr_policy.go index cdd89db2..56a7b2ba 100644 --- a/pkg/packet/bgp/sr_policy.go +++ b/pkg/packet/bgp/sr_policy.go @@ -684,11 +684,17 @@ type SRv6EndpointBehaviorStructure struct { ArgLen uint8 } +func (s *SRv6EndpointBehaviorStructure) String() string { + + return fmt.Sprintf("{Behavior: %s, BlockLen: %d, NodeLen: %d, FuncLen: %d, ArgLen: %d}", + s.Behavior.String(), s.BlockLen, s.NodeLen, s.FuncLen, s.ArgLen) +} + type SegmentTypeB struct { TunnelEncapSubTLV Flags uint8 SID []byte - EP *SRv6EndpointBehaviorStructure + //SRv6EBS SRv6EndpointBehaviorStructure } func (s *SegmentTypeB) DecodeFromBytes(data []byte) error { @@ -697,20 +703,24 @@ func (s *SegmentTypeB) DecodeFromBytes(data []byte) error { return NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, err.Error()) } s.Flags = value[0] + s.SID = value[2:18] return nil } func (s *SegmentTypeB) Serialize() ([]byte, error) { - buf := make([]byte, 6) + fmt.Printf("TypeB - SERIALIZE\n") + buf := make([]byte, 18) buf[0] = s.Flags + copy(buf[2:], s.SID) return s.TunnelEncapSubTLV.Serialize(buf) } func (s *SegmentTypeB) String() string { - - return fmt.Sprintf("{V-flag: %t, A-flag:, %t S-flag: %t, B-flag: %t}", - s.Flags&0x80 == 0x80, s.Flags&0x40 == 0x40, s.Flags&0x20 == 0x20, s.Flags&0x10 == 0x10) + fmt.Printf("%v\n", s.SID) + return fmt.Sprintf("{V-flag: %t, A-flag:, %t S-flag: %t, B-flag: %t, Sid: %s}", + s.Flags&0x80 == 0x80, s.Flags&0x40 == 0x40, s.Flags&0x20 == 0x20, s.Flags&0x10 == 0x10, net.IP(s.SID).To16().String()) } func (s *SegmentTypeB) MarshalJSON() ([]byte, error) { + fmt.Printf("TypeB - MarshalJSON\n") return json.Marshal(struct { Type EncapSubTLVType `json:"type"` VFlag bool `json:"v_flag"` @@ -766,7 +776,12 @@ func (t *TunnelEncapSubTLVSRSegmentList) DecodeFromBytes(data []byte) error { return NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, err.Error()) } case TypeB: - fallthrough + //fmt.Printf("TypeB\n") + segment = &SegmentTypeB{} + if err := segment.DecodeFromBytes(value); err != nil { + return NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, err.Error()) + } + //fmt.Printf(segment.String()) case TypeC: fallthrough case TypeD: diff --git a/pkg/packet/bgp/sr_policy_test.go b/pkg/packet/bgp/sr_policy_test.go index 41849d90..13d605f2 100644 --- a/pkg/packet/bgp/sr_policy_test.go +++ b/pkg/packet/bgp/sr_policy_test.go @@ -186,6 +186,36 @@ func TestSegmentListRoundTrip(t *testing.T) { }, fail: false, }, + { + name: "weight and 2 type B segment without SRv6 Endpoint Behavior and Structure", + input: &TunnelEncapSubTLVSRSegmentList{ + TunnelEncapSubTLV: TunnelEncapSubTLV{ + Type: ENCAP_SUBTLV_TYPE_SRSEGMENT_LIST, + Length: 6, // Weight (6 bytes) + Length of each segment + 2 + }, + Weight: &SegmentListWeight{ + TunnelEncapSubTLV: TunnelEncapSubTLV{ + Type: SegmentListSubTLVWeight, + Length: 6, + }, + Flags: 0, + Weight: 100, + }, + Segments: []TunnelEncapSubTLVInterface{ + &SegmentTypeB{ + TunnelEncapSubTLV: TunnelEncapSubTLV{Type: EncapSubTLVType(TypeB), Length: 6}, + Flags: 0, + SID: net.ParseIP("2001:1::1").To16(), //[]byte{}, + }, + &SegmentTypeB{ + TunnelEncapSubTLV: TunnelEncapSubTLV{Type: EncapSubTLVType(TypeB), Length: 6}, + Flags: 0, + SID: net.ParseIP("2001:1::2").To16(), //[]byte{} + }, + }, + }, + fail: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { |