go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2101/rx_placement_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  
    22  	vpp_ifs "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/interface"
    23  	ifs "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    24  )
    25  
    26  func TestSetRxPlacementForWorker(t *testing.T) {
    27  	ctx, ifHandler := ifTestSetup(t)
    28  	defer ctx.TeardownTestCtx()
    29  
    30  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetRxPlacementReply{})
    31  
    32  	err := ifHandler.SetRxPlacement(1, &ifs.Interface_RxPlacement{
    33  		Queue:      1,
    34  		Worker:     2,
    35  		MainThread: false,
    36  	})
    37  
    38  	Expect(err).To(BeNil())
    39  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ifs.SwInterfaceSetRxPlacement)
    40  	Expect(ok).To(BeTrue())
    41  	Expect(vppMsg.SwIfIndex).To(BeEquivalentTo(1))
    42  	Expect(vppMsg.QueueID).To(BeEquivalentTo(1))
    43  	Expect(vppMsg.WorkerID).To(BeEquivalentTo(uint32(2)))
    44  	Expect(vppMsg.IsMain).To(BeFalse())
    45  }
    46  
    47  func TestSetRxPlacementForMainThread(t *testing.T) {
    48  	ctx, ifHandler := ifTestSetup(t)
    49  	defer ctx.TeardownTestCtx()
    50  
    51  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetRxPlacementReply{})
    52  
    53  	err := ifHandler.SetRxPlacement(3, &ifs.Interface_RxPlacement{
    54  		Queue:      6,
    55  		Worker:     2, // ignored on the VPP side
    56  		MainThread: true,
    57  	})
    58  
    59  	Expect(err).To(BeNil())
    60  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ifs.SwInterfaceSetRxPlacement)
    61  	Expect(ok).To(BeTrue())
    62  	Expect(vppMsg.SwIfIndex).To(BeEquivalentTo(3))
    63  	Expect(vppMsg.QueueID).To(BeEquivalentTo(6))
    64  	Expect(vppMsg.WorkerID).To(BeEquivalentTo(uint32(2)))
    65  	Expect(vppMsg.IsMain).To(BeTrue())
    66  }
    67  
    68  func TestSetRxPlacementRetval(t *testing.T) {
    69  	ctx, ifHandler := ifTestSetup(t)
    70  	defer ctx.TeardownTestCtx()
    71  
    72  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetRxPlacementReply{
    73  		Retval: 1,
    74  	})
    75  
    76  	err := ifHandler.SetRxPlacement(1, &ifs.Interface_RxPlacement{
    77  		Queue:      1,
    78  		Worker:     2,
    79  		MainThread: false,
    80  	})
    81  
    82  	Expect(err).ToNot(BeNil())
    83  }
    84  
    85  func TestSetRxPlacementError(t *testing.T) {
    86  	ctx, ifHandler := ifTestSetup(t)
    87  	defer ctx.TeardownTestCtx()
    88  
    89  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetRxPlacement{})
    90  
    91  	err := ifHandler.SetRxPlacement(1, &ifs.Interface_RxPlacement{
    92  		Queue:      1,
    93  		Worker:     2,
    94  		MainThread: false,
    95  	})
    96  
    97  	Expect(err).ToNot(BeNil())
    98  }