Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CRUD integration tests for IPv4/IPv6 #1419

Merged
merged 4 commits into from
Jul 25, 2019
Merged
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
295 changes: 295 additions & 0 deletions tests/integration/vpp/020_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

vpp_l3 "github.com/ligato/vpp-agent/api/models/vpp/l3"
"github.com/ligato/vpp-agent/plugins/vpp/ifplugin/ifaceidx"
ifplugin_vppcalls "github.com/ligato/vpp-agent/plugins/vpp/ifplugin/vppcalls"
_ "github.com/ligato/vpp-agent/plugins/vpp/l3plugin"
l3plugin_vppcalls "github.com/ligato/vpp-agent/plugins/vpp/l3plugin/vppcalls"
"github.com/ligato/vpp-agent/plugins/vpp/l3plugin/vrfidx"
Expand Down Expand Up @@ -63,3 +64,297 @@ func TestRoutes(t *testing.T) {
t.Fatalf("expected dump to contain both IPv4 and IPv6 routes")
}
}

func TestCRUDIPv4Route(t *testing.T) {
ctx := setupVPP(t)
defer ctx.teardownVPP()

ih := ifplugin_vppcalls.CompatibleInterfaceVppHandler(ctx.vppBinapi, logrus.NewLogger("test"))
const ifName = "loop1"
ifIdx, err := ih.AddLoopbackInterface(ifName)
if err != nil {
t.Fatalf("creating interface failed: %v", err)
}
t.Logf("interface created %v", ifIdx)

ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-iface1"), "test-iface1")
ifIndexes.Put(ifName, &ifaceidx.IfaceMetadata{
SwIfIndex: ifIdx,
})

var vrfMetaIdx uint32
vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf")
vrfIndexes.Put("vrf1-ipv4-vrf0", &vrfidx.VRFMetadata{Index: vrfMetaIdx, Protocol: vpp_l3.VrfTable_IPV4})

h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppBinapi, ifIndexes, vrfIndexes, logrus.NewLogger("test"))

routes, errx := h.DumpRoutes()
if errx != nil {
t.Fatalf("dumping routes failed: %v", err)
}
routesCnt := len(routes)
t.Logf("%d routes dumped", routesCnt)

newRoute := vpp_l3.Route{VrfId: 0, DstNetwork: "192.168.10.21/24", NextHopAddr: "192.168.30.1", OutgoingInterface: ifName}
err = h.VppAddRoute(&newRoute)
if err != nil {
t.Fatalf("adding route failed: %v", err)
}
t.Logf("route added: %+v", newRoute)

routes, err = h.DumpRoutes()
routesCnt2 := len(routes)
if err != nil {
t.Fatalf("dumping routes failed: %v", err)
}
t.Logf("%d routes dumped", routesCnt2)

if routesCnt+1 != routesCnt2 {
t.Errorf("Number of routes after adding of one route is not incremented by 1")
}

newRouteIsPresent := false
for _, route := range routes {
if (route.Route.DstNetwork == newRoute.DstNetwork) && (route.Route.NextHopAddr == newRoute.NextHopAddr) && (route.Route.OutgoingInterface == newRoute.OutgoingInterface) {
newRouteIsPresent = true
stanislav-chlebec marked this conversation as resolved.
Show resolved Hide resolved
break
}
}
if !newRouteIsPresent {
t.Error("Added route is not present in route dump")
}

err = h.VppDelRoute(&newRoute)
if err != nil {
t.Fatalf("deleting route failed: %v", err)
}
t.Logf("route deleted")

routes, err = h.DumpRoutes()
routesCnt3 := len(routes)
if err != nil {
t.Fatalf("dumping routes failed: %v", err)
}
t.Logf("%d routes dumped", routesCnt3)
if routesCnt2-1 != routesCnt3 {
t.Errorf("Number of routes after deleting of one route is not decremented by 1")
}

for _, route := range routes {
if (route.Route.DstNetwork == newRoute.DstNetwork) && (route.Route.NextHopAddr == newRoute.NextHopAddr) && (route.Route.OutgoingInterface == newRoute.OutgoingInterface) {
t.Error("Added route is still present in route dump - should be deleted")
}
}

