go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2210/rdma_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  	vpp_ifs "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/interface"
    23  	vpp_rdma "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/rdma"
    24  
    25  	ifs "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    26  )
    27  
    28  func TestAddRdmaInterface(t *testing.T) {
    29  	ctx, ifHandler := ifTestSetup(t)
    30  	defer ctx.TeardownTestCtx()
    31  
    32  	ctx.MockVpp.MockReply(&vpp_rdma.RdmaCreateV3Reply{
    33  		SwIfIndex: 2,
    34  	})
    35  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
    36  
    37  	const qSize = 4096
    38  	const qNum = 4
    39  	rdmaLink := &ifs.RDMALink{
    40  		HostIfName: "ens4",
    41  		Mode:       ifs.RDMALink_DV,
    42  		RxqNum:     qNum,
    43  		RxqSize:    qSize,
    44  		TxqSize:    qSize,
    45  	}
    46  
    47  	index, err := ifHandler.AddRdmaInterface(ctx.Context, "rdma1", rdmaLink)
    48  	Expect(err).To(BeNil())
    49  	Expect(index).To(Equal(uint32(2)))
    50  	var msgCheck bool
    51  	for _, msg := range ctx.MockChannel.Msgs {
    52  		vppMsg, ok := msg.(*vpp_rdma.RdmaCreateV3)
    53  		if ok {
    54  			Expect(vppMsg.HostIf).To(BeEquivalentTo("ens4"))
    55  			Expect(vppMsg.Name).To(BeEquivalentTo("rdma1"))
    56  			Expect(vppMsg.Mode).To(BeEquivalentTo(vpp_rdma.RDMA_API_MODE_DV))
    57  			Expect(vppMsg.RxqNum).To(BeEquivalentTo(qNum))
    58  			Expect(vppMsg.RxqSize).To(BeEquivalentTo(qSize))
    59  			Expect(vppMsg.TxqSize).To(BeEquivalentTo(qSize))
    60  			msgCheck = true
    61  		}
    62  	}
    63  	Expect(msgCheck).To(BeTrue())
    64  }
    65  
    66  func TestDeleteRdmaInterface(t *testing.T) {
    67  	ctx, ifHandler := ifTestSetup(t)
    68  	defer ctx.TeardownTestCtx()
    69  	ctx.MockVpp.MockReply(&vpp_rdma.RdmaDeleteReply{})
    70  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
    71  
    72  	err := ifHandler.DeleteRdmaInterface(ctx.Context, "rdma1", 2)
    73  	Expect(err).To(BeNil())
    74  
    75  	var msgCheck bool
    76  	for _, msg := range ctx.MockChannel.Msgs {
    77  		vppMsg, ok := msg.(*vpp_rdma.RdmaDelete)
    78  		if ok {
    79  			Expect(vppMsg.SwIfIndex).To(BeEquivalentTo(2))
    80  			msgCheck = true
    81  		}
    82  	}
    83  	Expect(msgCheck).To(BeTrue())
    84  }