go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2202/afpacket_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 vpp2202 16 17 import ( 18 vpp_afpacket "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/af_packet" 19 ) 20 21 // AddAfPacketInterface implements AfPacket handler. 22 func (h *InterfaceVppHandler) AddAfPacketInterface(ifName, hwAddr, targetHostIfName string) (swIndex uint32, err error) { 23 req := &vpp_afpacket.AfPacketCreate{ 24 HostIfName: targetHostIfName, 25 } 26 if hwAddr == "" { 27 req.UseRandomHwAddr = true 28 } else { 29 mac, err := ParseMAC(hwAddr) 30 if err != nil { 31 return 0, err 32 } 33 req.HwAddr = mac 34 } 35 reply := &vpp_afpacket.AfPacketCreateReply{} 36 37 if err = h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 38 return 0, err 39 } 40 41 return uint32(reply.SwIfIndex), h.SetInterfaceTag(ifName, uint32(reply.SwIfIndex)) 42 } 43 44 // DeleteAfPacketInterface implements AfPacket handler. 45 func (h *InterfaceVppHandler) DeleteAfPacketInterface(ifName string, idx uint32, targetHostIfName string) error { 46 req := &vpp_afpacket.AfPacketDelete{ 47 HostIfName: targetHostIfName, 48 } 49 reply := &vpp_afpacket.AfPacketDeleteReply{} 50 51 if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 52 return err 53 } 54 55 return h.RemoveInterfaceTag(ifName, idx) 56 }