policer: use enum types 20/31220/8
authorBrian Russell <brian@graphiant.com>
Tue, 9 Feb 2021 11:36:31 +0000 (11:36 +0000)
committerNeale Ranns <neale@graphiant.com>
Fri, 12 Feb 2021 18:57:55 +0000 (18:57 +0000)
Make the policer action enum packed and use it in the policer code.
Use other policer enums where applicable.

Type: improvement
Signed-off-by: Brian Russell <brian@graphiant.com>
Change-Id: I32f9735942af8bca3160b9ef8a75f605d9aba5fa

src/vat/api_format.c
src/vnet/policer/police.h
src/vnet/policer/police_inlines.h
src/vnet/policer/policer_api.c
src/vnet/policer/xlate.c
src/vnet/policer/xlate.h

index b16f664..a59544a 100644 (file)
@@ -11652,11 +11652,14 @@ api_policer_add_del (vat_main_t * vam)
   mp->rate_type = rate_type;
   mp->round_type = round_type;
   mp->type = type;
-  mp->conform_action.type = conform_action.action_type;
+  mp->conform_action.type =
+    (vl_api_sse2_qos_action_type_t) conform_action.action_type;
   mp->conform_action.dscp = conform_action.dscp;
-  mp->exceed_action.type = exceed_action.action_type;
+  mp->exceed_action.type =
+    (vl_api_sse2_qos_action_type_t) exceed_action.action_type;
   mp->exceed_action.dscp = exceed_action.dscp;
-  mp->violate_action.type = violate_action.action_type;
+  mp->violate_action.type =
+    (vl_api_sse2_qos_action_type_t) violate_action.action_type;
   mp->violate_action.dscp = violate_action.dscp;
   mp->color_aware = color_aware;
 
index 6027845..7867a2e 100644 (file)
@@ -24,6 +24,13 @@ typedef enum
 
 #define NUM_POLICE_RESULTS 3
 
+typedef enum
+{
+  QOS_ACTION_DROP = 0,
+  QOS_ACTION_TRANSMIT,
+  QOS_ACTION_MARK_AND_TRANSMIT
+} __clib_packed qos_action_type_en;
+
 // This is the hardware representation of the policer.
 // To be multithread-safe, the policer is accessed through a spin-lock
 // on the lock field. (For a policer update operation, 24B needs to be
@@ -70,7 +77,7 @@ typedef struct
   u32 single_rate;             // 1 = single rate policer, 0 = two rate policer
   u32 color_aware;             // for hierarchical policing
   u32 scale;                   // power-of-2 shift amount for lower rates
-  u8 action[3];
+  qos_action_type_en action[3];
   ip_dscp_t mark_dscp[3];
   u8 pad[2];
 
