summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vnet/policer/policer.api18
-rw-r--r--src/vnet/policer/policer.c32
-rw-r--r--src/vnet/policer/policer.h1
-rw-r--r--src/vnet/policer/policer_api.c25
4 files changed, 76 insertions, 0 deletions
diff --git a/src/vnet/policer/policer.api b/src/vnet/policer/policer.api
index c3b8d7cd061..a664ab0be76 100644
--- a/src/vnet/policer/policer.api
+++ b/src/vnet/policer/policer.api
@@ -15,6 +15,7 @@
option version = "2.0.0";
+import "vnet/interface_types.api";
import "vnet/policer/policer_types.api";
/** \brief policer bind: Associate/disassociate a policer with a worker thread.
@@ -34,6 +35,23 @@ autoreply define policer_bind
bool bind_enable;
};
+/** \brief policer input: Apply policer as an input feature.
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param name - policer name
+ @param sw_if_index - interface to apply the policer
+ @param apply - Apply/remove
+*/
+autoreply define policer_input
+{
+ u32 client_index;
+ u32 context;
+
+ string name[64];
+ vl_api_interface_index_t sw_if_index;
+ bool apply;
+};
+
/** \brief Add/del policer
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
diff --git a/src/vnet/policer/policer.c b/src/vnet/policer/policer.c
index fb2ce7598fa..678e5884cdd 100644
--- a/src/vnet/policer/policer.c
+++ b/src/vnet/policer/policer.c
@@ -165,6 +165,38 @@ policer_bind_worker (u8 *name, u32 worker, bool bind)
return 0;
}
+int
+policer_input (u8 *name, u32 sw_if_index, bool apply)
+{
+ vnet_policer_main_t *pm = &vnet_policer_main;
+ policer_t *policer;
+ u32 policer_index;
+ uword *p;
+
+ p = hash_get_mem (pm->policer_index_by_name, name);
+ if (p == 0)
+ {
+ return VNET_API_ERROR_NO_SUCH_ENTRY;
+ }
+
+ policer = &pm->policers[p[0]];
+ policer_index = policer - pm->policers;
+
+ if (apply)
+ {
+ vec_validate (pm->policer_index_by_sw_if_index, sw_if_index);
+ pm->policer_index_by_sw_if_index[sw_if_index] = policer_index;
+ }
+ else
+ {
+ pm->policer_index_by_sw_if_index[sw_if_index] = ~0;
+ }
+
+ vnet_feature_enable_disable ("device-input", "policer-input", sw_if_index,
+ apply, 0, 0);
+ return 0;
+}
+
u8 *
format_policer_instance (u8 * s, va_list * va)
{
diff --git a/src/vnet/policer/policer.h b/src/vnet/policer/policer.h
index 9a6de1490a5..9f090b1bb74 100644
--- a/src/vnet/policer/policer.h
+++ b/src/vnet/policer/policer.h
@@ -63,6 +63,7 @@ clib_error_t *policer_add_del (vlib_main_t *vm, u8 *name,
qos_pol_cfg_params_st *cfg, u32 *policer_index,
u8 is_add);
int policer_bind_worker (u8 *name, u32 worker, bool bind);
+int policer_input (u8 *name, u32 sw_if_index, bool apply);
#endif /* __included_policer_h__ */
diff --git a/src/vnet/policer/policer_api.c b/src/vnet/policer/policer_api.c
index eff02fbeee7..c3a9800e201 100644
--- a/src/vnet/policer/policer_api.c
+++ b/src/vnet/policer/policer_api.c
@@ -45,6 +45,7 @@
#define foreach_vpe_api_msg \
_ (POLICER_ADD_DEL, policer_add_del) \
_ (POLICER_BIND, policer_bind) \
+ _ (POLICER_INPUT, policer_input) \
_ (POLICER_DUMP, policer_dump)
static void
@@ -117,6 +118,30 @@ vl_api_policer_bind_t_handler (vl_api_policer_bind_t *mp)
}
static void
+vl_api_policer_input_t_handler (vl_api_policer_input_t *mp)
+{
+ vl_api_policer_bind_reply_t *rmp;
+ u8 *name;
+ u32 sw_if_index;
+ u8 apply;
+ int rv;
+
+ VALIDATE_SW_IF_INDEX (mp);
+
+ name = format (0, "%s", mp->name);
+ vec_terminate_c_string (name);
+
+ sw_if_index = ntohl (mp->sw_if_index);
+ apply = mp->apply;
+
+ rv = policer_input (name, sw_if_index, apply);
+ vec_free (name);
+
+ BAD_SW_IF_INDEX_LABEL;
+ REPLY_MACRO (VL_API_POLICER_INPUT_REPLY);
+}
+
+static void
send_policer_details (u8 *name, qos_pol_cfg_params_st *config,
policer_t *templ, vl_api_registration_t *reg,
u32 context)