go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/abfplugin/abfplugin.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 //go:generate descriptor-adapter --descriptor-name ABF --value-type *vpp_abf.ABF --meta-type *abfidx.ABFMetadata --import "go.ligato.io/vpp-agent/v3/plugins/vpp/abfplugin/abfidx" --import "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/abf" --output-dir "descriptor" 16 17 package abfplugin 18 19 import ( 20 "github.com/go-errors/errors" 21 "go.ligato.io/cn-infra/v2/health/statuscheck" 22 "go.ligato.io/cn-infra/v2/infra" 23 24 "go.ligato.io/vpp-agent/v3/plugins/govppmux" 25 kvs "go.ligato.io/vpp-agent/v3/plugins/kvscheduler/api" 26 "go.ligato.io/vpp-agent/v3/plugins/vpp/abfplugin/abfidx" 27 "go.ligato.io/vpp-agent/v3/plugins/vpp/abfplugin/descriptor" 28 "go.ligato.io/vpp-agent/v3/plugins/vpp/abfplugin/vppcalls" 29 "go.ligato.io/vpp-agent/v3/plugins/vpp/aclplugin" 30 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin" 31 32 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/abfplugin/vppcalls/vpp2101" 33 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/abfplugin/vppcalls/vpp2106" 34 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/abfplugin/vppcalls/vpp2202" 35 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/abfplugin/vppcalls/vpp2210" 36 ) 37 38 // ABFPlugin is a plugin that manages ACL-based forwarding. 39 type ABFPlugin struct { 40 Deps 41 42 abfHandler vppcalls.ABFVppAPI 43 44 // index maps 45 abfIndex abfidx.ABFMetadataIndex 46 } 47 48 // Deps represents dependencies for the plugin. 49 type Deps struct { 50 infra.PluginDeps 51 Scheduler kvs.KVScheduler 52 VPP govppmux.API 53 ACLPlugin aclplugin.API 54 IfPlugin ifplugin.API 55 StatusCheck statuscheck.PluginStatusWriter // optional 56 } 57 58 // Init initializes ABF plugin. 59 func (p *ABFPlugin) Init() error { 60 if !p.VPP.IsPluginLoaded("abf") { 61 p.Log.Warnf("VPP plugin ABF was disabled by VPP") 62 return nil 63 } 64 65 // init handlers 66 p.abfHandler = vppcalls.CompatibleABFHandler(p.VPP, p.ACLPlugin.GetACLIndex(), p.IfPlugin.GetInterfaceIndex(), p.Log) 67 if p.abfHandler == nil { 68 return errors.New("abfHandler is not available") 69 } 70 71 // init & register descriptor 72 abfDescriptor := descriptor.NewABFDescriptor(p.abfHandler, p.ACLPlugin.GetACLIndex(), p.Log) 73 if err := p.Deps.Scheduler.RegisterKVDescriptor(abfDescriptor); err != nil { 74 return err 75 } 76 77 // obtain read-only reference to index map 78 var withIndex bool 79 metadataMap := p.Scheduler.GetMetadataMap(abfDescriptor.Name) 80 p.abfIndex, withIndex = metadataMap.(abfidx.ABFMetadataIndex) 81 if !withIndex { 82 return errors.New("missing index with ABF metadata") 83 } 84 85 // init & register derived value descriptor 86 abfInterfaceDescriptor := descriptor.NewABFToInterfaceDescriptor(p.abfIndex, p.abfHandler, p.IfPlugin, p.Log) 87 if err := p.Deps.Scheduler.RegisterKVDescriptor(abfInterfaceDescriptor); err != nil { 88 return err 89 } 90 91 return nil 92 } 93 94 // AfterInit registers plugin with StatusCheck. 95 func (p *ABFPlugin) AfterInit() error { 96 if p.StatusCheck != nil { 97 p.StatusCheck.Register(p.PluginName, nil) 98 } 99 return nil 100 }