From 8ae03aef86343068360a423d0e1ef8ea28899e55 Mon Sep 17 00:00:00 2001 From: Shaun Crampton Date: Thu, 25 Jan 2024 14:57:36 +0000 Subject: [PATCH] Add tests for VXLAN manager -> FDB. --- felix/dataplane/linux/vxlan_mgr.go | 4 ++-- felix/dataplane/linux/vxlan_mgr_test.go | 31 +++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/felix/dataplane/linux/vxlan_mgr.go b/felix/dataplane/linux/vxlan_mgr.go index 0f34bfafe93..17a921a0730 100644 --- a/felix/dataplane/linux/vxlan_mgr.go +++ b/felix/dataplane/linux/vxlan_mgr.go @@ -458,8 +458,8 @@ func (m *vxlanManager) CompleteDeferredWork() error { } l2routes = append(l2routes, vxlanfdb.VTEP{ TunnelMAC: mac, - TunnelIP: ip.FromString(addr), - HostIP: ip.FromString(parentDeviceIP), + TunnelIP: ip.FromIPOrCIDRString(addr), + HostIP: ip.FromIPOrCIDRString(parentDeviceIP), }) allowedVXLANSources = append(allowedVXLANSources, parentDeviceIP) } diff --git a/felix/dataplane/linux/vxlan_mgr_test.go b/felix/dataplane/linux/vxlan_mgr_test.go index b0486dc1af4..55262529e64 100644 --- a/felix/dataplane/linux/vxlan_mgr_test.go +++ b/felix/dataplane/linux/vxlan_mgr_test.go @@ -108,7 +108,8 @@ func (m *mockVXLANDataplane) LinkDel(netlink.Link) error { } type mockVXLANFDB struct { - currentVTEPs []vxlanfdb.VTEP // FIXME move to separate mock. + setVTEPsCalls int + currentVTEPs []vxlanfdb.VTEP } func (t *mockVXLANFDB) SetVTEPs(targets []vxlanfdb.VTEP) { @@ -116,6 +117,7 @@ func (t *mockVXLANFDB) SetVTEPs(targets []vxlanfdb.VTEP) { "targets": targets, }).Debug("SetL2Routes") t.currentVTEPs = targets + t.setVTEPsCalls++ } var _ = Describe("VXLANManager", func() { @@ -134,7 +136,6 @@ var _ = Describe("VXLANManager", func() { currentRoutes: map[string][]routetable.Target{}, } - // FIXME actually assert on the FDB contents. fdb = &mockVXLANFDB{} la := netlink.NewLinkAttrs() @@ -263,11 +264,22 @@ var _ = Describe("VXLANManager", func() { Expect(brt.currentRoutes[routetable.InterfaceNone]).To(HaveLen(0)) err = manager.CompleteDeferredWork() - Expect(err).NotTo(HaveOccurred()) + Expect(rt.currentRoutes["vxlan.calico"]).To(HaveLen(1)) Expect(brt.currentRoutes[routetable.InterfaceNone]).To(HaveLen(1)) Expect(prt.currentRoutes["eth0"]).NotTo(BeNil()) + + mac, err := net.ParseMAC("00:0a:95:9d:68:16") + Expect(fdb.currentVTEPs).To(ConsistOf(vxlanfdb.VTEP{ + HostIP: ip.FromString("172.0.12.1"), + TunnelIP: ip.FromString("10.0.80.0"), + TunnelMAC: mac, + })) + Expect(fdb.setVTEPsCalls).To(Equal(1)) + err = manager.CompleteDeferredWork() + Expect(err).NotTo(HaveOccurred()) + Expect(fdb.setVTEPsCalls).To(Equal(1)) }) It("successfully adds a IPv6 route to the parent interface", func() { @@ -339,11 +351,22 @@ var _ = Describe("VXLANManager", func() { Expect(brt.currentRoutes[routetable.InterfaceNone]).To(HaveLen(0)) err = managerV6.CompleteDeferredWork() - Expect(err).NotTo(HaveOccurred()) + Expect(rt.currentRoutes["vxlan-v6.calico"]).To(HaveLen(1)) Expect(brt.currentRoutes[routetable.InterfaceNone]).To(HaveLen(1)) Expect(prt.currentRoutes["eth0"]).NotTo(BeNil()) + + mac, err := net.ParseMAC("00:0a:95:9d:68:16") + Expect(fdb.currentVTEPs).To(ConsistOf(vxlanfdb.VTEP{ + HostIP: ip.FromString("fc00:10:10::1"), + TunnelIP: ip.FromString("fd00:10:96::"), + TunnelMAC: mac, + })) + Expect(fdb.setVTEPsCalls).To(Equal(1)) + err = managerV6.CompleteDeferredWork() + Expect(err).NotTo(HaveOccurred()) + Expect(fdb.setVTEPsCalls).To(Equal(1)) }) It("adds the route to the default table on next try when the parent route table is not immediately found", func() {