-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathxran_packets_collect.c
More file actions
313 lines (262 loc) · 10.9 KB
/
xran_packets_collect.c
File metadata and controls
313 lines (262 loc) · 10.9 KB
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/*
*
* This codelet is used to collect data related to XRAN messages.
* Specifically it could the following
* - for UL and DL it will collect the following user-plane info
* - Total Packet count, total Prb count, amd inter-arrival histograms
* - for DL it will collect the following ctrl-plane info
* - Packet count, amd inter-arrival histograms
*
* The stat are collected in this codelet, but reported and zeroed in the associated reporing codelet.
* The inter-arrival histogram has 16 bins, with the bins representing the
* following inter-arrival times (in nanosecs) ..
* bin range
* 0: 0 .. 511
* 1: 512 .. 1,023
* 2: 1,024 .. 2,047
* 3: 2,048 .. 4,095
* 4: 4,096 .. 8,191
* 5: 8,192 .. 16,383
* 6: 16,384 .. 32,767
* 7: 32,768 .. 65,535
* 8: 65,536 .. 131,071
* 9: 131,072 .. 262,143
* 10: 262,144 .. 524,143
* 11: 524,288 .. 1,048,575
* 12: 1,048,576 .. 2,097,151
* 13: 2,097,152 .. 4,192,303
* 14: 4,194,304 .. 8,388,607
* 15: 8,388,608 +
*
* The histogram ranges can be altered using these macros...
* - INTER_ARRIVAL_HIST_BIN_2_VAL
* - INTER_ARRIVAL_HIST_SHIFT
* - INTER_ARRIVAL_HIST_SIZE
*
* As described above, the inter-arrival stats are collected independently for each direction/plane.
*
* Note that TDD patterns, and also RACH opportunity frequency affect the expected histogram distribution.
* Ths is explained below, in a test which has the following srsRAN confif parameters ..
*
* common_scs: 30
*
* prach_config_index: 159 i.e. PRACH occurs every 10 ms frame.
*
* tdd_ul_dl_cfg:
* dl_ul_tx_period: 10
* nof_dl_slots: 7
* nof_dl_symbols: 6
* nof_ul_slots: 2
* nof_ul_symbols: 4
*
*
*
* Here is an example of the typical UL inter-arrival stats when zero UE are connected ..
* "ulPacketStats":{
* "dataPacketStats":{
* "PacketCount":4848,
* "PrbCount":"58176",
* "packetInterArrivalInfo":{
* "hist":[0, 0, 468, 96, 594, 3367, 218, 4, 0, 0, 0, 0, 0, 0, 0, 101]}}}
* Here it can be seen that the tail bin has close to 100 entries i.e. one for every 10ms RACH opportunity.
*
* Here is an example of the typical UL inter-arrival stats when UE is connected and actively doing uplink traffic connected ..
* "ulPacketStats":{
* "dataPacketStats":{
* "PacketCount":19576, "PrbCount":"1619344",
* "packetInterArrivalInfo":{
* "hist":[0, 0, 1265, 6601, 4295, 4402, 2789, 40, 0, 0, 0, 0, 0, 121, 46, 17]}}}
* In this case it can be seen that the tail bin is smaller due to the fact that the UE is able to transmit more frequently than every 10ms,
* due to maintaining a connection at the PHY layer. It can also be seen that the number of packets increases, as expected
*
*
* In the downlink, since the config has setting "nof_ul_slots: 2", it means that there will be a gap of 2 slots in which no DL data will be
* sent. Since the config has "common_scs: 30", this means that periodically (i.e. every 0.5ms slot), inter-arrival times will be > 1ms.
* Here is an example of the DL user plane stats ..
* "dlPacketStats":{
* "dataPacketStats":{
* "PacketCount":83764, "PrbCount":"8879408",
* "packetInterArrivalInfo":{
* "hist":[62244, 403, 128, 46, 4, 2, 8271, 12468, 0, 0, 0, 0, 202, 0, 0, 0]}},
* Bin 12 (i.e. 1.048ms .. 2.097ms) has a count of 202. This is as expected to be approx 200 due to the fact that slots 8,9,18,19
* are UL-only slots, so foL user-plane an inter-arrival time >1ms will be expected every 5ms.
*/
#include "jbpf_defs.h"
#include "jbpf_helper.h"
#include "../utils/misc_utils.h"
#include "../utils/net_utils.h"
#include "xran_packet_info.pb.h"
#include "jbpf_srsran_contexts.h"
#include "xran_format.h"
// map to store data before sending to output_map
struct jbpf_load_map_def SEC("maps") output_tmp_map = {
.type = JBPF_MAP_TYPE_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(packet_stats),
.max_entries = 1,
};
// map used to store the timestamps of of when a message was processed for each direction / plane
struct jbpf_load_map_def SEC("maps") last_timestamp = {
.type = JBPF_MAP_TYPE_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(uint64_t),
.max_entries = 3, // 0: uplink u plane,
// 1: downlink u plane,
// 2: downlink c plane
};
#define LAST_TS_UL_UPLANE (0)
#define LAST_TS_DL_UPLANE (1)
#define LAST_TS_DL_CPLANE (2)
#define ECPRI_ETH_TYPE (0xaefe)
#define MAX_PRB (273)
#define INTER_ARRIVAL_HIST_BIN_2_VAL (512)
#define INTER_ARRIVAL_HIST_SHIFT (1)
#define INTER_ARRIVAL_HIST_SIZE (16)
/*
GET_HIST_BIN - Macro to retrieve bin index
Explanation:
If __bin2_v = 32:
The first bin handles 0–31, so the second bin starts at 32.
value < 32:
Values less than 32 fall into bin 0.
boundary <<= 1: (e.g. if __shift_size==1)
The boundary doubles for each subsequent bin (e.g., 64, 128, 256, etc.).
bin < max_bins - 1:
Ensures the loop does not exceed the maximum number of bins.
Final bin Value:
The bin variable contains the index of the bin into which the value falls.
*/
#define GET_HIST_BIN(__value, __max_bins, __bin2_v, __shift_size) ({ \
int __bin = 0; \
int __boundary = __bin2_v; /* Start with the second bin boundary */ \
if (__value < __bin2_v) { \
__bin = 0; /* First bin (0–31) */ \
} else { \
while (__value >= __boundary && __bin < __max_bins - 1) { \
__bin++; \
__boundary <<= __shift_size; /* Increase the boundary by (<<__shift_size) */ \
} \
} \
__bin; \
})
SEC("jbpf_ran_ofh")
uint64_t jbpf_main(void *state)
{
struct jbpf_ran_ofh_ctx *ctx;
ctx = (struct jbpf_ran_ofh_ctx *)state;
int zero_index=0;
int last_timestamp_index=0;
void *xran_pkt_start;
void* xran_pkt_end;
data_packet_stats_item* data_item = NULL;
packet_inter_arrival_info_item* inter_arrival = NULL;
// set the packet start and end pointers
xran_pkt_start = (void *)ctx->data;
xran_pkt_end = (void *)ctx->data_end;
// get access to the temporary output map
packet_stats *out = (packet_stats *)jbpf_map_lookup_elem(&output_tmp_map, &zero_index);
if (!out) {
return JBPF_CODELET_FAILURE;
}
// the xran packet is an ethernet frame as defined in https://docs.o-ran-sc.org/projects/o-ran-sc-o-du-phy/en/latest/Transport-Layer-and-ORAN-Fronthaul-Protocol-Implementation_fh.html
// decode the ethernet type
struct ethhdr *eh = (struct ethhdr *)xran_pkt_start;
if ((void*)(eh + 1) >= xran_pkt_end) {
return JBPF_CODELET_FAILURE;
}
// point past eth_hdr
void* next_hdr = (__u8 *)eh + sizeof(struct ethhdr);
// correct endianness
//uint16_t ether_type = (eh->h_proto << 8) | (eh->h_proto >> 8);
uint16_t ether_type = jbpf_ntohs(eh->h_proto);
// handle if message has VLAN
if (ether_type == ETH_P_8021Q) {
struct vlan_hdr *vl_hdr = (struct vlan_hdr *)next_hdr;
if ((void*)(vl_hdr + 1) >= xran_pkt_end) {
return JBPF_CODELET_FAILURE;
}
// correct endianness
ether_type = jbpf_ntohs(vl_hdr->h_vlan_encapsulated_proto);
//ether_type = (vl_hdr->h_vlan_encapsulated_proto << 8) | (vl_hdr->h_vlan_encapsulated_proto >> 8);
// point past the VLAN header
next_hdr = (__u8 *)next_hdr + sizeof(struct vlan_hdr);
}
if (ether_type != ECPRI_ETH_TYPE) {
return JBPF_CODELET_FAILURE;
}
// move to the ECPRI header
struct xran_ecpri_hdr *ecpri_hdr = (struct xran_ecpri_hdr *)next_hdr;
if ((void*)(ecpri_hdr + 1) >= xran_pkt_end) {
return JBPF_CODELET_FAILURE;
}
// point past the ECPRI header
next_hdr = (__u8 *)next_hdr + sizeof(struct xran_ecpri_hdr);
if (ecpri_hdr->cmnhdr.bits.ecpri_mesg_type == ECPRI_IQ_DATA)
{
// process u plane message
// move to the radio_app_common_hdr
struct radio_app_common_hdr *app_common_hdr = (struct radio_app_common_hdr *)next_hdr;
if ((void*)(app_common_hdr + 1) >= xran_pkt_end) {
return JBPF_CODELET_FAILURE;
}
// point past the Radio App common header
next_hdr = (__u8 *)next_hdr + sizeof(struct radio_app_common_hdr);
// move to the data_section_hdr
struct data_section_hdr *data_sec_hdr = (struct data_section_hdr *)next_hdr;
if ((void*)(data_sec_hdr + 1) >= xran_pkt_end) {
return JBPF_CODELET_FAILURE;
}
if (ctx->direction == JBPF_UL) {
data_item = &out->ul_packet_stats.data_packet_stats;
last_timestamp_index = LAST_TS_UL_UPLANE;
} else if (ctx->direction == JBPF_DL) {
data_item = &out->dl_packet_stats.data_packet_stats;
last_timestamp_index = LAST_TS_DL_UPLANE;
} else {
return JBPF_CODELET_FAILURE;
}
// increment the packet count
__sync_fetch_and_add(&data_item->Packet_count, 1);
// add to the PRB count
uint64_t num_prb = (int64_t)((data_sec_hdr->fields.all_bits >> 24) & 0xff);
// num_pof of 0 means max PRB (273)
num_prb = (num_prb == 0) ? MAX_PRB : num_prb;
__sync_fetch_and_add(&data_item->Prb_count, num_prb);
inter_arrival = &data_item->packet_inter_arrival_info;
} else if (ecpri_hdr->cmnhdr.bits.ecpri_mesg_type == ECPRI_RT_CONTROL_DATA) {
// process c plane message
// we only expect CONTROL in dl
if (ctx->direction != JBPF_DL) {
return JBPF_CODELET_FAILURE;
}
ctrl_packet_stats_item* ctrl_item = &out->dl_packet_stats.ctrl_packet_stats;
// increment the packet count
__sync_fetch_and_add(&ctrl_item->Packet_count, 1);
inter_arrival = &ctrl_item->packet_inter_arrival_info;
last_timestamp_index = LAST_TS_DL_CPLANE;
} else {
return JBPF_CODELET_FAILURE;
}
// get timestamp of the last message processing for this direction / plane
uint64_t *last_ts = jbpf_map_lookup_elem(&last_timestamp, &last_timestamp_index);
if (!last_ts) {
return JBPF_CODELET_FAILURE;
}
uint64_t timestamp = jbpf_time_get_ns();
uint64_t last_ts_prev = *last_ts;
// if *last_ts_prev==0, this means it is the first message received. Therefore skip this as we
// cannot calculate an inter-arrival time
if (last_ts_prev == 0) {
*last_ts = timestamp;
return JBPF_CODELET_SUCCESS;
}
// update the inter-arrival time stats
uint64_t inter_arrival_time = timestamp - last_ts_prev;
*last_ts = timestamp;
// increment the relevant histogram bin
uint32_t inter_arrival_bin = GET_HIST_BIN(inter_arrival_time, INTER_ARRIVAL_HIST_SIZE, INTER_ARRIVAL_HIST_BIN_2_VAL, INTER_ARRIVAL_HIST_SHIFT);
inter_arrival->hist[inter_arrival_bin & (uint32_t)(sizeof(inter_arrival->hist) / sizeof(inter_arrival->hist[0]) - 1)]++;
return JBPF_CODELET_SUCCESS;
}