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