-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathextended_cdr.c
96 lines (82 loc) · 2.45 KB
/
extended_cdr.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
/* SPDX-License-Identifier: Apache-2.0
* Copyright(c) 2017 Intel Corporation
*/
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <rte_ether.h>
#include <rte_debug.h>
#include "cdr.h"
#include "util.h"
FILE *extended_cdr_file;
uint64_t extcdr_count;
void
extended_cdr_init(void)
{
char timestamp[NAME_MAX];
char filename[PATH_MAX];
extcdr_count = 0;
time_t t = time(NULL);
struct tm *tmp = localtime(&t);
strftime(timestamp, NAME_MAX, "%Y%m%d%H%M%S", tmp);
snprintf(filename, PATH_MAX, "%sextended_cdr_%s"
CDR_CSV_EXTENSION, cdr_path, timestamp);
printf("Logging Extended CDR Records to %s\n", filename);
extended_cdr_file = fopen(filename, "w");
if (!extended_cdr_file)
rte_panic("Extended CDR file %s failed to open for writing\n - %s (%d)",
filename, strerror(errno), errno);
if (fprintf(extended_cdr_file, "#%s,%s,%s,%s,%s,%s,%s,%s,"
"%s,%s,%s,%s,%s\n",
"record",
"time",
"ue_ip",
"app_ip",
"direction",
"pcc_rule_id",
"pcc_rule_name",
"filter_type",
"action",
"sponsor_id",
"service_id",
"rate_group",
"report_level") < 0)
rte_panic("%s [%d] fprintf(extended_cdr_file header failed - %s "
"(%d)\n",
__FILE__, __LINE__, strerror(errno), errno);
if (fflush(extended_cdr_file))
rte_panic("%s [%d] fflush(extended_cdr_file failed - %s (%d)\n",
__FILE__, __LINE__, strerror(errno), errno);
}
void
export_extended_cdr(char *ue_ip,
char *app_ip, uint8_t pkt_mask, struct pcc_rules *pcc_info,
int direction)
{
if(UL_FLOW == direction){
fprintf(extended_cdr_file, "%"PRIu64",%"PRIu32",%s,%s,%s,%"PRIu32
",%s,%s,%s,%s,%"PRIu32",%"PRIu32",%"PRIu32"\n",
extcdr_count, 1, ue_ip, app_ip, "UL", pcc_info->rule_id,
pcc_info->rule_name,
pcc_info->sdf_idx_cnt > 0 ? "SDF":"ADC",
pkt_mask == 1 ? "CHARGED":"DROPPED",
pcc_info->sponsor_id, pcc_info->service_id,
pcc_info->rating_group, pcc_info->report_level);
} else {
fprintf(extended_cdr_file, "%"PRIu64",%"PRIu32",%s,%s,%s,%"PRIu32
",%s,%s,%s,%s,%"PRIu32",%"PRIu32",%"PRIu32"\n",
extcdr_count, 1, app_ip, ue_ip, "DL", pcc_info->rule_id,
pcc_info->rule_name,
pcc_info->sdf_idx_cnt > 0 ? "SDF":"ADC",
pkt_mask == 1 ? "CHARGED":"DROPPED",
pcc_info->sponsor_id, pcc_info->service_id,
pcc_info->rating_group, pcc_info->report_level);
}
fflush(extended_cdr_file);
++extcdr_count;
}