go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/l2plugin/vppcalls/vpp2101/xconnect_vppcalls.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  	"errors"
    19  
    20  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/interface_types"
    21  	vpp_l2 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2101/l2"
    22  )
    23  
    24  // AddL2XConnect creates xConnect between two existing interfaces.
    25  func (h *XConnectVppHandler) AddL2XConnect(rxIface, txIface string) error {
    26  	return h.addDelXConnect(rxIface, txIface, true)
    27  }
    28  
    29  // DeleteL2XConnect removes xConnect between two interfaces.
    30  func (h *XConnectVppHandler) DeleteL2XConnect(rxIface, txIface string) error {
    31  	return h.addDelXConnect(rxIface, txIface, false)
    32  }
    33  
    34  func (h *XConnectVppHandler) addDelXConnect(rxIface, txIface string, enable bool) error {
    35  	// get Rx interface metadata
    36  	rxIfaceMeta, found := h.ifIndexes.LookupByName(rxIface)
    37  	if !found {
    38  		return errors.New("failed to get Rx interface metadata")
    39  	}
    40  
    41  	// get Tx interface metadata
    42  	txIfaceMeta, found := h.ifIndexes.LookupByName(txIface)
    43  	if !found {
    44  		return errors.New("failed to get Tx interface metadata")
    45  	}
    46  
    47  	// add/del xConnect pair
    48  	req := &vpp_l2.SwInterfaceSetL2Xconnect{
    49  		Enable:      enable,
    50  		TxSwIfIndex: interface_types.InterfaceIndex(txIfaceMeta.GetIndex()),
    51  		RxSwIfIndex: interface_types.InterfaceIndex(rxIfaceMeta.GetIndex()),
    52  	}
    53  	reply := &vpp_l2.SwInterfaceSetL2XconnectReply{}
    54  
    55  	if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil {
    56  		return err
    57  	}
    58  
    59  	return nil
    60  }