LCOV - code coverage report
Current view: top level - lib/meter - rte_meter.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 128 128 100.0 %
Date: 2025-12-01 19:08:10 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 38 40 95.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef __INCLUDE_RTE_METER_H__
       6                 :            : #define __INCLUDE_RTE_METER_H__
       7                 :            : 
       8                 :            : /**
       9                 :            :  * @file
      10                 :            :  * RTE Traffic Metering
      11                 :            :  *
      12                 :            :  * Traffic metering algorithms:
      13                 :            :  *    1. Single Rate Three Color Marker (srTCM): defined by IETF RFC 2697
      14                 :            :  *    2. Two Rate Three Color Marker (trTCM): defined by IETF RFC 2698
      15                 :            :  *    3. Two Rate Three Color Marker (trTCM): defined by IETF RFC 4115
      16                 :            :  */
      17                 :            : 
      18                 :            : #include <stdint.h>
      19                 :            : 
      20                 :            : #ifdef __cplusplus
      21                 :            : extern "C" {
      22                 :            : #endif
      23                 :            : 
      24                 :            : /*
      25                 :            :  * Application Programmer's Interface (API)
      26                 :            :  */
      27                 :            : 
      28                 :            : /**
      29                 :            :  * Color
      30                 :            :  */
      31                 :            : enum rte_color {
      32                 :            :         RTE_COLOR_GREEN = 0, /**< Green */
      33                 :            :         RTE_COLOR_YELLOW, /**< Yellow */
      34                 :            :         RTE_COLOR_RED, /**< Red */
      35                 :            :         RTE_COLORS /**< Number of colors */
      36                 :            : };
      37                 :            : 
      38                 :            : /** srTCM parameters per metered traffic flow. The CIR, CBS and EBS parameters only
      39                 :            : count bytes of IP packets and do not include link specific headers. At least one of
      40                 :            : the CBS or EBS parameters has to be greater than zero. */
      41                 :            : struct rte_meter_srtcm_params {
      42                 :            :         uint64_t cir; /**< Committed Information Rate (CIR). Measured in bytes per second. */
      43                 :            :         uint64_t cbs; /**< Committed Burst Size (CBS).  Measured in bytes. */
      44                 :            :         uint64_t ebs; /**< Excess Burst Size (EBS).  Measured in bytes. */
      45                 :            : };
      46                 :            : 
      47                 :            : /** trTCM parameters per metered traffic flow. The CIR, PIR, CBS and PBS parameters
      48                 :            : only count bytes of IP packets and do not include link specific headers. PIR has to
      49                 :            : be greater than or equal to CIR. Both CBS or EBS have to be greater than zero. */
      50                 :            : struct rte_meter_trtcm_params {
      51                 :            :         uint64_t cir; /**< Committed Information Rate (CIR). Measured in bytes per second. */
      52                 :            :         uint64_t pir; /**< Peak Information Rate (PIR). Measured in bytes per second. */
      53                 :            :         uint64_t cbs; /**< Committed Burst Size (CBS). Measured in bytes. */
      54                 :            :         uint64_t pbs; /**< Peak Burst Size (PBS). Measured in bytes. */
      55                 :            : };
      56                 :            : 
      57                 :            : /** trTCM parameters per metered traffic flow. The CIR, EIR, CBS and EBS
      58                 :            : parameters only count bytes of IP packets and do not include link specific
      59                 :            : headers. The CBS and EBS need to be greater than zero if CIR and EIR are
      60                 :            : none-zero respectively.*/
      61                 :            : struct rte_meter_trtcm_rfc4115_params {
      62                 :            :         uint64_t cir; /**< Committed Information Rate (CIR). Measured in bytes per second. */
      63                 :            :         uint64_t eir; /**< Excess Information Rate (EIR). Measured in bytes per second. */
      64                 :            :         uint64_t cbs; /**< Committed Burst Size (CBS). Measured in bytes. */
      65                 :            :         uint64_t ebs; /**< Excess Burst Size (EBS). Measured in bytes. */
      66                 :            : };
      67                 :            : 
      68                 :            : /**
      69                 :            :  * Internal data structure storing the srTCM configuration profile. Typically
      70                 :            :  * shared by multiple srTCM objects.
      71                 :            :  */
      72                 :            : struct rte_meter_srtcm_profile;
      73                 :            : 
      74                 :            : /**
      75                 :            :  * Internal data structure storing the trTCM configuration profile. Typically
      76                 :            :  * shared by multiple trTCM objects.
      77                 :            :  */
      78                 :            : struct rte_meter_trtcm_profile;
      79                 :            : 
      80                 :            : /**
      81                 :            :  * Internal data structure storing the trTCM RFC4115 configuration profile.
      82                 :            :  * Typically shared by multiple trTCM objects.
      83                 :            :  */
      84                 :            : struct rte_meter_trtcm_rfc4115_profile;
      85                 :            : 
      86                 :            : /** Internal data structure storing the srTCM run-time context per metered traffic flow. */
      87                 :            : struct rte_meter_srtcm;
      88                 :            : 
      89                 :            : /** Internal data structure storing the trTCM run-time context per metered traffic flow. */
      90                 :            : struct rte_meter_trtcm;
      91                 :            : 
      92                 :            : /**
      93                 :            :  * Internal data structure storing the trTCM RFC4115 run-time context per
      94                 :            :  * metered traffic flow.
      95                 :            :  */
      96                 :            : struct rte_meter_trtcm_rfc4115;
      97                 :            : 
      98                 :            : /**
      99                 :            :  * srTCM profile configuration
     100                 :            :  *
     101                 :            :  * @param p
     102                 :            :  *    Pointer to pre-allocated srTCM profile data structure
     103                 :            :  * @param params
     104                 :            :  *    srTCM profile parameters
     105                 :            :  * @return
     106                 :            :  *    0 upon success, error code otherwise
     107                 :            :  */
     108                 :            : int
     109                 :            : rte_meter_srtcm_profile_config(struct rte_meter_srtcm_profile *p,
     110                 :            :         struct rte_meter_srtcm_params *params);
     111                 :            : 
     112                 :            : /**
     113                 :            :  * trTCM profile configuration
     114                 :            :  *
     115                 :            :  * @param p
     116                 :            :  *    Pointer to pre-allocated trTCM profile data structure
     117                 :            :  * @param params
     118                 :            :  *    trTCM profile parameters
     119                 :            :  * @return
     120                 :            :  *    0 upon success, error code otherwise
     121                 :            :  */
     122                 :            : int
     123                 :            : rte_meter_trtcm_profile_config(struct rte_meter_trtcm_profile *p,
     124                 :            :         struct rte_meter_trtcm_params *params);
     125                 :            : /**
     126                 :            :  * trTCM RFC 4115 profile configuration
     127                 :            :  *
     128                 :            :  * @param p
     129                 :            :  *    Pointer to pre-allocated trTCM profile data structure
     130                 :            :  * @param params
     131                 :            :  *    trTCM profile parameters
     132                 :            :  * @return
     133                 :            :  *    0 upon success, error code otherwise
     134                 :            :  */
     135                 :            : int
     136                 :            : rte_meter_trtcm_rfc4115_profile_config(
     137                 :            :         struct rte_meter_trtcm_rfc4115_profile *p,
     138                 :            :         struct rte_meter_trtcm_rfc4115_params *params);
     139                 :            : 
     140                 :            : /**
     141                 :            :  * srTCM configuration per metered traffic flow
     142                 :            :  *
     143                 :            :  * @param m
     144                 :            :  *    Pointer to pre-allocated srTCM data structure
     145                 :            :  * @param p
     146                 :            :  *    srTCM profile. Needs to be valid.
     147                 :            :  * @return
     148                 :            :  *    0 upon success, error code otherwise
     149                 :            :  */
     150                 :            : int
     151                 :            : rte_meter_srtcm_config(struct rte_meter_srtcm *m,
     152                 :            :         struct rte_meter_srtcm_profile *p);
     153                 :            : 
     154                 :            : /**
     155                 :            :  * trTCM configuration per metered traffic flow
     156                 :            :  *
     157                 :            :  * @param m
     158                 :            :  *    Pointer to pre-allocated trTCM data structure
     159                 :            :  * @param p
     160                 :            :  *    trTCM profile. Needs to be valid.
     161                 :            :  * @return
     162                 :            :  *    0 upon success, error code otherwise
     163                 :            :  */
     164                 :            : int
     165                 :            : rte_meter_trtcm_config(struct rte_meter_trtcm *m,
     166                 :            :         struct rte_meter_trtcm_profile *p);
     167                 :            : 
     168                 :            : /**
     169                 :            :  * trTCM RFC 4115 configuration per metered traffic flow
     170                 :            :  *
     171                 :            :  * @param m
     172                 :            :  *    Pointer to pre-allocated trTCM data structure
     173                 :            :  * @param p
     174                 :            :  *    trTCM profile. Needs to be valid.
     175                 :            :  * @return
     176                 :            :  *    0 upon success, error code otherwise
     177                 :            :  */
     178                 :            : int
     179                 :            : rte_meter_trtcm_rfc4115_config(struct rte_meter_trtcm_rfc4115 *m,
     180                 :            :         struct rte_meter_trtcm_rfc4115_profile *p);
     181                 :            : 
     182                 :            : /**
     183                 :            :  * srTCM color blind traffic metering
     184                 :            :  *
     185                 :            :  * @param m
     186                 :            :  *    Handle to srTCM instance
     187                 :            :  * @param p
     188                 :            :  *    srTCM profile specified at srTCM object creation time
     189                 :            :  * @param time
     190                 :            :  *    Current CPU time stamp (measured in CPU cycles)
     191                 :            :  * @param pkt_len
     192                 :            :  *    Length of the current IP packet (measured in bytes)
     193                 :            :  * @return
     194                 :            :  *    Color assigned to the current IP packet
     195                 :            :  */
     196                 :            : static inline enum rte_color
     197                 :            : rte_meter_srtcm_color_blind_check(struct rte_meter_srtcm *m,
     198                 :            :         struct rte_meter_srtcm_profile *p,
     199                 :            :         uint64_t time,
     200                 :            :         uint32_t pkt_len);
     201                 :            : 
     202                 :            : /**
     203                 :            :  * srTCM color aware traffic metering
     204                 :            :  *
     205                 :            :  * @param m
     206                 :            :  *    Handle to srTCM instance
     207                 :            :  * @param p
     208                 :            :  *    srTCM profile specified at srTCM object creation time
     209                 :            :  * @param time
     210                 :            :  *    Current CPU time stamp (measured in CPU cycles)
     211                 :            :  * @param pkt_len
     212                 :            :  *    Length of the current IP packet (measured in bytes)
     213                 :            :  * @param pkt_color
     214                 :            :  *    Input color of the current IP packet
     215                 :            :  * @return
     216                 :            :  *    Color assigned to the current IP packet
     217                 :            :  */
     218                 :            : static inline enum rte_color
     219                 :            : rte_meter_srtcm_color_aware_check(struct rte_meter_srtcm *m,
     220                 :            :         struct rte_meter_srtcm_profile *p,
     221                 :            :         uint64_t time,
     222                 :            :         uint32_t pkt_len,
     223                 :            :         enum rte_color pkt_color);
     224                 :            : 
     225                 :            : /**
     226                 :            :  * trTCM color blind traffic metering
     227                 :            :  *
     228                 :            :  * @param m
     229                 :            :  *    Handle to trTCM instance
     230                 :            :  * @param p
     231                 :            :  *    trTCM profile specified at trTCM object creation time
     232                 :            :  * @param time
     233                 :            :  *    Current CPU time stamp (measured in CPU cycles)
     234                 :            :  * @param pkt_len
     235                 :            :  *    Length of the current IP packet (measured in bytes)
     236                 :            :  * @return
     237                 :            :  *    Color assigned to the current IP packet
     238                 :            :  */
     239                 :            : static inline enum rte_color
     240                 :            : rte_meter_trtcm_color_blind_check(struct rte_meter_trtcm *m,
     241                 :            :         struct rte_meter_trtcm_profile *p,
     242                 :            :         uint64_t time,
     243                 :            :         uint32_t pkt_len);
     244                 :            : 
     245                 :            : /**
     246                 :            :  * trTCM color aware traffic metering
     247                 :            :  *
     248                 :            :  * @param m
     249                 :            :  *    Handle to trTCM instance
     250                 :            :  * @param p
     251                 :            :  *    trTCM profile specified at trTCM object creation time
     252                 :            :  * @param time
     253                 :            :  *    Current CPU time stamp (measured in CPU cycles)
     254                 :            :  * @param pkt_len
     255                 :            :  *    Length of the current IP packet (measured in bytes)
     256                 :            :  * @param pkt_color
     257                 :            :  *    Input color of the current IP packet
     258                 :            :  * @return
     259                 :            :  *    Color assigned to the current IP packet
     260                 :            :  */
     261                 :            : static inline enum rte_color
     262                 :            : rte_meter_trtcm_color_aware_check(struct rte_meter_trtcm *m,
     263                 :            :         struct rte_meter_trtcm_profile *p,
     264                 :            :         uint64_t time,
     265                 :            :         uint32_t pkt_len,
     266                 :            :         enum rte_color pkt_color);
     267                 :            : 
     268                 :            : /**
     269                 :            :  * trTCM RFC4115 color blind traffic metering
     270                 :            :  *
     271                 :            :  * @param m
     272                 :            :  *    Handle to trTCM instance
     273                 :            :  * @param p
     274                 :            :  *    trTCM profile specified at trTCM object creation time
     275                 :            :  * @param time
     276                 :            :  *    Current CPU time stamp (measured in CPU cycles)
     277                 :            :  * @param pkt_len
     278                 :            :  *    Length of the current IP packet (measured in bytes)
     279                 :            :  * @return
     280                 :            :  *    Color assigned to the current IP packet
     281                 :            :  */
     282                 :            : static inline enum rte_color
     283                 :            : rte_meter_trtcm_rfc4115_color_blind_check(
     284                 :            :         struct rte_meter_trtcm_rfc4115 *m,
     285                 :            :         struct rte_meter_trtcm_rfc4115_profile *p,
     286                 :            :         uint64_t time,
     287                 :            :         uint32_t pkt_len);
     288                 :            : 
     289                 :            : /**
     290                 :            :  * trTCM RFC4115 color aware traffic metering
     291                 :            :  *
     292                 :            :  * @param m
     293                 :            :  *    Handle to trTCM instance
     294                 :            :  * @param p
     295                 :            :  *    trTCM profile specified at trTCM object creation time
     296                 :            :  * @param time
     297                 :            :  *    Current CPU time stamp (measured in CPU cycles)
     298                 :            :  * @param pkt_len
     299                 :            :  *    Length of the current IP packet (measured in bytes)
     300                 :            :  * @param pkt_color
     301                 :            :  *    Input color of the current IP packet
     302                 :            :  * @return
     303                 :            :  *    Color assigned to the current IP packet
     304                 :            :  */
     305                 :            : static inline enum rte_color
     306                 :            : rte_meter_trtcm_rfc4115_color_aware_check(
     307                 :            :         struct rte_meter_trtcm_rfc4115 *m,
     308                 :            :         struct rte_meter_trtcm_rfc4115_profile *p,
     309                 :            :         uint64_t time,
     310                 :            :         uint32_t pkt_len,
     311                 :            :         enum rte_color pkt_color);
     312                 :            : 
     313                 :            : /*
     314                 :            :  * Inline implementation of run-time methods
     315                 :            :  */
     316                 :            : 
     317                 :            : struct rte_meter_srtcm_profile {
     318                 :            :         uint64_t cbs;
     319                 :            :         /**< Upper limit for C token bucket */
     320                 :            :         uint64_t ebs;
     321                 :            :         /**< Upper limit for E token bucket */
     322                 :            :         uint64_t cir_period;
     323                 :            :         /**< Number of CPU cycles for each update of C and E token buckets */
     324                 :            :         uint64_t cir_bytes_per_period;
     325                 :            :         /**< Number of bytes to add to C and E token buckets on each update */
     326                 :            : };
     327                 :            : 
     328                 :            : /* Internal data structure storing the srTCM run-time context per metered traffic flow. */
     329                 :            : struct rte_meter_srtcm {
     330                 :            :         uint64_t time; /* Time of latest update of C and E token buckets */
     331                 :            :         uint64_t tc;   /* Number of bytes currently available in the committed (C) token bucket */
     332                 :            :         uint64_t te;   /* Number of bytes currently available in the excess (E) token bucket */
     333                 :            : };
     334                 :            : 
     335                 :            : struct rte_meter_trtcm_profile {
     336                 :            :         uint64_t cbs;
     337                 :            :         /**< Upper limit for C token bucket */
     338                 :            :         uint64_t pbs;
     339                 :            :         /**< Upper limit for P token bucket */
     340                 :            :         uint64_t cir_period;
     341                 :            :         /**< Number of CPU cycles for one update of C token bucket */
     342                 :            :         uint64_t cir_bytes_per_period;
     343                 :            :         /**< Number of bytes to add to C token bucket on each update */
     344                 :            :         uint64_t pir_period;
     345                 :            :         /**< Number of CPU cycles for one update of P token bucket */
     346                 :            :         uint64_t pir_bytes_per_period;
     347                 :            :         /**< Number of bytes to add to P token bucket on each update */
     348                 :            : };
     349                 :            : 
     350                 :            : /**
     351                 :            :  * Internal data structure storing the trTCM run-time context per metered
     352                 :            :  * traffic flow.
     353                 :            :  */
     354                 :            : struct rte_meter_trtcm {
     355                 :            :         uint64_t time_tc;
     356                 :            :         /**< Time of latest update of C token bucket */
     357                 :            :         uint64_t time_tp;
     358                 :            :         /**< Time of latest update of P token bucket */
     359                 :            :         uint64_t tc;
     360                 :            :         /**< Number of bytes currently available in committed(C) token bucket */
     361                 :            :         uint64_t tp;
     362                 :            :         /**< Number of bytes currently available in the peak(P) token bucket */
     363                 :            : };
     364                 :            : 
     365                 :            : struct rte_meter_trtcm_rfc4115_profile {
     366                 :            :         uint64_t cbs;
     367                 :            :         /**< Upper limit for C token bucket */
     368                 :            :         uint64_t ebs;
     369                 :            :         /**< Upper limit for E token bucket */
     370                 :            :         uint64_t cir_period;
     371                 :            :         /**< Number of CPU cycles for one update of C token bucket */
     372                 :            :         uint64_t cir_bytes_per_period;
     373                 :            :         /**< Number of bytes to add to C token bucket on each update */
     374                 :            :         uint64_t eir_period;
     375                 :            :         /**< Number of CPU cycles for one update of E token bucket */
     376                 :            :         uint64_t eir_bytes_per_period;
     377                 :            :         /**< Number of bytes to add to E token bucket on each update */
     378                 :            : };
     379                 :            : 
     380                 :            : /**
     381                 :            :  * Internal data structure storing the trTCM RFC4115 run-time context per
     382                 :            :  * metered traffic flow.
     383                 :            :  */
     384                 :            : struct rte_meter_trtcm_rfc4115 {
     385                 :            :         uint64_t time_tc;
     386                 :            :         /**< Time of latest update of C token bucket */
     387                 :            :         uint64_t time_te;
     388                 :            :         /**< Time of latest update of E token bucket */
     389                 :            :         uint64_t tc;
     390                 :            :         /**< Number of bytes currently available in committed(C) token bucket */
     391                 :            :         uint64_t te;
     392                 :            :         /**< Number of bytes currently available in the excess(E) token bucket */
     393                 :            : };
     394                 :            : 
     395                 :            : static inline enum rte_color
     396                 :          4 : rte_meter_srtcm_color_blind_check(struct rte_meter_srtcm *m,
     397                 :            :         struct rte_meter_srtcm_profile *p,
     398                 :            :         uint64_t time,
     399                 :            :         uint32_t pkt_len)
     400                 :            : {
     401                 :            :         uint64_t time_diff, n_periods, tc, te;
     402                 :            : 
     403                 :            :         /* Bucket update */
     404                 :          4 :         time_diff = time - m->time;
     405                 :          4 :         n_periods = time_diff / p->cir_period;
     406                 :          4 :         m->time += n_periods * p->cir_period;
     407                 :            : 
     408                 :            :         /* Put the tokens overflowing from tc into te bucket */
     409                 :          4 :         tc = m->tc + n_periods * p->cir_bytes_per_period;
     410                 :          4 :         te = m->te;
     411         [ +  - ]:          4 :         if (tc > p->cbs) {
     412                 :          4 :                 te += (tc - p->cbs);
     413                 :          4 :                 if (te > p->ebs)
     414                 :            :                         te = p->ebs;
     415                 :            :                 tc = p->cbs;
     416                 :            :         }
     417                 :            : 
     418                 :            :         /* Color logic */
     419         [ +  + ]:          4 :         if (tc >= pkt_len) {
     420                 :          1 :                 m->tc = tc - pkt_len;
     421                 :          1 :                 m->te = te;
     422                 :          1 :                 return RTE_COLOR_GREEN;
     423                 :            :         }
     424                 :            : 
     425         [ +  + ]:          3 :         if (te >= pkt_len) {
     426                 :          2 :                 m->tc = tc;
     427                 :          2 :                 m->te = te - pkt_len;
     428                 :          2 :                 return RTE_COLOR_YELLOW;
     429                 :            :         }
     430                 :            : 
     431                 :          1 :         m->tc = tc;
     432                 :          1 :         m->te = te;
     433                 :          1 :         return RTE_COLOR_RED;
     434                 :            : }
     435                 :            : 
     436                 :            : static inline enum rte_color
     437                 :         12 : rte_meter_srtcm_color_aware_check(struct rte_meter_srtcm *m,
     438                 :            :         struct rte_meter_srtcm_profile *p,
     439                 :            :         uint64_t time,
     440                 :            :         uint32_t pkt_len,
     441                 :            :         enum rte_color pkt_color)
     442                 :            : {
     443                 :            :         uint64_t time_diff, n_periods, tc, te;
     444                 :            : 
     445                 :            :         /* Bucket update */
     446                 :         12 :         time_diff = time - m->time;
     447                 :         12 :         n_periods = time_diff / p->cir_period;
     448                 :         12 :         m->time += n_periods * p->cir_period;
     449                 :            : 
     450                 :            :         /* Put the tokens overflowing from tc into te bucket */
     451                 :         12 :         tc = m->tc + n_periods * p->cir_bytes_per_period;
     452                 :         12 :         te = m->te;
     453         [ +  - ]:         12 :         if (tc > p->cbs) {
     454                 :         12 :                 te += (tc - p->cbs);
     455                 :         12 :                 if (te > p->ebs)
     456                 :            :                         te = p->ebs;
     457                 :            :                 tc = p->cbs;
     458                 :            :         }
     459                 :            : 
     460                 :            :         /* Color logic */
     461   [ +  +  +  + ]:         12 :         if ((pkt_color == RTE_COLOR_GREEN) && (tc >= pkt_len)) {
     462                 :          1 :                 m->tc = tc - pkt_len;
     463                 :          1 :                 m->te = te;
     464                 :          1 :                 return RTE_COLOR_GREEN;
     465                 :            :         }
     466                 :            : 
     467   [ +  +  +  + ]:         11 :         if ((pkt_color != RTE_COLOR_RED) && (te >= pkt_len)) {
     468                 :          5 :                 m->tc = tc;
     469                 :          5 :                 m->te = te - pkt_len;
     470                 :          5 :                 return RTE_COLOR_YELLOW;
     471                 :            :         }
     472                 :            : 
     473                 :          6 :         m->tc = tc;
     474                 :          6 :         m->te = te;
     475                 :          6 :         return RTE_COLOR_RED;
     476                 :            : }
     477                 :            : 
     478                 :            : static inline enum rte_color
     479                 :          4 : rte_meter_trtcm_color_blind_check(struct rte_meter_trtcm *m,
     480                 :            :         struct rte_meter_trtcm_profile *p,
     481                 :            :         uint64_t time,
     482                 :            :         uint32_t pkt_len)
     483                 :            : {
     484                 :            :         uint64_t time_diff_tc, time_diff_tp, n_periods_tc, n_periods_tp, tc, tp;
     485                 :            : 
     486                 :            :         /* Bucket update */
     487                 :          4 :         time_diff_tc = time - m->time_tc;
     488                 :          4 :         time_diff_tp = time - m->time_tp;
     489                 :          4 :         n_periods_tc = time_diff_tc / p->cir_period;
     490                 :          4 :         n_periods_tp = time_diff_tp / p->pir_period;
     491                 :          4 :         m->time_tc += n_periods_tc * p->cir_period;
     492                 :          4 :         m->time_tp += n_periods_tp * p->pir_period;
     493                 :            : 
     494                 :          4 :         tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
     495                 :          4 :         if (tc > p->cbs)
     496                 :            :                 tc = p->cbs;
     497                 :            : 
     498                 :          4 :         tp = m->tp + n_periods_tp * p->pir_bytes_per_period;
     499                 :          4 :         if (tp > p->pbs)
     500                 :            :                 tp = p->pbs;
     501                 :            : 
     502                 :            :         /* Color logic */
     503         [ +  + ]:          4 :         if (tp < pkt_len) {
     504                 :          1 :                 m->tc = tc;
     505                 :          1 :                 m->tp = tp;
     506                 :          1 :                 return RTE_COLOR_RED;
     507                 :            :         }
     508                 :            : 
     509         [ +  + ]:          3 :         if (tc < pkt_len) {
     510                 :          2 :                 m->tc = tc;
     511                 :          2 :                 m->tp = tp - pkt_len;
     512                 :          2 :                 return RTE_COLOR_YELLOW;
     513                 :            :         }
     514                 :            : 
     515                 :          1 :         m->tc = tc - pkt_len;
     516                 :          1 :         m->tp = tp - pkt_len;
     517                 :          1 :         return RTE_COLOR_GREEN;
     518                 :            : }
     519                 :            : 
     520                 :            : static inline enum rte_color
     521                 :         12 : rte_meter_trtcm_color_aware_check(struct rte_meter_trtcm *m,
     522                 :            :         struct rte_meter_trtcm_profile *p,
     523                 :            :         uint64_t time,
     524                 :            :         uint32_t pkt_len,
     525                 :            :         enum rte_color pkt_color)
     526                 :            : {
     527                 :            :         uint64_t time_diff_tc, time_diff_tp, n_periods_tc, n_periods_tp, tc, tp;
     528                 :            : 
     529                 :            :         /* Bucket update */
     530                 :         12 :         time_diff_tc = time - m->time_tc;
     531                 :         12 :         time_diff_tp = time - m->time_tp;
     532                 :         12 :         n_periods_tc = time_diff_tc / p->cir_period;
     533                 :         12 :         n_periods_tp = time_diff_tp / p->pir_period;
     534                 :         12 :         m->time_tc += n_periods_tc * p->cir_period;
     535                 :         12 :         m->time_tp += n_periods_tp * p->pir_period;
     536                 :            : 
     537                 :         12 :         tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
     538                 :         12 :         if (tc > p->cbs)
     539                 :            :                 tc = p->cbs;
     540                 :            : 
     541                 :         12 :         tp = m->tp + n_periods_tp * p->pir_bytes_per_period;
     542                 :         12 :         if (tp > p->pbs)
     543                 :            :                 tp = p->pbs;
     544                 :            : 
     545                 :            :         /* Color logic */
     546   [ +  +  +  + ]:         12 :         if ((pkt_color == RTE_COLOR_RED) || (tp < pkt_len)) {
     547                 :          6 :                 m->tc = tc;
     548                 :          6 :                 m->tp = tp;
     549                 :          6 :                 return RTE_COLOR_RED;
     550                 :            :         }
     551                 :            : 
     552   [ +  +  +  + ]:          6 :         if ((pkt_color == RTE_COLOR_YELLOW) || (tc < pkt_len)) {
     553                 :          5 :                 m->tc = tc;
     554                 :          5 :                 m->tp = tp - pkt_len;
     555                 :          5 :                 return RTE_COLOR_YELLOW;
     556                 :            :         }
     557                 :            : 
     558                 :          1 :         m->tc = tc - pkt_len;
     559                 :          1 :         m->tp = tp - pkt_len;
     560                 :          1 :         return RTE_COLOR_GREEN;
     561                 :            : }
     562                 :            : 
     563                 :            : static inline enum rte_color
     564                 :          4 : rte_meter_trtcm_rfc4115_color_blind_check(
     565                 :            :         struct rte_meter_trtcm_rfc4115 *m,
     566                 :            :         struct rte_meter_trtcm_rfc4115_profile *p,
     567                 :            :         uint64_t time,
     568                 :            :         uint32_t pkt_len)
     569                 :            : {
     570                 :            :         uint64_t time_diff_tc, time_diff_te, n_periods_tc, n_periods_te, tc, te;
     571                 :            : 
     572                 :            :         /* Bucket update */
     573                 :          4 :         time_diff_tc = time - m->time_tc;
     574                 :          4 :         time_diff_te = time - m->time_te;
     575                 :          4 :         n_periods_tc = time_diff_tc / p->cir_period;
     576                 :          4 :         n_periods_te = time_diff_te / p->eir_period;
     577                 :          4 :         m->time_tc += n_periods_tc * p->cir_period;
     578                 :          4 :         m->time_te += n_periods_te * p->eir_period;
     579                 :            : 
     580                 :          4 :         tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
     581                 :          4 :         if (tc > p->cbs)
     582                 :            :                 tc = p->cbs;
     583                 :            : 
     584                 :          4 :         te = m->te + n_periods_te * p->eir_bytes_per_period;
     585                 :          4 :         if (te > p->ebs)
     586                 :            :                 te = p->ebs;
     587                 :            : 
     588                 :            :         /* Color logic */
     589         [ +  + ]:          4 :         if (tc >= pkt_len) {
     590                 :          1 :                 m->tc = tc - pkt_len;
     591                 :          1 :                 m->te = te;
     592                 :          1 :                 return RTE_COLOR_GREEN;
     593                 :            :         }
     594         [ +  + ]:          3 :         if (te >= pkt_len) {
     595                 :          2 :                 m->tc = tc;
     596                 :          2 :                 m->te = te - pkt_len;
     597                 :          2 :                 return RTE_COLOR_YELLOW;
     598                 :            :         }
     599                 :            : 
     600                 :            :         /* If we end up here the color is RED */
     601                 :          1 :         m->tc = tc;
     602                 :          1 :         m->te = te;
     603                 :          1 :         return RTE_COLOR_RED;
     604                 :            : }
     605                 :            : 
     606                 :            : static inline enum rte_color
     607                 :         12 : rte_meter_trtcm_rfc4115_color_aware_check(
     608                 :            :         struct rte_meter_trtcm_rfc4115 *m,
     609                 :            :         struct rte_meter_trtcm_rfc4115_profile *p,
     610                 :            :         uint64_t time,
     611                 :            :         uint32_t pkt_len,
     612                 :            :         enum rte_color pkt_color)
     613                 :            : {
     614                 :            :         uint64_t time_diff_tc, time_diff_te, n_periods_tc, n_periods_te, tc, te;
     615                 :            : 
     616                 :            :         /* Bucket update */
     617                 :         12 :         time_diff_tc = time - m->time_tc;
     618                 :         12 :         time_diff_te = time - m->time_te;
     619                 :         12 :         n_periods_tc = time_diff_tc / p->cir_period;
     620                 :         12 :         n_periods_te = time_diff_te / p->eir_period;
     621                 :         12 :         m->time_tc += n_periods_tc * p->cir_period;
     622                 :         12 :         m->time_te += n_periods_te * p->eir_period;
     623                 :            : 
     624                 :         12 :         tc = m->tc + n_periods_tc * p->cir_bytes_per_period;
     625                 :         12 :         if (tc > p->cbs)
     626                 :            :                 tc = p->cbs;
     627                 :            : 
     628                 :         12 :         te = m->te + n_periods_te * p->eir_bytes_per_period;
     629                 :         12 :         if (te > p->ebs)
     630                 :            :                 te = p->ebs;
     631                 :            : 
     632                 :            :         /* Color logic */
     633   [ +  +  +  + ]:         12 :         if ((pkt_color == RTE_COLOR_GREEN) && (tc >= pkt_len)) {
     634                 :          1 :                 m->tc = tc - pkt_len;
     635                 :          1 :                 m->te = te;
     636                 :          1 :                 return RTE_COLOR_GREEN;
     637                 :            :         }
     638                 :            : 
     639   [ +  +  +  + ]:         11 :         if ((pkt_color != RTE_COLOR_RED) && (te >= pkt_len)) {
     640                 :          5 :                 m->tc = tc;
     641                 :          5 :                 m->te = te - pkt_len;
     642                 :          5 :                 return RTE_COLOR_YELLOW;
     643                 :            :         }
     644                 :            : 
     645                 :            :         /* If we end up here the color is RED */
     646                 :          6 :         m->tc = tc;
     647                 :          6 :         m->te = te;
     648                 :          6 :         return RTE_COLOR_RED;
     649                 :            : }
     650                 :            : 
     651                 :            : 
     652                 :            : #ifdef __cplusplus
     653                 :            : }
     654                 :            : #endif
     655                 :            : 
     656                 :            : #endif /* __INCLUDE_RTE_METER_H__ */

Generated by: LCOV version 1.14