go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2106/ip_container_vppcalls.go (about) 1 // Copyright (c) 2021 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 vpp2106 16 17 import ( 18 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/interface_types" 19 vpp_ip "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/ip" 20 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/ip_types" 21 ) 22 23 func (h *InterfaceVppHandler) sendAndLogMessageForVpp(ifIdx uint32, addr string, isAdd bool) error { 24 prefix, err := ip_types.ParsePrefix(addr) 25 if err != nil { 26 return err 27 } 28 29 req := &vpp_ip.IPContainerProxyAddDel{ 30 SwIfIndex: interface_types.InterfaceIndex(ifIdx), 31 IsAdd: isAdd, 32 Pfx: prefix, 33 } 34 reply := &vpp_ip.IPContainerProxyAddDelReply{} 35 36 if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 37 return err 38 } 39 40 return nil 41 } 42 43 func (h *InterfaceVppHandler) AddContainerIP(ifIdx uint32, addr string) error { 44 return h.sendAndLogMessageForVpp(ifIdx, addr, true) 45 } 46 47 func (h *InterfaceVppHandler) DelContainerIP(ifIdx uint32, addr string) error { 48 return h.sendAndLogMessageForVpp(ifIdx, addr, false) 49 }