go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2202/rx_mode_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  	ifs "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    24  )
    25  
    26  func TestSetRxMode(t *testing.T) {
    27  	ctx, ifHandler := ifTestSetup(t)
    28  	defer ctx.TeardownTestCtx()
    29  
    30  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetRxModeReply{})
    31  
    32  	err := ifHandler.SetRxMode(1, &ifs.Interface_RxMode{
    33  		Mode:        ifs.Interface_RxMode_DEFAULT,
    34  		Queue:       1,
    35  		DefaultMode: false,
    36  	})
    37  
    38  	Expect(err).To(BeNil())
    39  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ifs.SwInterfaceSetRxMode)
    40  	Expect(ok).To(BeTrue())
    41  	Expect(vppMsg.SwIfIndex).To(BeEquivalentTo(1))
    42  	Expect(vppMsg.Mode).To(BeEquivalentTo(4))
    43  	Expect(vppMsg.QueueID).To(BeEquivalentTo(1))
    44  	Expect(vppMsg.QueueIDValid).To(BeTrue())
    45  }
    46  
    47  func TestSetRxModeError(t *testing.T) {
    48  	ctx, ifHandler := ifTestSetup(t)
    49  	defer ctx.TeardownTestCtx()
    50  
    51  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetRxMode{})
    52  
    53  	err := ifHandler.SetRxMode(1, &ifs.Interface_RxMode{
    54  		Mode:        ifs.Interface_RxMode_DEFAULT,
    55  		Queue:       1,
    56  		DefaultMode: false,
    57  	})
    58  
    59  	Expect(err).ToNot(BeNil())
    60  }
    61  
    62  func TestSetRxModeRetval(t *testing.T) {
    63  	ctx, ifHandler := ifTestSetup(t)
    64  	defer ctx.TeardownTestCtx()
    65  
    66  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetRxModeReply{
    67  		Retval: 1,
    68  	})
    69  
    70  	err := ifHandler.SetRxMode(1, &ifs.Interface_RxMode{
    71  		Mode:        ifs.Interface_RxMode_DEFAULT,
    72  		Queue:       1,
    73  		DefaultMode: false,
    74  	})
    75  
    76  	Expect(err).ToNot(BeNil())
    77  }
    78  
    79  func TestSetDefaultRxMode(t *testing.T) {
    80  	ctx, ifHandler := ifTestSetup(t)
    81  	defer ctx.TeardownTestCtx()
    82  
    83  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceSetRxModeReply{})
    84  
    85  	err := ifHandler.SetRxMode(5, &ifs.Interface_RxMode{
    86  		Mode:        ifs.Interface_RxMode_POLLING,
    87  		Queue:       10, // ignored on the VPP side
    88  		DefaultMode: true,
    89  	})
    90  
    91  	Expect(err).To(BeNil())
    92  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ifs.SwInterfaceSetRxMode)
    93  	Expect(ok).To(BeTrue())
    94  	Expect(vppMsg.SwIfIndex).To(BeEquivalentTo(5))
    95  	Expect(vppMsg.Mode).To(BeEquivalentTo(1))
    96  	Expect(vppMsg.QueueID).To(BeEquivalentTo(10))
    97  	Expect(vppMsg.QueueIDValid).To(BeFalse())
    98  }