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