go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2101/vrf_dump.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  	"strings"
    19  
    20  	vpp_ip "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/ip"
    21  	l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3"
    22  )
    23  
    24  // DumpVrfTables dumps all configured VRF tables.
    25  func (h *VrfTableHandler) DumpVrfTables() (tables []*l3.VrfTable, err error) {
    26  	// dump IPv4 VRF tables
    27  	reqCtx := h.callsChannel.SendMultiRequest(&vpp_ip.IPTableDump{})
    28  	for {
    29  		fibDetails := &vpp_ip.IPTableDetails{}
    30  		stop, err := reqCtx.ReceiveReply(fibDetails)
    31  		if stop {
    32  			break
    33  		}
    34  		if err != nil {
    35  			return nil, err
    36  		}
    37  		tables = append(tables, &l3.VrfTable{
    38  			Id:       fibDetails.Table.TableID,
    39  			Protocol: getTableProto(fibDetails.Table.IsIP6),
    40  			Label:    strings.Trim(fibDetails.Table.Name, "\x00"),
    41  		})
    42  	}
    43  
    44  	return tables, nil
    45  }
    46  
    47  func getTableProto(isIPv6 bool) l3.VrfTable_Protocol {
    48  	if isIPv6 {
    49  		return l3.VrfTable_IPV6
    50  	}
    51  	return l3.VrfTable_IPV4
    52  }