summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorzvfvrv <franclombardo@gmail.com>2021-06-14 21:44:53 +0200
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2021-06-30 07:38:00 +0900
commit8aaeb6d33902c725e2980256c0e83a9edd853124 (patch)
tree4bcd7f20fb5a49fa633f3012ba4dc00e3a31b1ec
parent7f7a3c570b8b053cd323073a30455630bd983a56 (diff)
fix marshal and unmarshal
-rw-r--r--internal/pkg/apiutil/attribute.go46
-rw-r--r--pkg/packet/bgp/sr_policy.go5
2 files changed, 46 insertions, 5 deletions
diff --git a/internal/pkg/apiutil/attribute.go b/internal/pkg/apiutil/attribute.go
index f6003a6a..30737cc4 100644
--- a/internal/pkg/apiutil/attribute.go
+++ b/internal/pkg/apiutil/attribute.go
@@ -1826,7 +1826,19 @@ func UnmarshalSRBSID(bsid *any.Any) (bgp.TunnelEncapSubTLVInterface, error) {
Flags: flags,
}, nil
case *api.SRv6BindingSID:
- return nil, fmt.Errorf("srv6 binding sid is not yet supported")
+ b, err := bgp.NewBSID(v.Sid)
+ if err != nil {
+ return nil, err
+ }
+ return &bgp.TunnelEncapSubTLVSRv6BSID{
+ TunnelEncapSubTLV: bgp.TunnelEncapSubTLV{
+ Type: bgp.ENCAP_SUBTLV_TYPE_SRBINDING_SID,
+ Length: uint16(2 + b.Len()),
+ },
+ Flags: 0,
+ BSID: b,
+ EPBAS: &bgp.SRv6EndpointBehaviorStructure{},
+ }, nil
default:
return nil, fmt.Errorf("unknown binding sid type %+v", v)
}
@@ -1849,6 +1861,17 @@ func MarshalSRSegments(segs []bgp.TunnelEncapSubTLVInterface) []*any.Any {
},
}
// TODO (sbezverk) Add Type B Segment when SRv6 Binding SID gets finalized.
+ case *bgp.SegmentTypeB:
+ r = &api.SegmentTypeB{
+ Flags: &api.SegmentFlags{
+ VFlag: s.Flags&0x80 == 0x80,
+ AFlag: s.Flags&0x40 == 0x40,
+ SFlag: s.Flags&0x20 == 0x20,
+ BFlag: s.Flags&0x10 == 0x10,
+ },
+ Sid: s.SID,
+ //EndpointBehaviorStructure: &api.SRv6EndPointBehavior{},
+ }
default:
// Unrecognize Segment type, skip it
continue
@@ -1893,7 +1916,26 @@ func UnmarshalSRSegments(s []*any.Any) ([]bgp.TunnelEncapSubTLVInterface, error)
}
segments[i] = seg
case *api.SegmentTypeB:
- return nil, fmt.Errorf("segment of type B is not yet supported")
+ seg := &bgp.SegmentTypeB{
+ TunnelEncapSubTLV: bgp.TunnelEncapSubTLV{
+ Type: bgp.EncapSubTLVType(bgp.TypeB),
+ Length: 18,
+ },
+ SID: v.GetSid(),
+ }
+ if v.Flags.VFlag {
+ seg.Flags += 0x80
+ }
+ if v.Flags.AFlag {
+ seg.Flags += 0x40
+ }
+ if v.Flags.SFlag {
+ seg.Flags += 0x20
+ }
+ if v.Flags.BFlag {
+ seg.Flags += 0x10
+ }
+ segments[i] = seg
}
}
return segments, nil
diff --git a/pkg/packet/bgp/sr_policy.go b/pkg/packet/bgp/sr_policy.go
index 56a7b2ba..39015c37 100644
--- a/pkg/packet/bgp/sr_policy.go
+++ b/pkg/packet/bgp/sr_policy.go
@@ -707,32 +707,31 @@ func (s *SegmentTypeB) DecodeFromBytes(data []byte) error {
return nil
}
func (s *SegmentTypeB) Serialize() ([]byte, error) {
- 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 {
- 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"`
AFlag bool `json:"a_flag"`
SFlag bool `json:"s_flag"`
BFlag bool `json:"b_flag"`
+ Sid string `json:"sid"`
}{
Type: s.Type,
VFlag: s.Flags&0x80 == 0x80,
AFlag: s.Flags&0x40 == 0x40,
SFlag: s.Flags&0x20 == 0x20,
BFlag: s.Flags&0x10 == 0x10,
+ Sid: net.IP(s.SID).To16().String(),
})
}