-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathconfig.c
753 lines (672 loc) · 20.3 KB
/
config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
/* SPDX-License-Identifier: Apache-2.0
* Copyright(c) 2017 Intel Corporation
*/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <rte_ethdev.h>
#include <rte_kni.h>
#include "main.h"
#include "cdr.h"
#include "master_cdr.h"
#include "pipeline/epc_packet_framework.h"
#include "gtpu.h"
/* app config structure */
struct app_params app;
/* prints the usage statement and quits with an error message */
static inline void dp_print_usage(void)
{
printf("\nDataplane supported command line arguments are:\n\n");
printf("+-------------------+-------------+"
"--------------------------------------------+\n");
#define ARGUMENT_WIDTH 17
#define PRESENCE_WIDTH 11
#define DESCRIPTION_WIDTH 42
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "ARGUMENT",
PRESENCE_WIDTH, "PRESENCE",
DESCRIPTION_WIDTH, "DESCRIPTION");
printf("+-------------------+-------------+"
"--------------------------------------------+\n");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--s1u_ip",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "S1U IP address of the SGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--s1u_gw_ip",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "S1U GW IP address of the SGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--s1u_mask",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "S1U GW network mask of the SGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--s1u_mac",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "S1U port mac address of the SGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--s5s8_sgwu_ip",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "S5S8_SGWU IP address of the SGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--s5s8_sgwu_mac",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "S5S8_SGWU port mac address of the SGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--sgw_s5s8gw_ip",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "SGW_S5S8GW IP address of the SGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--sgw_s5s8gw_mask",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "SGW_S5S8GW network mask of the SGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--pgw_s5s8gw_ip",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "PGW_S5S8GW IP address of the PGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--pgw_s5s8gw_mask",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "PGW_S5S8GW network mask of the PGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--s5s8_pgwu_ip",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "S5S8_PGWU IP address of the PGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--s5s8_pgwu_mac",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "S5S8_PGWU port mac address of the PGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--sgi_ip",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "SGI IP address of the PGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--sgi_gw_ip",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "SGI GW IP address of the PGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--sgi_mask",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "SGI GW network mask of the PGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--sgi_mac",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH, "SGI port mac address of the PGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--num_workers",
PRESENCE_WIDTH, "MANDATORY",
DESCRIPTION_WIDTH, "no. of worker instances.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--log",
PRESENCE_WIDTH, "MANDATORY",
DESCRIPTION_WIDTH,
"log level, 1- Notification, 2- Debug.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--cdr_path",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH,
"CDR file path location.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--master_cdr",
PRESENCE_WIDTH, "OPTIONAL",
DESCRIPTION_WIDTH,
"CDR Master file.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--numa",
PRESENCE_WIDTH, "MANDATORY",
DESCRIPTION_WIDTH,
"numa 1- enable, 0- disable.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--spgw_cfg",
PRESENCE_WIDTH, "MANDATORY",
DESCRIPTION_WIDTH,
"spgw_cfg 01 - SGW, 02- PGW, 03- SPGW.");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--kni_portmask",
PRESENCE_WIDTH, "MANDATORY",
DESCRIPTION_WIDTH,
"Configured dpdk port mask");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--ul_iface",
PRESENCE_WIDTH, "MANDATORY",
DESCRIPTION_WIDTH,
"Configured UL interface name(i.e. S1U interface)");
printf("| %-*s | %-*s | %-*s |\n",
ARGUMENT_WIDTH, "--dl_iface",
PRESENCE_WIDTH, "MANDATORY",
DESCRIPTION_WIDTH,
"Configured DL interface name(i.e SGI interface)");
printf("+-------------------+-------------+"
"--------------------------------------------+\n");
printf("\n\nExample Usage:\n"
"$ ./build/ngic_dataplane -c 0xfff -n 4 --\n"
"--spgw_cfg 01\n"
"--s1u_ip 11.1.1.100 --s1u_mac 90:e2:ba:58:c8:64\n"
"--s5s8_sgwu_ip 12.3.1.93\n"
"--s5s8_pgwu_ip 14.3.1.93\n"
"--sgi_ip 13.1.1.93 --sgi_mac 90:e2:ba:58:c8:65\n"
"--s1uc 0 --sgic 1\n"
"--bal 2 --mct 3 --iface 4 --stats 3\n"
"--num_workers 2 --numa 0 --log 1\n"
"--spgw_cfg 3 --ul_iface S1Udev\n"
"--dl_iface SGIdev --kni_portmask 3\n");
exit(0);
}
/* parse ethernet address */
static inline int parse_ether_addr(struct ether_addr *hwaddr, const char *str)
{
/* 01 34 67 90 23 56 */
/* XX:XX:XX:XX:XX:XX */
if (strlen(str) != 17 ||
!isxdigit(str[0]) ||
!isxdigit(str[1]) ||
str[2] != ':' ||
!isxdigit(str[3]) ||
!isxdigit(str[4]) ||
str[5] != ':' ||
!isxdigit(str[6]) ||
!isxdigit(str[7]) ||
str[8] != ':' ||
!isxdigit(str[9]) ||
!isxdigit(str[10]) ||
str[11] != ':' ||
!isxdigit(str[12]) ||
!isxdigit(str[13]) ||
str[14] != ':' ||
!isxdigit(str[15]) ||
!isxdigit(str[16])) {
printf("invalid mac hardware address format->%s<-\n", str);
return 0;
}
sscanf(str, "%02zx:%02zx:%02zx:%02zx:%02zx:%02zx",
(size_t *) &hwaddr->addr_bytes[0],
(size_t *) &hwaddr->addr_bytes[1],
(size_t *) &hwaddr->addr_bytes[2],
(size_t *) &hwaddr->addr_bytes[3],
(size_t *) &hwaddr->addr_bytes[4],
(size_t *) &hwaddr->addr_bytes[5]);
return 1;
}
#define SLEEP_SEC 5
#define NUM_RETRIES 10
/**
* Parses c-string containing dotted decimal ipv4 or hostname and stores the
* value within the in_addr type
*
* @param optarg
* c-string containing dotted decimal ipv4 address or hostname
* @param addr
* destination of parsed IP string
*/
void
parse_arg_host(const char *optarg, struct in_addr *addr)
{
int ret = -1, retries = NUM_RETRIES;
struct addrinfo hints, *servinfo;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
/*NUM_RETRIES with SLEEP_SEC in between to resolve the name*/
while(retries-- > 0 && (ret = getaddrinfo(optarg, NULL, &hints, &servinfo) !=0)){
RTE_LOG(ERR, DP, "Unable to resolve %s. Retrying in %d sec\n",
optarg, SLEEP_SEC);
sleep(SLEEP_SEC);
}
if(ret)
rte_exit(EXIT_FAILURE, "Unable to resolve %s. Exiting\n", optarg);
struct sockaddr_in *h = (struct sockaddr_in *) servinfo->ai_addr;
memcpy(addr, &h->sin_addr, sizeof(struct in_addr));
freeaddrinfo(servinfo);
}
static inline void set_unused_lcore(int *core, uint64_t *used_coremask)
{
if (*core != -1) {
if (!rte_lcore_is_enabled(*core))
rte_panic("Invalid Core Assignment - "
"core %u not in coremask", *core);
return;
}
unsigned lcore;
RTE_LCORE_FOREACH(lcore) {
if ((1ULL << lcore) & *used_coremask)
continue;
*used_coremask |= (1ULL << lcore);
*core = lcore;
return;
}
rte_exit(EXIT_FAILURE, "No free core available - check coremask\n");
}
/**
* Function to parse command line config.
*
* @param app
* global app config structure.
* @param argc
* number of arguments.
* @param argv
* list of arguments.
*
* @return
* - 0 on success
* - -1 on failure
*/
static inline int
parse_config_args(struct app_params *app, int argc, char **argv)
{
int opt;
int option_index;
int i;
struct ether_addr mac_addr;
uint64_t used_coremask = 0;
#ifndef SGX_CDR
const char *master_cdr_file = NULL;
#endif
static struct option spgw_opts[] = {
{"spgw_cfg", required_argument, 0, 'h'},
{"s1u_ip", required_argument, 0, 'i'},
{"s1u_mac", required_argument, 0, 'm'},
{"sgi_ip", required_argument, 0, 's'},
{"sgi_mac", required_argument, 0, 'n'},
{"s1u_gw_ip", required_argument, 0, 'o'},
{"s1u_mask", required_argument, 0, 'q'},
{"sgw_s5s8gw_ip", required_argument, 0, '1'},
{"sgw_s5s8gw_mask", required_argument, 0, '2'},
{"s5s8_sgwu_ip", required_argument, 0, 'v'},
{"s5s8_sgwu_mac", required_argument, 0, 'j'},
{"s5s8_pgwu_ip", required_argument, 0, 'r'},
{"pgw_s5s8gw_ip", required_argument, 0, '3'},
{"pgw_s5s8gw_mask", required_argument, 0, '4'},
{"s5s8_pgwu_mac", required_argument, 0, 'k'},
{"sgi_gw_ip", required_argument, 0, 'x'},
{"sgi_mask", required_argument, 0, 'z'},
{"log", required_argument, 0, 'l'},
{"num_workers", required_argument, 0, 'w'},
{"cdr_path", required_argument, 0, 'a'},
{"master_cdr", required_argument, 0, 'e'},
{"numa", required_argument, 0, 'f'},
{"gtpu_seqnb_in", required_argument, 0, 'I'},
{"gtpu_seqnb_out", required_argument, 0, 'O'},
{"kni_portmask", required_argument, 0, 'p'},
{"ul_iface", required_argument, 0, 'b'},
{"dl_iface", required_argument, 0, 'c'},
{NULL, 0, 0, 0}
};
optind = 0;/* reset getopt lib */
while ((opt = getopt_long(argc, argv, "i:m:s:n:w:l:f:h:a:e:I:O",
spgw_opts, &option_index)) != EOF) {
switch (opt) {
case 'h':
app->spgw_cfg = atoi(optarg);
break;
/* s1u_ip address */
case 'i':
if (!inet_aton(optarg, (struct in_addr *)&app->s1u_ip)) {
printf("Invalid s1u interface ip ->%s<-\n",
optarg);
dp_print_usage();
app->s1u_ip = 0;
return -1;
}
printf("Parsed s1u ip: %s\n",
inet_ntoa(*((struct in_addr *)&app->s1u_ip)));
break;
/* s1u_mac address */
case 'm':
if (!parse_ether_addr(&app->s1u_ether_addr, optarg)) {
dp_print_usage();
return -1;
}
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
rte_eth_macaddr_get(i, &mac_addr);
if (is_same_ether_addr
(&app->s1u_ether_addr, &mac_addr)) {
printf("s1u port %d\n", i);
app->s1u_port = i;
break;
}
}
break;
/* sgi_ip address */
case 's':
if (!inet_aton(optarg, (struct in_addr *)&app->sgi_ip)) {
printf("invalid sgi interface ip ->%s<-\n",
optarg);
dp_print_usage();
app->sgi_ip = 0;
return -1;
}
printf("Parsed sgi ip: %s\n",
inet_ntoa(*((struct in_addr *)&app->sgi_ip)));
break;
/* sgi_mac address */
case 'n':
if (!parse_ether_addr(&app->sgi_ether_addr, optarg)) {
dp_print_usage();
return -1;
}
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
rte_eth_macaddr_get(i, &mac_addr);
if (is_same_ether_addr
(&app->sgi_ether_addr, &mac_addr)) {
printf("sgi port %d\n", i);
app->sgi_port = i;
break;
}
}
break;
/* s1u_gw_ip address */
case 'o':
if (!inet_aton(optarg, (struct in_addr *)&app->s1u_gw_ip)) {
printf("Invalid s1u gateway ip ->%s<-\n",
optarg);
dp_print_usage();
app->s1u_gw_ip = 0;
return -1;
}
printf("Parsed s1u gw ip: %s\n",
inet_ntoa(*((struct in_addr *)&app->s1u_gw_ip)));
break;
/* s1u_net address */
case 'q':
if (!inet_aton(optarg, (struct in_addr *)&app->s1u_mask)) {
printf("Invalid s1u network mask ->%s<-\n",
optarg);
dp_print_usage();
app->s1u_mask = 0;
return -1;
}
printf("Parsed s1u network mask: %s\n",
inet_ntoa(*((struct in_addr *)&app->s1u_mask)));
break;
/* sgw_s5s8gw_ip address */
case '1':
if (!inet_aton(optarg, (struct in_addr *)&app->sgw_s5s8gw_ip)) {
printf("Invalid sgw s5s8 gateway ip ->%s<-\n",
optarg);
dp_print_usage();
app->sgw_s5s8gw_ip = 0;
return -1;
}
printf("Parsed sgw s5s8gw ip: %s\n",
inet_ntoa(*((struct in_addr *)&app->sgw_s5s8gw_ip)));
break;
/* sgw_s5s8gw_mask address */
case '2':
if (!inet_aton(optarg, (struct in_addr *)&app->sgw_s5s8gw_mask)) {
printf("Invalid sgw s5s8gw network mask ->%s<-\n",
optarg);
dp_print_usage();
app->sgw_s5s8gw_mask = 0;
return -1;
}
printf("Parsed sgw s5s8 network mask: %s\n",
inet_ntoa(*((struct in_addr *)&app->sgw_s5s8gw_mask)));
break;
/* s5s8_sgwu_ip address */
case 'v':
if (!inet_aton(optarg, (struct in_addr *)&app->s5s8_sgwu_ip)) {
printf("Invalid s5s8_sgwu interface ip ->%s<-\n",
optarg);
dp_print_usage();
app->s5s8_sgwu_ip = 0;
return -1;
}
printf("Parsed s5s8_sgwu ip: %s\n",
inet_ntoa(*((struct in_addr *)&app->s5s8_sgwu_ip)));
break;
/* s5s8_sgwu_mac address */
case 'j':
if (!parse_ether_addr(&app->s5s8_sgwu_ether_addr, optarg)) {
dp_print_usage();
return -1;
}
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
rte_eth_macaddr_get(i, &mac_addr);
if (is_same_ether_addr
(&app->s5s8_sgwu_ether_addr, &mac_addr)) {
printf("s5s8_sgwu port %d\n", i);
app->s5s8_sgwu_port = i;
break;
}
}
break;
/* s5s8_pgwu_ip address */
case 'r':
if (!inet_aton(optarg, (struct in_addr *)&app->s5s8_pgwu_ip)) {
printf("Invalid s5s8_pgwu interface ip ->%s<-\n",
optarg);
dp_print_usage();
app->s5s8_pgwu_ip = 0;
return -1;
}
printf("Parsed s5s8_pgwu ip: %s\n",
inet_ntoa(*((struct in_addr *)&app->s5s8_pgwu_ip)));
break;
/* sgi_gw_ip address */
case 'x':
if (!inet_aton(optarg, (struct in_addr *)&app->sgi_gw_ip)) {
printf("Invalid sgi gateway ip ->%s<-\n",
optarg);
dp_print_usage();
app->sgi_gw_ip = 0;
return -1;
}
printf("Parsed sgi gw ip: %s\n",
inet_ntoa(*((struct in_addr *)&app->sgi_gw_ip)));
break;
/* sgi_net address */
case 'z':
if (!inet_aton(optarg, (struct in_addr *)&app->sgi_mask)) {
printf("Invalid sgi network mask ->%s<-\n",
optarg);
dp_print_usage();
app->sgi_mask = 0;
return -1;
}
printf("Parsed sgi network mask: %s\n",
inet_ntoa(*((struct in_addr *)&app->sgi_mask)));
break;
/* pgw_s5s8gw_ip address */
case '3':
if (!inet_aton(optarg, (struct in_addr *)&app->pgw_s5s8gw_ip)) {
printf("Invalid pgw s5s8 gateway ip ->%s<-\n",
optarg);
dp_print_usage();
app->pgw_s5s8gw_ip = 0;
return -1;
}
printf("Parsed pgw s5s8gw ip: %s\n",
inet_ntoa(*((struct in_addr *)&app->pgw_s5s8gw_ip)));
break;
/* pgw_s5s8gw_mask address */
case '4':
if (!inet_aton(optarg, (struct in_addr *)&app->pgw_s5s8gw_mask)) {
printf("Invalid sgw s5s8gw network mask ->%s<-\n",
optarg);
dp_print_usage();
app->pgw_s5s8gw_mask = 0;
return -1;
}
printf("Parsed pgw s5s8 network mask: %s\n",
inet_ntoa(*((struct in_addr *)&app->pgw_s5s8gw_mask)));
break;
/* s5s8_pgwu_mac address */
case 'k':
if (!parse_ether_addr(&app->s5s8_pgwu_ether_addr, optarg)) {
dp_print_usage();
return -1;
}
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
rte_eth_macaddr_get(i, &mac_addr);
if (is_same_ether_addr
(&app->s5s8_pgwu_ether_addr, &mac_addr)) {
printf("s5s8_pgwu port %d\n", i);
app->s5s8_pgwu_port = i;
break;
}
}
break;
case 'l':
app->log_level = atoi(optarg);
break;
case 'w':
epc_app.num_workers = atoi(optarg);
printf("Parsed num_workers:\t%u\n",
epc_app.num_workers);
break;
case 'a':
set_cdr_path(optarg);
break;
case 'e':
#ifndef SGX_CDR
master_cdr_file = optarg;
#endif
break;
case 'f':
app->numa_on = atoi(optarg);
break;
case 'I':
app->gtpu_seqnb_in = atoi(optarg);
break;
case 'O':
app->gtpu_seqnb_out = atoi(optarg);
break;
/* Dpdk ports mask */
case 'p':
app->ports_mask = atoi(optarg);
break;
/* Configure S1U interface name*/
case 'b':
memcpy(app->ul_iface_name, optarg, RTE_KNI_NAMESIZE);
break;
/* Configure SGI interface name*/
case 'c':
memcpy(app->dl_iface_name, optarg, RTE_KNI_NAMESIZE);
break;
default:
dp_print_usage();
return -1;
} /* end switch (opt) */
} /* end while() */
#ifndef SGX_CDR
set_master_cdr_file(master_cdr_file);
#endif /* SGX_CDR */
set_unused_lcore(&epc_app.core_mct, &used_coremask);
set_unused_lcore(&epc_app.core_iface, &used_coremask);
#ifdef NGCORE_SHRINK
set_unused_lcore(&epc_app.core_ul[S1U_PORT_ID], &used_coremask);
set_unused_lcore(&epc_app.core_dl[SGI_PORT_ID], &used_coremask);
#else
#ifdef STATS
set_unused_lcore(&epc_app.core_stats, &used_coremask);
#endif
set_unused_lcore(&epc_app.core_spns_dns, &used_coremask);
set_unused_lcore(&epc_app.core_rx[S1U_PORT_ID], &used_coremask);
epc_app.core_tx[S1U_PORT_ID] = epc_app.core_rx[S1U_PORT_ID];
set_unused_lcore(&epc_app.core_rx[SGI_PORT_ID], &used_coremask);
epc_app.core_tx[SGI_PORT_ID] = epc_app.core_rx[SGI_PORT_ID];
set_unused_lcore(&epc_app.core_load_balance, &used_coremask);
for (i = 0; i < epc_app.num_workers; ++i) {
epc_app.worker_cores[i] = -1;
set_unused_lcore(&epc_app.worker_cores[i], &used_coremask);
}
#endif /* NGCORE_SHRINK */
app->s1u_net = app->s1u_ip & app->s1u_mask;
app->s1u_bcast_addr = app->s1u_ip | ~(app->s1u_mask);
RTE_LOG(NOTICE, DP, "DP Config:%s::"
"\n\tDP: S1U IP:\t\t%s;\n\t",
__func__,
inet_ntoa(*(struct in_addr *)&app->s1u_ip));
RTE_LOG(NOTICE, DP, "S1U NET:\t\t%s;\n\t",
inet_ntoa(*(struct in_addr *)&app->s1u_net));
RTE_LOG(NOTICE, DP, "S1U MASK:\t\t%s;\n\t",
inet_ntoa(*(struct in_addr *)&app->s1u_mask));
RTE_LOG(NOTICE, DP, "S1U BCAST ADDR:\t%s;\n\t",
inet_ntoa(*(struct in_addr *)&app->s1u_bcast_addr));
RTE_LOG(NOTICE, DP, "S1U GW IP:\t\t%s\n",
inet_ntoa(*(struct in_addr *)&app->s1u_gw_ip));
app->sgw_s5s8gw_net = app->sgw_s5s8gw_ip & app->sgw_s5s8gw_mask;
app->pgw_s5s8gw_net = app->pgw_s5s8gw_ip & app->pgw_s5s8gw_mask;
app->sgi_net = app->sgi_ip & app->sgi_mask;
app->sgi_bcast_addr = app->sgi_ip | ~(app->sgi_mask);
RTE_LOG(NOTICE, DP, "DP Config:%s::"
"\n\tDP: SGI IP:\t\t%s;\n\t",
__func__,
inet_ntoa(*(struct in_addr *)&app->sgi_ip));
RTE_LOG(NOTICE, DP, "SGI NET:\t\t%s;\n\t",
inet_ntoa(*(struct in_addr *)&app->sgi_net));
RTE_LOG(NOTICE, DP, "SGI MASK:\t\t%s;\n\t",
inet_ntoa(*(struct in_addr *)&app->sgi_mask));
RTE_LOG(NOTICE, DP, "SGI BCAST ADDR:\t%s;\n\t",
inet_ntoa(*(struct in_addr *)&app->sgi_bcast_addr));
RTE_LOG(NOTICE, DP, "SGI GW IP:\t\t%s\n",
inet_ntoa(*(struct in_addr *)&app->sgi_gw_ip));
return 0;
}
/**
* Function to initialize the dp config.
*
* @param argc
* number of arguments.
* @param argv
* list of arguments.
*
* @return
* None
*/
void dp_init(int argc, char **argv)
{
if (parse_config_args(&app, argc, argv) < 0)
rte_exit(EXIT_FAILURE, "Error: Config parse fail !!!\n");
switch (app.gtpu_seqnb_in)
{
case 1: /* include sequence number */
{
fp_gtpu_get_inner_src_dst_ip = gtpu_get_inner_src_dst_ip_with_seqnb;
fp_gtpu_inner_src_ip = gtpu_inner_src_ip_with_seqnb;
fp_decap_gtpu_hdr = decap_gtpu_hdr_with_seqnb;
break;
}
case 2: /* sequence number not included */
{
fp_gtpu_get_inner_src_dst_ip = gtpu_get_inner_src_dst_ip_without_seqnb;
fp_gtpu_inner_src_ip = gtpu_inner_src_ip_without_seqnb;
fp_decap_gtpu_hdr = decap_gtpu_hdr_without_seqnb;
break;
}
case 0: /* dynamic */
default:
{
fp_gtpu_get_inner_src_dst_ip = gtpu_get_inner_src_dst_ip_dynamic_seqnb;
fp_gtpu_inner_src_ip = gtpu_inner_src_ip_dynamic_seqnb;
fp_decap_gtpu_hdr = decap_gtpu_hdr_dynamic_seqnb;
break;
}
}
switch (app.gtpu_seqnb_out)
{
case 1: /* include sequence number */
{
fp_encap_gtpu_hdr = encap_gtpu_hdr_with_seqnb;
break;
}
case 0: /* don't include sequence number */
default:
{
fp_encap_gtpu_hdr = encap_gtpu_hdr_without_seqnb;
break;
}
}
/* TODO: Make logs directory configurable */
int ret = mkdir(LOGS_DIR, S_IRWXU);
if (ret && errno != EEXIST)
rte_exit(EXIT_FAILURE, "Failed to create directory %s: %s\n", LOGS_DIR,
strerror(errno));
}