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