go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2101/l2_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  	"fmt"
    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  	ifs "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    23  )
    24  
    25  // TODO:  more suitable for the l2 plugin, but the tag-rewrite retrieve is a part of the vpp interface api
    26  
    27  // SetVLanTagRewrite sets an interface tag rewrite
    28  func (h *InterfaceVppHandler) SetVLanTagRewrite(ifIdx uint32, subIf *ifs.SubInterface) error {
    29  	req := &vpp_l2.L2InterfaceVlanTagRewrite{
    30  		SwIfIndex: interface_types.InterfaceIndex(ifIdx),
    31  		VtrOp:     getTagRewriteOption(subIf.TagRwOption),
    32  		PushDot1q: uint32(boolToUint(subIf.PushDot1Q)),
    33  		Tag1:      subIf.Tag1,
    34  		Tag2:      subIf.Tag2,
    35  	}
    36  	reply := &vpp_l2.L2InterfaceVlanTagRewriteReply{}
    37  	if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil {
    38  		return fmt.Errorf("%s returned error: %v", reply.GetMessageName(), err)
    39  	}
    40  
    41  	return nil
    42  }
    43  
    44  func getTagRewriteOption(op ifs.SubInterface_TagRewriteOptions) uint32 {
    45  	switch op {
    46  	case ifs.SubInterface_PUSH1:
    47  		return 1
    48  	case ifs.SubInterface_PUSH2:
    49  		return 2
    50  	case ifs.SubInterface_POP1:
    51  		return 3
    52  	case ifs.SubInterface_POP2:
    53  		return 4
    54  	case ifs.SubInterface_TRANSLATE11:
    55  		return 5
    56  	case ifs.SubInterface_TRANSLATE12:
    57  		return 6
    58  	case ifs.SubInterface_TRANSLATE21:
    59  		return 7
    60  	case ifs.SubInterface_TRANSLATE22:
    61  		return 8
    62  	default: // disabled
    63  		return 0
    64  	}
    65  }