forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy.go
92 lines (86 loc) · 1.79 KB
/
strategy.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
92
package main
import (
"encoding/base64"
"os"
"path"
"github.com/urfave/cli/v2"
)
func init() {
var withFib bool
defineCommand(&cli.Command{
Category: "strategy",
Name: "list-strategy",
Aliases: []string{"list-strategies"},
Usage: "List strategies",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "fib",
Usage: "show FIB entries",
Destination: &withFib,
},
},
Action: func(c *cli.Context) error {
return clientDoPrint(c.Context, `
query listStrategy($withFib: Boolean!) {
strategies {
id
name
fibEntries @include(if: $withFib) {
id
name
}
}
}
`, map[string]any{
"withFib": withFib,
}, "strategies")
},
})
}
func init() {
var name string
var elf []byte
defineCommand(&cli.Command{
Category: "strategy",
Name: "load-strategy",
Usage: "Load a strategy ELF program",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Usage: "short `name`",
Destination: &name,
},
&cli.StringFlag{
Name: "elffile",
Usage: "ELF program `file`",
Required: true,
Action: func(c *cli.Context, filename string) (e error) {
elf, e = os.ReadFile(filename)
if e != nil {
return e
}
if name == "" {
name = path.Base(filename)
}
return nil
},
},
},
Action: func(c *cli.Context) error {
return clientDoPrint(c.Context, `
mutation loadStrategy($name: String!, $elf: Bytes!) {
loadStrategy(name: $name, elf: $elf) {
id
name
}
}
`, map[string]any{
"name": name,
"elf": base64.StdEncoding.EncodeToString(elf),
}, "loadStrategy")
},
})
}
func init() {
defineDeleteCommand("strategy", "unload-strategy", "Unload a strategy ELF program", "strategy program")
}