aboutsummaryrefslogtreecommitdiffstats
path: root/vnet
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2016-05-13 05:44:48 -0700
committerDave Barach <openvpp@barachs.net>2016-05-16 13:30:40 +0000
commit65fcd4d7372718d353143c4deec65fe8b8e36577 (patch)
tree0358a6ac42188b39c14e567154e29bc967bbc95e /vnet
parent6b70c213ee0b53ab9cbd4a9a3768b2d64f63109d (diff)
Add configure policer API
JIRA: VPP-67 Change-Id: I04560d78e2eb131cd6cc31472b70b3d3e8fdd79a Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'vnet')
-rw-r--r--vnet/Makefile.am2
-rw-r--r--vnet/vnet/policer/policer.c95
-rw-r--r--vnet/vnet/policer/policer.h3
3 files changed, 57 insertions, 43 deletions
diff --git a/vnet/Makefile.am b/vnet/Makefile.am
index 8a9f214ca70..dddcdbfed63 100644
--- a/vnet/Makefile.am
+++ b/vnet/Makefile.am
@@ -58,6 +58,8 @@ libvnet_la_SOURCES += \
nobase_include_HEADERS += \
vnet/policer/police.h \
+ vnet/policer/policer.h \
+ vnet/policer/fix_types.h \
vnet/policer/xlate.h
########################################
diff --git a/vnet/vnet/policer/policer.c b/vnet/vnet/policer/policer.c
index 2dbd02b3d0a..9e98de17cc8 100644
--- a/vnet/vnet/policer/policer.c
+++ b/vnet/vnet/policer/policer.c
@@ -15,6 +15,56 @@
#include <stdint.h>
#include <vnet/policer/policer.h>
+clib_error_t *
+policer_add_del (vlib_main_t *vm,
+ u8 * name, sse2_qos_pol_cfg_params_st * cfg,
+ u8 is_add)
+{
+ vnet_policer_main_t *pm = &vnet_policer_main;
+ policer_read_response_type_st test_policer;
+ uword * p;
+ int rv;
+
+ if (is_add == 0)
+ {
+ p = hash_get_mem (pm->policer_config_by_name, name);
+ if (p == 0)
+ {
+ vec_free(name);
+ return clib_error_return (0, "No such policer configuration");
+ }
+ hash_unset_mem (pm->policer_config_by_name, name);
+ vec_free(name);
+ return 0;
+ }
+
+ /* Vet the configuration before adding it to the table */
+ rv = sse2_pol_logical_2_physical (cfg, &test_policer);
+
+ if (rv == 0)
+ {
+ policer_read_response_type_st *pp;
+ sse2_qos_pol_cfg_params_st *cp;
+
+ pool_get (pm->configs, cp);
+ pool_get (pm->policer_templates, pp);
+
+ ASSERT (cp - pm->configs == pp - pm->policer_templates);
+
+ clib_memcpy (cp, cfg, sizeof (*cp));
+ clib_memcpy (pp, &test_policer, sizeof (*pp));
+
+ hash_set_mem (pm->policer_config_by_name, name, cp - pm->configs);
+ }
+ else
+ {
+ vec_free (name);
+ return clib_error_return (0, "Config failed sanity check");
+ }
+
+ return 0;
+}
+
u8 * format_policer_instance (u8 * s, va_list * va)
{
policer_read_response_type_st * i
@@ -228,14 +278,10 @@ configure_policer_command_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
- vnet_policer_main_t *pm = &vnet_policer_main;
sse2_qos_pol_cfg_params_st c;
- policer_read_response_type_st test_policer;
unformat_input_t _line_input, * line_input = &_line_input;
- int is_add = 1;
- int rv;
+ u8 is_add = 1;
u8 * name = 0;
- uword * p;
/* Get a line of input. */
if (! unformat_user (input, unformat_line_input, line_input))
@@ -261,44 +307,7 @@ configure_policer_command_fn (vlib_main_t * vm,
unformat_free (line_input);
- if (is_add == 0)
- {
- p = hash_get_mem (pm->policer_config_by_name, name);
- if (p == 0)
- {
- vec_free(name);
- return clib_error_return (0, "No such policer configuration");
- }
- hash_unset_mem (pm->policer_config_by_name, name);
- vec_free(name);
- return 0;
- }
-
- /* Vet the configuration before adding it to the table */
- rv = sse2_pol_logical_2_physical (&c, &test_policer);
-
- if (rv == 0)
- {
- policer_read_response_type_st *pp;
- sse2_qos_pol_cfg_params_st *cp;
-
- pool_get (pm->configs, cp);
- pool_get (pm->policer_templates, pp);
-
- ASSERT (cp - pm->configs == pp - pm->policer_templates);
-
- clib_memcpy (cp, &c, sizeof (*cp));
- clib_memcpy (pp, &test_policer, sizeof (*pp));
-
- hash_set_mem (pm->policer_config_by_name, name, cp - pm->configs);
- }
- else
- {
- vec_free (name);
- return clib_error_return (0, "Config failed sanity check");
- }
-
- return 0;
+ return policer_add_del(vm, name, &c, is_add);
}
VLIB_CLI_COMMAND (configure_policer_command, static) = {
diff --git a/vnet/vnet/policer/policer.h b/vnet/vnet/policer/policer.h
index f91521e2268..02c2d228edd 100644
--- a/vnet/vnet/policer/policer.h
+++ b/vnet/vnet/policer/policer.h
@@ -56,5 +56,8 @@ enum {
} vnet_policer_next_t;
u8 * format_policer_instance (u8 * s, va_list * va);
+clib_error_t * policer_add_del (vlib_main_t *vm,
+ u8 * name, sse2_qos_pol_cfg_params_st * cfg,
+ u8 is_add);
#endif /* __included_policer_h__ */