go.ligato.io/vpp-agent/v3@v3.5.0/tests/integration/vpp/051_flowprobe_test.go (about) 1 package vpp 2 3 import ( 4 "testing" 5 6 . "github.com/onsi/gomega" 7 8 "go.ligato.io/cn-infra/v2/logging/logrus" 9 10 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx" 11 ifplugin_vppcalls "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/vppcalls" 12 ipfixplugin_vppcalls "go.ligato.io/vpp-agent/v3/plugins/vpp/ipfixplugin/vppcalls" 13 vpp_ipfix "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/ipfix" 14 15 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/ipfixplugin" 16 ) 17 18 func TestFlowprobe(t *testing.T) { 19 ctx := setupVPP(t) 20 defer ctx.teardownVPP() 21 22 // Prepare an interface to test Flowprobe feature enable/disable actions. 23 ih := ifplugin_vppcalls.CompatibleInterfaceVppHandler(ctx.vppClient, logrus.NewLogger("test")) 24 Expect(ih).ToNot(BeNil(), "Interface VPP handler is not available") 25 const ifName = "loop1" 26 ifIdx, err := ih.AddLoopbackInterface(ifName) 27 Expect(err).ToNot(HaveOccurred(), "failed to create an interface") 28 t.Logf("interface created with SwIfIndex=%v", ifIdx) 29 30 // Create interface index and add there previously created interface. 31 ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if") 32 ifIndexes.Put(ifName, &ifaceidx.IfaceMetadata{SwIfIndex: ifIdx}) 33 34 // Finally, create and start using IPFIX VPP handler. 35 h := ipfixplugin_vppcalls.CompatibleIpfixVppHandler(ctx.vppClient, ifIndexes, logrus.NewLogger("test")) 36 Expect(h).ToNot(BeNil(), "IPFIX VPP handler is not available") 37 38 // Try to set empty Flowprobe params. This must fail. 39 Expect(h.SetFPParams(&vpp_ipfix.FlowProbeParams{})).ToNot(Succeed()) 40 41 // But if at least one of params is set, everything should be ok. 42 Expect(h.SetFPParams(&vpp_ipfix.FlowProbeParams{RecordL2: true})).To(Succeed(), 43 "setting new params for Flowprobe failed", 44 ) 45 46 // Try to add Flowprobe feature to the interface. 47 Expect(h.AddFPFeature(&vpp_ipfix.FlowProbeFeature{Interface: ifName})).To(Succeed(), 48 "enabling Flowprobe feature for interface failed", 49 ) 50 51 // Try to update Flowprobe feature for the interface. 52 Expect(h.AddFPFeature(&vpp_ipfix.FlowProbeFeature{ 53 Interface: ifName, 54 L2: true, 55 })).ToNot(Succeed(), "updating Flowprobe feature on interface was not expected to work") 56 57 // So to update, first it needs to be deleted... 58 Expect(h.DelFPFeature(&vpp_ipfix.FlowProbeFeature{Interface: ifName})).To(Succeed(), 59 "removing Flowprobe feature for interface failed", 60 ) 61 62 // ... and afterwards created. 63 Expect(h.AddFPFeature(&vpp_ipfix.FlowProbeFeature{ 64 Interface: ifName, 65 L2: true, 66 })).To(Succeed(), "enabling Flowprobe feature for interface failed") 67 }