go.ligato.io/vpp-agent/v3@v3.5.0/tests/integration/vpp/050_ipfix_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 ipfixplugin_vppcalls "go.ligato.io/vpp-agent/v3/plugins/vpp/ipfixplugin/vppcalls" 12 vpp_ipfix "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/ipfix" 13 14 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/ipfixplugin" 15 ) 16 17 func TestIPFIX(t *testing.T) { 18 ctx := setupVPP(t) 19 defer ctx.teardownVPP() 20 21 ifIdx := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if") 22 h := ipfixplugin_vppcalls.CompatibleIpfixVppHandler(ctx.vppClient, ifIdx, logrus.NewLogger("test")) 23 Expect(h).ToNot(BeNil(), "IPFIX VPP handler is not available") 24 25 // Check default IPFIX configuration. 26 exporters, err := h.DumpExporters() 27 Expect(err).ToNot(HaveOccurred(), "failed to dump IPFIX configuration") 28 Expect(exporters).To(HaveLen(1), "dump must return only one record") 29 Expect(exporters[0].GetCollector().GetAddress()).To(Equal("0.0.0.0"), "unexpected initial address of collector") 30 31 tests := []struct { 32 name string 33 ipfix *vpp_ipfix.IPFIX 34 shouldFail bool 35 }{ 36 { 37 name: "Simple test", 38 ipfix: &vpp_ipfix.IPFIX{ 39 Collector: &vpp_ipfix.IPFIX_Collector{ 40 Address: "10.10.10.10", 41 }, 42 SourceAddress: "20.20.20.20", 43 }, 44 shouldFail: false, 45 }, 46 { 47 name: "Collector IP 0.0.0.0 fail", 48 ipfix: &vpp_ipfix.IPFIX{ 49 Collector: &vpp_ipfix.IPFIX_Collector{ 50 Address: "0.0.0.0", 51 }, 52 SourceAddress: "20.20.20.20", 53 }, 54 shouldFail: true, 55 }, 56 { 57 name: "Source IP 0.0.0.0 fail", 58 ipfix: &vpp_ipfix.IPFIX{ 59 Collector: &vpp_ipfix.IPFIX_Collector{ 60 Address: "20.20.20.20", 61 }, 62 SourceAddress: "0.0.0.0", 63 }, 64 shouldFail: true, 65 }, 66 { 67 name: "Collector IP6 fail", 68 ipfix: &vpp_ipfix.IPFIX{ 69 Collector: &vpp_ipfix.IPFIX_Collector{ 70 Address: "2020::4:7", 71 }, 72 SourceAddress: "20.20.20.20", 73 }, 74 shouldFail: true, 75 }, 76 { 77 name: "Source IP6 fail", 78 ipfix: &vpp_ipfix.IPFIX{ 79 Collector: &vpp_ipfix.IPFIX_Collector{ 80 Address: "20.20.20.20", 81 }, 82 SourceAddress: "2020::4:7", 83 }, 84 shouldFail: true, 85 }, 86 { 87 name: "MTU is in range", 88 ipfix: &vpp_ipfix.IPFIX{ 89 Collector: &vpp_ipfix.IPFIX_Collector{ 90 Address: "10.10.10.10", 91 }, 92 SourceAddress: "20.20.20.20", 93 PathMtu: 256, 94 }, 95 shouldFail: false, 96 }, 97 { 98 name: "Too small MTU fail", 99 ipfix: &vpp_ipfix.IPFIX{ 100 Collector: &vpp_ipfix.IPFIX_Collector{ 101 Address: "10.10.10.10", 102 }, 103 SourceAddress: "20.20.20.20", 104 PathMtu: 1, 105 }, 106 shouldFail: true, 107 }, 108 { 109 name: "Too big MTU fail", 110 ipfix: &vpp_ipfix.IPFIX{ 111 Collector: &vpp_ipfix.IPFIX_Collector{ 112 Address: "10.10.10.10", 113 }, 114 SourceAddress: "20.20.20.20", 115 PathMtu: 9999, 116 }, 117 shouldFail: true, 118 }, 119 } 120 121 for _, test := range tests { 122 t.Run(test.name, func(t *testing.T) { 123 if test.shouldFail { 124 Expect(h.SetExporter(test.ipfix)).ToNot(Succeed()) 125 return 126 } 127 128 Expect(h.SetExporter(test.ipfix)).To(Succeed()) 129 130 exporters, err := h.DumpExporters() 131 Expect(err).ToNot(HaveOccurred(), "failed to dump IPFIX configuration") 132 Expect(exporters).To(HaveLen(1), "dump must return only one record") 133 e := exporters[0] 134 Expect(e.GetCollector().GetAddress()).To(Equal(test.ipfix.GetCollector().GetAddress())) 135 Expect(e.GetSourceAddress()).To(Equal(test.ipfix.GetSourceAddress())) 136 }) 137 } 138 }