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 149ipv6 150netgraph 151ipsec 152``` 153 154For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?netstat). 155 156# ngctl 157Usage: 158``` 159ngctl -p <f-stack proc_id> [-d] [-f file] [-n name] [command ...] 160``` 161 162About interactive mode: 163- if you have `libedit` in your system, you can turn on `MK_HAVE_LIBEDIT` in `opts.mk`, 164 the interactive mode will support generic line editing, history functions. 165 166 167For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?ngctl). 168 169# ipfw 170Usage: 171``` 172ipfw -P <f-stack proc_id> [-abcdefhnNqStTv] <command> 173 174where <command> is one of the following: 175 176add [num] [set N] [prob x] RULE-BODY 177{pipe|queue} N config PIPE-BODY 178[pipe|queue] {zero|delete|show} [N{,N}] 179nat N config {ip IPADDR|if IFNAME|log|deny_in|same_ports|unreg_only|reset| 180 reverse|proxy_only|redirect_addr linkspec| 181 redirect_port linkspec|redirect_proto linkspec} 182set [disable N... enable N...] | move [rule] X to Y | swap X Y | show 183set N {show|list|zero|resetlog|delete} [N{,N}] | flush 184table N {add ip[/bits] [value] | delete ip[/bits] | flush | list} 185table all {flush | list} 186 187RULE-BODY: check-state [PARAMS] | ACTION [PARAMS] ADDR [OPTION_LIST] 188ACTION: check-state | allow | count | deny | unreach{,6} CODE | 189 skipto N | {divert|tee} PORT | forward ADDR | 190 pipe N | queue N | nat N | setfib FIB | reass 191PARAMS: [log [logamount LOGLIMIT]] [altq QUEUE_NAME] 192ADDR: [ MAC dst src ether_type ] 193 [ ip from IPADDR [ PORT ] to IPADDR [ PORTLIST ] ] 194 [ ipv6|ip6 from IP6ADDR [ PORT ] to IP6ADDR [ PORTLIST ] ] 195IPADDR: [not] { any | me | ip/bits{x,y,z} | table(t[,v]) | IPLIST } 196IP6ADDR: [not] { any | me | me6 | ip6/bits | IP6LIST } 197IP6LIST: { ip6 | ip6/bits }[,IP6LIST] 198IPLIST: { ip | ip/bits | ip:mask }[,IPLIST] 199OPTION_LIST: OPTION [OPTION_LIST] 200OPTION: bridged | diverted | diverted-loopback | diverted-output | 201 {dst-ip|src-ip} IPADDR | {dst-ip6|src-ip6|dst-ipv6|src-ipv6} IP6ADDR | 202 {dst-port|src-port} LIST | 203 estab | frag | {gid|uid} N | icmptypes LIST | in | out | ipid LIST | 204 iplen LIST | ipoptions SPEC | ipprecedence | ipsec | iptos SPEC | 205 ipttl LIST | ipversion VER | keep-state | layer2 | limit ... | 206 icmp6types LIST | ext6hdr LIST | flow-id N[,N] | fib FIB | 207 mac ... | mac-type LIST | proto LIST | {recv|xmit|via} {IF|IPADDR} | 208 setup | {tcpack|tcpseq|tcpwin} NN | tcpflags SPEC | tcpoptions SPEC | 209 tcpdatalen LIST | verrevpath | versrcreach | antispoof 210``` 211Note [dummynet](https://www.freebsd.org/cgi/man.cgi?query=dummynet) is not supported yet. 212 213For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?ipfw) or [handbook](https://www.freebsd.org/doc/handbook/firewalls-ipfw.html). 214 215# arp 216Usage 217``` 218usage: arp -p <f-stack proc_id> [-n] [-i interface] hostname 219 arp -p <f-stack proc_id> [-n] [-i interface] -a 220 arp -p <f-stack proc_id> -d hostname [pub] 221 arp -p <f-stack proc_id> -d [-i interface] -a 222 arp -p <f-stack proc_id> -s hostname ether_addr [temp] [reject | blackhole] [pub [only]] 223 arp -p <f-stack proc_id> -S hostname ether_addr [temp] [reject | blackhole] [pub [only]] 224 arp -p <f-stack proc_id> -f filename 225``` 226 227For more details, see [Manual page](https://www.freebsd.org/cgi/man.cgi?arp). 228 229# traffic 230Usage: 231``` 232traffic [-p <f-stack proc_id>] [-d <secs>] [-n num] 233``` 234Examples: 235``` 236./sbin/traffic 237 238|--------------------|--------------------|--------------------|--------------------| 239| rx packets| rx bytes| tx packets| tx bytes| 240|--------------------|--------------------|--------------------|--------------------| 241| 0| 0| 0| 0| 242| 298017| 30590860| 590912| 230712836| 243| 475808| 49008224| 951616| 372081856| 244| 474720| 48896160| 949440| 371231040| 245| 475296| 48955488| 950592| 371681472| 246| 475040| 48929120| 950080| 371481280| 247| 474368| 48859904| 948736| 370955776| 248| 475616| 48988448| 951232| 371931712| 249| 475552| 48981856| 951104| 371881664| 250| 476128| 49041184| 952256| 372332096| 251| 475680| 48995040| 951360| 371981760| 252| 475552| 48981856| 951104| 371881664| 253| 475488| 48975264| 950976| 371831616| 254| 473440| 48764320| 946880| 370230080| 255``` 256 257# how to implement a custom tool for communicating with F-Stack process 258 259Add a new FF_MSG_TYPE in ff_msg.h: 260``` 261enum FF_MSG_TYPE { 262 FF_UNKNOWN = 0, 263 FF_SYSCTL, 264 FF_HELLOWORLD, 265}; 266``` 267 268Define a structure used to communicate: 269``` 270struct ff_helloworld_args { 271 void *request; 272 size_t req_len; 273 void *reply; 274 size_t rep_len; 275}; 276``` 277Note 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)). 278 279And add it to ff_msg: 280``` 281struct ff_msg { 282 ... 283 union { 284 struct ff_sysctl_args sysctl; 285 struct ff_helloworld_args helloworld; 286 }; 287}; 288``` 289 290Modify ff_dpdk_if.c, add a handle function: 291``` 292static inline void 293handle_helloworld_msg(struct ff_msg *msg, uint16_t proc_id) 294{ 295 printf("helloworld msg recved.\n"); 296 msg->result = 0; 297 rte_ring_enqueue(msg_ring[proc_id].ring[1], msg); 298} 299 300static inline void 301handle_msg(struct ff_msg *msg, uint16_t proc_id) 302{ 303 switch (msg->msg_type) { 304 case FF_SYSCTL: 305 handle_sysctl_msg(msg, proc_id); 306 break; 307 case FF_HELLOWORLD: 308 handle_helloworld_msg(msg, proc_id); 309 default: 310 handle_default_msg(msg, proc_id); 311 break; 312 } 313} 314``` 315 316Create helloworld.c: 317 318``` 319int main() 320{ 321 struct ff_msg *msg = ff_ipc_msg_alloc(); 322 323 char *buf = msg->buf_addr; 324 325 msg->helloworld.request = buf; 326 memcpy(msg->helloworld.request, "hello", 5); 327 msg->helloworld.req_len = 5; 328 buf += 5; 329 330 msg->helloworld.reply = buf; 331 msg->helloworld.rep_len = 10; 332 333 ff_ipc_send(msg, 0); 334 335 struct ff_msg *retmsg; 336 ff_ipc_recv(retmsg, 0); 337 assert(remsg==msg); 338 339 ff_ipc_msg_free(msg); 340} 341 342``` 343 344The Makefile may like this: 345``` 346TOPDIR?=${CURDIR}/../.. 347 348PROG=helloworld 349 350include ${TOPDIR}/tools/prog.mk 351``` 352