aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Russell <brian@graphiant.com>2021-02-08 15:33:18 +0000
committerNeale Ranns <neale@graphiant.com>2021-02-11 08:21:56 +0000
commite3845d79bfa819355ac5085d73f3b8f2ffae2042 (patch)
treeef78beac6d512cbabb43546e41664b3cda1d05a1
parent1bb74944a385ea1b8f50b975359cb1c7ca94afb4 (diff)
policer: use ip dscp
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
-rw-r--r--src/vat/api_format.c17
-rw-r--r--src/vnet/policer/police.h2
-rw-r--r--src/vnet/policer/police_inlines.h2
-rw-r--r--src/vnet/policer/policer.c38
-rw-r--r--src/vnet/policer/policer.h30
-rw-r--r--src/vnet/policer/xlate.h3
-rw-r--r--src/vpp/api/custom_dump.c10
7 files changed, 20 insertions, 82 deletions
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index cf9c7742d46..649737bc64f 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -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
diff --git a/src/vnet/policer/police.h b/src/vnet/policer/police.h
index d135e43ef3e..602784504b2 100644
--- a/src/vnet/policer/police.h
+++ b/src/vnet/policer/police.h
@@ -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,
diff --git a/src/vnet/policer/police_inlines.h b/src/vnet/policer/police_inlines.h
index 0ed973079a6..c3bd324d85b 100644
--- a/src/vnet/policer/police_inlines.h
+++ b/src/vnet/policer/police_inlines.h
@@ -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;
diff --git a/src/vnet/policer/policer.c b/src/vnet/policer/policer.c
index fbb30551402..99c3ff1b4ba 100644
--- a/src/vnet/policer/policer.c
+++ b/src/vnet/policer/policer.c
@@ -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;
@@ -223,24 +224,6 @@ format_policer_type (u8 * s, va_list * va)
}
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)
{
sse2_qos_pol_action_params_st *a
@@ -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;
@@ -375,20 +358,6 @@ unformat_policer_eb (unformat_input_t * input, va_list * va)
}
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)
{
sse2_qos_pol_action_params_st *a
@@ -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;
diff --git a/src/vnet/policer/policer.h b/src/vnet/policer/policer.h
index 2e57e4654bd..5253bb6c432 100644
--- a/src/vnet/policer/policer.h
+++ b/src/vnet/policer/policer.h
@@ -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,
diff --git a/src/vnet/policer/xlate.h b/src/vnet/policer/xlate.h
index d03930b8813..535006569f5 100644
--- a/src/vnet/policer/xlate.h
+++ b/src/vnet/policer/xlate.h
@@ -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;
/*
diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c
index cd81a722b99..8bf2774c211 100644
--- a/src/vpp/api/custom_dump.c
+++ b/src/vpp/api/custom_dump.c
@@ -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;
}