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