This repository has been archived by the owner on Aug 3, 2020. It is now read-only.
forked from ligato/vpp-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
punt_vppcalls.go
78 lines (68 loc) · 2.54 KB
/
punt_vppcalls.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
// Copyright (c) 2018 Cisco 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.
package vppcalls
import (
govppapi "git.fd.io/govpp.git/api"
"github.com/ligato/cn-infra/logging"
punt "github.com/ligato/vpp-agent/api/models/vpp/punt"
"github.com/ligato/vpp-agent/plugins/vpp/ifplugin/ifaceidx"
)
// PuntDetails includes proto-modelled punt object and its socket path
type PuntDetails struct {
PuntData *punt.ToHost
SocketPath string
}
// PuntVppAPI provides methods for managing VPP punt configuration.
type PuntVppAPI interface {
PuntVPPRead
// AddPunt configures new punt to the host from the VPP
AddPunt(punt *punt.ToHost) error
// DeletePunt removes or unregisters punt entry
DeletePunt(punt *punt.ToHost) error
// RegisterPuntSocket registers new punt to unix domain socket entry
RegisterPuntSocket(puntCfg *punt.ToHost) (string, error)
// DeregisterPuntSocket removes existing punt to socket registration
DeregisterPuntSocket(puntCfg *punt.ToHost) error
// AddPuntRedirect adds new punt IP redirect entry
AddPuntRedirect(punt *punt.IPRedirect) error
// DeletePuntRedirect removes existing redirect entry
DeletePuntRedirect(punt *punt.IPRedirect) error
}
// PuntVPPRead provides read methods for punt
type PuntVPPRead interface {
// DumpPuntRegisteredSockets returns all punt socket registrations known to the VPP agent
DumpRegisteredPuntSockets() ([]*PuntDetails, error)
}
var Versions = map[string]HandlerVersion{}
type HandlerVersion struct {
Msgs []govppapi.Message
New func(govppapi.Channel, ifaceidx.IfaceMetadataIndex, logging.Logger) PuntVppAPI
}
func CompatiblePuntVppHandler(
ch govppapi.Channel, idx ifaceidx.IfaceMetadataIndex, log logging.Logger,
) PuntVppAPI {
if len(Versions) == 0 {
// puntplugin is not loaded
return nil
}
for ver, h := range Versions {
log.Debugf("checking compatibility with %s", ver)
if err := ch.CheckCompatiblity(h.Msgs...); err != nil {
continue
}
log.Debug("found compatible version:", ver)
return h.New(ch, idx, log)
}
panic("no compatible version available")
}