DPDK 22.11.1
Loading...
Searching...
No Matches
rte_meter.h
Go to the documentation of this file.
1
2/* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2010-2014 Intel Corporation
4 */
5
6#ifndef __INCLUDE_RTE_METER_H__
7#define __INCLUDE_RTE_METER_H__
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
24#include <stdint.h>
25
26
27/*
28 * Application Programmer's Interface (API)
29 *
30 ***/
31
40};
41
46 uint64_t cir;
47 uint64_t cbs;
48 uint64_t ebs;
49};
50
55 uint64_t cir;
56 uint64_t pir;
57 uint64_t cbs;
58 uint64_t pbs;
59};
60
66 uint64_t cir;
67 uint64_t eir;
68 uint64_t cbs;
69 uint64_t ebs;
70};
71
76struct rte_meter_srtcm_profile;
77
82struct rte_meter_trtcm_profile;
83
88struct rte_meter_trtcm_rfc4115_profile;
89
91struct rte_meter_srtcm;
92
94struct rte_meter_trtcm;
95
101
112int
113rte_meter_srtcm_profile_config(struct rte_meter_srtcm_profile *p,
114 struct rte_meter_srtcm_params *params);
115
126int
127rte_meter_trtcm_profile_config(struct rte_meter_trtcm_profile *p,
128 struct rte_meter_trtcm_params *params);
142int
144 struct rte_meter_trtcm_rfc4115_profile *p,
145 struct rte_meter_trtcm_rfc4115_params *params);
146
157int
158rte_meter_srtcm_config(struct rte_meter_srtcm *m,
159 struct rte_meter_srtcm_profile *p);
160
171int
173 struct rte_meter_trtcm_profile *p);
174
188int
190 struct rte_meter_trtcm_rfc4115_profile *p);
191
206static inline enum rte_color
207rte_meter_srtcm_color_blind_check(struct rte_meter_srtcm *m,
208 struct rte_meter_srtcm_profile *p,
209 uint64_t time,
210 uint32_t pkt_len);
211
228static inline enum rte_color
229rte_meter_srtcm_color_aware_check(struct rte_meter_srtcm *m,
230 struct rte_meter_srtcm_profile *p,
231 uint64_t time,
232 uint32_t pkt_len,
233 enum rte_color pkt_color);
234
249static inline enum rte_color
251 struct rte_meter_trtcm_profile *p,
252 uint64_t time,
253 uint32_t pkt_len);
254
271static inline enum rte_color
273 struct rte_meter_trtcm_profile *p,
274 uint64_t time,
275 uint32_t pkt_len,
276 enum rte_color pkt_color);
277
295static inline enum rte_color
297 struct rte_meter_trtcm_rfc4115 *m,
298 struct rte_meter_trtcm_rfc4115_profile *p,
299 uint64_t time,
300 uint32_t pkt_len);
301
321static inline enum rte_color
323 struct rte_meter_trtcm_rfc4115 *m,
324 struct rte_meter_trtcm_rfc4115_profile *p,
325 uint64_t time,
326 uint32_t pkt_len,
327 enum rte_color pkt_color);
328
329/*
330 * Inline implementation of run-time methods
331 *
332 ***/
333
334struct rte_meter_srtcm_profile {
335 uint64_t cbs;
337 uint64_t ebs;
339 uint64_t cir_period;
341 uint64_t cir_bytes_per_period;
343};
344
345/* Internal data structure storing the srTCM run-time context per metered traffic flow. */
346struct rte_meter_srtcm {
347 uint64_t time; /* Time of latest update of C and E token buckets */
348 uint64_t tc; /* Number of bytes currently available in the committed (C) token bucket */
349 uint64_t te; /* Number of bytes currently available in the excess (E) token bucket */
350};
351
352struct rte_meter_trtcm_profile {
353 uint64_t cbs;
355 uint64_t pbs;
357 uint64_t cir_period;
359 uint64_t cir_bytes_per_period;
361 uint64_t pir_period;
363 uint64_t pir_bytes_per_period;
365};
366
372 uint64_t time_tc;
374 uint64_t time_tp;
376 uint64_t tc;
378 uint64_t tp;
380};
381
382struct rte_meter_trtcm_rfc4115_profile {
383 uint64_t cbs;
385 uint64_t ebs;
387 uint64_t cir_period;
389 uint64_t cir_bytes_per_period;
391 uint64_t eir_period;
393 uint64_t eir_bytes_per_period;
395};
396
402 uint64_t time_tc;
404 uint64_t time_te;
406 uint64_t tc;
408 uint64_t te;
410};
411
412static inline enum rte_color
413rte_meter_srtcm_color_blind_check(struct rte_meter_srtcm *m,
414 struct rte_meter_srtcm_profile *p,
415 uint64_t time,
416 uint32_t pkt_len)
417{
418 uint64_t time_diff, n_periods, tc, te;
419
420 /* Bucket update */
421 time_diff = time - m->time;
422 n_periods = time_diff / p->cir_period;
423 m->time += n_periods * p->cir_period;
424
425 /* Put the tokens overflowing from tc into te bucket */
426 tc = m->tc + n_periods * p->cir_bytes_per_period;
427 te = m->te;
428 if (tc > p->cbs) {
429 te += (tc - p->cbs);
430 if (te > p->ebs)
431 te = p->ebs;
432 tc = p->cbs;
433 }
434
435 /* Color logic */
436 if (tc >= pkt_len) {
437 m->tc = tc - pkt_len;
438 m->te = te;
439 return RTE_COLOR_GREEN;
440 }
441
442 if (te >= pkt_len) {
443 m->tc = tc;
444 m->te = te - pkt_len;
445 return RTE_COLOR_YELLOW;
446 }
447
448 m->tc = tc;
449 m->te = te;
450 return RTE_COLOR_RED;
451}
452
453static inline enum rte_color
454rte_meter_srtcm_color_aware_check(struct rte_meter_srtcm *m,
455 struct rte_meter_srtcm_profile *p,
456 uint64_t time,
457 uint32_t pkt_len,
458 enum rte_color pkt_color)
459{
460 uint64_t time_diff, n_periods, tc, te;
461
462 /* Bucket update */
463 time_diff = time - m->time;
464 n_periods = time_diff / p->cir_period;
465 m->time += n_periods * p->cir_period;
466
467 /* Put the tokens overflowing from tc into te bucket */
468 tc = m->tc + n_periods * p->cir_bytes_per_period;
469 te = m->te;
470 if (tc > p->cbs) {
471 te += (tc - p->cbs);
472 if (te > p->ebs)
473 te = p->ebs;
474 tc = p->cbs;
475 }
476
477 /* Color logic */
478 if ((pkt_color == RTE_COLOR_GREEN) && (tc >= pkt_len)) {
479 m->tc = tc - pkt_len;
480 m->te = te;
481 return RTE_COLOR_GREEN;
482 }
483
484 if ((pkt_color != RTE_COLOR_RED) && (te >= pkt_len)) {
485 m->tc = tc;
486 m->te = te - pkt_len;
487 return RTE_COLOR_YELLOW;
488 }
489
490 m->tc = tc;
491 m->te = te;
492 return RTE_COLOR_RED;
493}
494
495static inline enum rte_color
497 struct rte_meter_trtcm_profile *p,
498 uint64_t time,
499 uint32_t pkt_len)
500{
501 uint64_t time_diff_tc, time_diff_tp, n_periods_tc, n_periods_tp, tc, tp;
502
503 /* Bucket update */
504 time_diff_tc = time - m->time_tc;
505 time_diff_tp = time - m->time_tp;
506 n_periods_tc = time_diff_tc / p->cir_period;
507 n_periods_tp = time_diff_tp / p->pir_period;
508 m->time_tc += n_periods_tc * p->cir_period;
509 m->time_tp += n_periods_tp * p->pir_period;
510
511 tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
512 if (tc > p->cbs)
513 tc = p->cbs;
514
515 tp = m->tp + n_periods_tp * p->pir_bytes_per_period;
516 if (tp > p->pbs)
517 tp = p->pbs;
518
519 /* Color logic */
520 if (tp < pkt_len) {
521 m->tc = tc;
522 m->tp = tp;
523 return RTE_COLOR_RED;
524 }
525
526 if (tc < pkt_len) {
527 m->tc = tc;
528 m->tp = tp - pkt_len;
529 return RTE_COLOR_YELLOW;
530 }
531
532 m->tc = tc - pkt_len;
533 m->tp = tp - pkt_len;
534 return RTE_COLOR_GREEN;
535}
536
537static inline enum rte_color
539 struct rte_meter_trtcm_profile *p,
540 uint64_t time,
541 uint32_t pkt_len,
542 enum rte_color pkt_color)
543{
544 uint64_t time_diff_tc, time_diff_tp, n_periods_tc, n_periods_tp, tc, tp;
545
546 /* Bucket update */
547 time_diff_tc = time - m->time_tc;
548 time_diff_tp = time - m->time_tp;
549 n_periods_tc = time_diff_tc / p->cir_period;
550 n_periods_tp = time_diff_tp / p->pir_period;
551 m->time_tc += n_periods_tc * p->cir_period;
552 m->time_tp += n_periods_tp * p->pir_period;
553
554 tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
555 if (tc > p->cbs)
556 tc = p->cbs;
557
558 tp = m->tp + n_periods_tp * p->pir_bytes_per_period;
559 if (tp > p->pbs)
560 tp = p->pbs;
561
562 /* Color logic */
563 if ((pkt_color == RTE_COLOR_RED) || (tp < pkt_len)) {
564 m->tc = tc;
565 m->tp = tp;
566 return RTE_COLOR_RED;
567 }
568
569 if ((pkt_color == RTE_COLOR_YELLOW) || (tc < pkt_len)) {
570 m->tc = tc;
571 m->tp = tp - pkt_len;
572 return RTE_COLOR_YELLOW;
573 }
574
575 m->tc = tc - pkt_len;
576 m->tp = tp - pkt_len;
577 return RTE_COLOR_GREEN;
578}
579
580static inline enum rte_color
582 struct rte_meter_trtcm_rfc4115 *m,
583 struct rte_meter_trtcm_rfc4115_profile *p,
584 uint64_t time,
585 uint32_t pkt_len)
586{
587 uint64_t time_diff_tc, time_diff_te, n_periods_tc, n_periods_te, tc, te;
588
589 /* Bucket update */
590 time_diff_tc = time - m->time_tc;
591 time_diff_te = time - m->time_te;
592 n_periods_tc = time_diff_tc / p->cir_period;
593 n_periods_te = time_diff_te / p->eir_period;
594 m->time_tc += n_periods_tc * p->cir_period;
595 m->time_te += n_periods_te * p->eir_period;
596
597 tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
598 if (tc > p->cbs)
599 tc = p->cbs;
600
601 te = m->te + n_periods_te * p->eir_bytes_per_period;
602 if (te > p->ebs)
603 te = p->ebs;
604
605 /* Color logic */
606 if (tc >= pkt_len) {
607 m->tc = tc - pkt_len;
608 m->te = te;
609 return RTE_COLOR_GREEN;
610 }
611 if (te >= pkt_len) {
612 m->tc = tc;
613 m->te = te - pkt_len;
614 return RTE_COLOR_YELLOW;
615 }
616
617 /* If we end up here the color is RED */
618 m->tc = tc;
619 m->te = te;
620 return RTE_COLOR_RED;
621}
622
623static inline enum rte_color
625 struct rte_meter_trtcm_rfc4115 *m,
626 struct rte_meter_trtcm_rfc4115_profile *p,
627 uint64_t time,
628 uint32_t pkt_len,
629 enum rte_color pkt_color)
630{
631 uint64_t time_diff_tc, time_diff_te, n_periods_tc, n_periods_te, tc, te;
632
633 /* Bucket update */
634 time_diff_tc = time - m->time_tc;
635 time_diff_te = time - m->time_te;
636 n_periods_tc = time_diff_tc / p->cir_period;
637 n_periods_te = time_diff_te / p->eir_period;
638 m->time_tc += n_periods_tc * p->cir_period;
639 m->time_te += n_periods_te * p->eir_period;
640
641 tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
642 if (tc > p->cbs)
643 tc = p->cbs;
644
645 te = m->te + n_periods_te * p->eir_bytes_per_period;
646 if (te > p->ebs)
647 te = p->ebs;
648
649 /* Color logic */
650 if ((pkt_color == RTE_COLOR_GREEN) && (tc >= pkt_len)) {
651 m->tc = tc - pkt_len;
652 m->te = te;
653 return RTE_COLOR_GREEN;
654 }
655
656 if ((pkt_color != RTE_COLOR_RED) && (te >= pkt_len)) {
657 m->tc = tc;
658 m->te = te - pkt_len;
659 return RTE_COLOR_YELLOW;
660 }
661
662 /* If we end up here the color is RED */
663 m->tc = tc;
664 m->te = te;
665 return RTE_COLOR_RED;
666}
667
668
669#ifdef __cplusplus
670}
671#endif
672
673#endif /* __INCLUDE_RTE_METER_H__ */
static enum rte_color rte_meter_trtcm_rfc4115_color_blind_check(struct rte_meter_trtcm_rfc4115 *m, struct rte_meter_trtcm_rfc4115_profile *p, uint64_t time, uint32_t pkt_len)
Definition rte_meter.h:581
static enum rte_color rte_meter_trtcm_rfc4115_color_aware_check(struct rte_meter_trtcm_rfc4115 *m, struct rte_meter_trtcm_rfc4115_profile *p, uint64_t time, uint32_t pkt_len, enum rte_color pkt_color)
Definition rte_meter.h:624
static enum rte_color rte_meter_trtcm_color_blind_check(struct rte_meter_trtcm *m, struct rte_meter_trtcm_profile *p, uint64_t time, uint32_t pkt_len)
Definition rte_meter.h:496
static enum rte_color rte_meter_trtcm_color_aware_check(struct rte_meter_trtcm *m, struct rte_meter_trtcm_profile *p, uint64_t time, uint32_t pkt_len, enum rte_color pkt_color)
Definition rte_meter.h:538
rte_color
Definition rte_meter.h:35
@ RTE_COLOR_GREEN
Definition rte_meter.h:36
@ RTE_COLOR_YELLOW
Definition rte_meter.h:37
@ RTE_COLOR_RED
Definition rte_meter.h:38
@ RTE_COLORS
Definition rte_meter.h:39
int rte_meter_trtcm_rfc4115_profile_config(struct rte_meter_trtcm_rfc4115_profile *p, struct rte_meter_trtcm_rfc4115_params *params)
int rte_meter_srtcm_profile_config(struct rte_meter_srtcm_profile *p, struct rte_meter_srtcm_params *params)
int rte_meter_srtcm_config(struct rte_meter_srtcm *m, struct rte_meter_srtcm_profile *p)
int rte_meter_trtcm_rfc4115_config(struct rte_meter_trtcm_rfc4115 *m, struct rte_meter_trtcm_rfc4115_profile *p)
static enum rte_color rte_meter_srtcm_color_aware_check(struct rte_meter_srtcm *m, struct rte_meter_srtcm_profile *p, uint64_t time, uint32_t pkt_len, enum rte_color pkt_color)
Definition rte_meter.h:454
int rte_meter_trtcm_config(struct rte_meter_trtcm *m, struct rte_meter_trtcm_profile *p)
int rte_meter_trtcm_profile_config(struct rte_meter_trtcm_profile *p, struct rte_meter_trtcm_params *params)
static enum rte_color rte_meter_srtcm_color_blind_check(struct rte_meter_srtcm *m, struct rte_meter_srtcm_profile *p, uint64_t time, uint32_t pkt_len)
Definition rte_meter.h:413
uint64_t time_tp
Definition rte_meter.h:374
uint64_t time_tc
Definition rte_meter.h:372