xref: /f-stack/tools/README.md (revision 03df98de)
1# Introduction
2
3Directory `compat` implements an ipc library using dpdk `rte_ring` and ports some source files compatible with FreeBSD and Linux.
4
5All other directories are useful tools ported from FreeBSD.
6Since F-Stack is multi-process architecture and every process has an independent stack, so we must communicate with every F-Stack process.
7Each tool add an option `-p`(Which F-Stack process to communicate with, default 0), except that, it is same with the original FreeBSD.
8
9Note that these tools must be executed serially.
10
11# sysctl
12Usage:
13```
14sysctl -p <f-stack proc_id> [-bdehiNnoqTtWx] [ -B <bufsize> ] [-f filename] name[=value] ...
15sysctl -p <f-stack proc_id> [-bdehNnoqTtWx] [ -B <bufsize> ] -a
16```
17For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?sysctl).
18
19# ifconfig
20Usage:
21```
22ifconfig -p <f-stack proc_id> [-f type:format] %sinterface address_family
23        [address [dest_address]] [parameters]
24    ifconfig -p <f-stack proc_id> interface create
25    ifconfig -p <f-stack proc_id> -a %s[-d] [-m] [-u] [-v] [address_family]
26    ifconfig -p <f-stack proc_id> -l [-d] [-u] [address_family]
27    ifconfig -p <f-stack proc_id> %s[-d] [-m] [-u] [-v]
28```
29Unsupported interfaces or parameters:
30```
31inet6
32MAC(Mandatory Access Control)
33media
34SFP/SFP+
35IEEE80211 Wireless
36pfsync
37LAGG LACP
38jail
39```
40For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?ifconfig).
41
42# route
43Usage:
44```
45route -p <f-stack proc_id> [-46dnqtv] command [[modifiers] args]
46```
47Examples:
48```
49     Add a default route:
50
51       ./route -p 0 add -net 0.0.0.0/0 192.168.1.1
52
53     A shorter version of adding a default route can also be written as:
54
55       ./route -p 0 add default 192.168.1.1
56
57     Add a static route to the 172.16.10.0/24 network via the 172.16.1.1 gate-
58     way:
59
60       ./route -p 0 add -net 172.16.10.0/24 172.16.1.1
61
62     Change the gateway of an already established static route in the routing
63     table:
64
65       ./route -p 0 change -net 172.16.10.0/24 172.16.1.2
66
67     Display the route for a destination network:
68
69       ./route -p 0 show 172.16.10.0
70
71     Delete a static route from the routing table:
72
73       ./route -p 0 delete -net 172.16.10.0/24 172.16.1.2
74
75     Remove all routes from the routing table:
76
77       ./route -p 0 flush
78
79    FreeBSD uses `netstat -rn ` to list the route table which we havn't ported,
80    you can execute the following command instead, `-d` means debug mode, `-v`
81    means verbose.
82        ./route -p 0 -d -v flush
83```
84Note that, if you want to modify the route table, you must use `-p` to execute the same command for each f-stack process.
85
86For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?route).
87
88# top
89Usage:
90```
91top [-p <f-stack proc_id>] [-d <secs>] [-n num]
92```
93Examples:
94```
95./tools/top/top
96
97|---------|---------|---------|---------------|
98|     idle|      sys|      usr|           loop|
99|---------|---------|---------|---------------|
100|   99.69%|    0.00%|    0.31%|        8214640|
101|   99.77%|    0.00%|    0.23%|        8205713|
102|    5.02%|   45.19%|   49.79%|         769435|
103|    0.00%|   19.88%|   80.12%|            393|
104|    0.00%|   20.28%|   79.72%|            395|
105|    0.00%|   15.50%|   84.50%|            403|
106|    0.00%|   31.31%|   68.69%|            427|
107|   32.07%|    8.78%|   59.15%|        2342862|
108|   99.79%|    0.00%|    0.21%|        9974439|
109|   99.81%|    0.00%|    0.19%|        7336153|
110|   99.79%|    0.00%|    0.21%|        8147676|
111```
112
113# netstat
114Usage:
115```
116   netstat -P <f-stack proc_id> [-46AaLnRSTWx] [-f protocol_family | -p protocol]
117   netstat -P <f-stack proc_id> -i | -I interface [-46abdhnW] [-f address_family]
118   netstat -P <f-stack proc_id> -w wait [-I interface] [-46d] [-q howmany]
119   netstat -P <f-stack proc_id> -s [-46sz] [-f protocol_family | -p protocol]
120   netstat -P <f-stack proc_id> -i | -I interface -s [-46s]
121           [-f protocol_family | -p protocol]
122   netstat -P <f-stack proc_id> -B [-z] [-I interface]
123   netstat -P <f-stack proc_id> -r [-46AnW] [-F fibnum] [-f address_family]
124   netstat -P <f-stack proc_id> -rs [-s]
125   netstat -P <f-stack proc_id> -g [-46W] [-f address_family]
126   netstat -P <f-stack proc_id> -gs [-46s] [-f address_family]
127   netstat -P <f-stack proc_id> -Q
128```
129
130Unsupported commands or features:
131```
132-M
133-N
134-m
135ipv6
136netgraph
137ipsec
138```
139
140For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?netstat).
141
142# ngctl
143Usage:
144```
145ngctl -p <f-stack proc_id>  [-d] [-f file] [-n name] [command ...]
146```
147
148About interactive mode:
149- if you have `libedit` in your system, you can turn on `MK_HAVE_LIBEDIT` in `opts.mk`,
150  the interactive mode will support generic line editing, history functions.
151
152
153For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?ngctl).
154
155# ipfw
156Usage:
157```
158ipfw -P <f-stack proc_id> [-abcdefhnNqStTv] <command>
159
160where <command> is one of the following:
161
162add [num] [set N] [prob x] RULE-BODY
163{pipe|queue} N config PIPE-BODY
164[pipe|queue] {zero|delete|show} [N{,N}]
165nat N config {ip IPADDR|if IFNAME|log|deny_in|same_ports|unreg_only|reset|
166                reverse|proxy_only|redirect_addr linkspec|
167                redirect_port linkspec|redirect_proto linkspec}
168set [disable N... enable N...] | move [rule] X to Y | swap X Y | show
169set N {show|list|zero|resetlog|delete} [N{,N}] | flush
170table N {add ip[/bits] [value] | delete ip[/bits] | flush | list}
171table all {flush | list}
172
173RULE-BODY:      check-state [PARAMS] | ACTION [PARAMS] ADDR [OPTION_LIST]
174ACTION: check-state | allow | count | deny | unreach{,6} CODE |
175               skipto N | {divert|tee} PORT | forward ADDR |
176               pipe N | queue N | nat N | setfib FIB | reass
177PARAMS:         [log [logamount LOGLIMIT]] [altq QUEUE_NAME]
178ADDR:           [ MAC dst src ether_type ]
179                [ ip from IPADDR [ PORT ] to IPADDR [ PORTLIST ] ]
180                [ ipv6|ip6 from IP6ADDR [ PORT ] to IP6ADDR [ PORTLIST ] ]
181IPADDR: [not] { any | me | ip/bits{x,y,z} | table(t[,v]) | IPLIST }
182IP6ADDR:        [not] { any | me | me6 | ip6/bits | IP6LIST }
183IP6LIST:        { ip6 | ip6/bits }[,IP6LIST]
184IPLIST: { ip | ip/bits | ip:mask }[,IPLIST]
185OPTION_LIST:    OPTION [OPTION_LIST]
186OPTION: bridged | diverted | diverted-loopback | diverted-output |
187        {dst-ip|src-ip} IPADDR | {dst-ip6|src-ip6|dst-ipv6|src-ipv6} IP6ADDR |
188        {dst-port|src-port} LIST |
189        estab | frag | {gid|uid} N | icmptypes LIST | in | out | ipid LIST |
190        iplen LIST | ipoptions SPEC | ipprecedence | ipsec | iptos SPEC |
191        ipttl LIST | ipversion VER | keep-state | layer2 | limit ... |
192        icmp6types LIST | ext6hdr LIST | flow-id N[,N] | fib FIB |
193        mac ... | mac-type LIST | proto LIST | {recv|xmit|via} {IF|IPADDR} |
194        setup | {tcpack|tcpseq|tcpwin} NN | tcpflags SPEC | tcpoptions SPEC |
195        tcpdatalen LIST | verrevpath | versrcreach | antispoof
196```
197Note [dummynet](https://www.freebsd.org/cgi/man.cgi?query=dummynet) is not supported yet.
198
199For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?ipfw) or [handbook](https://www.freebsd.org/doc/handbook/firewalls-ipfw.html).
200
201# arp
202Usage
203```
204usage: arp -p <f-stack proc_id> [-n] [-i interface] hostname
205       arp -p <f-stack proc_id> [-n] [-i interface] -a
206       arp -p <f-stack proc_id> -d hostname [pub]
207       arp -p <f-stack proc_id> -d [-i interface] -a
208       arp -p <f-stack proc_id> -s hostname ether_addr [temp] [reject | blackhole] [pub [only]]
209       arp -p <f-stack proc_id> -S hostname ether_addr [temp] [reject | blackhole] [pub [only]]
210       arp -p <f-stack proc_id> -f filename
211```
212
213For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?arp).
214
215# traffic
216Usage:
217```
218traffic [-p <f-stack proc_id>] [-d <secs>] [-n num]
219```
220Examples:
221```
222./tools/traffic/traffic
223
224|--------------------|--------------------|--------------------|--------------------|
225|          rx packets|            rx bytes|          tx packets|            tx bytes|
226|--------------------|--------------------|--------------------|--------------------|
227|                   0|                   0|                   0|                   0|
228|              298017|            30590860|              590912|           230712836|
229|              475808|            49008224|              951616|           372081856|
230|              474720|            48896160|              949440|           371231040|
231|              475296|            48955488|              950592|           371681472|
232|              475040|            48929120|              950080|           371481280|
233|              474368|            48859904|              948736|           370955776|
234|              475616|            48988448|              951232|           371931712|
235|              475552|            48981856|              951104|           371881664|
236|              476128|            49041184|              952256|           372332096|
237|              475680|            48995040|              951360|           371981760|
238|              475552|            48981856|              951104|           371881664|
239|              475488|            48975264|              950976|           371831616|
240|              473440|            48764320|              946880|           370230080|
241```
242
243# how to implement a custom tool for communicating with F-Stack process
244
245Add a new FF_MSG_TYPE in ff_msg.h:
246```
247enum FF_MSG_TYPE {
248    FF_UNKNOWN = 0,
249    FF_SYSCTL,
250    FF_HELLOWORLD,
251};
252```
253
254Define a structure used to communicate:
255```
256struct ff_helloworld_args {
257    void *request;
258    size_t req_len;
259    void *reply;
260    size_t rep_len;
261};
262```
263Note that, when using struct ff_helloworld_args, pointers in this structure must point to the addresses range from ff_msg.buf_addr and ff_msg.buf_addr+ff_msg.buf_len, ff_msg.buf_len is (10240 - sizeof(struct ff_msg)).
264
265And add it to ff_msg:
266```
267struct ff_msg {
268    ...
269    union {
270        struct ff_sysctl_args sysctl;
271        struct ff_helloworld_args helloworld;
272    };
273};
274```
275
276Modify ff_dpdk_if.c, add a handle function:
277```
278static inline void
279handle_helloworld_msg(struct ff_msg *msg, uint16_t proc_id)
280{
281    printf("helloworld msg recved.\n");
282    msg->result = 0;
283    rte_ring_enqueue(msg_ring[proc_id].ring[1], msg);
284}
285
286static inline void
287handle_msg(struct ff_msg *msg, uint16_t proc_id)
288{
289    switch (msg->msg_type) {
290        case FF_SYSCTL:
291            handle_sysctl_msg(msg, proc_id);
292            break;
293        case FF_HELLOWORLD:
294            handle_helloworld_msg(msg, proc_id);
295        default:
296            handle_default_msg(msg, proc_id);
297            break;
298    }
299}
300```
301
302Create helloworld.c:
303
304```
305int main()
306{
307    struct ff_msg *msg = ff_ipc_msg_alloc();
308
309    char *buf = msg->buf_addr;
310
311    msg->helloworld.request = buf;
312    memcpy(msg->helloworld.request, "hello", 5);
313    msg->helloworld.req_len = 5;
314    buf += 5;
315
316    msg->helloworld.reply = buf;
317    msg->helloworld.rep_len = 10;
318
319    ff_ipc_send(msg, 0);
320
321    struct ff_msg *retmsg;
322    ff_ipc_recv(retmsg, 0);
323    assert(remsg==msg);
324
325    ff_ipc_msg_free(msg);
326}
327
328```
329
330The Makefile may like this:
331```
332TOPDIR?=${CURDIR}/../..
333
334PROG=helloworld
335
336include ${TOPDIR}/tools/prog.mk
337```
338