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