6 #ifndef __INCLUDE_RTE_METER_H__
7 #define __INCLUDE_RTE_METER_H__
26 #include "rte_compat.h"
44 #define rte_meter_color rte_color
45 #define e_RTE_METER_GREEN RTE_COLOR_GREEN
46 #define e_RTE_METER_YELLOW RTE_COLOR_YELLOW
47 #define e_RTE_METER_RED RTE_COLOR_RED
48 #define e_RTE_METER_COLORS RTE_COLORS
84 struct rte_meter_srtcm_profile;
90 struct rte_meter_trtcm_profile;
96 struct rte_meter_trtcm_rfc4115_profile;
99 struct rte_meter_srtcm;
150 int __rte_experimental
152 struct rte_meter_trtcm_rfc4115_profile *p,
167 struct rte_meter_srtcm_profile *p);
181 struct rte_meter_trtcm_profile *p);
196 int __rte_experimental
198 struct rte_meter_trtcm_rfc4115_profile *p);
214 static inline enum rte_meter_color
216 struct rte_meter_srtcm_profile *p,
236 static inline enum rte_meter_color
238 struct rte_meter_srtcm_profile *p,
241 enum rte_meter_color pkt_color);
257 static inline enum rte_meter_color
259 struct rte_meter_trtcm_profile *p,
279 static inline enum rte_meter_color
281 struct rte_meter_trtcm_profile *p,
284 enum rte_meter_color pkt_color);
303 static inline enum rte_meter_color __rte_experimental
306 struct rte_meter_trtcm_rfc4115_profile *p,
329 static inline enum rte_meter_color __rte_experimental
332 struct rte_meter_trtcm_rfc4115_profile *p,
335 enum rte_meter_color pkt_color);
342 struct rte_meter_srtcm_profile {
349 uint64_t cir_bytes_per_period;
354 struct rte_meter_srtcm {
360 struct rte_meter_trtcm_profile {
367 uint64_t cir_bytes_per_period;
371 uint64_t pir_bytes_per_period;
390 struct rte_meter_trtcm_rfc4115_profile {
397 uint64_t cir_bytes_per_period;
401 uint64_t eir_bytes_per_period;
420 static inline enum rte_meter_color
422 struct rte_meter_srtcm_profile *p,
426 uint64_t time_diff, n_periods, tc, te;
429 time_diff = time - m->time;
430 n_periods = time_diff / p->cir_period;
431 m->time += n_periods * p->cir_period;
434 tc = m->tc + n_periods * p->cir_bytes_per_period;
445 m->tc = tc - pkt_len;
447 return e_RTE_METER_GREEN;
452 m->te = te - pkt_len;
453 return e_RTE_METER_YELLOW;
458 return e_RTE_METER_RED;
461 static inline enum rte_meter_color
463 struct rte_meter_srtcm_profile *p,
466 enum rte_meter_color pkt_color)
468 uint64_t time_diff, n_periods, tc, te;
471 time_diff = time - m->time;
472 n_periods = time_diff / p->cir_period;
473 m->time += n_periods * p->cir_period;
476 tc = m->tc + n_periods * p->cir_bytes_per_period;
486 if ((pkt_color == e_RTE_METER_GREEN) && (tc >= pkt_len)) {
487 m->tc = tc - pkt_len;
489 return e_RTE_METER_GREEN;
492 if ((pkt_color != e_RTE_METER_RED) && (te >= pkt_len)) {
494 m->te = te - pkt_len;
495 return e_RTE_METER_YELLOW;
500 return e_RTE_METER_RED;
503 static inline enum rte_meter_color
505 struct rte_meter_trtcm_profile *p,
509 uint64_t time_diff_tc, time_diff_tp, n_periods_tc, n_periods_tp, tc, tp;
512 time_diff_tc = time - m->
time_tc;
513 time_diff_tp = time - m->
time_tp;
514 n_periods_tc = time_diff_tc / p->cir_period;
515 n_periods_tp = time_diff_tp / p->pir_period;
516 m->
time_tc += n_periods_tc * p->cir_period;
517 m->
time_tp += n_periods_tp * p->pir_period;
519 tc = m->
tc + n_periods_tc * p->cir_bytes_per_period;
523 tp = m->
tp + n_periods_tp * p->pir_bytes_per_period;
531 return e_RTE_METER_RED;
536 m->
tp = tp - pkt_len;
537 return e_RTE_METER_YELLOW;
540 m->
tc = tc - pkt_len;
541 m->
tp = tp - pkt_len;
542 return e_RTE_METER_GREEN;
545 static inline enum rte_meter_color
547 struct rte_meter_trtcm_profile *p,
550 enum rte_meter_color pkt_color)
552 uint64_t time_diff_tc, time_diff_tp, n_periods_tc, n_periods_tp, tc, tp;
555 time_diff_tc = time - m->
time_tc;
556 time_diff_tp = time - m->
time_tp;
557 n_periods_tc = time_diff_tc / p->cir_period;
558 n_periods_tp = time_diff_tp / p->pir_period;
559 m->
time_tc += n_periods_tc * p->cir_period;
560 m->
time_tp += n_periods_tp * p->pir_period;
562 tc = m->
tc + n_periods_tc * p->cir_bytes_per_period;
566 tp = m->
tp + n_periods_tp * p->pir_bytes_per_period;
571 if ((pkt_color == e_RTE_METER_RED) || (tp < pkt_len)) {
574 return e_RTE_METER_RED;
577 if ((pkt_color == e_RTE_METER_YELLOW) || (tc < pkt_len)) {
579 m->
tp = tp - pkt_len;
580 return e_RTE_METER_YELLOW;
583 m->
tc = tc - pkt_len;
584 m->
tp = tp - pkt_len;
585 return e_RTE_METER_GREEN;
588 static inline enum rte_meter_color __rte_experimental
591 struct rte_meter_trtcm_rfc4115_profile *p,
595 uint64_t time_diff_tc, time_diff_te, n_periods_tc, n_periods_te, tc, te;
598 time_diff_tc = time - m->
time_tc;
599 time_diff_te = time - m->
time_te;
600 n_periods_tc = time_diff_tc / p->cir_period;
601 n_periods_te = time_diff_te / p->eir_period;
602 m->
time_tc += n_periods_tc * p->cir_period;
603 m->
time_te += n_periods_te * p->eir_period;
605 tc = m->
tc + n_periods_tc * p->cir_bytes_per_period;
609 te = m->
te + n_periods_te * p->eir_bytes_per_period;
615 m->
tc = tc - pkt_len;
617 return e_RTE_METER_GREEN;
621 m->
te = te - pkt_len;
622 return e_RTE_METER_YELLOW;
628 return e_RTE_METER_RED;
631 static inline enum rte_meter_color __rte_experimental
634 struct rte_meter_trtcm_rfc4115_profile *p,
637 enum rte_meter_color pkt_color)
639 uint64_t time_diff_tc, time_diff_te, n_periods_tc, n_periods_te, tc, te;
642 time_diff_tc = time - m->
time_tc;
643 time_diff_te = time - m->
time_te;
644 n_periods_tc = time_diff_tc / p->cir_period;
645 n_periods_te = time_diff_te / p->eir_period;
646 m->
time_tc += n_periods_tc * p->cir_period;
647 m->
time_te += n_periods_te * p->eir_period;
649 tc = m->
tc + n_periods_tc * p->cir_bytes_per_period;
653 te = m->
te + n_periods_te * p->eir_bytes_per_period;
658 if ((pkt_color == e_RTE_METER_GREEN) && (tc >= pkt_len)) {
659 m->
tc = tc - pkt_len;
661 return e_RTE_METER_GREEN;
664 if ((pkt_color != e_RTE_METER_RED) && (te >= pkt_len)) {
666 m->
te = te - pkt_len;
667 return e_RTE_METER_YELLOW;
673 return e_RTE_METER_RED;