go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2106/tap_vppcalls_test.go (about)

     1  //  Copyright (c) 2021 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 vpp2106_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/vpp2106/interface"
    23  	vpp_tapv2 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/tapv2"
    24  	ifs "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    25  )
    26  
    27  func TestAddTapInterfaceV2(t *testing.T) {
    28  	ctx, ifHandler := ifTestSetup(t)
    29  	defer ctx.TeardownTestCtx()
    30  
    31  	ctx.MockVpp.MockReply(&vpp_tapv2.TapCreateV2Reply{
    32  		SwIfIndex: 1,
    33  	})
    34  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
    35  
    36  	swIfIdx, err := ifHandler.AddTapInterface("tapIf", &ifs.TapLink{
    37  		Version:    2,
    38  		HostIfName: "hostIf",
    39  		RxRingSize: 1,
    40  		TxRingSize: 1,
    41  	})
    42  	Expect(err).To(BeNil())
    43  	Expect(swIfIdx).To(BeEquivalentTo(1))
    44  	var msgCheck bool
    45  	for _, msg := range ctx.MockChannel.Msgs {
    46  		vppMsg, ok := msg.(*vpp_tapv2.TapCreateV2)
    47  		if ok {
    48  			Expect(vppMsg.UseRandomMac).To(BeTrue())
    49  			Expect(vppMsg.HostIfName).To(BeEquivalentTo([]byte("hostIf")))
    50  			msgCheck = true
    51  		}
    52  	}
    53  	Expect(msgCheck).To(BeTrue())
    54  }
    55  
    56  func TestDeleteTapInterfaceV2(t *testing.T) {
    57  	ctx, ifHandler := ifTestSetup(t)
    58  	defer ctx.TeardownTestCtx()
    59  
    60  	ctx.MockVpp.MockReply(&vpp_tapv2.TapDeleteV2Reply{})
    61  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
    62  
    63  	err := ifHandler.DeleteTapInterface("tapIf", 1, 2)
    64  	Expect(err).To(BeNil())
    65  	var msgCheck bool
    66  	for _, msg := range ctx.MockChannel.Msgs {
    67  		vppMsg, ok := msg.(*vpp_tapv2.TapDeleteV2)
    68  		if ok {
    69  			Expect(vppMsg.SwIfIndex).To(BeEquivalentTo(1))
    70  			msgCheck = true
    71  		}
    72  	}
    73  	Expect(msgCheck).To(BeTrue())
    74  }