go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l2plugin/vppcalls/vpp2210/arp_term_vppcalls_test.go (about) 1 // Copyright (c) 2022 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 vpp2210_test 16 17 import ( 18 "testing" 19 20 . "github.com/onsi/gomega" 21 22 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/ethernet_types" 23 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/ip_types" 24 vpp_l2 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/l2" 25 ) 26 27 func TestVppAddArpTerminationTableEntry(t *testing.T) { 28 ctx, bdHandler, _ := bdTestSetup(t) 29 defer ctx.TeardownTestCtx() 30 31 ctx.MockVpp.MockReply(&vpp_l2.BdIPMacAddDelReply{}) 32 33 err := bdHandler.AddArpTerminationTableEntry( 34 4, "FF:FF:FF:FF:FF:FF", "192.168.4.4") 35 36 Expect(err).ShouldNot(HaveOccurred()) 37 Expect(ctx.MockChannel.Msg).To(Equal(&vpp_l2.BdIPMacAddDel{ 38 Entry: vpp_l2.BdIPMac{ 39 BdID: 4, 40 IP: ip_types.Address{ 41 Af: ip_types.ADDRESS_IP4, 42 Un: ip_types.AddressUnionIP4( 43 ip_types.IP4Address{192, 168, 4, 4}, 44 ), 45 }, 46 Mac: ethernet_types.MacAddress{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 47 }, 48 IsAdd: true, 49 })) 50 } 51 52 func TestVppAddArpTerminationTableEntryIPv6(t *testing.T) { 53 ctx, bdHandler, _ := bdTestSetup(t) 54 defer ctx.TeardownTestCtx() 55 56 ctx.MockVpp.MockReply(&vpp_l2.BdIPMacAddDelReply{}) 57 58 err := bdHandler.AddArpTerminationTableEntry(4, "FF:FF:FF:FF:FF:FF", "2001:db9::54") 59 60 Expect(err).ShouldNot(HaveOccurred()) 61 Expect(ctx.MockChannel.Msg).To(Equal(&vpp_l2.BdIPMacAddDel{ 62 Entry: vpp_l2.BdIPMac{ 63 BdID: 4, 64 IP: ip_types.Address{ 65 Af: ip_types.ADDRESS_IP6, 66 Un: ip_types.AddressUnionIP6( 67 ip_types.IP6Address{32, 1, 13, 185, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84}, 68 ), 69 }, 70 Mac: ethernet_types.MacAddress{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 71 }, 72 IsAdd: true, 73 })) 74 } 75 76 func TestVppRemoveArpTerminationTableEntry(t *testing.T) { 77 ctx, bdHandler, _ := bdTestSetup(t) 78 defer ctx.TeardownTestCtx() 79 80 ctx.MockVpp.MockReply(&vpp_l2.BdIPMacAddDelReply{}) 81 82 err := bdHandler.RemoveArpTerminationTableEntry(4, "FF:FF:FF:FF:FF:FF", "192.168.4.4") 83 84 Expect(err).ShouldNot(HaveOccurred()) 85 Expect(ctx.MockChannel.Msg).To(Equal(&vpp_l2.BdIPMacAddDel{ 86 Entry: vpp_l2.BdIPMac{ 87 BdID: 4, 88 IP: ip_types.Address{ 89 Af: ip_types.ADDRESS_IP4, 90 Un: ip_types.AddressUnionIP4( 91 ip_types.IP4Address{192, 168, 4, 4}, 92 ), 93 }, 94 Mac: ethernet_types.MacAddress{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 95 }, 96 IsAdd: false, 97 })) 98 } 99 100 func TestVppArpTerminationTableEntryMacError(t *testing.T) { 101 ctx, bdHandler, _ := bdTestSetup(t) 102 defer ctx.TeardownTestCtx() 103 104 ctx.MockVpp.MockReply(&vpp_l2.BdIPMacAddDelReply{}) 105 106 err := bdHandler.AddArpTerminationTableEntry(4, "in:va:li:d:ma:c", "192.168.4.4") 107 Expect(err).Should(HaveOccurred()) 108 109 err = bdHandler.RemoveArpTerminationTableEntry(4, "in:va:li:d:ma:c", "192.168.4.4") 110 Expect(err).Should(HaveOccurred()) 111 } 112 113 func TestVppArpTerminationTableEntryIpError(t *testing.T) { 114 ctx, bdHandler, _ := bdTestSetup(t) 115 defer ctx.TeardownTestCtx() 116 117 ctx.MockVpp.MockReply(&vpp_l2.BdIPMacAddDelReply{}) 118 119 err := bdHandler.AddArpTerminationTableEntry(4, "FF:FF:FF:FF:FF:FF", "") 120 Expect(err).Should(HaveOccurred()) 121 122 err = bdHandler.RemoveArpTerminationTableEntry(4, "FF:FF:FF:FF:FF:FF", "") 123 Expect(err).Should(HaveOccurred()) 124 } 125 126 func TestVppArpTerminationTableEntryError(t *testing.T) { 127 ctx, bdHandler, _ := bdTestSetup(t) 128 defer ctx.TeardownTestCtx() 129 130 ctx.MockVpp.MockReply(&vpp_l2.BdIPMacAddDelReply{ 131 Retval: 1, 132 }) 133 134 err := bdHandler.AddArpTerminationTableEntry(4, "FF:FF:FF:FF:FF:FF", "192.168.4.4") 135 Expect(err).Should(HaveOccurred()) 136 137 ctx.MockVpp.MockReply(&vpp_l2.BridgeDomainAddDelReply{}) 138 139 err = bdHandler.RemoveArpTerminationTableEntry(4, "FF:FF:FF:FF:FF:FF", "192.168.4.4") 140 Expect(err).Should(HaveOccurred()) 141 }