go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l2plugin/vppcalls/vpp2101/xconnect_vppcalls_test.go (about) 1 // Copyright (c) 2019 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 vpp2101_test 16 17 import ( 18 "testing" 19 20 . "github.com/onsi/gomega" 21 govppapi "go.fd.io/govpp/api" 22 "go.ligato.io/cn-infra/v2/logging/logrus" 23 24 vpp_l2 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/l2" 25 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx" 26 "go.ligato.io/vpp-agent/v3/plugins/vpp/l2plugin/vppcalls" 27 vpp2101 "go.ligato.io/vpp-agent/v3/plugins/vpp/l2plugin/vppcalls/vpp2101" 28 "go.ligato.io/vpp-agent/v3/plugins/vpp/vppmock" 29 ) 30 31 var inTestDataXConnect = []struct { 32 receiveIfaceIndex string 33 transmitIfaceIndex string 34 message govppapi.Message 35 }{ 36 {"rxIf1", "txIf1", &vpp_l2.SwInterfaceSetL2XconnectReply{}}, 37 {"rxIf2", "txIf2", &vpp_l2.SwInterfaceSetL2XconnectReply{Retval: 1}}, 38 {"rxIf2", "txIf2", &vpp_l2.BridgeDomainAddDelReply{}}, 39 } 40 41 var outTestDataXConnect = []struct { 42 outData *vpp_l2.SwInterfaceSetL2Xconnect 43 isResultOk bool 44 }{ 45 {&vpp_l2.SwInterfaceSetL2Xconnect{ 46 RxSwIfIndex: 100, 47 TxSwIfIndex: 200, 48 }, true}, 49 {&vpp_l2.SwInterfaceSetL2Xconnect{ 50 RxSwIfIndex: 101, 51 TxSwIfIndex: 201, 52 }, false}, 53 {&vpp_l2.SwInterfaceSetL2Xconnect{ 54 RxSwIfIndex: 101, 55 TxSwIfIndex: 201, 56 }, false}, 57 } 58 59 /** 60 scenarios: 61 - enabling xconnect 62 - ok 63 - retvalue != 0 64 - returned VPP message != what is expected 65 */ 66 // TestVppSetL2XConnect tests VppSetL2XConnect method 67 func TestVppSetL2XConnect(t *testing.T) { 68 ctx, xcHandler, ifaceIdx := xcTestSetup(t) 69 defer ctx.TeardownTestCtx() 70 71 ifaceIdx.Put("rxIf1", &ifaceidx.IfaceMetadata{SwIfIndex: 100}) 72 ifaceIdx.Put("rxIf2", &ifaceidx.IfaceMetadata{SwIfIndex: 101}) 73 ifaceIdx.Put("txIf1", &ifaceidx.IfaceMetadata{SwIfIndex: 200}) 74 ifaceIdx.Put("txIf2", &ifaceidx.IfaceMetadata{SwIfIndex: 201}) 75 76 for i := 0; i < len(inTestDataXConnect); i++ { 77 ctx.MockVpp.MockReply(inTestDataXConnect[i].message) 78 err := xcHandler.AddL2XConnect(inTestDataXConnect[i].receiveIfaceIndex, 79 inTestDataXConnect[i].transmitIfaceIndex) 80 81 if outTestDataXConnect[i].isResultOk { 82 Expect(err).To(BeNil()) 83 } else { 84 Expect(err).NotTo(BeNil()) 85 } 86 outTestDataXConnect[i].outData.Enable = true 87 Expect(ctx.MockChannel.Msg).To(Equal(outTestDataXConnect[i].outData)) 88 } 89 } 90 91 /** 92 scenarios: 93 - disabling xconnect 94 - ok 95 - retvalue != 0 96 - returned VPP message != what is expected 97 */ 98 // TestVppUnsetL2XConnect tests VppUnsetL2XConnect method 99 func TestVppUnsetL2XConnect(t *testing.T) { 100 ctx, xcHandler, ifaceIdx := xcTestSetup(t) 101 defer ctx.TeardownTestCtx() 102 103 ifaceIdx.Put("rxIf1", &ifaceidx.IfaceMetadata{SwIfIndex: 100}) 104 ifaceIdx.Put("rxIf2", &ifaceidx.IfaceMetadata{SwIfIndex: 101}) 105 ifaceIdx.Put("txIf1", &ifaceidx.IfaceMetadata{SwIfIndex: 200}) 106 ifaceIdx.Put("txIf2", &ifaceidx.IfaceMetadata{SwIfIndex: 201}) 107 108 for i := 0; i < len(inTestDataXConnect); i++ { 109 ctx.MockVpp.MockReply(inTestDataXConnect[i].message) 110 err := xcHandler.DeleteL2XConnect(inTestDataXConnect[i].receiveIfaceIndex, 111 inTestDataXConnect[i].transmitIfaceIndex) 112 113 if outTestDataXConnect[i].isResultOk { 114 Expect(err).To(BeNil()) 115 } else { 116 Expect(err).NotTo(BeNil()) 117 } 118 outTestDataXConnect[i].outData.Enable = false 119 Expect(ctx.MockChannel.Msg).To(Equal(outTestDataXConnect[i].outData)) 120 } 121 } 122 123 func xcTestSetup(t *testing.T) (*vppmock.TestCtx, vppcalls.XConnectVppAPI, ifaceidx.IfaceMetadataIndexRW) { 124 ctx := vppmock.SetupTestCtx(t) 125 log := logrus.NewLogger("test-log") 126 ifaceIdx := ifaceidx.NewIfaceIndex(log, "xc-if-idx") 127 xcHandler := vpp2101.NewL2VppHandler(ctx.MockChannel, ifaceIdx, nil, log) 128 return ctx, xcHandler, ifaceIdx 129 }