go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2106/arp_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_test
    16  
    17  import (
    18  	"testing"
    19  
    20  	. "github.com/onsi/gomega"
    21  	"go.ligato.io/cn-infra/v2/logging/logrus"
    22  
    23  	vpp_ip_neighbor "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/ip_neighbor"
    24  	"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx"
    25  	"go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vppcalls"
    26  	vpp2106 "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vppcalls/vpp2106"
    27  	"go.ligato.io/vpp-agent/v3/plugins/vpp/vppmock"
    28  	l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3"
    29  )
    30  
    31  var arpEntries = []*l3.ARPEntry{
    32  	{
    33  		Interface:   "if1",
    34  		IpAddress:   "192.168.10.21",
    35  		PhysAddress: "59:6C:45:59:8E:BD",
    36  		Static:      true,
    37  	},
    38  	{
    39  		Interface:   "if1",
    40  		IpAddress:   "192.168.10.22",
    41  		PhysAddress: "6C:45:59:59:8E:BD",
    42  		Static:      false,
    43  	},
    44  	{
    45  		Interface:   "if1",
    46  		IpAddress:   "dead::1",
    47  		PhysAddress: "8E:BD:6C:45:59:59",
    48  		Static:      false,
    49  	},
    50  }
    51  
    52  // Test adding of ARP
    53  func TestAddArp(t *testing.T) {
    54  	ctx, ifIndexes, arpHandler := arpTestSetup(t)
    55  	defer ctx.TeardownTestCtx()
    56  
    57  	ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 1})
    58  
    59  	ctx.MockVpp.MockReply(&vpp_ip_neighbor.IPNeighborAddDelReply{})
    60  	err := arpHandler.VppAddArp(arpEntries[0])
    61  	Expect(err).To(Succeed())
    62  	ctx.MockVpp.MockReply(&vpp_ip_neighbor.IPNeighborAddDelReply{})
    63  	err = arpHandler.VppAddArp(arpEntries[1])
    64  	Expect(err).To(Succeed())
    65  	ctx.MockVpp.MockReply(&vpp_ip_neighbor.IPNeighborAddDelReply{})
    66  	err = arpHandler.VppAddArp(arpEntries[2])
    67  	Expect(err).To(Succeed())
    68  
    69  	ctx.MockVpp.MockReply(&vpp_ip_neighbor.IPNeighborAddDelReply{Retval: 1})
    70  	err = arpHandler.VppAddArp(arpEntries[0])
    71  	Expect(err).NotTo(BeNil())
    72  }
    73  
    74  // Test deleting of ARP
    75  func TestDelArp(t *testing.T) {
    76  	ctx, ifIndexes, arpHandler := arpTestSetup(t)
    77  	defer ctx.TeardownTestCtx()
    78  
    79  	ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 1})
    80  
    81  	ctx.MockVpp.MockReply(&vpp_ip_neighbor.IPNeighborAddDelReply{})
    82  	err := arpHandler.VppDelArp(arpEntries[0])
    83  	Expect(err).To(Succeed())
    84  }
    85  
    86  func arpTestSetup(t *testing.T) (*vppmock.TestCtx, ifaceidx.IfaceMetadataIndexRW, vppcalls.ArpVppAPI) {
    87  	ctx := vppmock.SetupTestCtx(t)
    88  	log := logrus.NewLogger("test-log")
    89  	ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test"), "test")
    90  	arpHandler := vpp2106.NewArpVppHandler(ctx.MockChannel, ifIndexes, log)
    91  	return ctx, ifIndexes, arpHandler
    92  }