go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/stnplugin/stnplugin.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 STN --value-type *vpp_stn.Rule --import "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/stn" --output-dir "descriptor" 16 17 package stnplugin 18 19 import ( 20 "go.ligato.io/cn-infra/v2/health/statuscheck" 21 "go.ligato.io/cn-infra/v2/infra" 22 23 "go.ligato.io/vpp-agent/v3/plugins/govppmux" 24 kvs "go.ligato.io/vpp-agent/v3/plugins/kvscheduler/api" 25 "go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin" 26 "go.ligato.io/vpp-agent/v3/plugins/vpp/stnplugin/descriptor" 27 "go.ligato.io/vpp-agent/v3/plugins/vpp/stnplugin/descriptor/adapter" 28 "go.ligato.io/vpp-agent/v3/plugins/vpp/stnplugin/vppcalls" 29 30 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/stnplugin/vppcalls/vpp2101" 31 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/stnplugin/vppcalls/vpp2106" 32 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/stnplugin/vppcalls/vpp2202" 33 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/stnplugin/vppcalls/vpp2210" 34 ) 35 36 // STNPlugin configures VPP STN rules using GoVPP. 37 type STNPlugin struct { 38 Deps 39 40 // handlers 41 stnHandler vppcalls.StnVppAPI 42 43 // descriptors 44 stnDescriptor *descriptor.STNDescriptor 45 } 46 47 // Deps lists dependencies of the STN plugin. 48 type Deps struct { 49 infra.PluginDeps 50 KVScheduler kvs.KVScheduler 51 VPP govppmux.API 52 IfPlugin ifplugin.API 53 StatusCheck statuscheck.PluginStatusWriter // optional 54 } 55 56 // Init registers STN-related descriptors. 57 func (p *STNPlugin) Init() (err error) { 58 if !p.VPP.IsPluginLoaded("stn") { 59 p.Log.Warnf("VPP plugin STN was disabled by VPP") 60 return nil 61 } 62 63 // init handlers 64 p.stnHandler = vppcalls.CompatibleStnVppHandler(p.VPP, p.IfPlugin.GetInterfaceIndex(), p.Log) 65 66 // init and register STN descriptor 67 p.stnDescriptor = descriptor.NewSTNDescriptor(p.stnHandler, p.Log) 68 stnDescriptor := adapter.NewSTNDescriptor(p.stnDescriptor.GetDescriptor()) 69 err = p.KVScheduler.RegisterKVDescriptor(stnDescriptor) 70 if err != nil { 71 return err 72 } 73 74 return nil 75 } 76 77 // AfterInit registers plugin with StatusCheck. 78 func (p *STNPlugin) AfterInit() error { 79 if p.StatusCheck != nil { 80 p.StatusCheck.Register(p.PluginName, nil) 81 } 82 return nil 83 }