Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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 Marion | e936bbe | 2016-02-25 23:17:38 +0100 | [diff] [blame] | 15 | #include <stdint.h> |
Brian Russell | 48e2636 | 2021-02-10 13:53:42 +0000 | [diff] [blame] | 16 | #include <stdbool.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 17 | #include <vnet/policer/policer.h> |
Brian Russell | 97de8a2 | 2021-01-19 16:50:56 +0000 | [diff] [blame] | 18 | #include <vnet/policer/police_inlines.h> |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 19 | #include <vnet/classify/vnet_classify.h> |
Brian Russell | e3845d7 | 2021-02-08 15:33:18 +0000 | [diff] [blame] | 20 | #include <vnet/ip/ip_packet.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 21 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 22 | vnet_policer_main_t vnet_policer_main; |
| 23 | |
Brian Russell | 97de8a2 | 2021-01-19 16:50:56 +0000 | [diff] [blame] | 24 | u8 * |
| 25 | format_policer_handoff_trace (u8 *s, va_list *args) |
| 26 | { |
| 27 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 28 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 29 | policer_handoff_trace_t *t = va_arg (*args, policer_handoff_trace_t *); |
| 30 | |
| 31 | s = format (s, "policer %d, handoff thread %d to %d", t->policer_index, |
| 32 | t->current_worker_index, t->next_worker_index); |
| 33 | |
| 34 | return s; |
| 35 | } |
| 36 | |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 37 | vlib_combined_counter_main_t policer_counters[] = { |
| 38 | { |
| 39 | .name = "Policer-Conform", |
| 40 | .stat_segment_name = "/net/policer/conform", |
| 41 | }, |
| 42 | { |
| 43 | .name = "Policer-Exceed", |
| 44 | .stat_segment_name = "/net/policer/exceed", |
| 45 | }, |
| 46 | { |
| 47 | .name = "Policer-Violate", |
| 48 | .stat_segment_name = "/net/policer/violate", |
| 49 | }, |
| 50 | }; |
| 51 | |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 52 | clib_error_t * |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 53 | policer_add_del (vlib_main_t *vm, u8 *name, qos_pol_cfg_params_st *cfg, |
| 54 | u32 *policer_index, u8 is_add) |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 55 | { |
| 56 | vnet_policer_main_t *pm = &vnet_policer_main; |
Brian Russell | 54be0cc | 2021-02-15 11:49:42 +0000 | [diff] [blame] | 57 | policer_t test_policer; |
| 58 | policer_t *policer; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 59 | uword *p; |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 60 | u32 pi; |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 61 | int rv; |
| 62 | |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 63 | p = hash_get_mem (pm->policer_config_by_name, name); |
| 64 | |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 65 | if (is_add == 0) |
| 66 | { |
Chaoyu Jin | 913b873 | 2017-08-08 13:36:23 -0700 | [diff] [blame] | 67 | /* free policer config and template */ |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 68 | if (p == 0) |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 69 | { |
| 70 | vec_free (name); |
| 71 | return clib_error_return (0, "No such policer configuration"); |
| 72 | } |
Chaoyu Jin | 913b873 | 2017-08-08 13:36:23 -0700 | [diff] [blame] | 73 | pool_put_index (pm->configs, p[0]); |
| 74 | pool_put_index (pm->policer_templates, p[0]); |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 75 | hash_unset_mem (pm->policer_config_by_name, name); |
Chaoyu Jin | 913b873 | 2017-08-08 13:36:23 -0700 | [diff] [blame] | 76 | |
| 77 | /* free policer */ |
| 78 | p = hash_get_mem (pm->policer_index_by_name, name); |
| 79 | if (p == 0) |
| 80 | { |
| 81 | vec_free (name); |
| 82 | return clib_error_return (0, "No such policer"); |
| 83 | } |
| 84 | pool_put_index (pm->policers, p[0]); |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 85 | hash_unset_mem (pm->policer_index_by_name, name); |
Chaoyu Jin | 913b873 | 2017-08-08 13:36:23 -0700 | [diff] [blame] | 86 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 87 | vec_free (name); |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 88 | return 0; |
| 89 | } |
| 90 | |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 91 | if (p != 0) |
| 92 | { |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 93 | vec_free (name); |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 94 | return clib_error_return (0, "Policer already exists"); |
| 95 | } |
| 96 | |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 97 | /* Vet the configuration before adding it to the table */ |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 98 | rv = pol_logical_2_physical (cfg, &test_policer); |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 99 | |
| 100 | if (rv == 0) |
| 101 | { |
Brian Russell | 54be0cc | 2021-02-15 11:49:42 +0000 | [diff] [blame] | 102 | policer_t *pp; |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 103 | qos_pol_cfg_params_st *cp; |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 104 | int i; |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 105 | |
| 106 | pool_get (pm->configs, cp); |
| 107 | pool_get (pm->policer_templates, pp); |
| 108 | |
| 109 | ASSERT (cp - pm->configs == pp - pm->policer_templates); |
| 110 | |
| 111 | clib_memcpy (cp, cfg, sizeof (*cp)); |
| 112 | clib_memcpy (pp, &test_policer, sizeof (*pp)); |
| 113 | |
| 114 | hash_set_mem (pm->policer_config_by_name, name, cp - pm->configs); |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 115 | pool_get_aligned (pm->policers, policer, CLIB_CACHE_LINE_BYTES); |
| 116 | policer[0] = pp[0]; |
| 117 | pi = policer - pm->policers; |
| 118 | hash_set_mem (pm->policer_index_by_name, name, pi); |
| 119 | *policer_index = pi; |
Brian Russell | 89cd744 | 2021-01-19 16:46:08 +0000 | [diff] [blame] | 120 | policer->thread_index = ~0; |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 121 | |
| 122 | for (i = 0; i < NUM_POLICE_RESULTS; i++) |
| 123 | { |
| 124 | vlib_validate_combined_counter (&policer_counters[i], pi); |
| 125 | vlib_zero_combined_counter (&policer_counters[i], pi); |
| 126 | } |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 127 | } |
| 128 | else |
| 129 | { |
| 130 | vec_free (name); |
| 131 | return clib_error_return (0, "Config failed sanity check"); |
| 132 | } |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
Brian Russell | 48e2636 | 2021-02-10 13:53:42 +0000 | [diff] [blame] | 137 | int |
| 138 | policer_bind_worker (u8 *name, u32 worker, bool bind) |
| 139 | { |
| 140 | vnet_policer_main_t *pm = &vnet_policer_main; |
Brian Russell | 54be0cc | 2021-02-15 11:49:42 +0000 | [diff] [blame] | 141 | policer_t *policer; |
Brian Russell | 48e2636 | 2021-02-10 13:53:42 +0000 | [diff] [blame] | 142 | uword *p; |
| 143 | |
| 144 | p = hash_get_mem (pm->policer_index_by_name, name); |
| 145 | if (p == 0) |
| 146 | { |
| 147 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
| 148 | } |
| 149 | |
| 150 | policer = &pm->policers[p[0]]; |
| 151 | |
| 152 | if (bind) |
| 153 | { |
| 154 | if (worker >= vlib_num_workers ()) |
| 155 | { |
| 156 | return VNET_API_ERROR_INVALID_WORKER; |
| 157 | } |
| 158 | |
| 159 | policer->thread_index = vlib_get_worker_thread_index (worker); |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | policer->thread_index = ~0; |
| 164 | } |
| 165 | return 0; |
| 166 | } |
| 167 | |
Brian Russell | b046830 | 2021-02-17 15:51:45 +0000 | [diff] [blame] | 168 | int |
| 169 | policer_input (u8 *name, u32 sw_if_index, bool apply) |
| 170 | { |
| 171 | vnet_policer_main_t *pm = &vnet_policer_main; |
| 172 | policer_t *policer; |
| 173 | u32 policer_index; |
| 174 | uword *p; |
| 175 | |
| 176 | p = hash_get_mem (pm->policer_index_by_name, name); |
| 177 | if (p == 0) |
| 178 | { |
| 179 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
| 180 | } |
| 181 | |
| 182 | policer = &pm->policers[p[0]]; |
| 183 | policer_index = policer - pm->policers; |
| 184 | |
| 185 | if (apply) |
| 186 | { |
| 187 | vec_validate (pm->policer_index_by_sw_if_index, sw_if_index); |
| 188 | pm->policer_index_by_sw_if_index[sw_if_index] = policer_index; |
| 189 | } |
| 190 | else |
| 191 | { |
| 192 | pm->policer_index_by_sw_if_index[sw_if_index] = ~0; |
| 193 | } |
| 194 | |
| 195 | vnet_feature_enable_disable ("device-input", "policer-input", sw_if_index, |
| 196 | apply, 0, 0); |
| 197 | return 0; |
| 198 | } |
| 199 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 200 | u8 * |
| 201 | format_policer_instance (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 202 | { |
Brian Russell | 54be0cc | 2021-02-15 11:49:42 +0000 | [diff] [blame] | 203 | policer_t *i = va_arg (*va, policer_t *); |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 204 | uword pi = va_arg (*va, uword); |
| 205 | int result; |
| 206 | vlib_counter_t counts[NUM_POLICE_RESULTS]; |
| 207 | |
| 208 | for (result = 0; result < NUM_POLICE_RESULTS; result++) |
| 209 | { |
| 210 | vlib_get_combined_counter (&policer_counters[result], pi, |
| 211 | &counts[result]); |
| 212 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 213 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 214 | s = format (s, "policer at %llx: %s rate, %s color-aware\n", |
| 215 | i, i->single_rate ? "single" : "dual", |
| 216 | i->color_aware ? "is" : "not"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 217 | s = format (s, "cir %u tok/period, pir %u tok/period, scale %u\n", |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 218 | i->cir_tokens_per_period, i->pir_tokens_per_period, i->scale); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 219 | s = format (s, "cur lim %u, cur bkt %u, ext lim %u, ext bkt %u\n", |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 220 | i->current_limit, |
| 221 | i->current_bucket, i->extended_limit, i->extended_bucket); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 222 | s = format (s, "last update %llu\n", i->last_update_time); |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 223 | s = format (s, "conform %llu packets, %llu bytes\n", |
| 224 | counts[POLICE_CONFORM].packets, counts[POLICE_CONFORM].bytes); |
| 225 | s = format (s, "exceed %llu packets, %llu bytes\n", |
| 226 | counts[POLICE_EXCEED].packets, counts[POLICE_EXCEED].bytes); |
| 227 | s = format (s, "violate %llu packets, %llu bytes\n", |
| 228 | counts[POLICE_VIOLATE].packets, counts[POLICE_VIOLATE].bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 229 | return s; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 230 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 231 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 232 | static u8 * |
| 233 | format_policer_round_type (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 234 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 235 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 236 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 237 | if (c->rnd_type == QOS_ROUND_TO_CLOSEST) |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 238 | s = format (s, "closest"); |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 239 | else if (c->rnd_type == QOS_ROUND_TO_UP) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | s = format (s, "up"); |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 241 | else if (c->rnd_type == QOS_ROUND_TO_DOWN) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | s = format (s, "down"); |
| 243 | else |
| 244 | s = format (s, "ILLEGAL"); |
| 245 | return s; |
| 246 | } |
| 247 | |
| 248 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 249 | static u8 * |
| 250 | format_policer_rate_type (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 251 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 252 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 253 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 254 | if (c->rate_type == QOS_RATE_KBPS) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 255 | s = format (s, "kbps"); |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 256 | else if (c->rate_type == QOS_RATE_PPS) |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 257 | s = format (s, "pps"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 258 | else |
| 259 | s = format (s, "ILLEGAL"); |
| 260 | return s; |
| 261 | } |
| 262 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 263 | static u8 * |
| 264 | format_policer_type (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 266 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 267 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 268 | if (c->rfc == QOS_POLICER_TYPE_1R2C) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 269 | s = format (s, "1r2c"); |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 270 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 271 | else if (c->rfc == QOS_POLICER_TYPE_1R3C_RFC_2697) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 272 | s = format (s, "1r3c"); |
| 273 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 274 | else if (c->rfc == QOS_POLICER_TYPE_2R3C_RFC_2698) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 275 | s = format (s, "2r3c-2698"); |
| 276 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 277 | else if (c->rfc == QOS_POLICER_TYPE_2R3C_RFC_4115) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 278 | s = format (s, "2r3c-4115"); |
| 279 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 280 | else if (c->rfc == QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 281 | s = format (s, "2r3c-mef5cf1"); |
| 282 | else |
| 283 | s = format (s, "ILLEGAL"); |
| 284 | return s; |
| 285 | } |
| 286 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 287 | static u8 * |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 288 | format_policer_action_type (u8 * s, va_list * va) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 289 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 290 | qos_pol_action_params_st *a = va_arg (*va, qos_pol_action_params_st *); |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 291 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 292 | if (a->action_type == QOS_ACTION_DROP) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 293 | s = format (s, "drop"); |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 294 | else if (a->action_type == QOS_ACTION_TRANSMIT) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 295 | s = format (s, "transmit"); |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 296 | else if (a->action_type == QOS_ACTION_MARK_AND_TRANSMIT) |
Brian Russell | e3845d7 | 2021-02-08 15:33:18 +0000 | [diff] [blame] | 297 | s = format (s, "mark-and-transmit %U", format_ip_dscp, a->dscp); |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 298 | else |
| 299 | s = format (s, "ILLEGAL"); |
| 300 | return s; |
| 301 | } |
| 302 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 303 | u8 * |
| 304 | format_policer_config (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 305 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 306 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 307 | |
| 308 | s = format (s, "type %U cir %u eir %u cb %u eb %u\n", |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 309 | format_policer_type, c, |
| 310 | c->rb.kbps.cir_kbps, |
| 311 | c->rb.kbps.eir_kbps, c->rb.kbps.cb_bytes, c->rb.kbps.eb_bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 312 | s = format (s, "rate type %U, round type %U\n", |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 313 | format_policer_rate_type, c, format_policer_round_type, c); |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 314 | s = format (s, "conform action %U, exceed action %U, violate action %U\n", |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 315 | format_policer_action_type, &c->conform_action, |
| 316 | format_policer_action_type, &c->exceed_action, |
| 317 | format_policer_action_type, &c->violate_action); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 318 | return s; |
| 319 | } |
| 320 | |
| 321 | static uword |
| 322 | unformat_policer_type (unformat_input_t * input, va_list * va) |
| 323 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 324 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 325 | |
| 326 | if (!unformat (input, "type")) |
| 327 | return 0; |
| 328 | |
| 329 | if (unformat (input, "1r2c")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 330 | c->rfc = QOS_POLICER_TYPE_1R2C; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 331 | else if (unformat (input, "1r3c")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 332 | c->rfc = QOS_POLICER_TYPE_1R3C_RFC_2697; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 333 | else if (unformat (input, "2r3c-2698")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 334 | c->rfc = QOS_POLICER_TYPE_2R3C_RFC_2698; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 335 | else if (unformat (input, "2r3c-4115")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 336 | c->rfc = QOS_POLICER_TYPE_2R3C_RFC_4115; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 337 | else if (unformat (input, "2r3c-mef5cf1")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 338 | c->rfc = QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 339 | else |
| 340 | return 0; |
| 341 | return 1; |
| 342 | } |
| 343 | |
| 344 | static uword |
| 345 | unformat_policer_round_type (unformat_input_t * input, va_list * va) |
| 346 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 347 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 348 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 349 | if (!unformat (input, "round")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 350 | return 0; |
| 351 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 352 | if (unformat (input, "closest")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 353 | c->rnd_type = QOS_ROUND_TO_CLOSEST; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 354 | else if (unformat (input, "up")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 355 | c->rnd_type = QOS_ROUND_TO_UP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 356 | else if (unformat (input, "down")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 357 | c->rnd_type = QOS_ROUND_TO_DOWN; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 358 | else |
| 359 | return 0; |
| 360 | return 1; |
| 361 | } |
| 362 | |
| 363 | static uword |
| 364 | unformat_policer_rate_type (unformat_input_t * input, va_list * va) |
| 365 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 366 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 367 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 368 | if (!unformat (input, "rate")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 369 | return 0; |
| 370 | |
| 371 | if (unformat (input, "kbps")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 372 | c->rate_type = QOS_RATE_KBPS; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 373 | else if (unformat (input, "pps")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 374 | c->rate_type = QOS_RATE_PPS; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 375 | else |
| 376 | return 0; |
| 377 | return 1; |
| 378 | } |
| 379 | |
| 380 | static uword |
| 381 | unformat_policer_cir (unformat_input_t * input, va_list * va) |
| 382 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 383 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 384 | |
| 385 | if (unformat (input, "cir %u", &c->rb.kbps.cir_kbps)) |
| 386 | return 1; |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | static uword |
| 391 | unformat_policer_eir (unformat_input_t * input, va_list * va) |
| 392 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 393 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 394 | |
| 395 | if (unformat (input, "eir %u", &c->rb.kbps.eir_kbps)) |
| 396 | return 1; |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | static uword |
| 401 | unformat_policer_cb (unformat_input_t * input, va_list * va) |
| 402 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 403 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 404 | |
| 405 | if (unformat (input, "cb %u", &c->rb.kbps.cb_bytes)) |
| 406 | return 1; |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | static uword |
| 411 | unformat_policer_eb (unformat_input_t * input, va_list * va) |
| 412 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 413 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 414 | |
| 415 | if (unformat (input, "eb %u", &c->rb.kbps.eb_bytes)) |
| 416 | return 1; |
| 417 | return 0; |
| 418 | } |
| 419 | |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 420 | static uword |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 421 | unformat_policer_action_type (unformat_input_t * input, va_list * va) |
| 422 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 423 | qos_pol_action_params_st *a = va_arg (*va, qos_pol_action_params_st *); |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 424 | |
| 425 | if (unformat (input, "drop")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 426 | a->action_type = QOS_ACTION_DROP; |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 427 | else if (unformat (input, "transmit")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 428 | a->action_type = QOS_ACTION_TRANSMIT; |
Brian Russell | e3845d7 | 2021-02-08 15:33:18 +0000 | [diff] [blame] | 429 | else if (unformat (input, "mark-and-transmit %U", unformat_ip_dscp, |
| 430 | &a->dscp)) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 431 | a->action_type = QOS_ACTION_MARK_AND_TRANSMIT; |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 432 | else |
| 433 | return 0; |
| 434 | return 1; |
| 435 | } |
| 436 | |
| 437 | static uword |
| 438 | unformat_policer_action (unformat_input_t * input, va_list * va) |
| 439 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 440 | qos_pol_cfg_params_st *c = va_arg (*va, qos_pol_cfg_params_st *); |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 441 | |
| 442 | if (unformat (input, "conform-action %U", unformat_policer_action_type, |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 443 | &c->conform_action)) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 444 | return 1; |
| 445 | else if (unformat (input, "exceed-action %U", unformat_policer_action_type, |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 446 | &c->exceed_action)) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 447 | return 1; |
| 448 | else if (unformat (input, "violate-action %U", unformat_policer_action_type, |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 449 | &c->violate_action)) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 450 | return 1; |
| 451 | return 0; |
| 452 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 453 | |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 454 | static uword |
| 455 | unformat_policer_classify_next_index (unformat_input_t * input, va_list * va) |
| 456 | { |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 457 | u32 *r = va_arg (*va, u32 *); |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 458 | vnet_policer_main_t *pm = &vnet_policer_main; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 459 | uword *p; |
| 460 | u8 *match_name = 0; |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 461 | |
| 462 | if (unformat (input, "%s", &match_name)) |
| 463 | ; |
| 464 | else |
| 465 | return 0; |
| 466 | |
| 467 | p = hash_get_mem (pm->policer_index_by_name, match_name); |
| 468 | |
| 469 | if (p == 0) |
| 470 | return 0; |
| 471 | |
| 472 | *r = p[0]; |
| 473 | |
| 474 | return 1; |
| 475 | } |
| 476 | |
| 477 | static uword |
| 478 | unformat_policer_classify_precolor (unformat_input_t * input, va_list * va) |
| 479 | { |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 480 | u32 *r = va_arg (*va, u32 *); |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 481 | |
| 482 | if (unformat (input, "conform-color")) |
| 483 | *r = POLICE_CONFORM; |
| 484 | else if (unformat (input, "exceed-color")) |
| 485 | *r = POLICE_EXCEED; |
| 486 | else |
| 487 | return 0; |
| 488 | |
| 489 | return 1; |
| 490 | } |
| 491 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 492 | #define foreach_config_param \ |
| 493 | _(eb) \ |
| 494 | _(cb) \ |
| 495 | _(eir) \ |
| 496 | _(cir) \ |
| 497 | _(rate_type) \ |
| 498 | _(round_type) \ |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 499 | _(type) \ |
| 500 | _(action) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 501 | |
| 502 | static clib_error_t * |
| 503 | configure_policer_command_fn (vlib_main_t * vm, |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 504 | unformat_input_t * input, |
| 505 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 506 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 507 | qos_pol_cfg_params_st c; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 508 | unformat_input_t _line_input, *line_input = &_line_input; |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 509 | u8 is_add = 1; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 510 | u8 *name = 0; |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 511 | u32 pi; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 512 | clib_error_t *error = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 513 | |
| 514 | /* Get a line of input. */ |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 515 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 516 | return 0; |
| 517 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 518 | clib_memset (&c, 0, sizeof (c)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 519 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 520 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 521 | { |
| 522 | if (unformat (line_input, "del")) |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 523 | is_add = 0; |
| 524 | else if (unformat (line_input, "name %s", &name)) |
| 525 | ; |
| 526 | else if (unformat (line_input, "color-aware")) |
| 527 | c.color_aware = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 528 | |
| 529 | #define _(a) else if (unformat (line_input, "%U", unformat_policer_##a, &c)) ; |
| 530 | foreach_config_param |
| 531 | #undef _ |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 532 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 533 | { |
| 534 | error = clib_error_return (0, "unknown input `%U'", |
| 535 | format_unformat_error, line_input); |
| 536 | goto done; |
| 537 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 540 | error = policer_add_del (vm, name, &c, &pi, is_add); |
| 541 | |
| 542 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 543 | unformat_free (line_input); |
| 544 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 545 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 548 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 549 | VLIB_CLI_COMMAND (configure_policer_command, static) = { |
| 550 | .path = "configure policer", |
| 551 | .short_help = "configure policer name <name> <params> ", |
| 552 | .function = configure_policer_command_fn, |
| 553 | }; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 554 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 555 | |
| 556 | static clib_error_t * |
| 557 | show_policer_command_fn (vlib_main_t * vm, |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 558 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 559 | { |
| 560 | vnet_policer_main_t *pm = &vnet_policer_main; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 561 | hash_pair_t *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 562 | u32 pool_index; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 563 | u8 *match_name = 0; |
| 564 | u8 *name; |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 565 | uword *pi; |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 566 | qos_pol_cfg_params_st *config; |
Brian Russell | 54be0cc | 2021-02-15 11:49:42 +0000 | [diff] [blame] | 567 | policer_t *templ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 568 | |
| 569 | (void) unformat (input, "name %s", &match_name); |
| 570 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 571 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 572 | hash_foreach_pair (p, pm->policer_config_by_name, |
| 573 | ({ |
| 574 | name = (u8 *) p->key; |
| 575 | if (match_name == 0 || !strcmp((char *) name, (char *) match_name)) |
| 576 | { |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 577 | pi = hash_get_mem (pm->policer_index_by_name, name); |
| 578 | |
| 579 | pool_index = p->value[0]; |
| 580 | config = pool_elt_at_index (pm->configs, pool_index); |
| 581 | templ = pool_elt_at_index (pm->policer_templates, pool_index); |
| 582 | vlib_cli_output (vm, "Name \"%s\" %U ", name, format_policer_config, |
| 583 | config); |
| 584 | vlib_cli_output (vm, "Template %U", format_policer_instance, templ, |
| 585 | pi[0]); |
| 586 | vlib_cli_output (vm, "-----------"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 587 | } |
| 588 | })); |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 589 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 594 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 595 | VLIB_CLI_COMMAND (show_policer_command, static) = { |
| 596 | .path = "show policer", |
| 597 | .short_help = "show policer [name]", |
| 598 | .function = show_policer_command_fn, |
| 599 | }; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 600 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 601 | |
Chaoyu Jin | 913b873 | 2017-08-08 13:36:23 -0700 | [diff] [blame] | 602 | static clib_error_t * |
| 603 | show_policer_pools_command_fn (vlib_main_t * vm, |
| 604 | unformat_input_t * input, |
| 605 | vlib_cli_command_t * cmd) |
| 606 | { |
| 607 | vnet_policer_main_t *pm = &vnet_policer_main; |
| 608 | |
| 609 | vlib_cli_output (vm, "pool sizes: configs=%d templates=%d policers=%d", |
| 610 | pool_elts (pm->configs), |
| 611 | pool_elts (pm->policer_templates), |
| 612 | pool_elts (pm->policers)); |
| 613 | return 0; |
| 614 | } |
| 615 | /* *INDENT-OFF* */ |
| 616 | VLIB_CLI_COMMAND (show_policer_pools_command, static) = { |
| 617 | .path = "show policer pools", |
| 618 | .short_help = "show policer pools", |
| 619 | .function = show_policer_pools_command_fn, |
| 620 | }; |
| 621 | /* *INDENT-ON* */ |
| 622 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 623 | clib_error_t * |
| 624 | policer_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 625 | { |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 626 | vnet_policer_main_t *pm = &vnet_policer_main; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 627 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 628 | pm->vlib_main = vm; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 629 | pm->vnet_main = vnet_get_main (); |
Brian Russell | bbccdc5 | 2021-02-10 18:34:48 +0000 | [diff] [blame] | 630 | pm->log_class = vlib_log_register_class ("policer", 0); |
Brian Russell | 1aa9912 | 2021-02-18 11:00:38 +0000 | [diff] [blame^] | 631 | pm->fq_index = vlib_frame_queue_main_init (policer_input_node.index, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 632 | |
| 633 | pm->policer_config_by_name = hash_create_string (0, sizeof (uword)); |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 634 | pm->policer_index_by_name = hash_create_string (0, sizeof (uword)); |
| 635 | |
| 636 | vnet_classify_register_unformat_policer_next_index_fn |
| 637 | (unformat_policer_classify_next_index); |
| 638 | vnet_classify_register_unformat_opaque_index_fn |
| 639 | (unformat_policer_classify_precolor); |
| 640 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 641 | return 0; |
| 642 | } |
| 643 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 644 | VLIB_INIT_FUNCTION (policer_init); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 645 | |
| 646 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 647 | |
| 648 | /* |
| 649 | * fd.io coding-style-patch-verification: ON |
| 650 | * |
| 651 | * Local Variables: |
| 652 | * eval: (c-set-style "gnu") |
| 653 | * End: |
| 654 | */ |