go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ipfixplugin/vppcalls/ipfix_vppcalls.go (about) 1 // Copyright (c) 2020 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 vppcalls 16 17 import ( 18 govppapi "go.fd.io/govpp/api" 19 "go.ligato.io/cn-infra/v2/logging" 20 21 "go.ligato.io/vpp-agent/v3/plugins/vpp" 22 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin/ifaceidx" 23 ipfix "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/ipfix" 24 ) 25 26 const ( 27 // MinPathMTU and MaxPathMTU values were copied from VPP source code. 28 // If something will change, please, be kind and update values here 29 // and also update error messages in the IPFIX descriptor. 30 MinPathMTU = 68 31 MaxPathMTU = 1450 32 ) 33 34 // IpfixVppAPI provides methods for managing VPP IPFIX configuration. 35 type IpfixVppAPI interface { 36 SetExporter(conf *ipfix.IPFIX) error 37 DumpExporters() ([]*ipfix.IPFIX, error) 38 39 SetFPParams(conf *ipfix.FlowProbeParams) error 40 41 AddFPFeature(conf *ipfix.FlowProbeFeature) error 42 DelFPFeature(conf *ipfix.FlowProbeFeature) error 43 } 44 45 var handler = vpp.RegisterHandler(vpp.HandlerDesc{ 46 Name: "ipfix", 47 HandlerAPI: (*IpfixVppAPI)(nil), 48 }) 49 50 func AddIpfixHandlerVersion(version vpp.Version, msgs []govppapi.Message, 51 h func(ch govppapi.Channel, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) IpfixVppAPI, 52 ) { 53 handler.AddVersion(vpp.HandlerVersion{ 54 Version: version, 55 Check: func(c vpp.Client) error { 56 ch, err := c.NewAPIChannel() 57 if err != nil { 58 return err 59 } 60 return ch.CheckCompatiblity(msgs...) 61 }, 62 NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI { 63 ch, err := c.NewAPIChannel() 64 if err != nil { 65 return err 66 } 67 return h(ch, a[0].(ifaceidx.IfaceMetadataIndex), a[1].(logging.Logger)) 68 }, 69 }) 70 } 71 72 func CompatibleIpfixVppHandler(c vpp.Client, ifIdx ifaceidx.IfaceMetadataIndex, log logging.Logger) IpfixVppAPI { 73 if v := handler.FindCompatibleVersion(c); v != nil { 74 return v.NewHandler(c, ifIdx, log).(IpfixVppAPI) 75 } 76 return nil 77 }