go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2202/vrf_dump_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
    16  
    17  import (
    18  	"testing"
    19  
    20  	. "github.com/onsi/gomega"
    21  	"go.ligato.io/cn-infra/v2/logging/logrus"
    22  
    23  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/fib_types"
    24  	vpp_ip "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/ip"
    25  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/memclnt"
    26  	"go.ligato.io/vpp-agent/v3/plugins/vpp/vppmock"
    27  	l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3"
    28  )
    29  
    30  func TestDumpVrfTables(t *testing.T) {
    31  	ctx := vppmock.SetupTestCtx(t)
    32  	defer ctx.TeardownTestCtx()
    33  	vthandler := NewVrfTableVppHandler(ctx.MockChannel, logrus.DefaultLogger())
    34  
    35  	ctx.MockVpp.MockReply(
    36  		&vpp_ip.IPTableDetails{
    37  			Table: vpp_ip.IPTable{
    38  				TableID: 1,
    39  				Name:    "table3",
    40  				IsIP6:   false,
    41  			},
    42  		},
    43  		&vpp_ip.IPTableDetails{
    44  			Table: vpp_ip.IPTable{
    45  				TableID: 2,
    46  				Name:    "table3",
    47  				IsIP6:   false,
    48  			},
    49  		},
    50  		&vpp_ip.IPTableDetails{
    51  			Table: vpp_ip.IPTable{
    52  				TableID: 3,
    53  				Name:    "table2",
    54  				IsIP6:   true,
    55  			},
    56  		},
    57  	)
    58  	ctx.MockVpp.MockReply(&memclnt.ControlPingReply{})
    59  	ctx.MockVpp.MockReply(
    60  		&vpp_ip.IPRouteDetails{
    61  			Route: vpp_ip.IPRoute{
    62  				TableID: 2,
    63  				Paths:   []fib_types.FibPath{{SwIfIndex: 5}},
    64  			},
    65  		})
    66  	ctx.MockVpp.MockReply(&memclnt.ControlPingReply{})
    67  
    68  	vrfTables, err := vthandler.DumpVrfTables()
    69  	Expect(err).To(Succeed())
    70  	Expect(vrfTables).To(HaveLen(3))
    71  	if vrfTables[0].Label == "table2" {
    72  		Expect(vrfTables[1]).To(Equal(&l3.VrfTable{Id: 3, Protocol: l3.VrfTable_IPV4, Label: "table3"}))
    73  		Expect(vrfTables[0]).To(Equal(&l3.VrfTable{Id: 2, Protocol: l3.VrfTable_IPV4, Label: "table2"}))
    74  	} else {
    75  		Expect(vrfTables[0]).To(Equal(&l3.VrfTable{Id: 1, Protocol: l3.VrfTable_IPV4, Label: "table3"}))
    76  		Expect(vrfTables[1]).To(Equal(&l3.VrfTable{Id: 2, Protocol: l3.VrfTable_IPV4, Label: "table3"}))
    77  	}
    78  	Expect(vrfTables[2]).To(Equal(&l3.VrfTable{Id: 3, Protocol: l3.VrfTable_IPV6, Label: "table2"}))
    79  }