1
2
3
4
5
6#ifndef __INCLUDE_RTE_METER_H__
7#define __INCLUDE_RTE_METER_H__
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13
14
15
16
17
18
19
20
21
22
23
24#include <stdint.h>
25
26#include "rte_compat.h"
27
28
29
30
31
32
33
34
35
36enum rte_color {
37 RTE_COLOR_GREEN = 0,
38 RTE_COLOR_YELLOW,
39 RTE_COLOR_RED,
40 RTE_COLORS
41};
42
43
44
45
46struct rte_meter_srtcm_params {
47 uint64_t cir;
48 uint64_t cbs;
49 uint64_t ebs;
50};
51
52
53
54
55struct rte_meter_trtcm_params {
56 uint64_t cir;
57 uint64_t pir;
58 uint64_t cbs;
59 uint64_t pbs;
60};
61
62
63
64
65
66struct rte_meter_trtcm_rfc4115_params {
67 uint64_t cir;
68 uint64_t eir;
69 uint64_t cbs;
70 uint64_t ebs;
71};
72
73
74
75
76
77struct rte_meter_srtcm_profile;
78
79
80
81
82
83struct rte_meter_trtcm_profile;
84
85
86
87
88
89struct rte_meter_trtcm_rfc4115_profile;
90
91
92struct rte_meter_srtcm;
93
94
95struct rte_meter_trtcm;
96
97
98
99
100
101struct rte_meter_trtcm_rfc4115;
102
103
104
105
106
107
108
109
110
111
112
113int
114rte_meter_srtcm_profile_config(struct rte_meter_srtcm_profile *p,
115 struct rte_meter_srtcm_params *params);
116
117
118
119
120
121
122
123
124
125
126
127int
128rte_meter_trtcm_profile_config(struct rte_meter_trtcm_profile *p,
129 struct rte_meter_trtcm_params *params);
130
131
132
133
134
135
136
137
138
139
140
141
142
143int
144rte_meter_trtcm_rfc4115_profile_config(
145 struct rte_meter_trtcm_rfc4115_profile *p,
146 struct rte_meter_trtcm_rfc4115_params *params);
147
148
149
150
151
152
153
154
155
156
157
158int
159rte_meter_srtcm_config(struct rte_meter_srtcm *m,
160 struct rte_meter_srtcm_profile *p);
161
162
163
164
165
166
167
168
169
170
171
172int
173rte_meter_trtcm_config(struct rte_meter_trtcm *m,
174 struct rte_meter_trtcm_profile *p);
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189int
190rte_meter_trtcm_rfc4115_config(struct rte_meter_trtcm_rfc4115 *m,
191 struct rte_meter_trtcm_rfc4115_profile *p);
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207static inline enum rte_color
208rte_meter_srtcm_color_blind_check(struct rte_meter_srtcm *m,
209 struct rte_meter_srtcm_profile *p,
210 uint64_t time,
211 uint32_t pkt_len);
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229static inline enum rte_color
230rte_meter_srtcm_color_aware_check(struct rte_meter_srtcm *m,
231 struct rte_meter_srtcm_profile *p,
232 uint64_t time,
233 uint32_t pkt_len,
234 enum rte_color pkt_color);
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250static inline enum rte_color
251rte_meter_trtcm_color_blind_check(struct rte_meter_trtcm *m,
252 struct rte_meter_trtcm_profile *p,
253 uint64_t time,
254 uint32_t pkt_len);
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272static inline enum rte_color
273rte_meter_trtcm_color_aware_check(struct rte_meter_trtcm *m,
274 struct rte_meter_trtcm_profile *p,
275 uint64_t time,
276 uint32_t pkt_len,
277 enum rte_color pkt_color);
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296static inline enum rte_color
297rte_meter_trtcm_rfc4115_color_blind_check(
298 struct rte_meter_trtcm_rfc4115 *m,
299 struct rte_meter_trtcm_rfc4115_profile *p,
300 uint64_t time,
301 uint32_t pkt_len);
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322static inline enum rte_color
323rte_meter_trtcm_rfc4115_color_aware_check(
324 struct rte_meter_trtcm_rfc4115 *m,
325 struct rte_meter_trtcm_rfc4115_profile *p,
326 uint64_t time,
327 uint32_t pkt_len,
328 enum rte_color pkt_color);
329
330
331
332
333
334
335struct rte_meter_srtcm_profile {
336 uint64_t cbs;
337
338 uint64_t ebs;
339
340 uint64_t cir_period;
341
342 uint64_t cir_bytes_per_period;
343
344};
345
346
347struct rte_meter_srtcm {
348 uint64_t time;
349 uint64_t tc;
350 uint64_t te;
351};
352
353struct rte_meter_trtcm_profile {
354 uint64_t cbs;
355
356 uint64_t pbs;
357
358 uint64_t cir_period;
359
360 uint64_t cir_bytes_per_period;
361
362 uint64_t pir_period;
363
364 uint64_t pir_bytes_per_period;
365
366};
367
368
369
370
371
372struct rte_meter_trtcm {
373 uint64_t time_tc;
374
375 uint64_t time_tp;
376
377 uint64_t tc;
378
379 uint64_t tp;
380
381};
382
383struct rte_meter_trtcm_rfc4115_profile {
384 uint64_t cbs;
385
386 uint64_t ebs;
387
388 uint64_t cir_period;
389
390 uint64_t cir_bytes_per_period;
391
392 uint64_t eir_period;
393
394 uint64_t eir_bytes_per_period;
395
396};
397
398
399
400
401
402struct rte_meter_trtcm_rfc4115 {
403 uint64_t time_tc;
404
405 uint64_t time_te;
406
407 uint64_t tc;
408
409 uint64_t te;
410
411};
412
413static inline enum rte_color
414rte_meter_srtcm_color_blind_check(struct rte_meter_srtcm *m,
415 struct rte_meter_srtcm_profile *p,
416 uint64_t time,
417 uint32_t pkt_len)
418{
419 uint64_t time_diff, n_periods, tc, te;
420
421
422 time_diff = time - m->time;
423 n_periods = time_diff / p->cir_period;
424 m->time += n_periods * p->cir_period;
425
426
427 tc = m->tc + n_periods * p->cir_bytes_per_period;
428 te = m->te;
429 if (tc > p->cbs) {
430 te += (tc - p->cbs);
431 if (te > p->ebs)
432 te = p->ebs;
433 tc = p->cbs;
434 }
435
436
437 if (tc >= pkt_len) {
438 m->tc = tc - pkt_len;
439 m->te = te;
440 return RTE_COLOR_GREEN;
441 }
442
443 if (te >= pkt_len) {
444 m->tc = tc;
445 m->te = te - pkt_len;
446 return RTE_COLOR_YELLOW;
447 }
448
449 m->tc = tc;
450 m->te = te;
451 return RTE_COLOR_RED;
452}
453
454static inline enum rte_color
455rte_meter_srtcm_color_aware_check(struct rte_meter_srtcm *m,
456 struct rte_meter_srtcm_profile *p,
457 uint64_t time,
458 uint32_t pkt_len,
459 enum rte_color pkt_color)
460{
461 uint64_t time_diff, n_periods, tc, te;
462
463
464 time_diff = time - m->time;
465 n_periods = time_diff / p->cir_period;
466 m->time += n_periods * p->cir_period;
467
468
469 tc = m->tc + n_periods * p->cir_bytes_per_period;
470 te = m->te;
471 if (tc > p->cbs) {
472 te += (tc - p->cbs);
473 if (te > p->ebs)
474 te = p->ebs;
475 tc = p->cbs;
476 }
477
478
479 if ((pkt_color == RTE_COLOR_GREEN) && (tc >= pkt_len)) {
480 m->tc = tc - pkt_len;
481 m->te = te;
482 return RTE_COLOR_GREEN;
483 }
484
485 if ((pkt_color != RTE_COLOR_RED) && (te >= pkt_len)) {
486 m->tc = tc;
487 m->te = te - pkt_len;
488 return RTE_COLOR_YELLOW;
489 }
490
491 m->tc = tc;
492 m->te = te;
493 return RTE_COLOR_RED;
494}
495
496static inline enum rte_color
497rte_meter_trtcm_color_blind_check(struct rte_meter_trtcm *m,
498 struct rte_meter_trtcm_profile *p,
499 uint64_t time,
500 uint32_t pkt_len)
501{
502 uint64_t time_diff_tc, time_diff_tp, n_periods_tc, n_periods_tp, tc, tp;
503
504
505 time_diff_tc = time - m->time_tc;
506 time_diff_tp = time - m->time_tp;
507 n_periods_tc = time_diff_tc / p->cir_period;
508 n_periods_tp = time_diff_tp / p->pir_period;
509 m->time_tc += n_periods_tc * p->cir_period;
510 m->time_tp += n_periods_tp * p->pir_period;
511
512 tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
513 if (tc > p->cbs)
514 tc = p->cbs;
515
516 tp = m->tp + n_periods_tp * p->pir_bytes_per_period;
517 if (tp > p->pbs)
518 tp = p->pbs;
519
520
521 if (tp < pkt_len) {
522 m->tc = tc;
523 m->tp = tp;
524 return RTE_COLOR_RED;
525 }
526
527 if (tc < pkt_len) {
528 m->tc = tc;
529 m->tp = tp - pkt_len;
530 return RTE_COLOR_YELLOW;
531 }
532
533 m->tc = tc - pkt_len;
534 m->tp = tp - pkt_len;
535 return RTE_COLOR_GREEN;
536}
537
538static inline enum rte_color
539rte_meter_trtcm_color_aware_check(struct rte_meter_trtcm *m,
540 struct rte_meter_trtcm_profile *p,
541 uint64_t time,
542 uint32_t pkt_len,
543 enum rte_color pkt_color)
544{
545 uint64_t time_diff_tc, time_diff_tp, n_periods_tc, n_periods_tp, tc, tp;
546
547
548 time_diff_tc = time - m->time_tc;
549 time_diff_tp = time - m->time_tp;
550 n_periods_tc = time_diff_tc / p->cir_period;
551 n_periods_tp = time_diff_tp / p->pir_period;
552 m->time_tc += n_periods_tc * p->cir_period;
553 m->time_tp += n_periods_tp * p->pir_period;
554
555 tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
556 if (tc > p->cbs)
557 tc = p->cbs;
558
559 tp = m->tp + n_periods_tp * p->pir_bytes_per_period;
560 if (tp > p->pbs)
561 tp = p->pbs;
562
563
564 if ((pkt_color == RTE_COLOR_RED) || (tp < pkt_len)) {
565 m->tc = tc;
566 m->tp = tp;
567 return RTE_COLOR_RED;
568 }
569
570 if ((pkt_color == RTE_COLOR_YELLOW) || (tc < pkt_len)) {
571 m->tc = tc;
572 m->tp = tp - pkt_len;
573 return RTE_COLOR_YELLOW;
574 }
575
576 m->tc = tc - pkt_len;
577 m->tp = tp - pkt_len;
578 return RTE_COLOR_GREEN;
579}
580
581static inline enum rte_color
582rte_meter_trtcm_rfc4115_color_blind_check(
583 struct rte_meter_trtcm_rfc4115 *m,
584 struct rte_meter_trtcm_rfc4115_profile *p,
585 uint64_t time,
586 uint32_t pkt_len)
587{
588 uint64_t time_diff_tc, time_diff_te, n_periods_tc, n_periods_te, tc, te;
589
590
591 time_diff_tc = time - m->time_tc;
592 time_diff_te = time - m->time_te;
593 n_periods_tc = time_diff_tc / p->cir_period;
594 n_periods_te = time_diff_te / p->eir_period;
595 m->time_tc += n_periods_tc * p->cir_period;
596 m->time_te += n_periods_te * p->eir_period;
597
598 tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
599 if (tc > p->cbs)
600 tc = p->cbs;
601
602 te = m->te + n_periods_te * p->eir_bytes_per_period;
603 if (te > p->ebs)
604 te = p->ebs;
605
606
607 if (tc >= pkt_len) {
608 m->tc = tc - pkt_len;
609 m->te = te;
610 return RTE_COLOR_GREEN;
611 }
612 if (te >= pkt_len) {
613 m->tc = tc;
614 m->te = te - pkt_len;
615 return RTE_COLOR_YELLOW;
616 }
617
618
619 m->tc = tc;
620 m->te = te;
621 return RTE_COLOR_RED;
622}
623
624static inline enum rte_color
625rte_meter_trtcm_rfc4115_color_aware_check(
626 struct rte_meter_trtcm_rfc4115 *m,
627 struct rte_meter_trtcm_rfc4115_profile *p,
628 uint64_t time,
629 uint32_t pkt_len,
630 enum rte_color pkt_color)
631{
632 uint64_t time_diff_tc, time_diff_te, n_periods_tc, n_periods_te, tc, te;
633
634
635 time_diff_tc = time - m->time_tc;
636 time_diff_te = time - m->time_te;
637 n_periods_tc = time_diff_tc / p->cir_period;
638 n_periods_te = time_diff_te / p->eir_period;
639 m->time_tc += n_periods_tc * p->cir_period;
640 m->time_te += n_periods_te * p->eir_period;
641
642 tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
643 if (tc > p->cbs)
644 tc = p->cbs;
645
646 te = m->te + n_periods_te * p->eir_bytes_per_period;
647 if (te > p->ebs)
648 te = p->ebs;
649
650
651 if ((pkt_color == RTE_COLOR_GREEN) && (tc >= pkt_len)) {
652 m->tc = tc - pkt_len;
653 m->te = te;
654 return RTE_COLOR_GREEN;
655 }
656
657 if ((pkt_color != RTE_COLOR_RED) && (te >= pkt_len)) {
658 m->tc = tc;
659 m->te = te - pkt_len;
660 return RTE_COLOR_YELLOW;
661 }
662
663
664 m->tc = tc;
665 m->te = te;
666 return RTE_COLOR_RED;
667}
668
669
670#ifdef __cplusplus
671}
672#endif
673
674#endif
675