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