go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2202/ipsec_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  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/interface_types"
    23  	vpp_ipsec "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/ipsec"
    24  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/tunnel_types"
    25  	ifs "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    26  )
    27  
    28  func TestAddIPSecTunnelInterface(t *testing.T) {
    29  	ctx, ifHandler := ifTestSetup(t)
    30  	defer ctx.TeardownTestCtx()
    31  	ctx.MockVpp.MockReply(&vpp_ipsec.IpsecItfCreateReply{
    32  		SwIfIndex: 2,
    33  	})
    34  
    35  	ipSecLink := &ifs.IPSecLink{
    36  		TunnelMode: ifs.IPSecLink_POINT_TO_POINT,
    37  	}
    38  	index, err := ifHandler.AddIPSecTunnelInterface(ctx.Context, "if1", ipSecLink)
    39  	Expect(err).To(BeNil())
    40  	Expect(index).To(Equal(uint32(2)))
    41  
    42  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ipsec.IpsecItfCreate)
    43  	Expect(ok).To(BeTrue())
    44  	Expect(vppMsg).ToNot(BeNil())
    45  
    46  	itf := vpp_ipsec.IpsecItf{
    47  		Mode: tunnel_types.TunnelMode(ifs.IPSecLink_POINT_TO_POINT),
    48  	}
    49  
    50  	Expect(vppMsg.Itf).To(Equal(itf))
    51  }
    52  
    53  func TestAddIPSecTunnelInterfaceError(t *testing.T) {
    54  	ctx, ifHandler := ifTestSetup(t)
    55  	defer ctx.TeardownTestCtx()
    56  	ctx.MockVpp.MockReply(&vpp_ipsec.IpsecItfCreateReply{
    57  		SwIfIndex: 2,
    58  		Retval:    9,
    59  	})
    60  
    61  	index, err := ifHandler.AddIPSecTunnelInterface(ctx.Context, "if1", &ifs.IPSecLink{})
    62  	Expect(err).ToNot(BeNil())
    63  	Expect(index).To(Equal(uint32(0)))
    64  }
    65  
    66  func TestDeleteIPSecTunnelInterface(t *testing.T) {
    67  	ctx, ifHandler := ifTestSetup(t)
    68  	defer ctx.TeardownTestCtx()
    69  	ctx.MockVpp.MockReply(&vpp_ipsec.IpsecItfDeleteReply{})
    70  
    71  	err := ifHandler.DeleteIPSecTunnelInterface(ctx.Context, "if1", 2, &ifs.IPSecLink{})
    72  	Expect(err).To(BeNil())
    73  
    74  	vppMsg, ok := ctx.MockChannel.Msg.(*vpp_ipsec.IpsecItfDelete)
    75  	Expect(ok).To(BeTrue())
    76  	Expect(vppMsg).ToNot(BeNil())
    77  
    78  	Expect(vppMsg.SwIfIndex).To(Equal(interface_types.InterfaceIndex(2)))
    79  }
    80  
    81  func TestDeleteIPSecTunnelInterfaceError(t *testing.T) {
    82  	ctx, ifHandler := ifTestSetup(t)
    83  	defer ctx.TeardownTestCtx()
    84  	ctx.MockVpp.MockReply(&vpp_ipsec.IpsecItfDeleteReply{
    85  		Retval: 9,
    86  	})
    87  
    88  	err := ifHandler.DeleteIPSecTunnelInterface(ctx.Context, "if1", 2, &ifs.IPSecLink{})
    89  	Expect(err).ToNot(BeNil())
    90  }