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
|
#include <MESA_prof_load.h>
#include <pkt_classifier_engine.h>
#include <sc_node.h>
#include <sc_node_common.h>
#include <sc_trace.h>
#include <rte_graph.h>
#include <rte_graph_worker.h>
#define FWDSTEP 4
extern int sid_check(uint32_t sid);
enum
{
CLASSIFIER_NEXT_FORWARDER = 0,
CLASSIFIER_NEXT_PKT_DROP,
CLASSIFIER_NEXT_MAX
};
struct classifier_stats
{
volatile uint64_t deal_pkts;
volatile uint64_t hits;
volatile uint64_t miss;
volatile uint64_t ignore_icmp_pkts;
volatile uint64_t ignore_icmp6_pkts;
volatile uint64_t prepend_sid_err;
} __rte_cache_aligned;
struct node_classifier_main
{
unsigned int nr_max_ef_adapters;
unsigned int nr_max_vwires;
unsigned int nr_max_tera_adapters;
unsigned int ignore_all_icmp_pkts;
unsigned int ignore_all_icmp6_pkts;
struct pkt_classifier_engine * pkt_classifier_engine;
struct rule_list_parsed rule_list_parsed;
};
static struct node_classifier_main g_classifier_main = {};
static struct classifier_stats stats_per_graph[RTE_MAX_LCORE] = {};
static inline struct node_classifier_main * node_classifier_main_get(void)
{
return &g_classifier_main;
}
static inline int classifier_rules_changed(struct rule_list_parsed * old_rules, struct rule_list_parsed * new_rules)
{
if (old_rules->nr_rules != new_rules->nr_rules)
{
return RT_SUCCESS;
}
for (uint32_t new_index = 0; new_index < new_rules->nr_rules; new_index++)
{
int is_found = 0;
struct rule_field_parser * new_rule = &new_rules->rules[new_index];
for (uint32_t old_index = 0; old_index < old_rules->nr_rules; old_index++)
{
struct rule_field_parser * old_rule = &old_rules->rules[old_index];
if ((new_rule->rule_id == old_rule->rule_id) && (new_rule->priority == old_rule->priority))
{
if (memcmp(new_rule, old_rule, sizeof(struct rule_field_parser)) != 0)
{
return RT_SUCCESS;
}
is_found = 1;
break;
}
}
if (!is_found)
{
return RT_SUCCESS;
}
}
return RT_ERR;
}
/* Each ruleset type should implement its own 'rules verify' function to validate its unique match fields. */
static inline int classifier_rules_verify(const struct rule_list_parsed rule_list[])
{
for (uint32_t index = 0; index < rule_list->nr_rules; index++)
{
/* Verify the adapter ID. */
const struct rule_field_parser * rule_field_parser = &rule_list->rules[index];
if (rule_field_parser->adapter.type == ADAPTER_TYPE_EF)
{
if (ef_adapter_id_check(rule_field_parser->adapter.id) == RT_ERR)
{
MR_ERROR("The rule ID '%u' with configured ef adapter ID '%u' is invalid.", rule_field_parser->rule_id,
rule_field_parser->adapter.id);
return RT_ERR;
}
}
else if (rule_field_parser->adapter.type == ADAPTER_TYPE_VWIRE)
{
if (vwire_id_check(rule_field_parser->adapter.id) == RT_ERR)
{
MR_ERROR("The rule ID '%u' with configured vwire ID '%u' is invalid.", rule_field_parser->rule_id,
rule_field_parser->adapter.id);
return RT_ERR;
}
}
else if (rule_field_parser->adapter.type == ADAPTER_TYPE_TERA)
{
if (tera_adapter_id_check(rule_field_parser->adapter.id) == RT_ERR)
{
MR_ERROR("The rule ID '%u' with configured tera adapter ID '%u' is invalid.",
rule_field_parser->rule_id, rule_field_parser->adapter.id);
return RT_ERR;
}
}
/* Only when action.type == ACTION_NF_STEERING, verify the SID. */
if (rule_field_parser->action.type == ACTION_NF_STEERING)
{
/* Verify the sid. */
if (sid_check(rule_field_parser->action.sid) == RT_ERR)
{
MR_ERROR("The rule ID '%u' with configured action SID '%u' is invalid.", rule_field_parser->rule_id,
rule_field_parser->action.sid);
return RT_ERR;
}
}
}
return RT_SUCCESS;
}
static inline uint16_t domain_field_generator_for_classifier(enum adapter_type type, uint16_t adapter_id)
{
uint16_t domain_field = UINT16_MAX;
struct node_classifier_main * classifier_main = node_classifier_main_get();
switch (type)
{
case ADAPTER_TYPE_EF:
domain_field = adapter_id;
break;
case ADAPTER_TYPE_VWIRE:
domain_field = classifier_main->nr_max_ef_adapters + adapter_id;
break;
case ADAPTER_TYPE_TERA:
domain_field = classifier_main->nr_max_ef_adapters + classifier_main->nr_max_vwires + adapter_id;
break;
default:
domain_field = UINT16_MAX;
break;
}
return domain_field;
}
static inline void rule_list_engine_generator(struct rule_list_parsed * rule_list_parsed,
struct rule_list_engine * rule_list_engine)
{
rule_list_engine->nr_rules = rule_list_parsed->nr_rules;
for (uint32_t index = 0; index < rule_list_parsed->nr_rules; index++)
{
struct rule_field_parser * rule_field_parser = &rule_list_parsed->rules[index];
struct rule_field_engine * rule_field_engine = &rule_list_engine->rules[index];
rule_field_engine->proto = rule_field_parser->proto;
rule_field_engine->proto_mask = rule_field_parser->proto_mask;
rule_field_engine->priority = rule_field_parser->priority;
rule_field_engine->ether_type = rule_field_parser->ether_type;
rule_field_engine->src_port_start = rule_field_parser->src_port_start;
rule_field_engine->src_port_end = rule_field_parser->src_port_end;
rule_field_engine->dst_port_start = rule_field_parser->dst_port_start;
rule_field_engine->dst_port_end = rule_field_parser->dst_port_end;
rule_field_engine->src_addr_mask_len = rule_field_parser->src_addr_mask_len;
rule_field_engine->dst_addr_mask_len = rule_field_parser->dst_addr_mask_len;
rule_field_engine->rule_id = rule_field_parser->rule_id;
rule_field_engine->domain =
domain_field_generator_for_classifier(rule_field_parser->adapter.type, rule_field_parser->adapter.id);
switch (rule_field_parser->ether_type)
{
case RTE_ETHER_TYPE_IPV4:
rule_field_engine->src_addr_v4 = rule_field_parser->src_addr_v4;
rule_field_engine->dst_addr_v4 = rule_field_parser->dst_addr_v4;
break;
case RTE_ETHER_TYPE_IPV6:
memcpy(rule_field_engine->src_addr_v6, rule_field_parser->src_addr_v6,
sizeof(rule_field_engine->src_addr_v6));
memcpy(rule_field_engine->dst_addr_v6, rule_field_parser->dst_addr_v6,
sizeof(rule_field_engine->dst_addr_v6));
break;
default:
memset(rule_field_engine->src_addr_v6, 0, sizeof(rule_field_engine->src_addr_v6));
memset(rule_field_engine->dst_addr_v6, 0, sizeof(rule_field_engine->dst_addr_v6));
break;
}
memcpy(&rule_field_engine->action, &rule_field_parser->action, sizeof(rule_field_engine->action));
}
}
int classifier_rule_update(struct sc_main * sc)
{
/* Parse rules. */
struct node_classifier_main * classifier_main = node_classifier_main_get();
struct pkt_classifier_engine * pkt_classifier_engine = classifier_main->pkt_classifier_engine;
struct rule_list_parsed rule_list_parsed = {};
/* Parse static rules */
int ret = pkt_classifier_rule_parser(sc, pkt_classifier_engine_get_ruleset_type(pkt_classifier_engine), 0,
&rule_list_parsed);
if (ret != RT_SUCCESS)
{
MR_ERROR("Parsing of static packet classifier rule failed.");
return RT_ERR;
}
/* Parse dynamic rules */
ret = pkt_classifier_rule_parser(sc, pkt_classifier_engine_get_ruleset_type(pkt_classifier_engine), 1,
&rule_list_parsed);
if (ret != RT_SUCCESS)
{
MR_ERROR("Parsing of dynamic packet classifier rule failed.");
return RT_ERR;
}
ret = classifier_rules_changed(&classifier_main->rule_list_parsed, &rule_list_parsed);
if (ret != RT_SUCCESS)
{
MR_INFO("The classifier rules are not changed.\n");
return RT_SUCCESS;
}
/* Verify the classifier rule. */
ret = classifier_rules_verify(&rule_list_parsed);
if (ret != RT_SUCCESS)
{
MR_ERROR("Check classifier rules failed.");
return RT_ERR;
}
/* Generate the list of engine rules. */
struct rule_list_engine rule_list_engine = {};
rule_list_engine_generator(&rule_list_parsed, &rule_list_engine);
/* Construct the packet classifier engine. */
ret = pkt_classifier_engine_build(pkt_classifier_engine, &rule_list_engine);
if (ret != RT_SUCCESS)
{
MR_ERROR("Pkt classifier engine build failed");
return RT_ERR;
}
/* Display information about the packet classifier rules. */
memcpy(&classifier_main->rule_list_parsed, &rule_list_parsed, sizeof(struct rule_list_parsed));
classifier_rule_dump(&classifier_main->rule_list_parsed);
pkt_classifier_engine_info_dump(pkt_classifier_engine);
return RT_SUCCESS;
}
int classifier_init(struct sc_main * sc)
{
/* Initialize the main instance of the classifier. */
struct node_classifier_main * classifier_main = node_classifier_main_get();
memset(classifier_main, 0, sizeof(struct node_classifier_main));
/* Load to ignore icmp and icmpv6 options */
MESA_load_profile_uint_def(sc->local_cfgfile, "classifiers", "ignore_all_icmp_pkts",
&classifier_main->ignore_all_icmp_pkts, 0);
MESA_load_profile_uint_def(sc->local_cfgfile, "classifiers", "ignore_all_icmp6_pkts",
&classifier_main->ignore_all_icmp6_pkts, 0);
/* Create a new packet classifier engine. */
classifier_main->nr_max_ef_adapters = nr_max_ef_adapters_get();
classifier_main->nr_max_vwires = nr_max_vwires_get();
classifier_main->nr_max_tera_adapters = nr_max_tera_adapters_get();
uint16_t nr_domains = classifier_main->nr_max_ef_adapters;
nr_domains += classifier_main->nr_max_vwires;
nr_domains += +classifier_main->nr_max_tera_adapters;
/* Create pkt classifier engine */
struct pkt_classifier_engine * pkt_classifier_engine =
pkt_classifier_engine_create(sc->nr_io_thread, &sc->cpu_set_io, nr_domains, RULESET_TYPE_CLASSIFIER);
if (pkt_classifier_engine == NULL)
{
MR_ERROR("Failed to create the packet classifier engine for the classifier node.");
return RT_ERR;
}
else
{
classifier_main->pkt_classifier_engine = pkt_classifier_engine;
}
/* Parse static rules */
struct rule_list_parsed rule_list_parsed = {};
int ret = pkt_classifier_rule_parser(sc, pkt_classifier_engine_get_ruleset_type(pkt_classifier_engine), 0,
&rule_list_parsed);
if (ret != RT_SUCCESS)
{
MR_ERROR("Parsing of static packet classifier rule failed.");
return RT_ERR;
}
/* Parse dynamic rules */
ret = pkt_classifier_rule_parser(sc, pkt_classifier_engine_get_ruleset_type(pkt_classifier_engine), 1,
&rule_list_parsed);
if (ret != RT_SUCCESS)
{
MR_ERROR("Parsing of dynamic packet classifier rule failed.");
return RT_ERR;
}
/* Verify the classifier rule. */
ret = classifier_rules_verify(&rule_list_parsed);
if (ret != RT_SUCCESS)
{
MR_ERROR("Check classifier rules failed.");
return RT_ERR;
}
/* Generate the list of engine rules. */
struct rule_list_engine rule_list_engine = {};
rule_list_engine_generator(&rule_list_parsed, &rule_list_engine);
/* Construct the packet classifier engine. */
ret = pkt_classifier_engine_build(pkt_classifier_engine, &rule_list_engine);
if (ret != RT_SUCCESS)
{
MR_ERROR("Pkt classifier engine build failed");
return RT_ERR;
}
/* Display information about the packet classifier rules. */
memcpy(&classifier_main->rule_list_parsed, &rule_list_parsed, sizeof(struct rule_list_parsed));
classifier_rule_dump(&classifier_main->rule_list_parsed);
pkt_classifier_engine_info_dump(pkt_classifier_engine);
return RT_SUCCESS;
}
/* Generate and store the trace information */
static __rte_always_inline void gen_store_trace_info(struct rte_node * node, struct rte_mbuf * mbuf,
uint16_t next_node_index, struct classifier_stats * stats,
struct classifier_stats * stats_for_trace,
struct match_result_engine * result, uint8_t ignore_icmp)
{
struct dp_trace_record_meta meta = {.appsym = MR_TRACE_APPSYM, .module = node->name};
/* Populate the next node infomation */
char str_record[MR_STRING_MAX];
int len = snprintf(str_record, sizeof(str_record), "next node:%s", node->nodes[next_node_index]->name);
if (unlikely(stats->prepend_sid_err != stats_for_trace->prepend_sid_err))
{
stats_for_trace->prepend_sid_err = stats->prepend_sid_err;
len += snprintf(str_record + len, sizeof(str_record) - len, ", err:prepend sid err");
}
/* Populate the classifier result */
if (unlikely(result->nr_actions == 0))
{
if (unlikely(ignore_icmp))
{
len += snprintf(str_record + len, sizeof(str_record) - len, ", res:ignore icmp");
}
else
{
len += snprintf(str_record + len, sizeof(str_record) - len, ", res:miss");
}
}
else
{
len += snprintf(str_record + len, sizeof(str_record) - len, ", res:hit, pt:%u", result->pass_through);
for (uint8_t i = 0; i < result->nr_actions; i++)
{
struct action * action = &result->actions[i];
len += snprintf(str_record + len, sizeof(str_record) - len, ", [idx:%u, prio:%u, prep sid:%u]",
action->rule_index, i, action->sid);
}
}
/* Emit the trace record */
dp_trace_record_emit_str(sc_main_get()->trace, mbuf, rte_lcore_id(), &meta, str_record);
}
/* ++++++++++++++++++++++++++++++++++++++++++++ Classifier Node Process ++++++++++++++++++++++++++++++++++++++++++++ */
static __rte_always_inline uint16_t classifier_node_process(struct rte_graph * graph, struct rte_node * node,
void ** objs, uint16_t cnt)
{
struct node_classifier_main * classifier_main = node_classifier_main_get();
struct pkt_classifier_engine * pkt_classifier_engine = classifier_main->pkt_classifier_engine;
unsigned int ignore_all_icmp_pkts = classifier_main->ignore_all_icmp_pkts;
unsigned int ignore_all_icmp6_pkts = classifier_main->ignore_all_icmp6_pkts;
unsigned int n_left_from = cnt;
uint32_t lcore_id = rte_lcore_id();
struct classifier_stats stats = {};
struct classifier_stats stats_for_trace = {};
struct rte_mbuf ** mbufs = (struct rte_mbuf **)objs;
while (n_left_from >= FWDSTEP)
{
struct rte_mbuf ** pending_mbufs = mbufs;
mbufs += FWDSTEP;
n_left_from -= FWDSTEP;
struct mrb_metadata * mrb_metadata[FWDSTEP];
for (uint8_t pkt_idx = 0; pkt_idx < FWDSTEP; pkt_idx++)
{
mrb_metadata[pkt_idx] = mrbuf_cz_data(pending_mbufs[pkt_idx], MR_NODE_CTRLZONE_ID);
}
uint16_t domain_field_for_pkts[FWDSTEP];
for (uint8_t pkt_idx = 0; pkt_idx < FWDSTEP; pkt_idx++)
{
struct mrb_metadata * metadata = mrb_metadata[pkt_idx];
domain_field_for_pkts[pkt_idx] =
domain_field_generator_for_classifier(metadata->adapter_type, metadata->adapter_id);
}
struct match_result_engine results[FWDSTEP];
pkt_classifier_engine_multi_match(pkt_classifier_engine, lcore_id, pending_mbufs, FWDSTEP,
domain_field_for_pkts, results);
/* All the ICMP packet, go direct to egress, not for nfs */
uint8_t ignore_icmp_pkts[FWDSTEP] = {};
if (ignore_all_icmp_pkts)
{
for (uint8_t pkt_idx = 0; pkt_idx < FWDSTEP; pkt_idx++)
{
struct pkt_parser_result * pkt_parser_result = &mrb_metadata[pkt_idx]->pkt_parser_result;
void * icmp_start = complex_layer_jump_to_outermost(
pkt_parser_result, rte_pktmbuf_mtod(pending_mbufs[pkt_idx], void *), LAYER_TYPE_ID_ICMP);
if (unlikely(icmp_start != NULL))
{
ignore_icmp_pkts[pkt_idx] = 1;
results[pkt_idx].nr_actions = 0;
stats.ignore_icmp_pkts++;
}
}
}
if (ignore_all_icmp6_pkts)
{
for (uint8_t pkt_idx = 0; pkt_idx < FWDSTEP; pkt_idx++)
{
struct pkt_parser_result * pkt_parser_result = &mrb_metadata[pkt_idx]->pkt_parser_result;
void * icmp_start = complex_layer_jump_to_outermost(
pkt_parser_result, rte_pktmbuf_mtod(pending_mbufs[pkt_idx], void *), LAYER_TYPE_ID_ICMP6);
if (unlikely(icmp_start != NULL))
{
ignore_icmp_pkts[pkt_idx] = 1;
results[pkt_idx].nr_actions = 0;
stats.ignore_icmp6_pkts++;
}
}
}
/* Insert sid. */
for (uint8_t pkt_idx = 0; pkt_idx < FWDSTEP; pkt_idx++)
{
uint16_t prepend_sids[16];
uint8_t nr_actions = results[pkt_idx].nr_actions;
struct action * actions = results[pkt_idx].actions;
if (likely(nr_actions != 0))
{
if (mrb_metadata[pkt_idx]->dir == 0)
{
for (uint8_t action_idx = 0; action_idx < nr_actions; action_idx++)
{
prepend_sids[action_idx] = actions[action_idx].sid;
}
}
else
{
for (uint8_t action_idx = 0; action_idx < nr_actions; action_idx++)
{
prepend_sids[action_idx] = actions[nr_actions - action_idx - 1].sid;
}
}
if (unlikely(sid_list_prepend(&mrb_metadata[pkt_idx]->sid_list, prepend_sids, nr_actions) != 0))
{
stats.prepend_sid_err++;
}
stats.hits++;
}
else
{
if (likely(!ignore_icmp_pkts[pkt_idx]))
stats.miss++;
}
/* Check if tracing is enabled for the current Mbuf */
if (unlikely(dp_trace_record_can_emit(pending_mbufs[pkt_idx])))
{
gen_store_trace_info(node, pending_mbufs[pkt_idx], CLASSIFIER_NEXT_FORWARDER, &stats, &stats_for_trace,
&results[pkt_idx], ignore_icmp_pkts[pkt_idx]);
gen_store_trace_info_sid_list(node, pending_mbufs[pkt_idx]);
}
}
}
while (n_left_from > 0)
{
struct rte_mbuf * mbuf0 = mbufs[0];
mbufs += 1;
n_left_from -= 1;
struct match_result_engine result;
struct mrb_metadata * mrb_metadata = mrbuf_cz_data(mbuf0, MR_NODE_CTRLZONE_ID);
uint16_t pattern_group_id =
domain_field_generator_for_classifier(mrb_metadata->adapter_type, mrb_metadata->adapter_id);
pkt_classifier_engine_multi_match(pkt_classifier_engine, lcore_id, &mbuf0, 1, &pattern_group_id, &result);
/* All the ICMP packet, go direct to egress, not for nfs */
uint8_t ignore_icmp_pkt = 0;
if (ignore_all_icmp_pkts)
{
struct pkt_parser_result * pkt_parser_result = &mrb_metadata->pkt_parser_result;
void * icmp_start =
complex_layer_jump_to_outermost(pkt_parser_result, rte_pktmbuf_mtod(mbuf0, void *), LAYER_TYPE_ID_ICMP);
if (unlikely(icmp_start != NULL))
{
ignore_icmp_pkt = 1;
result.nr_actions = 0;
stats.ignore_icmp_pkts++;
}
}
if (ignore_all_icmp6_pkts)
{
struct pkt_parser_result * pkt_parser_result = &mrb_metadata->pkt_parser_result;
void * icmp_start = complex_layer_jump_to_outermost(pkt_parser_result, rte_pktmbuf_mtod(mbuf0, void *),
LAYER_TYPE_ID_ICMP6);
if (unlikely(icmp_start != NULL))
{
ignore_icmp_pkt = 1;
result.nr_actions = 0;
stats.ignore_icmp6_pkts++;
}
}
/* Insert sid. */
uint16_t prepend_sids[16];
uint8_t nr_actions = result.nr_actions;
if (likely(nr_actions != 0))
{
if (mrb_metadata->dir == 0)
{
for (uint8_t action_idx = 0; action_idx < nr_actions; action_idx++)
{
prepend_sids[action_idx] = result.actions[action_idx].sid;
}
}
else
{
for (uint8_t action_idx = 0; action_idx < nr_actions; action_idx++)
{
prepend_sids[action_idx] = result.actions[nr_actions - action_idx - 1].sid;
}
}
if (unlikely(sid_list_prepend(&mrb_metadata->sid_list, prepend_sids, nr_actions) != 0))
{
stats.prepend_sid_err++;
}
stats.hits++;
}
else
{
if (likely(!ignore_icmp_pkt))
stats.miss++;
}
/* Check if tracing is enabled for the current Mbuf */
if (unlikely(dp_trace_record_can_emit(mbuf0)))
{
gen_store_trace_info(node, mbuf0, CLASSIFIER_NEXT_FORWARDER, &stats, &stats_for_trace, &result,
ignore_icmp_pkt);
gen_store_trace_info_sid_list(node, mbuf0);
}
}
/* Forward to the next node. */
rte_node_next_stream_move(graph, node, CLASSIFIER_NEXT_FORWARDER);
/* Update the graph statistics */
struct classifier_stats * graph_stats = &stats_per_graph[graph->id];
graph_stats->deal_pkts += cnt;
graph_stats->hits += stats.hits;
graph_stats->miss += stats.miss;
graph_stats->ignore_icmp_pkts += stats.ignore_icmp_pkts;
graph_stats->ignore_icmp6_pkts += stats.ignore_icmp6_pkts;
graph_stats->prepend_sid_err += stats.prepend_sid_err;
return cnt;
}
static struct rte_node_register classifier_node_base = {
.process = classifier_node_process,
.name = "classifier",
.init = NULL,
.nb_edges = CLASSIFIER_NEXT_MAX,
.next_nodes =
{
[CLASSIFIER_NEXT_FORWARDER] = "forwarder",
[CLASSIFIER_NEXT_PKT_DROP] = "pkt_drop_trap",
},
};
RTE_NODE_REGISTER(classifier_node_base);
cJSON * classifier_node_monit_loop(struct sc_main * sc)
{
cJSON * json_root = cJSON_CreateObject();
unsigned int nr_graph_total = sc->nr_io_thread;
for (uint32_t graph_id = 0; graph_id < nr_graph_total; graph_id++)
{
struct classifier_stats * stats = &stats_per_graph[graph_id];
if (stats->deal_pkts == 0)
continue;
cJSON * graph_obj = cJSON_CreateObject();
cJSON_AddNumberToObject(graph_obj, "deal_pkts", stats->deal_pkts);
cJSON_AddNumberToObject(graph_obj, "hits", stats->hits);
cJSON_AddNumberToObject(graph_obj, "miss", stats->miss);
cJSON_AddNumberToObject(graph_obj, "ignore_icmp_pkts", stats->ignore_icmp_pkts);
cJSON_AddNumberToObject(graph_obj, "ignore_icmp6_pkts", stats->ignore_icmp6_pkts);
cJSON_AddNumberToObject(graph_obj, "prepend_sid_err", stats->prepend_sid_err);
char graph_index[MR_STRING_MAX];
snprintf(graph_index, sizeof(graph_index) - 1, "graph-%u", graph_id);
cJSON_AddItemToObject(json_root, graph_index, graph_obj);
}
cJSON_AddNumberToObject(json_root, "total_graph_num", nr_graph_total);
return json_root;
}
|