index f0b871a..f9378c7 100644 (file)
@@ -62,7 +62,7 @@ vnet_policer_police (vlib_main_t * vm,
                     u64 time_in_policer_periods,
                     policer_result_e packet_color)
 {
-  u8 act;
+  qos_action_type_en act;
   u32 len;
   u32 col;
   policer_read_response_type_st *pol;
index 855ebad..fb66667 100644 (file)
@@ -61,9 +61,9 @@ vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
   vec_terminate_c_string (name);
 
   clib_memset (&cfg, 0, sizeof (cfg));
-  cfg.rfc = mp->type;
-  cfg.rnd_type = mp->round_type;
-  cfg.rate_type = mp->rate_type;
+  cfg.rfc = (qos_policer_type_en) mp->type;
+  cfg.rnd_type = (qos_round_type_en) mp->round_type;
+  cfg.rate_type = (qos_rate_type_en) mp->rate_type;
   cfg.rb.kbps.cir_kbps = ntohl (mp->cir);
   cfg.rb.kbps.eir_kbps = ntohl (mp->eir);
   cfg.rb.kbps.cb_bytes = clib_net_to_host_u64 (mp->cb);
@@ -110,9 +110,9 @@ send_policer_details (u8 *name, qos_pol_cfg_params_st *config,
   mp->eir = htonl (config->rb.kbps.eir_kbps);
   mp->cb = clib_host_to_net_u64 (config->rb.kbps.cb_bytes);
   mp->eb = clib_host_to_net_u64 (config->rb.kbps.eb_bytes);
-  mp->rate_type = config->rate_type;
-  mp->round_type = config->rnd_type;
-  mp->type = config->rfc;
+  mp->rate_type = (vl_api_sse2_qos_rate_type_t) config->rate_type;
+  mp->round_type = (vl_api_sse2_qos_round_type_t) config->rnd_type;
+  mp->type = (vl_api_sse2_qos_policer_type_t) config->rfc;
   mp->conform_action.type =
     (vl_api_sse2_qos_action_type_t) config->conform_action.action_type;
   mp->conform_action.dscp = config->conform_action.dscp;
index 2ef9922..1b6015d 100644 (file)
@@ -256,8 +256,7 @@ pol_validate_cfg_params (qos_pol_cfg_params_st *cfg)
    */
   numer = (u64) (cfg->rb.kbps.cir_kbps);
   denom = (u64) (8 * QOS_POL_TICKS_PER_SEC) / 1000;
-  rc = qos_pol_round (numer, denom, &rnd_value,
-                     (qos_round_type_en) cfg->rnd_type);
+  rc = qos_pol_round (numer, denom, &rnd_value, cfg->rnd_type);
   if (rc != 0)
     {
       QOS_DEBUG_ERROR ("Unable to convert CIR to bytes/tick format");
@@ -267,8 +266,7 @@ pol_validate_cfg_params (qos_pol_cfg_params_st *cfg)
   cir_hw = (u32) rnd_value;
 
   numer = (u64) (cfg->rb.kbps.eir_kbps);
-  rc = qos_pol_round (numer, denom, &rnd_value,
-                     (qos_round_type_en) cfg->rnd_type);
+  rc = qos_pol_round (numer, denom, &rnd_value, cfg->rnd_type);
   if (rc != 0)
     {
       QOS_DEBUG_ERROR ("Unable to convert EIR to bytes/tick format");
@@ -390,8 +388,7 @@ pol_convert_cfg_rates_to_hw (qos_pol_cfg_params_st *cfg,
    */
   denom = (u64) ((QOS_POL_TICKS_PER_SEC * 8) / 1000);
   numer = (u64) (cfg->rb.kbps.cir_kbps);
-  rc = qos_pol_round (numer, denom, &rnd_value,
-                     (qos_round_type_en) cfg->rnd_type);
+  rc = qos_pol_round (numer, denom, &rnd_value, cfg->rnd_type);
   if (rc != 0)
     {
       QOS_DEBUG_ERROR ("Rounding error, rate: %d kbps, rounding_type: %d",
@@ -427,8 +424,7 @@ pol_convert_cfg_rates_to_hw (qos_pol_cfg_params_st *cfg,
     }
 
   numer = (u64) eir_kbps;
-  rc = qos_pol_round (numer, denom, &rnd_value,
-                     (qos_round_type_en) cfg->rnd_type);
+  rc = qos_pol_round (numer, denom, &rnd_value, cfg->rnd_type);
   if (rc != 0)
     {
       QOS_DEBUG_ERROR ("Rounding error, rate: %d kbps, rounding_type: %d",
@@ -471,24 +467,22 @@ pol_convert_cfg_rates_to_hw (qos_pol_cfg_params_st *cfg,
     }
   else
     {
-      qos_convert_value_to_exp_mant_fmt (
-       hi_rate, (u16) QOS_POL_RATE_EXP_MAX, (u16) QOS_POL_AVG_RATE_MANT_MAX,
-       (qos_round_type_en) cfg->rnd_type, &exp, &hi_mant);
+      qos_convert_value_to_exp_mant_fmt (hi_rate, (u16) QOS_POL_RATE_EXP_MAX,
+                                        (u16) QOS_POL_AVG_RATE_MANT_MAX,
+                                        cfg->rnd_type, &exp, &hi_mant);
     }
 
   denom = (1ULL << exp);
   if (hi_rate == eir_hw)
     {
       hw->peak_rate_man = (u16) hi_mant;
-      rc = qos_pol_round ((u64) cir_hw, denom, &rnd_value,
-                         (qos_round_type_en) cfg->rnd_type);
+      rc = qos_pol_round ((u64) cir_hw, denom, &rnd_value, cfg->rnd_type);
       hw->avg_rate_man = (u16) rnd_value;
     }
   else
     {
       hw->avg_rate_man = (u16) hi_mant;
-      rc = qos_pol_round ((u64) eir_hw, denom, &rnd_value,
-                         (qos_round_type_en) cfg->rnd_type);
+      rc = qos_pol_round ((u64) eir_hw, denom, &rnd_value, cfg->rnd_type);
       hw->peak_rate_man = (u16) rnd_value;
     }
   if (rc != 0)
index 101c070..46e58bd 100644 (file)
@@ -35,7 +35,7 @@ typedef enum qos_policer_type_en_
   QOS_POLICER_TYPE_2R3C_RFC_4115 = 3,
   QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1 = 4,
   QOS_POLICER_TYPE_MAX
-} qos_policer_type_en;
+} __clib_packed qos_policer_type_en;
 
 /*
  * edt: * enum
@@ -47,7 +47,7 @@ typedef enum
   QOS_ROUND_TO_UP,
   QOS_ROUND_TO_DOWN,
   QOS_ROUND_INVALID
-} qos_round_type_en;
+} __clib_packed qos_round_type_en;
 
 /*
  * edt: * enum
@@ -64,18 +64,7 @@ typedef enum
   QOS_RATE_KBPS = 0,
   QOS_RATE_PPS,
   QOS_RATE_INVALID
-} qos_rate_type_en;
-
-/*
- * edt: * enum
- * Defines type of policer actions.
- */
-typedef enum
-{
-  QOS_ACTION_DROP = 0,
-  QOS_ACTION_TRANSMIT,
-  QOS_ACTION_MARK_AND_TRANSMIT
-} qos_action_type_en;
+} __clib_packed qos_rate_type_en;
 
 /*
  * edt * struct qos_pol_action_params_st
@@ -88,7 +77,7 @@ typedef enum
  */
 typedef struct qos_pol_action_params_st_
 {
-  u8 action_type;
+  qos_action_type_en action_type;
   ip_dscp_t dscp;
 } qos_pol_action_params_st;
 
@@ -142,9 +131,9 @@ typedef struct qos_pol_cfg_params_st_
       u64 eb_ms;
     } pps;
   } rb;                                /* rate burst config */
-  u8 rate_type;                        /* qos_rate_type_en */
-  u8 rnd_type;                 /* qos_round_type_en */
-  u8 rfc;                      /* qos_policer_type_en */
+  qos_rate_type_en rate_type;
+  qos_round_type_en rnd_type;
+  qos_policer_type_en rfc;
   u8 color_aware;
   u8 overwrite_bucket;         /* for debugging purposes */
   u32 current_bucket;          /* for debugging purposes */