go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2202/vmxnet3_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 22 vpp_ifs "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/interface" 23 vpp_vmxnet3 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/vmxnet3" 24 ifs "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces" 25 ) 26 27 func TestAddVmxNet3Interface(t *testing.T) { 28 ctx, ifHandler := ifTestSetup(t) 29 defer ctx.TeardownTestCtx() 30 31 ctx.MockVpp.MockReply(&vpp_vmxnet3.Vmxnet3CreateReply{ 32 SwIfIndex: 1, 33 }) 34 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{}) 35 36 swIfIdx, err := ifHandler.AddVmxNet3("vmxnet3-face/be/1c/4", &ifs.VmxNet3Link{ 37 EnableElog: true, 38 RxqSize: 2048, 39 TxqSize: 512, 40 }) 41 Expect(err).To(BeNil()) 42 Expect(swIfIdx).To(BeEquivalentTo(1)) 43 var msgCheck bool 44 for _, msg := range ctx.MockChannel.Msgs { 45 vppMsg, ok := msg.(*vpp_vmxnet3.Vmxnet3Create) 46 if ok { 47 Expect(vppMsg.PciAddr).To(BeEquivalentTo(2629761742)) 48 Expect(vppMsg.EnableElog).To(BeEquivalentTo(1)) 49 Expect(vppMsg.RxqSize).To(BeEquivalentTo(2048)) 50 Expect(vppMsg.TxqSize).To(BeEquivalentTo(512)) 51 msgCheck = true 52 } 53 } 54 Expect(msgCheck).To(BeTrue()) 55 } 56 57 func TestAddVmxNet3InterfacePCIErr(t *testing.T) { 58 ctx, ifHandler := ifTestSetup(t) 59 defer ctx.TeardownTestCtx() 60 61 ctx.MockVpp.MockReply(&vpp_vmxnet3.Vmxnet3CreateReply{ 62 SwIfIndex: 1, 63 }) 64 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{}) 65 66 // Name in incorrect format 67 _, err := ifHandler.AddVmxNet3("vmxnet3-a/14/19", nil) 68 Expect(err).ToNot(BeNil()) 69 } 70 71 func TestAddVmxNet3InterfaceRetval(t *testing.T) { 72 ctx, ifHandler := ifTestSetup(t) 73 defer ctx.TeardownTestCtx() 74 75 ctx.MockVpp.MockReply(&vpp_vmxnet3.Vmxnet3CreateReply{ 76 Retval: 1, 77 }) 78 79 _, err := ifHandler.AddVmxNet3("vmxnet3-a/14/19/1e", nil) 80 Expect(err).ToNot(BeNil()) 81 } 82 83 func TestDelVmxNet3Interface(t *testing.T) { 84 ctx, ifHandler := ifTestSetup(t) 85 defer ctx.TeardownTestCtx() 86 87 ctx.MockVpp.MockReply(&vpp_vmxnet3.Vmxnet3DeleteReply{ 88 Retval: 0, 89 }) 90 ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{}) 91 92 err := ifHandler.DeleteVmxNet3("vmxnet3-a/14/19/1e", 1) 93 Expect(err).To(BeNil()) 94 var msgCheck bool 95 for _, msg := range ctx.MockChannel.Msgs { 96 vppMsg, ok := msg.(*vpp_vmxnet3.Vmxnet3Delete) 97 if ok { 98 Expect(vppMsg.SwIfIndex).To(BeEquivalentTo(1)) 99 msgCheck = true 100 } 101 } 102 Expect(msgCheck).To(BeTrue()) 103 } 104 105 func TestDelVmxNet3InterfaceRetval(t *testing.T) { 106 ctx, ifHandler := ifTestSetup(t) 107 defer ctx.TeardownTestCtx() 108 109 ctx.MockVpp.MockReply(&vpp_vmxnet3.Vmxnet3DeleteReply{ 110 Retval: 1, 111 }) 112 113 err := ifHandler.DeleteVmxNet3("vmxnet3-a/14/19/1e", 1) 114 Expect(err).ToNot(BeNil()) 115 }