1 #ifndef __CONFIG_H_
2 #define __CONFIG_H_
3 /*----------------------------------------------------------------------------*/
4 #include <sys/queue.h>
5 #include <stdint.h>
6 #include <net/if.h>
7 
8 #include "io_module.h"
9 /*----------------------------------------------------------------------------*/
10 #define WORD_LEN 20
11 #define STR_LEN  200
12 #define MOS_APP_ARGC 20
13 #define MAX_APP_BLOCK 10
14 #define MAX_MOS_BLOCK 1
15 #define MAX_ARP_ENTRY 128
16 #define MAX_ETH_ENTRY MAX_DEVICES
17 #define MAX_FORWARD_ENTRY MAX_ETH_ENTRY
18 #define MAX_ROUTE_ENTRY 128
19 #define ETH_ALEN 6
20 /*----------------------------------------------------------------------------*/
21 #define APP_BLOCK_NAME    	"application"
22 #define MOS_BLOCK_NAME    	"mos"
23 #define NETDEV_BLOCK_NAME 	"netdev"
24 #define ARP_BLOCK_NAME    	"arp_table"
25 #define ROUTE_BLOCK_NAME  	"route_table"
26 #define FORWARD_BLOCK_NAME 	"nic_forward_table"
27 /*----------------------------------------------------------------------------*/
28 struct conf_block;
29 extern int8_t end_app_exists;
30 extern int8_t mon_app_exists;
31 /*----------------------------------------------------------------------------*/
32 typedef void (*FEED)(struct conf_block *blk, char *line, int len);
33 typedef void (*ADDCHILD)(struct conf_block *blk, struct conf_block *child);
34 typedef int  (*ISVALID)(struct conf_block *blk);
35 typedef void (*PRINT)(struct conf_block *blk);
36 /*----------------------------------------------------------------------------*/
37 struct conf_block {
38 	char *name;
39 	char *buf;
40 	int len;
41 
42 	FEED feed;
43 	ADDCHILD addchild;
44 	ISVALID isvalid;
45 	PRINT print;
46 
47 	void *conf;
48 
49 	TAILQ_HEAD(, conf_block) *list;
50 
51 	TAILQ_ENTRY(conf_block) link;
52 };
53 /*----------------------------------------------------------------------------*/
54 struct netdev_entry {
55 	char dev_name[WORD_LEN];
56 	int ifindex;
57 	int stat_print;
58 	unsigned char haddr[ETH_ALEN];
59 	uint32_t netmask;
60 	uint32_t ip_addr;
61 	uint64_t cpu_mask;
62 
63 	struct ifreq ifr;
64 
65 	uint32_t gateway;
66 
67 	TAILQ_ENTRY(netdev_entry) link;
68 };
69 struct netdev_conf {
70 	int num;
71 	struct netdev_entry *ent[MAX_ETH_ENTRY];
72 
73 	TAILQ_HEAD(, netdev_entry) list;
74 };
75 /*----------------------------------------------------------------------------*/
76 struct _arp_entry {
77 	uint32_t ip;
78 	int8_t prefix;
79 	uint32_t mask;
80 	uint32_t masked_ip;
81 	uint8_t haddr[ETH_ALEN];
82 
83 	TAILQ_ENTRY(_arp_entry) link;
84 };
85 struct arp_conf {
86 	int num;
87 	struct _arp_entry *ent[MAX_ARP_ENTRY];
88 
89 	TAILQ_HEAD(, _arp_entry) list;
90 };
91 /*----------------------------------------------------------------------------*/
92 struct route_entry {
93 	uint32_t ip;
94 	int prefix;
95 	uint32_t mask;
96 	uint32_t masked_ip;
97 	int nif;
98 	char dev_name[WORD_LEN];
99 
100 	TAILQ_ENTRY(route_entry) link;
101 };
102 struct route_conf {
103 	int num;
104 	struct route_entry *ent[MAX_ROUTE_ENTRY];
105 	TAILQ_HEAD(, route_entry) list;
106 };
107 /*----------------------------------------------------------------------------*/
108 struct nic_forward_entry {
109 	char nif_in[WORD_LEN];
110 	char nif_out[WORD_LEN];
111 
112 	TAILQ_ENTRY(nic_forward_entry) link;
113 };
114 struct nic_forward_conf {
115 	int num;
116 	struct nic_forward_entry *ent[MAX_FORWARD_ENTRY];
117 	int nic_fwd_table[MAX_FORWARD_ENTRY];
118 	TAILQ_HEAD(, nic_forward_entry) list;
119 };
120 /*----------------------------------------------------------------------------*/
121 struct app_conf {
122 	char type[WORD_LEN];
123 	char run[STR_LEN];
124 	uint64_t cpu_mask;
125 	int ip_forward;
126 
127 	int app_argc;
128 	char *app_argv[MOS_APP_ARGC];
129 };
130 /*----------------------------------------------------------------------------*/
131 struct mos_conf {
132 	int num_cores;
133 	int nb_mem_channels;
134 	int max_concurrency;
135 	int no_ring_buffers;
136 	int rmem_size;
137 	int wmem_size;
138 	int tcp_tw_interval;
139 	int tcp_timeout;
140 	int multiprocess;
141 	int multiprocess_curr_core;
142 	int multiprocess_is_master;
143 	char mos_log[STR_LEN];
144 	char stat_print[STR_LEN];
145 	char port[STR_LEN];
146 	uint64_t cpu_mask;
147 	int forward;
148 
149 	struct netdev_conf *netdev_table;
150 	struct arp_conf *arp_table;
151 	struct route_conf *route_table;
152 	struct nic_forward_conf *nic_forward_table;
153 
154 	struct conf_block *netdev;
155 	struct conf_block *arp;
156 	struct conf_block *route;
157 	struct conf_block *nic_forward;
158 };
159 /*----------------------------------------------------------------------------*/
160 TAILQ_HEAD(, conf_block) g_free_blkh;
161 struct config {
162 	TAILQ_HEAD(, conf_block) app_blkh;
163 	TAILQ_HEAD(, conf_block) mos_blkh;
164 
165 	struct mos_conf *mos;
166 } g_config;
167 
168 int num_cpus;
169 int num_queues;
170 int num_devices;
171 //struct ps_device devices[MAX_DEVICES];
172 
173 int num_devices_attached;
174 int devices_attached[MAX_DEVICES];
175 /*----------------------------------------------------------------------------*/
176 int
177 LoadConfigurationUpperHalf(const char *fname);
178 
179 void
180 LoadConfigurationLowerHalf(void);
181 
182 /* set configurations from the setted
183    interface information */
184 int
185 SetInterfaceInfo();
186 
187 /* set configurations from the files */
188 int
189 SetRoutingTable();
190 
191 int
192 LoadARPTable();
193 
194 /* print setted configuration */
195 void
196 PrintConf(struct config *conf);
197 
198 /* set socket modes */
199 int
200 SetSocketMode(int8_t socket_mode);
201 
202 void
203 ParseMACAddress(unsigned char *haddr, char *haddr_str);
204 
205 int
206 ParseIPAddress(uint32_t *ip_addr, char *ip_str);
207 
208 void
209 FreeConfigResources();
210 
211 int
212 mystrtol(const char *nptr, int base);
213 
214 /* retrive device-specific endian type */
215 int
216 FetchEndianType();
217 /*----------------------------------------------------------------------------*/
218 #endif /* __CONFIG_H_ */
219