go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ipfixplugin/vppcalls/vpp2202/flowprobe_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 "github.com/pkg/errors" 19 20 vpp_flowprobe "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/flowprobe" 21 "go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2202/interface_types" 22 ipfix "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/ipfix" 23 ) 24 25 // SetFPParams sends message with configuration for Flowprobe. 26 func (h *IpfixVppHandler) SetFPParams(conf *ipfix.FlowProbeParams) error { 27 var flags vpp_flowprobe.FlowprobeRecordFlags 28 29 if conf.GetRecordL2() { 30 flags |= vpp_flowprobe.FLOWPROBE_RECORD_FLAG_L2 31 } 32 33 if conf.GetRecordL3() { 34 flags |= vpp_flowprobe.FLOWPROBE_RECORD_FLAG_L3 35 } 36 37 if conf.GetRecordL4() { 38 flags |= vpp_flowprobe.FLOWPROBE_RECORD_FLAG_L4 39 } 40 41 if flags == 0 { 42 err := errors.New("one of the record fields (l2, l3 or l4) must be enabled") 43 return err 44 } 45 46 req := &vpp_flowprobe.FlowprobeParams{ 47 RecordFlags: flags, 48 ActiveTimer: conf.GetActiveTimer(), 49 PassiveTimer: conf.GetPassiveTimer(), 50 } 51 reply := &vpp_flowprobe.FlowprobeParamsReply{} 52 53 if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 54 return err 55 } 56 57 return nil 58 } 59 60 func (h *IpfixVppHandler) sendFPFeature(isAdd bool, conf *ipfix.FlowProbeFeature) error { 61 meta, found := h.ifIndexes.LookupByName(conf.Interface) 62 if !found { 63 return errors.Errorf("interface %s not found", conf.Interface) 64 } 65 66 var flags vpp_flowprobe.FlowprobeWhichFlags 67 68 if conf.GetL2() { 69 flags |= vpp_flowprobe.FLOWPROBE_WHICH_FLAG_L2 70 } 71 72 if conf.GetIp4() { 73 flags |= vpp_flowprobe.FLOWPROBE_WHICH_FLAG_IP4 74 } 75 76 if conf.GetIp6() { 77 flags |= vpp_flowprobe.FLOWPROBE_WHICH_FLAG_IP6 78 } 79 80 req := &vpp_flowprobe.FlowprobeTxInterfaceAddDel{ 81 IsAdd: isAdd, 82 Which: flags, 83 SwIfIndex: interface_types.InterfaceIndex(meta.SwIfIndex), 84 } 85 reply := &vpp_flowprobe.FlowprobeTxInterfaceAddDelReply{} 86 87 if err := h.callsChannel.SendRequest(req).ReceiveReply(reply); err != nil { 88 return err 89 } 90 91 return nil 92 } 93 94 // AddFPFeature sends message to enable Flowprobe on interface. 95 func (h *IpfixVppHandler) AddFPFeature(conf *ipfix.FlowProbeFeature) error { 96 return h.sendFPFeature(true, conf) 97 } 98 99 // DelFPFeature sends message to disable Flowprobe on interface. 100 func (h *IpfixVppHandler) DelFPFeature(conf *ipfix.FlowProbeFeature) error { 101 return h.sendFPFeature(false, conf) 102 }