go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2210/vrf_vppcalls.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 vpp2210
    16  
    17  import (
    18  	vpp_ifs "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/interface"
    19  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/interface_types"
    20  )
    21  
    22  func (h *InterfaceVppHandler) SetInterfaceVrf(ifIdx, vrfID uint32) error {
    23  	return h.setInterfaceVrf(ifIdx, vrfID, false)
    24  }
    25  
    26  func (h *InterfaceVppHandler) SetInterfaceVrfIPv6(ifIdx, vrfID uint32) error {
    27  	return h.setInterfaceVrf(ifIdx, vrfID, true)
    28  }
    29  
    30  func (h *InterfaceVppHandler) GetInterfaceVrf(ifIdx uint32) (vrfID uint32, err error) {
    31  	return h.getInterfaceVrf(ifIdx, false)
    32  }
    33  
    34  func (h *InterfaceVppHandler) GetInterfaceVrfIPv6(ifIdx uint32) (vrfID uint32, err error) {
    35  	return h.getInterfaceVrf(ifIdx, true)
    36  }
    37  
    38  // Interface is set to VRF table. Table IP version has to be defined.
    39  func (h *InterfaceVppHandler) setInterfaceVrf(ifIdx, vrfID uint32, isIPv6 bool) error {
    40  	req := &vpp_ifs.SwInterfaceSetTable{
    41  		SwIfIndex: interface_types.InterfaceIndex(ifIdx),
    42  		VrfID:     vrfID,
    43  		IsIPv6:    isIPv6,
    44  	}
    45  	reply := &vpp_ifs.SwInterfaceSetTableReply{}
    46  
    47  	if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil {
    48  		return err
    49  	}
    50  
    51  	h.log.Debugf("Interface %d set to VRF %d", ifIdx, vrfID)
    52  
    53  	return nil
    54  }
    55  
    56  // Returns VRF ID for provided interface.
    57  func (h *InterfaceVppHandler) getInterfaceVrf(ifIdx uint32, isIPv6 bool) (vrfID uint32, err error) {
    58  	req := &vpp_ifs.SwInterfaceGetTable{
    59  		SwIfIndex: interface_types.InterfaceIndex(ifIdx),
    60  		IsIPv6:    isIPv6,
    61  	}
    62  	reply := &vpp_ifs.SwInterfaceGetTableReply{}
    63  
    64  	if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil {
    65  		return 0, err
    66  	}
    67  
    68  	return reply.VrfID, nil
    69  }