vrfMetaIdx = 2
err = h.AddVrfTable(&vpp_l3.VrfTable{Id: vrfMetaIdx, Protocol: vpp_l3.VrfTable_IPV4, Label: "table1"})
if err != nil {
t.Fatalf("creating vrf table failed: %v", err)
}
t.Logf("vrf table 2 created")
vrfIndexes.Put("vrf1-ipv4-vrf2", &vrfidx.VRFMetadata{Index: vrfMetaIdx, Protocol: vpp_l3.VrfTable_IPV4})

routes, errx = h.DumpRoutes()
if errx != nil {
t.Fatalf("dumping routes failed: %v", err)
}
routesCnt = len(routes)
t.Logf("%d routes dumped", routesCnt)

newRoute = vpp_l3.Route{VrfId: 2, DstNetwork: "192.168.10.21/24", NextHopAddr: "192.168.30.1", OutgoingInterface: ifName}
err = h.VppAddRoute(&newRoute)
if err != nil {
t.Fatalf("adding route failed: %v", err)
}
t.Logf("route added: %+v", newRoute)

routes, err = h.DumpRoutes()
routesCnt2 = len(routes)
if err != nil {
t.Fatalf("dumping routes failed: %v", err)
}
t.Logf("%d routes dumped", routesCnt2)

if routesCnt+1 != routesCnt2 {
t.Errorf("Number of routes after adding of one route is not incremented by 1")
}

newRouteIsPresent = false
for _, route := range routes {
if (route.Route.DstNetwork == newRoute.DstNetwork) && (route.Route.NextHopAddr == newRoute.NextHopAddr) && (route.Route.OutgoingInterface == newRoute.OutgoingInterface) {
newRouteIsPresent = true
break
}
}
if !newRouteIsPresent {
t.Error("Added route is not present in route dump")
}

err = h.VppDelRoute(&newRoute)
if err != nil {
t.Fatalf("deleting route failed: %v", err)
}
t.Logf("route deleted")

routes, err = h.DumpRoutes()
routesCnt3 = len(routes)
if err != nil {
t.Fatalf("dumping routes failed: %v", err)
}
t.Logf("%d routes dumped", routesCnt3)
if routesCnt2-1 != routesCnt3 {
t.Errorf("Number of routes after deleting of one route is not decremented by 1")
}

for _, route := range routes {
if (route.Route.DstNetwork == newRoute.DstNetwork) && (route.Route.NextHopAddr == newRoute.NextHopAddr) && (route.Route.OutgoingInterface == newRoute.OutgoingInterface) {
t.Error("Added route is still present in route dump - should be deleted")
}
}
}

func TestCRUDIPv6Route(t *testing.T) {
ctx := setupVPP(t)
defer ctx.teardownVPP()

ih := ifplugin_vppcalls.CompatibleInterfaceVppHandler(ctx.vppBinapi, logrus.NewLogger("test"))
const ifName = "loop1"
ifIdx, err := ih.AddLoopbackInterface(ifName)
if err != nil {
t.Fatalf("creating interface failed: %v", err)
}
t.Logf("interface created %v", ifIdx)

ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-iface1"), "test-iface1")
ifIndexes.Put(ifName, &ifaceidx.IfaceMetadata{
SwIfIndex: ifIdx,
})

var vrfMetaIdx uint32
vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf")
vrfIndexes.Put("vrf1-ipv6-vrf0", &vrfidx.VRFMetadata{Index: vrfMetaIdx, Protocol: vpp_l3.VrfTable_IPV6})

h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppBinapi, ifIndexes, vrfIndexes, logrus.NewLogger("test"))

routes, errx := h.DumpRoutes()
if errx != nil {
t.Fatalf("dumping routes failed: %v", err)
}
routesCnt := len(routes)
t.Logf("%d routes dumped", routesCnt)

newRoute := vpp_l3.Route{VrfId: 0, DstNetwork: "fd30:0:0:1::/64", NextHopAddr: "fd31::1:1:0:0:1", OutgoingInterface: ifName}
err = h.VppAddRoute(&newRoute)
if err != nil {
t.Fatalf("adding route failed: %v", err)
}
t.Logf("route added: %+v", newRoute)

