go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l2plugin/vppcalls/vpp2202/dump_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 vpp2202_test 16 17 import ( 18 "testing" 19 20 . "github.com/onsi/gomega" 21 govppapi "go.fd.io/govpp/api" 22 23 "go.ligato.io/vpp-agent/v3/pkg/idxvpp" 24 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/ethernet_types" 25 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/interface_types" 26 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/ip_types" 27 vpp_l2 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/l2" 28 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/memclnt" 29 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx" 30 "go.ligato.io/vpp-agent/v3/plugins/vpp/l2plugin/vppcalls" 31 "go.ligato.io/vpp-agent/v3/plugins/vpp/vppmock" 32 l2 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l2" 33 ) 34 35 var testDataInMessagesBDs = []govppapi.Message{ 36 &vpp_l2.BridgeDomainDetails{ 37 BdID: 4, 38 Flood: true, UuFlood: true, Forward: true, Learn: true, ArpTerm: true, MacAge: 140, 39 SwIfDetails: []vpp_l2.BridgeDomainSwIf{ 40 {SwIfIndex: 5}, 41 {SwIfIndex: 7}, 42 }, 43 }, 44 &vpp_l2.BridgeDomainDetails{ 45 BdID: 5, 46 Flood: false, UuFlood: false, Forward: false, Learn: false, ArpTerm: false, MacAge: 141, 47 SwIfDetails: []vpp_l2.BridgeDomainSwIf{ 48 {SwIfIndex: 5}, 49 {SwIfIndex: 8}, 50 }, 51 }, 52 } 53 54 var testDataOutMessage = []*vppcalls.BridgeDomainDetails{ 55 { 56 Bd: &l2.BridgeDomain{ 57 Flood: true, 58 UnknownUnicastFlood: true, 59 Forward: true, 60 Learn: true, 61 ArpTermination: true, 62 MacAge: 140, 63 Interfaces: []*l2.BridgeDomain_Interface{ 64 { 65 Name: "if1", 66 }, 67 { 68 Name: "if2", 69 }, 70 }, 71 }, 72 Meta: &vppcalls.BridgeDomainMeta{ 73 BdID: 4, 74 }, 75 }, { 76 Bd: &l2.BridgeDomain{ 77 Flood: false, 78 UnknownUnicastFlood: false, 79 Forward: false, 80 Learn: false, 81 ArpTermination: false, 82 MacAge: 141, 83 Interfaces: []*l2.BridgeDomain_Interface{ 84 { 85 Name: "if1", 86 }, 87 { 88 Name: "if3", 89 }, 90 }, 91 ArpTerminationTable: []*l2.BridgeDomain_ArpTerminationEntry{ 92 { 93 IpAddress: "192.168.0.1", 94 PhysAddress: "aa:aa:aa:aa:aa:aa", 95 }, 96 }, 97 }, 98 Meta: &vppcalls.BridgeDomainMeta{ 99 BdID: 5, 100 }, 101 }, 102 } 103 104 // TestDumpBridgeDomains tests DumpBridgeDomains method 105 func TestDumpBridgeDomains(t *testing.T) { 106 ctx, bdHandler, ifIndexes := bdTestSetup(t) 107 defer ctx.TeardownTestCtx() 108 109 ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 5}) 110 ifIndexes.Put("if2", &ifaceidx.IfaceMetadata{SwIfIndex: 7}) 111 112 ctx.MockReplies([]*vppmock.HandleReplies{ 113 { 114 Name: (&vpp_l2.BdIPMacDump{}).GetMessageName(), 115 Ping: true, 116 Message: &vpp_l2.BdIPMacDetails{}, 117 }, 118 { 119 Name: (&vpp_l2.BridgeDomainDump{}).GetMessageName(), 120 Ping: true, 121 Message: testDataInMessagesBDs[0], 122 }, 123 }) 124 125 bridgeDomains, err := bdHandler.DumpBridgeDomains() 126 127 Expect(err).To(BeNil()) 128 Expect(bridgeDomains).To(HaveLen(1)) 129 Expect(bridgeDomains[0]).To(Equal(testDataOutMessage[0])) 130 131 ctx.MockVpp.MockReply(&vpp_l2.BridgeDomainAddDelReply{}) 132 _, err = bdHandler.DumpBridgeDomains() 133 Expect(err).Should(HaveOccurred()) 134 } 135 136 // TestDumpBridgeDomains tests DumpBridgeDomains method 137 func TestDumpBridgeDomainsWithARP(t *testing.T) { 138 ctx, bdHandler, ifIndexes := bdTestSetup(t) 139 defer ctx.TeardownTestCtx() 140 141 ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 5}) 142 ifIndexes.Put("if3", &ifaceidx.IfaceMetadata{SwIfIndex: 8}) 143 144 ctx.MockReplies([]*vppmock.HandleReplies{ 145 { 146 Name: (&vpp_l2.BdIPMacDump{}).GetMessageName(), 147 Ping: true, 148 Message: &vpp_l2.BdIPMacDetails{ 149 Entry: vpp_l2.BdIPMac{ 150 BdID: 5, 151 IP: ip_types.Address{ 152 Af: ip_types.ADDRESS_IP4, 153 Un: ip_types.AddressUnionIP4( 154 ip_types.IP4Address{192, 168, 0, 1}, 155 ), 156 }, 157 Mac: ethernet_types.MacAddress{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, 158 }, 159 }, 160 }, 161 { 162 Name: (&vpp_l2.BridgeDomainDump{}).GetMessageName(), 163 Ping: true, 164 Message: testDataInMessagesBDs[1], 165 }, 166 }) 167 168 bridgeDomains, err := bdHandler.DumpBridgeDomains() 169 170 Expect(err).To(BeNil()) 171 Expect(bridgeDomains).To(HaveLen(1)) 172 Expect(bridgeDomains[0]).To(Equal(testDataOutMessage[1])) 173 174 ctx.MockVpp.MockReply(&vpp_l2.BridgeDomainAddDelReply{}) 175 _, err = bdHandler.DumpBridgeDomains() 176 Expect(err).Should(HaveOccurred()) 177 } 178 179 var testDataInMessagesFIBs = []govppapi.Message{ 180 &vpp_l2.L2FibTableDetails{ 181 BdID: 10, 182 Mac: ethernet_types.MacAddress{0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, 183 BviMac: false, SwIfIndex: ^interface_types.InterfaceIndex(0), FilterMac: true, StaticMac: false, 184 }, 185 &vpp_l2.L2FibTableDetails{ 186 BdID: 20, 187 Mac: ethernet_types.MacAddress{0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB}, 188 BviMac: true, SwIfIndex: 1, FilterMac: false, StaticMac: true, 189 }, 190 } 191 192 var testDataOutFIBs = []*vppcalls.FibTableDetails{ 193 { 194 Fib: &l2.FIBEntry{ 195 PhysAddress: "aa:aa:aa:aa:aa:aa", 196 BridgeDomain: "bd1", 197 Action: l2.FIBEntry_DROP, 198 StaticConfig: false, 199 BridgedVirtualInterface: false, 200 OutgoingInterface: "", 201 }, 202 Meta: &vppcalls.FibMeta{ 203 BdID: 10, 204 IfIdx: ^uint32(0), 205 }, 206 }, 207 { 208 Fib: &l2.FIBEntry{ 209 PhysAddress: "bb:bb:bb:bb:bb:bb", 210 BridgeDomain: "bd2", 211 Action: l2.FIBEntry_FORWARD, 212 StaticConfig: true, 213 BridgedVirtualInterface: true, 214 OutgoingInterface: "if1", 215 }, 216 Meta: &vppcalls.FibMeta{ 217 BdID: 20, 218 IfIdx: 1, 219 }, 220 }, 221 } 222 223 // Scenario: 224 // - 2 FIB entries in VPP 225 // TestDumpFIBTableEntries tests DumpFIBTableEntries method 226 func TestDumpFIBTableEntries(t *testing.T) { 227 ctx, fibHandler, ifIndexes, bdIndexes := fibTestSetup(t) 228 defer ctx.TeardownTestCtx() 229 230 ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 1}) 231 bdIndexes.Put("bd1", &idxvpp.OnlyIndex{Index: 10}) 232 bdIndexes.Put("bd2", &idxvpp.OnlyIndex{Index: 20}) 233 234 ctx.MockVpp.MockReply(testDataInMessagesFIBs...) 235 ctx.MockVpp.MockReply(&memclnt.ControlPingReply{}) 236 237 fibTable, err := fibHandler.DumpL2FIBs() 238 Expect(err).To(BeNil()) 239 Expect(fibTable).To(HaveLen(2)) 240 Expect(fibTable["aa:aa:aa:aa:aa:aa"]).To(Equal(testDataOutFIBs[0])) 241 Expect(fibTable["bb:bb:bb:bb:bb:bb"]).To(Equal(testDataOutFIBs[1])) 242 243 ctx.MockVpp.MockReply(&vpp_l2.BridgeDomainAddDelReply{}) 244 _, err = fibHandler.DumpL2FIBs() 245 Expect(err).Should(HaveOccurred()) 246 } 247 248 var testDataInXConnect = []govppapi.Message{ 249 &vpp_l2.L2XconnectDetails{ 250 RxSwIfIndex: 1, 251 TxSwIfIndex: 2, 252 }, 253 &vpp_l2.L2XconnectDetails{ 254 RxSwIfIndex: 3, 255 TxSwIfIndex: 4, 256 }, 257 } 258 259 var testDataOutXconnect = []*vppcalls.XConnectDetails{ 260 { 261 Xc: &l2.XConnectPair{ 262 ReceiveInterface: "if1", 263 TransmitInterface: "if2", 264 }, 265 Meta: &vppcalls.XcMeta{ 266 ReceiveInterfaceSwIfIdx: 1, 267 TransmitInterfaceSwIfIdx: 2, 268 }, 269 }, 270 { 271 Xc: &l2.XConnectPair{ 272 ReceiveInterface: "if3", 273 TransmitInterface: "if4", 274 }, 275 Meta: &vppcalls.XcMeta{ 276 ReceiveInterfaceSwIfIdx: 3, 277 TransmitInterfaceSwIfIdx: 4, 278 }, 279 }, 280 } 281 282 // Scenario: 283 // - 2 Xconnect entries in VPP 284 // TestDumpXConnectPairs tests DumpXConnectPairs method 285 func TestDumpXConnectPairs(t *testing.T) { 286 ctx, xcHandler, ifIndex := xcTestSetup(t) 287 defer ctx.TeardownTestCtx() 288 289 ifIndex.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 1}) 290 ifIndex.Put("if2", &ifaceidx.IfaceMetadata{SwIfIndex: 2}) 291 ifIndex.Put("if3", &ifaceidx.IfaceMetadata{SwIfIndex: 3}) 292 ifIndex.Put("if4", &ifaceidx.IfaceMetadata{SwIfIndex: 4}) 293 294 ctx.MockVpp.MockReply(testDataInXConnect...) 295 ctx.MockVpp.MockReply(&memclnt.ControlPingReply{}) 296 297 xConnectPairs, err := xcHandler.DumpXConnectPairs() 298 299 Expect(err).To(BeNil()) 300 Expect(xConnectPairs).To(HaveLen(2)) 301 Expect(xConnectPairs[1]).To(Equal(testDataOutXconnect[0])) 302 Expect(xConnectPairs[3]).To(Equal(testDataOutXconnect[1])) 303 304 ctx.MockVpp.MockReply(&vpp_l2.BridgeDomainAddDelReply{}) 305 _, err = xcHandler.DumpXConnectPairs() 306 Expect(err).Should(HaveOccurred()) 307 }