@@ -19,6 +19,8 @@ import (
1919 "fmt"
2020 "net"
2121
22+ bgpapi "github.com/osrg/gobgp/v3/api"
23+ bgpserver "github.com/osrg/gobgp/v3/pkg/server"
2224 "github.com/pkg/errors"
2325 calicov3cli "github.com/projectcalico/calico/libcalico-go/lib/clientv3"
2426 "github.com/sirupsen/logrus"
@@ -33,8 +35,8 @@ import (
3335 "github.com/projectcalico/vpp-dataplane/v3/calico-vpp-agent/felix/cni/model"
3436 "github.com/projectcalico/vpp-dataplane/v3/calico-vpp-agent/felix/connectivity"
3537 "github.com/projectcalico/vpp-dataplane/v3/calico-vpp-agent/felix/policies"
38+ "github.com/projectcalico/vpp-dataplane/v3/calico-vpp-agent/felix/routing"
3639 "github.com/projectcalico/vpp-dataplane/v3/calico-vpp-agent/felix/services"
37- "github.com/projectcalico/vpp-dataplane/v3/calico-vpp-agent/routing"
3840 "github.com/projectcalico/vpp-dataplane/v3/config"
3941 "github.com/projectcalico/vpp-dataplane/v3/vpplink"
4042 "github.com/projectcalico/vpp-dataplane/v3/vpplink/types"
@@ -61,6 +63,8 @@ type Server struct {
6163 connectivityHandler * connectivity.ConnectivityHandler
6264 serviceHandler * services.ServiceHandler
6365 peerHandler * routing.PeerHandler
66+ routingHandler * routing.RoutingHandler
67+ bgpHandler * routing.BGPHandler
6468}
6569
6670// NewFelixServer creates a felix server
@@ -80,6 +84,8 @@ func NewFelixServer(vpp *vpplink.VppLink, clientv3 calicov3cli.Interface, log *l
8084 connectivityHandler : connectivity .NewConnectivityHandler (vpp , cache , clientv3 , log ),
8185 serviceHandler : services .NewServiceHandler (vpp , cache , log ),
8286 peerHandler : routing .NewPeerHandler (cache , log ),
87+ routingHandler : routing .NewRoutingHandler (vpp , cache , log ),
88+ bgpHandler : routing .NewBGPHandler (log ),
8389 }
8490
8591 reg := common .RegisterHandler (server .felixServerEventChan , "felix server events" )
@@ -90,10 +96,21 @@ func NewFelixServer(vpp *vpplink.VppLink, clientv3 calicov3cli.Interface, log *l
9096 common .TunnelDeleted ,
9197 common .NetAddedOrUpdated ,
9298 common .NetDeleted ,
99+ common .BGPPathAdded ,
100+ common .BGPPathDeleted ,
101+ common .BGPPeerAdded ,
102+ common .BGPPeerUpdated ,
103+ common .BGPPeerDeleted ,
104+ common .BGPFilterAddedOrUpdated ,
105+ common .BGPFilterDeleted ,
106+ common .BGPDefinedSetAdded ,
107+ common .BGPDefinedSetDeleted ,
93108 common .ConnectivityAdded ,
94109 common .ConnectivityDeleted ,
95110 common .SRv6PolicyAdded ,
96111 common .SRv6PolicyDeleted ,
112+ common .LocalPodAddressAdded ,
113+ common .LocalPodAddressDeleted ,
97114 )
98115
99116 return server
@@ -111,10 +128,26 @@ func (s *Server) GetPeerHandler() *routing.PeerHandler {
111128 return s .peerHandler
112129}
113130
131+ func (s * Server ) GetRoutingHandler () * routing.RoutingHandler {
132+ return s .routingHandler
133+ }
134+
135+ func (s * Server ) GetConnectivityHandler () * connectivity.ConnectivityHandler {
136+ return s .connectivityHandler
137+ }
138+
139+ func (s * Server ) GetBGPHandler () * routing.BGPHandler {
140+ return s .bgpHandler
141+ }
142+
114143func (s * Server ) SetBGPConf (bgpConf * calicov3.BGPConfigurationSpec ) {
115144 s .cache .BGPConf = bgpConf
116145}
117146
147+ func (s * Server ) SetBGPServer (bgpServer * bgpserver.BgpServer ) {
148+ s .bgpHandler .SetBGPServer (bgpServer )
149+ }
150+
118151func (s * Server ) getMainInterface () * config.UplinkStatus {
119152 for _ , i := range common .VppManagerInfo .UplinkStatuses {
120153 if i .IsMain {
@@ -375,42 +408,100 @@ func (s *Server) handleFelixServerEvents(msg interface{}) (err error) {
375408 return fmt .Errorf ("evt.Old not a uint32 %v" , evt .Old )
376409 }
377410 s .policiesHandler .OnTunnelDelete (swIfIndex )
378- case common .ConnectivityAdded :
379- new , ok := evt .New .(* common. NodeConnectivity )
411+ case common .BGPPathAdded :
412+ path , ok := evt .New .(* bgpapi. Path )
380413 if ! ok {
381- s . log . Errorf ("evt.New is not a *common.NodeConnectivity %v" , evt .New )
414+ return fmt . Errorf ("evt.New is not a (*bgpapi.Path) %v" , evt .New )
382415 }
383- err := s .connectivityHandler .UpdateIPConnectivity (new , false /* isWithdraw */ )
384- if err != nil {
385- s .log .Errorf ("Error while adding connectivity %s" , err )
416+ err = s .bgpHandler .HandleBGPPathAdded (path )
417+ case common .BGPPathDeleted :
418+ path , ok := evt .Old .(* bgpapi.Path )
419+ if ! ok {
420+ return fmt .Errorf ("evt.Old is not a (*bgpapi.Path) %v" , evt .Old )
386421 }
387- case common .ConnectivityDeleted :
388- old , ok := evt .Old .(* common.NodeConnectivity )
422+ err = s .bgpHandler .HandleBGPPathDeleted (path )
423+ case common .BGPPeerAdded :
424+ peer , ok := evt .New .(* routing.LocalBGPPeer )
389425 if ! ok {
390- s . log . Errorf ("evt.Old is not a *common.NodeConnectivity %v" , evt .Old )
426+ return fmt . Errorf ("evt.New is not a (*routing.LocalBGPPeer) %v" , evt .New )
391427 }
392- err := s .connectivityHandler .UpdateIPConnectivity (old , true /* isWithdraw */ )
393- if err != nil {
394- s .log .Errorf ("Error while deleting connectivity %s" , err )
428+ err = s .bgpHandler .HandleBGPPeerAdded (peer )
429+ case common .BGPPeerUpdated :
430+ newPeer , ok := evt .New .(* routing.LocalBGPPeer )
431+ if ! ok {
432+ return fmt .Errorf ("evt.New is not a (*routing.LocalBGPPeer) %v" , evt .New )
395433 }
396- case common .SRv6PolicyAdded :
397- new , ok := evt .New .(* common.NodeConnectivity )
434+ oldPeer , ok := evt .Old .(* routing.LocalBGPPeer )
398435 if ! ok {
399- s . log . Errorf ("evt.New is not a *common.NodeConnectivity %v" , evt .New )
436+ return fmt . Errorf ("evt.Old is not a (*routing.LocalBGPPeer) %v" , evt .Old )
400437 }
401- err := s .connectivityHandler .UpdateSRv6Policy (new , false /* isWithdraw */ )
402- if err != nil {
403- s .log .Errorf ("Error while adding SRv6 Policy %s" , err )
438+ err = s .bgpHandler .HandleBGPPeerUpdated (newPeer , oldPeer )
439+ case common .BGPPeerDeleted :
440+ peerIP , ok := evt .Old .(string )
441+ if ! ok {
442+ return fmt .Errorf ("evt.Old is not a string %v" , evt .Old )
443+ }
444+ err = s .bgpHandler .HandleBGPPeerDeleted (peerIP )
445+ case common .BGPFilterAddedOrUpdated :
446+ filter , ok := evt .New .(calicov3.BGPFilter )
447+ if ! ok {
448+ return fmt .Errorf ("evt.New is not a (calicov3.BGPFilter) %v" , evt .New )
404449 }
450+ err = s .bgpHandler .HandleBGPFilterAddedOrUpdated (filter )
451+ case common .BGPFilterDeleted :
452+ filter , ok := evt .Old .(calicov3.BGPFilter )
453+ if ! ok {
454+ return fmt .Errorf ("evt.Old is not a (calicov3.BGPFilter) %v" , evt .Old )
455+ }
456+ err = s .bgpHandler .HandleBGPFilterDeleted (filter )
457+ case common .BGPDefinedSetAdded :
458+ definedSet , ok := evt .New .(* bgpapi.DefinedSet )
459+ if ! ok {
460+ return fmt .Errorf ("evt.New is not a (*bgpapi.DefinedSet) %v" , evt .New )
461+ }
462+ err = s .bgpHandler .HandleBGPDefinedSetAdded (definedSet )
463+ case common .BGPDefinedSetDeleted :
464+ definedSet , ok := evt .Old .(* bgpapi.DefinedSet )
465+ if ! ok {
466+ return fmt .Errorf ("evt.Old is not a (*bgpapi.DefinedSet) %v" , evt .Old )
467+ }
468+ err = s .bgpHandler .HandleBGPDefinedSetDeleted (definedSet )
469+ case common .ConnectivityAdded :
470+ connectivity , ok := evt .New .(* common.NodeConnectivity )
471+ if ! ok {
472+ return fmt .Errorf ("evt.New is not a (*common.NodeConnectivity) %v" , evt .New )
473+ }
474+ err = s .connectivityHandler .UpdateIPConnectivity (connectivity , false /* isWithdraw */ )
475+ case common .ConnectivityDeleted :
476+ connectivity , ok := evt .Old .(* common.NodeConnectivity )
477+ if ! ok {
478+ return fmt .Errorf ("evt.Old is not a (*common.NodeConnectivity) %v" , evt .Old )
479+ }
480+ err = s .connectivityHandler .UpdateIPConnectivity (connectivity , true /* isWithdraw */ )
481+ case common .SRv6PolicyAdded :
482+ connectivity , ok := evt .New .(* common.NodeConnectivity )
483+ if ! ok {
484+ return fmt .Errorf ("evt.New is not a (*common.NodeConnectivity) %v" , evt .New )
485+ }
486+ err = s .connectivityHandler .UpdateSRv6Policy (connectivity , false /* isWithdraw */ )
405487 case common .SRv6PolicyDeleted :
406- old , ok := evt .Old .(* common.NodeConnectivity )
488+ connectivity , ok := evt .Old .(* common.NodeConnectivity )
407489 if ! ok {
408- s . log . Errorf ("evt.Old is not a *common.NodeConnectivity %v" , evt .Old )
490+ return fmt . Errorf ("evt.Old is not a ( *common.NodeConnectivity) %v" , evt .Old )
409491 }
410- err := s .connectivityHandler .UpdateSRv6Policy (old , true /* isWithdraw */ )
411- if err != nil {
412- s .log .Errorf ("Error while deleting SRv6 Policy %s" , err )
492+ err = s .connectivityHandler .UpdateSRv6Policy (connectivity , true /* isWithdraw */ )
493+ case common .LocalPodAddressAdded :
494+ networkPod , ok := evt .New .(cni.NetworkPod )
495+ if ! ok {
496+ return fmt .Errorf ("evt.New is not a (cni.NetworkPod) %v" , evt .New )
497+ }
498+ err = s .routingHandler .AnnounceLocalAddress (networkPod .ContainerIP , networkPod .NetworkVni )
499+ case common .LocalPodAddressDeleted :
500+ networkPod , ok := evt .Old .(cni.NetworkPod )
501+ if ! ok {
502+ return fmt .Errorf ("evt.Old is not a (cni.NetworkPod) %v" , evt .Old )
413503 }
504+ err = s .routingHandler .WithdrawLocalAddress (networkPod .ContainerIP , networkPod .NetworkVni )
414505 default :
415506 s .log .Warnf ("Unhandled CalicoVppEvent.Type: %s" , evt .Type )
416507 }
0 commit comments