Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * l2_bd.c : layer 2 bridge domain |
| 3 | * |
| 4 | * Copyright (c) 2013 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <vlib/vlib.h> |
| 19 | #include <vnet/vnet.h> |
| 20 | #include <vlib/cli.h> |
| 21 | #include <vnet/ethernet/ethernet.h> |
| 22 | #include <vnet/ip/format.h> |
| 23 | #include <vnet/l2/l2_input.h> |
| 24 | #include <vnet/l2/feat_bitmap.h> |
| 25 | #include <vnet/l2/l2_bd.h> |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 26 | #include <vnet/l2/l2_learn.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | #include <vnet/l2/l2_fib.h> |
| 28 | #include <vnet/l2/l2_vtr.h> |
| 29 | #include <vnet/ip/ip4_packet.h> |
| 30 | #include <vnet/ip/ip6_packet.h> |
| 31 | |
| 32 | #include <vppinfra/error.h> |
| 33 | #include <vppinfra/hash.h> |
| 34 | #include <vppinfra/vec.h> |
| 35 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 36 | /** |
| 37 | * @file |
| 38 | * @brief Ethernet Bridge Domain. |
| 39 | * |
| 40 | * Code in this file manages Layer 2 bridge domains. |
| 41 | * |
| 42 | */ |
| 43 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | bd_main_t bd_main; |
| 45 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 46 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 47 | Init bridge domain if not done already. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 48 | For feature bitmap, set all bits except ARP termination |
| 49 | */ |
Damjan Marion | 99d8c76 | 2015-12-14 15:01:56 +0100 | [diff] [blame] | 50 | void |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 51 | bd_validate (l2_bridge_domain_t * bd_config) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 53 | if (!bd_is_valid (bd_config)) |
| 54 | { |
| 55 | bd_config->feature_bitmap = ~L2INPUT_FEAT_ARP_TERM; |
| 56 | bd_config->bvi_sw_if_index = ~0; |
| 57 | bd_config->members = 0; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 58 | bd_config->flood_count = 0; |
| 59 | bd_config->tun_master_count = 0; |
| 60 | bd_config->tun_normal_count = 0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 61 | bd_config->mac_by_ip4 = 0; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 62 | bd_config->mac_by_ip6 = hash_create_mem (0, sizeof (ip6_address_t), |
| 63 | sizeof (uword)); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 64 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 67 | u32 |
| 68 | bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 70 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | u32 rv; |
| 72 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 73 | if (bd_id == ~0) |
| 74 | { |
| 75 | bd_id = 0; |
| 76 | while (hash_get (bdm->bd_index_by_bd_id, bd_id)) |
| 77 | bd_id++; |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 82 | if (p) |
| 83 | return (p[0]); |
| 84 | } |
| 85 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | rv = clib_bitmap_first_clear (bdm->bd_index_bitmap); |
| 87 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 88 | /* mark this index busy */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 89 | bdm->bd_index_bitmap = clib_bitmap_set (bdm->bd_index_bitmap, rv, 1); |
| 90 | |
| 91 | hash_set (bdm->bd_index_by_bd_id, bd_id, rv); |
| 92 | |
| 93 | vec_validate (l2input_main.bd_configs, rv); |
| 94 | l2input_main.bd_configs[rv].bd_id = bd_id; |
| 95 | |
| 96 | return rv; |
| 97 | } |
| 98 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 99 | int |
| 100 | bd_delete_bd_index (bd_main_t * bdm, u32 bd_id) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 102 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 103 | u32 bd_index; |
| 104 | |
| 105 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 106 | if (p == 0) |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 107 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 108 | |
| 109 | bd_index = p[0]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 110 | |
| 111 | /* mark this index clear */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 112 | bdm->bd_index_bitmap = clib_bitmap_set (bdm->bd_index_bitmap, bd_index, 0); |
| 113 | hash_unset (bdm->bd_index_by_bd_id, bd_id); |
| 114 | |
| 115 | l2input_main.bd_configs[bd_index].bd_id = ~0; |
| 116 | l2input_main.bd_configs[bd_index].feature_bitmap = 0; |
| 117 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 118 | l2fib_flush_bd_mac (vlib_get_main (), bd_index); |
| 119 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 123 | static void |
| 124 | update_flood_count (l2_bridge_domain_t * bd_config) |
| 125 | { |
| 126 | bd_config->flood_count = vec_len (bd_config->members) - |
| 127 | (bd_config->tun_master_count ? bd_config->tun_normal_count : 0); |
| 128 | } |
| 129 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | void |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 131 | bd_add_member (l2_bridge_domain_t * bd_config, l2_flood_member_t * member) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 132 | { |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 133 | u32 ix; |
| 134 | vnet_sw_interface_t *sw_if = vnet_get_sw_interface |
| 135 | (vnet_get_main (), member->sw_if_index); |
| 136 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 137 | /* |
| 138 | * Add one element to the vector |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 139 | * vector is ordered [ bvi, normal/tun_masters..., tun_normals... ] |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 140 | * When flooding, the bvi interface (if present) must be the last member |
| 141 | * processed due to how BVI processing can change the packet. To enable |
| 142 | * this order, we make the bvi interface the first in the vector and |
| 143 | * flooding walks the vector in reverse. |
| 144 | */ |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 145 | switch (sw_if->flood_class) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 146 | { |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 147 | case VNET_FLOOD_CLASS_TUNNEL_MASTER: |
| 148 | bd_config->tun_master_count++; |
| 149 | /* Fall through */ |
| 150 | default: |
| 151 | /* Fall through */ |
| 152 | case VNET_FLOOD_CLASS_NORMAL: |
| 153 | ix = (member->flags & L2_FLOOD_MEMBER_BVI) ? 0 : |
| 154 | vec_len (bd_config->members) - bd_config->tun_normal_count; |
| 155 | break; |
| 156 | case VNET_FLOOD_CLASS_TUNNEL_NORMAL: |
| 157 | ix = vec_len (bd_config->members); |
| 158 | bd_config->tun_normal_count++; |
| 159 | break; |
| 160 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 161 | |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 162 | vec_insert_elts (bd_config->members, member, 1, ix); |
| 163 | update_flood_count (bd_config); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | #define BD_REMOVE_ERROR_OK 0 |
| 167 | #define BD_REMOVE_ERROR_NOT_FOUND 1 |
| 168 | |
| 169 | u32 |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 170 | bd_remove_member (l2_bridge_domain_t * bd_config, u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 171 | { |
| 172 | u32 ix; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 173 | |
| 174 | /* Find and delete the member */ |
| 175 | vec_foreach_index (ix, bd_config->members) |
| 176 | { |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 177 | l2_flood_member_t *m = vec_elt_at_index (bd_config->members, ix); |
| 178 | if (m->sw_if_index == sw_if_index) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 179 | { |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 180 | vnet_sw_interface_t *sw_if = vnet_get_sw_interface |
| 181 | (vnet_get_main (), sw_if_index); |
| 182 | |
| 183 | if (sw_if->flood_class != VNET_FLOOD_CLASS_NORMAL) |
| 184 | { |
| 185 | if (sw_if->flood_class == VNET_FLOOD_CLASS_TUNNEL_MASTER) |
| 186 | bd_config->tun_master_count--; |
| 187 | else if (sw_if->flood_class == VNET_FLOOD_CLASS_TUNNEL_NORMAL) |
| 188 | bd_config->tun_normal_count--; |
| 189 | } |
Eyal Bari | 25b3667 | 2017-03-02 10:43:19 +0200 | [diff] [blame] | 190 | vec_delete (bd_config->members, 1, ix); |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 191 | update_flood_count (bd_config); |
| 192 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 193 | return BD_REMOVE_ERROR_OK; |
| 194 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | return BD_REMOVE_ERROR_NOT_FOUND; |
| 198 | } |
| 199 | |
| 200 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 201 | clib_error_t * |
| 202 | l2bd_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 203 | { |
| 204 | bd_main_t *bdm = &bd_main; |
| 205 | u32 bd_index; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 206 | bdm->bd_index_by_bd_id = hash_create (0, sizeof (uword)); |
| 207 | /* |
| 208 | * create a dummy bd with bd_id of 0 and bd_index of 0 with feature set |
| 209 | * to packet drop only. Thus, packets received from any L2 interface with |
| 210 | * uninitialized bd_index of 0 can be dropped safely. |
| 211 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 212 | bd_index = bd_find_or_add_bd_index (bdm, 0); |
| 213 | ASSERT (bd_index == 0); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 214 | l2input_main.bd_configs[0].feature_bitmap = L2INPUT_FEAT_DROP; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 215 | |
| 216 | bdm->vlib_main = vm; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | VLIB_INIT_FUNCTION (l2bd_init); |
| 221 | |
| 222 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 223 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 224 | Set the learn/forward/flood flags for the bridge domain. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 225 | Return 0 if ok, non-zero if for an error. |
| 226 | */ |
| 227 | u32 |
| 228 | bd_set_flags (vlib_main_t * vm, u32 bd_index, u32 flags, u32 enable) |
| 229 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 230 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 231 | l2_bridge_domain_t *bd_config; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 232 | u32 feature_bitmap = 0; |
| 233 | |
| 234 | vec_validate (l2input_main.bd_configs, bd_index); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 235 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 236 | |
| 237 | bd_validate (bd_config); |
| 238 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 239 | if (flags & L2_LEARN) |
| 240 | { |
| 241 | feature_bitmap |= L2INPUT_FEAT_LEARN; |
| 242 | } |
| 243 | if (flags & L2_FWD) |
| 244 | { |
| 245 | feature_bitmap |= L2INPUT_FEAT_FWD; |
| 246 | } |
| 247 | if (flags & L2_FLOOD) |
| 248 | { |
| 249 | feature_bitmap |= L2INPUT_FEAT_FLOOD; |
| 250 | } |
| 251 | if (flags & L2_UU_FLOOD) |
| 252 | { |
| 253 | feature_bitmap |= L2INPUT_FEAT_UU_FLOOD; |
| 254 | } |
| 255 | if (flags & L2_ARP_TERM) |
| 256 | { |
| 257 | feature_bitmap |= L2INPUT_FEAT_ARP_TERM; |
| 258 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 259 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 260 | if (enable) |
| 261 | { |
| 262 | bd_config->feature_bitmap |= feature_bitmap; |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | bd_config->feature_bitmap &= ~feature_bitmap; |
| 267 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 272 | /** |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 273 | Set the mac age for the bridge domain. |
| 274 | */ |
| 275 | void |
| 276 | bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age) |
| 277 | { |
| 278 | l2_bridge_domain_t *bd_config; |
| 279 | int enable = 0; |
| 280 | |
| 281 | vec_validate (l2input_main.bd_configs, bd_index); |
| 282 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
| 283 | bd_config->mac_age = age; |
| 284 | |
| 285 | /* check if there is at least one bd with mac aging enabled */ |
| 286 | vec_foreach (bd_config, l2input_main.bd_configs) |
Eyal Bari | fead670 | 2017-04-04 04:46:32 +0300 | [diff] [blame^] | 287 | enable |= bd_config->bd_id != ~0 && bd_config->mac_age != 0; |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 288 | |
| 289 | vlib_process_signal_event (vm, l2fib_mac_age_scanner_process_node.index, |
| 290 | enable ? L2_MAC_AGE_PROCESS_EVENT_START : |
| 291 | L2_MAC_AGE_PROCESS_EVENT_STOP, 0); |
| 292 | } |
| 293 | |
| 294 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 295 | Set bridge-domain learn enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 296 | The CLI format is: |
| 297 | set bridge-domain learn <bd_id> [disable] |
| 298 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 299 | static clib_error_t * |
| 300 | bd_learn (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 301 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 302 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 303 | bd_main_t *bdm = &bd_main; |
| 304 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 305 | u32 bd_index, bd_id; |
| 306 | u32 enable; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 307 | uword *p; |
| 308 | |
| 309 | if (!unformat (input, "%d", &bd_id)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 310 | { |
| 311 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 312 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 313 | goto done; |
| 314 | } |
| 315 | |
| 316 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 317 | |
| 318 | if (p == 0) |
| 319 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 320 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 321 | bd_index = p[0]; |
| 322 | |
| 323 | enable = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 324 | if (unformat (input, "disable")) |
| 325 | { |
| 326 | enable = 0; |
| 327 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 328 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 329 | /* set the bridge domain flag */ |
| 330 | if (bd_set_flags (vm, bd_index, L2_LEARN, enable)) |
| 331 | { |
| 332 | error = |
| 333 | clib_error_return (0, "bridge-domain id %d out of range", bd_index); |
| 334 | goto done; |
| 335 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 336 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 337 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 338 | return error; |
| 339 | } |
| 340 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 341 | /*? |
| 342 | * Layer 2 learning can be enabled and disabled on each |
| 343 | * interface and on each bridge-domain. Use this command to |
| 344 | * manage bridge-domains. It is enabled by default. |
| 345 | * |
| 346 | * @cliexpar |
| 347 | * Example of how to enable learning (where 200 is the bridge-domain-id): |
| 348 | * @cliexcmd{set bridge-domain learn 200} |
| 349 | * Example of how to disable learning (where 200 is the bridge-domain-id): |
| 350 | * @cliexcmd{set bridge-domain learn 200 disable} |
| 351 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 352 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 353 | VLIB_CLI_COMMAND (bd_learn_cli, static) = { |
| 354 | .path = "set bridge-domain learn", |
| 355 | .short_help = "set bridge-domain learn <bridge-domain-id> [disable]", |
| 356 | .function = bd_learn, |
| 357 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 358 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 359 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 360 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 361 | Set bridge-domain forward enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 362 | The CLI format is: |
| 363 | set bridge-domain forward <bd_index> [disable] |
| 364 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 365 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 366 | bd_fwd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 367 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 368 | bd_main_t *bdm = &bd_main; |
| 369 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 370 | u32 bd_index, bd_id; |
| 371 | u32 enable; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 372 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 373 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 374 | if (!unformat (input, "%d", &bd_id)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 375 | { |
| 376 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 377 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 378 | goto done; |
| 379 | } |
| 380 | |
| 381 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 382 | |
| 383 | if (p == 0) |
| 384 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 385 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 386 | bd_index = p[0]; |
| 387 | |
| 388 | enable = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 389 | if (unformat (input, "disable")) |
| 390 | { |
| 391 | enable = 0; |
| 392 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 393 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 394 | /* set the bridge domain flag */ |
| 395 | if (bd_set_flags (vm, bd_index, L2_FWD, enable)) |
| 396 | { |
| 397 | error = |
| 398 | clib_error_return (0, "bridge-domain id %d out of range", bd_index); |
| 399 | goto done; |
| 400 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 401 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 402 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 403 | return error; |
| 404 | } |
| 405 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 406 | |
| 407 | /*? |
| 408 | * Layer 2 unicast forwarding can be enabled and disabled on each |
| 409 | * interface and on each bridge-domain. Use this command to |
| 410 | * manage bridge-domains. It is enabled by default. |
| 411 | * |
| 412 | * @cliexpar |
| 413 | * Example of how to enable forwarding (where 200 is the bridge-domain-id): |
| 414 | * @cliexcmd{set bridge-domain forward 200} |
| 415 | * Example of how to disable forwarding (where 200 is the bridge-domain-id): |
| 416 | * @cliexcmd{set bridge-domain forward 200 disable} |
| 417 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 418 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 419 | VLIB_CLI_COMMAND (bd_fwd_cli, static) = { |
| 420 | .path = "set bridge-domain forward", |
| 421 | .short_help = "set bridge-domain forward <bridge-domain-id> [disable]", |
| 422 | .function = bd_fwd, |
| 423 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 424 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 425 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 426 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 427 | Set bridge-domain flood enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 428 | The CLI format is: |
| 429 | set bridge-domain flood <bd_index> [disable] |
| 430 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 431 | static clib_error_t * |
| 432 | bd_flood (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 433 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 434 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 435 | bd_main_t *bdm = &bd_main; |
| 436 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 437 | u32 bd_index, bd_id; |
| 438 | u32 enable; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 439 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 440 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 441 | if (!unformat (input, "%d", &bd_id)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 442 | { |
| 443 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 444 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 445 | goto done; |
| 446 | } |
| 447 | |
| 448 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 449 | |
| 450 | if (p == 0) |
| 451 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 452 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 453 | bd_index = p[0]; |
| 454 | |
| 455 | enable = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 456 | if (unformat (input, "disable")) |
| 457 | { |
| 458 | enable = 0; |
| 459 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 460 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 461 | /* set the bridge domain flag */ |
| 462 | if (bd_set_flags (vm, bd_index, L2_FLOOD, enable)) |
| 463 | { |
| 464 | error = |
| 465 | clib_error_return (0, "bridge-domain id %d out of range", bd_index); |
| 466 | goto done; |
| 467 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 468 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 469 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 470 | return error; |
| 471 | } |
| 472 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 473 | /*? |
| 474 | * Layer 2 flooding can be enabled and disabled on each |
| 475 | * interface and on each bridge-domain. Use this command to |
| 476 | * manage bridge-domains. It is enabled by default. |
| 477 | * |
| 478 | * @cliexpar |
| 479 | * Example of how to enable flooding (where 200 is the bridge-domain-id): |
| 480 | * @cliexcmd{set bridge-domain flood 200} |
| 481 | * Example of how to disable flooding (where 200 is the bridge-domain-id): |
| 482 | * @cliexcmd{set bridge-domain flood 200 disable} |
| 483 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 484 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 485 | VLIB_CLI_COMMAND (bd_flood_cli, static) = { |
| 486 | .path = "set bridge-domain flood", |
| 487 | .short_help = "set bridge-domain flood <bridge-domain-id> [disable]", |
| 488 | .function = bd_flood, |
| 489 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 490 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 491 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 492 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 493 | Set bridge-domain unkown-unicast flood enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 494 | The CLI format is: |
| 495 | set bridge-domain uu-flood <bd_index> [disable] |
| 496 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 497 | static clib_error_t * |
| 498 | bd_uu_flood (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 499 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 500 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 501 | bd_main_t *bdm = &bd_main; |
| 502 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 503 | u32 bd_index, bd_id; |
| 504 | u32 enable; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 505 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 506 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 507 | if (!unformat (input, "%d", &bd_id)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 508 | { |
| 509 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 510 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 511 | goto done; |
| 512 | } |
| 513 | |
| 514 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 515 | |
| 516 | if (p == 0) |
| 517 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 518 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 519 | bd_index = p[0]; |
| 520 | |
| 521 | enable = 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 522 | if (unformat (input, "disable")) |
| 523 | { |
| 524 | enable = 0; |
| 525 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 526 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 527 | /* set the bridge domain flag */ |
| 528 | if (bd_set_flags (vm, bd_index, L2_UU_FLOOD, enable)) |
| 529 | { |
| 530 | error = |
| 531 | clib_error_return (0, "bridge-domain id %d out of range", bd_index); |
| 532 | goto done; |
| 533 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 534 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 535 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 536 | return error; |
| 537 | } |
| 538 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 539 | /*? |
| 540 | * Layer 2 unknown-unicast flooding can be enabled and disabled on each |
| 541 | * bridge-domain. It is enabled by default. |
| 542 | * |
| 543 | * @cliexpar |
| 544 | * Example of how to enable unknown-unicast flooding (where 200 is the |
| 545 | * bridge-domain-id): |
| 546 | * @cliexcmd{set bridge-domain uu-flood 200} |
| 547 | * Example of how to disable unknown-unicast flooding (where 200 is the bridge-domain-id): |
| 548 | * @cliexcmd{set bridge-domain uu-flood 200 disable} |
| 549 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 550 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 551 | VLIB_CLI_COMMAND (bd_uu_flood_cli, static) = { |
| 552 | .path = "set bridge-domain uu-flood", |
| 553 | .short_help = "set bridge-domain uu-flood <bridge-domain-id> [disable]", |
| 554 | .function = bd_uu_flood, |
| 555 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 556 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 557 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 558 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 559 | Set bridge-domain arp term enable/disable. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 560 | The CLI format is: |
| 561 | set bridge-domain arp term <bridge-domain-id> [disable] |
| 562 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 563 | static clib_error_t * |
| 564 | bd_arp_term (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 565 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 566 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 567 | bd_main_t *bdm = &bd_main; |
| 568 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 569 | u32 bd_index, bd_id; |
| 570 | u32 enable; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 571 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 572 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 573 | if (!unformat (input, "%d", &bd_id)) |
| 574 | { |
| 575 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
| 576 | format_unformat_error, input); |
| 577 | goto done; |
| 578 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 579 | |
| 580 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 581 | if (p) |
| 582 | bd_index = *p; |
| 583 | else |
| 584 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 585 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 586 | enable = 1; |
| 587 | if (unformat (input, "disable")) |
| 588 | enable = 0; |
| 589 | |
| 590 | /* set the bridge domain flag */ |
| 591 | if (bd_set_flags (vm, bd_index, L2_ARP_TERM, enable)) |
| 592 | { |
| 593 | error = |
| 594 | clib_error_return (0, "bridge-domain id %d out of range", bd_index); |
| 595 | goto done; |
| 596 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 597 | |
| 598 | done: |
| 599 | return error; |
| 600 | } |
| 601 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 602 | static clib_error_t * |
| 603 | bd_mac_age (vlib_main_t * vm, |
| 604 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 605 | { |
| 606 | bd_main_t *bdm = &bd_main; |
| 607 | clib_error_t *error = 0; |
| 608 | u32 bd_index, bd_id; |
| 609 | u32 age; |
| 610 | uword *p; |
| 611 | |
| 612 | if (!unformat (input, "%d", &bd_id)) |
| 613 | { |
| 614 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
| 615 | format_unformat_error, input); |
| 616 | goto done; |
| 617 | } |
| 618 | |
| 619 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 620 | |
| 621 | if (p == 0) |
| 622 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
| 623 | |
| 624 | bd_index = p[0]; |
| 625 | |
| 626 | if (!unformat (input, "%u", &age)) |
| 627 | { |
| 628 | error = |
| 629 | clib_error_return (0, "expecting ageing time in minutes but got `%U'", |
| 630 | format_unformat_error, input); |
| 631 | goto done; |
| 632 | } |
| 633 | |
| 634 | /* set the bridge domain flag */ |
| 635 | if (age > 255) |
| 636 | { |
| 637 | error = |
| 638 | clib_error_return (0, "mac aging time cannot be bigger than 255"); |
| 639 | goto done; |
| 640 | } |
| 641 | bd_set_mac_age (vm, bd_index, (u8) age); |
| 642 | |
| 643 | done: |
| 644 | return error; |
| 645 | } |
| 646 | |
| 647 | /*? |
| 648 | * Layer 2 mac aging can be enabled and disabled on each |
| 649 | * bridge-domain. Use this command to set or disable mac aging |
| 650 | * on specific bridge-domains. It is disabled by default. |
| 651 | * |
| 652 | * @cliexpar |
| 653 | * Example of how to set mac aging (where 200 is the bridge-domain-id and |
| 654 | * 5 is aging time in minutes): |
| 655 | * @cliexcmd{set bridge-domain mac-age 200 5} |
| 656 | * Example of how to disable mac aging (where 200 is the bridge-domain-id): |
| 657 | * @cliexcmd{set bridge-domain flood 200 0} |
| 658 | ?*/ |
| 659 | /* *INDENT-OFF* */ |
| 660 | VLIB_CLI_COMMAND (bd_mac_age_cli, static) = { |
| 661 | .path = "set bridge-domain mac-age", |
| 662 | .short_help = "set bridge-domain mac-age <bridge-domain-id> <mins>", |
| 663 | .function = bd_mac_age, |
| 664 | }; |
| 665 | /* *INDENT-ON* */ |
| 666 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 667 | /*? |
| 668 | * Modify whether or not an existing bridge-domain should terminate and respond |
| 669 | * to ARP Requests. ARP Termination is disabled by default. |
| 670 | * |
| 671 | * @cliexpar |
| 672 | * Example of how to enable ARP termination (where 200 is the bridge-domain-id): |
| 673 | * @cliexcmd{set bridge-domain arp term 200} |
| 674 | * Example of how to disable ARP termination (where 200 is the bridge-domain-id): |
| 675 | * @cliexcmd{set bridge-domain arp term 200 disable} |
| 676 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 677 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 678 | VLIB_CLI_COMMAND (bd_arp_term_cli, static) = { |
| 679 | .path = "set bridge-domain arp term", |
| 680 | .short_help = "set bridge-domain arp term <bridge-domain-id> [disable]", |
| 681 | .function = bd_arp_term, |
| 682 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 683 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 684 | |
| 685 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 686 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 687 | * Add/delete IP address to MAC address mapping. |
| 688 | * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 689 | * The clib hash implementation stores uword entries in the hash table. |
| 690 | * The hash table mac_by_ip4 is keyed via IP4 address and store the |
| 691 | * 6-byte MAC address directly in the hash table entry uword. |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 692 | * |
| 693 | * @warning This only works for 64-bit processor with 8-byte uword; |
| 694 | * which means this code *WILL NOT WORK* for a 32-bit prcessor with |
| 695 | * 4-byte uword. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 696 | */ |
| 697 | u32 |
| 698 | bd_add_del_ip_mac (u32 bd_index, |
| 699 | u8 * ip_addr, u8 * mac_addr, u8 is_ip6, u8 is_add) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 700 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 701 | l2input_main_t *l2im = &l2input_main; |
| 702 | l2_bridge_domain_t *bd_cfg = l2input_bd_config_from_index (l2im, bd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 703 | u64 new_mac = *(u64 *) mac_addr; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 704 | u64 *old_mac; |
| 705 | u16 *mac16 = (u16 *) & new_mac; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 706 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 707 | ASSERT (sizeof (uword) == sizeof (u64)); /* make sure uword is 8 bytes */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 708 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 709 | mac16[3] = 0; /* Clear last 2 unsed bytes of the 8-byte MAC address */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 710 | if (is_ip6) |
| 711 | { |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 712 | ip6_address_t *ip6_addr_key; |
| 713 | hash_pair_t *hp; |
| 714 | old_mac = (u64 *) hash_get_mem (bd_cfg->mac_by_ip6, ip_addr); |
| 715 | if (is_add) |
| 716 | { |
| 717 | if (old_mac == 0) |
| 718 | { /* new entry - allocate and craete ip6 address key */ |
| 719 | ip6_addr_key = clib_mem_alloc (sizeof (ip6_address_t)); |
| 720 | clib_memcpy (ip6_addr_key, ip_addr, sizeof (ip6_address_t)); |
| 721 | } |
| 722 | else if (*old_mac == new_mac) |
| 723 | { /* same mac entry already exist for ip6 address */ |
| 724 | return 0; |
| 725 | } |
| 726 | else |
| 727 | { /* updat mac for ip6 address */ |
| 728 | hp = hash_get_pair (bd_cfg->mac_by_ip6, ip_addr); |
| 729 | ip6_addr_key = (ip6_address_t *) hp->key; |
| 730 | } |
| 731 | hash_set_mem (bd_cfg->mac_by_ip6, ip6_addr_key, new_mac); |
| 732 | } |
| 733 | else |
| 734 | { |
| 735 | if (old_mac && (*old_mac == new_mac)) |
| 736 | { |
| 737 | hp = hash_get_pair (bd_cfg->mac_by_ip6, ip_addr); |
| 738 | ip6_addr_key = (ip6_address_t *) hp->key; |
| 739 | hash_unset_mem (bd_cfg->mac_by_ip6, ip_addr); |
| 740 | clib_mem_free (ip6_addr_key); |
| 741 | } |
| 742 | else |
| 743 | return 1; |
| 744 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 745 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 746 | else |
| 747 | { |
| 748 | ip4_address_t ip4_addr = *(ip4_address_t *) ip_addr; |
| 749 | old_mac = (u64 *) hash_get (bd_cfg->mac_by_ip4, ip4_addr.as_u32); |
| 750 | if (is_add) |
| 751 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 752 | if (old_mac && (*old_mac == new_mac)) |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 753 | return 0; /* mac entry already exist */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 754 | hash_set (bd_cfg->mac_by_ip4, ip4_addr.as_u32, new_mac); |
| 755 | } |
| 756 | else |
| 757 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 758 | if (old_mac && (*old_mac == new_mac)) |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 759 | hash_unset (bd_cfg->mac_by_ip4, ip4_addr.as_u32); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 760 | else |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 761 | return 1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 762 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 763 | } |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 764 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 767 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 768 | Set bridge-domain arp entry add/delete. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 769 | The CLI format is: |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 770 | set bridge-domain arp entry <bridge-domain-id> <ip-addr> <mac-addr> [del] |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 771 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 772 | static clib_error_t * |
| 773 | bd_arp_entry (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 774 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 775 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 776 | bd_main_t *bdm = &bd_main; |
| 777 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 778 | u32 bd_index, bd_id; |
| 779 | u8 is_add = 1; |
| 780 | u8 is_ip6 = 0; |
| 781 | u8 ip_addr[16]; |
| 782 | u8 mac_addr[6]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 783 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 784 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 785 | if (!unformat (input, "%d", &bd_id)) |
| 786 | { |
| 787 | error = clib_error_return (0, "expecting bridge-domain id but got `%U'", |
| 788 | format_unformat_error, input); |
| 789 | goto done; |
| 790 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 791 | |
| 792 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 793 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 794 | if (p) |
| 795 | bd_index = *p; |
| 796 | else |
| 797 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 798 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 799 | if (unformat (input, "%U", unformat_ip4_address, ip_addr)) |
| 800 | { |
| 801 | is_ip6 = 0; |
| 802 | } |
| 803 | else if (unformat (input, "%U", unformat_ip6_address, ip_addr)) |
| 804 | { |
| 805 | is_ip6 = 1; |
| 806 | } |
| 807 | else |
| 808 | { |
| 809 | error = clib_error_return (0, "expecting IP address but got `%U'", |
| 810 | format_unformat_error, input); |
| 811 | goto done; |
| 812 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 813 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 814 | if (!unformat (input, "%U", unformat_ethernet_address, mac_addr)) |
| 815 | { |
| 816 | error = clib_error_return (0, "expecting MAC address but got `%U'", |
| 817 | format_unformat_error, input); |
| 818 | goto done; |
| 819 | } |
| 820 | |
| 821 | if (unformat (input, "del")) |
| 822 | { |
| 823 | is_add = 0; |
| 824 | } |
| 825 | |
| 826 | /* set the bridge domain flagAdd IP-MAC entry into bridge domain */ |
| 827 | if (bd_add_del_ip_mac (bd_index, ip_addr, mac_addr, is_ip6, is_add)) |
| 828 | { |
| 829 | error = clib_error_return (0, "MAC %s for IP %U and MAC %U failed", |
| 830 | is_add ? "add" : "del", |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 831 | is_ip6 ? |
| 832 | format_ip4_address : format_ip6_address, |
| 833 | ip_addr, format_ethernet_address, mac_addr); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 834 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 835 | |
| 836 | done: |
| 837 | return error; |
| 838 | } |
| 839 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 840 | /*? |
| 841 | * Add an ARP entry to an existing bridge-domain. |
| 842 | * |
| 843 | * @cliexpar |
| 844 | * Example of how to add an ARP entry (where 200 is the bridge-domain-id): |
| 845 | * @cliexcmd{set bridge-domain arp entry 200 192.168.72.45 52:54:00:3b:83:1a} |
| 846 | * Example of how to delete an ARP entry (where 200 is the bridge-domain-id): |
| 847 | * @cliexcmd{set bridge-domain arp entry 200 192.168.72.45 52:54:00:3b:83:1a del} |
| 848 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 849 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 850 | VLIB_CLI_COMMAND (bd_arp_entry_cli, static) = { |
| 851 | .path = "set bridge-domain arp entry", |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 852 | .short_help = "set bridge-domain arp entry <bridge-domain-id> <ip-addr> <mac-addr> [del]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 853 | .function = bd_arp_entry, |
| 854 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 855 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 856 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 857 | u8 * |
| 858 | format_vtr (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 859 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 860 | u32 vtr_op = va_arg (*args, u32); |
| 861 | u32 dot1q = va_arg (*args, u32); |
| 862 | u32 tag1 = va_arg (*args, u32); |
| 863 | u32 tag2 = va_arg (*args, u32); |
| 864 | switch (vtr_op) |
| 865 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 866 | case L2_VTR_DISABLED: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 867 | return format (s, "none"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 868 | case L2_VTR_PUSH_1: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 869 | return format (s, "push-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 870 | case L2_VTR_PUSH_2: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 871 | return format (s, "push-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1, |
| 872 | tag2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 873 | case L2_VTR_POP_1: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 874 | return format (s, "pop-1"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 875 | case L2_VTR_POP_2: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 876 | return format (s, "pop-2"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 877 | case L2_VTR_TRANSLATE_1_1: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 878 | return format (s, "trans-1-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 879 | case L2_VTR_TRANSLATE_1_2: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 880 | return format (s, "trans-1-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", |
| 881 | tag1, tag2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 882 | case L2_VTR_TRANSLATE_2_1: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 883 | return format (s, "trans-2-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 884 | case L2_VTR_TRANSLATE_2_2: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 885 | return format (s, "trans-2-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", |
| 886 | tag1, tag2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 887 | default: |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 888 | return format (s, "none"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 892 | /** |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 893 | Show bridge-domain state. |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 894 | The CLI format is: |
| 895 | show bridge-domain [<bd_index>] |
| 896 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 897 | static clib_error_t * |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 898 | bd_show (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 899 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 900 | vnet_main_t *vnm = vnet_get_main (); |
| 901 | bd_main_t *bdm = &bd_main; |
| 902 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 903 | u32 bd_index = ~0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 904 | l2_bridge_domain_t *bd_config; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 905 | u32 start, end; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 906 | u32 detail = 0; |
| 907 | u32 intf = 0; |
| 908 | u32 arp = 0; |
| 909 | u32 bd_id = ~0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 910 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 911 | |
| 912 | start = 0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 913 | end = vec_len (l2input_main.bd_configs); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 914 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 915 | if (unformat (input, "%d", &bd_id)) |
| 916 | { |
| 917 | if (unformat (input, "detail")) |
| 918 | detail = 1; |
| 919 | else if (unformat (input, "det")) |
| 920 | detail = 1; |
| 921 | if (unformat (input, "int")) |
| 922 | intf = 1; |
| 923 | if (unformat (input, "arp")) |
| 924 | arp = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 925 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 926 | p = hash_get (bdm->bd_index_by_bd_id, bd_id); |
| 927 | if (p) |
| 928 | bd_index = *p; |
| 929 | else |
| 930 | return clib_error_return (0, "No such bridge domain %d", bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 931 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 932 | vec_validate (l2input_main.bd_configs, bd_index); |
| 933 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
| 934 | if (bd_is_valid (bd_config)) |
| 935 | { |
| 936 | start = bd_index; |
| 937 | end = start + 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 938 | } |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 939 | else |
| 940 | { |
| 941 | vlib_cli_output (vm, "bridge-domain %d not in use", bd_id); |
| 942 | goto done; |
| 943 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 944 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 945 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 946 | /* Show all bridge-domains that have been initialized */ |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 947 | u32 printed = 0; |
| 948 | u8 *as = 0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 949 | for (bd_index = start; bd_index < end; bd_index++) |
| 950 | { |
| 951 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
| 952 | if (bd_is_valid (bd_config)) |
| 953 | { |
| 954 | if (!printed) |
| 955 | { |
| 956 | printed = 1; |
| 957 | vlib_cli_output (vm, |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 958 | "%=5s %=7s %=4s %=9s %=9s %=9s %=9s %=9s %=9s %=9s", |
| 959 | "ID", "Index", "BSN", "Age(min)", "Learning", |
| 960 | "U-Forwrd", "UU-Flood", "Flooding", "ARP-Term", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 961 | "BVI-Intf"); |
| 962 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 963 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 964 | if (bd_config->mac_age) |
| 965 | as = format (as, "%d", bd_config->mac_age); |
| 966 | else |
| 967 | as = format (as, "off"); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 968 | vlib_cli_output (vm, |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 969 | "%=5d %=7d %=4d %=9v %=9s %=9s %=9s %=9s %=9s %=9U", |
| 970 | bd_config->bd_id, bd_index, bd_config->seq_num, as, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 971 | bd_config->feature_bitmap & L2INPUT_FEAT_LEARN ? |
| 972 | "on" : "off", |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 973 | bd_config->feature_bitmap & L2INPUT_FEAT_FWD ? |
| 974 | "on" : "off", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 975 | bd_config->feature_bitmap & L2INPUT_FEAT_UU_FLOOD ? |
| 976 | "on" : "off", |
| 977 | bd_config->feature_bitmap & L2INPUT_FEAT_FLOOD ? |
| 978 | "on" : "off", |
| 979 | bd_config->feature_bitmap & L2INPUT_FEAT_ARP_TERM ? |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 980 | "on" : "off", |
| 981 | format_vnet_sw_if_index_name_with_NA, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 982 | vnm, bd_config->bvi_sw_if_index); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 983 | vec_reset_length (as); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 984 | |
| 985 | if (detail || intf) |
| 986 | { |
| 987 | /* Show all member interfaces */ |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 988 | int i; |
| 989 | vec_foreach_index (i, bd_config->members) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 990 | { |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 991 | l2_flood_member_t *member = |
| 992 | vec_elt_at_index (bd_config->members, i); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 993 | l2_input_config_t *int_config = |
| 994 | l2input_intf_config (member->sw_if_index); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 995 | u32 vtr_opr, dot1q, tag1, tag2; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 996 | if (i == 0) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 997 | { |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 998 | vlib_cli_output (vm, "\n%=30s%=7s%=5s%=5s%=5s%=9s%=30s", |
| 999 | "Interface", "If-idx", "ISN", "SHG", |
| 1000 | "BVI", "TxFlood", "VLAN-Tag-Rewrite"); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1001 | } |
| 1002 | l2vtr_get (vm, vnm, member->sw_if_index, &vtr_opr, &dot1q, |
| 1003 | &tag1, &tag2); |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1004 | vlib_cli_output (vm, "%=30U%=7d%=5d%=5d%=5s%=9s%=30U", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1005 | format_vnet_sw_if_index_name, vnm, |
| 1006 | member->sw_if_index, member->sw_if_index, |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1007 | int_config->seq_num, member->shg, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1008 | member->flags & L2_FLOOD_MEMBER_BVI ? "*" : |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 1009 | "-", i < bd_config->flood_count ? "*" : "-", |
| 1010 | format_vtr, vtr_opr, dot1q, tag1, tag2); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | if ((detail || arp) && |
| 1015 | (bd_config->feature_bitmap & L2INPUT_FEAT_ARP_TERM)) |
| 1016 | { |
| 1017 | u32 ip4_addr; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 1018 | ip6_address_t *ip6_addr; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1019 | u64 mac_addr; |
| 1020 | vlib_cli_output (vm, |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 1021 | "\n IP4/IP6 to MAC table for ARP Termination"); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1022 | |
| 1023 | /* *INDENT-OFF* */ |
| 1024 | hash_foreach (ip4_addr, mac_addr, bd_config->mac_by_ip4, |
| 1025 | ({ |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 1026 | vlib_cli_output (vm, "%=40U => %=20U", |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1027 | format_ip4_address, &ip4_addr, |
| 1028 | format_ethernet_address, &mac_addr); |
| 1029 | })); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 1030 | |
| 1031 | hash_foreach_mem (ip6_addr, mac_addr, bd_config->mac_by_ip6, |
| 1032 | ({ |
| 1033 | vlib_cli_output (vm, "%=40U => %=20U", |
| 1034 | format_ip6_address, ip6_addr, |
| 1035 | format_ethernet_address, &mac_addr); |
| 1036 | })); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1037 | /* *INDENT-ON* */ |
| 1038 | } |
| 1039 | } |
| 1040 | } |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 1041 | vec_free (as); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1042 | |
| 1043 | if (!printed) |
| 1044 | { |
| 1045 | vlib_cli_output (vm, "no bridge-domains in use"); |
| 1046 | } |
| 1047 | |
| 1048 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1049 | return error; |
| 1050 | } |
| 1051 | |
Billy McFall | 22aa3e9 | 2016-09-09 08:46:40 -0400 | [diff] [blame] | 1052 | /*? |
| 1053 | * Show a summary of all the bridge-domain instances or detailed view of a |
| 1054 | * single bridge-domain. Bridge-domains are created by adding an interface |
| 1055 | * to a bridge using the '<em>set interface l2 bridge</em>' command. |
| 1056 | * |
| 1057 | * @cliexpar |
| 1058 | * @parblock |
| 1059 | * Example of displaying all bridge-domains: |
| 1060 | * @cliexstart{show bridge-domain} |
| 1061 | * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf |
| 1062 | * 0 0 off off off off off local0 |
| 1063 | * 200 1 on on on on off N/A |
| 1064 | * @cliexend |
| 1065 | * |
| 1066 | * Example of displaying details of a single bridge-domains: |
| 1067 | * @cliexstart{show bridge-domain 200 detail} |
| 1068 | * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf |
| 1069 | * 200 1 on on on on off N/A |
| 1070 | * |
| 1071 | * Interface Index SHG BVI VLAN-Tag-Rewrite |
| 1072 | * GigabitEthernet0/8/0.200 3 0 - none |
| 1073 | * GigabitEthernet0/9/0.200 4 0 - none |
| 1074 | * @cliexend |
| 1075 | * @endparblock |
| 1076 | ?*/ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1077 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1078 | VLIB_CLI_COMMAND (bd_show_cli, static) = { |
| 1079 | .path = "show bridge-domain", |
| 1080 | .short_help = "show bridge-domain [bridge-domain-id [detail|int|arp]]", |
| 1081 | .function = bd_show, |
| 1082 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1083 | /* *INDENT-ON* */ |
| 1084 | |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 1085 | int |
| 1086 | bd_add_del (l2_bridge_domain_add_del_args_t * a) |
| 1087 | { |
| 1088 | bd_main_t *bdm = &bd_main; |
| 1089 | vlib_main_t *vm = bdm->vlib_main; |
| 1090 | u32 enable_flags = 0, disable_flags = 0; |
| 1091 | u32 bd_index = ~0; |
| 1092 | int rv = 0; |
| 1093 | |
| 1094 | if (a->is_add) |
| 1095 | { |
| 1096 | bd_index = bd_find_or_add_bd_index (bdm, a->bd_id); |
| 1097 | if (bd_index == ~0) |
| 1098 | return bd_index; |
| 1099 | |
| 1100 | if (a->flood) |
| 1101 | enable_flags |= L2_FLOOD; |
| 1102 | else |
| 1103 | disable_flags |= L2_FLOOD; |
| 1104 | |
| 1105 | if (a->uu_flood) |
| 1106 | enable_flags |= L2_UU_FLOOD; |
| 1107 | else |
| 1108 | disable_flags |= L2_UU_FLOOD; |
| 1109 | |
| 1110 | if (a->forward) |
| 1111 | enable_flags |= L2_FWD; |
| 1112 | else |
| 1113 | disable_flags |= L2_FWD; |
| 1114 | |
| 1115 | if (a->learn) |
| 1116 | enable_flags |= L2_LEARN; |
| 1117 | else |
| 1118 | disable_flags |= L2_LEARN; |
| 1119 | |
| 1120 | if (a->arp_term) |
| 1121 | enable_flags |= L2_ARP_TERM; |
| 1122 | else |
| 1123 | disable_flags |= L2_ARP_TERM; |
| 1124 | |
| 1125 | if (enable_flags) |
| 1126 | bd_set_flags (vm, bd_index, enable_flags, 1 /* enable */ ); |
| 1127 | |
| 1128 | if (disable_flags) |
| 1129 | bd_set_flags (vm, bd_index, disable_flags, 0 /* disable */ ); |
| 1130 | |
| 1131 | bd_set_mac_age (vm, bd_index, a->mac_age); |
| 1132 | } |
| 1133 | else |
| 1134 | rv = bd_delete_bd_index (bdm, a->bd_id); |
| 1135 | |
| 1136 | return rv; |
| 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | Create or delete bridge-domain. |
| 1141 | The CLI format is: |
| 1142 | create bridge-domain <bd_index> [learn <0|1>] [forward <0|1>] [uu-flood <0|1>] |
| 1143 | [flood <0|1>] [arp-term <0|1>] [mac-age <nn>] [del] |
| 1144 | */ |
| 1145 | |
| 1146 | static clib_error_t * |
| 1147 | bd_add_del_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1148 | vlib_cli_command_t * cmd) |
| 1149 | { |
| 1150 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1151 | clib_error_t *error = 0; |
| 1152 | u8 is_add = 1; |
| 1153 | u32 bd_id = ~0; |
| 1154 | u32 flood = 1, forward = 1, learn = 1, uu_flood = 0, arp_term = 0; |
| 1155 | u32 mac_age = 0; |
| 1156 | l2_bridge_domain_add_del_args_t _a, *a = &_a; |
| 1157 | int rv; |
| 1158 | |
| 1159 | /* Get a line of input. */ |
| 1160 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1161 | return 0; |
| 1162 | |
| 1163 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1164 | { |
| 1165 | if (unformat (line_input, "%d", &bd_id)) |
| 1166 | ; |
| 1167 | else if (unformat (line_input, "flood %d", &flood)) |
| 1168 | ; |
| 1169 | else if (unformat (line_input, "uu-flood %d", &uu_flood)) |
| 1170 | ; |
| 1171 | else if (unformat (line_input, "forward %d", &forward)) |
| 1172 | ; |
| 1173 | else if (unformat (line_input, "arp-term %d", &arp_term)) |
| 1174 | ; |
| 1175 | else if (unformat (line_input, "mac-age %d", &mac_age)) |
| 1176 | ; |
| 1177 | else if (unformat (line_input, "del")) |
| 1178 | { |
| 1179 | is_add = 0; |
| 1180 | flood = uu_flood = forward = learn = 0; |
| 1181 | } |
| 1182 | else |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | if (bd_id == ~0) |
| 1187 | { |
| 1188 | error = clib_error_return (0, "bridge-domain-id not specified"); |
| 1189 | goto done; |
| 1190 | } |
| 1191 | |
| 1192 | if (mac_age > 255) |
| 1193 | { |
| 1194 | error = clib_error_return (0, "mac age must be less than 256"); |
| 1195 | goto done; |
| 1196 | } |
| 1197 | |
| 1198 | memset (a, 0, sizeof (*a)); |
| 1199 | a->is_add = is_add; |
| 1200 | a->bd_id = bd_id; |
| 1201 | a->flood = (u8) flood; |
| 1202 | a->uu_flood = (u8) uu_flood; |
| 1203 | a->forward = (u8) forward; |
| 1204 | a->learn = (u8) learn; |
| 1205 | a->arp_term = (u8) arp_term; |
| 1206 | a->mac_age = (u8) mac_age; |
| 1207 | |
| 1208 | rv = bd_add_del (a); |
| 1209 | |
| 1210 | switch (rv) |
| 1211 | { |
| 1212 | case 0: |
| 1213 | if (is_add) |
| 1214 | vlib_cli_output (vm, "bridge-domain %d", bd_id); |
| 1215 | break; |
| 1216 | case VNET_API_ERROR_NO_SUCH_ENTRY: |
| 1217 | error = clib_error_return (0, "bridge domain id does not exist"); |
| 1218 | goto done; |
| 1219 | default: |
| 1220 | error = clib_error_return (0, "bd_add_del returned %d", rv); |
| 1221 | goto done; |
| 1222 | } |
| 1223 | |
| 1224 | done: |
| 1225 | unformat_free (line_input); |
| 1226 | |
| 1227 | return error; |
| 1228 | } |
| 1229 | |
| 1230 | |
| 1231 | /*? |
| 1232 | * Create/Delete bridge-domain instance |
| 1233 | * |
| 1234 | * @cliexpar |
| 1235 | * @parblock |
| 1236 | * Example of creating bridge-domain 1: |
| 1237 | * @cliexstart{create bridge-domain 1} |
| 1238 | * bridge-domain 1 |
| 1239 | * @cliexend |
| 1240 | * |
| 1241 | * Example of creating bridge-domain 2 with enabling arp-term, mac-age 60: |
| 1242 | * @cliexstart{create bridge-domain 2 arp-term 1 mac-age 60} |
| 1243 | * bridge-domain 2 |
| 1244 | * |
| 1245 | * vpp# show bridge-domain |
| 1246 | * ID Index BSN Age(min) Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf |
| 1247 | * 0 0 0 off off off off off off local0 |
| 1248 | * 1 1 0 off on on off on off N/A |
| 1249 | * 2 2 0 60 on on off on on N/A |
| 1250 | * |
| 1251 | * @cliexend |
| 1252 | * |
| 1253 | * Example of delete bridge-domain 1: |
| 1254 | * @cliexstart{create bridge-domain 1 del} |
| 1255 | * @cliexend |
| 1256 | * @endparblock |
| 1257 | ?*/ |
| 1258 | |
| 1259 | /* *INDENT-OFF* */ |
| 1260 | VLIB_CLI_COMMAND (bd_create_cli, static) = { |
| 1261 | .path = "create bridge-domain", |
| 1262 | .short_help = "create bridge-domain <bridge-domain-id>" |
| 1263 | " [learn <0|1>] [forward <0|1>] [uu-flood <0|1>] [flood <0|1>] [arp-term <0|1>]" |
| 1264 | " [mac-age <nn>] [del]", |
| 1265 | .function = bd_add_del_command_fn, |
| 1266 | }; |
| 1267 | /* *INDENT-ON* */ |
| 1268 | |
| 1269 | |
| 1270 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 1271 | /* |
| 1272 | * fd.io coding-style-patch-verification: ON |
| 1273 | * |
| 1274 | * Local Variables: |
| 1275 | * eval: (c-set-style "gnu") |
| 1276 | * End: |
| 1277 | */ |