Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions calico-vpp-agent/cmd/calico_vpp_dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func main() {
routeWatcher := watchers.NewRouteWatcher(common.VppManagerInfo.FakeNextHopIP4, common.VppManagerInfo.FakeNextHopIP6)
linkWatcher := watchers.NewLinkWatcher(common.VppManagerInfo.UplinkStatuses)
bgpConfigurationWatcher := watchers.NewBGPConfigurationWatcher(clientv3, log.WithFields(logrus.Fields{"subcomponent": "bgp-conf-watch"}))
nodeWatcher := watchers.NewNodeWatcher(vpp, clientv3, log.WithFields(logrus.Fields{"subcomponent": "node-watcher"}))
prefixWatcher := watchers.NewPrefixWatcher(client, log.WithFields(logrus.Fields{"subcomponent": "prefix-watcher"}))
peerWatcher := watchers.NewPeerWatcher(clientv3, k8sclient, log.WithFields(logrus.Fields{"subcomponent": "peer-watcher"}))
netWatcher := watchers.NewNetWatcher(vpp, log.WithFields(logrus.Fields{"component": "net-watcher"}))
Expand All @@ -154,15 +153,15 @@ func main() {
routingServer.SetBGPConf(bgpConf)
serviceServer.SetBGPConf(bgpConf)

Go(policyServer.ServePolicy)
log.Infof("Waiting for our node's BGP spec...")
Go(nodeWatcher.WatchNodes)
ourBGPSpec := nodeWatcher.WaitForOurBGPSpec()
felixConfig := policyServer.WaitForFelixConfig()
ourBGPSpec := policyServer.WaitForOurBGPSpec()

prefixWatcher.SetOurBGPSpec(ourBGPSpec)
connectivityServer.SetOurBGPSpec(ourBGPSpec)
routingServer.SetOurBGPSpec(ourBGPSpec)
serviceServer.SetOurBGPSpec(ourBGPSpec)
policyServer.SetOurBGPSpec(ourBGPSpec)
localSIDWatcher.SetOurBGPSpec(ourBGPSpec)

/**
Expand All @@ -176,8 +175,6 @@ func main() {
<-netWatcher.InSync
log.Infof("Networks synced")
}
Go(policyServer.ServePolicy)
felixConfig := policyServer.WaitForFelixConfig()

cniServer.SetFelixConfig(felixConfig)
connectivityServer.SetFelixConfig(felixConfig)
Expand Down
24 changes: 12 additions & 12 deletions calico-vpp-agent/cni/cni_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var _ = Describe("Node-related functionality of CNI", func() {
}
connectivityServer = connectivity.NewConnectivityServer(vpp, ipamStub, client,
log.WithFields(logrus.Fields{"subcomponent": "connectivity"}))
connectivityServer.SetOurBGPSpec(&oldv3.NodeBGPSpec{})
connectivityServer.SetOurBGPSpec(&common.LocalNodeSpec{})
if felixConfig == nil {
felixConfig = &config.Config{}
}
Expand Down Expand Up @@ -563,14 +563,10 @@ var _ = Describe("Node-related functionality of CNI", func() {
Expect(err).ToNot(HaveOccurred(), "could not call ForceProviderEnableDisable")

addedNodePublicKey := "public-key-for-added-node" // max 32 characters due to VPP binapi
connectivityServer.ForceNodeAddition(oldv3.Node{
ObjectMeta: metav1.ObjectMeta{
Name: AddedNodeName,
},
Status: oldv3.NodeStatus{
WireguardPublicKey: base64.StdEncoding.EncodeToString([]byte(addedNodePublicKey)),
},
connectivityServer.ForceNodeAddition(common.LocalNodeSpec{
Name: AddedNodeName,
}, net.ParseIP(AddedNodeIP))
connectivityServer.ForceWGPublicKeyAddition(AddedNodeName, base64.StdEncoding.EncodeToString([]byte(addedNodePublicKey)))
err = connectivityServer.UpdateIPConnectivity(&common.NodeConnectivity{
Dst: *ipNet(AddedNodeIP + "/24"),
NextHop: net.ParseIP(AddedNodeIP), // wireguard impl uses nexthop as node IP
Expand All @@ -584,11 +580,11 @@ var _ = Describe("Node-related functionality of CNI", func() {
Expect(err).ToNot(HaveOccurred(), "can't find wireguard tunnel interface")
wgTunnel, err := vpp.GetWireguardTunnel(wireguardSwIfIndex)
Expect(err).ToNot(HaveOccurred(), "can't get wireguard tunnel from VPP")

Expect(wgTunnel.Port).To(Equal(uint16(felixConfig.WireguardListeningPort)),
"incorrectly set wireguard listening port")
Expect(wgTunnel.Addr).To(Equal(net.ParseIP(ThisNodeIP).To4()),
"incorrectly set IP address of this node's wireguard tunnel interface")

By("checking wireguard tunnel interface attributes (Unnumbered)")
assertUnnumberedInterface(wireguardSwIfIndex, "wireguard tunnel interface", vpp)

Expand Down Expand Up @@ -1017,9 +1013,13 @@ func assertNextNodeLink(node, linkedNextNode string, vpp *vpplink.VppLink) int {
}

func configureBGPNodeIPAddresses(connectivityServer *connectivity.ConnectivityServer) {
connectivityServer.SetOurBGPSpec(&oldv3.NodeBGPSpec{
IPv4Address: ThisNodeIP + "/24",
IPv6Address: ThisNodeIPv6 + "/128",
ip4, ip4net, _ := net.ParseCIDR(ThisNodeIP + "/24")
ip4net.IP = ip4
ip6, ip6net, _ := net.ParseCIDR(ThisNodeIPv6 + "/128")
ip6net.IP = ip6
connectivityServer.SetOurBGPSpec(&common.LocalNodeSpec{
IPv4Address: ip4net,
IPv6Address: ip6net,
})
}

Expand Down
5 changes: 4 additions & 1 deletion calico-vpp-agent/cni/cni_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,10 @@ func (s *Server) cniServerEventLoop(t *tomb.Tomb) error {
}

func (s *Server) ServeCNI(t *tomb.Tomb) error {
syscall.Unlink(config.CNIServerSocket)
err := syscall.Unlink(config.CNIServerSocket)
if err != nil {
s.log.Warnf("unable to unlink cni server socket: %+v", err)
}

socketListener, err := net.Listen("unix", config.CNIServerSocket)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions calico-vpp-agent/cni/pod_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ func (s *Server) ParsePortSpec(value string) (ifPortConfigs *storage.LocalIfPort
return nil, fmt.Errorf("Please specify a port or a port range e.g. '1234-5678'")
}

start, err := strconv.ParseInt(portParts[0], 10, 16)
start, err := strconv.ParseUint(portParts[0], 10, 16)
if err != nil {
return nil, errors.Wrapf(err, "Error parsing port %s", portParts[0])
}
ifPortConfigs.Start = uint16(start)
ifPortConfigs.End = uint16(start)

if len(portParts) == 2 {
end, err := strconv.ParseInt(portParts[1], 10, 16)
end, err := strconv.ParseUint(portParts[1], 10, 16)
if err != nil {
return nil, errors.Wrapf(err, "Error parsing end port %s", portParts[1])
}
Expand Down
85 changes: 31 additions & 54 deletions calico-vpp-agent/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/golang/protobuf/ptypes/any"
bgpapi "github.com/osrg/gobgp/api"
calicov3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3"
oldv3 "github.com/projectcalico/calico/libcalico-go/lib/apis/v3"
"github.com/projectcalico/api/pkg/lib/numorstring"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/proto"
"github.com/projectcalico/vpp-dataplane/vpplink"
"github.com/projectcalico/vpp-dataplane/vpplink/types"
Expand All @@ -56,6 +56,19 @@ type PolicyServerIpam interface {
GetPrefixIPPool(prefix *net.IPNet) *proto.IPAMPool
}

type LocalNodeSpec struct {
ASNumber *numorstring.ASNumber
Labels map[string]string
Name string
IPv4Address *net.IPNet
IPv6Address *net.IPNet
}

type NodeWireguardPublicKey struct {
Name string
WireguardPublicKey string
}

// CreateVppLink creates new link to VPP and waits for VPP to be up and running (by using simple VPP API call)
func CreateVppLink(socket string, log *logrus.Entry) (vpp *vpplink.VppLink, err error) {
return CreateVppLinkInRetryLoop(socket, log, 20*time.Second, 2*time.Second)
Expand Down Expand Up @@ -173,11 +186,6 @@ var (
BgpFamilySRv6IPv6 = bgpapi.Family{Afi: bgpapi.Family_AFI_IP6, Safi: bgpapi.Family_SAFI_SR_POLICY}
)

type NodeState struct {
oldv3.Node
SweepFlag bool
}

func v46ify(s string, isv6 bool) string {
if isv6 {
return s + "-v6"
Expand Down Expand Up @@ -422,6 +430,17 @@ const (
ChangeUpdated ChangeType = 4
)

func GetIpNetChangeType(old, new *net.IPNet) ChangeType {
var oldStr, newStr string
if old != nil {
oldStr = old.IP.String()
}
if new != nil {
newStr = new.IP.String()
}
return GetStringChangeType(oldStr, newStr)
}

func GetStringChangeType(old, new string) ChangeType {
if old == new && new == "" {
return ChangeSame
Expand Down Expand Up @@ -458,56 +477,14 @@ type SRv6Tunnel struct {
Priority uint32
}

func GetBGPSpecAddresses(nodeBGPSpec *oldv3.NodeBGPSpec) (*net.IP, *net.IP) {
var ip4 *net.IP
var ip6 *net.IP
if nodeBGPSpec.IPv4Address != "" {
addr, _, err := net.ParseCIDR(nodeBGPSpec.IPv4Address)
if err == nil {
ip4 = &addr
}
func GetBGPSpecAddresses(nodeBGPSpec *LocalNodeSpec) (ip4 *net.IP, ip6 *net.IP) {
if nodeBGPSpec.IPv4Address != nil {
ip4 = &nodeBGPSpec.IPv4Address.IP
}
if nodeBGPSpec.IPv6Address != "" {
addr, _, err := net.ParseCIDR(nodeBGPSpec.IPv6Address)
if err == nil {
ip6 = &addr
}
if nodeBGPSpec.IPv6Address != nil {
ip6 = &nodeBGPSpec.IPv6Address.IP
}
return ip4, ip6
}

func GetBGPSpecIPNet(nodeBGPSpec *oldv3.NodeBGPSpec) (ip4 *net.IPNet, ip6 *net.IPNet) {
if nodeBGPSpec.IPv4Address != "" {
_, ipNet, err := net.ParseCIDR(nodeBGPSpec.IPv4Address)
if err == nil {
ip4 = ipNet
}
}
if nodeBGPSpec.IPv6Address != "" {
_, ipNet, err := net.ParseCIDR(nodeBGPSpec.IPv6Address)
if err == nil {
ip6 = ipNet
}
}
return ip4, ip6
}

func GetNodeSpecAddresses(node *oldv3.Node) (string, string) {
nodeIP4 := ""
nodeIP6 := ""
if node.Spec.BGP.IPv4Address != "" {
addr, _, err := net.ParseCIDR(node.Spec.BGP.IPv4Address)
if err == nil {
nodeIP4 = addr.String()
}
}
if node.Spec.BGP.IPv6Address != "" {
addr, _, err := net.ParseCIDR(node.Spec.BGP.IPv6Address)
if err == nil {
nodeIP6 = addr.String()
}
}
return nodeIP4, nodeIP6
return
}

func FormatBGPConfiguration(conf *calicov3.BGPConfigurationSpec) string {
Expand Down
2 changes: 2 additions & 0 deletions calico-vpp-agent/common/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const (

IpamPoolUpdate CalicoVppEventType = "IpamPoolUpdate"
IpamPoolRemove CalicoVppEventType = "IpamPoolRemove"

WireguardPublicKeyChanged CalicoVppEventType = "WireguardPublicKeyChanged"
)

var (
Expand Down
3 changes: 1 addition & 2 deletions calico-vpp-agent/connectivity/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"net"

felixConfig "github.com/projectcalico/calico/felix/config"
oldv3 "github.com/projectcalico/calico/libcalico-go/lib/apis/v3"
calicov3cli "github.com/projectcalico/calico/libcalico-go/lib/clientv3"
"github.com/projectcalico/vpp-dataplane/calico-vpp-agent/common"
"github.com/projectcalico/vpp-dataplane/vpplink"
Expand Down Expand Up @@ -55,7 +54,7 @@ type ConnectivityProvider interface {
EnableDisable(isEnable bool)
}

func (p *ConnectivityProviderData) GetNodeByIp(addr net.IP) *oldv3.Node {
func (p *ConnectivityProviderData) GetNodeByIp(addr net.IP) *common.LocalNodeSpec {
return p.server.GetNodeByIp(addr)
}
func (p *ConnectivityProviderData) GetNodeIPs() (*net.IP, *net.IP) {
Expand Down
Loading