go.ligato.io/vpp-agent/v3@v3.5.0/tests/integration/vpp/031_proxy_arp_test.go (about) 1 // Copyright (c) 2020 Cisco and/or its affiliates. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package vpp 16 17 import ( 18 "net" 19 "testing" 20 21 . "github.com/onsi/gomega" 22 23 "go.ligato.io/cn-infra/v2/logging/logrus" 24 25 netalloc_mock "go.ligato.io/vpp-agent/v3/plugins/netalloc/mock" 26 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx" 27 l3plugin_vppcalls "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vppcalls" 28 "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vrfidx" 29 vpp_l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3" 30 31 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin" 32 ) 33 34 func TestProxyARPRange(t *testing.T) { 35 ctx := setupVPP(t) 36 defer ctx.teardownVPP() 37 38 ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if") 39 vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf") 40 vrfIndexes.Put("vrf1-ipv4", &vrfidx.VRFMetadata{Index: 0, Protocol: vpp_l3.VrfTable_IPV4}) 41 vrfIndexes.Put("vrf1-ipv6", &vrfidx.VRFMetadata{Index: 0, Protocol: vpp_l3.VrfTable_IPV6}) 42 43 h := l3plugin_vppcalls.CompatibleL3VppHandler(ctx.vppClient, ifIndexes, vrfIndexes, 44 netalloc_mock.NewMockNetAlloc(), logrus.NewLogger("test")) 45 46 tests := []struct { 47 name string 48 proxyARPRange *vpp_l3.ProxyARP_Range 49 addMustFail bool 50 }{ 51 { 52 name: "base test of proxy ARP range", 53 proxyARPRange: &vpp_l3.ProxyARP_Range{ 54 FirstIpAddr: "192.168.1.1", 55 LastIpAddr: "192.168.1.10", 56 VrfId: 0, 57 }, 58 addMustFail: false, 59 }, 60 { 61 name: "Without first IP address", 62 proxyARPRange: &vpp_l3.ProxyARP_Range{ 63 LastIpAddr: "192.168.1.10", 64 VrfId: 0, 65 }, 66 addMustFail: true, 67 }, 68 { 69 name: "Without last IP address", 70 proxyARPRange: &vpp_l3.ProxyARP_Range{ 71 FirstIpAddr: "192.168.1.1", 72 VrfId: 0, 73 }, 74 addMustFail: true, 75 }, 76 { 77 name: "Without both IP addresses", 78 proxyARPRange: &vpp_l3.ProxyARP_Range{ 79 VrfId: 0, 80 }, 81 addMustFail: true, 82 }, 83 { 84 name: "No such FIB / VRF", 85 proxyARPRange: &vpp_l3.ProxyARP_Range{ 86 FirstIpAddr: "192.168.1.1", 87 LastIpAddr: "192.168.1.10", 88 VrfId: 2, 89 }, 90 addMustFail: true, 91 }, 92 } 93 94 for _, test := range tests { 95 t.Run(test.name, func(t *testing.T) { 96 initialRanges, err := h.DumpProxyArpRanges() 97 Expect(err).ToNot(HaveOccurred(), "dumping proxy ARP ranges failed") 98 Expect(initialRanges).To(HaveLen(0), "expected no proxy ARP ranges in the beginning") 99 err = h.AddProxyArpRange( 100 net.ParseIP(test.proxyARPRange.FirstIpAddr).To4(), 101 net.ParseIP(test.proxyARPRange.LastIpAddr).To4(), 102 test.proxyARPRange.VrfId, 103 ) 104 if test.addMustFail { 105 Expect(err).To(HaveOccurred(), "adding proxy ARP range passed successfully but must fail") 106 return 107 } 108 Expect(err).ToNot(HaveOccurred(), "adding proxy ARP range failed") 109 110 afterAddRanges, err := h.DumpProxyArpRanges() 111 Expect(err).ToNot(HaveOccurred(), "dumping proxy ARP ranges failed") 112 Expect(afterAddRanges).To(HaveLen(1), "expected one proxy ARP range") 113 Expect(afterAddRanges[0].Range.FirstIpAddr).To(Equal(test.proxyARPRange.FirstIpAddr), 114 "First IP address of proxy ARP range retrieved from dump is not equal to expected", 115 ) 116 Expect(afterAddRanges[0].Range.LastIpAddr).To(Equal(test.proxyARPRange.LastIpAddr), 117 "Last IP address of proxy ARP range retrieved from dump is not equal to expected", 118 ) 119 Expect(afterAddRanges[0].Range.VrfId).To(Equal(test.proxyARPRange.VrfId), 120 "VRF ID of proxy ARP range retrieved from dump is not equal to expected", 121 ) 122 123 Expect( 124 h.DeleteProxyArpRange( 125 net.ParseIP(test.proxyARPRange.FirstIpAddr).To4(), 126 net.ParseIP(test.proxyARPRange.LastIpAddr).To4(), 127 test.proxyARPRange.VrfId, 128 ), 129 ).To(Succeed(), "deleting proxy ARP range failed") 130 131 afterDeleteRanges, err := h.DumpProxyArpRanges() 132 Expect(err).ToNot(HaveOccurred(), "dumping proxy ARP ranges failed") 133 Expect(afterDeleteRanges).To(HaveLen(0), "expected no proxy ARP ranges after deleting one") 134 }) 135 } 136 }