gateway: Created common code for routing in gateway
[samplevnf.git] / common / vnf_common / config_check.c
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include <stdio.h>
18
19 #include <rte_ip.h>
20
21 #include "app.h"
22 //uint8_t g_n_hwq_in = N_RXQ;
23 uint8_t g_n_hwq_in;
24 static void
25 check_mempools(struct app_params *app)
26 {
27         uint32_t i;
28
29         for (i = 0; i < app->n_mempools; i++) {
30                 struct app_mempool_params *p = &app->mempool_params[i];
31
32                 APP_CHECK((p->pool_size > 0),
33                         "Mempool %s size is 0\n", p->name);
34
35                 APP_CHECK((p->cache_size > 0),
36                         "Mempool %s cache size is 0\n", p->name);
37
38                 APP_CHECK(rte_is_power_of_2(p->cache_size),
39                         "Mempool %s cache size not a power of 2\n", p->name);
40         }
41 }
42
43 static void
44 check_links(struct app_params *app)
45 {
46         uint32_t i;
47
48         /* Check that number of links matches the port mask */
49         if (app->port_mask) {
50                 uint32_t n_links_port_mask =
51                         __builtin_popcountll(app->port_mask);
52
53                 APP_CHECK((app->n_links == n_links_port_mask),
54                         "Not enough links provided in the PORT_MASK\n");
55         }
56
57         for (i = 0; i < app->n_links; i++) {
58                 struct app_link_params *link = &app->link_params[i];
59                 uint32_t rxq_max, n_rxq, n_txq, link_id, i;
60
61                 APP_PARAM_GET_ID(link, "LINK", link_id);
62
63                 /* Check that link RXQs are contiguous */
64                 rxq_max = 0;
65                 if (link->arp_q > rxq_max)
66                         rxq_max = link->arp_q;
67                 if (link->tcp_syn_q > rxq_max)
68                         rxq_max = link->tcp_syn_q;
69                 if (link->ip_local_q > rxq_max)
70                         rxq_max = link->ip_local_q;
71                 if (link->tcp_local_q > rxq_max)
72                         rxq_max = link->tcp_local_q;
73                 if (link->udp_local_q > rxq_max)
74                         rxq_max = link->udp_local_q;
75                 if (link->sctp_local_q > rxq_max)
76                         rxq_max = link->sctp_local_q;
77
78 if(enable_hwlb || enable_flow_dir){
79         g_n_hwq_in = app->n_hwlb_q;
80         rxq_max = (g_n_hwq_in - 1);
81         for (i = g_n_hwq_in; i <= rxq_max; i++)
82                         APP_CHECK(((link->arp_q == i) ||
83                                 (link->tcp_syn_q == i) ||
84                                 (link->ip_local_q == i) ||
85                                 (link->tcp_local_q == i) ||
86                                 (link->udp_local_q == i) ||
87                                 (link->sctp_local_q == i)),
88                                 "%s RXQs are not contiguous (A)\n", link->name);
89
90 }
91 else{
92                 for (i = 1; i <= rxq_max; i++)
93                         APP_CHECK(((link->arp_q == i) ||
94                                 (link->tcp_syn_q == i) ||
95                                 (link->ip_local_q == i) ||
96                                 (link->tcp_local_q == i) ||
97                                 (link->udp_local_q == i) ||
98                                 (link->sctp_local_q == i)),
99                                 "%s RXQs are not contiguous (A)\n", link->name);
100 }
101                 n_rxq = app_link_get_n_rxq(app, link);
102
103                 APP_CHECK((n_rxq), "%s does not have any RXQ\n", link->name);
104                 printf("n_rxq = %d\n",n_rxq);
105                 printf("rxq_max = %d\n",rxq_max);
106                 //APP_CHECK((n_rxq == rxq_max + 1),
107                 //      "%s RXQs are not contiguous (B)\n", link->name);
108
109                 for (i = 0; i < n_rxq; i++) {
110                         char name[APP_PARAM_NAME_SIZE];
111                         int pos;
112
113                         sprintf(name, "RXQ%" PRIu32 ".%" PRIu32,
114                                 link_id, i);
115                         pos = APP_PARAM_FIND(app->hwq_in_params, name);
116                         APP_CHECK((pos >= 0),
117                                 "%s RXQs are not contiguous (C)\n", link->name);
118                 }
119
120                 /* Check that link RXQs are contiguous */
121                 n_txq = app_link_get_n_txq(app, link);
122
123                 APP_CHECK((n_txq),  "%s does not have any TXQ\n", link->name);
124
125                 for (i = 0; i < n_txq; i++) {
126                         char name[APP_PARAM_NAME_SIZE];
127                         int pos;
128
129                         sprintf(name, "TXQ%" PRIu32 ".%" PRIu32,
130                                 link_id, i);
131                         pos = APP_PARAM_FIND(app->hwq_out_params, name);
132                         APP_CHECK((pos >= 0),
133                                 "%s TXQs are not contiguous\n", link->name);
134                 }
135         }
136 }
137
138 static void
139 check_rxqs(struct app_params *app)
140 {
141         uint32_t i;
142
143         for (i = 0; i < app->n_pktq_hwq_in; i++) {
144                 struct app_pktq_hwq_in_params *p = &app->hwq_in_params[i];
145                 uint32_t n_readers = app_rxq_get_readers(app, p);
146
147                 APP_CHECK((p->size > 0),
148                         "%s size is 0\n", p->name);
149
150                 APP_CHECK((rte_is_power_of_2(p->size)),
151                         "%s size is not a power of 2\n", p->name);
152
153                 APP_CHECK((p->burst > 0),
154                         "%s burst size is 0\n", p->name);
155
156                 APP_CHECK((p->burst <= p->size),
157                         "%s burst size is bigger than its size\n", p->name);
158
159                 APP_CHECK((n_readers != 0),
160                         "%s has no reader\n", p->name);
161
162                 APP_CHECK((n_readers == 1),
163                         "%s has more than one reader\n", p->name);
164         }
165 }
166
167 static void
168 check_txqs(struct app_params *app)
169 {
170         uint32_t i;
171
172         for (i = 0; i < app->n_pktq_hwq_out; i++) {
173                 struct app_pktq_hwq_out_params *p = &app->hwq_out_params[i];
174                 uint32_t n_writers = app_txq_get_writers(app, p);
175
176                 APP_CHECK((p->size > 0),
177                         "%s size is 0\n", p->name);
178
179                 APP_CHECK((rte_is_power_of_2(p->size)),
180                         "%s size is not a power of 2\n", p->name);
181
182                 APP_CHECK((p->burst > 0),
183                         "%s burst size is 0\n", p->name);
184
185                 APP_CHECK((p->burst <= p->size),
186                         "%s burst size is bigger than its size\n", p->name);
187
188                 APP_CHECK((n_writers != 0),
189                         "%s has no writer\n", p->name);
190
191                 APP_CHECK((n_writers == 1),
192                         "%s has more than one writer\n", p->name);
193         }
194 }
195
196 static void
197 check_swqs(struct app_params *app)
198 {
199         uint32_t i;
200
201         for (i = 0; i < app->n_pktq_swq; i++) {
202                 struct app_pktq_swq_params *p = &app->swq_params[i];
203                 uint32_t n_readers = app_swq_get_readers(app, p);
204                 uint32_t n_writers = app_swq_get_writers(app, p);
205                 uint32_t n_flags;
206
207                 APP_CHECK((p->size > 0),
208                         "%s size is 0\n", p->name);
209
210                 APP_CHECK((rte_is_power_of_2(p->size)),
211                         "%s size is not a power of 2\n", p->name);
212
213                 APP_CHECK((p->burst_read > 0),
214                         "%s read burst size is 0\n", p->name);
215
216                 APP_CHECK((p->burst_read <= p->size),
217                         "%s read burst size is bigger than its size\n",
218                         p->name);
219
220                 APP_CHECK((p->burst_write > 0),
221                         "%s write burst size is 0\n", p->name);
222
223                 APP_CHECK((p->burst_write <= p->size),
224                         "%s write burst size is bigger than its size\n",
225                         p->name);
226
227                 APP_CHECK((n_readers != 0),
228                         "%s has no reader\n", p->name);
229
230                 if (n_readers > 1)
231                         APP_LOG(app, LOW, "%s has more than one reader", p->name);
232
233                 APP_CHECK((n_writers != 0),
234                         "%s has no writer\n", p->name);
235
236                 if (n_writers > 1)
237                         APP_LOG(app, LOW, "%s has more than one writer", p->name);
238
239                 n_flags = p->ipv4_frag + p->ipv6_frag + p->ipv4_ras + p->ipv6_ras;
240
241                 APP_CHECK((n_flags < 2),
242                         "%s has more than one fragmentation or reassembly mode enabled\n",
243                         p->name);
244
245                 APP_CHECK((!((n_readers > 1) && (n_flags == 1))),
246                         "%s has more than one reader when fragmentation or reassembly"
247                         " mode enabled\n",
248                         p->name);
249
250                 APP_CHECK((!((n_writers > 1) && (n_flags == 1))),
251                         "%s has more than one writer when fragmentation or reassembly"
252                         " mode enabled\n",
253                         p->name);
254
255                 n_flags = p->ipv4_ras + p->ipv6_ras;
256
257                 APP_CHECK((!((p->dropless == 1) && (n_flags == 1))),
258                         "%s has dropless when reassembly mode enabled\n", p->name);
259
260                 n_flags = p->ipv4_frag + p->ipv6_frag;
261
262                 if (n_flags == 1) {
263                         uint16_t ip_hdr_size = (p->ipv4_frag) ? sizeof(struct ipv4_hdr) :
264                                 sizeof(struct ipv6_hdr);
265
266                         APP_CHECK((p->mtu > ip_hdr_size),
267                                 "%s mtu size is smaller than ip header\n", p->name);
268
269                         APP_CHECK((!((p->mtu - ip_hdr_size) % 8)),
270                                 "%s mtu size is incorrect\n", p->name);
271                 }
272         }
273 }
274
275 static void
276 check_tms(struct app_params *app)
277 {
278         uint32_t i;
279
280         for (i = 0; i < app->n_pktq_tm; i++) {
281                 struct app_pktq_tm_params *p = &app->tm_params[i];
282                 uint32_t n_readers = app_tm_get_readers(app, p);
283                 uint32_t n_writers = app_tm_get_writers(app, p);
284
285                 APP_CHECK((n_readers != 0),
286                         "%s has no reader\n", p->name);
287
288                 APP_CHECK((n_readers == 1),
289                         "%s has more than one reader\n", p->name);
290
291                 APP_CHECK((n_writers != 0),
292                         "%s has no writer\n", p->name);
293
294                 APP_CHECK((n_writers == 1),
295                         "%s has more than one writer\n", p->name);
296         }
297 }
298
299 static void
300 check_sources(struct app_params *app)
301 {
302         uint32_t i;
303
304         for (i = 0; i < app->n_pktq_source; i++) {
305                 struct app_pktq_source_params *p = &app->source_params[i];
306                 uint32_t n_readers = app_source_get_readers(app, p);
307
308                 APP_CHECK((n_readers != 0),
309                         "%s has no reader\n", p->name);
310
311                 APP_CHECK((n_readers == 1),
312                         "%s has more than one reader\n", p->name);
313         }
314 }
315
316 static void
317 check_sinks(struct app_params *app)
318 {
319         uint32_t i;
320
321         for (i = 0; i < app->n_pktq_sink; i++) {
322                 struct app_pktq_sink_params *p = &app->sink_params[i];
323                 uint32_t n_writers = app_sink_get_writers(app, p);
324
325                 APP_CHECK((n_writers != 0),
326                         "%s has no writer\n", p->name);
327
328                 APP_CHECK((n_writers == 1),
329                         "%s has more than one writer\n", p->name);
330         }
331 }
332
333 static void
334 check_msgqs(struct app_params *app)
335 {
336         uint32_t i;
337
338         for (i = 0; i < app->n_msgq; i++) {
339                 struct app_msgq_params *p = &app->msgq_params[i];
340                 uint32_t n_readers = app_msgq_get_readers(app, p);
341                 uint32_t n_writers = app_msgq_get_writers(app, p);
342                 uint32_t msgq_req_pipeline, msgq_rsp_pipeline;
343                 uint32_t msgq_req_core, msgq_rsp_core;
344
345                 APP_CHECK((p->size > 0),
346                         "%s size is 0\n", p->name);
347
348                 APP_CHECK((rte_is_power_of_2(p->size)),
349                         "%s size is not a power of 2\n", p->name);
350
351                 msgq_req_pipeline = (strncmp(p->name, "MSGQ-REQ-PIPELINE",
352                         strlen("MSGQ-REQ-PIPELINE")) == 0);
353
354                 msgq_rsp_pipeline = (strncmp(p->name, "MSGQ-RSP-PIPELINE",
355                         strlen("MSGQ-RSP-PIPELINE")) == 0);
356
357                 msgq_req_core = (strncmp(p->name, "MSGQ-REQ-CORE",
358                         strlen("MSGQ-REQ-CORE")) == 0);
359
360                 msgq_rsp_core = (strncmp(p->name, "MSGQ-RSP-CORE",
361                         strlen("MSGQ-RSP-CORE")) == 0);
362
363                 if ((msgq_req_pipeline == 0) &&
364                         (msgq_rsp_pipeline == 0) &&
365                         (msgq_req_core == 0) &&
366                         (msgq_rsp_core == 0)) {
367                         APP_CHECK((n_readers != 0),
368                                 "%s has no reader\n", p->name);
369
370                         APP_CHECK((n_readers == 1),
371                                 "%s has more than one reader\n", p->name);
372
373                         APP_CHECK((n_writers != 0),
374                                 "%s has no writer\n", p->name);
375
376                         APP_CHECK((n_writers == 1),
377                                 "%s has more than one writer\n", p->name);
378                 }
379
380                 if (msgq_req_pipeline) {
381                         struct app_pipeline_params *pipeline;
382                         uint32_t pipeline_id;
383
384                         APP_PARAM_GET_ID(p, "MSGQ-REQ-PIPELINE", pipeline_id);
385
386                         APP_PARAM_FIND_BY_ID(app->pipeline_params,
387                                 "PIPELINE",
388                                 pipeline_id,
389                                 pipeline);
390
391                         APP_CHECK((pipeline != NULL),
392                                 "%s is not associated with a valid pipeline\n",
393                                 p->name);
394                 }
395
396                 if (msgq_rsp_pipeline) {
397                         struct app_pipeline_params *pipeline;
398                         uint32_t pipeline_id;
399
400                         APP_PARAM_GET_ID(p, "MSGQ-RSP-PIPELINE", pipeline_id);
401
402                         APP_PARAM_FIND_BY_ID(app->pipeline_params,
403                                 "PIPELINE",
404                                 pipeline_id,
405                                 pipeline);
406
407                         APP_CHECK((pipeline != NULL),
408                                 "%s is not associated with a valid pipeline\n",
409                                 p->name);
410                 }
411         }
412 }
413
414 static void
415 check_pipelines(struct app_params *app)
416 {
417         uint32_t i;
418
419         for (i = 0; i < app->n_pipelines; i++) {
420                 struct app_pipeline_params *p = &app->pipeline_params[i];
421
422                 APP_CHECK((p->n_msgq_in == p->n_msgq_out),
423                         "%s number of input MSGQs does not match "
424                         "the number of output MSGQs\n", p->name);
425         }
426 }
427
428 int
429 app_config_check(struct app_params *app)
430 {
431         check_mempools(app);
432         check_links(app);
433         check_rxqs(app);
434         check_txqs(app);
435         check_swqs(app);
436         check_tms(app);
437         check_sources(app);
438         check_sinks(app);
439         check_msgqs(app);
440         check_pipelines(app);
441
442         return 0;
443 }