@@ -28,7 +28,10 @@ import (
2828 oldv3 "github.com/projectcalico/libcalico-go/lib/apis/v3"
2929 calicocli "github.com/projectcalico/libcalico-go/lib/client"
3030 calicov3cli "github.com/projectcalico/libcalico-go/lib/clientv3"
31+ "github.com/projectcalico/vpp-dataplane/calico-vpp-agent/config"
3132 "github.com/projectcalico/vpp-dataplane/vpplink"
33+ "github.com/projectcalico/vpp-dataplane/vpplink/types"
34+ "google.golang.org/protobuf/types/known/anypb"
3235)
3336
3437const (
@@ -39,7 +42,9 @@ const (
3942
4043var (
4144 BgpFamilyUnicastIPv4 = bgpapi.Family {Afi : bgpapi .Family_AFI_IP , Safi : bgpapi .Family_SAFI_UNICAST }
45+ BgpFamilySRv6IPv4 = bgpapi.Family {Afi : bgpapi .Family_AFI_IP , Safi : bgpapi .Family_SAFI_SR_POLICY }
4246 BgpFamilyUnicastIPv6 = bgpapi.Family {Afi : bgpapi .Family_AFI_IP6 , Safi : bgpapi .Family_SAFI_UNICAST }
47+ BgpFamilySRv6IPv6 = bgpapi.Family {Afi : bgpapi .Family_AFI_IP6 , Safi : bgpapi .Family_SAFI_SR_POLICY }
4348)
4449
4550// Data managed by the routing server and
@@ -115,9 +120,17 @@ func MakePath(prefix string, isWithdrawal bool, nodeIpv4 net.IP, nodeIpv6 net.IP
115120
116121 if v4 {
117122 family = & BgpFamilyUnicastIPv4
118- nhAttr , err := ptypes .MarshalAny (& bgpapi.NextHopAttribute {
119- NextHop : nodeIpv4 .String (),
120- })
123+ var nhAttr * anypb.Any
124+
125+ if config .EnableSRv6 {
126+ nhAttr , err = ptypes .MarshalAny (& bgpapi.NextHopAttribute {
127+ NextHop : nodeIpv6 .String (),
128+ })
129+ } else {
130+ nhAttr , err = ptypes .MarshalAny (& bgpapi.NextHopAttribute {
131+ NextHop : nodeIpv4 .String (),
132+ })
133+ }
121134 if err != nil {
122135 return nil , err
123136 }
@@ -147,6 +160,111 @@ func MakePath(prefix string, isWithdrawal bool, nodeIpv4 net.IP, nodeIpv6 net.IP
147160 }, nil
148161}
149162
163+ func MakePathSRv6Tunnel (localSid net.IP , bSid net.IP , nodeIpv6 net.IP , trafficType int , isWithdrawal bool ) (* bgpapi.Path , error ) {
164+ originAttr , err := ptypes .MarshalAny (& bgpapi.OriginAttribute {Origin : 0 })
165+ if err != nil {
166+ return nil , err
167+ }
168+ attrs := []* any.Any {originAttr }
169+
170+ var family * bgpapi.Family
171+ var nodeIP = nodeIpv6
172+ var epbs = & bgpapi.SRv6EndPointBehavior {}
173+ family = & BgpFamilySRv6IPv6
174+ if trafficType == 4 {
175+ epbs .Behavior = bgpapi .SRv6Behavior_END_DT4
176+ } else {
177+ epbs .Behavior = bgpapi .SRv6Behavior_END_DT6
178+ }
179+
180+ nlrisr , err := ptypes .MarshalAny (& bgpapi.SRPolicyNLRI {
181+ Length : 192 ,
182+ Endpoint : nodeIP ,
183+ })
184+
185+ if err != nil {
186+ return nil , err
187+ }
188+ nhAttr , err := ptypes .MarshalAny (& bgpapi.NextHopAttribute {
189+ NextHop : nodeIP .String (),
190+ })
191+ if err != nil {
192+ return nil , err
193+ }
194+ attrs = append (attrs , nhAttr )
195+
196+ sid , err := ptypes .MarshalAny (& bgpapi.SRBindingSID {
197+ SFlag : true ,
198+ IFlag : false ,
199+ Sid : bSid ,
200+ })
201+
202+ if err != nil {
203+ return nil , err
204+ }
205+ bsid , err := ptypes .MarshalAny (& bgpapi.TunnelEncapSubTLVSRBindingSID {
206+ Bsid : sid ,
207+ })
208+ if err != nil {
209+ return nil , err
210+ }
211+
212+ segment , err := ptypes .MarshalAny (& bgpapi.SegmentTypeB {
213+ Flags : & bgpapi.SegmentFlags {SFlag : true },
214+ Sid : localSid ,
215+ EndpointBehaviorStructure : epbs ,
216+ })
217+ if err != nil {
218+ return nil , err
219+ }
220+ seglist , err := ptypes .MarshalAny (& bgpapi.TunnelEncapSubTLVSRSegmentList {
221+ Weight : & bgpapi.SRWeight {
222+ Flags : 0 ,
223+ Weight : 12 ,
224+ },
225+ Segments : []* any.Any {segment },
226+ })
227+ if err != nil {
228+ return nil , err
229+ }
230+ pref , err := ptypes .MarshalAny (& bgpapi.TunnelEncapSubTLVSRPreference {
231+ Flags : 0 ,
232+ Preference : 11 ,
233+ })
234+ if err != nil {
235+ return nil , err
236+ }
237+
238+ pri , err := ptypes .MarshalAny (& bgpapi.TunnelEncapSubTLVSRPriority {
239+ Priority : 10 ,
240+ })
241+ if err != nil {
242+ return nil , err
243+ }
244+ // Tunnel Encapsulation attribute for SR Policy
245+ tun , err := ptypes .MarshalAny (& bgpapi.TunnelEncapAttribute {
246+ Tlvs : []* bgpapi.TunnelEncapTLV {
247+ {
248+ Type : 15 ,
249+ Tlvs : []* anypb.Any {bsid , seglist , pref , pri },
250+ },
251+ },
252+ })
253+ if err != nil {
254+ return nil , err
255+ }
256+ attrs = append (attrs , tun )
257+
258+ return & bgpapi.Path {
259+ Nlri : nlrisr ,
260+ IsWithdraw : isWithdrawal ,
261+ Pattrs : attrs ,
262+ Age : ptypes .TimestampNow (),
263+ Family : family ,
264+ }, nil
265+
266+ }
267+
150268type ChangeType int
151269
152270const (
@@ -181,6 +299,8 @@ const (
181299 RescanState ConnectivityEventType = "RescanState"
182300 ConnectivtyAdded ConnectivityEventType = "ConnectivtyAdded"
183301 ConnectivtyDeleted ConnectivityEventType = "ConnectivtyDeleted"
302+ SRv6PolicyAdded ConnectivityEventType = "SRv6PolicyAdded"
303+ SRv6PolicyDeleted ConnectivityEventType = "SRv6PolicyDeleted"
184304)
185305
186306type ConnectivityEvent struct {
@@ -194,8 +314,18 @@ type NodeConnectivity struct {
194314 Dst net.IPNet
195315 NextHop net.IP
196316 ResolvedProvider string
317+ Custom interface {}
197318}
198319
199320func (cn * NodeConnectivity ) String () string {
200321 return fmt .Sprintf ("%s-%s" , cn .Dst .String (), cn .NextHop .String ())
201322}
323+
324+ type SRv6Tunnel struct {
325+ Dst net.IP
326+ Bsid net.IP
327+ Policy * types.SrPolicy
328+ Sid net.IP
329+ Behavior uint8
330+ Priority uint32
331+ }
0 commit comments