routes, err = h.DumpRoutes()
routesCnt2 := len(routes)
if err != nil {
t.Fatalf("dumping routes failed: %v", err)
}
t.Logf("%d routes dumped", routesCnt2)

if routesCnt+1 != routesCnt2 {
t.Errorf("Number of routes after adding of one route is not incremented by 1")
}

newRouteIsPresent := false
for _, route := range routes {
if (route.Route.DstNetwork == newRoute.DstNetwork) && (route.Route.NextHopAddr == newRoute.NextHopAddr) && (route.Route.OutgoingInterface == newRoute.OutgoingInterface) {
newRouteIsPresent = true
}
}
if !newRouteIsPresent {
t.Error("Added route is not present in route dump")
}

err = h.VppDelRoute(&newRoute)
if err != nil {
t.Fatalf("deleting route failed: %v", err)
}
t.Logf("route deleted")

routes, err = h.DumpRoutes()
routesCnt3 := len(routes)
if err != nil {
t.Fatalf("dumping routes failed: %v", err)
}
t.Logf("%d routes dumped", routesCnt3)
if routesCnt2-1 != routesCnt3 {
t.Errorf("Number of routes after deleting of one route is not decremented by 1")
}

for _, route := range routes {
if (route.Route.DstNetwork == newRoute.DstNetwork) && (route.Route.NextHopAddr == newRoute.NextHopAddr) && (route.Route.OutgoingInterface == newRoute.OutgoingInterface) {
t.Error("Added route is still present in route dump - should be deleted")
}
}

vrfMetaIdx = 2
err = h.AddVrfTable(&vpp_l3.VrfTable{Id: vrfMetaIdx, Protocol: vpp_l3.VrfTable_IPV6, Label: "table1"})
if err != nil {
t.Fatalf("creating vrf table failed: %v", err)
}
t.Logf("vrf table 2 created")
vrfIndexes.Put("vrf1-ipv6-vrf2", &vrfidx.VRFMetadata{Index: vrfMetaIdx, Protocol: vpp_l3.VrfTable_IPV6})

routes, errx = h.DumpRoutes()
if errx != nil {
t.Fatalf("dumping routes failed: %v", err)
}
routesCnt = len(routes)
t.Logf("%d routes dumped", routesCnt)

newRoute = vpp_l3.Route{VrfId: 2, DstNetwork: "fd30:0:0:1::/64", NextHopAddr: "fd31::1:1:0:0:1", OutgoingInterface: ifName}
err = h.VppAddRoute(&newRoute)
if err != nil {
t.Fatalf("adding route failed: %v", err)
}
t.Logf("route added: %+v", newRoute)

routes, err = h.DumpRoutes()
routesCnt2 = len(routes)
if err != nil {
t.Fatalf("dumping routes failed: %v", err)
}
t.Logf("%d routes dumped", routesCnt2)

if routesCnt+1 != routesCnt2 {
t.Errorf("Number of routes after adding of one route is not incremented by 1")
}

newRouteIsPresent = false
for _, route := range routes {
if (route.Route.DstNetwork == newRoute.DstNetwork) && (route.Route.NextHopAddr == newRoute.NextHopAddr) && (route.Route.OutgoingInterface == newRoute.OutgoingInterface) {
newRouteIsPresent = true
}
}
if !newRouteIsPresent {
t.Error("Added route is not present in route dump")
}

err = h.VppDelRoute(&newRoute)
if err != nil {
t.Fatalf("deleting route failed: %v", err)
}
t.Logf("route deleted")

routes, err = h.DumpRoutes()
routesCnt3 = len(routes)
if err != nil {
t.Fatalf("dumping routes failed: %v", err)
}
t.Logf("%d routes dumped", routesCnt3)
if routesCnt2-1 != routesCnt3 {
t.Errorf("Number of routes after deleting of one route is not decremented by 1")
}

for _, route := range routes {
if (route.Route.DstNetwork == newRoute.DstNetwork) && (route.Route.NextHopAddr == newRoute.NextHopAddr) && (route.Route.OutgoingInterface == newRoute.OutgoingInterface) {
t.Error("Added route is still present in route dump - should be deleted")
}
}
}