-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdataplane.c
1133 lines (973 loc) · 26.1 KB
/
dataplane.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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: Apache-2.0
* Copyright(c) 2017 Intel Corporation
*/
#include <arpa/inet.h>
#ifdef PCAP_GEN
#include <pcap.h>
#endif /* PCAP_GEN */
#include <rte_cycles.h>
#include <rte_ip.h>
#include <rte_ip_frag.h>
#include <rte_errno.h>
#include "main.h"
#include "interface.h"
#include "epc_packet_framework.h"
#include "gtpu.h"
#include "ipv4.h"
#include "ether.h"
#include "util.h"
#include "meter.h"
#include "acl_dp.h"
#include "cdr.h"
#include <sponsdn.h>
#include <stdbool.h>
struct rte_hash *rte_uplink_hash;
struct rte_hash *rte_downlink_hash;
struct rte_hash *rte_adc_hash;
struct rte_hash *rte_adc_ue_hash;
struct rte_hash *rte_sess_hash;
struct rte_hash *rte_ue_hash;
struct rte_hash *rte_sdf_pcc_hash;
struct rte_hash *rte_adc_pcc_hash;
#ifdef PCAP_GEN
pcap_dumper_t *pcap_dumper_east;
pcap_dumper_t *pcap_dumper_west;
#endif /* PCAP_GEN */
void
gtpu_decap(struct rte_mbuf **pkts, uint32_t n,
uint64_t *pkts_mask)
{
uint32_t i;
int ret = 0;
struct ipv4_hdr *ipv4_hdr;
struct udp_hdr *udp_hdr;
struct gtpu_hdr *gtpu_hdr;
struct epc_meta_data *meta_data;
for (i = 0; i < n; i++) {
/* reject if not with s1u ip */
ipv4_hdr = get_mtoip(pkts[i]);
uint32_t ip = 0; //GCC_Security flag
switch(app.spgw_cfg) {
case SPGWU:
ip = app.s1u_ip;
break;
case PGWU:
ip = app.s5s8_pgwu_ip;
break;
default:
break;
}
if (ipv4_hdr->dst_addr != ip) {
RESET_BIT(*pkts_mask, i);
continue;
}
/* reject un-tunneled packet */
udp_hdr = get_mtoudp(pkts[i]);
if (ntohs(udp_hdr->dst_port) != UDP_PORT_GTPU) {
RESET_BIT(*pkts_mask, i);
continue;
}
gtpu_hdr = get_mtogtpu(pkts[i]);
if (gtpu_hdr->teid == 0 || gtpu_hdr->msgtype != GTP_GPDU) {
#ifdef NGCORE_SHRINK
#ifdef STATS
--epc_app.ul_params[S1U_PORT_ID].pkts_in;
#ifdef EXSTATS
++epc_app.ul_params[S1U_PORT_ID].pkts_echo;
#endif /* EXSTATS */
#endif /* STATS */
#endif /* NGCORE_SHRINK */
RESET_BIT(*pkts_mask, i);
continue;
}
meta_data =
(struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(pkts[i],
META_DATA_OFFSET);
meta_data->teid = ntohl(gtpu_hdr->teid);
meta_data->enb_ipv4 = ntohl(ipv4_hdr->src_addr);
RTE_LOG_DP(DEBUG, DP, "Received tunneled packet with teid 0x%X\n",
ntohl(meta_data->teid));
RTE_LOG_DP(DEBUG, DP, "From Ue IP " IPV4_ADDR "\n",
IPV4_ADDR_FORMAT(GTPU_INNER_SRC_IP(pkts[i])));
ret = DECAP_GTPU_HDR(pkts[i]);
if (ret < 0){
RESET_BIT(*pkts_mask, i);
#ifdef NGCORE_SHRINK
#ifdef STATS
--epc_app.ul_params[S1U_PORT_ID].pkts_in;
#endif /* STATS */
#endif /* NGCORE_SHRINK */
}
}
}
void
gtpu_encap(struct dp_session_info **sess_info, struct rte_mbuf **pkts,
uint32_t n, uint64_t *pkts_mask, uint64_t *pkts_queue_mask)
{
uint32_t i;
struct dp_session_info *si;
struct rte_mbuf *m;
uint16_t len;
uint32_t src_addr;
uint32_t dst_addr;
for (i = 0; i < n; i++) {
si = sess_info[i];
m = pkts[i];
if (!ISSET_BIT(*pkts_mask, i)) {
#ifdef NGCORE_SHRINK
#ifdef STATS
--epc_app.dl_params[SGI_PORT_ID].pkts_in;
#endif /* STATS */
#endif /* NGCORE_SHRINK */
//wr_pkts++;
continue;
}
if (si == NULL) {
#ifdef NGCORE_SHRINK
#ifdef STATS
--epc_app.dl_params[SGI_PORT_ID].pkts_in;
#endif /* STATS */
#endif /* NGCORE_SHRINK */
RESET_BIT(*pkts_mask, i);
continue;
}
/** Check downlink bearer is ACTIVE or IDLE */
#ifdef DP_DDN
if (si->sess_state != CONNECTED) {
#ifdef NGCORE_SHRINK
#ifdef STATS
--epc_app.dl_params[SGI_PORT_ID].pkts_in;
++epc_app.dl_params[SGI_PORT_ID].ddn;
#endif /* STATS */
#endif /* NGCORE_SHRINK */
RESET_BIT(*pkts_mask, i);
SET_BIT(*pkts_queue_mask, i);
continue;
}
#endif /* DP_DDN */
if (!si->dl_s1_info.enb_teid) {
#ifdef NGCORE_SHRINK
#ifdef STATS
--epc_app.dl_params[SGI_PORT_ID].pkts_in;
#endif /* STATS */
#endif /* NGCORE_SHRINK */
RESET_BIT(*pkts_mask, i);
SET_BIT(*pkts_queue_mask, i);
continue;
}
if (ENCAP_GTPU_HDR(m, si->dl_s1_info.enb_teid) < 0) {
#ifdef NGCORE_SHRINK
#ifdef STATS
--epc_app.dl_params[SGI_PORT_ID].pkts_in;
#endif /* STATS */
#endif /* NGCORE_SHRINK */
RESET_BIT(*pkts_mask, i);
continue;
}
len = rte_pktmbuf_data_len(m);
len = len - ETH_HDR_SIZE;
if (app.spgw_cfg == PGWU)
dst_addr = si->dl_s1_info.s5s8_sgwu_addr.u.ipv4_addr;
else
dst_addr = si->dl_s1_info.enb_addr.u.ipv4_addr;
/* construct iphdr */
switch(app.spgw_cfg) {
case SPGWU:
src_addr = app.s1u_ip;
break;
case PGWU:
src_addr = app.s5s8_pgwu_ip;
break;
default:
break;
}
construct_ipv4_hdr(m, len, IP_PROTO_UDP, ntohl(src_addr),
dst_addr);
len = len - IPv4_HDR_SIZE;
/* construct udphdr */
construct_udp_hdr(m, len, UDP_PORT_GTPU, UDP_PORT_GTPU);
}
}
void
ul_sess_info_get(struct rte_mbuf **pkts, uint32_t n,
uint64_t *pkts_mask, struct dp_sdf_per_bearer_info **sess_info)
{
uint32_t j;
struct ul_bm_key key[MAX_BURST_SZ];
void *key_ptr[MAX_BURST_SZ];
struct epc_meta_data *meta_data;
uint64_t hit_mask = 0;
/* TODO: uplink hash is created based on values pushed from CP.
* CP always sends rule-id = 1 while creation.
* After new implementation of ADC-PCC relation lookup will fail.
* Hard coding rule id to 1. (temporary fix)
*/
for (j = 0; j < n; j++) {
key[j].rid =1;
key[j].s1u_sgw_teid = 0;
key_ptr[j] = &key[j];
switch (app.spgw_cfg) {
case SPGWU: {
meta_data =
(struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(pkts[j],
META_DATA_OFFSET);
key[j].s1u_sgw_teid = meta_data->teid;
break;
}
case SGWU: {
struct ipv4_hdr *ipv4_hdr = NULL;
struct udp_hdr *udp_hdr = NULL;
struct gtpu_hdr *gtpu_hdr = NULL;
/* reject if not with s1u ip */
ipv4_hdr = get_mtoip(pkts[j]);
if (ipv4_hdr->dst_addr != app.s1u_ip) {
RESET_BIT(*pkts_mask, j);
continue;
}
/* reject un-tunneled packet */
udp_hdr = get_mtoudp(pkts[j]);
if (ntohs(udp_hdr->dst_port) != UDP_PORT_GTPU) {
RESET_BIT(*pkts_mask, j);
continue;
}
gtpu_hdr = get_mtogtpu(pkts[j]);
if (gtpu_hdr->teid == 0 || gtpu_hdr->msgtype != GTP_GPDU) {
RESET_BIT(*pkts_mask, j);
continue;
}
key[j].s1u_sgw_teid = ntohl(gtpu_hdr->teid);
break;
}
default:
break;
}
}
if ((iface_lookup_uplink_bulk_data((const void **)&key_ptr[0], n,
&hit_mask, (void **)sess_info)) < 0) {
hit_mask = 0;
}
if (app.spgw_cfg != PGWU) {
for (j = 0; j < n; j++) {
if (!ISSET_BIT(hit_mask, j)) {
RESET_BIT(*pkts_mask, j);
RTE_LOG_DP(DEBUG, DP, "SDF BEAR LKUP:FAIL!! UL_KEY "
"teid:%u, rid:%u\n",
key[j].s1u_sgw_teid, key[j].rid);
sess_info[j] = NULL;
}
}
}
}
void
adc_ue_info_get(struct rte_mbuf **pkts, uint32_t n, uint32_t *res,
void **adc_ue_info, uint32_t flow)
{
uint32_t j;
struct dl_bm_key key[MAX_BURST_SZ];
struct ipv4_hdr *ipv4_hdr;
void *key_ptr[MAX_BURST_SZ];
uint64_t hit_mask = 0;
for (j = 0; j < n; j++) {
ipv4_hdr = get_mtoip(pkts[j]);
key[j].rid = res[j];
if (flow == UL_FLOW)
key[j].ue_ipv4 = ntohl(ipv4_hdr->src_addr);
else
key[j].ue_ipv4 = ntohl(ipv4_hdr->dst_addr);
key_ptr[j] = &key[j];
}
if ((rte_hash_lookup_bulk_data(rte_adc_ue_hash,
(const void **)&key_ptr[0], n, &hit_mask, adc_ue_info)) < 0)
RTE_LOG_DP(ERR, DP, "ADC UE Bulk LKUP:FAIL!!\n");
for (j = 0; j < n; j++)
if (!ISSET_BIT(hit_mask, j))
adc_ue_info[j] = NULL;
}
void
dl_sess_info_get(struct rte_mbuf **pkts, uint32_t n,
uint64_t *pkts_mask, struct dp_sdf_per_bearer_info **sess_info,
struct dp_session_info **si)
{
uint32_t j;
struct dl_bm_key key[MAX_BURST_SZ];
void *key_ptr[MAX_BURST_SZ];
struct ipv4_hdr *ipv4_hdr = NULL;
uint32_t dst_addr = 0;
uint64_t hit_mask = 0;
/* TODO: downlink hash is created based on values pushed from CP.
* CP always sends rule-id = 1 while creation.
* After new implementation of ADC-PCC relation lookup will fail.
* Hard coding rule id to 1. (temporary fix)
*/
for (j = 0; j < n; j++) {
key[j].rid =1;
key[j].ue_ipv4 = 0;
key_ptr[j] = &key[j];
switch (app.spgw_cfg) {
case SGWU: {
struct udp_hdr *udp_hdr = NULL;
struct gtpu_hdr *gtpu_hdr = NULL;
/* reject if not with s1u ip */
ipv4_hdr = get_mtoip(pkts[j]);
if (ipv4_hdr->dst_addr != app.s5s8_sgwu_ip) {
RESET_BIT(*pkts_mask, j);
continue;
}
/* reject un-tunneled packet */
udp_hdr = get_mtoudp(pkts[j]);
if (ntohs(udp_hdr->dst_port) != UDP_PORT_GTPU) {
RESET_BIT(*pkts_mask, j);
continue;
}
gtpu_hdr = get_mtogtpu(pkts[j]);
if (gtpu_hdr->teid == 0 || gtpu_hdr->msgtype != GTP_GPDU) {
RESET_BIT(*pkts_mask, j);
continue;
}
uint8_t *pkt_ptr = (uint8_t *) gtpu_hdr;
pkt_ptr += GPDU_HDR_SIZE_DYNAMIC(*pkt_ptr);
ipv4_hdr = (struct ipv4_hdr *)pkt_ptr;
dst_addr = ntohl(ipv4_hdr->dst_addr);
break;
}
case PGWU: {
/* Values are same as SPGWU.*/
}
case SPGWU: {
ipv4_hdr = get_mtoip(pkts[j]);
dst_addr = ntohl(ipv4_hdr->dst_addr);
break;
}
default:
break;
}
key[j].ue_ipv4 = dst_addr;
struct epc_meta_data *meta_data =
(struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(pkts[j],
META_DATA_OFFSET);
meta_data->key.ue_ipv4 = key[j].ue_ipv4;
meta_data->key.rid = key[j].rid;
RTE_LOG_DP(DEBUG, DP, "BEAR_SESS LKUP:DL_KEY ue_addr:"IPV4_ADDR
", rid:%u\n",
IPV4_ADDR_HOST_FORMAT(meta_data->key.ue_ipv4),
meta_data->key.rid);
key_ptr[j] = &key[j];
}
if ((iface_lookup_downlink_bulk_data((const void **)&key_ptr[0], n,
&hit_mask, (void **)sess_info)) < 0)
RTE_LOG_DP(ERR, DP, "SDF BEAR Bulk LKUP:FAIL!!\n");
for (j = 0; j < n; j++) {
if (!ISSET_BIT(hit_mask, j)) {
RESET_BIT(*pkts_mask, j);
RTE_LOG_DP(DEBUG, DP, "SDF BEAR LKUP FAIL!! DL_KEY "
"ue_addr:"IPV4_ADDR", rid:%u\n",
IPV4_ADDR_HOST_FORMAT((key[j]).ue_ipv4),
key[j].rid);
sess_info[j] = NULL;
si[j] = NULL;
} else {
si[j] = sess_info[j]->bear_sess_info;
}
}
}
void
get_pcc_info(void **sess_info, uint32_t n, void **pcc_info)
{
uint32_t i;
struct dp_sdf_per_bearer_info *psdf;
for (i = 0; i < n; i++) {
psdf = (struct dp_sdf_per_bearer_info *)sess_info[i];
if (psdf == NULL) {
pcc_info[i] = NULL;
continue;
}
pcc_info[i] = &psdf->pcc_info;
}
}
void
pcc_gating(struct pcc_id_precedence *sdf_info, struct pcc_id_precedence *adc_info,
uint32_t n, uint64_t *pkts_mask, uint32_t *pcc_id)
{
uint32_t i;
for (i = 0; i < n; i++) {
/* Lowest value, highest precedance. ref: 29.212 */
if (sdf_info[i].precedence < adc_info[i].precedence) {
if (sdf_info[i].gate_status == CLOSE) {
RESET_BIT(*pkts_mask, i);
}
pcc_id[i] = sdf_info[i].pcc_id;
} else {
if (adc_info[i].gate_status == CLOSE) {
RESET_BIT(*pkts_mask, i);
}
pcc_id[i] = adc_info[i].pcc_id;
}
}
}
/**
* To map rating group value to index
* @param rg_val
* rating group.
* @param rg_idx_map
* index map structure.
*
* @return
* rating group index
*/
static uint8_t
get_rg_idx(uint32_t rg_val, struct rating_group_index_map *rg_idx_map)
{
uint32_t i;
if (rg_val == 0)
return MAX_RATING_GRP;
for (i = 0; i < MAX_RATING_GRP; i++)
if (rg_idx_map[i].rg_val == rg_val)
return i;
return MAX_RATING_GRP;
}
void
get_rating_grp(void **adc_ue_info, void **sdf_info,
uint32_t **rgrp, uint32_t n)
{
uint32_t i;
struct dp_adc_ue_info *adc_ue;
struct dp_sdf_per_bearer_info *psdf;
struct dp_pcc_rules *pcc;
for (i = 0; i < n; i++) {
adc_ue = adc_ue_info[i];
if (adc_ue && adc_ue->adc_info.rating_group) {
rgrp[i] = &adc_ue->adc_info.rating_group;
continue;
}
psdf = (struct dp_sdf_per_bearer_info *)sdf_info[i];
if (psdf == NULL)
continue;
pcc = &psdf->pcc_info;
if (pcc && pcc->rating_group)
rgrp[i] = &pcc->rating_group;
else
rgrp[i] = NULL;
}
}
static void
update_cdr(struct ipcan_dp_bearer_cdr *cdr, struct rte_mbuf *pkt,
uint32_t flow, enum pkt_action_t action)
{
uint32_t charged_len;
struct ipv4_hdr *ip_h = NULL;
ip_h = rte_pktmbuf_mtod_offset(pkt, struct ipv4_hdr *,
sizeof(struct ether_hdr));
charged_len =
RTE_MIN(rte_pktmbuf_pkt_len(pkt) -
sizeof(struct ether_hdr),
ntohs(ip_h->total_length));
if (action == CHARGED) {
if (flow == UL_FLOW) {
cdr->data_vol.ul_cdr.bytes += charged_len;
cdr->data_vol.ul_cdr.pkt_count++;
} else {
cdr->data_vol.dl_cdr.bytes += charged_len;
cdr->data_vol.dl_cdr.pkt_count++;
} /* if (flow == UL_FLOW) */
} else {
if (flow == UL_FLOW) {
cdr->data_vol.ul_drop.bytes += charged_len;
cdr->data_vol.ul_drop.pkt_count++;
} else {
cdr->data_vol.dl_drop.bytes += charged_len;
cdr->data_vol.dl_drop.pkt_count++;
} /* if (flow == UL_FLOW) */
}
}
void
update_adc_cdr(void **adc_ue_info,
struct rte_mbuf **pkts, uint32_t n,
uint64_t *adc_pkts_mask, uint64_t *pkts_mask,
uint32_t flow)
{
uint32_t i;
struct dp_adc_ue_info *adc_ue;
for (i = 0; i < n; i++) {
adc_ue = (struct dp_adc_ue_info *)adc_ue_info[i];
if (adc_ue == NULL)
continue;
/* record cdr counts if ADC rule is open and pkt is not dropped
* due to pcc rule of metering.*/
if ((ISSET_BIT(*adc_pkts_mask, i))
&& (ISSET_BIT(*pkts_mask, i)))
update_cdr(&adc_ue->adc_cdr, pkts[i], flow, CHARGED);
/* record drop counts if ADC rule is hit but gate is closed*/
if (!(ISSET_BIT(*adc_pkts_mask, i)))
update_cdr(&adc_ue->adc_cdr, pkts[i], flow, DROPPED);
} /* for (i = 0; i < n; i++)*/
}
void
update_sdf_cdr(void **adc_ue_info,
struct dp_sdf_per_bearer_info **sdf_bear_info,
struct rte_mbuf **pkts, uint32_t n,
uint64_t *adc_pkts_mask, uint64_t *pkts_mask,
uint32_t flow)
{
uint32_t i;
struct dp_sdf_per_bearer_info *psdf;
struct dp_adc_ue_info *adc_ue;
for (i = 0; i < n; i++) {
psdf = sdf_bear_info[i];
if (psdf == NULL)
continue;
/* if ADC rule is hit, but gate is closed
* then don't update PCC cdr. */
adc_ue = (struct dp_adc_ue_info *)adc_ue_info[i];
if ((adc_ue != NULL)
&& !ISSET_BIT(*adc_pkts_mask, i))
continue;
/* if ADC CDR is updated, then no need to
* update PCC cdr */
if (ISSET_BIT(*adc_pkts_mask, i))
continue;
if (ISSET_BIT(*pkts_mask, i))
update_cdr(&psdf->sdf_cdr, pkts[i], flow, CHARGED);
else
update_cdr(&psdf->sdf_cdr, pkts[i], flow, DROPPED);
} /* for (i = 0; i < n; i++)*/
}
void
update_pcc_cdr(struct dp_sdf_per_bearer_info **sdf_bear_info,
struct rte_mbuf **pkts, uint32_t n, uint64_t *pkts_mask,
uint32_t *pcc_rule, uint32_t flow)
{
uint32_t i;
struct dp_sdf_per_bearer_info *psdf = NULL;
for (i = 0; i < n; i++) {
psdf = sdf_bear_info[i];
if (NULL == psdf)
continue;
if (psdf->sdf_cdr.charging_rule_id == 0) {
psdf->sdf_cdr.charging_rule_id = pcc_rule[i];
}
if (ISSET_BIT(*pkts_mask, i))
update_cdr(&psdf->sdf_cdr, pkts[i], flow, CHARGED);
else
update_cdr(&psdf->sdf_cdr, pkts[i], flow, DROPPED);
}
}
void
update_bear_cdr(struct dp_sdf_per_bearer_info **sdf_bear_info,
struct rte_mbuf **pkts, uint32_t n,
uint64_t *pkts_mask, uint32_t flow)
{
uint32_t i;
struct dp_session_info *si;
struct dp_sdf_per_bearer_info *psdf;
for (i = 0; i < n; i++) {
psdf = sdf_bear_info[i];
if (psdf == NULL)
continue;
si = psdf->bear_sess_info;
if (si == NULL)
continue;
if (ISSET_BIT(*pkts_mask, i))
update_cdr(&si->ipcan_dp_bearer_cdr, pkts[i],
flow, CHARGED);
else
update_cdr(&si->ipcan_dp_bearer_cdr, pkts[i],
flow, DROPPED);
} /* for (i = 0; i < n; i++)*/
}
void
update_rating_grp_cdr(void **sess_info, uint32_t **rgrp,
struct rte_mbuf **pkts, uint32_t n,
uint64_t *pkts_mask, uint32_t flow)
{
uint32_t i;
struct dp_session_info *si;
struct dp_sdf_per_bearer_info *psdf;
uint8_t rg_idx;
for (i = 0; i < n; i++) {
psdf = (struct dp_sdf_per_bearer_info *)sess_info[i];
if (psdf == NULL)
continue;
si = psdf->bear_sess_info;
if (si == NULL)
continue;
if (rgrp[i] == NULL)
continue;
rg_idx = get_rg_idx(*rgrp[i], si->ue_info_ptr->rg_idx_map);
if (rg_idx >= MAX_RATING_GRP)
continue;
if (ISSET_BIT(*pkts_mask, i))
update_cdr(&si->ue_info_ptr->rating_grp[rg_idx],
pkts[i], flow, CHARGED);
else
update_cdr(&si->ue_info_ptr->rating_grp[rg_idx],
pkts[i], flow, DROPPED);
} /* for (i = 0; i < n; i++)*/
}
void
update_extended_cdr(struct rte_mbuf **pkts, uint32_t n,
uint64_t *pkts_mask, uint64_t *non_gtp_pkts_mask, uint32_t *pcc_rule,
uint32_t direction)
{
uint32_t i;
struct dp_pcc_rules *pcc_info = NULL;
for (i = 0; i < n; i++) {
struct ether_hdr *eth_hdr = rte_pktmbuf_mtod(pkts[i], void *);
struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)ð_hdr[1];
struct in_addr sip_addr;
struct in_addr dip_addr;
char sip[INET_ADDRSTRLEN] = {0};
char dip[INET_ADDRSTRLEN] = {0};
/*Do not add GTPU Echo and other non-gtp packets in extended cdr*/
if(!ISSET_BIT(*non_gtp_pkts_mask, i)) continue;
pcc_info = NULL;
sip_addr.s_addr = ipv4_hdr->src_addr;
dip_addr.s_addr = ipv4_hdr->dst_addr;
strncpy(sip, inet_ntoa(sip_addr), INET_ADDRSTRLEN);
strncpy(dip, inet_ntoa(dip_addr), INET_ADDRSTRLEN);
iface_lookup_pcc_data(pcc_rule[i], &pcc_info);
if (NULL != pcc_info)
export_extended_cdr(sip, dip, ISSET_BIT(*pkts_mask, i), pcc_info, direction);
}
}
void
adc_hash_lookup(struct rte_mbuf **pkts, uint32_t n, uint32_t *rid, uint8_t flow)
{
uint32_t j;
uint32_t key32[MAX_BURST_SZ];
uint32_t *key_ptr[MAX_BURST_SZ];
uint64_t hit_mask = 0;
struct msg_adc *data[MAX_BURST_SZ];
struct ipv4_hdr *ipv4_hdr;
for (j = 0; j < n; j++) {
ipv4_hdr = get_mtoip(pkts[j]);
key32[j] = (flow == UL_FLOW) ? ipv4_hdr->dst_addr :
ipv4_hdr->src_addr;
key_ptr[j] = &key32[j];
}
if (iface_lookup_adc_bulk_data((const void **)key_ptr,
n, &hit_mask, (void **)data) < 0)
hit_mask = 0;
for (j = 0; j < n; j++) {
if (ISSET_BIT(hit_mask, j)) {
RTE_LOG_DP(DEBUG, DP, "ADC_DNS_LKUP: rid[%d]:%u\n", j,
data[j]->rule_id);
rid[j] = data[j]->rule_id;
} else {
rid[j] = 0;
}
}
}
static inline bool is_dns_pkt(struct rte_mbuf *m, uint32_t rid)
{
struct ipv4_hdr *ip_hdr;
struct ether_hdr *eth_hdr;
eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
ip_hdr = (struct ipv4_hdr *)(eth_hdr + 1);
if (rte_ipv4_frag_pkt_is_fragmented(ip_hdr))
return false;
if (rid != DNS_RULE_ID)
return false;
return true;
}
void
update_dns_meta(struct rte_mbuf **pkts, uint32_t n, uint32_t *rid)
{
uint32_t i;
struct epc_meta_data *meta_data;
for (i = 0; i < n; i++) {
meta_data =
(struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(
pkts[i], META_DATA_OFFSET);
if (likely(!is_dns_pkt(pkts[i], rid[i]))) {
meta_data->dns = 0;
continue;
}
meta_data->dns = 1;
}
}
#ifdef HYPERSCAN_DPI
static int
get_worker_index(unsigned lcore_id)
{
return epc_app.worker_core_mapping[lcore_id];
}
void
clone_dns_pkts(struct rte_mbuf **pkts, uint32_t n, uint64_t pkts_mask)
{
uint32_t i;
struct epc_meta_data *meta_data;
unsigned lcore_id = rte_lcore_id();
int worker_index = get_worker_index(lcore_id);
for (i = 0; i < n; i++) {
if (ISSET_BIT(pkts_mask, i)) {
meta_data =
(struct epc_meta_data *)RTE_MBUF_METADATA_UINT8_PTR(
pkts[i], META_DATA_OFFSET);
if (meta_data->dns) {
push_dns_ring(pkts[i]);
/* ASR- NGCORE_SHRINK HYPERSCAN clone_dns_pkt to be tested */
#ifdef NGCORE_SHRINK
++(epc_app.dl_params[worker_index].
num_dns_packets);
#else
++(epc_app.worker[worker_index].
num_dns_packets);
#endif /* NGCORE_SHRINK */
}
}
}
}
#endif /* HYPERSCAN_DPI */
void
update_nexthop_info(struct rte_mbuf **pkts, uint32_t n,
uint64_t *pkts_mask, uint8_t portid,
struct dp_sdf_per_bearer_info **sess_info)
{
uint32_t i;
for (i = 0; i < n; i++) {
if (ISSET_BIT(*pkts_mask, i)) {
if (construct_ether_hdr(pkts[i], portid, &sess_info[i]) < 0)
RESET_BIT(*pkts_mask, i);
}
/* TODO: Set checksum offload.*/
}
}
void
update_nexts5s8_info(struct rte_mbuf **pkts, uint32_t n,
uint64_t *pkts_mask, struct dp_sdf_per_bearer_info **sdf_bear_info)
{
/*TODO: Do we need to update TEID in GTP header?*/
uint16_t len;
uint32_t i;
for (i = 0; i < n; i++) {
if (ISSET_BIT(*pkts_mask, i)) {
len = rte_pktmbuf_data_len(pkts[i]);
len = len - ETH_HDR_SIZE;
if (app.spgw_cfg == SGWU) {
/*TODO : Make readable*/
uint32_t s5s8_pgwu_addr =
sdf_bear_info[i]->bear_sess_info->ul_s1_info.s5s8_pgwu_addr.u.ipv4_addr;
construct_ipv4_hdr(pkts[i], len, IP_PROTO_UDP,
ntohl(app.s5s8_sgwu_ip), s5s8_pgwu_addr);
}else if (app.spgw_cfg == PGWU) {
uint32_t s5s8_sgwu_addr =
sdf_bear_info[i]->bear_sess_info->dl_s1_info.s5s8_sgwu_addr.u.ipv4_addr;
construct_ipv4_hdr(pkts[i], len, IP_PROTO_UDP,
ntohl(app.s5s8_pgwu_ip), s5s8_sgwu_addr);
}
}
}
}
void
update_enb_info(struct rte_mbuf **pkts, uint32_t n,
uint64_t *pkts_mask, struct dp_sdf_per_bearer_info **sess_info)
{
uint16_t len;
uint32_t i;
for (i = 0; i < n; i++) {
if (ISSET_BIT(*pkts_mask, i)) {
len = rte_pktmbuf_data_len(pkts[i]);
len = len - ETH_HDR_SIZE;
uint32_t enb_addr =
sess_info[i]->bear_sess_info->dl_s1_info.enb_addr.u.ipv4_addr;
construct_ipv4_hdr(pkts[i], len, IP_PROTO_UDP,
ntohl(app.s1u_ip), enb_addr);
/*Update tied in GTP U header*/
((struct gtpu_hdr *)get_mtogtpu(pkts[i]))->teid =
ntohl(sess_info[i]->bear_sess_info->dl_s1_info.enb_teid);
}
}
}
void
update_adc_rid_from_domain_lookup(uint32_t *rb, uint32_t *rc, uint32_t n)
{
uint32_t i;
for (i = 0; i < n; i++)
if (rc[i] != 0)
rb[i] = rc[i];
}
/**
* @brief create hash table.
*
*/
int
hash_create(const char *name, struct rte_hash **rte_hash,
uint32_t entries, uint32_t key_len)
{
struct rte_hash_parameters rte_hash_params = {
.name = name,
.entries = entries,
.key_len = key_len,
.hash_func = DEFAULT_HASH_FUNC,
.hash_func_init_val = 0,
.socket_id = rte_socket_id(),
};
*rte_hash = rte_hash_create(&rte_hash_params);
if (*rte_hash == NULL)
rte_exit(EXIT_FAILURE, "%s hash create failed: %s (%u)\n",
rte_hash_params.name,
rte_strerror(rte_errno), rte_errno);
return 0;
}
void dp_table_init(void)
{
int ret;
/*
* Create Uplink DB
*/
hash_create("iface_uplink_db", &rte_uplink_hash,
LDB_ENTRIES_DEFAULT * HASH_SIZE_FACTOR,
sizeof(struct ul_bm_key));
/*
* Create Downlink DB
*/
hash_create("iface_downlink_db", &rte_downlink_hash,
LDB_ENTRIES_DEFAULT * HASH_SIZE_FACTOR,
sizeof(struct dl_bm_key));
/*
* Create ADC Domain Hash table
*/
hash_create("adc_domain_hash", &rte_adc_hash, LDB_ENTRIES_DEFAULT,
sizeof(uint32_t));
/*
* Create ADC UE info Hash table
*/
hash_create("adc_ue_info", &rte_adc_ue_hash, LDB_ENTRIES_DEFAULT,
sizeof(struct dl_bm_key));
/*
* Create UE Sess Hash table
*/
hash_create("ue_sess_info", &rte_ue_hash, LDB_ENTRIES_DEFAULT,
sizeof(uint32_t));
/* Create table for sponsored domain names */
ret = epc_sponsdn_create(DEFAULT_DN_NUM);
if (ret)
rte_exit(EXIT_FAILURE,
"error allocating sponsored DN context %d\n", ret);
/*
* Init callback APIs
*/
app_sess_tbl_init();
app_pcc_tbl_init();
app_mtr_tbl_init();
app_filter_tbl_init();
app_adc_tbl_init();
struct dp_id dp_id = { .id = DPN_ID };
sprintf(dp_id.name, SDF_FILTER_TABLE);
ret = dp_sdf_filter_table_create(dp_id, SDF_FILTER_TABLE_SIZE);
if (ret)
rte_exit(EXIT_FAILURE,
"error in creating SDF filter table %d\n", ret);
sprintf(dp_id.name, ADC_TABLE);
ret = dp_adc_table_create(dp_id, ADC_TABLE_SIZE);