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
/
vppcalls_api.go
70 lines (59 loc) · 1.57 KB
/
vppcalls_api.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
package vppcalls
import (
"fmt"
govppapi "git.fd.io/govpp.git/api"
log "github.com/ligato/cn-infra/logging"
)
// VersionInfo contains values returned from ShowVersion
type VersionInfo struct {
Program string
Version string
BuildDate string
BuildDirectory string
}
// Release returns version in shortened format YY.MM that describes release.
func (v VersionInfo) Release() string {
if len(v.Version) < 5 {
return ""
}
return v.Version[:5]
}
// VpeInfo contains information about VPP connection and process.
type VpeInfo struct {
PID uint32
ClientIdx uint32
ModuleVersions []ModuleVersion
}
// ModuleVersion contains info about version of particular VPP module.
type ModuleVersion struct {
Name string
Major uint32
Minor uint32
Patch uint32
}
func (m ModuleVersion) String() string {
return fmt.Sprintf("%s-%d.%d.%d", m.Name, m.Major, m.Minor, m.Patch)
}
// VpeVppAPI provides methods for retrieving info and running CLI commands.
type VpeVppAPI interface {
Ping() error
GetVersionInfo() (*VersionInfo, error)
GetVpeInfo() (*VpeInfo, error)
RunCli(cmd string) (string, error)
}
var Versions = map[string]HandlerVersion{}
type HandlerVersion struct {
Msgs []govppapi.Message
New func(govppapi.Channel) VpeVppAPI
}
func CompatibleVpeHandler(ch govppapi.Channel) VpeVppAPI {
for ver, h := range Versions {
if err := ch.CheckCompatiblity(h.Msgs...); err != nil {
log.Debugf("version %s not compatible", ver)
continue
}
log.Debug("found compatible version:", ver)
return h.New(ch)
}
panic("no compatible version available")
}