go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2101/route_dump_test.go (about)

     1  //  Copyright (c) 2019 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 vpp2101
    16  
    17  import (
    18  	"testing"
    19  
    20  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/fib_types"
    21  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/ip_types"
    22  	l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3"
    23  
    24  	"go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vrfidx"
    25  
    26  	. "github.com/onsi/gomega"
    27  	"go.ligato.io/cn-infra/v2/logging/logrus"
    28  
    29  	netallock_mock "go.ligato.io/vpp-agent/v3/plugins/netalloc/mock"
    30  	vpp_ip "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/ip"
    31  	vpp_vpe "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/vpe"
    32  	"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx"
    33  	"go.ligato.io/vpp-agent/v3/plugins/vpp/vppmock"
    34  )
    35  
    36  // Test dumping routes
    37  func TestDumpStaticRoutes(t *testing.T) {
    38  	ctx := vppmock.SetupTestCtx(t)
    39  	defer ctx.TeardownTestCtx()
    40  	ifIndexes := ifaceidx.NewIfaceIndex(logrus.NewLogger("test-if"), "test-if")
    41  	vrfIndexes := vrfidx.NewVRFIndex(logrus.NewLogger("test-vrf"), "test-vrf")
    42  	l3handler := NewRouteVppHandler(ctx.MockChannel, ifIndexes, vrfIndexes, netallock_mock.NewMockNetAlloc(),
    43  		logrus.DefaultLogger())
    44  
    45  	vrfIndexes.Put("vrf1-ipv4", &vrfidx.VRFMetadata{Index: 0, Protocol: l3.VrfTable_IPV4})
    46  	vrfIndexes.Put("vrf1-ipv6", &vrfidx.VRFMetadata{Index: 0, Protocol: l3.VrfTable_IPV6})
    47  	ifIndexes.Put("if1", &ifaceidx.IfaceMetadata{SwIfIndex: 1})
    48  	ifIndexes.Put("if2", &ifaceidx.IfaceMetadata{SwIfIndex: 2})
    49  
    50  	ctx.MockVpp.MockReply(&vpp_ip.IPRouteDetails{
    51  		Route: vpp_ip.IPRoute{
    52  			Prefix: ip_types.Prefix{
    53  				Address: ip_types.Address{
    54  					Af: ip_types.ADDRESS_IP4,
    55  					Un: ip_types.AddressUnionIP4([4]uint8{10, 0, 0, 1}),
    56  				},
    57  			},
    58  			Paths: []fib_types.FibPath{
    59  				{
    60  					SwIfIndex: 2,
    61  				},
    62  			},
    63  		},
    64  	})
    65  	ctx.MockVpp.MockReply(&vpp_vpe.ControlPingReply{})
    66  	ctx.MockVpp.MockReply(&vpp_ip.IPRouteDetails{
    67  		Route: vpp_ip.IPRoute{
    68  			Prefix: ip_types.Prefix{
    69  				Address: ip_types.Address{
    70  					Af: ip_types.ADDRESS_IP6,
    71  					Un: ip_types.AddressUnionIP6([16]uint8{255, 255, 10, 1}),
    72  				},
    73  			},
    74  			Paths: []fib_types.FibPath{
    75  				{
    76  					SwIfIndex: 1,
    77  				},
    78  			},
    79  		},
    80  	})
    81  	ctx.MockVpp.MockReply(&vpp_vpe.ControlPingReply{})
    82  
    83  	rtDetails, err := l3handler.DumpRoutes()
    84  	Expect(err).To(Succeed())
    85  	Expect(rtDetails).To(HaveLen(2))
    86  	Expect(rtDetails[0].Route.OutgoingInterface).To(Equal("if2"))
    87  	Expect(rtDetails[1].Route.OutgoingInterface).To(Equal("if1"))
    88  }