forked from ligato/vpp-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
srplugin.go
91 lines (76 loc) · 3.36 KB
/
srplugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2019 Bell Canada, Pantheon Technologies and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:generate descriptor-adapter --descriptor-name LocalSID --value-type *vpp_srv6.LocalSID --import "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/srv6" --output-dir "descriptor"
//go:generate descriptor-adapter --descriptor-name Policy --value-type *vpp_srv6.Policy --import "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/srv6" --output-dir "descriptor"
//go:generate descriptor-adapter --descriptor-name Steering --value-type *vpp_srv6.Steering --import "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/srv6" --output-dir "descriptor"
//go:generate descriptor-adapter --descriptor-name SRv6Global --value-type *vpp_srv6.SRv6Global --import "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/srv6" --output-dir "descriptor"
package srplugin
import (
"go.ligato.io/cn-infra/v2/health/statuscheck"
"go.ligato.io/cn-infra/v2/infra"
"go.ligato.io/vpp-agent/v3/plugins/govppmux"
scheduler "go.ligato.io/vpp-agent/v3/plugins/kvscheduler/api"
"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin"
"go.ligato.io/vpp-agent/v3/plugins/vpp/srplugin/descriptor"
"go.ligato.io/vpp-agent/v3/plugins/vpp/srplugin/vppcalls"
_ "go.ligato.io/vpp-agent/v3/plugins/vpp/srplugin/vppcalls/vpp1908"
_ "go.ligato.io/vpp-agent/v3/plugins/vpp/srplugin/vppcalls/vpp2001"
_ "go.ligato.io/vpp-agent/v3/plugins/vpp/srplugin/vppcalls/vpp2005"
_ "go.ligato.io/vpp-agent/v3/plugins/vpp/srplugin/vppcalls/vpp2009"
)
// SRPlugin configures segment routing.
type SRPlugin struct {
Deps
// VPP handler
srHandler vppcalls.SRv6VppAPI
// descriptors
localSIDDescriptor *descriptor.LocalSIDDescriptor
policyDescriptor *descriptor.PolicyDescriptor
steeringDescriptor *descriptor.SteeringDescriptor
}
type Deps struct {
infra.PluginDeps
Scheduler scheduler.KVScheduler
VPP govppmux.API
IfPlugin ifplugin.API
StatusCheck statuscheck.PluginStatusWriter // optional
}
// Init initializes and registers descriptors for Linux ARPs and Routes.
func (p *SRPlugin) Init() error {
var err error
// init handlers
p.srHandler = vppcalls.CompatibleSRv6Handler(p.VPP, p.IfPlugin.GetInterfaceIndex(), p.Log)
// init & register descriptors
localSIDDescriptor := descriptor.NewLocalSIDDescriptor(p.srHandler, p.Log)
policyDescriptor := descriptor.NewPolicyDescriptor(p.srHandler, p.Log)
steeringDescriptor := descriptor.NewSteeringDescriptor(p.srHandler, p.Log)
encapSourceAddressDescriptor := descriptor.NewSRv6GlobalDescriptor(p.srHandler, p.Log)
err = p.Deps.Scheduler.RegisterKVDescriptor(
localSIDDescriptor,
policyDescriptor,
steeringDescriptor,
encapSourceAddressDescriptor,
)
if err != nil {
return err
}
return nil
}
// AfterInit registers plugin with StatusCheck.
func (p *SRPlugin) AfterInit() error {
if p.StatusCheck != nil {
p.StatusCheck.Register(p.PluginName, nil)
}
return nil
}