Skip to content

Commit

Permalink
Add tests for VXLAN manager -> FDB.
Browse files Browse the repository at this point in the history
  • Loading branch information
fasaxc committed Jan 26, 2024
1 parent 44181d9 commit 8ae03ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions felix/dataplane/linux/vxlan_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
31 changes: 27 additions & 4 deletions felix/dataplane/linux/vxlan_mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ 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) {
log.WithFields(log.Fields{
"targets": targets,
}).Debug("SetL2Routes")
t.currentVTEPs = targets
t.setVTEPsCalls++
}

var _ = Describe("VXLANManager", func() {
Expand All @@ -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()
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 8ae03ae

Please sign in to comment.