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