go.ligato.io/vpp-agent/v3@v3.5.0/tests/integration/vpp/022_ip_neighbor_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 vpp
    16  
    17  import (
    18  	"testing"
    19  
    20  	"go.ligato.io/cn-infra/v2/logging/logrus"
    21  	"google.golang.org/protobuf/encoding/prototext"
    22  
    23  	vpe_vppcalls "go.ligato.io/vpp-agent/v3/plugins/govppmux/vppcalls"
    24  	netalloc_mock "go.ligato.io/vpp-agent/v3/plugins/netalloc/mock"
    25  	"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx"
    26  	l3plugin_vppcalls "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vppcalls"
    27  	"go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vrfidx"
    28  	vpp_l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3"
    29  
    30  	_ "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin"
    31  	_ "go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin"
    32  )
    33  
    34  func TestIPNeighbor(t *testing.T) {
    35  	test := setupVPP(t)
    36  	defer test.teardownVPP()
    37  
    38  	// TODO update this test
    39  	if test.versionInfo.Release() >= "20.01" {
    40  		t.Skipf("SKIP for VPP %s>=20.01", test.versionInfo.Release())
    41  	}
    42  
    43  	vpp := vpe_vppcalls.CompatibleHandler(test.vppClient)
    44  
    45  	ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if")
    46  	vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf")
    47  	vrfIndexes.Put("vrf1-ipv4", &vrfidx.VRFMetadata{Index: 0, Protocol: vpp_l3.VrfTable_IPV4})
    48  	vrfIndexes.Put("vrf1-ipv6", &vrfidx.VRFMetadata{Index: 0, Protocol: vpp_l3.VrfTable_IPV6})
    49  
    50  	h := l3plugin_vppcalls.CompatibleL3VppHandler(
    51  		test.vppClient, ifIndexes, vrfIndexes, netalloc_mock.NewMockNetAlloc(), logrus.NewLogger("test"),
    52  	)
    53  
    54  	cliShowConfig := func() {
    55  		out, err := vpp.RunCli(test.Ctx, "show ip scan-neighbor")
    56  		if err != nil {
    57  			t.Fatal(err)
    58  		}
    59  		t.Logf("cli config:\n%v", out)
    60  	}
    61  
    62  	def := h.DefaultIPScanNeighbor()
    63  	if def == nil {
    64  		t.Fatal("default config is nil")
    65  	}
    66  
    67  	cliShowConfig()
    68  
    69  	ipneigh, err := h.GetIPScanNeighbor()
    70  	if err != nil {
    71  		t.Fatal("getting ip neighbor config failed:", err)
    72  	}
    73  	t.Logf("dump config:\n%+v", prototext.Format(ipneigh))
    74  	if ipneigh.Mode != vpp_l3.IPScanNeighbor_DISABLED {
    75  		t.Fatal("expected Mode to be DISABLED")
    76  	}
    77  
    78  	if err := h.SetIPScanNeighbor(&vpp_l3.IPScanNeighbor{
    79  		Mode:           vpp_l3.IPScanNeighbor_IPV4,
    80  		MaxProcTime:    20,
    81  		MaxUpdate:      0, // MaxUpdate will be set to 10
    82  		ScanInterval:   1,
    83  		ScanIntDelay:   1,
    84  		StaleThreshold: 4,
    85  	}); err != nil {
    86  		t.Fatal(err)
    87  	}
    88  
    89  	cliShowConfig()
    90  
    91  	ipneigh, err = h.GetIPScanNeighbor()
    92  	if err != nil {
    93  		t.Fatal("getting ip neighbor config failed:", err)
    94  	}
    95  	t.Logf("dump config:\n%+v", prototext.Format(ipneigh))
    96  	if ipneigh.Mode != vpp_l3.IPScanNeighbor_IPV4 {
    97  		t.Fatalf("expected Mode to be IPV4, got %v", ipneigh.Mode)
    98  	}
    99  	if ipneigh.MaxProcTime != 20 {
   100  		t.Fatalf("expected MaxProcTime to be 20, got %v", ipneigh.MaxProcTime)
   101  	}
   102  	if ipneigh.MaxUpdate != 10 {
   103  		t.Logf("expected MaxUpdate to be 10, got %v", ipneigh.MaxUpdate)
   104  	}
   105  	if ipneigh.ScanInterval != 1 {
   106  		t.Fatalf("expected ScanInterval to be 1, got %v", ipneigh.ScanInterval)
   107  	}
   108  	if ipneigh.ScanIntDelay != 1 {
   109  		t.Fatalf("expected ScanIntDelay to be 5, got %v", ipneigh.ScanIntDelay)
   110  	}
   111  	if ipneigh.StaleThreshold != 4 {
   112  		t.Fatalf("expected ScanInterval to be 1, got %v", ipneigh.StaleThreshold)
   113  	}
   114  }