go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l3plugin/vppcalls/vpp2101/proxyarp_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  	"net"
    19  
    20  	vpp_arp "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/arp"
    21  	"go.ligato.io/vpp-agent/v3/plugins/vpp/l3plugin/vppcalls"
    22  	l3 "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/l3"
    23  )
    24  
    25  // DumpProxyArpRanges implements proxy arp handler.
    26  func (h *ProxyArpVppHandler) DumpProxyArpRanges() (pArpRngs []*vppcalls.ProxyArpRangesDetails, err error) {
    27  	reqCtx := h.callsChannel.SendMultiRequest(&vpp_arp.ProxyArpDump{})
    28  
    29  	for {
    30  		proxyArpDetails := &vpp_arp.ProxyArpDetails{}
    31  		stop, err := reqCtx.ReceiveReply(proxyArpDetails)
    32  		if stop {
    33  			break
    34  		}
    35  		if err != nil {
    36  			h.log.Error(err)
    37  			return nil, err
    38  		}
    39  
    40  		pArpRngs = append(pArpRngs, &vppcalls.ProxyArpRangesDetails{
    41  			Range: &l3.ProxyARP_Range{
    42  				FirstIpAddr: net.IP(proxyArpDetails.Proxy.Low[:]).To4().String(),
    43  				LastIpAddr:  net.IP(proxyArpDetails.Proxy.Hi[:]).To4().String(),
    44  				VrfId:       proxyArpDetails.Proxy.TableID,
    45  			},
    46  		})
    47  	}
    48  
    49  	return pArpRngs, nil
    50  }
    51  
    52  // DumpProxyArpInterfaces implements proxy arp handler.
    53  func (h *ProxyArpVppHandler) DumpProxyArpInterfaces() (pArpIfs []*vppcalls.ProxyArpInterfaceDetails, err error) {
    54  	reqCtx := h.callsChannel.SendMultiRequest(&vpp_arp.ProxyArpIntfcDump{})
    55  
    56  	for {
    57  		proxyArpDetails := &vpp_arp.ProxyArpIntfcDetails{}
    58  		stop, err := reqCtx.ReceiveReply(proxyArpDetails)
    59  		if stop {
    60  			break
    61  		}
    62  		if err != nil {
    63  			h.log.Error(err)
    64  			return nil, err
    65  		}
    66  
    67  		// Interface
    68  		ifName, _, exists := h.ifIndexes.LookupBySwIfIndex(proxyArpDetails.SwIfIndex)
    69  		if !exists {
    70  			h.log.Warnf("Proxy ARP interface dump: missing name for interface index %d", proxyArpDetails.SwIfIndex)
    71  		}
    72  
    73  		// Create entry
    74  		pArpIfs = append(pArpIfs, &vppcalls.ProxyArpInterfaceDetails{
    75  			Interface: &l3.ProxyARP_Interface{
    76  				Name: ifName,
    77  			},
    78  			Meta: &vppcalls.ProxyArpInterfaceMeta{
    79  				SwIfIndex: proxyArpDetails.SwIfIndex,
    80  			},
    81  		})
    82  
    83  	}
    84  
    85  	return pArpIfs, nil
    86  }