1 /* 2 * Copyright (C) 2017 THL A29 Limited, a Tencent company. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 */ 26 27 #ifndef __FSTACK_CONFIG_H 28 #define __FSTACK_CONFIG_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 // dpdk argc, argv, max argc: 16, member of dpdk_config 35 #define DPDK_CONFIG_NUM 16 36 #define DPDK_CONFIG_MAXLEN 256 37 #define DPDK_MAX_LCORE 128 38 #define PCAP_SNAP_MINLEN 94 39 #define PCAP_SAVE_MINLEN (2<<22) 40 41 extern int dpdk_argc; 42 extern char *dpdk_argv[DPDK_CONFIG_NUM + 1]; 43 44 #define MAX_PKT_BURST 32 45 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */ 46 47 struct ff_hw_features { 48 uint8_t rx_csum; 49 uint8_t rx_lro; 50 uint8_t tx_csum_ip; 51 uint8_t tx_csum_l4; 52 uint8_t tx_tso; 53 }; 54 55 struct ff_port_cfg { 56 char *name; 57 uint8_t port_id; 58 uint8_t mac[6]; 59 struct ff_hw_features hw_features; 60 char *addr; 61 char *netmask; 62 char *broadcast; 63 char *gateway; 64 65 #ifdef INET6 66 char *addr6_str; 67 char *gateway6_str; 68 uint8_t prefix_len; 69 #endif 70 71 char *pcap; 72 uint16_t snaplen; 73 uint32_t savelen; 74 75 int nb_lcores; 76 int nb_slaves; 77 uint16_t lcore_list[DPDK_MAX_LCORE]; 78 uint16_t *slave_portid_list; 79 }; 80 81 struct ff_vdev_cfg { 82 char *name; 83 char *iface; 84 char *path; 85 char *mac; 86 uint8_t vdev_id; 87 uint8_t nb_queues; 88 uint8_t nb_cq; 89 uint16_t queue_size; 90 }; 91 92 struct ff_bond_cfg { 93 char *name; 94 char *slave; 95 char *primary; 96 char *bond_mac; 97 char *xmit_policy; 98 uint8_t bond_id; 99 uint8_t mode; 100 uint8_t socket_id; 101 uint8_t lsc_poll_period_ms; 102 uint16_t up_delay; 103 uint16_t down_delay; 104 }; 105 106 struct ff_freebsd_cfg { 107 char *name; 108 char *str; 109 void *value; 110 size_t vlen; 111 struct ff_freebsd_cfg *next; 112 }; 113 114 struct ff_config { 115 char *filename; 116 struct { 117 char *proc_type; 118 /* mask of enabled lcores */ 119 char *lcore_mask; 120 /* mask of current proc on all lcores */ 121 char *proc_mask; 122 123 /* specify base virtual address to map. */ 124 char *base_virtaddr; 125 126 /* allow processes that do not want to co-operate to have different memory regions */ 127 char *file_prefix; 128 129 /* load an external driver */ 130 char *pci_whitelist; 131 132 int nb_channel; 133 int memory; 134 int no_huge; 135 int nb_procs; 136 int proc_id; 137 int promiscuous; 138 int nb_vdev; 139 int nb_bond; 140 int numa_on; 141 int tso; 142 int tx_csum_offoad_skip; 143 int vlan_strip; 144 int symmetric_rss; 145 146 /* sleep x microseconds when no pkts incomming */ 147 unsigned idle_sleep; 148 149 /* TX burst queue drain nodelay dalay time */ 150 unsigned pkt_tx_delay; 151 152 /* list of proc-lcore */ 153 uint16_t *proc_lcore; 154 155 int nb_ports; 156 uint16_t max_portid; 157 uint16_t *portid_list; 158 // MAP(portid => struct ff_port_cfg*) 159 struct ff_port_cfg *port_cfgs; 160 struct ff_vdev_cfg *vdev_cfgs; 161 struct ff_bond_cfg *bond_cfgs; 162 } dpdk; 163 164 struct { 165 int enable; 166 char *kni_action; 167 char *method; 168 char *tcp_port; 169 char *udp_port; 170 } kni; 171 172 struct { 173 int level; 174 const char *dir; 175 } log; 176 177 struct { 178 struct ff_freebsd_cfg *boot; 179 struct ff_freebsd_cfg *sysctl; 180 long physmem; 181 int hz; 182 int fd_reserve; 183 int mem_size; 184 } freebsd; 185 186 struct { 187 uint16_t enable; 188 uint16_t snap_len; 189 uint32_t save_len; 190 char* save_path; 191 } pcap; 192 }; 193 194 extern struct ff_config ff_global_cfg; 195 196 int ff_load_config(int argc, char * const argv[]); 197 198 #ifdef __cplusplus 199 } 200 #endif 201 202 #endif /* ifndef __FSTACK_CONFIG_H */ 203