policer: use ip dscp 18/31218/2
authorBrian Russell <brian@graphiant.com>
Mon, 8 Feb 2021 15:33:18 +0000 (15:33 +0000)
committerNeale Ranns <neale@graphiant.com>
Thu, 11 Feb 2021 08:21:56 +0000 (08:21 +0000)
Use the common IP definitions of DSCP rather than duplicating in the
policer code.

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

src/vat/api_format.c
src/vnet/policer/police.h
src/vnet/policer/police_inlines.h
src/vnet/policer/policer.c
src/vnet/policer/policer.h
src/vnet/policer/xlate.h
src/vpp/api/custom_dump.c

index cf9c774..649737b 100644 (file)
@@ -530,11 +530,10 @@ unformat_dscp (unformat_input_t * input, va_list * va)
   u8 *r = va_arg (*va, u8 *);
 
   if (0);
-#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
-  foreach_vnet_dscp
+#define _(v, f) else if (unformat (input, #f)) *r = IP_DSCP_##f;
+  foreach_ip_dscp
 #undef _
-    else
-    return 0;
+    else return 0;
   return 1;
 }
 
@@ -2751,14 +2750,14 @@ format_dscp (u8 * s, va_list * va)
 
   switch (i)
     {
-#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
-      foreach_vnet_dscp
+#define _(v, f)                                                               \
+  case IP_DSCP_##f:                                                           \
+    return (format (s, "%s", #f));
+      foreach_ip_dscp
 #undef _
-    default:
-      return format (s, "ILLEGAL");
     }
   s = format (s, "%s", t);
-  return s;
+  return (format (s, "ILLEGAL"));
 }
 
 static void
index d135e43..6027845 100644 (file)
@@ -71,7 +71,7 @@ typedef struct
   u32 color_aware;             // for hierarchical policing
   u32 scale;                   // power-of-2 shift amount for lower rates
   u8 action[3];
-  u8 mark_dscp[3];
+  ip_dscp_t mark_dscp[3];
   u8 pad[2];
 
   // Fields are marked as 2R if they are only used for a 2-rate policer,
index 0ed9730..c3bd324 100644 (file)
@@ -25,7 +25,7 @@
 #define IP6_DSCP_SHIFT    22
 
 static_always_inline void
-vnet_policer_mark (vlib_buffer_t * b, u8 dscp)
+vnet_policer_mark (vlib_buffer_t *b, ip_dscp_t dscp)
 {
   ethernet_header_t *eh;
   ip4_header_t *ip4h;
index fbb3055..99c3ff1 100644 (file)
@@ -16,6 +16,7 @@
 #include <vnet/policer/policer.h>
 #include <vnet/policer/police_inlines.h>
 #include <vnet/classify/vnet_classify.h>
+#include <vnet/ip/ip_packet.h>
 
 vnet_policer_main_t vnet_policer_main;
 
@@ -222,24 +223,6 @@ format_policer_type (u8 * s, va_list * va)
   return s;
 }
 
-static u8 *
-format_dscp (u8 * s, va_list * va)
-{
-  u32 i = va_arg (*va, u32);
-  char *t = 0;
-
-  switch (i)
-    {
-#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
-      foreach_vnet_dscp
-#undef _
-    default:
-      return format (s, "ILLEGAL");
-    }
-  s = format (s, "%s", t);
-  return s;
-}
-
 static u8 *
 format_policer_action_type (u8 * s, va_list * va)
 {
@@ -251,7 +234,7 @@ format_policer_action_type (u8 * s, va_list * va)
   else if (a->action_type == SSE2_QOS_ACTION_TRANSMIT)
     s = format (s, "transmit");
   else if (a->action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
-    s = format (s, "mark-and-transmit %U", format_dscp, a->dscp);
+    s = format (s, "mark-and-transmit %U", format_ip_dscp, a->dscp);
   else
     s = format (s, "ILLEGAL");
   return s;
@@ -374,20 +357,6 @@ unformat_policer_eb (unformat_input_t * input, va_list * va)
   return 0;
 }
 
-static uword
-unformat_dscp (unformat_input_t * input, va_list * va)
-{
-  u8 *r = va_arg (*va, u8 *);
-
-  if (0);
-#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
-  foreach_vnet_dscp
-#undef _
-    else
-    return 0;
-  return 1;
-}
-
 static uword
 unformat_policer_action_type (unformat_input_t * input, va_list * va)
 {
@@ -398,7 +367,8 @@ unformat_policer_action_type (unformat_input_t * input, va_list * va)
     a->action_type = SSE2_QOS_ACTION_DROP;
   else if (unformat (input, "transmit"))
     a->action_type = SSE2_QOS_ACTION_TRANSMIT;
-  else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
+  else if (unformat (input, "mark-and-transmit %U", unformat_ip_dscp,
+                    &a->dscp))
     a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
   else
     return 0;
index 2e57e46..5253bb6 100644 (file)
@@ -62,36 +62,6 @@ typedef enum
   VNET_POLICER_N_NEXT,
 } vnet_policer_next_t;
 
-#define foreach_vnet_dscp \
-  _(0 , CS0,  "CS0")  \
-  _(8 , CS1,  "CS1")  \
-  _(10, AF11, "AF11") \
-  _(12, AF12, "AF12") \
-  _(14, AF13, "AF13") \
-  _(16, CS2,  "CS2")  \
-  _(18, AF21, "AF21") \
-  _(20, AF22, "AF22") \
-  _(22, AF23, "AF23") \
-  _(24, CS3,  "CS3")  \
-  _(26, AF31, "AF31") \
-  _(28, AF32, "AF32") \
-  _(30, AF33, "AF33") \
-  _(32, CS4,  "CS4")  \
-  _(34, AF41, "AF41") \
-  _(36, AF42, "AF42") \
-  _(38, AF43, "AF43") \
-  _(40, CS5,  "CS5")  \
-  _(46, EF,   "EF")   \
-  _(48, CS6,  "CS6")  \
-  _(50, CS7,  "CS7")
-
-typedef enum
-{
-#define _(v,f,str) VNET_DSCP_##f = v,
-  foreach_vnet_dscp
-#undef _
-} vnet_dscp_t;
-
 u8 *format_policer_instance (u8 * s, va_list * va);
 clib_error_t *policer_add_del (vlib_main_t * vm,
                               u8 * name,
index d03930b..5350065 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef __included_xlate_h__
 #define __included_xlate_h__
 
+#include <vnet/ip/ip_packet.h>
 #include <vnet/policer/police.h>
 
 /*
@@ -88,7 +89,7 @@ typedef enum
 typedef struct sse2_qos_pol_action_params_st_
 {
   u8 action_type;
-  u8 dscp;
+  ip_dscp_t dscp;
 } sse2_qos_pol_action_params_st;
 
 /*
index cd81a72..8bf2774 100644 (file)
@@ -2029,7 +2029,6 @@ format_policer_action (u8 * s, va_list * va)
 {
   u32 action = va_arg (*va, u32);
   u32 dscp = va_arg (*va, u32);
-  char *t = 0;
 
   if (action == SSE2_QOS_ACTION_DROP)
     s = format (s, "drop");
@@ -2040,13 +2039,12 @@ format_policer_action (u8 * s, va_list * va)
       s = format (s, "mark-and-transmit ");
       switch (dscp)
        {
-#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
-         foreach_vnet_dscp
+#define _(v, f)                                                               \
+  case IP_DSCP_##f:                                                           \
+    format (s, "%s", #f);
+         foreach_ip_dscp
 #undef _
-       default:
-         break;
        }
-      s = format (s, "%s", t);
     }
   return s;
 }