-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathsess_table.c
1584 lines (1383 loc) · 38.8 KB
/
sess_table.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
*/
#define _GNU_SOURCE /* Expose declaration of tdestroy() */
#include <search.h>
#include <rte_mbuf.h>
#include <rte_common.h>
#include <rte_eal.h>
#include <rte_log.h>
#include <rte_malloc.h>
#include <rte_jhash.h>
#include <rte_cfgfile.h>
#include <rte_hash.h>
#include <rte_hash_crc.h>
#include "vepc_cp_dp_api.h"
#include "main.h"
#include "util.h"
#include "acl_dp.h"
#include "interface.h"
#include "cdr.h"
#include "session_cdr.h"
#include "meter.h"
#define SESS_CREATE 0
#define SESS_MODIFY 1
#define SESS_DEL 2
extern struct rte_hash *rte_sess_hash;
extern struct rte_hash *rte_ue_hash;
extern struct rte_hash *rte_uplink_hash;
extern struct rte_hash *rte_downlink_hash;
extern struct rte_hash *rte_adc_hash;
extern struct rte_hash *rte_adc_ue_hash;
#define DEBUG_SESS_TABLE 0
#if DEBUG_SESS_TABLE
#define WIDTH 40
#define PRINT_SESSION_INFO(entry) \
do {\
puts(__FUNCTION__);\
printf("\t%*s:0x%"PRIx64"\n", WIDTH, "entry->sess_id", \
entry->sess_id);\
printf("\t%*s:0x%"PRIx32"\n", WIDTH, "ue_addr.u.ipv4_addr", \
entry->ue_addr.u.ipv4_addr);\
printf("\t%*s:0x%"PRIx32"\n", WIDTH, "ul_s1_info.enb_addr.u.ipv4_addr",\
entry->ul_s1_info.enb_addr.u.ipv4_addr);\
printf("\t%*s:0x%"PRIx32"\n", WIDTH, "ul_s1_info.sgw_addr.u.ipv4_addr",\
entry->ul_s1_info.sgw_addr.u.ipv4_addr);\
printf("\t%*s:0x%"PRIx32"\n", WIDTH, "ul_s1_info.s5s8_pgwu_addr.u.ipv4_addr",\
entry->ul_s1_info.s5s8_pgwu_addr.u.ipv4_addr);\
printf("\t%*s:0x%"PRIx32"\n", WIDTH, "dl_s1_info.s5s8_sgwu_addr.u.ipv4_addr",\
entry->dl_s1_info.s5s8_sgwu_addr.u.ipv4_addr);\
printf("\t%*s:0x%"PRIx32"\n", WIDTH, "ul_s1_info.sgw_teid", \
entry->ul_s1_info.sgw_teid);\
printf("\t%*s:0x%"PRIx32"\n", WIDTH, "dl_s1_info.enb_addr.u.ipv4_addr",\
entry->dl_s1_info.enb_addr.u.ipv4_addr);\
printf("\t%*s:0x%"PRIx32"\n", WIDTH, "dl_s1_info.sgw_addr.u.ipv4_addr",\
entry->dl_s1_info.sgw_addr.u.ipv4_addr);\
printf("\t%*s:0x%"PRIx32"\n", WIDTH, "dl_s1_info.enb_teid", \
entry->dl_s1_info.enb_teid);\
} while (0)
#else
#define PRINT_SESSION_INFO(entry) do {} while (0)
#endif
/** Function used to compare keys */
typedef int (*rte_hash_cmp_eq_t) (const void *key1, const void *key2,
size_t key_len);
/** Structure storing both primary and secondary hashes */
struct rte_hash_signatures {
union {
struct {
hash_sig_t current;
hash_sig_t alt;
};
uint64_t sig;
};
};
#define RTE_HASH_BUCKET_ENTRIES 4
/** Bucket structure */
struct rte_hash_bucket {
struct rte_hash_signatures signatures[RTE_HASH_BUCKET_ENTRIES];
/** Includes dummy key index that always contains index 0 */
uint32_t key_idx[RTE_HASH_BUCKET_ENTRIES + 1];
uint8_t flag[RTE_HASH_BUCKET_ENTRIES];
} __rte_cache_aligned;
/** A hash table structure. */
struct rte_hash {
char name[RTE_HASH_NAMESIZE];
/** Total table entries. */
uint32_t entries;
/** Number of buckets in table. */
uint32_t num_buckets;
/** Length of hash key. */
uint32_t key_len;
/** Function used to calculate hash. */
rte_hash_function hash_func;
/** Init value used by hash_func. */
uint32_t hash_func_init_val;
/** Function used to compare keys. */
rte_hash_cmp_eq_t rte_hash_cmp_eq;
/** Bitmask for getting bucket index from hash signature */
uint32_t bucket_bitmask;
/** Size of each key entry. */
uint32_t key_entry_size;
/** Ring that stores all indexes of the free slots in the key table*/
struct rte_ring *free_slots;
/** Table storing all keys and data */
void *key_store;
/** Table with buckets storing all the hash values and key indexes
* to the key table
*/
struct rte_hash_bucket *buckets;
} __rte_cache_aligned;
int
iface_lookup_uplink_data(struct ul_bm_key *key,
void **value)
{
return rte_hash_lookup_data(rte_uplink_hash, key, value);
}
int
iface_lookup_uplink_bulk_data(const void **key, uint32_t n,
uint64_t *hit_mask, void **value)
{
return rte_hash_lookup_bulk_data(rte_uplink_hash, key, n, hit_mask, value);
}
int
iface_lookup_downlink_data(struct dl_bm_key *key,
void **value)
{
return rte_hash_lookup_data(rte_downlink_hash, key, value);
}
int
iface_lookup_downlink_bulk_data(const void **key, uint32_t n,
uint64_t *hit_mask, void **value)
{
return rte_hash_lookup_bulk_data(rte_downlink_hash, key, n, hit_mask, value);
}
int
iface_lookup_adc_ue_data(struct dl_bm_key *key,
void **value)
{
return rte_hash_lookup_data(rte_adc_ue_hash, key, value);
}
/******************** DP- ADC, PCC funcitons **********************/
int iface_lookup_adc_data(const uint32_t key32,
void **value)
{
return rte_hash_lookup_data(rte_adc_hash, &key32, (void **)value);
}
int iface_lookup_adc_bulk_data(const void **key, uint32_t n,
uint64_t *hit_mask, void **value)
{
return rte_hash_lookup_bulk_data(rte_adc_hash, key, n, hit_mask, value);
}
struct rte_hash_bucket *bucket_ul_addr(uint64_t key)
{
uint32_t bucket_idx;
hash_sig_t sig = rte_hash_hash(rte_uplink_hash, &key);
bucket_idx = sig & rte_uplink_hash->bucket_bitmask;
return &rte_uplink_hash->buckets[bucket_idx];
}
struct rte_hash_bucket *bucket_dl_addr(uint64_t key)
{
uint32_t bucket_idx;
hash_sig_t sig = rte_hash_hash(rte_downlink_hash, &key);
bucket_idx = sig & rte_downlink_hash->bucket_bitmask;
return &rte_downlink_hash->buckets[bucket_idx];
}
int
add_rg_idx(uint32_t rg_val, struct rating_group_index_map *rg_idx_map)
{
uint32_t i;
for (i = 0; i < MAX_RATING_GRP; i++) {
if ((rg_idx_map+i)->rg_val == rg_val)
return 0;
if ((rg_idx_map+i)->rg_val == 0) {
(rg_idx_map+i)->rg_val = rg_val;
return 0;
}
}
return -1;
}
/********************* PCC rules update functions ***********************/
/**
* @brief Function to add UL pcc entry with key and
* update pcc address and rating group.
*
*/
static void
add_ul_pcc_entry_key_with_idx(struct dp_session_info *old,
struct dp_session_info *data, uint32_t idx)
{
int ret;
struct ul_bm_key ul_key;
struct dp_pcc_rules *pcc_info = NULL;
uint32_t pcc_id;
struct dp_sdf_per_bearer_info *psdf = NULL;
pcc_id = data->ul_pcc_rule_id[idx];
if (pcc_id == 0)
return;
/* get pcc rule info address*/
iface_lookup_pcc_data(pcc_id, &pcc_info);
old->ul_pcc_rule_id[idx] = pcc_id;
/* update rating group idx*/
if (old->ue_info_ptr != NULL) {
ret = add_rg_idx(pcc_info->rating_group, old->ue_info_ptr->rg_idx_map);
if (ret)
rte_panic("Failed to add rating group to index map");
}
/* alloc memory for per sdf per bearer info structure*/
psdf = rte_zmalloc("sdf per bearer", sizeof(struct dp_sdf_per_bearer_info),
RTE_CACHE_LINE_SIZE);
if (NULL == psdf) {
RTE_LOG_DP(ERR, DP, "Failed to allocate memory for sdf per bearer info");
return ;
}
psdf->pcc_info = *pcc_info;
psdf->bear_sess_info = old;
#ifdef SDF_MTR
mtr_cfg_entry(pcc_info->qos.ul_mtr_profile_index, &psdf->sdf_mtr_obj);
RTE_LOG_DP(DEBUG, DP, "SDF MTR ADD:UL pcc %d, mtr_idx %d\n",
pcc_info->rule_id, pcc_info->qos.ul_mtr_profile_index);
#endif /* SDF_MTR */
ul_key.s1u_sgw_teid = data->ul_s1_info.sgw_teid;
ul_key.rid = pcc_id;
RTE_LOG_DP(DEBUG, DP, "SDF ADD:UL_KEY: teid:0x%X, rid:%u\n",
ul_key.s1u_sgw_teid, ul_key.rid);
ret = rte_hash_add_key_data(rte_uplink_hash,
&ul_key, psdf);
if (ret < 0)
rte_panic("Failed to add entry in hash table");
}
/**
* @brief Function to del UL pcc entry with key and
* update pcc address and rating group.
*
*/
static void
del_ul_pcc_entry_key_with_idx(struct dp_session_info *data, uint32_t idx)
{
int ret;
struct ul_bm_key ul_key;
struct dp_sdf_per_bearer_info *psdf = NULL;
ul_key.s1u_sgw_teid = data->ul_s1_info.sgw_teid;
ul_key.rid = data->ul_pcc_rule_id[idx];
RTE_LOG_DP(DEBUG, DP, "BEAR_SESS DEL:UL_KEY: teid:0x%X, rid:%u\n",
ul_key.s1u_sgw_teid, ul_key.rid);
if (ul_key.rid == 0)
return;
/* Get the sdf per bearer info */
ret = iface_lookup_uplink_data(&ul_key, (void **)&psdf);
if (ret < 0) {
RTE_LOG_DP(DEBUG, DP, "BEAR_SESS DEL FAIL:UL_KEY: teid:0x%X, rid:%u\n",
ul_key.s1u_sgw_teid, ul_key.rid);
return ;
}
ret = rte_hash_del_key(rte_uplink_hash,
&ul_key);
if (ret == -ENOENT)
RTE_LOG_DP(DEBUG, DP, "key is not found\n");
if (ret == -EINVAL)
RTE_LOG_DP(DEBUG, DP, "Invalid Params: Failed to del from hash table");
if (ret < 0)
rte_panic("Failed to del entry from hash table");
rte_free(psdf);
}
/**
* @brief Function to add DL pcc entry with key and
* update pcc address and rating group.
*
*/
static void
add_dl_pcc_entry_key_with_idx(struct dp_session_info *old,
struct dp_session_info *data, uint32_t idx)
{
int ret;
struct dl_bm_key dl_key;
struct dp_pcc_rules *pcc_info = NULL;
uint32_t pcc_id;
struct dp_sdf_per_bearer_info *psdf = NULL;
pcc_id = data->dl_pcc_rule_id[idx];
if (pcc_id == 0)
return;
/* get pcc rule info address*/
iface_lookup_pcc_data(pcc_id, &pcc_info);
if (pcc_info == NULL)
return;
old->dl_pcc_rule_id[idx] = pcc_id;
/* update rating group idx*/
if (old->ue_info_ptr != NULL) {
ret = add_rg_idx(pcc_info->rating_group, old->ue_info_ptr->rg_idx_map);
if (ret)
rte_panic("Failed to add rating group to index map");
}
/* alloc memory for per sdf per bearer info */
psdf = rte_zmalloc("sdf per bearer", sizeof(struct dp_sdf_per_bearer_info),
RTE_CACHE_LINE_SIZE);
if (psdf == NULL) {
RTE_LOG_DP(ERR, DP, "Failed to allocate memory for sdf per bearer info");
return ;
}
psdf->pcc_info = *pcc_info;
psdf->bear_sess_info = old;
#ifdef SDF_MTR
mtr_cfg_entry(pcc_info->qos.dl_mtr_profile_index, &psdf->sdf_mtr_obj);
RTE_LOG_DP(DEBUG, DP, "SDF MTR ADD:DL pcc %d, mtr_idx %d\n",
pcc_info->rule_id, pcc_info->qos.dl_mtr_profile_index);
#endif /* SDF_MTR */
dl_key.ue_ipv4 = old->ue_addr.u.ipv4_addr;
dl_key.rid = pcc_id;
RTE_LOG_DP(DEBUG, DP, "SDF ADD:DL_KEY: ue_addr:"IPV4_ADDR ", rid: %d\n",
IPV4_ADDR_HOST_FORMAT(dl_key.ue_ipv4), pcc_id);
ret = rte_hash_add_key_data(rte_downlink_hash,
&dl_key, psdf);
if (ret < 0)
rte_panic("Failed to add entry in hash table");
}
#ifdef SDF_MTR
static void
flush_sdf_mtr(struct dp_sdf_per_bearer_info *psdf, char *s)
{
export_mtr(psdf->bear_sess_info, s, psdf->pcc_info.rule_id,
psdf->sdf_mtr_drops);
}
#endif /* SDF_MTR*/
#ifdef APN_MTR
static void
flush_apn_mtr(struct dp_sdf_per_bearer_info *psdf)
{
export_mtr(psdf->bear_sess_info, "UL-APN",
psdf->bear_sess_info->ue_info_ptr->ul_apn_mtr_idx,
psdf->bear_sess_info->ue_info_ptr->ul_apn_mtr_drops);
export_mtr(psdf->bear_sess_info, "DL-APN",
psdf->bear_sess_info->ue_info_ptr->dl_apn_mtr_idx,
psdf->bear_sess_info->ue_info_ptr->dl_apn_mtr_drops);
}
#endif /* APN_MTR*/
/**
* @brief Function to del DL pcc entry with key and
* update pcc address and rating group.
*
*/
static void
del_dl_pcc_entry_key_with_idx(struct dp_session_info *data, uint32_t idx)
{
int ret;
struct dl_bm_key dl_key;
struct dp_sdf_per_bearer_info *psdf = NULL;
dl_key.ue_ipv4 = data->ue_addr.u.ipv4_addr;
dl_key.rid = data->dl_pcc_rule_id[idx];
if (dl_key.rid == 0)
return;
RTE_LOG_DP(DEBUG, DP, "BEAR_SESS DEL:DL_KEY: pcc_id: %d, ue_addr:"
IPV4_ADDR "\n",
dl_key.rid, IPV4_ADDR_HOST_FORMAT(dl_key.ue_ipv4));
/* Get the sdf per bearer info */
ret = iface_lookup_downlink_data(&dl_key, (void **)&psdf);
if (ret < 0) {
RTE_LOG_DP(DEBUG, DP, "BEAR_SESS DEL FAIL:DL_KEY: ue_addr:"IPV4_ADDR ",",
IPV4_ADDR_HOST_FORMAT(dl_key.ue_ipv4));
return ;
}
ret = rte_hash_del_key(rte_downlink_hash,
&dl_key);
if (ret < 0)
rte_panic("Failed to del entry from hash table");
#ifdef SDF_MTR
flush_sdf_mtr(psdf, "DL-SDF");
#endif
rte_free(psdf);
}
/**
* @brief Check for change in PCC rule.
*/
static void
update_pcc_rules(struct dp_session_info *old,
struct dp_session_info *new)
{
uint32_t i;
uint32_t *p1;
uint32_t *p2;
uint32_t n1;
uint32_t n2;
uint32_t n;
/* Modify UL PCC rule keys*/
p1 = old->ul_pcc_rule_id;
p2 = new->ul_pcc_rule_id;
n1 = old->num_ul_pcc_rules;
n2 = new->num_ul_pcc_rules;
n = (n1 > n2) ? (n2) : (n1);
for (i = 0; i < n; i++)
if (p1[i] != p2[i]) {
del_ul_pcc_entry_key_with_idx(old, i);
add_ul_pcc_entry_key_with_idx(old, new, i);
}
if (n1 > n2)
while (i < n1) {
del_ul_pcc_entry_key_with_idx(old, i);
i++;
}
else if (n1 < n2)
while (i < n2) {
add_ul_pcc_entry_key_with_idx(old, new, i);
i++;
}
old->num_ul_pcc_rules = n2;
/* Modify DL PCC rule keys*/
p1 = old->dl_pcc_rule_id;
p2 = new->dl_pcc_rule_id;
n1 = old->num_dl_pcc_rules;
n2 = new->num_dl_pcc_rules;
n = (n1 > n2) ? (n2) : (n1);
for (i = 0; i < n; i++)
if (p1[i] != p2[i]) {
del_dl_pcc_entry_key_with_idx(old, i);
add_dl_pcc_entry_key_with_idx(old, new, i);
}
if (n1 > n2)
while (i < n1) {
del_dl_pcc_entry_key_with_idx(old, i);
i++;
}
else if (n1 < n2)
while (i < n2) {
add_dl_pcc_entry_key_with_idx(old, new, i);
i++;
}
old->num_dl_pcc_rules = n2;
}
/******************** ADC rules update functions **************/
/**
* @brief Function to copy fields from struct adc_rules to
* struct dp_adc_rules. *
*/
static void
copy_dp_adc_rules(struct dp_adc_rules *dst,
struct adc_rules *src)
{
dst->rule_id = src->rule_id;
}
/**
* @brief Function to add adc entry with key and
* update adc address and rating group.
*
*/
static void
add_adc_entry_key_with_idx(struct ue_session_info *old,
struct ue_session_info *new, uint32_t idx)
{
int ret;
struct dl_bm_key key;
struct adc_rules *adc_info;
uint32_t adc_id;
uint64_t pkts_mask = 1;
struct dp_adc_ue_info *padc_ue;
void *data = NULL;
adc_id = new->adc_rule_id[idx];
if (adc_id == 0)
return;
key.ue_ipv4 = old->ue_addr.u.ipv4_addr;
key.rid = adc_id;
ret = rte_hash_lookup_data(rte_adc_ue_hash, &key, &data);
if (data)
return;
/* get adc rule info address*/
adc_rule_info_get(&adc_id, 1, &pkts_mask, (void **)&adc_info);
old->adc_rule_id[idx] = adc_id;
/* alloc memory for per ADC per UE info structure*/
padc_ue = rte_zmalloc("adc ue info", sizeof(struct dp_adc_ue_info),
RTE_CACHE_LINE_SIZE);
if (padc_ue == NULL) {
RTE_LOG_DP(ERR, DP, "Failed to allocate memory for adc ue info");
return ;
}
copy_dp_adc_rules(&padc_ue->adc_info, adc_info);
RTE_LOG_DP(DEBUG, DP, "ADC UE INFO ADD: ue_addr:"IPV4_ADDR ",",
IPV4_ADDR_HOST_FORMAT(key.ue_ipv4));
RTE_LOG_DP(DEBUG, DP, "adc_id:%u\n",
old->adc_rule_id[idx]);
ret = rte_hash_add_key_data(rte_adc_ue_hash,
&key, padc_ue);
if (ret < 0)
rte_panic("Failed to add entry in hash table");
#ifdef SDF_MTR
mtr_cfg_entry(padc_ue->adc_info.mtr_profile_index, &padc_ue->mtr_obj);
#endif /* SDF_MTR */
}
/**
* @brief Function to del adc entry with key and
* update adc address and rating group.
*
*/
static void
del_adc_entry_key_with_idx(struct ue_session_info *data, uint32_t idx)
{
int ret;
struct dl_bm_key key;
struct dp_adc_ue_info *padc_ue;
key.ue_ipv4 = data->ue_addr.u.ipv4_addr;
key.rid = data->adc_rule_id[idx];
if (key.rid == 0)
return;
RTE_LOG_DP(DEBUG, DP, "ADC UE DEL:key: adc_id: %d, ue_addr:"IPV4_ADDR ",",
key.rid, IPV4_ADDR_HOST_FORMAT(key.ue_ipv4));
/* Get per ADC per UE info structure */
ret = iface_lookup_adc_ue_data(&key, (void **)&padc_ue);
if (ret < 0) {
RTE_LOG_DP(DEBUG, DP, "ADC UE DEL Fail !!:key: adc_id: %d, ue_addr:"IPV4_ADDR ",",
key.rid, IPV4_ADDR_HOST_FORMAT(key.ue_ipv4));
return ;
}
ret = rte_hash_del_key(rte_adc_ue_hash,
&key);
if (ret < 0)
rte_panic("Failed to del entry from hash table");
/* free the memory*/
rte_free(padc_ue);
}
/**
* @brief Check for change in adc rule.
*/
static void
update_adc_rules(struct ue_session_info *old,
struct ue_session_info *new)
{
uint32_t i;
uint32_t *p1;
uint32_t *p2;
uint32_t n1;
uint32_t n2;
uint32_t n;
/* Modify adc rule keys*/
p1 = old->adc_rule_id;
p2 = new->adc_rule_id;
n1 = old->num_adc_rules;
n2 = new->num_adc_rules;
n = (n1 > n2) ? (n2) : (n1);
for (i = 0; i < n; i++)
if (p1[i] != p2[i]) {
del_adc_entry_key_with_idx(old, i);
add_adc_entry_key_with_idx(old, new, i);
}
if (n1 > n2)
while (i < n1) {
del_adc_entry_key_with_idx(old, i);
i++;
}
else if (n1 < n2)
while (i < n2) {
add_adc_entry_key_with_idx(old, new, i);
i++;
}
old->num_adc_rules = n2;
}
/******************** ADC SponsDNS Table **********************/
void print_adc_hash(void)
{
const void *next_key;
void *next_data;
uint32_t iter = 0;
while (rte_hash_iterate(rte_adc_hash, &next_key, &next_data, &iter) >= 0) {
struct in_addr tmp_ip_key;
memcpy(&tmp_ip_key, next_key, sizeof(struct in_addr));
}
puts("<\\ >\n");
}
int
adc_dns_entry_add(struct msg_adc *data)
{
struct msg_adc *adc;
uint32_t key32 = 0;
int32_t ret;
adc = rte_malloc("data", sizeof(struct msg_adc),
RTE_CACHE_LINE_SIZE);
if (adc == NULL){
RTE_LOG_DP(ERR, DP, "Failed to allocate memory");
return -1;
}
*adc = *data;
key32 = adc->ipv4;
ret = rte_hash_add_key_data(rte_adc_hash, &key32,
adc);
if (ret < 0){
RTE_LOG_DP(ERR, DP, "Failed to add entry in hash table");
return -1;
}
return 0;
}
int adc_dns_entry_delete(struct msg_adc *data)
{
struct msg_adc *adc;
uint32_t key32 = 0;
int32_t ret;
key32 = data->ipv4;
ret = rte_hash_lookup_data(rte_adc_hash, &key32,
(void **)&adc);
if (ret < 0) {
RTE_LOG_DP(ERR, DP, "Failed to del\n"
"adc key 0x%X to hash table\n",
data->ipv4);
return -1;
}
ret = rte_hash_del_key(rte_adc_hash, &key32);
if (ret < 0){
RTE_LOG_DP(ERR, DP, "Failed to del entry in hash table");
return -1;
}
rte_free(adc);
return 0;
}
/******************** Session functions **********************/
/**
* @brief Function to return session info entry address.
* if entry not found, allocate the memory & add entry.
*
*/
struct dp_session_info *
get_session_data(uint64_t sess_id, uint32_t is_mod)
{
struct dp_session_info *data = NULL;
int ret;
/* check if session exists*/
if (unlikely(rte_sess_hash == NULL))
{
static int show_message_once;
if (show_message_once == 0) {
RTE_LOG_DP(NOTICE, DP, "Sess Hash Table not yet setup\n");
show_message_once = 1;
}
return NULL;
}
rte_hash_lookup_data(rte_sess_hash, &sess_id, (void **)&data);
if (data != NULL)
return data;
/* allocate memory only if request is from session create*/
if (is_mod != SESS_CREATE)
return NULL;
/* allocate memory for session info*/
data = rte_zmalloc("data", sizeof(struct dp_session_info),
RTE_CACHE_LINE_SIZE);
if (data == NULL){
RTE_LOG_DP(ERR, DP, "Failed to allocate memory for session info\n");
return NULL;
}
/* add entry*/
ret = rte_hash_add_key_data(rte_sess_hash, &sess_id, data);
if (ret < 0){
RTE_LOG_DP(ERR, DP, "Failed to add entry in hash table\n");
rte_free(data);
return NULL;
}
return data;
}
int
dp_session_table_create(struct dp_id dp_id, uint32_t max_elements)
{
RTE_SET_USED(dp_id);
int rc;
if (rte_sess_hash) {
RTE_LOG_DP(INFO, DP, "PCC table: \"%s\" exist\n", dp_id.name);
return 0;
}
rc = hash_create(dp_id.name, &rte_sess_hash, max_elements * 4,
sizeof(uint64_t));
return rc;
}
int
dp_session_table_delete(struct dp_id dp_id)
{
RTE_SET_USED(dp_id);
rte_hash_free(rte_sess_hash);
return 0;
}
static void
copy_session_info(struct dp_session_info *dst,
struct session_info *src)
{
int i;
dst->ue_addr = src->ue_addr;
dst->ul_s1_info = src->ul_s1_info;
dst->dl_s1_info = src->dl_s1_info;
dst->num_ul_pcc_rules = src->num_ul_pcc_rules;
for (i = 0; i < dst->num_ul_pcc_rules; i++)
dst->ul_pcc_rule_id[i] = src->ul_pcc_rule_id[i];
dst->num_dl_pcc_rules = src->num_dl_pcc_rules;
for (i = 0; i < dst->num_dl_pcc_rules; i++)
dst->dl_pcc_rule_id[i] = src->dl_pcc_rule_id[i];
dst->ipcan_dp_bearer_cdr = src->ipcan_dp_bearer_cdr;
dst->sess_id = src->sess_id;
dst->client_id = src->client_id;
dst->service_id = src->service_id;
}
int
dp_session_create(struct dp_id dp_id,
struct session_info *entry)
{
PRINT_SESSION_INFO(entry);
int ret;
int i;
struct dp_session_info *data;
struct dp_session_info new;
struct ue_session_info *ue_data = NULL;
uint32_t ue_sess_id = UE_SESS_ID(entry->sess_id);
uint32_t bear_id = UE_BEAR_ID(entry->sess_id);
RTE_SET_USED(dp_id);
RTE_LOG_DP(DEBUG, DP, "BEAR_SESS ADD:sess_id:%u, bear_id:%u, ue_addr:"
IPV4_ADDR "\n",
ue_sess_id, bear_id,
IPV4_ADDR_HOST_FORMAT(entry->ue_addr.u.ipv4_addr));
if ((entry->num_ul_pcc_rules > MAX_PCC_RULES)
|| (entry->num_dl_pcc_rules > MAX_PCC_RULES)) {
RTE_LOG_DP(ERR, DP, "Number of PCC rule exceeds max limit %d\n",
MAX_PCC_RULES);
return -1;
}
if (entry->num_adc_rules > MAX_ADC_RULES) {
RTE_LOG_DP(ERR, DP, "Number of ADC rule exceeds max limit %d\n",
MAX_ADC_RULES);
return -1;
}
data = get_session_data(entry->sess_id, SESS_CREATE);
if (data == NULL) {
RTE_LOG_DP(ERR, DP, "Failed to allocate memory");
return -1;
}
copy_session_info(data, entry);
data->num_ul_pcc_rules = 0;
data->num_dl_pcc_rules = 0;
copy_session_info(&new, entry);
ret = rte_hash_lookup_data(rte_ue_hash, &ue_sess_id, (void **)&ue_data);
if ((ue_data == NULL) || (ret == -ENOENT)) {
/* return if this is not a default bearer and ue_data not created.
* only default bearer can create ue_data.*/
if (bear_id != DEFAULT_BEARER) {
/* create req for dedicated bearer, but ue_data not created,
* this means default bearer is not created for this UE. Hence
* return error and free memory allocated for dedicated bearer.
*/
RTE_LOG_DP(ERR, DP, "BEAR_SESS ADD Fail: Default bearer not found for sess_id:%u, bear_id:%u\n",
ue_sess_id, bear_id);
rte_hash_del_key(rte_sess_hash, &entry->sess_id);
free(data);
return 0;
}
/* add UE data*/
ue_data = rte_zmalloc("ue sess info", sizeof(struct ue_session_info),
RTE_CACHE_LINE_SIZE);
if (ue_data == NULL)
rte_panic("Failed to alloc mem for ue session");
ret = rte_hash_add_key_data(rte_ue_hash, &ue_sess_id, ue_data);
if (ret < 0) {
rte_panic("Failed to add entry in hash table");
return -1;
}
ue_data->ue_addr = data->ue_addr;
ue_data->ul_apn_mtr_idx = entry->ul_apn_mtr_idx;
ue_data->dl_apn_mtr_idx = entry->dl_apn_mtr_idx;
ue_data->bearer_count = 1;
#ifdef APN_MTR
mtr_cfg_entry(ue_data->ul_apn_mtr_idx,
&ue_data->ul_apn_mtr_obj);
RTE_LOG_DP(DEBUG, DP, "UL-APN MTR ADD: apn_mtr_id: %u, "
"apn_obj:0x%"PRIx64"\n",
ue_data->ul_apn_mtr_idx,
(uint64_t)&ue_data->ul_apn_mtr_obj);
mtr_cfg_entry(ue_data->dl_apn_mtr_idx,
&ue_data->dl_apn_mtr_obj);
RTE_LOG_DP(DEBUG, DP, "DL-APN MTR ADD: apn_mtr_id: %u, "
"apn_obj:0x%"PRIx64"\n",
ue_data->dl_apn_mtr_idx,
(uint64_t)&ue_data->dl_apn_mtr_obj);
#endif /* APN_MTR */
} else {
/* update UE data*/
ue_data->bearer_count += 1;
RTE_LOG_DP(DEBUG, DP, "BEAR_SESS ADD:bear_id:%u, bear_count:%u,\n",
bear_id, ue_data->bearer_count);
}
/* Update UE session info ptr */
data->ue_info_ptr = ue_data;
data->sess_state = IN_PROGRESS;
/* Update adc rules */
if (entry->num_adc_rules) {
struct ue_session_info new_ue_data;
new_ue_data.num_adc_rules = entry->num_adc_rules;
for (i = 0; i < new_ue_data.num_adc_rules; i++)
new_ue_data.adc_rule_id[i] = entry->adc_rule_id[i];
/* Update ADC rules addr*/
update_adc_rules(ue_data, &new_ue_data);
}
/* Update PCC rules addr*/
update_pcc_rules(data, &new);
data->client_id = entry->client_id;
new.client_id = entry->client_id;
return 0;
}
int
dp_session_modify(struct dp_id dp_id,
struct session_info *entry)
{
PRINT_SESSION_INFO(entry);
struct dp_session_info *data;
struct dp_session_info mod_data;
uint32_t ue_sess_id = UE_SESS_ID(entry->sess_id);
uint32_t bear_id = UE_BEAR_ID(entry->sess_id);
int i;
RTE_SET_USED(dp_id);
RTE_LOG_DP(DEBUG, DP, "BEAR_SESS MOD:sess_id:%u, bear_id:%u, ue_addr:"
IPV4_ADDR "\n",
ue_sess_id, bear_id,
IPV4_ADDR_HOST_FORMAT(entry->ue_addr.u.ipv4_addr));
if ((entry->num_ul_pcc_rules > MAX_PCC_RULES)
|| (entry->num_dl_pcc_rules > MAX_PCC_RULES)) {
RTE_LOG_DP(ERR, DP, "Number of PCC rule exceeds max limit %d\n",
MAX_PCC_RULES);
return -1;
}
if (entry->num_adc_rules > MAX_ADC_RULES) {
RTE_LOG_DP(ERR, DP, "Number of ADC rule exceeds max limit %d\n",
MAX_ADC_RULES);
return -1;
}
data = get_session_data(entry->sess_id, SESS_MODIFY);
if (data == NULL) {
RTE_LOG_DP(ERR, DP, "Session id 0x%"PRIx64" not found\n",
entry->sess_id);
fprintf(stderr, "DP:Session id 0x%"PRIx64" not found\n",
entry->sess_id);
return -1;
}
copy_session_info(&mod_data, entry);
/* Update adc rules */
if (entry->num_adc_rules) {
struct ue_session_info new_ue_data;
new_ue_data.num_adc_rules = entry->num_adc_rules;
for (i = 0; i < new_ue_data.num_adc_rules; i++)
new_ue_data.adc_rule_id[i] = entry->adc_rule_id[i];
/* Update ADC rules addr*/
update_adc_rules(data->ue_info_ptr, &new_ue_data);
}
/* Update PCC rules addr*/
update_pcc_rules(data, &mod_data);
/* Copy dl information */
struct dl_s1_info *dl_info;
dl_info = &data->dl_s1_info;
*dl_info = mod_data.dl_s1_info;
if (!dl_info->enb_teid) {
if (data->sess_state == CONNECTED)
data->sess_state = IDLE;
} else {
switch (data->sess_state) {
case IDLE:
data->sess_state = CONNECTED;
break;
case IN_PROGRESS:
{
/** Resolved queued pkts by dl core and enqueue pkts into notification ring */
#ifdef NGCORE_SHRINK
#ifdef DP_DDN
{
struct rte_mbuf *buf_pkt =
rte_ctrlmbuf_alloc(notify_msg_pool);
uint64_t *sess =
rte_pktmbuf_mtod(buf_pkt, uint64_t *);
*sess = entry->sess_id;
rte_ring_enqueue(notify_ring,
buf_pkt);
}
#endif /* DP_DDN */
#else
//GCC_Security flag
struct ue_session_info *ue_data = NULL;