go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/dnsplugin/dnsplugin.go (about) 1 // Copyright (c) 2021 Pantheon.tech 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 DNSCache --value-type *vpp_dns.DNSCache --import "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/dns" --output-dir "descriptor" 16 17 package dnsplugin 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 scheduler "go.ligato.io/vpp-agent/v3/plugins/kvscheduler/api" 25 "go.ligato.io/vpp-agent/v3/plugins/vpp/dnsplugin/descriptor" 26 "go.ligato.io/vpp-agent/v3/plugins/vpp/dnsplugin/vppcalls" 27 28 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/dnsplugin/vppcalls/vpp2101" 29 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/dnsplugin/vppcalls/vpp2106" 30 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/dnsplugin/vppcalls/vpp2202" 31 _ "go.ligato.io/vpp-agent/v3/plugins/vpp/dnsplugin/vppcalls/vpp2210" 32 ) 33 34 // DNSPlugin configures VPP ability to act as DNS cache server. 35 type DNSPlugin struct { 36 Deps 37 38 dnsHandler vppcalls.DNSVppAPI 39 } 40 41 type Deps struct { 42 infra.PluginDeps 43 Scheduler scheduler.KVScheduler 44 VPP govppmux.API 45 StatusCheck statuscheck.PluginStatusWriter // optional 46 } 47 48 // Init initializes and registers descriptor for DNS. 49 func (p *DNSPlugin) Init() error { 50 // init handler 51 p.dnsHandler = vppcalls.CompatibleDNSHandler(p.VPP, p.Log) 52 53 // init & register descriptor 54 dnsDescriptor := descriptor.NewDNSCacheDescriptor(p.dnsHandler, p.Log) 55 if err := p.Deps.Scheduler.RegisterKVDescriptor(dnsDescriptor); err != nil { 56 return err 57 } 58 59 return nil 60 } 61 62 // AfterInit registers plugin with StatusCheck. 63 func (p *DNSPlugin) AfterInit() error { 64 if p.StatusCheck != nil { 65 p.StatusCheck.Register(p.PluginName, nil) 66 } 67 return nil 68 }