forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface.go
267 lines (254 loc) · 6.5 KB
/
face.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package main
import (
"net"
"net/netip"
"github.com/urfave/cli/v2"
"github.com/usnistgov/ndn-dpdk/core/macaddr"
"github.com/usnistgov/ndn-dpdk/ndn/packettransport"
)
const gqlFaceCounters = "rxFrames rxInterests rxData rxNacks txFrames txInterests txData txNacks"
func createFace(c *cli.Context, loc any) error {
return clientDoPrint(c.Context, `
mutation createFace($locator: JSON!) {
createFace(locator: $locator) {
id
}
}
`, map[string]any{
"locator": loc,
}, "createFace")
}
func init() {
var withCounters bool
defineCommand(&cli.Command{
Category: "face",
Name: "list-face",
Aliases: []string{"list-faces"},
Usage: "List faces",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "cnt",
Usage: "show counters",
Destination: &withCounters,
},
},
Action: func(c *cli.Context) error {
return clientDoPrint(c.Context, `
query listFace($withCounters: Boolean!) {
faces {
id
locator
counters @include(if: $withCounters) {`+gqlFaceCounters+`}
}
}
`, map[string]any{
"withCounters": withCounters,
}, "faces")
},
})
}
func init() {
var id string
var withCounters bool
defineCommand(&cli.Command{
Category: "face",
Name: "get-face",
Usage: "Retrieve face information",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "face `ID`",
Destination: &id,
Required: true,
},
&cli.BoolFlag{
Name: "cnt",
Usage: "show counters",
Destination: &withCounters,
},
},
Action: func(c *cli.Context) error {
return clientDoPrint(c.Context, `
query getFace($id: ID!, $withCounters: Boolean!) {
face: node(id: $id) {
id
... on Face {
locator
counters @include(if: $withCounters) {`+gqlFaceCounters+`}
}
}
}
`, map[string]any{
"id": id,
"withCounters": withCounters,
}, "face")
},
})
}
func init() {
defineStdinJSONCommand(stdinJSONCommand{
Category: "face",
Name: "create-face",
Usage: "Create a face",
SchemaName: "locator",
ParamNoun: "locator",
Action: func(c *cli.Context, arg map[string]any) error {
return createFace(c, arg)
},
})
}
func init() {
var loc struct {
Scheme string `json:"scheme"`
Port string `json:"port,omitempty"`
MTU int `json:"mtu,omitempty"`
NRxQueues int `json:"nRxQueues,omitempty"`
Local macaddr.Flag `json:"local"`
Remote macaddr.Flag `json:"remote"`
VLAN int `json:"vlan,omitempty"`
LocalIP *netip.Addr `json:"localIP,omitempty"`
RemoteIP *netip.Addr `json:"remoteIP,omitempty"`
LocalUDP *int `json:"localUDP,omitempty"`
RemoteUDP *int `json:"remoteUDP,omitempty"`
VXLAN int `json:"vxlan,omitempty"`
InnerLocal *macaddr.Flag `json:"innerLocal,omitempty"`
InnerRemote *macaddr.Flag `json:"innerRemote,omitempty"`
}
loc.Remote.HardwareAddr = packettransport.MulticastAddressNDN
define := func(name, usage, scheme string, remoteRequired bool, addlFlags ...cli.Flag) {
defineCommand(&cli.Command{
Category: "face",
Name: name,
Usage: usage,
Flags: append([]cli.Flag{
&cli.StringFlag{
Name: "port",
Usage: "DPDK `port` name",
DefaultText: "search by local MAC address",
Destination: &loc.Port,
},
&cli.IntFlag{
Name: "mtu",
Usage: "face `MTU` (excluding all headers)",
DefaultText: "maximum",
Destination: &loc.MTU,
},
&cli.IntFlag{
Name: "rx-queues",
Usage: "number of RX queues",
DefaultText: "1",
Destination: &loc.NRxQueues,
},
&cli.GenericFlag{
Name: "local",
Usage: "local MAC `address`",
Value: &loc.Local,
Required: true,
},
&cli.GenericFlag{
Name: "remote",
Usage: "remote MAC `address`",
Value: &loc.Remote,
Required: remoteRequired,
},
&cli.IntFlag{
Name: "vlan",
Usage: "`VLAN` identifier",
DefaultText: "no VLAN",
Destination: &loc.VLAN,
},
}, addlFlags...),
Action: func(c *cli.Context) error {
loc.Scheme = scheme
return createFace(c, loc)
},
})
}
define("create-ether-face", "Create an Ethernet face", "ether", false)
resolveUDPFlag := func(s string) (*netip.Addr, *int, error) {
addr, e := net.ResolveUDPAddr("udp", s)
if e != nil {
return nil, nil, e
}
ip := addr.AddrPort().Addr()
return &ip, &addr.Port, nil
}
define("create-udp-face", "Create a UDP face (using EthDev)", "udpe", true,
&cli.StringFlag{
Name: "udp-local",
Usage: "local UDP `host:port`",
Required: true,
Action: func(c *cli.Context, s string) (e error) {
loc.LocalIP, loc.LocalUDP, e = resolveUDPFlag(s)
return
},
},
&cli.StringFlag{
Name: "udp-remote",
Usage: "remote UDP `host:port`",
Required: true,
Action: func(c *cli.Context, s string) (e error) {
loc.RemoteIP, loc.RemoteUDP, e = resolveUDPFlag(s)
return
},
},
)
resolveIPFlag := func(s string) (*netip.Addr, error) {
addr, e := net.ResolveIPAddr("ip", s)
if e != nil {
return nil, e
}
ip, _ := netip.AddrFromSlice(addr.IP)
return &ip, nil
}
var innerLocal, innerRemote macaddr.Flag
define("create-vxlan-face", "Create a VXLAN face", "vxlan", true,
&cli.StringFlag{
Name: "ip-local",
Usage: "local IP `host`",
Required: true,
Action: func(c *cli.Context, s string) (e error) {
loc.LocalIP, e = resolveIPFlag(s)
return
},
},
&cli.StringFlag{
Name: "ip-remote",
Usage: "remote IP `host`",
Required: true,
Action: func(c *cli.Context, s string) (e error) {
loc.RemoteIP, e = resolveIPFlag(s)
return
},
},
&cli.IntFlag{
Name: "vxlan",
Usage: "`VXLAN` virtual network identifier",
Destination: &loc.VXLAN,
Required: true,
},
&cli.GenericFlag{
Name: "inner-local",
Usage: "VXLAN inner local MAC `address`",
Value: &innerLocal,
Required: true,
Action: func(c *cli.Context, value any) error {
loc.InnerLocal = &innerLocal
return nil
},
},
&cli.GenericFlag{
Name: "inner-remote",
Usage: "VXLAN inner remote MAC `address`",
Value: &innerRemote,
Required: true,
Action: func(c *cli.Context, value any) error {
loc.InnerRemote = &innerRemote
return nil
},
},
)
}
func init() {
defineDeleteCommand("face", "destroy-face", "Destroy a face", "face")
}