go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2210/memif_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_memif "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/memif"
    24  	ifs "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    25  )
    26  
    27  func TestAddMasterMemifInterface(t *testing.T) {
    28  	ctx, ifHandler := ifTestSetup(t)
    29  	defer ctx.TeardownTestCtx()
    30  
    31  	ctx.MockVpp.MockReply(&vpp_memif.MemifCreateReply{
    32  		SwIfIndex: 1,
    33  	})
    34  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
    35  
    36  	swIfIdx, err := ifHandler.AddMemifInterface(ctx.Context, "memif", &ifs.MemifLink{
    37  		Id:     1,
    38  		Mode:   ifs.MemifLink_IP,
    39  		Secret: "secret",
    40  		Master: true,
    41  	}, 5)
    42  
    43  	Expect(err).To(BeNil())
    44  	Expect(swIfIdx).To(BeEquivalentTo(1))
    45  	var msgCheck bool
    46  	for _, msg := range ctx.MockChannel.Msgs {
    47  		vppMsg, ok := msg.(*vpp_memif.MemifCreate)
    48  		if ok {
    49  			Expect(vppMsg.ID).To(BeEquivalentTo(1))
    50  			Expect(vppMsg.Mode).To(BeEquivalentTo(1))
    51  			Expect(vppMsg.Role).To(BeEquivalentTo(0))
    52  			Expect(vppMsg.SocketID).To(BeEquivalentTo(5))
    53  			Expect(vppMsg.RxQueues).To(BeEquivalentTo(1))
    54  			Expect(vppMsg.TxQueues).To(BeEquivalentTo(1))
    55  			msgCheck = true
    56  		}
    57  	}
    58  	Expect(msgCheck).To(BeTrue())
    59  }
    60  
    61  func TestAddMasterMemifInterfaceAsSlave(t *testing.T) {
    62  	ctx, ifHandler := ifTestSetup(t)
    63  	defer ctx.TeardownTestCtx()
    64  
    65  	ctx.MockVpp.MockReply(&vpp_memif.MemifCreateReply{
    66  		SwIfIndex: 1,
    67  	})
    68  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
    69  
    70  	swIfIdx, err := ifHandler.AddMemifInterface(ctx.Context, "memif", &ifs.MemifLink{
    71  		Id:     1,
    72  		Mode:   ifs.MemifLink_IP,
    73  		Secret: "secret",
    74  		Master: false,
    75  	}, 5)
    76  
    77  	Expect(err).To(BeNil())
    78  	Expect(swIfIdx).To(BeEquivalentTo(1))
    79  	var msgCheck bool
    80  	for _, msg := range ctx.MockChannel.Msgs {
    81  		vppMsg, ok := msg.(*vpp_memif.MemifCreate)
    82  		if ok {
    83  			Expect(vppMsg.Role).To(BeEquivalentTo(1))
    84  			msgCheck = true
    85  		}
    86  	}
    87  	Expect(msgCheck).To(BeTrue())
    88  }
    89  
    90  func TestAddMasterMemifInterfaceError(t *testing.T) {
    91  	ctx, ifHandler := ifTestSetup(t)
    92  	defer ctx.TeardownTestCtx()
    93  
    94  	ctx.MockVpp.MockReply(&vpp_memif.MemifCreate{})
    95  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
    96  
    97  	_, err := ifHandler.AddMemifInterface(ctx.Context, "memif", &ifs.MemifLink{
    98  		Id:     1,
    99  		Mode:   ifs.MemifLink_IP,
   100  		Secret: "secret",
   101  		Master: false,
   102  	}, 5)
   103  
   104  	Expect(err).ToNot(BeNil())
   105  }
   106  
   107  func TestAddMasterMemifInterfaceRetval(t *testing.T) {
   108  	ctx, ifHandler := ifTestSetup(t)
   109  	defer ctx.TeardownTestCtx()
   110  
   111  	ctx.MockVpp.MockReply(&vpp_memif.MemifCreateReply{
   112  		Retval: 1,
   113  	})
   114  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
   115  
   116  	_, err := ifHandler.AddMemifInterface(ctx.Context, "memif", &ifs.MemifLink{
   117  		Id:     1,
   118  		Mode:   ifs.MemifLink_IP,
   119  		Secret: "secret",
   120  		Master: false,
   121  	}, 5)
   122  
   123  	Expect(err).ToNot(BeNil())
   124  }
   125  
   126  func TestDeleteMemifInterface(t *testing.T) {
   127  	ctx, ifHandler := ifTestSetup(t)
   128  	defer ctx.TeardownTestCtx()
   129  
   130  	ctx.MockVpp.MockReply(&vpp_memif.MemifDeleteReply{})
   131  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
   132  
   133  	err := ifHandler.DeleteMemifInterface(ctx.Context, "memif", 1)
   134  
   135  	Expect(err).To(BeNil())
   136  }
   137  
   138  func TestDeleteMemifInterfaceError(t *testing.T) {
   139  	ctx, ifHandler := ifTestSetup(t)
   140  	defer ctx.TeardownTestCtx()
   141  
   142  	ctx.MockVpp.MockReply(&vpp_memif.MemifDelete{})
   143  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
   144  
   145  	err := ifHandler.DeleteMemifInterface(ctx.Context, "memif", 1)
   146  
   147  	Expect(err).ToNot(BeNil())
   148  }
   149  
   150  func TestDeleteMemifInterfaceRetval(t *testing.T) {
   151  	ctx, ifHandler := ifTestSetup(t)
   152  	defer ctx.TeardownTestCtx()
   153  
   154  	ctx.MockVpp.MockReply(&vpp_memif.MemifDeleteReply{
   155  		Retval: 1,
   156  	})
   157  	ctx.MockVpp.MockReply(&vpp_ifs.SwInterfaceTagAddDelReply{})
   158  
   159  	err := ifHandler.DeleteMemifInterface(ctx.Context, "memif", 1)
   160  
   161  	Expect(err).ToNot(BeNil())
   162  }
   163  
   164  func TestRegisterMemifSocketFilename(t *testing.T) {
   165  	ctx, ifHandler := ifTestSetup(t)
   166  	defer ctx.TeardownTestCtx()
   167  
   168  	ctx.MockVpp.MockReply(&vpp_memif.MemifSocketFilenameAddDelReply{})
   169  
   170  	err := ifHandler.RegisterMemifSocketFilename(ctx.Context, "filename", 1)
   171  
   172  	Expect(err).To(BeNil())
   173  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_memif.MemifSocketFilenameAddDel)
   174  	Expect(ok).To(BeTrue())
   175  	Expect(vppMsg.IsAdd).To(BeTrue())
   176  	Expect(vppMsg.SocketID).To(BeEquivalentTo(1))
   177  	Expect(vppMsg.SocketFilename).To(BeEquivalentTo([]byte("filename")))
   178  }
   179  
   180  func TestRegisterMemifSocketFilenameError(t *testing.T) {
   181  	ctx, ifHandler := ifTestSetup(t)
   182  	defer ctx.TeardownTestCtx()
   183  
   184  	ctx.MockVpp.MockReply(&vpp_memif.MemifSocketFilenameAddDel{})
   185  
   186  	err := ifHandler.RegisterMemifSocketFilename(ctx.Context, "filename", 1)
   187  
   188  	Expect(err).ToNot(BeNil())
   189  }
   190  
   191  func TestRegisterMemifSocketFilenameRetval(t *testing.T) {
   192  	ctx, ifHandler := ifTestSetup(t)
   193  	defer ctx.TeardownTestCtx()
   194  
   195  	ctx.MockVpp.MockReply(&vpp_memif.MemifSocketFilenameAddDelReply{
   196  		Retval: 1,
   197  	})
   198  
   199  	err := ifHandler.RegisterMemifSocketFilename(ctx.Context, "filename", 1)
   200  
   201  	Expect(err).ToNot(BeNil())
   202  }