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# how to implement a custom tool for communicating with F-Stack process 89 90Add a new FF_MSG_TYPE in ff_msg.h: 91``` 92enum FF_MSG_TYPE { 93 FF_UNKNOWN = 0, 94 FF_SYSCTL, 95 FF_HELLOWORLD, 96}; 97``` 98 99Define a structure used to communicate: 100``` 101struct ff_helloworld_args { 102 void *request; 103 size_t req_len; 104 void *reply; 105 size_t rep_len; 106}; 107``` 108Note 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)). 109 110And add it to ff_msg: 111``` 112struct ff_msg { 113 ... 114 union { 115 struct ff_sysctl_args sysctl; 116 struct ff_helloworld_args helloworld; 117 }; 118}; 119``` 120 121Modify ff_dpdk_if.c, add a handle function: 122``` 123static inline void 124handle_helloworld_msg(struct ff_msg *msg, uint16_t proc_id) 125{ 126 printf("helloworld msg recved.\n"); 127 msg->result = 0; 128 rte_ring_enqueue(msg_ring[proc_id].ring[1], msg); 129} 130 131static inline void 132handle_msg(struct ff_msg *msg, uint16_t proc_id) 133{ 134 switch (msg->msg_type) { 135 case FF_SYSCTL: 136 handle_sysctl_msg(msg, proc_id); 137 break; 138 case FF_HELLOWORLD: 139 handle_helloworld_msg(msg, proc_id); 140 default: 141 handle_default_msg(msg, proc_id); 142 break; 143 } 144} 145``` 146 147Create helloworld.c: 148 149``` 150int main() 151{ 152 struct ff_msg *msg = ff_ipc_msg_alloc(); 153 154 char *buf = msg->buf_addr; 155 156 msg->helloworld.request = buf; 157 memcpy(msg->helloworld.request, "hello", 5); 158 msg->helloworld.req_len = 5; 159 buf += 5; 160 161 msg->helloworld.reply = buf; 162 msg->helloworld.rep_len = 10; 163 164 ff_ipc_send(msg, 0); 165 166 struct ff_msg *retmsg; 167 ff_ipc_recv(retmsg, 0); 168 assert(remsg==msg); 169 170 ff_ipc_msg_free(msg); 171} 172 173``` 174 175The Makefile may like this: 176``` 177TOPDIR?=${CURDIR}/../.. 178 179PROG=helloworld 180 181include ${TOPDIR}/tools/prog.mk 182``` 183