1 /* 2 * Copyright (C) 2017-2021 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 #define VIP_MAX_NUM 64 48 49 struct ff_hw_features { 50 uint8_t rx_csum; 51 uint8_t rx_lro; 52 uint8_t tx_csum_ip; 53 uint8_t tx_csum_l4; 54 uint8_t tx_tso; 55 }; 56 57 struct ff_port_cfg { 58 char *name; 59 uint8_t port_id; 60 uint8_t mac[6]; 61 struct ff_hw_features hw_features; 62 char *addr; 63 char *netmask; 64 char *broadcast; 65 char *gateway; 66 67 char *vip_ifname; 68 char *vip_addr_str; 69 char **vip_addr_array; 70 uint32_t nb_vip; 71 72 #ifdef INET6 73 char *addr6_str; 74 char *gateway6_str; 75 uint8_t prefix_len; 76 77 char *vip_addr6_str; 78 char **vip_addr6_array; 79 uint32_t nb_vip6; 80 uint8_t vip_prefix_len; 81 #endif 82 83 int nb_lcores; 84 int nb_slaves; 85 uint16_t lcore_list[DPDK_MAX_LCORE]; 86 uint16_t *slave_portid_list; 87 }; 88 89 struct ff_vdev_cfg { 90 char *name; 91 char *iface; 92 char *path; 93 char *mac; 94 uint8_t vdev_id; 95 uint8_t nb_queues; 96 uint8_t nb_cq; 97 uint16_t queue_size; 98 }; 99 100 struct ff_bond_cfg { 101 char *name; 102 char *slave; 103 char *primary; 104 char *bond_mac; 105 char *xmit_policy; 106 uint8_t bond_id; 107 uint8_t mode; 108 uint8_t socket_id; 109 uint8_t lsc_poll_period_ms; 110 uint16_t up_delay; 111 uint16_t down_delay; 112 }; 113 114 struct ff_freebsd_cfg { 115 char *name; 116 char *str; 117 void *value; 118 size_t vlen; 119 struct ff_freebsd_cfg *next; 120 }; 121 122 struct ff_config { 123 char *filename; 124 struct { 125 char *proc_type; 126 /* mask of enabled lcores */ 127 char *lcore_mask; 128 /* mask of current proc on all lcores */ 129 char *proc_mask; 130 131 /* specify base virtual address to map. */ 132 char *base_virtaddr; 133 134 /* allow processes that do not want to co-operate to have different memory regions */ 135 char *file_prefix; 136 137 /* load an external driver */ 138 char *pci_whitelist; 139 140 int nb_channel; 141 int memory; 142 int no_huge; 143 int nb_procs; 144 int proc_id; 145 int promiscuous; 146 int nb_vdev; 147 int nb_bond; 148 int numa_on; 149 int tso; 150 int tx_csum_offoad_skip; 151 int vlan_strip; 152 int symmetric_rss; 153 154 /* sleep x microseconds when no pkts incomming */ 155 unsigned idle_sleep; 156 157 /* TX burst queue drain nodelay dalay time */ 158 unsigned pkt_tx_delay; 159 160 /* list of proc-lcore */ 161 uint16_t *proc_lcore; 162 163 int nb_ports; 164 uint16_t max_portid; 165 uint16_t *portid_list; 166 // MAP(portid => struct ff_port_cfg*) 167 struct ff_port_cfg *port_cfgs; 168 struct ff_vdev_cfg *vdev_cfgs; 169 struct ff_bond_cfg *bond_cfgs; 170 } dpdk; 171 172 struct { 173 int enable; 174 char *kni_action; 175 char *method; 176 char *tcp_port; 177 char *udp_port; 178 } kni; 179 180 struct { 181 int level; 182 const char *dir; 183 } log; 184 185 struct { 186 struct ff_freebsd_cfg *boot; 187 struct ff_freebsd_cfg *sysctl; 188 long physmem; 189 int hz; 190 int fd_reserve; 191 int mem_size; 192 } freebsd; 193 194 struct { 195 uint16_t enable; 196 uint16_t snap_len; 197 uint32_t save_len; 198 char* save_path; 199 } pcap; 200 }; 201 202 extern struct ff_config ff_global_cfg; 203 204 int ff_load_config(int argc, char * const argv[]); 205 206 #ifdef __cplusplus 207 } 208 #endif 209 210 #endif /* ifndef __FSTACK_CONFIG_H */ 211