go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/aclplugin/vppcalls/vpp2106/interfaces_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
    16  
    17  import (
    18  	"testing"
    19  
    20  	. "github.com/onsi/gomega"
    21  
    22  	vpp_acl "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/acl"
    23  )
    24  
    25  // Test assignment of IP acl rule to given interface
    26  func TestRequestSetACLToInterfaces(t *testing.T) {
    27  	ctx := setupACLTest(t)
    28  	defer ctx.teardownACLTest()
    29  
    30  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceListDetails{
    31  		SwIfIndex: 0,
    32  		Count:     1,
    33  		NInput:    1,
    34  		Acls:      []uint32{0, 1},
    35  	})
    36  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceSetACLListReply{})
    37  	err := ctx.aclHandler.SetACLToInterfacesAsIngress(0, []uint32{0})
    38  	Expect(err).To(BeNil())
    39  
    40  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceListDetails{
    41  		SwIfIndex: 0,
    42  		Count:     1,
    43  		NInput:    1,
    44  		Acls:      []uint32{0, 1},
    45  	})
    46  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceSetACLListReply{})
    47  	err = ctx.aclHandler.SetACLToInterfacesAsEgress(0, []uint32{0})
    48  	Expect(err).To(BeNil())
    49  
    50  	// error cases
    51  
    52  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceSetACLListReply{})
    53  	err = ctx.aclHandler.SetACLToInterfacesAsIngress(0, []uint32{0})
    54  	Expect(err).To(Not(BeNil()))
    55  
    56  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceListDetails{
    57  		SwIfIndex: 0,
    58  		Count:     1,
    59  		NInput:    1,
    60  		Acls:      []uint32{0, 1},
    61  	})
    62  	ctx.MockVpp.MockReply(&vpp_acl.MacipACLAddReplaceReply{})
    63  	err = ctx.aclHandler.SetACLToInterfacesAsIngress(0, []uint32{0})
    64  	Expect(err).To(Not(BeNil()))
    65  
    66  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceListDetails{
    67  		SwIfIndex: 0,
    68  		Count:     1,
    69  		NInput:    1,
    70  		Acls:      []uint32{0, 1},
    71  	})
    72  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceSetACLListReply{Retval: -1})
    73  	err = ctx.aclHandler.SetACLToInterfacesAsIngress(0, []uint32{0})
    74  	Expect(err).To(Not(BeNil()))
    75  }
    76  
    77  // Test deletion of IP acl rule from given interface
    78  func TestRequestRemoveInterfacesFromACL(t *testing.T) {
    79  	ctx := setupACLTest(t)
    80  	defer ctx.teardownACLTest()
    81  
    82  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceListDetails{
    83  		SwIfIndex: 0,
    84  		Count:     1,
    85  		NInput:    1,
    86  		Acls:      []uint32{0, 1},
    87  	})
    88  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceSetACLListReply{})
    89  	err := ctx.aclHandler.RemoveACLFromInterfacesAsIngress(0, []uint32{0})
    90  	Expect(err).To(BeNil())
    91  
    92  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceListDetails{
    93  		SwIfIndex: 0,
    94  		Count:     1,
    95  		NInput:    1,
    96  		Acls:      []uint32{0, 1},
    97  	})
    98  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceSetACLListReply{})
    99  	err = ctx.aclHandler.RemoveACLFromInterfacesAsEgress(0, []uint32{0})
   100  	Expect(err).To(BeNil())
   101  
   102  	// error cases
   103  
   104  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceSetACLListReply{})
   105  	err = ctx.aclHandler.RemoveACLFromInterfacesAsEgress(0, []uint32{0})
   106  	Expect(err).To(Not(BeNil()))
   107  
   108  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceListDetails{
   109  		SwIfIndex: 0,
   110  		Count:     1,
   111  		NInput:    1,
   112  		Acls:      []uint32{0, 1},
   113  	})
   114  	ctx.MockVpp.MockReply(&vpp_acl.MacipACLAddReplaceReply{})
   115  	err = ctx.aclHandler.RemoveACLFromInterfacesAsEgress(0, []uint32{0})
   116  	Expect(err).To(Not(BeNil()))
   117  
   118  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceListDetails{
   119  		SwIfIndex: 0,
   120  		Count:     1,
   121  		NInput:    1,
   122  		Acls:      []uint32{0, 1},
   123  	})
   124  	ctx.MockVpp.MockReply(&vpp_acl.ACLInterfaceSetACLListReply{Retval: -1})
   125  	err = ctx.aclHandler.RemoveACLFromInterfacesAsEgress(0, []uint32{0})
   126  	Expect(err).To(Not(BeNil()))
   127  }
   128  
   129  // Test assignment of MACIP acl rule to given interface
   130  func TestSetMacIPAclToInterface(t *testing.T) {
   131  	ctx := setupACLTest(t)
   132  	defer ctx.teardownACLTest()
   133  
   134  	ctx.MockVpp.MockReply(&vpp_acl.MacipACLInterfaceAddDelReply{})
   135  	err := ctx.aclHandler.SetMACIPACLToInterfaces(0, []uint32{0})
   136  	Expect(err).To(BeNil())
   137  
   138  	// error cases
   139  
   140  	ctx.MockVpp.MockReply(&vpp_acl.MacipACLAddReplaceReply{})
   141  	err = ctx.aclHandler.SetMACIPACLToInterfaces(0, []uint32{0})
   142  	Expect(err).To(Not(BeNil()))
   143  
   144  	ctx.MockVpp.MockReply(&vpp_acl.MacipACLInterfaceAddDelReply{Retval: -1})
   145  	err = ctx.aclHandler.SetMACIPACLToInterfaces(0, []uint32{0})
   146  	Expect(err).To(Not(BeNil()))
   147  }
   148  
   149  // Test deletion of MACIP acl rule from given interface
   150  func TestRemoveMacIPIngressACLFromInterfaces(t *testing.T) {
   151  	ctx := setupACLTest(t)
   152  	defer ctx.teardownACLTest()
   153  
   154  	ctx.MockVpp.MockReply(&vpp_acl.MacipACLInterfaceAddDelReply{})
   155  	err := ctx.aclHandler.RemoveMACIPACLFromInterfaces(1, []uint32{0})
   156  	Expect(err).To(BeNil())
   157  
   158  	// error cases
   159  
   160  	ctx.MockVpp.MockReply(&vpp_acl.MacipACLAddReplaceReply{})
   161  	err = ctx.aclHandler.RemoveMACIPACLFromInterfaces(0, []uint32{0})
   162  	Expect(err).To(Not(BeNil()))
   163  
   164  	ctx.MockVpp.MockReply(&vpp_acl.MacipACLInterfaceAddDelReply{Retval: -1})
   165  	err = ctx.aclHandler.RemoveMACIPACLFromInterfaces(0, []uint32{0})
   166  	Expect(err).To(Not(BeNil()))
   167  }