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 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 168 | u8 * |
| 169 | format_policer_instance (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | { |
Brian Russell | 54be0cc | 2021-02-15 11:49:42 +0000 | [diff] [blame^] | 171 | policer_t *i = va_arg (*va, policer_t *); |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 172 | uword pi = va_arg (*va, uword); |
| 173 | int result; |
| 174 | vlib_counter_t counts[NUM_POLICE_RESULTS]; |
| 175 | |
| 176 | for (result = 0; result < NUM_POLICE_RESULTS; result++) |
| 177 | { |
| 178 | vlib_get_combined_counter (&policer_counters[result], pi, |
| 179 | &counts[result]); |
| 180 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 182 | s = format (s, "policer at %llx: %s rate, %s color-aware\n", |
| 183 | i, i->single_rate ? "single" : "dual", |
| 184 | i->color_aware ? "is" : "not"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 185 | 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] | 186 | i->cir_tokens_per_period, i->pir_tokens_per_period, i->scale); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 187 | 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] | 188 | i->current_limit, |
| 189 | i->current_bucket, i->extended_limit, i->extended_bucket); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 190 | s = format (s, "last update %llu\n", i->last_update_time); |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 191 | s = format (s, "conform %llu packets, %llu bytes\n", |
| 192 | counts[POLICE_CONFORM].packets, counts[POLICE_CONFORM].bytes); |
| 193 | s = format (s, "exceed %llu packets, %llu bytes\n", |
| 194 | counts[POLICE_EXCEED].packets, counts[POLICE_EXCEED].bytes); |
| 195 | s = format (s, "violate %llu packets, %llu bytes\n", |
| 196 | counts[POLICE_VIOLATE].packets, counts[POLICE_VIOLATE].bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 197 | return s; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 198 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 199 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 200 | static u8 * |
| 201 | format_policer_round_type (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 202 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 203 | 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] | 204 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 205 | if (c->rnd_type == QOS_ROUND_TO_CLOSEST) |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 206 | s = format (s, "closest"); |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 207 | else if (c->rnd_type == QOS_ROUND_TO_UP) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 208 | s = format (s, "up"); |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 209 | else if (c->rnd_type == QOS_ROUND_TO_DOWN) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 210 | s = format (s, "down"); |
| 211 | else |
| 212 | s = format (s, "ILLEGAL"); |
| 213 | return s; |
| 214 | } |
| 215 | |
| 216 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 217 | static u8 * |
| 218 | format_policer_rate_type (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 219 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 220 | 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] | 221 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 222 | if (c->rate_type == QOS_RATE_KBPS) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 223 | s = format (s, "kbps"); |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 224 | else if (c->rate_type == QOS_RATE_PPS) |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 225 | s = format (s, "pps"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | else |
| 227 | s = format (s, "ILLEGAL"); |
| 228 | return s; |
| 229 | } |
| 230 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 231 | static u8 * |
| 232 | format_policer_type (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 234 | 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] | 235 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 236 | if (c->rfc == QOS_POLICER_TYPE_1R2C) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 237 | s = format (s, "1r2c"); |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 238 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 239 | else if (c->rfc == QOS_POLICER_TYPE_1R3C_RFC_2697) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | s = format (s, "1r3c"); |
| 241 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 242 | else if (c->rfc == QOS_POLICER_TYPE_2R3C_RFC_2698) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 243 | s = format (s, "2r3c-2698"); |
| 244 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 245 | else if (c->rfc == QOS_POLICER_TYPE_2R3C_RFC_4115) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 246 | s = format (s, "2r3c-4115"); |
| 247 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 248 | else if (c->rfc == QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 249 | s = format (s, "2r3c-mef5cf1"); |
| 250 | else |
| 251 | s = format (s, "ILLEGAL"); |
| 252 | return s; |
| 253 | } |
| 254 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 255 | static u8 * |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 256 | format_policer_action_type (u8 * s, va_list * va) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 257 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 258 | 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] | 259 | |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 260 | if (a->action_type == QOS_ACTION_DROP) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 261 | s = format (s, "drop"); |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 262 | else if (a->action_type == QOS_ACTION_TRANSMIT) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 263 | s = format (s, "transmit"); |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 264 | else if (a->action_type == QOS_ACTION_MARK_AND_TRANSMIT) |
Brian Russell | e3845d7 | 2021-02-08 15:33:18 +0000 | [diff] [blame] | 265 | s = format (s, "mark-and-transmit %U", format_ip_dscp, a->dscp); |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 266 | else |
| 267 | s = format (s, "ILLEGAL"); |
| 268 | return s; |
| 269 | } |
| 270 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 271 | u8 * |
| 272 | format_policer_config (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 273 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 274 | 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] | 275 | |
| 276 | 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] | 277 | format_policer_type, c, |
| 278 | c->rb.kbps.cir_kbps, |
| 279 | 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] | 280 | s = format (s, "rate type %U, round type %U\n", |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 281 | format_policer_rate_type, c, format_policer_round_type, c); |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 282 | 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] | 283 | format_policer_action_type, &c->conform_action, |
| 284 | format_policer_action_type, &c->exceed_action, |
| 285 | format_policer_action_type, &c->violate_action); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 286 | return s; |
| 287 | } |
| 288 | |
| 289 | static uword |
| 290 | unformat_policer_type (unformat_input_t * input, va_list * va) |
| 291 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 292 | 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] | 293 | |
| 294 | if (!unformat (input, "type")) |
| 295 | return 0; |
| 296 | |
| 297 | if (unformat (input, "1r2c")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 298 | c->rfc = QOS_POLICER_TYPE_1R2C; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 299 | else if (unformat (input, "1r3c")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 300 | c->rfc = QOS_POLICER_TYPE_1R3C_RFC_2697; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 301 | else if (unformat (input, "2r3c-2698")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 302 | c->rfc = QOS_POLICER_TYPE_2R3C_RFC_2698; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 303 | else if (unformat (input, "2r3c-4115")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 304 | c->rfc = QOS_POLICER_TYPE_2R3C_RFC_4115; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 305 | else if (unformat (input, "2r3c-mef5cf1")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 306 | c->rfc = QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 307 | else |
| 308 | return 0; |
| 309 | return 1; |
| 310 | } |
| 311 | |
| 312 | static uword |
| 313 | unformat_policer_round_type (unformat_input_t * input, va_list * va) |
| 314 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 315 | 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] | 316 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 317 | if (!unformat (input, "round")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 318 | return 0; |
| 319 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 320 | if (unformat (input, "closest")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 321 | c->rnd_type = QOS_ROUND_TO_CLOSEST; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 322 | else if (unformat (input, "up")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 323 | c->rnd_type = QOS_ROUND_TO_UP; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 324 | else if (unformat (input, "down")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 325 | c->rnd_type = QOS_ROUND_TO_DOWN; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 326 | else |
| 327 | return 0; |
| 328 | return 1; |
| 329 | } |
| 330 | |
| 331 | static uword |
| 332 | unformat_policer_rate_type (unformat_input_t * input, va_list * va) |
| 333 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 334 | 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] | 335 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 336 | if (!unformat (input, "rate")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 337 | return 0; |
| 338 | |
| 339 | if (unformat (input, "kbps")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 340 | c->rate_type = QOS_RATE_KBPS; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 341 | else if (unformat (input, "pps")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 342 | c->rate_type = QOS_RATE_PPS; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 343 | else |
| 344 | return 0; |
| 345 | return 1; |
| 346 | } |
| 347 | |
| 348 | static uword |
| 349 | unformat_policer_cir (unformat_input_t * input, va_list * va) |
| 350 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 351 | 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] | 352 | |
| 353 | if (unformat (input, "cir %u", &c->rb.kbps.cir_kbps)) |
| 354 | return 1; |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | static uword |
| 359 | unformat_policer_eir (unformat_input_t * input, va_list * va) |
| 360 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 361 | 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] | 362 | |
| 363 | if (unformat (input, "eir %u", &c->rb.kbps.eir_kbps)) |
| 364 | return 1; |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | static uword |
| 369 | unformat_policer_cb (unformat_input_t * input, va_list * va) |
| 370 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 371 | 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] | 372 | |
| 373 | if (unformat (input, "cb %u", &c->rb.kbps.cb_bytes)) |
| 374 | return 1; |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static uword |
| 379 | unformat_policer_eb (unformat_input_t * input, va_list * va) |
| 380 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 381 | 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] | 382 | |
| 383 | if (unformat (input, "eb %u", &c->rb.kbps.eb_bytes)) |
| 384 | return 1; |
| 385 | return 0; |
| 386 | } |
| 387 | |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 388 | static uword |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 389 | unformat_policer_action_type (unformat_input_t * input, va_list * va) |
| 390 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 391 | 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] | 392 | |
| 393 | if (unformat (input, "drop")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 394 | a->action_type = QOS_ACTION_DROP; |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 395 | else if (unformat (input, "transmit")) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 396 | a->action_type = QOS_ACTION_TRANSMIT; |
Brian Russell | e3845d7 | 2021-02-08 15:33:18 +0000 | [diff] [blame] | 397 | else if (unformat (input, "mark-and-transmit %U", unformat_ip_dscp, |
| 398 | &a->dscp)) |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 399 | a->action_type = QOS_ACTION_MARK_AND_TRANSMIT; |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 400 | else |
| 401 | return 0; |
| 402 | return 1; |
| 403 | } |
| 404 | |
| 405 | static uword |
| 406 | unformat_policer_action (unformat_input_t * input, va_list * va) |
| 407 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 408 | 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] | 409 | |
| 410 | if (unformat (input, "conform-action %U", unformat_policer_action_type, |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 411 | &c->conform_action)) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 412 | return 1; |
| 413 | else if (unformat (input, "exceed-action %U", unformat_policer_action_type, |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 414 | &c->exceed_action)) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 415 | return 1; |
| 416 | else if (unformat (input, "violate-action %U", unformat_policer_action_type, |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 417 | &c->violate_action)) |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 418 | return 1; |
| 419 | return 0; |
| 420 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 421 | |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 422 | static uword |
| 423 | unformat_policer_classify_next_index (unformat_input_t * input, va_list * va) |
| 424 | { |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 425 | u32 *r = va_arg (*va, u32 *); |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 426 | vnet_policer_main_t *pm = &vnet_policer_main; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 427 | uword *p; |
| 428 | u8 *match_name = 0; |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 429 | |
| 430 | if (unformat (input, "%s", &match_name)) |
| 431 | ; |
| 432 | else |
| 433 | return 0; |
| 434 | |
| 435 | p = hash_get_mem (pm->policer_index_by_name, match_name); |
| 436 | |
| 437 | if (p == 0) |
| 438 | return 0; |
| 439 | |
| 440 | *r = p[0]; |
| 441 | |
| 442 | return 1; |
| 443 | } |
| 444 | |
| 445 | static uword |
| 446 | unformat_policer_classify_precolor (unformat_input_t * input, va_list * va) |
| 447 | { |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 448 | u32 *r = va_arg (*va, u32 *); |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 449 | |
| 450 | if (unformat (input, "conform-color")) |
| 451 | *r = POLICE_CONFORM; |
| 452 | else if (unformat (input, "exceed-color")) |
| 453 | *r = POLICE_EXCEED; |
| 454 | else |
| 455 | return 0; |
| 456 | |
| 457 | return 1; |
| 458 | } |
| 459 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 460 | #define foreach_config_param \ |
| 461 | _(eb) \ |
| 462 | _(cb) \ |
| 463 | _(eir) \ |
| 464 | _(cir) \ |
| 465 | _(rate_type) \ |
| 466 | _(round_type) \ |
Matus Fabian | 4ac74c9 | 2016-05-31 07:33:29 -0700 | [diff] [blame] | 467 | _(type) \ |
| 468 | _(action) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 469 | |
| 470 | static clib_error_t * |
| 471 | configure_policer_command_fn (vlib_main_t * vm, |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 472 | unformat_input_t * input, |
| 473 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 474 | { |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 475 | qos_pol_cfg_params_st c; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 476 | unformat_input_t _line_input, *line_input = &_line_input; |
Matus Fabian | 65fcd4d | 2016-05-13 05:44:48 -0700 | [diff] [blame] | 477 | u8 is_add = 1; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 478 | u8 *name = 0; |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 479 | u32 pi; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 480 | clib_error_t *error = NULL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 481 | |
| 482 | /* Get a line of input. */ |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 483 | if (!unformat_user (input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 484 | return 0; |
| 485 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 486 | clib_memset (&c, 0, sizeof (c)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 487 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 488 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 489 | { |
| 490 | if (unformat (line_input, "del")) |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 491 | is_add = 0; |
| 492 | else if (unformat (line_input, "name %s", &name)) |
| 493 | ; |
| 494 | else if (unformat (line_input, "color-aware")) |
| 495 | c.color_aware = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 496 | |
| 497 | #define _(a) else if (unformat (line_input, "%U", unformat_policer_##a, &c)) ; |
| 498 | foreach_config_param |
| 499 | #undef _ |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 500 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 501 | { |
| 502 | error = clib_error_return (0, "unknown input `%U'", |
| 503 | format_unformat_error, line_input); |
| 504 | goto done; |
| 505 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 508 | error = policer_add_del (vm, name, &c, &pi, is_add); |
| 509 | |
| 510 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 511 | unformat_free (line_input); |
| 512 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 513 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 516 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 517 | VLIB_CLI_COMMAND (configure_policer_command, static) = { |
| 518 | .path = "configure policer", |
| 519 | .short_help = "configure policer name <name> <params> ", |
| 520 | .function = configure_policer_command_fn, |
| 521 | }; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 522 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 523 | |
| 524 | static clib_error_t * |
| 525 | show_policer_command_fn (vlib_main_t * vm, |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 526 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 527 | { |
| 528 | vnet_policer_main_t *pm = &vnet_policer_main; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 529 | hash_pair_t *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 530 | u32 pool_index; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 531 | u8 *match_name = 0; |
| 532 | u8 *name; |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 533 | uword *pi; |
Brian Russell | c5299ff | 2021-02-09 10:16:58 +0000 | [diff] [blame] | 534 | qos_pol_cfg_params_st *config; |
Brian Russell | 54be0cc | 2021-02-15 11:49:42 +0000 | [diff] [blame^] | 535 | policer_t *templ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 536 | |
| 537 | (void) unformat (input, "name %s", &match_name); |
| 538 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 539 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 540 | hash_foreach_pair (p, pm->policer_config_by_name, |
| 541 | ({ |
| 542 | name = (u8 *) p->key; |
| 543 | if (match_name == 0 || !strcmp((char *) name, (char *) match_name)) |
| 544 | { |
Brian Russell | a71ed78 | 2021-01-27 11:34:33 +0000 | [diff] [blame] | 545 | pi = hash_get_mem (pm->policer_index_by_name, name); |
| 546 | |
| 547 | pool_index = p->value[0]; |
| 548 | config = pool_elt_at_index (pm->configs, pool_index); |
| 549 | templ = pool_elt_at_index (pm->policer_templates, pool_index); |
| 550 | vlib_cli_output (vm, "Name \"%s\" %U ", name, format_policer_config, |
| 551 | config); |
| 552 | vlib_cli_output (vm, "Template %U", format_policer_instance, templ, |
| 553 | pi[0]); |
| 554 | vlib_cli_output (vm, "-----------"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 555 | } |
| 556 | })); |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 557 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 562 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 563 | VLIB_CLI_COMMAND (show_policer_command, static) = { |
| 564 | .path = "show policer", |
| 565 | .short_help = "show policer [name]", |
| 566 | .function = show_policer_command_fn, |
| 567 | }; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 568 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 569 | |
Chaoyu Jin | 913b873 | 2017-08-08 13:36:23 -0700 | [diff] [blame] | 570 | static clib_error_t * |
| 571 | show_policer_pools_command_fn (vlib_main_t * vm, |
| 572 | unformat_input_t * input, |
| 573 | vlib_cli_command_t * cmd) |
| 574 | { |
| 575 | vnet_policer_main_t *pm = &vnet_policer_main; |
| 576 | |
| 577 | vlib_cli_output (vm, "pool sizes: configs=%d templates=%d policers=%d", |
| 578 | pool_elts (pm->configs), |
| 579 | pool_elts (pm->policer_templates), |
| 580 | pool_elts (pm->policers)); |
| 581 | return 0; |
| 582 | } |
| 583 | /* *INDENT-OFF* */ |
| 584 | VLIB_CLI_COMMAND (show_policer_pools_command, static) = { |
| 585 | .path = "show policer pools", |
| 586 | .short_help = "show policer pools", |
| 587 | .function = show_policer_pools_command_fn, |
| 588 | }; |
| 589 | /* *INDENT-ON* */ |
| 590 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 591 | clib_error_t * |
| 592 | policer_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 593 | { |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 594 | vnet_policer_main_t *pm = &vnet_policer_main; |
| 595 | void vnet_policer_node_funcs_reference (void); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 596 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 597 | vnet_policer_node_funcs_reference (); |
| 598 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 599 | pm->vlib_main = vm; |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 600 | pm->vnet_main = vnet_get_main (); |
Brian Russell | bbccdc5 | 2021-02-10 18:34:48 +0000 | [diff] [blame] | 601 | pm->log_class = vlib_log_register_class ("policer", 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 602 | |
| 603 | pm->policer_config_by_name = hash_create_string (0, sizeof (uword)); |
Matus Fabian | 70e6a8d | 2016-06-20 08:10:42 -0700 | [diff] [blame] | 604 | pm->policer_index_by_name = hash_create_string (0, sizeof (uword)); |
| 605 | |
| 606 | vnet_classify_register_unformat_policer_next_index_fn |
| 607 | (unformat_policer_classify_next_index); |
| 608 | vnet_classify_register_unformat_opaque_index_fn |
| 609 | (unformat_policer_classify_precolor); |
| 610 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 611 | return 0; |
| 612 | } |
| 613 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 614 | VLIB_INIT_FUNCTION (policer_init); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 615 | |
| 616 | |
Damjan Marion | 3891cd8 | 2016-10-27 10:27:00 +0200 | [diff] [blame] | 617 | |
| 618 | /* |
| 619 | * fd.io coding-style-patch-verification: ON |
| 620 | * |
| 621 | * Local Variables: |
| 622 | * eval: (c-set-style "gnu") |
| 623 | * End: |
| 624 | */ |