Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * l2_bd.h : 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 | #ifndef included_l2bd_h |
| 19 | #define included_l2bd_h |
| 20 | |
| 21 | #include <vlib/vlib.h> |
| 22 | #include <vnet/vnet.h> |
| 23 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 24 | typedef struct |
| 25 | { |
| 26 | /* hash bd_id -> bd_index */ |
| 27 | uword *bd_index_by_bd_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 29 | /* Busy bd_index bitmap */ |
| 30 | uword *bd_index_bitmap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 32 | /* convenience */ |
| 33 | vlib_main_t *vlib_main; |
| 34 | vnet_main_t *vnet_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 35 | } bd_main_t; |
| 36 | |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 37 | extern bd_main_t bd_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 38 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 39 | /* Bridge domain member */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 40 | |
| 41 | #define L2_FLOOD_MEMBER_NORMAL 0 |
| 42 | #define L2_FLOOD_MEMBER_BVI 1 |
| 43 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 44 | typedef struct |
| 45 | { |
| 46 | u32 sw_if_index; /* the output L2 interface */ |
| 47 | u8 flags; /* 0=normal, 1=bvi */ |
| 48 | u8 shg; /* split horizon group number */ |
| 49 | u16 spare; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | } l2_flood_member_t; |
| 51 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 52 | /* Per-bridge domain configuration */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 53 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 54 | typedef struct |
| 55 | { |
| 56 | u32 feature_bitmap; |
| 57 | /* |
| 58 | * Contains bit enables for flooding, learning, and forwarding. |
| 59 | * All other feature bits should always be set. |
| 60 | * |
| 61 | * identity of the bridge-domain's BVI interface |
| 62 | * set to ~0 if there is no BVI |
| 63 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | u32 bvi_sw_if_index; |
| 65 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 66 | /* bridge domain id, not to be confused with bd_index */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | u32 bd_id; |
| 68 | |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 69 | /* Vector of member ports */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 70 | l2_flood_member_t *members; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 72 | /* First flood_count member ports are flooded */ |
| 73 | u32 flood_count; |
| 74 | |
| 75 | /* Tunnel Master (Multicast vxlan) are always flooded */ |
| 76 | u32 tun_master_count; |
| 77 | |
| 78 | /* Tunnels (Unicast vxlan) are flooded if there are no masters */ |
| 79 | u32 tun_normal_count; |
| 80 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 81 | /* hash ip4/ip6 -> mac for arp/nd termination */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | uword *mac_by_ip4; |
| 83 | uword *mac_by_ip6; |
| 84 | |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 85 | /* mac aging */ |
| 86 | u8 mac_age; |
| 87 | |
John Lo | da1f2c7 | 2017-03-24 20:11:15 -0400 | [diff] [blame] | 88 | /* sequence number for bridge domain based flush of MACs */ |
| 89 | u8 seq_num; |
| 90 | |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame^] | 91 | /* Bridge domain tag (C string NULL terminated) */ |
| 92 | u8 *bd_tag; |
| 93 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | } l2_bridge_domain_t; |
| 95 | |
John Lo | 9793477 | 2017-05-18 22:26:47 -0400 | [diff] [blame] | 96 | /* Limit Bridge Domain ID to 24 bits to match 24-bit VNI range */ |
| 97 | #define L2_BD_ID_MAX ((1<<24)-1) |
| 98 | |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 99 | typedef struct |
| 100 | { |
| 101 | u32 bd_id; |
| 102 | u8 flood; |
| 103 | u8 uu_flood; |
| 104 | u8 forward; |
| 105 | u8 learn; |
| 106 | u8 arp_term; |
| 107 | u8 mac_age; |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame^] | 108 | u8 *bd_tag; |
Choonho Son | 0548079 | 2017-03-29 20:07:45 +0900 | [diff] [blame] | 109 | u8 is_add; |
| 110 | } l2_bridge_domain_add_del_args_t; |
| 111 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 112 | /* Return 1 if bridge domain has been initialized */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | always_inline u32 |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 114 | bd_is_valid (l2_bridge_domain_t * bd_config) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 115 | { |
| 116 | return (bd_config->feature_bitmap != 0); |
| 117 | } |
| 118 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 119 | /* Init bridge domain if not done already */ |
| 120 | void bd_validate (l2_bridge_domain_t * bd_config); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | |
| 122 | |
| 123 | void |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 124 | 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] | 125 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 126 | u32 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] | 127 | |
| 128 | |
| 129 | #define L2_LEARN (1<<0) |
| 130 | #define L2_FWD (1<<1) |
| 131 | #define L2_FLOOD (1<<2) |
| 132 | #define L2_UU_FLOOD (1<<3) |
| 133 | #define L2_ARP_TERM (1<<4) |
| 134 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 135 | u32 bd_set_flags (vlib_main_t * vm, u32 bd_index, u32 flags, u32 enable); |
Damjan Marion | d171d48 | 2016-12-05 14:16:38 +0100 | [diff] [blame] | 136 | void bd_set_mac_age (vlib_main_t * vm, u32 bd_index, u8 age); |
Jerome Tollet | 4830414 | 2017-09-05 12:13:22 +0100 | [diff] [blame^] | 137 | void bd_set_bd_tag (vlib_main_t * vm, u32 bd_index, u8 * bd_tag); |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 138 | int bd_add_del (l2_bridge_domain_add_del_args_t * args); |
| 139 | |
| 140 | /** |
| 141 | * \brief Get a bridge domain. |
| 142 | * |
| 143 | * Get a bridge domain with the given bridge domain ID. |
| 144 | * |
| 145 | * \param bdm bd_main pointer. |
| 146 | * \param bd_id The bridge domain ID |
| 147 | * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector. |
| 148 | */ |
| 149 | u32 bd_find_index (bd_main_t * bdm, u32 bd_id); |
| 150 | |
| 151 | /** |
| 152 | * \brief Create a bridge domain. |
| 153 | * |
| 154 | * Create a bridge domain with the given bridge domain ID |
| 155 | * |
| 156 | * \param bdm bd_main pointer. |
| 157 | * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector. |
| 158 | */ |
| 159 | u32 bd_add_bd_index (bd_main_t * bdm, u32 bd_id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 160 | |
Pierre Pfister | 530bd8e | 2016-05-10 17:11:22 +0100 | [diff] [blame] | 161 | /** |
| 162 | * \brief Get or create a bridge domain. |
| 163 | * |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 164 | * Get a bridge domain with the given bridge domain ID, if one exists, otherwise |
| 165 | * create one with the given ID, or the first unused ID if the given ID is ~0.. |
Pierre Pfister | 530bd8e | 2016-05-10 17:11:22 +0100 | [diff] [blame] | 166 | * |
| 167 | * \param bdm bd_main pointer. |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 168 | * \param bd_id The bridge domain ID |
Pierre Pfister | 530bd8e | 2016-05-10 17:11:22 +0100 | [diff] [blame] | 169 | * \return The bridge domain index in \c l2input_main->l2_bridge_domain_t vector. |
| 170 | */ |
Eyal Bari | b1352ed | 2017-04-07 23:14:17 +0300 | [diff] [blame] | 171 | static inline u32 |
| 172 | bd_find_or_add_bd_index (bd_main_t * bdm, u32 bd_id) |
| 173 | { |
| 174 | u32 bd_index = bd_find_index (bdm, bd_id); |
| 175 | if (bd_index == ~0) |
| 176 | return bd_add_bd_index (bdm, bd_id); |
| 177 | return bd_index; |
| 178 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 180 | u32 bd_add_del_ip_mac (u32 bd_index, |
| 181 | u8 * ip_addr, u8 * mac_addr, u8 is_ip6, u8 is_add); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 182 | |
| 183 | #endif |
| 184 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 185 | /* |
| 186 | * fd.io coding-style-patch-verification: ON |
| 187 | * |
| 188 | * Local Variables: |
| 189 | * eval: (c-set-style "gnu") |
| 190 | * End: |
| 191 | */ |