go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2210/admin_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  	"context"
    19  
    20  	interfaces "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/interface"
    21  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2210/interface_types"
    22  )
    23  
    24  func (h *InterfaceVppHandler) InterfaceAdminDown(ctx context.Context, ifIdx uint32) error {
    25  	return h.interfaceSetFlags(ifIdx, false)
    26  }
    27  
    28  func (h *InterfaceVppHandler) InterfaceAdminUp(ctx context.Context, ifIdx uint32) error {
    29  	return h.interfaceSetFlags(ifIdx, true)
    30  }
    31  
    32  func (h *InterfaceVppHandler) SetInterfaceTag(tag string, ifIdx uint32) error {
    33  	return h.handleInterfaceTag(tag, interface_types.InterfaceIndex(ifIdx), true)
    34  }
    35  
    36  func (h *InterfaceVppHandler) RemoveInterfaceTag(tag string, ifIdx uint32) error {
    37  	return h.handleInterfaceTag(tag, interface_types.InterfaceIndex(ifIdx), false)
    38  }
    39  
    40  func (h *InterfaceVppHandler) interfaceSetFlags(ifIdx uint32, adminUp bool) error {
    41  	req := &interfaces.SwInterfaceSetFlags{
    42  		SwIfIndex: interface_types.InterfaceIndex(ifIdx),
    43  		Flags:     setAdminUpFlag(adminUp),
    44  	}
    45  	reply := &interfaces.SwInterfaceSetFlagsReply{}
    46  
    47  	if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil {
    48  		return err
    49  	}
    50  
    51  	return nil
    52  }
    53  
    54  func (h *InterfaceVppHandler) handleInterfaceTag(tag string, ifIdx interface_types.InterfaceIndex, isAdd bool) error {
    55  	req := &interfaces.SwInterfaceTagAddDel{
    56  		Tag:   tag,
    57  		IsAdd: isAdd,
    58  	}
    59  	// For some reason, if deleting tag, the software interface index has to be 0 and only name should be set.
    60  	// Otherwise reply returns with error core -2 (incorrect sw_if_idx)
    61  	if isAdd {
    62  		req.SwIfIndex = ifIdx
    63  	}
    64  	reply := &interfaces.SwInterfaceTagAddDelReply{}
    65  
    66  	if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil {
    67  		return err
    68  	}
    69  
    70  	return nil
    71  }
    72  
    73  func setAdminUpFlag(adminUp bool) interface_types.IfStatusFlags {
    74  	if adminUp {
    75  		return interface_types.IF_STATUS_API_FLAG_ADMIN_UP
    76  	}
    77  	return 0
    78  }