blob: cd754e29be96d806393c1d76af91a7b18277acb6 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
Damjan Marione936bbe2016-02-25 23:17:38 +010015#include <stdint.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070016#include <vnet/policer/policer.h>
Matus Fabian70e6a8d2016-06-20 08:10:42 -070017#include <vnet/classify/vnet_classify.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070018
Matus Fabian65fcd4d2016-05-13 05:44:48 -070019clib_error_t *
Damjan Marion3891cd82016-10-27 10:27:00 +020020policer_add_del (vlib_main_t * vm,
21 u8 * name,
22 sse2_qos_pol_cfg_params_st * cfg,
23 u32 * policer_index, u8 is_add)
Matus Fabian65fcd4d2016-05-13 05:44:48 -070024{
25 vnet_policer_main_t *pm = &vnet_policer_main;
26 policer_read_response_type_st test_policer;
Damjan Marion3891cd82016-10-27 10:27:00 +020027 policer_read_response_type_st *policer;
28 uword *p;
Matus Fabian70e6a8d2016-06-20 08:10:42 -070029 u32 pi;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070030 int rv;
31
Matus Fabian70e6a8d2016-06-20 08:10:42 -070032 p = hash_get_mem (pm->policer_config_by_name, name);
33
Matus Fabian65fcd4d2016-05-13 05:44:48 -070034 if (is_add == 0)
35 {
Matus Fabian65fcd4d2016-05-13 05:44:48 -070036 if (p == 0)
Damjan Marion3891cd82016-10-27 10:27:00 +020037 {
38 vec_free (name);
39 return clib_error_return (0, "No such policer configuration");
40 }
Matus Fabian65fcd4d2016-05-13 05:44:48 -070041 hash_unset_mem (pm->policer_config_by_name, name);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070042 hash_unset_mem (pm->policer_index_by_name, name);
Damjan Marion3891cd82016-10-27 10:27:00 +020043 vec_free (name);
Matus Fabian65fcd4d2016-05-13 05:44:48 -070044 return 0;
45 }
46
Matus Fabian70e6a8d2016-06-20 08:10:42 -070047 if (p != 0)
48 {
Damjan Marion3891cd82016-10-27 10:27:00 +020049 vec_free (name);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070050 return clib_error_return (0, "Policer already exists");
51 }
52
Matus Fabian65fcd4d2016-05-13 05:44:48 -070053 /* Vet the configuration before adding it to the table */
54 rv = sse2_pol_logical_2_physical (cfg, &test_policer);
55
56 if (rv == 0)
57 {
58 policer_read_response_type_st *pp;
59 sse2_qos_pol_cfg_params_st *cp;
60
61 pool_get (pm->configs, cp);
62 pool_get (pm->policer_templates, pp);
63
64 ASSERT (cp - pm->configs == pp - pm->policer_templates);
65
66 clib_memcpy (cp, cfg, sizeof (*cp));
67 clib_memcpy (pp, &test_policer, sizeof (*pp));
68
69 hash_set_mem (pm->policer_config_by_name, name, cp - pm->configs);
Matus Fabian70e6a8d2016-06-20 08:10:42 -070070 pool_get_aligned (pm->policers, policer, CLIB_CACHE_LINE_BYTES);
71 policer[0] = pp[0];
72 pi = policer - pm->policers;
73 hash_set_mem (pm->policer_index_by_name, name, pi);
74 *policer_index = pi;
Matus Fabian65fcd4d2016-05-13 05:44:48 -070075 }
76 else
77 {
78 vec_free (name);
79 return clib_error_return (0, "Config failed sanity check");
80 }
81
82 return 0;
83}
84
Damjan Marion3891cd82016-10-27 10:27:00 +020085u8 *
86format_policer_instance (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -070087{
Damjan Marion3891cd82016-10-27 10:27:00 +020088 policer_read_response_type_st *i
Ed Warnickecb9cada2015-12-08 15:45:58 -070089 = va_arg (*va, policer_read_response_type_st *);
90
Damjan Marion3891cd82016-10-27 10:27:00 +020091 s = format (s, "policer at %llx: %s rate, %s color-aware\n",
92 i, i->single_rate ? "single" : "dual",
93 i->color_aware ? "is" : "not");
Ed Warnickecb9cada2015-12-08 15:45:58 -070094 s = format (s, "cir %u tok/period, pir %u tok/period, scale %u\n",
Damjan Marion3891cd82016-10-27 10:27:00 +020095 i->cir_tokens_per_period, i->pir_tokens_per_period, i->scale);
Ed Warnickecb9cada2015-12-08 15:45:58 -070096 s = format (s, "cur lim %u, cur bkt %u, ext lim %u, ext bkt %u\n",
Damjan Marion3891cd82016-10-27 10:27:00 +020097 i->current_limit,
98 i->current_bucket, i->extended_limit, i->extended_bucket);
Ed Warnickecb9cada2015-12-08 15:45:58 -070099 s = format (s, "last update %llu\n", i->last_update_time);
100 return s;
Damjan Marion3891cd82016-10-27 10:27:00 +0200101}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102
Damjan Marion3891cd82016-10-27 10:27:00 +0200103static u8 *
104format_policer_round_type (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700105{
Damjan Marion3891cd82016-10-27 10:27:00 +0200106 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700107
108 if (c->rnd_type == SSE2_QOS_ROUND_TO_CLOSEST)
Damjan Marion3891cd82016-10-27 10:27:00 +0200109 s = format (s, "closest");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110 else if (c->rnd_type == SSE2_QOS_ROUND_TO_UP)
111 s = format (s, "up");
112 else if (c->rnd_type == SSE2_QOS_ROUND_TO_DOWN)
113 s = format (s, "down");
114 else
115 s = format (s, "ILLEGAL");
116 return s;
117}
118
119
Damjan Marion3891cd82016-10-27 10:27:00 +0200120static u8 *
121format_policer_rate_type (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122{
Damjan Marion3891cd82016-10-27 10:27:00 +0200123 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124
125 if (c->rate_type == SSE2_QOS_RATE_KBPS)
126 s = format (s, "kbps");
127 else if (c->rate_type == SSE2_QOS_RATE_PPS)
Damjan Marion3891cd82016-10-27 10:27:00 +0200128 s = format (s, "pps");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700129 else
130 s = format (s, "ILLEGAL");
131 return s;
132}
133
Damjan Marion3891cd82016-10-27 10:27:00 +0200134static u8 *
135format_policer_type (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700136{
Damjan Marion3891cd82016-10-27 10:27:00 +0200137 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
138
Ed Warnickecb9cada2015-12-08 15:45:58 -0700139 if (c->rfc == SSE2_QOS_POLICER_TYPE_1R2C)
140 s = format (s, "1r2c");
Damjan Marion3891cd82016-10-27 10:27:00 +0200141
Ed Warnickecb9cada2015-12-08 15:45:58 -0700142 else if (c->rfc == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
143 s = format (s, "1r3c");
144
145 else if (c->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
146 s = format (s, "2r3c-2698");
147
148 else if (c->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
149 s = format (s, "2r3c-4115");
150
151 else if (c->rfc == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
152 s = format (s, "2r3c-mef5cf1");
153 else
154 s = format (s, "ILLEGAL");
155 return s;
156}
157
Damjan Marion3891cd82016-10-27 10:27:00 +0200158static u8 *
159format_dscp (u8 * s, va_list * va)
Matus Fabian4ac74c92016-05-31 07:33:29 -0700160{
161 u32 i = va_arg (*va, u32);
Damjan Marion3891cd82016-10-27 10:27:00 +0200162 char *t = 0;
Matus Fabian4ac74c92016-05-31 07:33:29 -0700163
Damjan Marion3891cd82016-10-27 10:27:00 +0200164 switch (i)
165 {
166#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
167 foreach_vnet_dscp
168#undef _
Matus Fabian4ac74c92016-05-31 07:33:29 -0700169 default:
170 return format (s, "ILLEGAL");
Damjan Marion3891cd82016-10-27 10:27:00 +0200171 }
Matus Fabian4ac74c92016-05-31 07:33:29 -0700172 s = format (s, "%s", t);
173 return s;
174}
175
Damjan Marion3891cd82016-10-27 10:27:00 +0200176static u8 *
177format_policer_action_type (u8 * s, va_list * va)
Matus Fabian4ac74c92016-05-31 07:33:29 -0700178{
Damjan Marion3891cd82016-10-27 10:27:00 +0200179 sse2_qos_pol_action_params_st *a
Matus Fabian4ac74c92016-05-31 07:33:29 -0700180 = va_arg (*va, sse2_qos_pol_action_params_st *);
181
182 if (a->action_type == SSE2_QOS_ACTION_DROP)
183 s = format (s, "drop");
184 else if (a->action_type == SSE2_QOS_ACTION_TRANSMIT)
185 s = format (s, "transmit");
186 else if (a->action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
187 s = format (s, "mark-and-transmit %U", format_dscp, a->dscp);
188 else
189 s = format (s, "ILLEGAL");
190 return s;
191}
192
Damjan Marion3891cd82016-10-27 10:27:00 +0200193u8 *
194format_policer_config (u8 * s, va_list * va)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700195{
Damjan Marion3891cd82016-10-27 10:27:00 +0200196 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197
198 s = format (s, "type %U cir %u eir %u cb %u eb %u\n",
Damjan Marion3891cd82016-10-27 10:27:00 +0200199 format_policer_type, c,
200 c->rb.kbps.cir_kbps,
201 c->rb.kbps.eir_kbps, c->rb.kbps.cb_bytes, c->rb.kbps.eb_bytes);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202 s = format (s, "rate type %U, round type %U\n",
Damjan Marion3891cd82016-10-27 10:27:00 +0200203 format_policer_rate_type, c, format_policer_round_type, c);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700204 s = format (s, "conform action %U, exceed action %U, violate action %U\n",
Damjan Marion3891cd82016-10-27 10:27:00 +0200205 format_policer_action_type, &c->conform_action,
206 format_policer_action_type, &c->exceed_action,
207 format_policer_action_type, &c->violate_action);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700208 return s;
209}
210
211static uword
212unformat_policer_type (unformat_input_t * input, va_list * va)
213{
Damjan Marion3891cd82016-10-27 10:27:00 +0200214 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700215
216 if (!unformat (input, "type"))
217 return 0;
218
219 if (unformat (input, "1r2c"))
220 c->rfc = SSE2_QOS_POLICER_TYPE_1R2C;
221 else if (unformat (input, "1r3c"))
222 c->rfc = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
223 else if (unformat (input, "2r3c-2698"))
224 c->rfc = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
225 else if (unformat (input, "2r3c-4115"))
226 c->rfc = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
227 else if (unformat (input, "2r3c-mef5cf1"))
228 c->rfc = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
229 else
230 return 0;
231 return 1;
232}
233
234static uword
235unformat_policer_round_type (unformat_input_t * input, va_list * va)
236{
Damjan Marion3891cd82016-10-27 10:27:00 +0200237 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700238
Damjan Marion3891cd82016-10-27 10:27:00 +0200239 if (!unformat (input, "round"))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700240 return 0;
241
Damjan Marion3891cd82016-10-27 10:27:00 +0200242 if (unformat (input, "closest"))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700243 c->rnd_type = SSE2_QOS_ROUND_TO_CLOSEST;
244 else if (unformat (input, "up"))
245 c->rnd_type = SSE2_QOS_ROUND_TO_UP;
246 else if (unformat (input, "down"))
247 c->rnd_type = SSE2_QOS_ROUND_TO_DOWN;
248 else
249 return 0;
250 return 1;
251}
252
253static uword
254unformat_policer_rate_type (unformat_input_t * input, va_list * va)
255{
Damjan Marion3891cd82016-10-27 10:27:00 +0200256 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700257
Damjan Marion3891cd82016-10-27 10:27:00 +0200258 if (!unformat (input, "rate"))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700259 return 0;
260
261 if (unformat (input, "kbps"))
262 c->rate_type = SSE2_QOS_RATE_KBPS;
Damjan Marion3891cd82016-10-27 10:27:00 +0200263 else if (unformat (input, "pps"))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700264 c->rate_type = SSE2_QOS_RATE_PPS;
265 else
266 return 0;
267 return 1;
268}
269
270static uword
271unformat_policer_cir (unformat_input_t * input, va_list * va)
272{
Damjan Marion3891cd82016-10-27 10:27:00 +0200273 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700274
275 if (unformat (input, "cir %u", &c->rb.kbps.cir_kbps))
276 return 1;
277 return 0;
278}
279
280static uword
281unformat_policer_eir (unformat_input_t * input, va_list * va)
282{
Damjan Marion3891cd82016-10-27 10:27:00 +0200283 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700284
285 if (unformat (input, "eir %u", &c->rb.kbps.eir_kbps))
286 return 1;
287 return 0;
288}
289
290static uword
291unformat_policer_cb (unformat_input_t * input, va_list * va)
292{
Damjan Marion3891cd82016-10-27 10:27:00 +0200293 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700294
295 if (unformat (input, "cb %u", &c->rb.kbps.cb_bytes))
296 return 1;
297 return 0;
298}
299
300static uword
301unformat_policer_eb (unformat_input_t * input, va_list * va)
302{
Damjan Marion3891cd82016-10-27 10:27:00 +0200303 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700304
305 if (unformat (input, "eb %u", &c->rb.kbps.eb_bytes))
306 return 1;
307 return 0;
308}
309
Matus Fabian4ac74c92016-05-31 07:33:29 -0700310static uword
311unformat_dscp (unformat_input_t * input, va_list * va)
312{
Damjan Marion3891cd82016-10-27 10:27:00 +0200313 u8 *r = va_arg (*va, u8 *);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700314
Damjan Marion3891cd82016-10-27 10:27:00 +0200315 if (0);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700316#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
Damjan Marion3891cd82016-10-27 10:27:00 +0200317 foreach_vnet_dscp
Matus Fabian4ac74c92016-05-31 07:33:29 -0700318#undef _
Damjan Marion3891cd82016-10-27 10:27:00 +0200319 else
Matus Fabian4ac74c92016-05-31 07:33:29 -0700320 return 0;
321 return 1;
322}
323
324static uword
325unformat_policer_action_type (unformat_input_t * input, va_list * va)
326{
Damjan Marion3891cd82016-10-27 10:27:00 +0200327 sse2_qos_pol_action_params_st *a
Matus Fabian4ac74c92016-05-31 07:33:29 -0700328 = va_arg (*va, sse2_qos_pol_action_params_st *);
329
330 if (unformat (input, "drop"))
331 a->action_type = SSE2_QOS_ACTION_DROP;
332 else if (unformat (input, "transmit"))
333 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
334 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
335 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
336 else
337 return 0;
338 return 1;
339}
340
341static uword
342unformat_policer_action (unformat_input_t * input, va_list * va)
343{
Damjan Marion3891cd82016-10-27 10:27:00 +0200344 sse2_qos_pol_cfg_params_st *c = va_arg (*va, sse2_qos_pol_cfg_params_st *);
Matus Fabian4ac74c92016-05-31 07:33:29 -0700345
346 if (unformat (input, "conform-action %U", unformat_policer_action_type,
Damjan Marion3891cd82016-10-27 10:27:00 +0200347 &c->conform_action))
Matus Fabian4ac74c92016-05-31 07:33:29 -0700348 return 1;
349 else if (unformat (input, "exceed-action %U", unformat_policer_action_type,
Damjan Marion3891cd82016-10-27 10:27:00 +0200350 &c->exceed_action))
Matus Fabian4ac74c92016-05-31 07:33:29 -0700351 return 1;
352 else if (unformat (input, "violate-action %U", unformat_policer_action_type,
Damjan Marion3891cd82016-10-27 10:27:00 +0200353 &c->violate_action))
Matus Fabian4ac74c92016-05-31 07:33:29 -0700354 return 1;
355 return 0;
356}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700357
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700358static uword
359unformat_policer_classify_next_index (unformat_input_t * input, va_list * va)
360{
Damjan Marion3891cd82016-10-27 10:27:00 +0200361 u32 *r = va_arg (*va, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700362 vnet_policer_main_t *pm = &vnet_policer_main;
Damjan Marion3891cd82016-10-27 10:27:00 +0200363 uword *p;
364 u8 *match_name = 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700365
366 if (unformat (input, "%s", &match_name))
367 ;
368 else
369 return 0;
370
371 p = hash_get_mem (pm->policer_index_by_name, match_name);
372
373 if (p == 0)
374 return 0;
375
376 *r = p[0];
377
378 return 1;
379}
380
381static uword
382unformat_policer_classify_precolor (unformat_input_t * input, va_list * va)
383{
Damjan Marion3891cd82016-10-27 10:27:00 +0200384 u32 *r = va_arg (*va, u32 *);
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700385
386 if (unformat (input, "conform-color"))
387 *r = POLICE_CONFORM;
388 else if (unformat (input, "exceed-color"))
389 *r = POLICE_EXCEED;
390 else
391 return 0;
392
393 return 1;
394}
395
Ed Warnickecb9cada2015-12-08 15:45:58 -0700396#define foreach_config_param \
397_(eb) \
398_(cb) \
399_(eir) \
400_(cir) \
401_(rate_type) \
402_(round_type) \
Matus Fabian4ac74c92016-05-31 07:33:29 -0700403_(type) \
404_(action)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700405
406static clib_error_t *
407configure_policer_command_fn (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200408 unformat_input_t * input,
409 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700411 sse2_qos_pol_cfg_params_st c;
Damjan Marion3891cd82016-10-27 10:27:00 +0200412 unformat_input_t _line_input, *line_input = &_line_input;
Matus Fabian65fcd4d2016-05-13 05:44:48 -0700413 u8 is_add = 1;
Damjan Marion3891cd82016-10-27 10:27:00 +0200414 u8 *name = 0;
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700415 u32 pi;
Billy McFalla9a20e72017-02-15 11:39:12 -0500416 clib_error_t *error = NULL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700417
418 /* Get a line of input. */
Damjan Marion3891cd82016-10-27 10:27:00 +0200419 if (!unformat_user (input, unformat_line_input, line_input))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700420 return 0;
421
422 memset (&c, 0, sizeof (c));
423
Damjan Marion3891cd82016-10-27 10:27:00 +0200424 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700425 {
426 if (unformat (line_input, "del"))
Damjan Marion3891cd82016-10-27 10:27:00 +0200427 is_add = 0;
428 else if (unformat (line_input, "name %s", &name))
429 ;
430 else if (unformat (line_input, "color-aware"))
431 c.color_aware = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700432
433#define _(a) else if (unformat (line_input, "%U", unformat_policer_##a, &c)) ;
434 foreach_config_param
435#undef _
Damjan Marion3891cd82016-10-27 10:27:00 +0200436 else
Billy McFalla9a20e72017-02-15 11:39:12 -0500437 {
438 error = clib_error_return (0, "unknown input `%U'",
439 format_unformat_error, line_input);
440 goto done;
441 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700442 }
443
Billy McFalla9a20e72017-02-15 11:39:12 -0500444 error = policer_add_del (vm, name, &c, &pi, is_add);
445
446done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700447 unformat_free (line_input);
448
Billy McFalla9a20e72017-02-15 11:39:12 -0500449 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700450}
451
Damjan Marion3891cd82016-10-27 10:27:00 +0200452/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700453VLIB_CLI_COMMAND (configure_policer_command, static) = {
454 .path = "configure policer",
455 .short_help = "configure policer name <name> <params> ",
456 .function = configure_policer_command_fn,
457};
Damjan Marion3891cd82016-10-27 10:27:00 +0200458/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700459
460static clib_error_t *
461show_policer_command_fn (vlib_main_t * vm,
Damjan Marion3891cd82016-10-27 10:27:00 +0200462 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700463{
464 vnet_policer_main_t *pm = &vnet_policer_main;
Damjan Marion3891cd82016-10-27 10:27:00 +0200465 hash_pair_t *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700466 u32 pool_index;
Damjan Marion3891cd82016-10-27 10:27:00 +0200467 u8 *match_name = 0;
468 u8 *name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700469 sse2_qos_pol_cfg_params_st *config;
470 policer_read_response_type_st *templ;
471
472 (void) unformat (input, "name %s", &match_name);
473
Damjan Marion3891cd82016-10-27 10:27:00 +0200474 /* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700475 hash_foreach_pair (p, pm->policer_config_by_name,
476 ({
477 name = (u8 *) p->key;
478 if (match_name == 0 || !strcmp((char *) name, (char *) match_name))
479 {
480 pool_index = p->value[0];
481 config = pool_elt_at_index (pm->configs, pool_index);
482 templ = pool_elt_at_index (pm->policer_templates, pool_index);
Damjan Marion3891cd82016-10-27 10:27:00 +0200483 vlib_cli_output (vm, "Name \"%s\" %U ",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700484 name, format_policer_config, config);
Damjan Marion3891cd82016-10-27 10:27:00 +0200485 vlib_cli_output (vm, "Template %U",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700486 format_policer_instance, templ);
487 vlib_cli_output (vm, "-----------");
488 }
489 }));
Damjan Marion3891cd82016-10-27 10:27:00 +0200490 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700491 return 0;
492}
493
494
Damjan Marion3891cd82016-10-27 10:27:00 +0200495/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700496VLIB_CLI_COMMAND (show_policer_command, static) = {
497 .path = "show policer",
498 .short_help = "show policer [name]",
499 .function = show_policer_command_fn,
500};
Damjan Marion3891cd82016-10-27 10:27:00 +0200501/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700502
Damjan Marion3891cd82016-10-27 10:27:00 +0200503clib_error_t *
504policer_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700505{
Damjan Marion3891cd82016-10-27 10:27:00 +0200506 vnet_policer_main_t *pm = &vnet_policer_main;
507 void vnet_policer_node_funcs_reference (void);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700508
Damjan Marion3891cd82016-10-27 10:27:00 +0200509 vnet_policer_node_funcs_reference ();
510
Ed Warnickecb9cada2015-12-08 15:45:58 -0700511 pm->vlib_main = vm;
Damjan Marion3891cd82016-10-27 10:27:00 +0200512 pm->vnet_main = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700513
514 pm->policer_config_by_name = hash_create_string (0, sizeof (uword));
Matus Fabian70e6a8d2016-06-20 08:10:42 -0700515 pm->policer_index_by_name = hash_create_string (0, sizeof (uword));
516
517 vnet_classify_register_unformat_policer_next_index_fn
518 (unformat_policer_classify_next_index);
519 vnet_classify_register_unformat_opaque_index_fn
520 (unformat_policer_classify_precolor);
521
Ed Warnickecb9cada2015-12-08 15:45:58 -0700522 return 0;
523}
524
Damjan Marion3891cd82016-10-27 10:27:00 +0200525VLIB_INIT_FUNCTION (policer_init);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700526
527
Damjan Marion3891cd82016-10-27 10:27:00 +0200528
529/*
530 * fd.io coding-style-patch-verification: ON
531 *
532 * Local Variables:
533 * eval: (c-set-style "gnu")
534 * End:
535 */