forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfib.go
95 lines (89 loc) · 1.94 KB
/
fib.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
93
94
95
package main
import (
"encoding/json"
"fmt"
"github.com/chaseisabelle/flagz"
"github.com/urfave/cli/v2"
)
func init() {
defineCommand(&cli.Command{
Category: "fib",
Name: "list-fib",
Usage: "List FIB entries",
Action: func(c *cli.Context) error {
return clientDoPrint(c.Context, `
{
fib {
id
name
nexthops {
id
}
strategy {
id
}
}
}
`, nil, "fib")
},
})
}
func init() {
var name, strategy, params string
var nexthops flagz.Flagz
defineCommand(&cli.Command{
Category: "fib",
Name: "insert-fib",
Usage: "Insert or replace a FIB entry",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Usage: "name `prefix`",
Destination: &name,
Required: true,
},
&cli.GenericFlag{
Name: "nh",
Usage: "FIB nexthop face `ID` (repeatable)",
Value: &nexthops,
Required: true,
},
&cli.StringFlag{
Name: "strategy",
Usage: "forwarding strategy `ID`",
Destination: &strategy,
},
&cli.StringFlag{
Name: "params",
Usage: "forwarding strategy parameters `JSON`",
Destination: ¶ms,
},
},
Action: func(c *cli.Context) error {
vars := map[string]any{
"name": name,
"nexthops": nexthops.Array(),
}
if strategy != "" {
vars["strategy"] = strategy
}
if params != "" {
var paramsJ map[string]any
if e := json.Unmarshal([]byte(params), ¶msJ); e != nil {
return fmt.Errorf("params: %w", e)
}
vars["params"] = paramsJ
}
return clientDoPrint(c.Context, `
mutation insertFibEntry($name: Name!, $nexthops: [ID!]!, $strategy: ID, $params: JSON) {
insertFibEntry(name: $name, nexthops: $nexthops, strategy: $strategy, params: $params) {
id
}
}
`, vars, "insertFibEntry")
},
})
}
func init() {
defineDeleteCommand("fib", "erase-fib", "Erase a FIB entry", "FIB entry")
}