forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethdev.go
164 lines (157 loc) · 3.47 KB
/
ethdev.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
package main
import (
"errors"
"github.com/urfave/cli/v2"
)
const gqlEthDevFields = "id name numaSocket macAddr mtu isDown"
func init() {
var withDevInfo, withStats, withFaces bool
defineCommand(&cli.Command{
Category: "ethdev",
Name: "list-ethdev",
Aliases: []string{"list-ethdevs"},
Usage: "List Ethernet devices",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "devinfo",
Usage: "show DPDK device information",
Destination: &withDevInfo,
},
&cli.BoolFlag{
Name: "stats",
Usage: "show hardware statistics",
Destination: &withStats,
},
&cli.BoolFlag{
Name: "faces",
Usage: "show face list",
Destination: &withFaces,
},
},
Action: func(c *cli.Context) error {
return clientDoPrint(c.Context, `
query listEthDev(
$withDevInfo: Boolean!
$withStats: Boolean!
$withFaces: Boolean!
) {
ethDevs {
`+gqlEthDevFields+`
devInfo @include(if: $withDevInfo)
stats @include(if: $withStats)
faces @include(if: $withFaces) {
id
locator
}
}
}
`, map[string]any{
"withDevInfo": withDevInfo,
"withStats": withStats,
"withFaces": withFaces,
}, "ethDevs")
},
})
}
func init() {
defineCommand(&cli.Command{
Category: "ethdev",
Name: "create-eth-port",
Usage: "Create an Ethernet port",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "pci",
Usage: "use PCI driver with `PCI address`",
},
&cli.StringFlag{
Name: "netif",
Usage: "network `interface` name",
},
&cli.BoolFlag{
Name: "xdp",
Usage: "use XDP driver on netif",
DefaultText: "use AF_PACKET driver",
},
&cli.UintFlag{
Name: "mtu",
Usage: "set interface `MTU`",
DefaultText: "unchanged",
},
&cli.UintFlag{
Name: "rx-flow",
Usage: "enable RxFlow with specified number of `queues`",
DefaultText: "disable RxFlow",
},
},
Action: func(c *cli.Context) error {
vars := map[string]any{
"driver": "AF_PACKET",
}
switch {
case c.IsSet("pci"):
vars["driver"] = "PCI"
vars["pciAddr"] = c.String("pci")
case c.Bool("xdp"):
vars["driver"] = "XDP"
fallthrough
default:
if c.IsSet("netif") {
vars["netif"] = c.String("netif")
} else {
return errors.New("either --pci or --netif must be set")
}
}
if c.IsSet("mtu") {
vars["mtu"] = c.Uint("mtu")
}
if c.IsSet("rx-flow") {
vars["rxFlowQueues"] = c.Uint("rx-flow")
}
return clientDoPrint(c.Context, `
mutation createEthPort(
$driver: NetifDriverKind!
$pciAddr: String
$netif: String
$mtu: Int
$rxFlowQueues: Int
) {
createEthPort(
driver: $driver
pciAddr: $pciAddr
netif: $netif
mtu: $mtu
rxFlowQueues: $rxFlowQueues
) {`+gqlEthDevFields+`}
}
`, vars, "createEthPort")
},
})
}
func init() {
var id string
defineCommand(&cli.Command{
Category: "ethdev",
Name: "reset-eth-stats",
Usage: "Reset hardware statistics of an Ethernet device",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "id",
Usage: "device `ID`",
Destination: &id,
Required: true,
},
},
Action: func(c *cli.Context) error {
return clientDoPrint(c.Context, `
mutation resetEthStats($id: ID!) {
resetEthStats(id: $id) {
id
name
}
}
`, map[string]any{
"id": id,
}, "resetEthStats")
},
})
}