Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 16 | #include <vnet/fib/fib_test.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 17 | #include <vnet/fib/ip6_fib.h> |
| 18 | #include <vnet/fib/ip4_fib.h> |
| 19 | #include <vnet/fib/mpls_fib.h> |
| 20 | #include <vnet/adj/adj.h> |
| 21 | #include <vnet/dpo/load_balance.h> |
| 22 | #include <vnet/dpo/load_balance_map.h> |
| 23 | #include <vnet/dpo/mpls_label_dpo.h> |
| 24 | #include <vnet/dpo/lookup_dpo.h> |
| 25 | #include <vnet/dpo/drop_dpo.h> |
| 26 | #include <vnet/dpo/receive_dpo.h> |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 27 | #include <vnet/dpo/ip_null_dpo.h> |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 28 | #include <vnet/bfd/bfd_main.h> |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 29 | #include <vnet/dpo/interface_rx_dpo.h> |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 30 | #include <vnet/dpo/replicate_dpo.h> |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 31 | #include <vnet/dpo/dvr_dpo.h> |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 32 | #include <vnet/dpo/mpls_disposition.h> |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 33 | #include <vnet/dpo/punt_dpo.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 34 | |
| 35 | #include <vnet/mpls/mpls.h> |
| 36 | |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 37 | #include <vnet/fib/fib_test.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 38 | #include <vnet/fib/fib_path_list.h> |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 39 | #include <vnet/fib/fib_entry_src.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 40 | #include <vnet/fib/fib_walk.h> |
| 41 | #include <vnet/fib/fib_node_list.h> |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 42 | #include <vnet/fib/fib_urpf_list.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 43 | |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 44 | #include <vlib/unix/plugin.h> |
| 45 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 46 | /* |
| 47 | * Add debugs for passing tests |
| 48 | */ |
| 49 | static int fib_test_do_debug; |
| 50 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 51 | #define FIB_TEST_I(_cond, _comment, _args...) \ |
| 52 | ({ \ |
| 53 | int _evald = (_cond); \ |
| 54 | if (!(_evald)) { \ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 55 | fformat(stderr, "FAIL:%d: " _comment "\n", \ |
| 56 | __LINE__, ##_args); \ |
| 57 | res = 1; \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 58 | } else { \ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 59 | if (fib_test_do_debug) \ |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 60 | fformat(stderr, "PASS:%d: " _comment "\n", \ |
| 61 | __LINE__, ##_args); \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 62 | } \ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 63 | res; \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 64 | }) |
| 65 | #define FIB_TEST(_cond, _comment, _args...) \ |
| 66 | { \ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 67 | if (FIB_TEST_I(_cond, _comment, ##_args)) { \ |
| 68 | return 1; \ |
| 69 | ASSERT(!("FAIL: " _comment)); \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 70 | } \ |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * A 'i'm not fussed is this is not efficient' store of test data |
| 75 | */ |
| 76 | typedef struct test_main_t_ { |
| 77 | /** |
| 78 | * HW if indicies |
| 79 | */ |
| 80 | u32 hw_if_indicies[4]; |
| 81 | /** |
| 82 | * HW interfaces |
| 83 | */ |
| 84 | vnet_hw_interface_t * hw[4]; |
| 85 | |
| 86 | } test_main_t; |
| 87 | static test_main_t test_main; |
| 88 | |
| 89 | /* fake ethernet device class, distinct from "fake-ethX" */ |
| 90 | static u8 * format_test_interface_name (u8 * s, va_list * args) |
| 91 | { |
| 92 | u32 dev_instance = va_arg (*args, u32); |
| 93 | return format (s, "test-eth%d", dev_instance); |
| 94 | } |
| 95 | |
| 96 | static uword dummy_interface_tx (vlib_main_t * vm, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 97 | vlib_node_runtime_t * node, |
| 98 | vlib_frame_t * frame) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 99 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 100 | clib_warning ("you shouldn't be here, leaking buffers..."); |
| 101 | return frame->n_vectors; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 102 | } |
| 103 | |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 104 | static clib_error_t * |
| 105 | test_interface_admin_up_down (vnet_main_t * vnm, |
| 106 | u32 hw_if_index, |
| 107 | u32 flags) |
| 108 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 109 | u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? |
| 110 | VNET_HW_INTERFACE_FLAG_LINK_UP : 0; |
| 111 | vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags); |
| 112 | return 0; |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 115 | VNET_DEVICE_CLASS (test_interface_device_class,static) = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 116 | .name = "Test interface", |
| 117 | .format_device_name = format_test_interface_name, |
| 118 | .tx_function = dummy_interface_tx, |
| 119 | .admin_up_down_function = test_interface_admin_up_down, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | static u8 *hw_address; |
| 123 | |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 124 | static int |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 125 | fib_test_mk_intf (u32 ninterfaces) |
| 126 | { |
| 127 | clib_error_t * error = NULL; |
| 128 | test_main_t *tm = &test_main; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 129 | u32 i, res; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 130 | u8 byte; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 131 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 132 | res = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 133 | ASSERT(ninterfaces <= ARRAY_LEN(tm->hw_if_indicies)); |
| 134 | |
| 135 | for (i=0; i<6; i++) |
| 136 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 137 | byte = 0xd0+i; |
| 138 | vec_add1(hw_address, byte); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | for (i = 0; i < ninterfaces; i++) |
| 142 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 143 | hw_address[5] = i; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 144 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 145 | error = ethernet_register_interface(vnet_get_main(), |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 146 | test_interface_device_class.index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 147 | i /* instance */, |
| 148 | hw_address, |
| 149 | &tm->hw_if_indicies[i], |
| 150 | /* flag change */ 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 151 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 152 | FIB_TEST((NULL == error), "ADD interface %d", i); |
| 153 | |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 154 | error = vnet_hw_interface_set_flags(vnet_get_main(), |
| 155 | tm->hw_if_indicies[i], |
| 156 | VNET_HW_INTERFACE_FLAG_LINK_UP); |
| 157 | tm->hw[i] = vnet_get_hw_interface(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 158 | tm->hw_if_indicies[i]); |
| 159 | vec_validate (ip4_main.fib_index_by_sw_if_index, |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 160 | tm->hw[i]->sw_if_index); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 161 | vec_validate (ip6_main.fib_index_by_sw_if_index, |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 162 | tm->hw[i]->sw_if_index); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 163 | ip4_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0; |
| 164 | ip6_main.fib_index_by_sw_if_index[tm->hw[i]->sw_if_index] = 0; |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 165 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 166 | error = vnet_sw_interface_set_flags(vnet_get_main(), |
| 167 | tm->hw[i]->sw_if_index, |
| 168 | VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
| 169 | FIB_TEST((NULL == error), "UP interface %d", i); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 170 | } |
| 171 | /* |
| 172 | * re-eval after the inevitable realloc |
| 173 | */ |
| 174 | for (i = 0; i < ninterfaces; i++) |
| 175 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 176 | tm->hw[i] = vnet_get_hw_interface(vnet_get_main(), |
| 177 | tm->hw_if_indicies[i]); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 178 | } |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 179 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 180 | return (res); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 183 | #define FIB_TEST_REC_FORW(_rec_prefix, _via_prefix, _bucket) \ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 184 | { \ |
| 185 | const dpo_id_t *_rec_dpo = fib_entry_contribute_ip_forwarding( \ |
| 186 | fib_table_lookup_exact_match(fib_index, (_rec_prefix))); \ |
| 187 | const dpo_id_t *_via_dpo = fib_entry_contribute_ip_forwarding( \ |
| 188 | fib_table_lookup(fib_index, (_via_prefix))); \ |
| 189 | FIB_TEST(!dpo_cmp(_via_dpo, \ |
| 190 | load_balance_get_bucket(_rec_dpo->dpoi_index, \ |
| 191 | _bucket)), \ |
| 192 | "%U is recursive via %U", \ |
| 193 | format_fib_prefix, (_rec_prefix), \ |
| 194 | format_fib_prefix, _via_prefix); \ |
| 195 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 196 | |
| 197 | #define FIB_TEST_LB_BUCKET_VIA_ADJ(_prefix, _bucket, _ai) \ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 198 | { \ |
| 199 | const dpo_id_t *_dpo = fib_entry_contribute_ip_forwarding( \ |
| 200 | fib_table_lookup_exact_match(fib_index, (_prefix))); \ |
| 201 | const dpo_id_t *_dpo1 = \ |
| 202 | load_balance_get_bucket(_dpo->dpoi_index, _bucket); \ |
| 203 | FIB_TEST(DPO_ADJACENCY == _dpo1->dpoi_type, "type is %U", \ |
| 204 | format_dpo_type, _dpo1->dpoi_type); \ |
| 205 | FIB_TEST((_ai == _dpo1->dpoi_index), \ |
| 206 | "%U bucket %d resolves via %U", \ |
| 207 | format_fib_prefix, (_prefix), \ |
| 208 | _bucket, \ |
| 209 | format_dpo_id, _dpo1, 0); \ |
| 210 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 211 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 212 | #define FIB_TEST_RPF(_cond, _comment, _args...) \ |
| 213 | { \ |
| 214 | if (FIB_TEST_I(_cond, _comment, ##_args)) { \ |
| 215 | return (1); \ |
| 216 | } \ |
| 217 | } |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 218 | |
| 219 | static int |
| 220 | fib_test_urpf_is_equal (fib_node_index_t fei, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 221 | fib_forward_chain_type_t fct, |
| 222 | u32 num, ...) |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 223 | { |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 224 | dpo_id_t dpo = DPO_INVALID; |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 225 | fib_urpf_list_t *urpf; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 226 | int ii, res; |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 227 | index_t ui; |
| 228 | va_list ap; |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 229 | |
| 230 | va_start(ap, num); |
| 231 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 232 | res = 0; |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 233 | fib_entry_contribute_forwarding(fei, fct, &dpo); |
| 234 | ui = load_balance_get_urpf(dpo.dpoi_index); |
| 235 | |
| 236 | urpf = fib_urpf_list_get(ui); |
| 237 | |
| 238 | FIB_TEST_RPF(num == vec_len(urpf->furpf_itfs), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 239 | "RPF:%U len %d == %d", |
| 240 | format_fib_urpf_list, ui, |
| 241 | num, vec_len(urpf->furpf_itfs)); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 242 | FIB_TEST_RPF(num == fib_urpf_check_size(ui), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 243 | "RPF:%U check-size %d == %d", |
| 244 | format_fib_urpf_list, ui, |
| 245 | num, vec_len(urpf->furpf_itfs)); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 246 | |
| 247 | for (ii = 0; ii < num; ii++) |
| 248 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 249 | adj_index_t ai = va_arg(ap, adj_index_t); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 250 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 251 | FIB_TEST_RPF(ai == urpf->furpf_itfs[ii], |
| 252 | "RPF:%d item:%d - %d == %d", |
| 253 | ui, ii, ai, urpf->furpf_itfs[ii]); |
| 254 | FIB_TEST_RPF(fib_urpf_check(ui, ai), |
| 255 | "RPF:%d %d found", |
| 256 | ui, ai); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | dpo_reset(&dpo); |
| 260 | |
Neale Ranns | 5899fde | 2016-10-12 13:51:05 +0100 | [diff] [blame] | 261 | va_end(ap); |
| 262 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 263 | return (res); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 264 | } |
| 265 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 266 | static u8* |
| 267 | fib_test_build_rewrite (u8 *eth_addr) |
| 268 | { |
| 269 | u8* rewrite = NULL; |
| 270 | |
| 271 | vec_validate(rewrite, 13); |
| 272 | |
| 273 | memcpy(rewrite, eth_addr, 6); |
| 274 | memcpy(rewrite+6, eth_addr, 6); |
| 275 | |
| 276 | return (rewrite); |
| 277 | } |
| 278 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 279 | #define FIB_TEST_LB(_cond, _comment, _args...) \ |
| 280 | { \ |
| 281 | if (FIB_TEST_I(_cond, _comment, ##_args)) { \ |
| 282 | return (1); \ |
| 283 | } \ |
| 284 | } |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 285 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 286 | int |
| 287 | fib_test_validate_rep_v (const replicate_t *rep, |
| 288 | u16 n_buckets, |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 289 | va_list *ap) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 290 | { |
| 291 | const fib_test_rep_bucket_t *exp; |
| 292 | const dpo_id_t *dpo; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 293 | int bucket, res; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 294 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 295 | res = 0; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 296 | FIB_TEST_LB((n_buckets == rep->rep_n_buckets), |
| 297 | "n_buckets = %d", rep->rep_n_buckets); |
| 298 | |
| 299 | for (bucket = 0; bucket < n_buckets; bucket++) |
| 300 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 301 | exp = va_arg(*ap, fib_test_rep_bucket_t*); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 302 | |
| 303 | dpo = replicate_get_bucket_i(rep, bucket); |
| 304 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 305 | switch (exp->type) |
| 306 | { |
| 307 | case FT_REP_LABEL_O_ADJ: |
| 308 | { |
| 309 | const mpls_label_dpo_t *mld; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 310 | mpls_label_t hdr; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 311 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 312 | FIB_TEST_LB((mpls_label_dpo_get_type(MPLS_LABEL_DPO_FLAG_NONE) |
| 313 | == dpo->dpoi_type), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 314 | "bucket %d stacks on %U", |
| 315 | bucket, |
| 316 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 317 | |
| 318 | mld = mpls_label_dpo_get(dpo->dpoi_index); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 319 | hdr = clib_net_to_host_u32(mld->mld_hdr[0].label_exp_s_ttl); |
| 320 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 321 | FIB_TEST_LB((vnet_mpls_uc_get_label(hdr) == |
| 322 | exp->label_o_adj.label), |
| 323 | "bucket %d stacks on label %d", |
| 324 | bucket, |
| 325 | exp->label_o_adj.label); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 326 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 327 | FIB_TEST_LB((vnet_mpls_uc_get_s(hdr) == |
| 328 | exp->label_o_adj.eos), |
| 329 | "bucket %d stacks on label %d %U", |
| 330 | bucket, |
| 331 | exp->label_o_adj.label, |
| 332 | format_mpls_eos_bit, exp->label_o_adj.eos); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 333 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 334 | FIB_TEST_LB((DPO_ADJACENCY_INCOMPLETE == mld->mld_dpo.dpoi_type), |
| 335 | "bucket %d label stacks on %U", |
| 336 | bucket, |
| 337 | format_dpo_type, mld->mld_dpo.dpoi_type); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 338 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 339 | FIB_TEST_LB((exp->label_o_adj.adj == mld->mld_dpo.dpoi_index), |
| 340 | "bucket %d label stacks on adj %d", |
| 341 | bucket, |
| 342 | exp->label_o_adj.adj); |
| 343 | } |
| 344 | break; |
| 345 | case FT_REP_INTF: |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 346 | FIB_TEST_LB((DPO_INTERFACE_RX == dpo->dpoi_type), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 347 | "bucket %d stacks on %U", |
| 348 | bucket, |
| 349 | format_dpo_type, dpo->dpoi_type); |
| 350 | |
| 351 | FIB_TEST_LB((exp->adj.adj == dpo->dpoi_index), |
| 352 | "bucket %d stacks on adj %d", |
| 353 | bucket, |
| 354 | exp->adj.adj); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 355 | break; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 356 | case FT_REP_DISP_MFIB_LOOKUP: |
| 357 | // ASSERT(0); |
| 358 | break; |
| 359 | } |
| 360 | } |
| 361 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 362 | return (res); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | int |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 366 | fib_test_validate_lb_v (const load_balance_t *lb, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 367 | int n_buckets, |
| 368 | va_list *ap) |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 369 | { |
| 370 | const dpo_id_t *dpo; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 371 | int bucket, res; |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 372 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 373 | res = 0; |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 374 | FIB_TEST_LB((n_buckets == lb->lb_n_buckets), "n_buckets = %d", lb->lb_n_buckets); |
| 375 | |
| 376 | for (bucket = 0; bucket < n_buckets; bucket++) |
| 377 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 378 | const fib_test_lb_bucket_t *exp; |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 379 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 380 | exp = va_arg(*ap, fib_test_lb_bucket_t*); |
| 381 | dpo = load_balance_get_bucket_i(lb, bucket); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 382 | |
| 383 | switch (exp->type) |
| 384 | { |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 385 | case FT_LB_LABEL_STACK_O_ADJ: |
| 386 | { |
| 387 | const mpls_label_dpo_t *mld; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 388 | mpls_label_dpo_flags_t mf; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 389 | mpls_label_t hdr; |
| 390 | u32 ii; |
| 391 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 392 | mf = ((exp->label_stack_o_adj.mode == |
| 393 | FIB_MPLS_LSP_MODE_UNIFORM) ? |
| 394 | MPLS_LABEL_DPO_FLAG_UNIFORM_MODE : |
| 395 | MPLS_LABEL_DPO_FLAG_NONE); |
| 396 | FIB_TEST_LB((mpls_label_dpo_get_type(mf) == dpo->dpoi_type), |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 397 | "bucket %d stacks on %U", |
| 398 | bucket, |
| 399 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 400 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 401 | mld = mpls_label_dpo_get(dpo->dpoi_index); |
| 402 | |
| 403 | FIB_TEST_LB(exp->label_stack_o_adj.label_stack_size == mld->mld_n_labels, |
| 404 | "label stack size", |
| 405 | mld->mld_n_labels); |
| 406 | |
| 407 | for (ii = 0; ii < mld->mld_n_labels; ii++) |
| 408 | { |
| 409 | hdr = clib_net_to_host_u32(mld->mld_hdr[ii].label_exp_s_ttl); |
| 410 | FIB_TEST_LB((vnet_mpls_uc_get_label(hdr) == |
| 411 | exp->label_stack_o_adj.label_stack[ii]), |
| 412 | "bucket %d stacks on label %d", |
| 413 | bucket, |
| 414 | exp->label_stack_o_adj.label_stack[ii]); |
| 415 | |
| 416 | if (ii == mld->mld_n_labels-1) |
| 417 | { |
| 418 | FIB_TEST_LB((vnet_mpls_uc_get_s(hdr) == |
| 419 | exp->label_o_adj.eos), |
| 420 | "bucket %d stacks on label %d %U!=%U", |
| 421 | bucket, |
| 422 | exp->label_stack_o_adj.label_stack[ii], |
| 423 | format_mpls_eos_bit, exp->label_o_adj.eos, |
| 424 | format_mpls_eos_bit, vnet_mpls_uc_get_s(hdr)); |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | FIB_TEST_LB((vnet_mpls_uc_get_s(hdr) == MPLS_NON_EOS), |
| 429 | "bucket %d stacks on label %d %U", |
| 430 | bucket, |
| 431 | exp->label_stack_o_adj.label_stack[ii], |
| 432 | format_mpls_eos_bit, vnet_mpls_uc_get_s(hdr)); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | FIB_TEST_LB((DPO_ADJACENCY_INCOMPLETE == mld->mld_dpo.dpoi_type), |
| 437 | "bucket %d label stacks on %U", |
| 438 | bucket, |
| 439 | format_dpo_type, mld->mld_dpo.dpoi_type); |
| 440 | |
| 441 | FIB_TEST_LB((exp->label_stack_o_adj.adj == mld->mld_dpo.dpoi_index), |
| 442 | "bucket %d label stacks on adj %d", |
| 443 | bucket, |
| 444 | exp->label_stack_o_adj.adj); |
| 445 | } |
| 446 | break; |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 447 | case FT_LB_LABEL_O_ADJ: |
| 448 | { |
| 449 | const mpls_label_dpo_t *mld; |
| 450 | mpls_label_t hdr; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 451 | FIB_TEST_LB((mpls_label_dpo_get_type(MPLS_LABEL_DPO_FLAG_NONE) |
| 452 | == dpo->dpoi_type), |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 453 | "bucket %d stacks on %U", |
| 454 | bucket, |
| 455 | format_dpo_type, dpo->dpoi_type); |
| 456 | |
| 457 | mld = mpls_label_dpo_get(dpo->dpoi_index); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 458 | hdr = clib_net_to_host_u32(mld->mld_hdr[0].label_exp_s_ttl); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 459 | |
| 460 | FIB_TEST_LB((vnet_mpls_uc_get_label(hdr) == |
| 461 | exp->label_o_adj.label), |
| 462 | "bucket %d stacks on label %d", |
| 463 | bucket, |
| 464 | exp->label_o_adj.label); |
| 465 | |
| 466 | FIB_TEST_LB((vnet_mpls_uc_get_s(hdr) == |
| 467 | exp->label_o_adj.eos), |
| 468 | "bucket %d stacks on label %d %U", |
| 469 | bucket, |
| 470 | exp->label_o_adj.label, |
| 471 | format_mpls_eos_bit, exp->label_o_adj.eos); |
| 472 | |
| 473 | FIB_TEST_LB((DPO_ADJACENCY_INCOMPLETE == mld->mld_dpo.dpoi_type), |
| 474 | "bucket %d label stacks on %U", |
| 475 | bucket, |
| 476 | format_dpo_type, mld->mld_dpo.dpoi_type); |
| 477 | |
| 478 | FIB_TEST_LB((exp->label_o_adj.adj == mld->mld_dpo.dpoi_index), |
| 479 | "bucket %d label stacks on adj %d", |
| 480 | bucket, |
| 481 | exp->label_o_adj.adj); |
| 482 | } |
| 483 | break; |
| 484 | case FT_LB_LABEL_O_LB: |
| 485 | { |
| 486 | const mpls_label_dpo_t *mld; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 487 | mpls_label_dpo_flags_t mf; |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 488 | mpls_label_t hdr; |
| 489 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 490 | mf = ((exp->label_o_lb.mode == |
| 491 | FIB_MPLS_LSP_MODE_UNIFORM) ? |
| 492 | MPLS_LABEL_DPO_FLAG_UNIFORM_MODE : |
| 493 | MPLS_LABEL_DPO_FLAG_NONE); |
| 494 | FIB_TEST_LB((mpls_label_dpo_get_type(mf) == dpo->dpoi_type), |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 495 | "bucket %d stacks on %U", |
| 496 | bucket, |
| 497 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 498 | |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 499 | mld = mpls_label_dpo_get(dpo->dpoi_index); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 500 | hdr = clib_net_to_host_u32(mld->mld_hdr[0].label_exp_s_ttl); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 501 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 502 | FIB_TEST_LB(1 == mld->mld_n_labels, "label stack size", |
| 503 | mld->mld_n_labels); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 504 | FIB_TEST_LB((vnet_mpls_uc_get_label(hdr) == |
| 505 | exp->label_o_lb.label), |
| 506 | "bucket %d stacks on label %d", |
| 507 | bucket, |
| 508 | exp->label_o_lb.label); |
| 509 | |
| 510 | FIB_TEST_LB((vnet_mpls_uc_get_s(hdr) == |
| 511 | exp->label_o_lb.eos), |
| 512 | "bucket %d stacks on label %d %U", |
| 513 | bucket, |
| 514 | exp->label_o_lb.label, |
| 515 | format_mpls_eos_bit, exp->label_o_lb.eos); |
| 516 | |
| 517 | FIB_TEST_LB((DPO_LOAD_BALANCE == mld->mld_dpo.dpoi_type), |
| 518 | "bucket %d label stacks on %U", |
| 519 | bucket, |
| 520 | format_dpo_type, mld->mld_dpo.dpoi_type); |
| 521 | |
| 522 | FIB_TEST_LB((exp->label_o_lb.lb == mld->mld_dpo.dpoi_index), |
| 523 | "bucket %d label stacks on LB %d", |
| 524 | bucket, |
| 525 | exp->label_o_lb.lb); |
| 526 | } |
| 527 | break; |
| 528 | case FT_LB_ADJ: |
Neale Ranns | 756cd94 | 2018-04-06 09:18:11 -0700 | [diff] [blame] | 529 | res = FIB_TEST_I(((DPO_ADJACENCY == dpo->dpoi_type) || |
| 530 | (DPO_ADJACENCY_INCOMPLETE == dpo->dpoi_type)), |
| 531 | "bucket %d stacks on %U", |
| 532 | bucket, |
| 533 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 534 | FIB_TEST_LB((exp->adj.adj == dpo->dpoi_index), |
| 535 | "bucket %d stacks on adj %d", |
| 536 | bucket, |
| 537 | exp->adj.adj); |
| 538 | break; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 539 | case FT_LB_MPLS_DISP_PIPE_O_ADJ: |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 540 | { |
| 541 | const mpls_disp_dpo_t *mdd; |
| 542 | |
Neale Ranns | 756cd94 | 2018-04-06 09:18:11 -0700 | [diff] [blame] | 543 | res = FIB_TEST_I((DPO_MPLS_DISPOSITION_PIPE == dpo->dpoi_type), |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 544 | "bucket %d stacks on %U", |
| 545 | bucket, |
| 546 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 547 | |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 548 | mdd = mpls_disp_dpo_get(dpo->dpoi_index); |
| 549 | |
| 550 | dpo = &mdd->mdd_dpo; |
| 551 | |
Neale Ranns | 756cd94 | 2018-04-06 09:18:11 -0700 | [diff] [blame] | 552 | res = FIB_TEST_I(((DPO_ADJACENCY == dpo->dpoi_type) || |
| 553 | (DPO_ADJACENCY_INCOMPLETE == dpo->dpoi_type)), |
| 554 | "bucket %d stacks on %U", |
| 555 | bucket, |
| 556 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 557 | FIB_TEST_LB((exp->adj.adj == dpo->dpoi_index), |
| 558 | "bucket %d stacks on adj %d", |
| 559 | bucket, |
| 560 | exp->adj.adj); |
| 561 | break; |
| 562 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 563 | case FT_LB_INTF: |
Neale Ranns | 756cd94 | 2018-04-06 09:18:11 -0700 | [diff] [blame] | 564 | res = FIB_TEST_I((DPO_INTERFACE_RX == dpo->dpoi_type), |
| 565 | "bucket %d stacks on %U", |
| 566 | bucket, |
| 567 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 568 | FIB_TEST_LB((exp->adj.adj == dpo->dpoi_index), |
| 569 | "bucket %d stacks on adj %d", |
| 570 | bucket, |
| 571 | exp->adj.adj); |
| 572 | break; |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 573 | case FT_LB_L2: |
Neale Ranns | 756cd94 | 2018-04-06 09:18:11 -0700 | [diff] [blame] | 574 | res = FIB_TEST_I((DPO_DVR == dpo->dpoi_type), |
| 575 | "bucket %d stacks on %U", |
| 576 | bucket, |
| 577 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 578 | FIB_TEST_LB((exp->adj.adj == dpo->dpoi_index), |
| 579 | "bucket %d stacks on adj %d", |
| 580 | bucket, |
| 581 | exp->adj.adj); |
| 582 | break; |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 583 | case FT_LB_O_LB: |
Neale Ranns | 756cd94 | 2018-04-06 09:18:11 -0700 | [diff] [blame] | 584 | res = FIB_TEST_I((DPO_LOAD_BALANCE == dpo->dpoi_type), |
| 585 | "bucket %d stacks on %U", |
| 586 | bucket, |
| 587 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 588 | FIB_TEST_LB((exp->lb.lb == dpo->dpoi_index), |
| 589 | "bucket %d stacks on lb %d not %d", |
| 590 | bucket, |
| 591 | dpo->dpoi_index, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 592 | exp->lb.lb); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 593 | break; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 594 | case FT_LB_BIER_TABLE: |
| 595 | FIB_TEST_LB((DPO_BIER_TABLE == dpo->dpoi_type), |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 596 | "bucket %d stacks on %U", |
| 597 | bucket, |
| 598 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 599 | FIB_TEST_LB((exp->bier.table == dpo->dpoi_index), |
| 600 | "bucket %d stacks on lb %d", |
| 601 | bucket, |
| 602 | exp->bier.table); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 603 | break; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 604 | case FT_LB_BIER_FMASK: |
| 605 | FIB_TEST_LB((DPO_BIER_FMASK == dpo->dpoi_type), |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 606 | "bucket %d stacks on %U", |
| 607 | bucket, |
| 608 | format_dpo_type, dpo->dpoi_type); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 609 | FIB_TEST_LB((exp->bier.fmask == dpo->dpoi_index), |
| 610 | "bucket %d stacks on lb %d", |
| 611 | bucket, |
| 612 | exp->bier.fmask); |
| 613 | break; |
| 614 | case FT_LB_DROP: |
| 615 | FIB_TEST_LB((DPO_DROP == dpo->dpoi_type), |
| 616 | "bucket %d stacks on %U", |
| 617 | bucket, |
| 618 | format_dpo_type, dpo->dpoi_type); |
| 619 | break; |
| 620 | case FT_LB_PUNT: |
| 621 | FIB_TEST_LB((DPO_PUNT == dpo->dpoi_type), |
| 622 | "bucket %d stacks on %U", |
| 623 | bucket, |
| 624 | format_dpo_type, dpo->dpoi_type); |
| 625 | break; |
| 626 | } |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 627 | } |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 628 | return (res); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 629 | } |
| 630 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 631 | int |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 632 | fib_test_validate_lb (const dpo_id_t *dpo, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 633 | int n_buckets, |
| 634 | ...) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 635 | { |
| 636 | const load_balance_t *lb; |
| 637 | va_list ap; |
| 638 | int res; |
| 639 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 640 | res = 0; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 641 | va_start(ap, n_buckets); |
| 642 | |
Neale Ranns | 93149bb | 2017-11-15 10:44:07 -0800 | [diff] [blame] | 643 | if (FIB_TEST_I((DPO_LOAD_BALANCE == dpo->dpoi_type), |
| 644 | "Entry links to %U", |
| 645 | format_dpo_type, dpo->dpoi_type)) |
| 646 | { |
| 647 | lb = load_balance_get(dpo->dpoi_index); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 648 | |
Neale Ranns | 93149bb | 2017-11-15 10:44:07 -0800 | [diff] [blame] | 649 | res = fib_test_validate_lb_v(lb, n_buckets, &ap); |
| 650 | } |
| 651 | else |
| 652 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 653 | res = 0; |
Neale Ranns | 93149bb | 2017-11-15 10:44:07 -0800 | [diff] [blame] | 654 | } |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 655 | |
| 656 | va_end(ap); |
| 657 | |
| 658 | return (res); |
| 659 | } |
| 660 | |
| 661 | int |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 662 | fib_test_validate_entry (fib_node_index_t fei, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 663 | fib_forward_chain_type_t fct, |
| 664 | int n_buckets, |
| 665 | ...) |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 666 | { |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 667 | dpo_id_t dpo = DPO_INVALID; |
| 668 | fib_prefix_t pfx; |
| 669 | index_t fw_lbi; |
| 670 | u32 fib_index; |
| 671 | va_list ap; |
| 672 | int res; |
| 673 | |
| 674 | va_start(ap, n_buckets); |
| 675 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 676 | res = 0; |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 677 | fib_entry_get_prefix(fei, &pfx); |
| 678 | fib_index = fib_entry_get_fib_index(fei); |
| 679 | fib_entry_contribute_forwarding(fei, fct, &dpo); |
| 680 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 681 | if (DPO_REPLICATE == dpo.dpoi_type) |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 682 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 683 | const replicate_t *rep; |
| 684 | |
| 685 | rep = replicate_get(dpo.dpoi_index); |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 686 | res = fib_test_validate_rep_v(rep, n_buckets, &ap); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 687 | } |
| 688 | else |
| 689 | { |
| 690 | const load_balance_t *lb; |
| 691 | |
| 692 | FIB_TEST_LB((DPO_LOAD_BALANCE == dpo.dpoi_type), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 693 | "%U Entry links to %U", |
| 694 | format_fib_prefix, &pfx, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 695 | format_dpo_type, dpo.dpoi_type); |
| 696 | |
| 697 | lb = load_balance_get(dpo.dpoi_index); |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 698 | res = fib_test_validate_lb_v(lb, n_buckets, &ap); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 699 | |
| 700 | /* |
| 701 | * ensure that the LB contributed by the entry is the |
| 702 | * same as the LB in the forwarding tables |
| 703 | */ |
| 704 | if (fct == fib_entry_get_default_chain_type(fib_entry_get(fei))) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 705 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 706 | switch (pfx.fp_proto) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 707 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 708 | case FIB_PROTOCOL_IP4: |
| 709 | fw_lbi = ip4_fib_forwarding_lookup(fib_index, &pfx.fp_addr.ip4); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 710 | break; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 711 | case FIB_PROTOCOL_IP6: |
| 712 | fw_lbi = ip6_fib_table_fwding_lookup(&ip6_main, fib_index, &pfx.fp_addr.ip6); |
| 713 | break; |
| 714 | case FIB_PROTOCOL_MPLS: |
| 715 | { |
| 716 | mpls_unicast_header_t hdr = { |
| 717 | .label_exp_s_ttl = 0, |
| 718 | }; |
| 719 | |
| 720 | vnet_mpls_uc_set_label(&hdr.label_exp_s_ttl, pfx.fp_label); |
| 721 | vnet_mpls_uc_set_s(&hdr.label_exp_s_ttl, pfx.fp_eos); |
| 722 | hdr.label_exp_s_ttl = clib_host_to_net_u32(hdr.label_exp_s_ttl); |
| 723 | |
| 724 | fw_lbi = mpls_fib_table_forwarding_lookup(fib_index, &hdr); |
| 725 | break; |
| 726 | } |
| 727 | default: |
| 728 | fw_lbi = 0; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 729 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 730 | FIB_TEST_LB((fw_lbi == dpo.dpoi_index), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 731 | "Contributed LB = FW LB:\n fwd:%U\n cont:%U", |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 732 | format_load_balance, fw_lbi, 0, |
| 733 | format_load_balance, dpo.dpoi_index, 0); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 734 | } |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 735 | } |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 736 | |
| 737 | dpo_reset(&dpo); |
| 738 | |
| 739 | va_end(ap); |
| 740 | |
| 741 | return (res); |
| 742 | } |
| 743 | |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 744 | static int |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 745 | fib_test_v4 (void) |
| 746 | { |
| 747 | /* |
| 748 | * In the default table check for the presence and correct forwarding |
| 749 | * of the special entries |
| 750 | */ |
| 751 | fib_node_index_t dfrt, fei, ai, ai2, locked_ai, ai_01, ai_02, ai_03; |
| 752 | const dpo_id_t *dpo, *dpo1, *dpo2, *dpo_drop; |
| 753 | const ip_adjacency_t *adj; |
| 754 | const load_balance_t *lb; |
| 755 | test_main_t *tm; |
| 756 | u32 fib_index; |
Neale Ranns | 994dab4 | 2017-04-18 12:56:45 -0700 | [diff] [blame] | 757 | int lb_count; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 758 | int ii, res; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 759 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 760 | res = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 761 | /* via 10.10.10.1 */ |
| 762 | ip46_address_t nh_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 763 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a01), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 764 | }; |
| 765 | /* via 10.10.10.2 */ |
| 766 | ip46_address_t nh_10_10_10_2 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 767 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a02), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 768 | }; |
| 769 | |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 770 | FIB_TEST((0 == pool_elts(load_balance_map_pool)), "LB-map pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 771 | pool_elts(load_balance_map_pool)); |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 772 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 773 | tm = &test_main; |
| 774 | |
Neale Ranns | 994dab4 | 2017-04-18 12:56:45 -0700 | [diff] [blame] | 775 | /* record the nubmer of load-balances in use before we start */ |
| 776 | lb_count = pool_elts(load_balance_pool); |
| 777 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 778 | /* Find or create FIB table 11 */ |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 779 | fib_index = fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP4, 11, |
| 780 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 781 | |
| 782 | for (ii = 0; ii < 4; ii++) |
| 783 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 784 | ip4_main.fib_index_by_sw_if_index[tm->hw[ii]->sw_if_index] = fib_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | fib_prefix_t pfx_0_0_0_0_s_0 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 788 | .fp_len = 0, |
| 789 | .fp_proto = FIB_PROTOCOL_IP4, |
| 790 | .fp_addr = { |
| 791 | .ip4 = { |
| 792 | {0} |
| 793 | }, |
| 794 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 795 | }; |
| 796 | |
| 797 | fib_prefix_t pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 798 | .fp_len = 0, |
| 799 | .fp_proto = FIB_PROTOCOL_IP4, |
| 800 | .fp_addr = { |
| 801 | .ip4 = { |
| 802 | {0} |
| 803 | }, |
| 804 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 805 | }; |
| 806 | |
| 807 | dpo_drop = drop_dpo_get(DPO_PROTO_IP4); |
| 808 | |
| 809 | dfrt = fib_table_lookup(fib_index, &pfx_0_0_0_0_s_0); |
| 810 | FIB_TEST((FIB_NODE_INDEX_INVALID != dfrt), "default route present"); |
| 811 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(dfrt)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 812 | "Default route is DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 813 | |
| 814 | pfx.fp_len = 32; |
| 815 | fei = fib_table_lookup(fib_index, &pfx); |
| 816 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "all zeros route present"); |
| 817 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 818 | "all 0s route is DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 819 | |
| 820 | pfx.fp_addr.ip4.as_u32 = clib_host_to_net_u32(0xffffffff); |
| 821 | pfx.fp_len = 32; |
| 822 | fei = fib_table_lookup(fib_index, &pfx); |
| 823 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "all ones route present"); |
| 824 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 825 | "all 1s route is DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 826 | |
| 827 | pfx.fp_addr.ip4.as_u32 = clib_host_to_net_u32(0xe0000000); |
| 828 | pfx.fp_len = 8; |
| 829 | fei = fib_table_lookup(fib_index, &pfx); |
| 830 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "all-mcast route present"); |
| 831 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 832 | "all-mcast route is DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 833 | |
| 834 | pfx.fp_addr.ip4.as_u32 = clib_host_to_net_u32(0xf0000000); |
| 835 | pfx.fp_len = 8; |
| 836 | fei = fib_table_lookup(fib_index, &pfx); |
| 837 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "class-e route present"); |
| 838 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 839 | "class-e route is DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 840 | |
| 841 | /* |
| 842 | * at this stage there are 5 entries in the test FIB (plus 5 in the default), |
| 843 | * all of which are special sourced and so none of which share path-lists. |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 844 | * There are also 2 entries, and 2 non-shared path-lists, in the v6 default |
| 845 | * table, and 4 path-lists in the v6 MFIB table |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 846 | */ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 847 | #define ENBR (5+5+2) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 848 | |
| 849 | u32 PNBR = 5+5+2+4; |
| 850 | |
| 851 | /* |
| 852 | * if the IGMP plugin is loaded this adds two more entries to the v4 MFIB |
| 853 | */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 854 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB is empty"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 855 | FIB_TEST((PNBR == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 856 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 857 | FIB_TEST((ENBR == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 858 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 859 | |
| 860 | /* |
| 861 | * add interface routes. |
| 862 | * validate presence of /24 attached and /32 recieve. |
| 863 | * test for the presence of the receive address in the glean and local adj |
| 864 | */ |
| 865 | fib_prefix_t local_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 866 | .fp_len = 24, |
| 867 | .fp_proto = FIB_PROTOCOL_IP4, |
| 868 | .fp_addr = { |
| 869 | .ip4 = { |
| 870 | .as_u32 = clib_host_to_net_u32(0x0a0a0a0a), |
| 871 | }, |
| 872 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 873 | }; |
| 874 | |
| 875 | fib_table_entry_update_one_path(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 876 | FIB_SOURCE_INTERFACE, |
| 877 | (FIB_ENTRY_FLAG_CONNECTED | |
| 878 | FIB_ENTRY_FLAG_ATTACHED), |
| 879 | DPO_PROTO_IP4, |
| 880 | NULL, |
| 881 | tm->hw[0]->sw_if_index, |
| 882 | ~0, // invalid fib index |
| 883 | 1, // weight |
| 884 | NULL, |
| 885 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 886 | fei = fib_table_lookup(fib_index, &local_pfx); |
| 887 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "attached interface route present"); |
| 888 | FIB_TEST(((FIB_ENTRY_FLAG_ATTACHED | FIB_ENTRY_FLAG_CONNECTED) == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 889 | fib_entry_get_flags(fei)), |
| 890 | "Flags set on attached interface"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 891 | |
| 892 | ai = fib_entry_get_adj(fei); |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 893 | FIB_TEST((FIB_NODE_INDEX_INVALID != ai), |
| 894 | "attached interface route adj present %d", ai); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 895 | adj = adj_get(ai); |
| 896 | FIB_TEST((IP_LOOKUP_NEXT_GLEAN == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 897 | "attached interface adj is glean"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 898 | FIB_TEST((0 == ip46_address_cmp(&local_pfx.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 899 | &adj->sub_type.glean.receive_addr)), |
| 900 | "attached interface adj is receive ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 901 | |
| 902 | local_pfx.fp_len = 32; |
| 903 | fib_table_entry_update_one_path(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 904 | FIB_SOURCE_INTERFACE, |
| 905 | (FIB_ENTRY_FLAG_CONNECTED | |
| 906 | FIB_ENTRY_FLAG_LOCAL), |
| 907 | DPO_PROTO_IP4, |
| 908 | NULL, |
| 909 | tm->hw[0]->sw_if_index, |
| 910 | ~0, // invalid fib index |
| 911 | 1, // weight |
| 912 | NULL, |
| 913 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 914 | fei = fib_table_lookup(fib_index, &local_pfx); |
| 915 | FIB_TEST(((FIB_ENTRY_FLAG_LOCAL | FIB_ENTRY_FLAG_CONNECTED) == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 916 | fib_entry_get_flags(fei)), |
| 917 | "Flags set on local interface"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 918 | |
| 919 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local interface route present"); |
| 920 | |
| 921 | dpo = fib_entry_contribute_ip_forwarding(fei); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 922 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 0), |
| 923 | "RPF list for local length 0"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 924 | dpo = load_balance_get_bucket(dpo->dpoi_index, 0); |
| 925 | FIB_TEST((DPO_RECEIVE == dpo->dpoi_type), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 926 | "local interface adj is local"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 927 | receive_dpo_t *rd = receive_dpo_get(dpo->dpoi_index); |
| 928 | |
| 929 | FIB_TEST((0 == ip46_address_cmp(&local_pfx.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 930 | &rd->rd_addr)), |
| 931 | "local interface adj is receive ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 932 | |
| 933 | FIB_TEST((2 == fib_table_get_num_entries(fib_index, |
| 934 | FIB_PROTOCOL_IP4, |
| 935 | FIB_SOURCE_INTERFACE)), |
| 936 | "2 Interface Source'd prefixes"); |
| 937 | |
| 938 | /* |
| 939 | * +2 interface routes +2 non-shared path-lists |
| 940 | */ |
| 941 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB is empty"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 942 | FIB_TEST((PNBR+2 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 943 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 944 | FIB_TEST((ENBR+2 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 945 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 946 | |
| 947 | /* |
| 948 | * Modify the default route to be via an adj not yet known. |
| 949 | * this sources the defalut route with the API source, which is |
| 950 | * a higher preference to the DEFAULT_ROUTE source |
| 951 | */ |
| 952 | pfx.fp_addr.ip4.as_u32 = 0; |
| 953 | pfx.fp_len = 0; |
| 954 | fib_table_entry_path_add(fib_index, &pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 955 | FIB_SOURCE_API, |
| 956 | FIB_ENTRY_FLAG_NONE, |
| 957 | DPO_PROTO_IP4, |
| 958 | &nh_10_10_10_1, |
| 959 | tm->hw[0]->sw_if_index, |
| 960 | ~0, // invalid fib index |
| 961 | 1, |
| 962 | NULL, |
| 963 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 964 | fei = fib_table_lookup(fib_index, &pfx); |
| 965 | FIB_TEST((FIB_ENTRY_FLAG_NONE == fib_entry_get_flags(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 966 | "Flags set on API route"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 967 | |
| 968 | FIB_TEST((fei == dfrt), "default route same index"); |
| 969 | ai = fib_entry_get_adj(fei); |
| 970 | FIB_TEST((FIB_NODE_INDEX_INVALID != ai), "default route adj present"); |
| 971 | adj = adj_get(ai); |
| 972 | FIB_TEST((IP_LOOKUP_NEXT_ARP == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 973 | "adj is incomplete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 974 | FIB_TEST((0 == ip46_address_cmp(&nh_10_10_10_1, &adj->sub_type.nbr.next_hop)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 975 | "adj nbr next-hop ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 976 | FIB_TEST((1 == fib_table_get_num_entries(fib_index, |
| 977 | FIB_PROTOCOL_IP4, |
| 978 | FIB_SOURCE_API)), |
| 979 | "1 API Source'd prefixes"); |
| 980 | |
| 981 | /* |
| 982 | * find the adj in the shared db |
| 983 | */ |
| 984 | locked_ai = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 985 | VNET_LINK_IP4, |
| 986 | &nh_10_10_10_1, |
| 987 | tm->hw[0]->sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 988 | FIB_TEST((locked_ai == ai), "ADJ NBR DB find"); |
| 989 | adj_unlock(locked_ai); |
| 990 | |
| 991 | /* |
| 992 | * +1 shared path-list |
| 993 | */ |
| 994 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 995 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 996 | FIB_TEST((PNBR+3 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 997 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 998 | FIB_TEST((ENBR+2 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 999 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1000 | |
| 1001 | /* |
| 1002 | * remove the API source from the default route. We expected |
| 1003 | * the route to remain, sourced by DEFAULT_ROUTE, and hence a DROP |
| 1004 | */ |
| 1005 | pfx.fp_addr.ip4.as_u32 = 0; |
| 1006 | pfx.fp_len = 0; |
| 1007 | fib_table_entry_path_remove(fib_index, &pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1008 | FIB_SOURCE_API, |
| 1009 | DPO_PROTO_IP4, |
| 1010 | &nh_10_10_10_1, |
| 1011 | tm->hw[0]->sw_if_index, |
| 1012 | ~0, // non-recursive path, so no FIB index |
| 1013 | 1, |
| 1014 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1015 | |
| 1016 | fei = fib_table_lookup(fib_index, &pfx); |
| 1017 | |
| 1018 | FIB_TEST((fei == dfrt), "default route same index"); |
| 1019 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1020 | "Default route is DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1021 | |
| 1022 | /* |
| 1023 | * -1 shared-path-list |
| 1024 | */ |
| 1025 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB is empty"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1026 | FIB_TEST((PNBR+2 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1027 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1028 | FIB_TEST((ENBR+2 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1029 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1030 | |
| 1031 | /* |
| 1032 | * Add an 2 ARP entry => a complete ADJ plus adj-fib. |
| 1033 | */ |
| 1034 | fib_prefix_t pfx_10_10_10_1_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1035 | .fp_len = 32, |
| 1036 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1037 | .fp_addr = { |
| 1038 | /* 10.10.10.1 */ |
| 1039 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a01), |
| 1040 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1041 | }; |
| 1042 | fib_prefix_t pfx_10_10_10_2_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1043 | .fp_len = 32, |
| 1044 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1045 | .fp_addr = { |
| 1046 | /* 10.10.10.2 */ |
| 1047 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a02), |
| 1048 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1049 | }; |
| 1050 | fib_prefix_t pfx_11_11_11_11_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1051 | .fp_len = 32, |
| 1052 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1053 | .fp_addr = { |
| 1054 | /* 11.11.11.11 */ |
| 1055 | .ip4.as_u32 = clib_host_to_net_u32(0x0b0b0b0b), |
| 1056 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1057 | }; |
| 1058 | u8 eth_addr[] = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1059 | 0xde, 0xde, 0xde, 0xba, 0xba, 0xba, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1060 | }; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 1061 | |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1062 | ip46_address_t nh_12_12_12_12 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1063 | .ip4.as_u32 = clib_host_to_net_u32(0x0c0c0c0c), |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1064 | }; |
| 1065 | adj_index_t ai_12_12_12_12; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1066 | |
| 1067 | /* |
| 1068 | * Add a route via an incomplete ADJ. then complete the ADJ |
| 1069 | * Expect the route LB is updated to use complete adj type. |
| 1070 | */ |
| 1071 | fei = fib_table_entry_update_one_path(fib_index, |
| 1072 | &pfx_11_11_11_11_s_32, |
| 1073 | FIB_SOURCE_API, |
| 1074 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1075 | DPO_PROTO_IP4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1076 | &pfx_10_10_10_1_s_32.fp_addr, |
| 1077 | tm->hw[0]->sw_if_index, |
| 1078 | ~0, // invalid fib index |
| 1079 | 1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1080 | NULL, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1081 | FIB_ROUTE_PATH_FLAG_NONE); |
| 1082 | |
| 1083 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 1084 | dpo1 = load_balance_get_bucket(dpo->dpoi_index, 0); |
| 1085 | FIB_TEST(DPO_ADJACENCY_INCOMPLETE == dpo1->dpoi_type, |
| 1086 | "11.11.11.11/32 via incomplete adj"); |
| 1087 | |
| 1088 | ai_01 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1089 | VNET_LINK_IP4, |
| 1090 | &pfx_10_10_10_1_s_32.fp_addr, |
| 1091 | tm->hw[0]->sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1092 | FIB_TEST((FIB_NODE_INDEX_INVALID != ai_01), "adj created"); |
| 1093 | adj = adj_get(ai_01); |
| 1094 | FIB_TEST((IP_LOOKUP_NEXT_ARP == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1095 | "adj is incomplete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1096 | FIB_TEST((0 == ip46_address_cmp(&pfx_10_10_10_1_s_32.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1097 | &adj->sub_type.nbr.next_hop)), |
| 1098 | "adj nbr next-hop ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1099 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 1100 | adj_nbr_update_rewrite(ai_01, ADJ_NBR_REWRITE_FLAG_COMPLETE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1101 | fib_test_build_rewrite(eth_addr)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1102 | FIB_TEST((IP_LOOKUP_NEXT_REWRITE == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1103 | "adj is complete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1104 | FIB_TEST((0 == ip46_address_cmp(&pfx_10_10_10_1_s_32.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1105 | &adj->sub_type.nbr.next_hop)), |
| 1106 | "adj nbr next-hop ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1107 | ai = fib_entry_get_adj(fei); |
| 1108 | FIB_TEST((ai_01 == ai), "ADJ-FIB resolves via adj"); |
| 1109 | |
| 1110 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 1111 | dpo1 = load_balance_get_bucket(dpo->dpoi_index, 0); |
| 1112 | FIB_TEST(DPO_ADJACENCY == dpo1->dpoi_type, |
| 1113 | "11.11.11.11/32 via complete adj"); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1114 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 1, |
| 1115 | tm->hw[0]->sw_if_index), |
| 1116 | "RPF list for adj-fib contains adj"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1117 | |
| 1118 | ai_12_12_12_12 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1119 | VNET_LINK_IP4, |
| 1120 | &nh_12_12_12_12, |
| 1121 | tm->hw[1]->sw_if_index); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1122 | FIB_TEST((FIB_NODE_INDEX_INVALID != ai_12_12_12_12), "adj created"); |
| 1123 | adj = adj_get(ai_12_12_12_12); |
| 1124 | FIB_TEST((IP_LOOKUP_NEXT_ARP == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1125 | "adj is incomplete"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1126 | FIB_TEST((0 == ip46_address_cmp(&nh_12_12_12_12, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1127 | &adj->sub_type.nbr.next_hop)), |
| 1128 | "adj nbr next-hop ok"); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 1129 | adj_nbr_update_rewrite(ai_12_12_12_12, ADJ_NBR_REWRITE_FLAG_COMPLETE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1130 | fib_test_build_rewrite(eth_addr)); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1131 | FIB_TEST((IP_LOOKUP_NEXT_REWRITE == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1132 | "adj is complete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1133 | |
| 1134 | /* |
| 1135 | * add the adj fib |
| 1136 | */ |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 1137 | fei = fib_table_entry_path_add(fib_index, |
| 1138 | &pfx_10_10_10_1_s_32, |
| 1139 | FIB_SOURCE_ADJ, |
| 1140 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1141 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 1142 | &pfx_10_10_10_1_s_32.fp_addr, |
| 1143 | tm->hw[0]->sw_if_index, |
| 1144 | ~0, // invalid fib index |
| 1145 | 1, |
| 1146 | NULL, |
| 1147 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1148 | FIB_TEST((FIB_ENTRY_FLAG_ATTACHED == fib_entry_get_flags(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1149 | "Flags set on adj-fib"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1150 | ai = fib_entry_get_adj(fei); |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 1151 | FIB_TEST((ai_01 == ai), "ADJ-FIB resolves via adj, %d", ai); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1152 | |
| 1153 | fib_table_entry_path_remove(fib_index, |
| 1154 | &pfx_11_11_11_11_s_32, |
| 1155 | FIB_SOURCE_API, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1156 | DPO_PROTO_IP4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1157 | &pfx_10_10_10_1_s_32.fp_addr, |
| 1158 | tm->hw[0]->sw_if_index, |
| 1159 | ~0, // invalid fib index |
| 1160 | 1, |
| 1161 | FIB_ROUTE_PATH_FLAG_NONE); |
| 1162 | |
| 1163 | eth_addr[5] = 0xb2; |
| 1164 | |
| 1165 | ai_02 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1166 | VNET_LINK_IP4, |
| 1167 | &pfx_10_10_10_2_s_32.fp_addr, |
| 1168 | tm->hw[0]->sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1169 | FIB_TEST((FIB_NODE_INDEX_INVALID != ai_02), "adj created"); |
| 1170 | adj = adj_get(ai_02); |
| 1171 | FIB_TEST((IP_LOOKUP_NEXT_ARP == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1172 | "adj is incomplete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1173 | FIB_TEST((0 == ip46_address_cmp(&pfx_10_10_10_2_s_32.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1174 | &adj->sub_type.nbr.next_hop)), |
| 1175 | "adj nbr next-hop ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1176 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 1177 | adj_nbr_update_rewrite(ai_02, ADJ_NBR_REWRITE_FLAG_COMPLETE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1178 | fib_test_build_rewrite(eth_addr)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1179 | FIB_TEST((IP_LOOKUP_NEXT_REWRITE == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1180 | "adj is complete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1181 | FIB_TEST((0 == ip46_address_cmp(&pfx_10_10_10_2_s_32.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1182 | &adj->sub_type.nbr.next_hop)), |
| 1183 | "adj nbr next-hop ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1184 | FIB_TEST((ai_01 != ai_02), "ADJs are different"); |
| 1185 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 1186 | fib_table_entry_path_add(fib_index, |
| 1187 | &pfx_10_10_10_2_s_32, |
| 1188 | FIB_SOURCE_ADJ, |
| 1189 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1190 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 1191 | &pfx_10_10_10_2_s_32.fp_addr, |
| 1192 | tm->hw[0]->sw_if_index, |
| 1193 | ~0, // invalid fib index |
| 1194 | 1, |
| 1195 | NULL, |
| 1196 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1197 | |
| 1198 | fei = fib_table_lookup(fib_index, &pfx_10_10_10_2_s_32); |
| 1199 | ai = fib_entry_get_adj(fei); |
| 1200 | FIB_TEST((ai_02 == ai), "ADJ-FIB resolves via adj"); |
| 1201 | |
| 1202 | /* |
| 1203 | * +2 adj-fibs, and their non-shared path-lists |
| 1204 | */ |
| 1205 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB is empty"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1206 | FIB_TEST((PNBR+4 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1207 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1208 | FIB_TEST((ENBR+4 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1209 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1210 | |
| 1211 | /* |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1212 | * Add 2 routes via the first ADJ. ensure path-list sharing |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1213 | */ |
| 1214 | fib_prefix_t pfx_1_1_1_1_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1215 | .fp_len = 32, |
| 1216 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1217 | .fp_addr = { |
| 1218 | /* 1.1.1.1/32 */ |
| 1219 | .ip4.as_u32 = clib_host_to_net_u32(0x01010101), |
| 1220 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1221 | }; |
| 1222 | |
| 1223 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1224 | &pfx_1_1_1_1_s_32, |
| 1225 | FIB_SOURCE_API, |
| 1226 | FIB_ENTRY_FLAG_NONE, |
| 1227 | DPO_PROTO_IP4, |
| 1228 | &nh_10_10_10_1, |
| 1229 | tm->hw[0]->sw_if_index, |
| 1230 | ~0, // invalid fib index |
| 1231 | 1, |
| 1232 | NULL, |
| 1233 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1234 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_1_s_32); |
| 1235 | ai = fib_entry_get_adj(fei); |
| 1236 | FIB_TEST((ai_01 == ai), "1.1.1.1 resolves via 10.10.10.1"); |
| 1237 | |
| 1238 | /* |
| 1239 | * +1 entry and a shared path-list |
| 1240 | */ |
| 1241 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB is empty"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1242 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1243 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1244 | FIB_TEST((ENBR+5 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1245 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1246 | |
| 1247 | /* 1.1.2.0/24 */ |
| 1248 | fib_prefix_t pfx_1_1_2_0_s_24 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1249 | .fp_len = 24, |
| 1250 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1251 | .fp_addr = { |
| 1252 | .ip4.as_u32 = clib_host_to_net_u32(0x01010200), |
| 1253 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1254 | }; |
| 1255 | |
| 1256 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1257 | &pfx_1_1_2_0_s_24, |
| 1258 | FIB_SOURCE_API, |
| 1259 | FIB_ENTRY_FLAG_NONE, |
| 1260 | DPO_PROTO_IP4, |
| 1261 | &nh_10_10_10_1, |
| 1262 | tm->hw[0]->sw_if_index, |
| 1263 | ~0, // invalid fib index |
| 1264 | 1, |
| 1265 | NULL, |
| 1266 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1267 | fei = fib_table_lookup(fib_index, &pfx_1_1_2_0_s_24); |
| 1268 | ai = fib_entry_get_adj(fei); |
| 1269 | FIB_TEST((ai_01 == ai), "1.1.2.0/24 resolves via 10.10.10.1"); |
| 1270 | |
| 1271 | /* |
| 1272 | * +1 entry only |
| 1273 | */ |
| 1274 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB is empty"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1275 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1276 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1277 | FIB_TEST((ENBR+6 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1278 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1279 | |
| 1280 | /* |
| 1281 | * modify 1.1.2.0/24 to use multipath. |
| 1282 | */ |
| 1283 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1284 | &pfx_1_1_2_0_s_24, |
| 1285 | FIB_SOURCE_API, |
| 1286 | FIB_ENTRY_FLAG_NONE, |
| 1287 | DPO_PROTO_IP4, |
| 1288 | &nh_10_10_10_2, |
| 1289 | tm->hw[0]->sw_if_index, |
| 1290 | ~0, // invalid fib index |
| 1291 | 1, |
| 1292 | NULL, |
| 1293 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1294 | fei = fib_table_lookup(fib_index, &pfx_1_1_2_0_s_24); |
| 1295 | dpo = fib_entry_contribute_ip_forwarding(fei); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1296 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 1297 | 1, tm->hw[0]->sw_if_index), |
| 1298 | "RPF list for 1.1.2.0/24 contains both adjs"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1299 | |
| 1300 | dpo1 = load_balance_get_bucket(dpo->dpoi_index, 0); |
| 1301 | FIB_TEST(DPO_ADJACENCY == dpo1->dpoi_type, "type is %d", dpo1->dpoi_type); |
| 1302 | FIB_TEST((ai_01 == dpo1->dpoi_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1303 | "1.1.2.0/24 bucket 0 resolves via 10.10.10.1 (%d=%d)", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1304 | ai_01, dpo1->dpoi_index); |
| 1305 | |
| 1306 | dpo1 = load_balance_get_bucket(dpo->dpoi_index, 1); |
| 1307 | FIB_TEST(DPO_ADJACENCY == dpo1->dpoi_type, "type is %d", dpo1->dpoi_type); |
| 1308 | FIB_TEST((ai_02 == dpo1->dpoi_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1309 | "1.1.2.0/24 bucket 1 resolves via 10.10.10.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1310 | |
| 1311 | /* |
| 1312 | * +1 shared-pathlist |
| 1313 | */ |
| 1314 | FIB_TEST((2 == fib_path_list_db_size()), "path list DB is empty"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1315 | FIB_TEST((PNBR+6 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1316 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1317 | FIB_TEST((ENBR+6 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1318 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1319 | |
| 1320 | /* |
| 1321 | * revert the modify |
| 1322 | */ |
| 1323 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1324 | &pfx_1_1_2_0_s_24, |
| 1325 | FIB_SOURCE_API, |
| 1326 | DPO_PROTO_IP4, |
| 1327 | &nh_10_10_10_2, |
| 1328 | tm->hw[0]->sw_if_index, |
| 1329 | ~0, |
| 1330 | 1, |
| 1331 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1332 | fei = fib_table_lookup(fib_index, &pfx_1_1_2_0_s_24); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1333 | dpo = fib_entry_contribute_ip_forwarding(fei); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1334 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 1335 | 1, tm->hw[0]->sw_if_index), |
| 1336 | "RPF list for 1.1.2.0/24 contains one adj"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1337 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1338 | ai = fib_entry_get_adj(fei); |
| 1339 | FIB_TEST((ai_01 == ai), "1.1.2.0/24 resolves via 10.10.10.1"); |
| 1340 | |
| 1341 | /* |
| 1342 | * +1 shared-pathlist |
| 1343 | */ |
| 1344 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1345 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1346 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1347 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1348 | FIB_TEST((ENBR+6 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1349 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1350 | |
| 1351 | /* |
| 1352 | * Add 2 recursive routes: |
| 1353 | * 100.100.100.100/32 via 1.1.1.1/32 => the via entry is installed. |
| 1354 | * 100.100.100.101/32 via 1.1.1.1/32 => the via entry is installed. |
| 1355 | */ |
| 1356 | fib_prefix_t bgp_100_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1357 | .fp_len = 32, |
| 1358 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1359 | .fp_addr = { |
| 1360 | /* 100.100.100.100/32 */ |
| 1361 | .ip4.as_u32 = clib_host_to_net_u32(0x64646464), |
| 1362 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1363 | }; |
| 1364 | /* via 1.1.1.1 */ |
| 1365 | ip46_address_t nh_1_1_1_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1366 | .ip4.as_u32 = clib_host_to_net_u32(0x01010101), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1367 | }; |
| 1368 | |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1369 | fei = fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1370 | &bgp_100_pfx, |
| 1371 | FIB_SOURCE_API, |
| 1372 | FIB_ENTRY_FLAG_NONE, |
| 1373 | DPO_PROTO_IP4, |
| 1374 | &nh_1_1_1_1, |
| 1375 | ~0, // no index provided. |
| 1376 | fib_index, // nexthop in same fib as route |
| 1377 | 1, |
| 1378 | NULL, |
| 1379 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1380 | |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1381 | FIB_TEST_REC_FORW(&bgp_100_pfx, &pfx_1_1_1_1_s_32, 0); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1382 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 1, |
| 1383 | tm->hw[0]->sw_if_index), |
| 1384 | "RPF list for adj-fib contains adj"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1385 | |
| 1386 | /* |
| 1387 | * +1 entry and +1 shared-path-list |
| 1388 | */ |
| 1389 | FIB_TEST((2 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1390 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1391 | FIB_TEST((PNBR+6 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1392 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1393 | FIB_TEST((ENBR+7 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1394 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1395 | |
| 1396 | fib_prefix_t bgp_101_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1397 | .fp_len = 32, |
| 1398 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1399 | .fp_addr = { |
| 1400 | /* 100.100.100.101/32 */ |
| 1401 | .ip4.as_u32 = clib_host_to_net_u32(0x64646465), |
| 1402 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1403 | }; |
| 1404 | |
| 1405 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1406 | &bgp_101_pfx, |
| 1407 | FIB_SOURCE_API, |
| 1408 | FIB_ENTRY_FLAG_NONE, |
| 1409 | DPO_PROTO_IP4, |
| 1410 | &nh_1_1_1_1, |
| 1411 | ~0, // no index provided. |
| 1412 | fib_index, // nexthop in same fib as route |
| 1413 | 1, |
| 1414 | NULL, |
| 1415 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1416 | |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1417 | FIB_TEST_REC_FORW(&bgp_101_pfx, &pfx_1_1_1_1_s_32, 0); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1418 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 1, |
| 1419 | tm->hw[0]->sw_if_index), |
| 1420 | "RPF list for adj-fib contains adj"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1421 | |
| 1422 | /* |
| 1423 | * +1 entry, but the recursive path-list is shared. |
| 1424 | */ |
| 1425 | FIB_TEST((2 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1426 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1427 | FIB_TEST((PNBR+6 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1428 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1429 | FIB_TEST((ENBR+8 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1430 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1431 | |
| 1432 | /* |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 1433 | * An special route; one where the user (me) provides the |
| 1434 | * adjacency through which the route will resovle by setting the flags |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1435 | */ |
| 1436 | fib_prefix_t ex_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1437 | .fp_len = 32, |
| 1438 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1439 | .fp_addr = { |
| 1440 | /* 4.4.4.4/32 */ |
| 1441 | .ip4.as_u32 = clib_host_to_net_u32(0x04040404), |
| 1442 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1443 | }; |
| 1444 | |
| 1445 | fib_table_entry_special_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1446 | &ex_pfx, |
| 1447 | FIB_SOURCE_SPECIAL, |
| 1448 | FIB_ENTRY_FLAG_LOCAL); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1449 | fei = fib_table_lookup_exact_match(fib_index, &ex_pfx); |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 1450 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 1451 | dpo = load_balance_get_bucket(dpo->dpoi_index, 0); |
| 1452 | FIB_TEST((DPO_RECEIVE == dpo->dpoi_type), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1453 | "local interface adj is local"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1454 | |
| 1455 | fib_table_entry_special_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1456 | &ex_pfx, |
| 1457 | FIB_SOURCE_SPECIAL); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1458 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1459 | fib_table_lookup_exact_match(fib_index, &ex_pfx), |
| 1460 | "Exclusive reoute removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1461 | |
| 1462 | /* |
| 1463 | * An EXCLUSIVE route; one where the user (me) provides the exclusive |
| 1464 | * adjacency through which the route will resovle |
| 1465 | */ |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1466 | dpo_id_t ex_dpo = DPO_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1467 | |
| 1468 | lookup_dpo_add_or_lock_w_fib_index(fib_index, |
| 1469 | DPO_PROTO_IP4, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1470 | LOOKUP_UNICAST, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1471 | LOOKUP_INPUT_DST_ADDR, |
| 1472 | LOOKUP_TABLE_FROM_CONFIG, |
| 1473 | &ex_dpo); |
| 1474 | |
| 1475 | fib_table_entry_special_dpo_add(fib_index, |
| 1476 | &ex_pfx, |
| 1477 | FIB_SOURCE_SPECIAL, |
| 1478 | FIB_ENTRY_FLAG_EXCLUSIVE, |
| 1479 | &ex_dpo); |
| 1480 | fei = fib_table_lookup_exact_match(fib_index, &ex_pfx); |
| 1481 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 1482 | FIB_TEST(!dpo_cmp(&ex_dpo, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1483 | "exclusive remote uses lookup DPO"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1484 | |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1485 | /* |
| 1486 | * update the exclusive to use a different DPO |
| 1487 | */ |
Neale Ranns | 450cd30 | 2016-11-09 17:49:42 +0000 | [diff] [blame] | 1488 | ip_null_dpo_add_and_lock(DPO_PROTO_IP4, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1489 | IP_NULL_ACTION_SEND_ICMP_UNREACH, |
| 1490 | &ex_dpo); |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1491 | fib_table_entry_special_dpo_update(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1492 | &ex_pfx, |
| 1493 | FIB_SOURCE_SPECIAL, |
| 1494 | FIB_ENTRY_FLAG_EXCLUSIVE, |
| 1495 | &ex_dpo); |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1496 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 1497 | FIB_TEST(!dpo_cmp(&ex_dpo, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1498 | "exclusive remote uses now uses NULL DPO"); |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1499 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1500 | fib_table_entry_special_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1501 | &ex_pfx, |
| 1502 | FIB_SOURCE_SPECIAL); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1503 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1504 | fib_table_lookup_exact_match(fib_index, &ex_pfx), |
| 1505 | "Exclusive reoute removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1506 | dpo_reset(&ex_dpo); |
| 1507 | |
| 1508 | /* |
| 1509 | * Add a recursive route: |
| 1510 | * 200.200.200.200/32 via 1.1.1.2/32 => the via entry is NOT installed. |
| 1511 | */ |
| 1512 | fib_prefix_t bgp_200_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1513 | .fp_len = 32, |
| 1514 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1515 | .fp_addr = { |
| 1516 | /* 200.200.200.200/32 */ |
| 1517 | .ip4.as_u32 = clib_host_to_net_u32(0xc8c8c8c8), |
| 1518 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1519 | }; |
| 1520 | /* via 1.1.1.2 */ |
| 1521 | fib_prefix_t pfx_1_1_1_2_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1522 | .fp_len = 32, |
| 1523 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1524 | .fp_addr = { |
| 1525 | .ip4.as_u32 = clib_host_to_net_u32(0x01010102), |
| 1526 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1527 | }; |
| 1528 | |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 1529 | fei = fib_table_entry_path_add(fib_index, |
| 1530 | &bgp_200_pfx, |
| 1531 | FIB_SOURCE_API, |
| 1532 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1533 | DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 1534 | &pfx_1_1_1_2_s_32.fp_addr, |
| 1535 | ~0, // no index provided. |
| 1536 | fib_index, // nexthop in same fib as route |
| 1537 | 1, |
| 1538 | NULL, |
| 1539 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1540 | |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 1541 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 1542 | "Recursive via unresolved is drop"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1543 | |
| 1544 | /* |
| 1545 | * the adj should be recursive via drop, since the route resolves via |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1546 | * the default route, which is itself a DROP |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1547 | */ |
| 1548 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_2_s_32); |
| 1549 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 1550 | FIB_TEST(load_balance_is_drop(dpo1), "1.1.1.2/32 is drop"); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1551 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 0), |
| 1552 | "RPF list for 1.1.1.2/32 contains 0 adjs"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1553 | |
| 1554 | /* |
| 1555 | * +2 entry and +1 shared-path-list |
| 1556 | */ |
| 1557 | FIB_TEST((3 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1558 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1559 | FIB_TEST((PNBR+7 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1560 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1561 | FIB_TEST((ENBR+10 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1562 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1563 | |
| 1564 | /* |
| 1565 | * Unequal Cost load-balance. 3:1 ratio. fits in a 4 bucket LB |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1566 | * The paths are sort by NH first. in this case the the path with greater |
| 1567 | * weight is first in the set. This ordering is to test the RPF sort|uniq logic |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1568 | */ |
| 1569 | fib_prefix_t pfx_1_2_3_4_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1570 | .fp_len = 32, |
| 1571 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1572 | .fp_addr = { |
| 1573 | .ip4.as_u32 = clib_host_to_net_u32(0x01020304), |
| 1574 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1575 | }; |
| 1576 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1577 | &pfx_1_2_3_4_s_32, |
| 1578 | FIB_SOURCE_API, |
| 1579 | FIB_ENTRY_FLAG_NONE, |
| 1580 | DPO_PROTO_IP4, |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1581 | &nh_10_10_10_1, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1582 | tm->hw[0]->sw_if_index, |
| 1583 | ~0, |
| 1584 | 1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1585 | NULL, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1586 | FIB_ROUTE_PATH_FLAG_NONE); |
| 1587 | fei = fib_table_entry_path_add(fib_index, |
| 1588 | &pfx_1_2_3_4_s_32, |
| 1589 | FIB_SOURCE_API, |
| 1590 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1591 | DPO_PROTO_IP4, |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1592 | &nh_12_12_12_12, |
| 1593 | tm->hw[1]->sw_if_index, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1594 | ~0, |
| 1595 | 3, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1596 | NULL, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1597 | FIB_ROUTE_PATH_FLAG_NONE); |
| 1598 | |
| 1599 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "1.2.3.4/32 presnet"); |
| 1600 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 1601 | lb = load_balance_get(dpo->dpoi_index); |
| 1602 | FIB_TEST((lb->lb_n_buckets == 4), |
| 1603 | "1.2.3.4/32 LB has %d bucket", |
| 1604 | lb->lb_n_buckets); |
| 1605 | |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1606 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_4_s_32, 0, ai_12_12_12_12); |
| 1607 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_4_s_32, 1, ai_12_12_12_12); |
| 1608 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_4_s_32, 2, ai_12_12_12_12); |
| 1609 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_4_s_32, 3, ai_01); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1610 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1611 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 2, |
| 1612 | tm->hw[0]->sw_if_index, |
| 1613 | tm->hw[1]->sw_if_index), |
| 1614 | "RPF list for 1.2.3.4/32 contains both adjs"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1615 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1616 | |
| 1617 | /* |
| 1618 | * Unequal Cost load-balance. 4:1 ratio. |
| 1619 | * fits in a 16 bucket LB with ratio 13:3 |
| 1620 | */ |
| 1621 | fib_prefix_t pfx_1_2_3_5_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1622 | .fp_len = 32, |
| 1623 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1624 | .fp_addr = { |
| 1625 | .ip4.as_u32 = clib_host_to_net_u32(0x01020305), |
| 1626 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1627 | }; |
| 1628 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1629 | &pfx_1_2_3_5_s_32, |
| 1630 | FIB_SOURCE_API, |
| 1631 | FIB_ENTRY_FLAG_NONE, |
| 1632 | DPO_PROTO_IP4, |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1633 | &nh_12_12_12_12, |
| 1634 | tm->hw[1]->sw_if_index, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1635 | ~0, |
| 1636 | 1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1637 | NULL, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1638 | FIB_ROUTE_PATH_FLAG_NONE); |
| 1639 | fei = fib_table_entry_path_add(fib_index, |
| 1640 | &pfx_1_2_3_5_s_32, |
| 1641 | FIB_SOURCE_API, |
| 1642 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1643 | DPO_PROTO_IP4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1644 | &nh_10_10_10_1, |
| 1645 | tm->hw[0]->sw_if_index, |
| 1646 | ~0, |
| 1647 | 4, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1648 | NULL, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1649 | FIB_ROUTE_PATH_FLAG_NONE); |
| 1650 | |
| 1651 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "1.2.3.5/32 presnet"); |
| 1652 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 1653 | lb = load_balance_get(dpo->dpoi_index); |
| 1654 | FIB_TEST((lb->lb_n_buckets == 16), |
| 1655 | "1.2.3.5/32 LB has %d bucket", |
| 1656 | lb->lb_n_buckets); |
| 1657 | |
| 1658 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 0, ai_01); |
| 1659 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 1, ai_01); |
| 1660 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 2, ai_01); |
| 1661 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 3, ai_01); |
| 1662 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 4, ai_01); |
| 1663 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 5, ai_01); |
| 1664 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 6, ai_01); |
| 1665 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 7, ai_01); |
| 1666 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 8, ai_01); |
| 1667 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 9, ai_01); |
| 1668 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 10, ai_01); |
| 1669 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 11, ai_01); |
| 1670 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 12, ai_01); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1671 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 13, ai_12_12_12_12); |
| 1672 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 14, ai_12_12_12_12); |
| 1673 | FIB_TEST_LB_BUCKET_VIA_ADJ(&pfx_1_2_3_5_s_32, 15, ai_12_12_12_12); |
| 1674 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1675 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 2, |
| 1676 | tm->hw[0]->sw_if_index, |
| 1677 | tm->hw[1]->sw_if_index), |
| 1678 | "RPF list for 1.2.3.4/32 contains both adjs"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 1679 | |
| 1680 | /* |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1681 | * Test UCMP with a large weight skew - this produces load-balance objects with large |
| 1682 | * numbers of buckets to accommodate the skew. By updating said load-balances we are |
| 1683 | * laso testing the LB in placce modify code when number of buckets is large. |
| 1684 | */ |
| 1685 | fib_prefix_t pfx_6_6_6_6_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1686 | .fp_len = 32, |
| 1687 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1688 | .fp_addr = { |
| 1689 | /* 1.1.1.1/32 */ |
| 1690 | .ip4.as_u32 = clib_host_to_net_u32(0x06060606), |
| 1691 | }, |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1692 | }; |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 1693 | fib_test_lb_bucket_t ip_o_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1694 | .type = FT_LB_ADJ, |
| 1695 | .adj = { |
| 1696 | .adj = ai_01, |
| 1697 | }, |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1698 | }; |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 1699 | fib_test_lb_bucket_t ip_o_10_10_10_2 = { |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1700 | .type = FT_LB_ADJ, |
| 1701 | .adj = { |
| 1702 | .adj = ai_02, |
| 1703 | }, |
| 1704 | }; |
| 1705 | fib_test_lb_bucket_t ip_6_6_6_6_o_12_12_12_12 = { |
| 1706 | .type = FT_LB_ADJ, |
| 1707 | .adj = { |
| 1708 | .adj = ai_12_12_12_12, |
| 1709 | }, |
| 1710 | }; |
| 1711 | fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1712 | &pfx_6_6_6_6_s_32, |
| 1713 | FIB_SOURCE_API, |
| 1714 | FIB_ENTRY_FLAG_NONE, |
| 1715 | DPO_PROTO_IP4, |
| 1716 | &nh_10_10_10_1, |
| 1717 | tm->hw[0]->sw_if_index, |
| 1718 | ~0, // invalid fib index |
| 1719 | 0, // zero weigth |
| 1720 | NULL, |
| 1721 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1722 | |
| 1723 | fei = fib_table_lookup(fib_index, &pfx_6_6_6_6_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1724 | FIB_TEST(!fib_test_validate_entry(fei, |
| 1725 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 1726 | 1, |
| 1727 | &ip_o_10_10_10_1), |
| 1728 | "6.6.6.6/32 via 10.10.10.1"); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1729 | |
| 1730 | fib_table_entry_path_add(fib_index, |
| 1731 | &pfx_6_6_6_6_s_32, |
| 1732 | FIB_SOURCE_API, |
| 1733 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1734 | DPO_PROTO_IP4, |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1735 | &nh_10_10_10_2, |
| 1736 | tm->hw[0]->sw_if_index, |
| 1737 | ~0, // invalid fib index |
| 1738 | 100, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1739 | NULL, |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1740 | FIB_ROUTE_PATH_FLAG_NONE); |
| 1741 | |
| 1742 | fei = fib_table_lookup(fib_index, &pfx_6_6_6_6_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1743 | FIB_TEST(!fib_test_validate_entry(fei, |
| 1744 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 1745 | 64, |
| 1746 | &ip_o_10_10_10_2, |
| 1747 | &ip_o_10_10_10_2, |
| 1748 | &ip_o_10_10_10_2, |
| 1749 | &ip_o_10_10_10_2, |
| 1750 | &ip_o_10_10_10_2, |
| 1751 | &ip_o_10_10_10_2, |
| 1752 | &ip_o_10_10_10_2, |
| 1753 | &ip_o_10_10_10_2, |
| 1754 | &ip_o_10_10_10_2, |
| 1755 | &ip_o_10_10_10_2, |
| 1756 | &ip_o_10_10_10_2, |
| 1757 | &ip_o_10_10_10_2, |
| 1758 | &ip_o_10_10_10_2, |
| 1759 | &ip_o_10_10_10_2, |
| 1760 | &ip_o_10_10_10_2, |
| 1761 | &ip_o_10_10_10_2, |
| 1762 | &ip_o_10_10_10_2, |
| 1763 | &ip_o_10_10_10_2, |
| 1764 | &ip_o_10_10_10_2, |
| 1765 | &ip_o_10_10_10_2, |
| 1766 | &ip_o_10_10_10_2, |
| 1767 | &ip_o_10_10_10_2, |
| 1768 | &ip_o_10_10_10_2, |
| 1769 | &ip_o_10_10_10_2, |
| 1770 | &ip_o_10_10_10_2, |
| 1771 | &ip_o_10_10_10_2, |
| 1772 | &ip_o_10_10_10_2, |
| 1773 | &ip_o_10_10_10_2, |
| 1774 | &ip_o_10_10_10_2, |
| 1775 | &ip_o_10_10_10_2, |
| 1776 | &ip_o_10_10_10_2, |
| 1777 | &ip_o_10_10_10_2, |
| 1778 | &ip_o_10_10_10_2, |
| 1779 | &ip_o_10_10_10_2, |
| 1780 | &ip_o_10_10_10_2, |
| 1781 | &ip_o_10_10_10_2, |
| 1782 | &ip_o_10_10_10_2, |
| 1783 | &ip_o_10_10_10_2, |
| 1784 | &ip_o_10_10_10_2, |
| 1785 | &ip_o_10_10_10_2, |
| 1786 | &ip_o_10_10_10_2, |
| 1787 | &ip_o_10_10_10_2, |
| 1788 | &ip_o_10_10_10_2, |
| 1789 | &ip_o_10_10_10_2, |
| 1790 | &ip_o_10_10_10_2, |
| 1791 | &ip_o_10_10_10_2, |
| 1792 | &ip_o_10_10_10_2, |
| 1793 | &ip_o_10_10_10_2, |
| 1794 | &ip_o_10_10_10_2, |
| 1795 | &ip_o_10_10_10_2, |
| 1796 | &ip_o_10_10_10_2, |
| 1797 | &ip_o_10_10_10_2, |
| 1798 | &ip_o_10_10_10_2, |
| 1799 | &ip_o_10_10_10_2, |
| 1800 | &ip_o_10_10_10_2, |
| 1801 | &ip_o_10_10_10_2, |
| 1802 | &ip_o_10_10_10_2, |
| 1803 | &ip_o_10_10_10_2, |
| 1804 | &ip_o_10_10_10_2, |
| 1805 | &ip_o_10_10_10_2, |
| 1806 | &ip_o_10_10_10_2, |
| 1807 | &ip_o_10_10_10_2, |
| 1808 | &ip_o_10_10_10_2, |
| 1809 | &ip_o_10_10_10_1), |
| 1810 | "6.6.6.6/32 via 10.10.10.1 and 10.10.10.2 in 63:1 ratio"); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1811 | |
| 1812 | fib_table_entry_path_add(fib_index, |
| 1813 | &pfx_6_6_6_6_s_32, |
| 1814 | FIB_SOURCE_API, |
| 1815 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1816 | DPO_PROTO_IP4, |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1817 | &nh_12_12_12_12, |
| 1818 | tm->hw[1]->sw_if_index, |
| 1819 | ~0, // invalid fib index |
| 1820 | 100, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1821 | NULL, |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1822 | FIB_ROUTE_PATH_FLAG_NONE); |
| 1823 | |
| 1824 | fei = fib_table_lookup(fib_index, &pfx_6_6_6_6_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1825 | FIB_TEST(!fib_test_validate_entry(fei, |
| 1826 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 1827 | 128, |
| 1828 | &ip_o_10_10_10_1, |
| 1829 | &ip_o_10_10_10_2, |
| 1830 | &ip_o_10_10_10_2, |
| 1831 | &ip_o_10_10_10_2, |
| 1832 | &ip_o_10_10_10_2, |
| 1833 | &ip_o_10_10_10_2, |
| 1834 | &ip_o_10_10_10_2, |
| 1835 | &ip_o_10_10_10_2, |
| 1836 | &ip_o_10_10_10_2, |
| 1837 | &ip_o_10_10_10_2, |
| 1838 | &ip_o_10_10_10_2, |
| 1839 | &ip_o_10_10_10_2, |
| 1840 | &ip_o_10_10_10_2, |
| 1841 | &ip_o_10_10_10_2, |
| 1842 | &ip_o_10_10_10_2, |
| 1843 | &ip_o_10_10_10_2, |
| 1844 | &ip_o_10_10_10_2, |
| 1845 | &ip_o_10_10_10_2, |
| 1846 | &ip_o_10_10_10_2, |
| 1847 | &ip_o_10_10_10_2, |
| 1848 | &ip_o_10_10_10_2, |
| 1849 | &ip_o_10_10_10_2, |
| 1850 | &ip_o_10_10_10_2, |
| 1851 | &ip_o_10_10_10_2, |
| 1852 | &ip_o_10_10_10_2, |
| 1853 | &ip_o_10_10_10_2, |
| 1854 | &ip_o_10_10_10_2, |
| 1855 | &ip_o_10_10_10_2, |
| 1856 | &ip_o_10_10_10_2, |
| 1857 | &ip_o_10_10_10_2, |
| 1858 | &ip_o_10_10_10_2, |
| 1859 | &ip_o_10_10_10_2, |
| 1860 | &ip_o_10_10_10_2, |
| 1861 | &ip_o_10_10_10_2, |
| 1862 | &ip_o_10_10_10_2, |
| 1863 | &ip_o_10_10_10_2, |
| 1864 | &ip_o_10_10_10_2, |
| 1865 | &ip_o_10_10_10_2, |
| 1866 | &ip_o_10_10_10_2, |
| 1867 | &ip_o_10_10_10_2, |
| 1868 | &ip_o_10_10_10_2, |
| 1869 | &ip_o_10_10_10_2, |
| 1870 | &ip_o_10_10_10_2, |
| 1871 | &ip_o_10_10_10_2, |
| 1872 | &ip_o_10_10_10_2, |
| 1873 | &ip_o_10_10_10_2, |
| 1874 | &ip_o_10_10_10_2, |
| 1875 | &ip_o_10_10_10_2, |
| 1876 | &ip_o_10_10_10_2, |
| 1877 | &ip_o_10_10_10_2, |
| 1878 | &ip_o_10_10_10_2, |
| 1879 | &ip_o_10_10_10_2, |
| 1880 | &ip_o_10_10_10_2, |
| 1881 | &ip_o_10_10_10_2, |
| 1882 | &ip_o_10_10_10_2, |
| 1883 | &ip_o_10_10_10_2, |
| 1884 | &ip_o_10_10_10_2, |
| 1885 | &ip_o_10_10_10_2, |
| 1886 | &ip_o_10_10_10_2, |
| 1887 | &ip_o_10_10_10_2, |
| 1888 | &ip_o_10_10_10_2, |
| 1889 | &ip_o_10_10_10_2, |
| 1890 | &ip_o_10_10_10_2, |
| 1891 | &ip_o_10_10_10_2, |
| 1892 | &ip_o_10_10_10_2, |
| 1893 | &ip_6_6_6_6_o_12_12_12_12, |
| 1894 | &ip_6_6_6_6_o_12_12_12_12, |
| 1895 | &ip_6_6_6_6_o_12_12_12_12, |
| 1896 | &ip_6_6_6_6_o_12_12_12_12, |
| 1897 | &ip_6_6_6_6_o_12_12_12_12, |
| 1898 | &ip_6_6_6_6_o_12_12_12_12, |
| 1899 | &ip_6_6_6_6_o_12_12_12_12, |
| 1900 | &ip_6_6_6_6_o_12_12_12_12, |
| 1901 | &ip_6_6_6_6_o_12_12_12_12, |
| 1902 | &ip_6_6_6_6_o_12_12_12_12, |
| 1903 | &ip_6_6_6_6_o_12_12_12_12, |
| 1904 | &ip_6_6_6_6_o_12_12_12_12, |
| 1905 | &ip_6_6_6_6_o_12_12_12_12, |
| 1906 | &ip_6_6_6_6_o_12_12_12_12, |
| 1907 | &ip_6_6_6_6_o_12_12_12_12, |
| 1908 | &ip_6_6_6_6_o_12_12_12_12, |
| 1909 | &ip_6_6_6_6_o_12_12_12_12, |
| 1910 | &ip_6_6_6_6_o_12_12_12_12, |
| 1911 | &ip_6_6_6_6_o_12_12_12_12, |
| 1912 | &ip_6_6_6_6_o_12_12_12_12, |
| 1913 | &ip_6_6_6_6_o_12_12_12_12, |
| 1914 | &ip_6_6_6_6_o_12_12_12_12, |
| 1915 | &ip_6_6_6_6_o_12_12_12_12, |
| 1916 | &ip_6_6_6_6_o_12_12_12_12, |
| 1917 | &ip_6_6_6_6_o_12_12_12_12, |
| 1918 | &ip_6_6_6_6_o_12_12_12_12, |
| 1919 | &ip_6_6_6_6_o_12_12_12_12, |
| 1920 | &ip_6_6_6_6_o_12_12_12_12, |
| 1921 | &ip_6_6_6_6_o_12_12_12_12, |
| 1922 | &ip_6_6_6_6_o_12_12_12_12, |
| 1923 | &ip_6_6_6_6_o_12_12_12_12, |
| 1924 | &ip_6_6_6_6_o_12_12_12_12, |
| 1925 | &ip_6_6_6_6_o_12_12_12_12, |
| 1926 | &ip_6_6_6_6_o_12_12_12_12, |
| 1927 | &ip_6_6_6_6_o_12_12_12_12, |
| 1928 | &ip_6_6_6_6_o_12_12_12_12, |
| 1929 | &ip_6_6_6_6_o_12_12_12_12, |
| 1930 | &ip_6_6_6_6_o_12_12_12_12, |
| 1931 | &ip_6_6_6_6_o_12_12_12_12, |
| 1932 | &ip_6_6_6_6_o_12_12_12_12, |
| 1933 | &ip_6_6_6_6_o_12_12_12_12, |
| 1934 | &ip_6_6_6_6_o_12_12_12_12, |
| 1935 | &ip_6_6_6_6_o_12_12_12_12, |
| 1936 | &ip_6_6_6_6_o_12_12_12_12, |
| 1937 | &ip_6_6_6_6_o_12_12_12_12, |
| 1938 | &ip_6_6_6_6_o_12_12_12_12, |
| 1939 | &ip_6_6_6_6_o_12_12_12_12, |
| 1940 | &ip_6_6_6_6_o_12_12_12_12, |
| 1941 | &ip_6_6_6_6_o_12_12_12_12, |
| 1942 | &ip_6_6_6_6_o_12_12_12_12, |
| 1943 | &ip_6_6_6_6_o_12_12_12_12, |
| 1944 | &ip_6_6_6_6_o_12_12_12_12, |
| 1945 | &ip_6_6_6_6_o_12_12_12_12, |
| 1946 | &ip_6_6_6_6_o_12_12_12_12, |
| 1947 | &ip_6_6_6_6_o_12_12_12_12, |
| 1948 | &ip_6_6_6_6_o_12_12_12_12, |
| 1949 | &ip_6_6_6_6_o_12_12_12_12, |
| 1950 | &ip_6_6_6_6_o_12_12_12_12, |
| 1951 | &ip_6_6_6_6_o_12_12_12_12, |
| 1952 | &ip_6_6_6_6_o_12_12_12_12, |
| 1953 | &ip_6_6_6_6_o_12_12_12_12, |
| 1954 | &ip_6_6_6_6_o_12_12_12_12, |
| 1955 | &ip_6_6_6_6_o_12_12_12_12), |
| 1956 | "6.6.6.6/32 via 10.10.10.1 and 10.10.10.2 in 63:1 ratio"); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1957 | |
| 1958 | fib_table_entry_path_remove(fib_index, |
| 1959 | &pfx_6_6_6_6_s_32, |
| 1960 | FIB_SOURCE_API, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1961 | DPO_PROTO_IP4, |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 1962 | &nh_12_12_12_12, |
| 1963 | tm->hw[1]->sw_if_index, |
| 1964 | ~0, // invalid fib index |
| 1965 | 100, |
| 1966 | FIB_ROUTE_PATH_FLAG_NONE); |
| 1967 | |
| 1968 | fei = fib_table_lookup(fib_index, &pfx_6_6_6_6_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1969 | FIB_TEST(!fib_test_validate_entry(fei, |
| 1970 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 1971 | 64, |
| 1972 | &ip_o_10_10_10_2, |
| 1973 | &ip_o_10_10_10_2, |
| 1974 | &ip_o_10_10_10_2, |
| 1975 | &ip_o_10_10_10_2, |
| 1976 | &ip_o_10_10_10_2, |
| 1977 | &ip_o_10_10_10_2, |
| 1978 | &ip_o_10_10_10_2, |
| 1979 | &ip_o_10_10_10_2, |
| 1980 | &ip_o_10_10_10_2, |
| 1981 | &ip_o_10_10_10_2, |
| 1982 | &ip_o_10_10_10_2, |
| 1983 | &ip_o_10_10_10_2, |
| 1984 | &ip_o_10_10_10_2, |
| 1985 | &ip_o_10_10_10_2, |
| 1986 | &ip_o_10_10_10_2, |
| 1987 | &ip_o_10_10_10_2, |
| 1988 | &ip_o_10_10_10_2, |
| 1989 | &ip_o_10_10_10_2, |
| 1990 | &ip_o_10_10_10_2, |
| 1991 | &ip_o_10_10_10_2, |
| 1992 | &ip_o_10_10_10_2, |
| 1993 | &ip_o_10_10_10_2, |
| 1994 | &ip_o_10_10_10_2, |
| 1995 | &ip_o_10_10_10_2, |
| 1996 | &ip_o_10_10_10_2, |
| 1997 | &ip_o_10_10_10_2, |
| 1998 | &ip_o_10_10_10_2, |
| 1999 | &ip_o_10_10_10_2, |
| 2000 | &ip_o_10_10_10_2, |
| 2001 | &ip_o_10_10_10_2, |
| 2002 | &ip_o_10_10_10_2, |
| 2003 | &ip_o_10_10_10_2, |
| 2004 | &ip_o_10_10_10_2, |
| 2005 | &ip_o_10_10_10_2, |
| 2006 | &ip_o_10_10_10_2, |
| 2007 | &ip_o_10_10_10_2, |
| 2008 | &ip_o_10_10_10_2, |
| 2009 | &ip_o_10_10_10_2, |
| 2010 | &ip_o_10_10_10_2, |
| 2011 | &ip_o_10_10_10_2, |
| 2012 | &ip_o_10_10_10_2, |
| 2013 | &ip_o_10_10_10_2, |
| 2014 | &ip_o_10_10_10_2, |
| 2015 | &ip_o_10_10_10_2, |
| 2016 | &ip_o_10_10_10_2, |
| 2017 | &ip_o_10_10_10_2, |
| 2018 | &ip_o_10_10_10_2, |
| 2019 | &ip_o_10_10_10_2, |
| 2020 | &ip_o_10_10_10_2, |
| 2021 | &ip_o_10_10_10_2, |
| 2022 | &ip_o_10_10_10_2, |
| 2023 | &ip_o_10_10_10_2, |
| 2024 | &ip_o_10_10_10_2, |
| 2025 | &ip_o_10_10_10_2, |
| 2026 | &ip_o_10_10_10_2, |
| 2027 | &ip_o_10_10_10_2, |
| 2028 | &ip_o_10_10_10_2, |
| 2029 | &ip_o_10_10_10_2, |
| 2030 | &ip_o_10_10_10_2, |
| 2031 | &ip_o_10_10_10_2, |
| 2032 | &ip_o_10_10_10_2, |
| 2033 | &ip_o_10_10_10_2, |
| 2034 | &ip_o_10_10_10_2, |
| 2035 | &ip_o_10_10_10_1), |
| 2036 | "6.6.6.6/32 via 10.10.10.1 and 10.10.10.2 in 63:1 ratio"); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 2037 | |
| 2038 | fib_table_entry_path_remove(fib_index, |
| 2039 | &pfx_6_6_6_6_s_32, |
| 2040 | FIB_SOURCE_API, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 2041 | DPO_PROTO_IP4, |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 2042 | &nh_10_10_10_2, |
| 2043 | tm->hw[0]->sw_if_index, |
| 2044 | ~0, // invalid fib index |
| 2045 | 100, |
| 2046 | FIB_ROUTE_PATH_FLAG_NONE); |
| 2047 | |
| 2048 | fei = fib_table_lookup(fib_index, &pfx_6_6_6_6_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2049 | FIB_TEST(!fib_test_validate_entry(fei, |
| 2050 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 2051 | 1, |
| 2052 | &ip_o_10_10_10_1), |
| 2053 | "6.6.6.6/32 via 10.10.10.1"); |
Neale Ranns | 0bd36ea | 2016-11-16 11:47:44 +0000 | [diff] [blame] | 2054 | |
| 2055 | fib_table_entry_delete(fib_index, &pfx_6_6_6_6_s_32, FIB_SOURCE_API); |
| 2056 | |
| 2057 | /* |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2058 | * A recursive via the two unequal cost entries |
| 2059 | */ |
| 2060 | fib_prefix_t bgp_44_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2061 | .fp_len = 32, |
| 2062 | .fp_proto = FIB_PROTOCOL_IP4, |
| 2063 | .fp_addr = { |
| 2064 | /* 200.200.200.201/32 */ |
| 2065 | .ip4.as_u32 = clib_host_to_net_u32(0x44444444), |
| 2066 | }, |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2067 | }; |
| 2068 | fei = fib_table_entry_path_add(fib_index, |
| 2069 | &bgp_44_s_32, |
| 2070 | FIB_SOURCE_API, |
| 2071 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2072 | DPO_PROTO_IP4, |
| 2073 | &pfx_1_2_3_4_s_32.fp_addr, |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2074 | ~0, |
| 2075 | fib_index, |
| 2076 | 1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 2077 | NULL, |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2078 | FIB_ROUTE_PATH_FLAG_NONE); |
| 2079 | fei = fib_table_entry_path_add(fib_index, |
| 2080 | &bgp_44_s_32, |
| 2081 | FIB_SOURCE_API, |
| 2082 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2083 | DPO_PROTO_IP4, |
| 2084 | &pfx_1_2_3_5_s_32.fp_addr, |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2085 | ~0, |
| 2086 | fib_index, |
| 2087 | 1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 2088 | NULL, |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2089 | FIB_ROUTE_PATH_FLAG_NONE); |
| 2090 | |
| 2091 | FIB_TEST_REC_FORW(&bgp_44_s_32, &pfx_1_2_3_4_s_32, 0); |
| 2092 | FIB_TEST_REC_FORW(&bgp_44_s_32, &pfx_1_2_3_5_s_32, 1); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2093 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 2, |
| 2094 | tm->hw[0]->sw_if_index, |
| 2095 | tm->hw[1]->sw_if_index), |
| 2096 | "RPF list for 1.2.3.4/32 contains both adjs"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2097 | |
| 2098 | /* |
| 2099 | * test the uRPF check functions |
| 2100 | */ |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 2101 | dpo_id_t dpo_44 = DPO_INVALID; |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2102 | index_t urpfi; |
| 2103 | |
| 2104 | fib_entry_contribute_forwarding(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, &dpo_44); |
| 2105 | urpfi = load_balance_get_urpf(dpo_44.dpoi_index); |
| 2106 | |
| 2107 | FIB_TEST(fib_urpf_check(urpfi, tm->hw[0]->sw_if_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2108 | "uRPF check for 68.68.68.68/32 on %d OK", |
| 2109 | tm->hw[0]->sw_if_index); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2110 | FIB_TEST(fib_urpf_check(urpfi, tm->hw[1]->sw_if_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2111 | "uRPF check for 68.68.68.68/32 on %d OK", |
| 2112 | tm->hw[1]->sw_if_index); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2113 | FIB_TEST(!fib_urpf_check(urpfi, 99), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2114 | "uRPF check for 68.68.68.68/32 on 99 not-OK", |
| 2115 | 99); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2116 | dpo_reset(&dpo_44); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2117 | |
| 2118 | fib_table_entry_delete(fib_index, |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2119 | &bgp_44_s_32, |
| 2120 | FIB_SOURCE_API); |
| 2121 | fib_table_entry_delete(fib_index, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2122 | &pfx_1_2_3_5_s_32, |
| 2123 | FIB_SOURCE_API); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2124 | fib_table_entry_delete(fib_index, |
| 2125 | &pfx_1_2_3_4_s_32, |
| 2126 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2127 | |
| 2128 | /* |
| 2129 | * Add a recursive route: |
| 2130 | * 200.200.200.201/32 via 1.1.1.200/32 => the via entry is NOT installed. |
| 2131 | */ |
| 2132 | fib_prefix_t bgp_201_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2133 | .fp_len = 32, |
| 2134 | .fp_proto = FIB_PROTOCOL_IP4, |
| 2135 | .fp_addr = { |
| 2136 | /* 200.200.200.201/32 */ |
| 2137 | .ip4.as_u32 = clib_host_to_net_u32(0xc8c8c8c9), |
| 2138 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2139 | }; |
| 2140 | /* via 1.1.1.200 */ |
| 2141 | fib_prefix_t pfx_1_1_1_200_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2142 | .fp_len = 32, |
| 2143 | .fp_proto = FIB_PROTOCOL_IP4, |
| 2144 | .fp_addr = { |
| 2145 | .ip4.as_u32 = clib_host_to_net_u32(0x010101c8), |
| 2146 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2147 | }; |
| 2148 | |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 2149 | fei = fib_table_entry_path_add(fib_index, |
| 2150 | &bgp_201_pfx, |
| 2151 | FIB_SOURCE_API, |
| 2152 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 2153 | DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 2154 | &pfx_1_1_1_200_s_32.fp_addr, |
| 2155 | ~0, // no index provided. |
| 2156 | fib_index, // nexthop in same fib as route |
| 2157 | 1, |
| 2158 | NULL, |
| 2159 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2160 | |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 2161 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 2162 | "Recursive via unresolved is drop"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2163 | |
| 2164 | fei = fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_200_s_32); |
| 2165 | FIB_TEST((FIB_ENTRY_FLAG_NONE == fib_entry_get_flags(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2166 | "Flags set on RR via non-attached"); |
| 2167 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 0), |
| 2168 | "RPF list for BGP route empty"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2169 | |
| 2170 | /* |
| 2171 | * +2 entry (BGP & RR) and +1 shared-path-list |
| 2172 | */ |
| 2173 | FIB_TEST((4 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2174 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2175 | FIB_TEST((PNBR+8 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2176 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2177 | FIB_TEST((ENBR+12 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2178 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2179 | |
| 2180 | /* |
| 2181 | * insert a route that covers the missing 1.1.1.2/32. we epxect |
| 2182 | * 200.200.200.200/32 and 200.200.200.201/32 to resolve through it. |
| 2183 | */ |
| 2184 | fib_prefix_t pfx_1_1_1_0_s_24 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2185 | .fp_len = 24, |
| 2186 | .fp_proto = FIB_PROTOCOL_IP4, |
| 2187 | .fp_addr = { |
| 2188 | /* 1.1.1.0/24 */ |
| 2189 | .ip4.as_u32 = clib_host_to_net_u32(0x01010100), |
| 2190 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2191 | }; |
| 2192 | |
| 2193 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2194 | &pfx_1_1_1_0_s_24, |
| 2195 | FIB_SOURCE_API, |
| 2196 | FIB_ENTRY_FLAG_NONE, |
| 2197 | DPO_PROTO_IP4, |
| 2198 | &nh_10_10_10_1, |
| 2199 | tm->hw[0]->sw_if_index, |
| 2200 | ~0, // invalid fib index |
| 2201 | 1, |
| 2202 | NULL, |
| 2203 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2204 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_0_s_24); |
| 2205 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 2206 | ai = fib_entry_get_adj(fei); |
| 2207 | FIB_TEST((ai_01 == ai), "1.1.1.0/24 resolves via 10.10.10.1"); |
| 2208 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_2_s_32); |
| 2209 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 2210 | ai = fib_entry_get_adj(fei); |
| 2211 | FIB_TEST((ai_01 == ai), "1.1.1.2/32 resolves via 10.10.10.1"); |
| 2212 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_200_s_32); |
| 2213 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 2214 | ai = fib_entry_get_adj(fei); |
| 2215 | FIB_TEST((ai_01 == ai), "1.1.1.200/24 resolves via 10.10.10.1"); |
| 2216 | |
| 2217 | /* |
| 2218 | * +1 entry. 1.1.1.1/32 already uses 10.10.10.1 so no new pah-list |
| 2219 | */ |
| 2220 | FIB_TEST((4 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2221 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2222 | FIB_TEST((PNBR+8 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2223 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2224 | FIB_TEST((ENBR+13 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2225 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2226 | |
| 2227 | /* |
| 2228 | * the recursive adj for 200.200.200.200 should be updated. |
| 2229 | */ |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2230 | FIB_TEST_REC_FORW(&bgp_201_pfx, &pfx_1_1_1_200_s_32, 0); |
| 2231 | FIB_TEST_REC_FORW(&bgp_200_pfx, &pfx_1_1_1_2_s_32, 0); |
| 2232 | fei = fib_table_lookup(fib_index, &bgp_200_pfx); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2233 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 1, |
| 2234 | tm->hw[0]->sw_if_index), |
| 2235 | "RPF list for BGP route has itf index 0"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2236 | |
| 2237 | /* |
| 2238 | * insert a more specific route than 1.1.1.0/24 that also covers the |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2239 | * missing 1.1.1.2/32, but not 1.1.1.200/32. we expect |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2240 | * 200.200.200.200 to resolve through it. |
| 2241 | */ |
| 2242 | fib_prefix_t pfx_1_1_1_0_s_28 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2243 | .fp_len = 28, |
| 2244 | .fp_proto = FIB_PROTOCOL_IP4, |
| 2245 | .fp_addr = { |
| 2246 | /* 1.1.1.0/24 */ |
| 2247 | .ip4.as_u32 = clib_host_to_net_u32(0x01010100), |
| 2248 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2249 | }; |
| 2250 | |
| 2251 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2252 | &pfx_1_1_1_0_s_28, |
| 2253 | FIB_SOURCE_API, |
| 2254 | FIB_ENTRY_FLAG_NONE, |
| 2255 | DPO_PROTO_IP4, |
| 2256 | &nh_10_10_10_2, |
| 2257 | tm->hw[0]->sw_if_index, |
| 2258 | ~0, // invalid fib index |
| 2259 | 1, |
| 2260 | NULL, |
| 2261 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2262 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_0_s_28); |
| 2263 | dpo2 = fib_entry_contribute_ip_forwarding(fei); |
| 2264 | ai = fib_entry_get_adj(fei); |
| 2265 | FIB_TEST((ai_02 == ai), "1.1.1.0/24 resolves via 10.10.10.2"); |
| 2266 | |
| 2267 | /* |
| 2268 | * +1 entry. +1 shared path-list |
| 2269 | */ |
| 2270 | FIB_TEST((5 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2271 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2272 | FIB_TEST((PNBR+9 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2273 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2274 | FIB_TEST((ENBR+14 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2275 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2276 | |
| 2277 | /* |
| 2278 | * the recursive adj for 200.200.200.200 should be updated. |
| 2279 | * 200.200.200.201 remains unchanged. |
| 2280 | */ |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2281 | FIB_TEST_REC_FORW(&bgp_201_pfx, &pfx_1_1_1_200_s_32, 0); |
| 2282 | FIB_TEST_REC_FORW(&bgp_200_pfx, &pfx_1_1_1_2_s_32, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2283 | |
| 2284 | /* |
| 2285 | * remove this /28. 200.200.200.200/32 should revert back to via 1.1.1.0/24 |
| 2286 | */ |
| 2287 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2288 | &pfx_1_1_1_0_s_28, |
| 2289 | FIB_SOURCE_API, |
| 2290 | DPO_PROTO_IP4, |
| 2291 | &nh_10_10_10_2, |
| 2292 | tm->hw[0]->sw_if_index, |
| 2293 | ~0, |
| 2294 | 1, |
| 2295 | FIB_ROUTE_PATH_FLAG_NONE); |
| 2296 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_0_s_28) == |
| 2297 | FIB_NODE_INDEX_INVALID), |
| 2298 | "1.1.1.0/28 removed"); |
| 2299 | FIB_TEST((fib_table_lookup(fib_index, &pfx_1_1_1_0_s_28) == |
| 2300 | fib_table_lookup(fib_index, &pfx_1_1_1_0_s_24)), |
| 2301 | "1.1.1.0/28 lookup via /24"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2302 | FIB_TEST_REC_FORW(&bgp_201_pfx, &pfx_1_1_1_200_s_32, 0); |
| 2303 | FIB_TEST_REC_FORW(&bgp_200_pfx, &pfx_1_1_1_2_s_32, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2304 | |
| 2305 | /* |
| 2306 | * -1 entry. -1 shared path-list |
| 2307 | */ |
| 2308 | FIB_TEST((4 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2309 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2310 | FIB_TEST((PNBR+8 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2311 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2312 | FIB_TEST((ENBR+13 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2313 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2314 | |
| 2315 | /* |
| 2316 | * remove 1.1.1.0/24. 200.200.200.200/32 should revert back to via 0.0.0.0/0 |
| 2317 | */ |
| 2318 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2319 | &pfx_1_1_1_0_s_24, |
| 2320 | FIB_SOURCE_API, |
| 2321 | DPO_PROTO_IP4, |
| 2322 | &nh_10_10_10_1, |
| 2323 | tm->hw[0]->sw_if_index, |
| 2324 | ~0, |
| 2325 | 1, |
| 2326 | FIB_ROUTE_PATH_FLAG_NONE); |
| 2327 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_0_s_24) == |
| 2328 | FIB_NODE_INDEX_INVALID), |
| 2329 | "1.1.1.0/24 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2330 | |
| 2331 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_2_s_32); |
| 2332 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2333 | "1.1.1.2/32 route is DROP"); |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 2334 | fei = fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_200_s_32); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2335 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2336 | "1.1.1.200/32 route is DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2337 | |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 2338 | fei = fib_table_lookup_exact_match(fib_index, &bgp_201_pfx); |
| 2339 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 2340 | "201 is drop"); |
| 2341 | fei = fib_table_lookup_exact_match(fib_index, &bgp_200_pfx); |
| 2342 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 2343 | "200 is drop"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2344 | |
| 2345 | /* |
| 2346 | * -1 entry |
| 2347 | */ |
| 2348 | FIB_TEST((4 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2349 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2350 | FIB_TEST((PNBR+8 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2351 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2352 | FIB_TEST((ENBR+12 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2353 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2354 | |
| 2355 | /* |
| 2356 | * insert the missing 1.1.1.2/32 |
| 2357 | */ |
| 2358 | fei = fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2359 | &pfx_1_1_1_2_s_32, |
| 2360 | FIB_SOURCE_API, |
| 2361 | FIB_ENTRY_FLAG_NONE, |
| 2362 | DPO_PROTO_IP4, |
| 2363 | &nh_10_10_10_1, |
| 2364 | tm->hw[0]->sw_if_index, |
| 2365 | ~0, // invalid fib index |
| 2366 | 1, |
| 2367 | NULL, |
| 2368 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2369 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 2370 | ai = fib_entry_get_adj(fei); |
| 2371 | FIB_TEST((ai = ai_01), "1.1.1.2/32 resolves via 10.10.10.1"); |
| 2372 | |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 2373 | fei = fib_table_lookup_exact_match(fib_index, &bgp_201_pfx); |
| 2374 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 2375 | "201 is drop"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 2376 | FIB_TEST_REC_FORW(&bgp_200_pfx, &pfx_1_1_1_2_s_32, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2377 | |
| 2378 | /* |
| 2379 | * no change. 1.1.1.2/32 was already there RR sourced. |
| 2380 | */ |
| 2381 | FIB_TEST((4 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2382 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2383 | FIB_TEST((PNBR+8 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2384 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2385 | FIB_TEST((ENBR+12 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2386 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2387 | |
| 2388 | /* |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 2389 | * give 201 a resolved path. |
| 2390 | * it now has the unresolved 1.1.1.200 and the resolved 1.1.1.2, |
| 2391 | * only the latter contributes forwarding. |
| 2392 | */ |
| 2393 | fei = fib_table_entry_path_add(fib_index, |
| 2394 | &bgp_201_pfx, |
| 2395 | FIB_SOURCE_API, |
| 2396 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 2397 | DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 2398 | &pfx_1_1_1_2_s_32.fp_addr, |
| 2399 | ~0, |
| 2400 | fib_index, |
| 2401 | 1, |
| 2402 | NULL, |
| 2403 | FIB_ROUTE_PATH_FLAG_NONE); |
| 2404 | FIB_TEST_REC_FORW(&bgp_201_pfx, &pfx_1_1_1_2_s_32, 0); |
| 2405 | fib_table_entry_path_remove(fib_index, |
| 2406 | &bgp_201_pfx, |
| 2407 | FIB_SOURCE_API, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 2408 | DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 2409 | &pfx_1_1_1_2_s_32.fp_addr, |
| 2410 | ~0, |
| 2411 | fib_index, |
| 2412 | 1, |
| 2413 | FIB_ROUTE_PATH_FLAG_NONE); |
| 2414 | |
| 2415 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2416 | * remove 200.200.200.201/32 which does not have a valid via FIB |
| 2417 | */ |
| 2418 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2419 | &bgp_201_pfx, |
| 2420 | FIB_SOURCE_API, |
| 2421 | DPO_PROTO_IP4, |
| 2422 | &pfx_1_1_1_200_s_32.fp_addr, |
| 2423 | ~0, // no index provided. |
| 2424 | fib_index, |
| 2425 | 1, |
| 2426 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2427 | |
| 2428 | /* |
| 2429 | * -2 entries (BGP and RR). -1 shared path-list; |
| 2430 | */ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2431 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &bgp_201_pfx) == |
| 2432 | FIB_NODE_INDEX_INVALID), |
| 2433 | "200.200.200.201/32 removed"); |
| 2434 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_200_s_32) == |
| 2435 | FIB_NODE_INDEX_INVALID), |
| 2436 | "1.1.1.200/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2437 | |
| 2438 | FIB_TEST((3 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2439 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2440 | FIB_TEST((PNBR+7 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2441 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2442 | FIB_TEST((ENBR+10 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2443 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2444 | |
| 2445 | /* |
| 2446 | * remove 200.200.200.200/32 which does have a valid via FIB |
| 2447 | */ |
| 2448 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2449 | &bgp_200_pfx, |
| 2450 | FIB_SOURCE_API, |
| 2451 | DPO_PROTO_IP4, |
| 2452 | &pfx_1_1_1_2_s_32.fp_addr, |
| 2453 | ~0, // no index provided. |
| 2454 | fib_index, |
| 2455 | 1, |
| 2456 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2457 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2458 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &bgp_200_pfx) == |
| 2459 | FIB_NODE_INDEX_INVALID), |
| 2460 | "200.200.200.200/32 removed"); |
| 2461 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_2_s_32) != |
| 2462 | FIB_NODE_INDEX_INVALID), |
| 2463 | "1.1.1.2/32 still present"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2464 | |
| 2465 | /* |
| 2466 | * -1 entry (BGP, the RR source is also API sourced). -1 shared path-list; |
| 2467 | */ |
| 2468 | FIB_TEST((2 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2469 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2470 | FIB_TEST((PNBR+6 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2471 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2472 | FIB_TEST((ENBR+9 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2473 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2474 | |
| 2475 | /* |
| 2476 | * A recursive prefix that has a 2 path load-balance. |
| 2477 | * It also shares a next-hop with other BGP prefixes and hence |
| 2478 | * test the ref counting of RR sourced prefixes and 2 level LB. |
| 2479 | */ |
| 2480 | const fib_prefix_t bgp_102 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2481 | .fp_len = 32, |
| 2482 | .fp_proto = FIB_PROTOCOL_IP4, |
| 2483 | .fp_addr = { |
| 2484 | /* 100.100.100.101/32 */ |
| 2485 | .ip4.as_u32 = clib_host_to_net_u32(0x64646466), |
| 2486 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2487 | }; |
| 2488 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2489 | &bgp_102, |
| 2490 | FIB_SOURCE_API, |
| 2491 | FIB_ENTRY_FLAG_NONE, |
| 2492 | DPO_PROTO_IP4, |
| 2493 | &pfx_1_1_1_1_s_32.fp_addr, |
| 2494 | ~0, // no index provided. |
| 2495 | fib_index, // same as route |
| 2496 | 1, |
| 2497 | NULL, |
| 2498 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2499 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2500 | &bgp_102, |
| 2501 | FIB_SOURCE_API, |
| 2502 | FIB_ENTRY_FLAG_NONE, |
| 2503 | DPO_PROTO_IP4, |
| 2504 | &pfx_1_1_1_2_s_32.fp_addr, |
| 2505 | ~0, // no index provided. |
| 2506 | fib_index, // same as route's FIB |
| 2507 | 1, |
| 2508 | NULL, |
| 2509 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2510 | fei = fib_table_lookup_exact_match(fib_index, &bgp_102); |
| 2511 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "100.100.100.102/32 presnet"); |
| 2512 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 2513 | |
| 2514 | fei = fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_1_s_32); |
| 2515 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 2516 | fei = fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_2_s_32); |
| 2517 | dpo2 = fib_entry_contribute_ip_forwarding(fei); |
| 2518 | |
| 2519 | lb = load_balance_get(dpo->dpoi_index); |
| 2520 | FIB_TEST((lb->lb_n_buckets == 2), "Recursive LB has %d bucket", lb->lb_n_buckets); |
| 2521 | FIB_TEST(!dpo_cmp(dpo1, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2522 | "First via 10.10.10.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2523 | FIB_TEST(!dpo_cmp(dpo2, load_balance_get_bucket(dpo->dpoi_index, 1)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2524 | "Second via 10.10.10.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2525 | |
| 2526 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2527 | &bgp_102, |
| 2528 | FIB_SOURCE_API, |
| 2529 | DPO_PROTO_IP4, |
| 2530 | &pfx_1_1_1_1_s_32.fp_addr, |
| 2531 | ~0, // no index provided. |
| 2532 | fib_index, // same as route's FIB |
| 2533 | 1, |
| 2534 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2535 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2536 | &bgp_102, |
| 2537 | FIB_SOURCE_API, |
| 2538 | DPO_PROTO_IP4, |
| 2539 | &pfx_1_1_1_2_s_32.fp_addr, |
| 2540 | ~0, // no index provided. |
| 2541 | fib_index, // same as route's FIB |
| 2542 | 1, |
| 2543 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2544 | fei = fib_table_lookup_exact_match(fib_index, &bgp_102); |
| 2545 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "100.100.100.102/32 removed"); |
| 2546 | |
| 2547 | /* |
| 2548 | * remove the remaining recursives |
| 2549 | */ |
| 2550 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2551 | &bgp_100_pfx, |
| 2552 | FIB_SOURCE_API, |
| 2553 | DPO_PROTO_IP4, |
| 2554 | &pfx_1_1_1_1_s_32.fp_addr, |
| 2555 | ~0, // no index provided. |
| 2556 | fib_index, // same as route's FIB |
| 2557 | 1, |
| 2558 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2559 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2560 | &bgp_101_pfx, |
| 2561 | FIB_SOURCE_API, |
| 2562 | DPO_PROTO_IP4, |
| 2563 | &pfx_1_1_1_1_s_32.fp_addr, |
| 2564 | ~0, // no index provided. |
| 2565 | fib_index, // same as route's FIB |
| 2566 | 1, |
| 2567 | FIB_ROUTE_PATH_FLAG_NONE); |
| 2568 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &bgp_100_pfx) == |
| 2569 | FIB_NODE_INDEX_INVALID), |
| 2570 | "100.100.100.100/32 removed"); |
| 2571 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &bgp_101_pfx) == |
| 2572 | FIB_NODE_INDEX_INVALID), |
| 2573 | "100.100.100.101/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2574 | |
| 2575 | /* |
| 2576 | * -2 entry (2*BGP, the RR source is also API sourced). -1 shared path-list; |
| 2577 | */ |
| 2578 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2579 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2580 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2581 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2582 | FIB_TEST((ENBR+7 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2583 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2584 | |
| 2585 | /* |
| 2586 | * Add a recursive route via a connected cover, using an adj-fib that does exist |
| 2587 | */ |
| 2588 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2589 | &bgp_200_pfx, |
| 2590 | FIB_SOURCE_API, |
| 2591 | FIB_ENTRY_FLAG_NONE, |
| 2592 | DPO_PROTO_IP4, |
| 2593 | &nh_10_10_10_1, |
| 2594 | ~0, // no index provided. |
| 2595 | fib_index, // Same as route's FIB |
| 2596 | 1, |
| 2597 | NULL, |
| 2598 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2599 | |
| 2600 | /* |
| 2601 | * +1 entry. +1 shared path-list (recursive via 10.10.10.1) |
| 2602 | */ |
| 2603 | FIB_TEST((2 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2604 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2605 | FIB_TEST((PNBR+6 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2606 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2607 | FIB_TEST((ENBR+8 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2608 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2609 | |
| 2610 | fei = fib_table_lookup_exact_match(fib_index, &bgp_200_pfx); |
| 2611 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 2612 | |
| 2613 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_1_s_32); |
| 2614 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 2615 | |
| 2616 | FIB_TEST(!dpo_cmp(dpo1, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2617 | "200.200.200.200/32 is recursive via adj for 10.10.10.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2618 | |
| 2619 | FIB_TEST((FIB_ENTRY_FLAG_ATTACHED == fib_entry_get_flags(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2620 | "Flags set on RR via existing attached"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2621 | |
| 2622 | /* |
| 2623 | * Add a recursive route via a connected cover, using and adj-fib that does |
| 2624 | * not exist |
| 2625 | */ |
| 2626 | ip46_address_t nh_10_10_10_3 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2627 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a03), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2628 | }; |
| 2629 | fib_prefix_t pfx_10_10_10_3 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2630 | .fp_len = 32, |
| 2631 | .fp_proto = FIB_PROTOCOL_IP4, |
| 2632 | .fp_addr = nh_10_10_10_3, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2633 | }; |
| 2634 | |
| 2635 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2636 | &bgp_201_pfx, |
| 2637 | FIB_SOURCE_API, |
| 2638 | FIB_ENTRY_FLAG_NONE, |
| 2639 | DPO_PROTO_IP4, |
| 2640 | &nh_10_10_10_3, |
| 2641 | ~0, // no index provided. |
| 2642 | fib_index, |
| 2643 | 1, |
| 2644 | NULL, |
| 2645 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2646 | |
| 2647 | /* |
| 2648 | * +2 entries (BGP and RR). +1 shared path-list (recursive via 10.10.10.3) and |
| 2649 | * one unshared non-recursive via 10.10.10.3 |
| 2650 | */ |
| 2651 | FIB_TEST((3 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2652 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2653 | FIB_TEST((PNBR+8 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2654 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2655 | FIB_TEST((ENBR+10 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2656 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2657 | |
| 2658 | ai_03 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2659 | VNET_LINK_IP4, |
| 2660 | &nh_10_10_10_3, |
| 2661 | tm->hw[0]->sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2662 | |
| 2663 | fei = fib_table_lookup_exact_match(fib_index, &bgp_201_pfx); |
| 2664 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 2665 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_3); |
| 2666 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 2667 | |
| 2668 | ai = fib_entry_get_adj(fei); |
| 2669 | FIB_TEST((ai == ai_03), "adj for 10.10.10.3/32 is via adj for 10.10.10.3"); |
| 2670 | FIB_TEST(((FIB_ENTRY_FLAG_ATTACHED | FIB_ENTRY_FLAG_CONNECTED) == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2671 | fib_entry_get_flags(fei)), |
| 2672 | "Flags set on RR via non-existing attached"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2673 | |
| 2674 | FIB_TEST(!dpo_cmp(dpo1, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2675 | "adj for 200.200.200.200/32 is recursive via adj for 10.10.10.3"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2676 | |
| 2677 | adj_unlock(ai_03); |
| 2678 | |
| 2679 | /* |
| 2680 | * remove the recursives |
| 2681 | */ |
| 2682 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2683 | &bgp_200_pfx, |
| 2684 | FIB_SOURCE_API, |
| 2685 | DPO_PROTO_IP4, |
| 2686 | &nh_10_10_10_1, |
| 2687 | ~0, // no index provided. |
| 2688 | fib_index, // same as route's FIB |
| 2689 | 1, |
| 2690 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2691 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2692 | &bgp_201_pfx, |
| 2693 | FIB_SOURCE_API, |
| 2694 | DPO_PROTO_IP4, |
| 2695 | &nh_10_10_10_3, |
| 2696 | ~0, // no index provided. |
| 2697 | fib_index, // same as route's FIB |
| 2698 | 1, |
| 2699 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2700 | |
| 2701 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &bgp_201_pfx) == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2702 | FIB_NODE_INDEX_INVALID), |
| 2703 | "200.200.200.201/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2704 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &bgp_200_pfx) == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2705 | FIB_NODE_INDEX_INVALID), |
| 2706 | "200.200.200.200/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2707 | FIB_TEST((fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_3) == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2708 | FIB_NODE_INDEX_INVALID), |
| 2709 | "10.10.10.3/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2710 | |
| 2711 | /* |
| 2712 | * -3 entries (2*BGP and RR). -2 shared path-list (recursive via 10.10.10.3 & |
| 2713 | * 10.10.10.1) and one unshared non-recursive via 10.10.10.3 |
| 2714 | */ |
| 2715 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2716 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2717 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2718 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2719 | FIB_TEST((ENBR+7 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2720 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2721 | |
| 2722 | |
| 2723 | /* |
| 2724 | * RECURSION LOOPS |
| 2725 | * Add 5.5.5.5/32 -> 5.5.5.6/32 -> 5.5.5.7/32 -> 5.5.5.5/32 |
| 2726 | */ |
| 2727 | fib_prefix_t pfx_5_5_5_5_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2728 | .fp_len = 32, |
| 2729 | .fp_proto = FIB_PROTOCOL_IP4, |
| 2730 | .fp_addr = { |
| 2731 | .ip4.as_u32 = clib_host_to_net_u32(0x05050505), |
| 2732 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2733 | }; |
| 2734 | fib_prefix_t pfx_5_5_5_6_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2735 | .fp_len = 32, |
| 2736 | .fp_proto = FIB_PROTOCOL_IP4, |
| 2737 | .fp_addr = { |
| 2738 | .ip4.as_u32 = clib_host_to_net_u32(0x05050506), |
| 2739 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2740 | }; |
| 2741 | fib_prefix_t pfx_5_5_5_7_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2742 | .fp_len = 32, |
| 2743 | .fp_proto = FIB_PROTOCOL_IP4, |
| 2744 | .fp_addr = { |
| 2745 | .ip4.as_u32 = clib_host_to_net_u32(0x05050507), |
| 2746 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2747 | }; |
| 2748 | |
| 2749 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2750 | &pfx_5_5_5_5_s_32, |
| 2751 | FIB_SOURCE_API, |
| 2752 | FIB_ENTRY_FLAG_NONE, |
| 2753 | DPO_PROTO_IP4, |
| 2754 | &pfx_5_5_5_6_s_32.fp_addr, |
| 2755 | ~0, // no index provided. |
| 2756 | fib_index, |
| 2757 | 1, |
| 2758 | NULL, |
| 2759 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2760 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2761 | &pfx_5_5_5_6_s_32, |
| 2762 | FIB_SOURCE_API, |
| 2763 | FIB_ENTRY_FLAG_NONE, |
| 2764 | DPO_PROTO_IP4, |
| 2765 | &pfx_5_5_5_7_s_32.fp_addr, |
| 2766 | ~0, // no index provided. |
| 2767 | fib_index, |
| 2768 | 1, |
| 2769 | NULL, |
| 2770 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2771 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2772 | &pfx_5_5_5_7_s_32, |
| 2773 | FIB_SOURCE_API, |
| 2774 | FIB_ENTRY_FLAG_NONE, |
| 2775 | DPO_PROTO_IP4, |
| 2776 | &pfx_5_5_5_5_s_32.fp_addr, |
| 2777 | ~0, // no index provided. |
| 2778 | fib_index, |
| 2779 | 1, |
| 2780 | NULL, |
| 2781 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2782 | /* |
| 2783 | * +3 entries, +3 shared path-list |
| 2784 | */ |
| 2785 | FIB_TEST((4 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2786 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2787 | FIB_TEST((PNBR+8 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2788 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2789 | FIB_TEST((ENBR+10 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2790 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2791 | |
| 2792 | /* |
| 2793 | * All the entries have only looped paths, so they are all drop |
| 2794 | */ |
| 2795 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_7_s_32); |
| 2796 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2797 | "LB for 5.5.5.7/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2798 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_5_s_32); |
| 2799 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2800 | "LB for 5.5.5.5/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2801 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_6_s_32); |
| 2802 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2803 | "LB for 5.5.5.6/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2804 | |
| 2805 | /* |
| 2806 | * provide 5.5.5.6/32 with alternate path. |
| 2807 | * this will allow only 5.5.5.6/32 to forward with this path, the others |
| 2808 | * are still drop since the loop is still present. |
| 2809 | */ |
| 2810 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2811 | &pfx_5_5_5_6_s_32, |
| 2812 | FIB_SOURCE_API, |
| 2813 | FIB_ENTRY_FLAG_NONE, |
| 2814 | DPO_PROTO_IP4, |
| 2815 | &nh_10_10_10_1, |
| 2816 | tm->hw[0]->sw_if_index, |
| 2817 | ~0, |
| 2818 | 1, |
| 2819 | NULL, |
| 2820 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2821 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2822 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_6_s_32); |
| 2823 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 2824 | |
| 2825 | lb = load_balance_get(dpo1->dpoi_index); |
| 2826 | FIB_TEST((lb->lb_n_buckets == 1), "5.5.5.6 LB has %d bucket", lb->lb_n_buckets); |
| 2827 | |
| 2828 | dpo2 = load_balance_get_bucket(dpo1->dpoi_index, 0); |
| 2829 | FIB_TEST(DPO_ADJACENCY == dpo2->dpoi_type, "type is %d", dpo2->dpoi_type); |
| 2830 | FIB_TEST((ai_01 == dpo2->dpoi_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2831 | "5.5.5.6 bucket 0 resolves via 10.10.10.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2832 | |
| 2833 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_7_s_32); |
| 2834 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2835 | "LB for 5.5.5.7/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2836 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_5_s_32); |
| 2837 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2838 | "LB for 5.5.5.5/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2839 | |
| 2840 | /* |
| 2841 | * remove the alternate path for 5.5.5.6/32 |
| 2842 | * back to all drop |
| 2843 | */ |
| 2844 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2845 | &pfx_5_5_5_6_s_32, |
| 2846 | FIB_SOURCE_API, |
| 2847 | DPO_PROTO_IP4, |
| 2848 | &nh_10_10_10_1, |
| 2849 | tm->hw[0]->sw_if_index, |
| 2850 | ~0, |
| 2851 | 1, |
| 2852 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2853 | |
| 2854 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_7_s_32); |
| 2855 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2856 | "LB for 5.5.5.7/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2857 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_5_s_32); |
| 2858 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2859 | "LB for 5.5.5.5/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2860 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_6_s_32); |
| 2861 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2862 | "LB for 5.5.5.6/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2863 | |
| 2864 | /* |
| 2865 | * break the loop by giving 5.5.5.5/32 a new set of paths |
| 2866 | * expect all to forward via this new path. |
| 2867 | */ |
| 2868 | fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2869 | &pfx_5_5_5_5_s_32, |
| 2870 | FIB_SOURCE_API, |
| 2871 | FIB_ENTRY_FLAG_NONE, |
| 2872 | DPO_PROTO_IP4, |
| 2873 | &nh_10_10_10_1, |
| 2874 | tm->hw[0]->sw_if_index, |
| 2875 | ~0, // invalid fib index |
| 2876 | 1, |
| 2877 | NULL, |
| 2878 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2879 | |
| 2880 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_5_s_32); |
| 2881 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 2882 | lb = load_balance_get(dpo1->dpoi_index); |
| 2883 | FIB_TEST((lb->lb_n_buckets == 1), "5.5.5.5 LB has %d bucket", lb->lb_n_buckets); |
| 2884 | |
| 2885 | dpo2 = load_balance_get_bucket(dpo1->dpoi_index, 0); |
| 2886 | FIB_TEST(DPO_ADJACENCY == dpo2->dpoi_type, "type is %d", dpo2->dpoi_type); |
| 2887 | FIB_TEST((ai_01 == dpo2->dpoi_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2888 | "5.5.5.5 bucket 0 resolves via 10.10.10.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2889 | |
| 2890 | fei = fib_table_lookup_exact_match(fib_index, &pfx_5_5_5_7_s_32); |
| 2891 | dpo2 = fib_entry_contribute_ip_forwarding(fei); |
| 2892 | |
| 2893 | lb = load_balance_get(dpo2->dpoi_index); |
| 2894 | FIB_TEST((lb->lb_n_buckets == 1), "Recursive LB has %d bucket", lb->lb_n_buckets); |
| 2895 | FIB_TEST(!dpo_cmp(dpo1, load_balance_get_bucket(dpo2->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2896 | "5.5.5.5.7 via 5.5.5.5"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2897 | |
| 2898 | fei = fib_table_lookup_exact_match(fib_index, &pfx_5_5_5_6_s_32); |
| 2899 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 2900 | |
| 2901 | lb = load_balance_get(dpo1->dpoi_index); |
| 2902 | FIB_TEST((lb->lb_n_buckets == 1), "Recursive LB has %d bucket", lb->lb_n_buckets); |
| 2903 | FIB_TEST(!dpo_cmp(dpo2, load_balance_get_bucket(dpo1->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2904 | "5.5.5.5.6 via 5.5.5.7"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2905 | |
| 2906 | /* |
| 2907 | * revert back to the loop. so we can remove the prefixes with |
| 2908 | * the loop intact |
| 2909 | */ |
| 2910 | fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2911 | &pfx_5_5_5_5_s_32, |
| 2912 | FIB_SOURCE_API, |
| 2913 | FIB_ENTRY_FLAG_NONE, |
| 2914 | DPO_PROTO_IP4, |
| 2915 | &pfx_5_5_5_6_s_32.fp_addr, |
| 2916 | ~0, // no index provided. |
| 2917 | fib_index, |
| 2918 | 1, |
| 2919 | NULL, |
| 2920 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2921 | |
| 2922 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_7_s_32); |
| 2923 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2924 | "LB for 5.5.5.7/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2925 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_5_s_32); |
| 2926 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2927 | "LB for 5.5.5.5/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2928 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_6_s_32); |
| 2929 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2930 | "LB for 5.5.5.6/32 is via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2931 | |
| 2932 | /* |
| 2933 | * remove all the 5.5.5.x/32 prefixes |
| 2934 | */ |
| 2935 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2936 | &pfx_5_5_5_5_s_32, |
| 2937 | FIB_SOURCE_API, |
| 2938 | DPO_PROTO_IP4, |
| 2939 | &pfx_5_5_5_6_s_32.fp_addr, |
| 2940 | ~0, // no index provided. |
| 2941 | fib_index, // same as route's FIB |
| 2942 | 1, |
| 2943 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2944 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2945 | &pfx_5_5_5_6_s_32, |
| 2946 | FIB_SOURCE_API, |
| 2947 | DPO_PROTO_IP4, |
| 2948 | &pfx_5_5_5_7_s_32.fp_addr, |
| 2949 | ~0, // no index provided. |
| 2950 | fib_index, // same as route's FIB |
| 2951 | 1, |
| 2952 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2953 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2954 | &pfx_5_5_5_7_s_32, |
| 2955 | FIB_SOURCE_API, |
| 2956 | DPO_PROTO_IP4, |
| 2957 | &pfx_5_5_5_5_s_32.fp_addr, |
| 2958 | ~0, // no index provided. |
| 2959 | fib_index, // same as route's FIB |
| 2960 | 1, |
| 2961 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2962 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2963 | &pfx_5_5_5_6_s_32, |
| 2964 | FIB_SOURCE_API, |
| 2965 | DPO_PROTO_IP4, |
| 2966 | &nh_10_10_10_2, |
| 2967 | ~0, // no index provided. |
| 2968 | fib_index, // same as route's FIB |
| 2969 | 1, |
| 2970 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2971 | |
| 2972 | /* |
| 2973 | * -3 entries, -3 shared path-list |
| 2974 | */ |
| 2975 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2976 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2977 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2978 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2979 | FIB_TEST((ENBR+7 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2980 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2981 | |
| 2982 | /* |
| 2983 | * Single level loop 5.5.5.5/32 via 5.5.5.5/32 |
| 2984 | */ |
| 2985 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2986 | &pfx_5_5_5_6_s_32, |
| 2987 | FIB_SOURCE_API, |
| 2988 | FIB_ENTRY_FLAG_NONE, |
| 2989 | DPO_PROTO_IP4, |
| 2990 | &pfx_5_5_5_6_s_32.fp_addr, |
| 2991 | ~0, // no index provided. |
| 2992 | fib_index, |
| 2993 | 1, |
| 2994 | NULL, |
| 2995 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2996 | fei = fib_table_lookup(fib_index, &pfx_5_5_5_6_s_32); |
| 2997 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 2998 | "1-level 5.5.5.6/32 loop is via adj for DROP"); |
| 2999 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3000 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3001 | &pfx_5_5_5_6_s_32, |
| 3002 | FIB_SOURCE_API, |
| 3003 | DPO_PROTO_IP4, |
| 3004 | &pfx_5_5_5_6_s_32.fp_addr, |
| 3005 | ~0, // no index provided. |
| 3006 | fib_index, // same as route's FIB |
| 3007 | 1, |
| 3008 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3009 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3010 | fib_table_lookup_exact_match(fib_index, &pfx_5_5_5_6_s_32), |
| 3011 | "1-level 5.5.5.6/32 loop is removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3012 | |
| 3013 | /* |
Neale Ranns | 3dffb1e | 2016-11-01 20:38:53 +0000 | [diff] [blame] | 3014 | * A recursive route whose next-hop is covered by the prefix. |
| 3015 | * This would mean the via-fib, which inherits forwarding from its |
| 3016 | * cover, thus picks up forwarding from the prfix, which is via the |
| 3017 | * via-fib, and we have a loop. |
| 3018 | */ |
| 3019 | fib_prefix_t pfx_23_23_23_0_s_24 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3020 | .fp_len = 24, |
| 3021 | .fp_proto = FIB_PROTOCOL_IP4, |
| 3022 | .fp_addr = { |
| 3023 | .ip4.as_u32 = clib_host_to_net_u32(0x17171700), |
| 3024 | }, |
Neale Ranns | 3dffb1e | 2016-11-01 20:38:53 +0000 | [diff] [blame] | 3025 | }; |
| 3026 | fib_prefix_t pfx_23_23_23_23_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3027 | .fp_len = 32, |
| 3028 | .fp_proto = FIB_PROTOCOL_IP4, |
| 3029 | .fp_addr = { |
Neale Ranns | 3dffb1e | 2016-11-01 20:38:53 +0000 | [diff] [blame] | 3030 | .ip4.as_u32 = clib_host_to_net_u32(0x17171717), |
| 3031 | }, |
| 3032 | }; |
| 3033 | fei = fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3034 | &pfx_23_23_23_0_s_24, |
| 3035 | FIB_SOURCE_API, |
| 3036 | FIB_ENTRY_FLAG_NONE, |
| 3037 | DPO_PROTO_IP4, |
| 3038 | &pfx_23_23_23_23_s_32.fp_addr, |
| 3039 | ~0, // recursive |
| 3040 | fib_index, |
| 3041 | 1, |
| 3042 | NULL, |
| 3043 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 3dffb1e | 2016-11-01 20:38:53 +0000 | [diff] [blame] | 3044 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3045 | FIB_TEST(load_balance_is_drop(dpo), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3046 | "23.23.23.0/24 via covered is DROP"); |
Neale Ranns | 3dffb1e | 2016-11-01 20:38:53 +0000 | [diff] [blame] | 3047 | fib_table_entry_delete_index(fei, FIB_SOURCE_API); |
| 3048 | |
| 3049 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3050 | * add-remove test. no change. |
| 3051 | */ |
| 3052 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3053 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3054 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3055 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3056 | FIB_TEST((ENBR+7 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3057 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3058 | |
| 3059 | /* |
Neale Ranns | 08b1648 | 2017-05-13 05:52:58 -0700 | [diff] [blame] | 3060 | * Make the default route recursive via a unknown next-hop. Thus the |
| 3061 | * next hop's cover would be the default route |
| 3062 | */ |
| 3063 | fei = fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3064 | &pfx_0_0_0_0_s_0, |
| 3065 | FIB_SOURCE_API, |
| 3066 | FIB_ENTRY_FLAG_NONE, |
| 3067 | DPO_PROTO_IP4, |
| 3068 | &pfx_23_23_23_23_s_32.fp_addr, |
| 3069 | ~0, // recursive |
| 3070 | fib_index, |
| 3071 | 1, |
| 3072 | NULL, |
| 3073 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 08b1648 | 2017-05-13 05:52:58 -0700 | [diff] [blame] | 3074 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3075 | FIB_TEST(load_balance_is_drop(dpo), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3076 | "0.0.0.0.0/0 via is DROP"); |
Neale Ranns | 08b1648 | 2017-05-13 05:52:58 -0700 | [diff] [blame] | 3077 | FIB_TEST((fib_entry_get_resolving_interface(fei) == ~0), |
| 3078 | "no resolving interface for looped 0.0.0.0/0"); |
| 3079 | |
| 3080 | fei = fib_table_lookup_exact_match(fib_index, &pfx_23_23_23_23_s_32); |
| 3081 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3082 | FIB_TEST(load_balance_is_drop(dpo), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3083 | "23.23.23.23/32 via is DROP"); |
Neale Ranns | 08b1648 | 2017-05-13 05:52:58 -0700 | [diff] [blame] | 3084 | FIB_TEST((fib_entry_get_resolving_interface(fei) == ~0), |
| 3085 | "no resolving interface for looped 23.23.23.23/32"); |
| 3086 | |
| 3087 | fib_table_entry_delete(fib_index, &pfx_0_0_0_0_s_0, FIB_SOURCE_API); |
| 3088 | |
| 3089 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3090 | * A recursive route with recursion constraints. |
| 3091 | * 200.200.200.200/32 via 1.1.1.1 is recurse via host constrained |
| 3092 | */ |
| 3093 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3094 | &bgp_200_pfx, |
| 3095 | FIB_SOURCE_API, |
| 3096 | FIB_ENTRY_FLAG_NONE, |
| 3097 | DPO_PROTO_IP4, |
| 3098 | &nh_1_1_1_1, |
| 3099 | ~0, |
| 3100 | fib_index, |
| 3101 | 1, |
| 3102 | NULL, |
| 3103 | FIB_ROUTE_PATH_RESOLVE_VIA_HOST); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3104 | |
| 3105 | fei = fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_1_s_32); |
| 3106 | dpo2 = fib_entry_contribute_ip_forwarding(fei); |
| 3107 | |
| 3108 | fei = fib_table_lookup_exact_match(fib_index, &bgp_200_pfx); |
| 3109 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 3110 | |
| 3111 | FIB_TEST(!dpo_cmp(dpo2, load_balance_get_bucket(dpo1->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3112 | "adj for 200.200.200.200/32 is recursive via adj for 1.1.1.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3113 | |
| 3114 | /* |
| 3115 | * save the load-balance. we expect it to be inplace modified |
| 3116 | */ |
| 3117 | lb = load_balance_get(dpo1->dpoi_index); |
| 3118 | |
| 3119 | /* |
| 3120 | * add a covering prefix for the via fib that would otherwise serve |
| 3121 | * as the resolving route when the host is removed |
| 3122 | */ |
| 3123 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3124 | &pfx_1_1_1_0_s_28, |
| 3125 | FIB_SOURCE_API, |
| 3126 | FIB_ENTRY_FLAG_NONE, |
| 3127 | DPO_PROTO_IP4, |
| 3128 | &nh_10_10_10_1, |
| 3129 | tm->hw[0]->sw_if_index, |
| 3130 | ~0, // invalid fib index |
| 3131 | 1, |
| 3132 | NULL, |
| 3133 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3134 | fei = fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_0_s_28); |
| 3135 | ai = fib_entry_get_adj(fei); |
| 3136 | FIB_TEST((ai == ai_01), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3137 | "adj for 1.1.1.0/28 is via adj for 1.1.1.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3138 | |
| 3139 | /* |
| 3140 | * remove the host via FIB - expect the BGP prefix to be drop |
| 3141 | */ |
| 3142 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3143 | &pfx_1_1_1_1_s_32, |
| 3144 | FIB_SOURCE_API, |
| 3145 | DPO_PROTO_IP4, |
| 3146 | &nh_10_10_10_1, |
| 3147 | tm->hw[0]->sw_if_index, |
| 3148 | ~0, // invalid fib index |
| 3149 | 1, |
| 3150 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3151 | |
| 3152 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo1->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3153 | "adj for 200.200.200.200/32 is recursive via adj for DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3154 | |
| 3155 | /* |
| 3156 | * add the via-entry host reoute back. expect to resolve again |
| 3157 | */ |
| 3158 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3159 | &pfx_1_1_1_1_s_32, |
| 3160 | FIB_SOURCE_API, |
| 3161 | FIB_ENTRY_FLAG_NONE, |
| 3162 | DPO_PROTO_IP4, |
| 3163 | &nh_10_10_10_1, |
| 3164 | tm->hw[0]->sw_if_index, |
| 3165 | ~0, // invalid fib index |
| 3166 | 1, |
| 3167 | NULL, |
| 3168 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3169 | FIB_TEST(!dpo_cmp(dpo2, load_balance_get_bucket(dpo1->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3170 | "adj for 200.200.200.200/32 is recursive via adj for 1.1.1.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3171 | |
| 3172 | /* |
| 3173 | * add another path for the recursive. it will then have 2. |
| 3174 | */ |
| 3175 | fib_prefix_t pfx_1_1_1_3_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3176 | .fp_len = 32, |
| 3177 | .fp_proto = FIB_PROTOCOL_IP4, |
| 3178 | .fp_addr = { |
| 3179 | .ip4.as_u32 = clib_host_to_net_u32(0x01010103), |
| 3180 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3181 | }; |
| 3182 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3183 | &pfx_1_1_1_3_s_32, |
| 3184 | FIB_SOURCE_API, |
| 3185 | FIB_ENTRY_FLAG_NONE, |
| 3186 | DPO_PROTO_IP4, |
| 3187 | &nh_10_10_10_2, |
| 3188 | tm->hw[0]->sw_if_index, |
| 3189 | ~0, // invalid fib index |
| 3190 | 1, |
| 3191 | NULL, |
| 3192 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3193 | |
| 3194 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3195 | &bgp_200_pfx, |
| 3196 | FIB_SOURCE_API, |
| 3197 | FIB_ENTRY_FLAG_NONE, |
| 3198 | DPO_PROTO_IP4, |
| 3199 | &pfx_1_1_1_3_s_32.fp_addr, |
| 3200 | ~0, |
| 3201 | fib_index, |
| 3202 | 1, |
| 3203 | NULL, |
| 3204 | FIB_ROUTE_PATH_RESOLVE_VIA_HOST); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3205 | |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3206 | /* |
| 3207 | * add a bunch load more entries using this path combo so that we get |
| 3208 | * an LB-map created. |
| 3209 | */ |
| 3210 | #define N_P 128 |
| 3211 | fib_prefix_t bgp_78s[N_P]; |
| 3212 | for (ii = 0; ii < N_P; ii++) |
| 3213 | { |
| 3214 | bgp_78s[ii].fp_len = 32; |
| 3215 | bgp_78s[ii].fp_proto = FIB_PROTOCOL_IP4; |
| 3216 | bgp_78s[ii].fp_addr.ip4.as_u32 = clib_host_to_net_u32(0x4e000000+ii); |
| 3217 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3218 | |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3219 | fib_table_entry_path_add(fib_index, |
| 3220 | &bgp_78s[ii], |
| 3221 | FIB_SOURCE_API, |
| 3222 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 3223 | DPO_PROTO_IP4, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3224 | &pfx_1_1_1_3_s_32.fp_addr, |
| 3225 | ~0, |
| 3226 | fib_index, |
| 3227 | 1, |
| 3228 | NULL, |
| 3229 | FIB_ROUTE_PATH_RESOLVE_VIA_HOST); |
| 3230 | fib_table_entry_path_add(fib_index, |
| 3231 | &bgp_78s[ii], |
| 3232 | FIB_SOURCE_API, |
| 3233 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 3234 | DPO_PROTO_IP4, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3235 | &nh_1_1_1_1, |
| 3236 | ~0, |
| 3237 | fib_index, |
| 3238 | 1, |
| 3239 | NULL, |
| 3240 | FIB_ROUTE_PATH_RESOLVE_VIA_HOST); |
| 3241 | } |
| 3242 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3243 | fei = fib_table_lookup_exact_match(fib_index, &bgp_200_pfx); |
| 3244 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3245 | |
| 3246 | fei = fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_1_s_32); |
| 3247 | dpo2 = fib_entry_contribute_ip_forwarding(fei); |
| 3248 | FIB_TEST(!dpo_cmp(dpo2, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3249 | "adj for 200.200.200.200/32 is recursive via adj for 1.1.1.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3250 | fei = fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_3_s_32); |
| 3251 | dpo1 = fib_entry_contribute_ip_forwarding(fei); |
| 3252 | FIB_TEST(!dpo_cmp(dpo1, load_balance_get_bucket(dpo->dpoi_index, 1)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3253 | "adj for 200.200.200.200/32 is recursive via adj for 1.1.1.3"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3254 | |
| 3255 | /* |
| 3256 | * expect the lb-map used by the recursive's load-balance is using both buckets |
| 3257 | */ |
| 3258 | load_balance_map_t *lbm; |
| 3259 | index_t lbmi; |
| 3260 | |
| 3261 | lb = load_balance_get(dpo->dpoi_index); |
| 3262 | lbmi = lb->lb_map; |
| 3263 | load_balance_map_lock(lbmi); |
| 3264 | lbm = load_balance_map_get(lbmi); |
| 3265 | |
| 3266 | FIB_TEST(lbm->lbm_buckets[0] == 0, |
| 3267 | "LB maps's bucket 0 is %d", |
| 3268 | lbm->lbm_buckets[0]); |
| 3269 | FIB_TEST(lbm->lbm_buckets[1] == 1, |
| 3270 | "LB maps's bucket 1 is %d", |
| 3271 | lbm->lbm_buckets[1]); |
| 3272 | |
| 3273 | /* |
| 3274 | * withdraw one of the /32 via-entrys. |
| 3275 | * that ECMP path will be unresolved and forwarding should continue on the |
| 3276 | * other available path. this is an iBGP PIC edge failover. |
| 3277 | * Test the forwarding changes without re-fetching the adj from the |
| 3278 | * recursive entry. this ensures its the same one that is updated; i.e. an |
| 3279 | * inplace-modify. |
| 3280 | */ |
| 3281 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3282 | &pfx_1_1_1_1_s_32, |
| 3283 | FIB_SOURCE_API, |
| 3284 | DPO_PROTO_IP4, |
| 3285 | &nh_10_10_10_1, |
| 3286 | tm->hw[0]->sw_if_index, |
| 3287 | ~0, // invalid fib index |
| 3288 | 1, |
| 3289 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3290 | |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3291 | /* suspend so the update walk kicks int */ |
| 3292 | vlib_process_suspend(vlib_get_main(), 1e-5); |
| 3293 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3294 | fei = fib_table_lookup_exact_match(fib_index, &bgp_200_pfx); |
| 3295 | FIB_TEST(!dpo_cmp(dpo, fib_entry_contribute_ip_forwarding(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3296 | "post PIC 200.200.200.200/32 was inplace modified"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3297 | |
| 3298 | FIB_TEST(!dpo_cmp(dpo1, load_balance_get_bucket_i(lb, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3299 | "post PIC adj for 200.200.200.200/32 is recursive" |
| 3300 | " via adj for 1.1.1.3"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3301 | |
| 3302 | /* |
| 3303 | * the LB maps that was locked above should have been modified to remove |
| 3304 | * the path that was down, and thus its bucket points to a path that is |
| 3305 | * still up. |
| 3306 | */ |
| 3307 | FIB_TEST(lbm->lbm_buckets[0] == 1, |
| 3308 | "LB maps's bucket 0 is %d", |
| 3309 | lbm->lbm_buckets[0]); |
| 3310 | FIB_TEST(lbm->lbm_buckets[1] == 1, |
| 3311 | "LB maps's bucket 1 is %d", |
| 3312 | lbm->lbm_buckets[1]); |
| 3313 | |
Neale Ranns | 994dab4 | 2017-04-18 12:56:45 -0700 | [diff] [blame] | 3314 | load_balance_map_unlock(lbmi); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3315 | |
| 3316 | /* |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3317 | * add it back. again |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3318 | */ |
| 3319 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3320 | &pfx_1_1_1_1_s_32, |
| 3321 | FIB_SOURCE_API, |
| 3322 | FIB_ENTRY_FLAG_NONE, |
| 3323 | DPO_PROTO_IP4, |
| 3324 | &nh_10_10_10_1, |
| 3325 | tm->hw[0]->sw_if_index, |
| 3326 | ~0, // invalid fib index |
| 3327 | 1, |
| 3328 | NULL, |
| 3329 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3330 | |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3331 | /* suspend so the update walk kicks in */ |
| 3332 | vlib_process_suspend(vlib_get_main(), 1e-5); |
| 3333 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3334 | FIB_TEST(!dpo_cmp(dpo2, load_balance_get_bucket_i(lb, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3335 | "post PIC recovery adj for 200.200.200.200/32 is recursive " |
| 3336 | "via adj for 1.1.1.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3337 | FIB_TEST(!dpo_cmp(dpo1, load_balance_get_bucket_i(lb, 1)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3338 | "post PIC recovery adj for 200.200.200.200/32 is recursive " |
| 3339 | "via adj for 1.1.1.3"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3340 | |
| 3341 | fei = fib_table_lookup_exact_match(fib_index, &bgp_200_pfx); |
| 3342 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3343 | FIB_TEST(lb == load_balance_get(dpo->dpoi_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3344 | "post PIC 200.200.200.200/32 was inplace modified"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3345 | |
| 3346 | /* |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3347 | * add a 3rd path. this makes the LB 16 buckets. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3348 | */ |
| 3349 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3350 | &bgp_200_pfx, |
| 3351 | FIB_SOURCE_API, |
| 3352 | FIB_ENTRY_FLAG_NONE, |
| 3353 | DPO_PROTO_IP4, |
| 3354 | &pfx_1_1_1_2_s_32.fp_addr, |
| 3355 | ~0, |
| 3356 | fib_index, |
| 3357 | 1, |
| 3358 | NULL, |
| 3359 | FIB_ROUTE_PATH_RESOLVE_VIA_HOST); |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3360 | for (ii = 0; ii < N_P; ii++) |
| 3361 | { |
| 3362 | fib_table_entry_path_add(fib_index, |
| 3363 | &bgp_78s[ii], |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3364 | FIB_SOURCE_API, |
| 3365 | FIB_ENTRY_FLAG_NONE, |
| 3366 | DPO_PROTO_IP4, |
| 3367 | &pfx_1_1_1_2_s_32.fp_addr, |
| 3368 | ~0, |
| 3369 | fib_index, |
| 3370 | 1, |
| 3371 | NULL, |
| 3372 | FIB_ROUTE_PATH_RESOLVE_VIA_HOST); |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3373 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3374 | |
| 3375 | fei = fib_table_lookup_exact_match(fib_index, &bgp_200_pfx); |
| 3376 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3377 | FIB_TEST(lb == load_balance_get(dpo->dpoi_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3378 | "200.200.200.200/32 was inplace modified for 3rd path"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3379 | FIB_TEST(16 == lb->lb_n_buckets, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3380 | "200.200.200.200/32 was inplace modified for 3rd path to 16 buckets"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3381 | |
| 3382 | lbmi = lb->lb_map; |
| 3383 | load_balance_map_lock(lbmi); |
| 3384 | lbm = load_balance_map_get(lbmi); |
| 3385 | |
| 3386 | for (ii = 0; ii < 16; ii++) |
| 3387 | { |
| 3388 | FIB_TEST(lbm->lbm_buckets[ii] == ii, |
| 3389 | "LB Map for 200.200.200.200/32 at %d is %d", |
| 3390 | ii, lbm->lbm_buckets[ii]); |
| 3391 | } |
| 3392 | |
| 3393 | /* |
| 3394 | * trigger PIC by removing the first via-entry |
| 3395 | * the first 6 buckets of the map should map to the next 6 |
| 3396 | */ |
| 3397 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3398 | &pfx_1_1_1_1_s_32, |
| 3399 | FIB_SOURCE_API, |
| 3400 | DPO_PROTO_IP4, |
| 3401 | &nh_10_10_10_1, |
| 3402 | tm->hw[0]->sw_if_index, |
| 3403 | ~0, |
| 3404 | 1, |
| 3405 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3406 | /* suspend so the update walk kicks int */ |
| 3407 | vlib_process_suspend(vlib_get_main(), 1e-5); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3408 | |
| 3409 | fei = fib_table_lookup_exact_match(fib_index, &bgp_200_pfx); |
| 3410 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3411 | FIB_TEST(lb == load_balance_get(dpo->dpoi_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3412 | "200.200.200.200/32 was inplace modified for 3rd path"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3413 | FIB_TEST(2 == lb->lb_n_buckets, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3414 | "200.200.200.200/32 was inplace modified for 3rd path remove to 2 buckets"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3415 | |
| 3416 | for (ii = 0; ii < 6; ii++) |
| 3417 | { |
| 3418 | FIB_TEST(lbm->lbm_buckets[ii] == ii+6, |
| 3419 | "LB Map for 200.200.200.200/32 at %d is %d", |
| 3420 | ii, lbm->lbm_buckets[ii]); |
| 3421 | } |
| 3422 | for (ii = 6; ii < 16; ii++) |
| 3423 | { |
| 3424 | FIB_TEST(lbm->lbm_buckets[ii] == ii, |
| 3425 | "LB Map for 200.200.200.200/32 at %d is %d", |
| 3426 | ii, lbm->lbm_buckets[ii]); |
| 3427 | } |
Neale Ranns | 994dab4 | 2017-04-18 12:56:45 -0700 | [diff] [blame] | 3428 | load_balance_map_unlock(lbmi); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3429 | |
| 3430 | /* |
| 3431 | * tidy up |
| 3432 | */ |
| 3433 | fib_table_entry_path_add(fib_index, |
| 3434 | &pfx_1_1_1_1_s_32, |
| 3435 | FIB_SOURCE_API, |
| 3436 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3437 | DPO_PROTO_IP4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3438 | &nh_10_10_10_1, |
| 3439 | tm->hw[0]->sw_if_index, |
| 3440 | ~0, |
| 3441 | 1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 3442 | NULL, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3443 | FIB_ROUTE_PATH_FLAG_NONE); |
| 3444 | |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3445 | for (ii = 0; ii < N_P; ii++) |
| 3446 | { |
| 3447 | fib_table_entry_delete(fib_index, |
| 3448 | &bgp_78s[ii], |
| 3449 | FIB_SOURCE_API); |
| 3450 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
| 3451 | fib_table_lookup_exact_match(fib_index, &bgp_78s[ii])), |
| 3452 | "%U removed", |
| 3453 | format_fib_prefix, &bgp_78s[ii]); |
| 3454 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3455 | fib_table_entry_path_remove(fib_index, |
| 3456 | &bgp_200_pfx, |
| 3457 | FIB_SOURCE_API, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3458 | DPO_PROTO_IP4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3459 | &pfx_1_1_1_2_s_32.fp_addr, |
| 3460 | ~0, |
| 3461 | fib_index, |
| 3462 | 1, |
| 3463 | MPLS_LABEL_INVALID); |
| 3464 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3465 | &bgp_200_pfx, |
| 3466 | FIB_SOURCE_API, |
| 3467 | DPO_PROTO_IP4, |
| 3468 | &nh_1_1_1_1, |
| 3469 | ~0, |
| 3470 | fib_index, |
| 3471 | 1, |
| 3472 | FIB_ROUTE_PATH_RESOLVE_VIA_HOST); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3473 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3474 | &bgp_200_pfx, |
| 3475 | FIB_SOURCE_API, |
| 3476 | DPO_PROTO_IP4, |
| 3477 | &pfx_1_1_1_3_s_32.fp_addr, |
| 3478 | ~0, |
| 3479 | fib_index, |
| 3480 | 1, |
| 3481 | FIB_ROUTE_PATH_RESOLVE_VIA_HOST); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3482 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3483 | &pfx_1_1_1_3_s_32, |
| 3484 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3485 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3486 | &pfx_1_1_1_0_s_28, |
| 3487 | FIB_SOURCE_API); |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 3488 | /* suspend so the update walk kicks int */ |
| 3489 | vlib_process_suspend(vlib_get_main(), 1e-5); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3490 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3491 | fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_0_s_28)), |
| 3492 | "1.1.1.1/28 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3493 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3494 | fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_3_s_32)), |
| 3495 | "1.1.1.3/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3496 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3497 | fib_table_lookup_exact_match(fib_index, &bgp_200_pfx)), |
| 3498 | "200.200.200.200/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3499 | |
| 3500 | /* |
| 3501 | * add-remove test. no change. |
| 3502 | */ |
| 3503 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3504 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3505 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3506 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3507 | FIB_TEST((ENBR+7 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3508 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3509 | |
| 3510 | /* |
| 3511 | * A route whose paths are built up iteratively and then removed |
| 3512 | * all at once |
| 3513 | */ |
| 3514 | fib_prefix_t pfx_4_4_4_4_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3515 | .fp_len = 32, |
| 3516 | .fp_proto = FIB_PROTOCOL_IP4, |
| 3517 | .fp_addr = { |
| 3518 | /* 4.4.4.4/32 */ |
| 3519 | .ip4.as_u32 = clib_host_to_net_u32(0x04040404), |
| 3520 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3521 | }; |
| 3522 | |
| 3523 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3524 | &pfx_4_4_4_4_s_32, |
| 3525 | FIB_SOURCE_API, |
| 3526 | FIB_ENTRY_FLAG_NONE, |
| 3527 | DPO_PROTO_IP4, |
| 3528 | &nh_10_10_10_1, |
| 3529 | tm->hw[0]->sw_if_index, |
| 3530 | ~0, |
| 3531 | 1, |
| 3532 | NULL, |
| 3533 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3534 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3535 | &pfx_4_4_4_4_s_32, |
| 3536 | FIB_SOURCE_API, |
| 3537 | FIB_ENTRY_FLAG_NONE, |
| 3538 | DPO_PROTO_IP4, |
| 3539 | &nh_10_10_10_2, |
| 3540 | tm->hw[0]->sw_if_index, |
| 3541 | ~0, |
| 3542 | 1, |
| 3543 | NULL, |
| 3544 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3545 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3546 | &pfx_4_4_4_4_s_32, |
| 3547 | FIB_SOURCE_API, |
| 3548 | FIB_ENTRY_FLAG_NONE, |
| 3549 | DPO_PROTO_IP4, |
| 3550 | &nh_10_10_10_3, |
| 3551 | tm->hw[0]->sw_if_index, |
| 3552 | ~0, |
| 3553 | 1, |
| 3554 | NULL, |
| 3555 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3556 | FIB_TEST(FIB_NODE_INDEX_INVALID != |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3557 | fib_table_lookup_exact_match(fib_index, &pfx_4_4_4_4_s_32), |
| 3558 | "4.4.4.4/32 present"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3559 | |
| 3560 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3561 | &pfx_4_4_4_4_s_32, |
| 3562 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3563 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3564 | fib_table_lookup_exact_match(fib_index, &pfx_4_4_4_4_s_32), |
| 3565 | "4.4.4.4/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3566 | |
| 3567 | /* |
| 3568 | * add-remove test. no change. |
| 3569 | */ |
| 3570 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3571 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3572 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3573 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3574 | FIB_TEST((ENBR+7 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3575 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3576 | |
| 3577 | /* |
| 3578 | * A route with multiple paths at once |
| 3579 | */ |
| 3580 | fib_route_path_t *r_paths = NULL; |
| 3581 | |
| 3582 | for (ii = 0; ii < 4; ii++) |
| 3583 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3584 | fib_route_path_t r_path = { |
| 3585 | .frp_proto = DPO_PROTO_IP4, |
| 3586 | .frp_addr = { |
| 3587 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a02 + ii), |
| 3588 | }, |
| 3589 | .frp_sw_if_index = tm->hw[0]->sw_if_index, |
| 3590 | .frp_weight = 1, |
| 3591 | .frp_fib_index = ~0, |
| 3592 | }; |
| 3593 | vec_add1(r_paths, r_path); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | fib_table_entry_update(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3597 | &pfx_4_4_4_4_s_32, |
| 3598 | FIB_SOURCE_API, |
| 3599 | FIB_ENTRY_FLAG_NONE, |
| 3600 | r_paths); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3601 | |
| 3602 | fei = fib_table_lookup_exact_match(fib_index, &pfx_4_4_4_4_s_32); |
| 3603 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "4.4.4.4/32 present"); |
| 3604 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3605 | |
| 3606 | lb = load_balance_get(dpo->dpoi_index); |
| 3607 | FIB_TEST((lb->lb_n_buckets == 4), "4.4.4.4/32 lb over %d paths", lb->lb_n_buckets); |
| 3608 | |
| 3609 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3610 | &pfx_4_4_4_4_s_32, |
| 3611 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3612 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3613 | fib_table_lookup_exact_match(fib_index, &pfx_4_4_4_4_s_32), |
| 3614 | "4.4.4.4/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3615 | vec_free(r_paths); |
| 3616 | |
| 3617 | /* |
| 3618 | * add-remove test. no change. |
| 3619 | */ |
| 3620 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3621 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3622 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3623 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3624 | FIB_TEST((ENBR+7 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3625 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3626 | |
| 3627 | /* |
| 3628 | * A route deag route |
| 3629 | */ |
| 3630 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3631 | &pfx_4_4_4_4_s_32, |
| 3632 | FIB_SOURCE_API, |
| 3633 | FIB_ENTRY_FLAG_NONE, |
| 3634 | DPO_PROTO_IP4, |
| 3635 | &zero_addr, |
| 3636 | ~0, |
| 3637 | fib_index, |
| 3638 | 1, |
| 3639 | NULL, |
| 3640 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3641 | |
| 3642 | fei = fib_table_lookup_exact_match(fib_index, &pfx_4_4_4_4_s_32); |
| 3643 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "4.4.4.4/32 present"); |
| 3644 | |
| 3645 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3646 | dpo = load_balance_get_bucket(dpo->dpoi_index, 0); |
| 3647 | lookup_dpo_t *lkd = lookup_dpo_get(dpo->dpoi_index); |
| 3648 | |
| 3649 | FIB_TEST((fib_index == lkd->lkd_fib_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3650 | "4.4.4.4/32 is deag in %d %U", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3651 | lkd->lkd_fib_index, |
| 3652 | format_dpo_id, dpo, 0); |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 3653 | FIB_TEST((LOOKUP_INPUT_DST_ADDR == lkd->lkd_input), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3654 | "4.4.4.4/32 is source deag in %d %U", |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 3655 | lkd->lkd_input, |
| 3656 | format_dpo_id, dpo, 0); |
| 3657 | |
| 3658 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3659 | &pfx_4_4_4_4_s_32, |
| 3660 | FIB_SOURCE_API); |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 3661 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3662 | fib_table_lookup_exact_match(fib_index, &pfx_4_4_4_4_s_32), |
| 3663 | "4.4.4.4/32 removed"); |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 3664 | vec_free(r_paths); |
| 3665 | |
| 3666 | /* |
| 3667 | * A route deag route in a source lookup table |
| 3668 | */ |
| 3669 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3670 | &pfx_4_4_4_4_s_32, |
| 3671 | FIB_SOURCE_API, |
| 3672 | FIB_ENTRY_FLAG_NONE, |
| 3673 | DPO_PROTO_IP4, |
| 3674 | &zero_addr, |
| 3675 | ~0, |
| 3676 | fib_index, |
| 3677 | 1, |
| 3678 | NULL, |
| 3679 | FIB_ROUTE_PATH_SOURCE_LOOKUP); |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 3680 | |
| 3681 | fei = fib_table_lookup_exact_match(fib_index, &pfx_4_4_4_4_s_32); |
| 3682 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "4.4.4.4/32 present"); |
| 3683 | |
| 3684 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3685 | dpo = load_balance_get_bucket(dpo->dpoi_index, 0); |
| 3686 | lkd = lookup_dpo_get(dpo->dpoi_index); |
| 3687 | |
| 3688 | FIB_TEST((fib_index == lkd->lkd_fib_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3689 | "4.4.4.4/32 is deag in %d %U", |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 3690 | lkd->lkd_fib_index, |
| 3691 | format_dpo_id, dpo, 0); |
| 3692 | FIB_TEST((LOOKUP_INPUT_SRC_ADDR == lkd->lkd_input), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3693 | "4.4.4.4/32 is source deag in %d %U", |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 3694 | lkd->lkd_input, |
| 3695 | format_dpo_id, dpo, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3696 | |
| 3697 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3698 | &pfx_4_4_4_4_s_32, |
| 3699 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3700 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3701 | fib_table_lookup_exact_match(fib_index, &pfx_4_4_4_4_s_32), |
| 3702 | "4.4.4.4/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3703 | vec_free(r_paths); |
| 3704 | |
| 3705 | /* |
| 3706 | * add-remove test. no change. |
| 3707 | */ |
| 3708 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3709 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3710 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3711 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3712 | FIB_TEST((ENBR+7 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3713 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3714 | |
| 3715 | /* |
Neale Ranns | bcc889c | 2016-11-03 14:15:28 -0700 | [diff] [blame] | 3716 | * Duplicate paths: |
| 3717 | * add a recursive with duplicate paths. Expect the duplicate to be ignored. |
| 3718 | */ |
| 3719 | fib_prefix_t pfx_34_1_1_1_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3720 | .fp_len = 32, |
| 3721 | .fp_proto = FIB_PROTOCOL_IP4, |
| 3722 | .fp_addr = { |
| 3723 | .ip4.as_u32 = clib_host_to_net_u32(0x22010101), |
| 3724 | }, |
Neale Ranns | bcc889c | 2016-11-03 14:15:28 -0700 | [diff] [blame] | 3725 | }; |
| 3726 | fib_prefix_t pfx_34_34_1_1_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3727 | .fp_len = 32, |
| 3728 | .fp_proto = FIB_PROTOCOL_IP4, |
| 3729 | .fp_addr = { |
| 3730 | .ip4.as_u32 = clib_host_to_net_u32(0x22220101), |
| 3731 | }, |
Neale Ranns | bcc889c | 2016-11-03 14:15:28 -0700 | [diff] [blame] | 3732 | }; |
| 3733 | fei = fib_table_entry_path_add(fib_index, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 3734 | &pfx_34_34_1_1_s_32, |
| 3735 | FIB_SOURCE_API, |
| 3736 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 3737 | DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 3738 | &nh_10_10_10_1, |
| 3739 | tm->hw[0]->sw_if_index, |
| 3740 | 0, |
| 3741 | 1, |
| 3742 | NULL, |
| 3743 | FIB_ROUTE_PATH_FLAG_NONE); |
| 3744 | fei = fib_table_entry_path_add(fib_index, |
Neale Ranns | bcc889c | 2016-11-03 14:15:28 -0700 | [diff] [blame] | 3745 | &pfx_34_1_1_1_s_32, |
| 3746 | FIB_SOURCE_API, |
| 3747 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 3748 | DPO_PROTO_IP4, |
Neale Ranns | bcc889c | 2016-11-03 14:15:28 -0700 | [diff] [blame] | 3749 | &pfx_34_34_1_1_s_32.fp_addr, |
| 3750 | ~0, |
| 3751 | fib_index, |
| 3752 | 1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 3753 | NULL, |
Neale Ranns | bcc889c | 2016-11-03 14:15:28 -0700 | [diff] [blame] | 3754 | FIB_ROUTE_PATH_FLAG_NONE); |
| 3755 | fei = fib_table_entry_path_add(fib_index, |
| 3756 | &pfx_34_1_1_1_s_32, |
| 3757 | FIB_SOURCE_API, |
| 3758 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 3759 | DPO_PROTO_IP4, |
Neale Ranns | bcc889c | 2016-11-03 14:15:28 -0700 | [diff] [blame] | 3760 | &pfx_34_34_1_1_s_32.fp_addr, |
| 3761 | ~0, |
| 3762 | fib_index, |
| 3763 | 1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 3764 | NULL, |
Neale Ranns | bcc889c | 2016-11-03 14:15:28 -0700 | [diff] [blame] | 3765 | FIB_ROUTE_PATH_FLAG_NONE); |
| 3766 | FIB_TEST_REC_FORW(&pfx_34_1_1_1_s_32, &pfx_34_34_1_1_s_32, 0); |
| 3767 | fib_table_entry_delete_index(fei, FIB_SOURCE_API); |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 3768 | fib_table_entry_delete(fib_index, |
| 3769 | &pfx_34_34_1_1_s_32, |
| 3770 | FIB_SOURCE_API); |
Neale Ranns | bcc889c | 2016-11-03 14:15:28 -0700 | [diff] [blame] | 3771 | |
| 3772 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3773 | * CLEANUP |
| 3774 | * remove: 1.1.1.2/32, 1.1.2.0/24 and 1.1.1.1/32 |
| 3775 | * all of which are via 10.10.10.1, Itf1 |
| 3776 | */ |
| 3777 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3778 | &pfx_1_1_1_2_s_32, |
| 3779 | FIB_SOURCE_API, |
| 3780 | DPO_PROTO_IP4, |
| 3781 | &nh_10_10_10_1, |
| 3782 | tm->hw[0]->sw_if_index, |
| 3783 | ~0, |
| 3784 | 1, |
| 3785 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3786 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3787 | &pfx_1_1_1_1_s_32, |
| 3788 | FIB_SOURCE_API, |
| 3789 | DPO_PROTO_IP4, |
| 3790 | &nh_10_10_10_1, |
| 3791 | tm->hw[0]->sw_if_index, |
| 3792 | ~0, |
| 3793 | 1, |
| 3794 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3795 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3796 | &pfx_1_1_2_0_s_24, |
| 3797 | FIB_SOURCE_API, |
| 3798 | DPO_PROTO_IP4, |
| 3799 | &nh_10_10_10_1, |
| 3800 | tm->hw[0]->sw_if_index, |
| 3801 | ~0, |
| 3802 | 1, |
| 3803 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3804 | |
| 3805 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3806 | fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_1_s_32), |
| 3807 | "1.1.1.1/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3808 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3809 | fib_table_lookup_exact_match(fib_index, &pfx_1_1_1_2_s_32), |
| 3810 | "1.1.1.2/32 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3811 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3812 | fib_table_lookup_exact_match(fib_index, &pfx_1_1_2_0_s_24), |
| 3813 | "1.1.2.0/24 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3814 | |
| 3815 | /* |
| 3816 | * -3 entries and -1 shared path-list |
| 3817 | */ |
| 3818 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3819 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3820 | FIB_TEST((PNBR+4 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3821 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3822 | FIB_TEST((ENBR+4 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3823 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3824 | |
| 3825 | /* |
| 3826 | * An attached-host route. Expect to link to the incomplete adj |
| 3827 | */ |
| 3828 | fib_prefix_t pfx_4_1_1_1_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3829 | .fp_len = 32, |
| 3830 | .fp_proto = FIB_PROTOCOL_IP4, |
| 3831 | .fp_addr = { |
| 3832 | /* 4.1.1.1/32 */ |
| 3833 | .ip4.as_u32 = clib_host_to_net_u32(0x04010101), |
| 3834 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3835 | }; |
| 3836 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3837 | &pfx_4_1_1_1_s_32, |
| 3838 | FIB_SOURCE_API, |
| 3839 | FIB_ENTRY_FLAG_NONE, |
| 3840 | DPO_PROTO_IP4, |
| 3841 | &zero_addr, |
| 3842 | tm->hw[0]->sw_if_index, |
| 3843 | fib_index, |
| 3844 | 1, |
| 3845 | NULL, |
| 3846 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3847 | |
| 3848 | fei = fib_table_lookup_exact_match(fib_index, &pfx_4_1_1_1_s_32); |
| 3849 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "4.1.1.1/32 present"); |
| 3850 | ai = fib_entry_get_adj(fei); |
| 3851 | |
| 3852 | ai2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3853 | VNET_LINK_IP4, |
| 3854 | &pfx_4_1_1_1_s_32.fp_addr, |
| 3855 | tm->hw[0]->sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3856 | FIB_TEST((ai == ai2), "Attached-host link to incomplete ADJ"); |
| 3857 | adj_unlock(ai2); |
| 3858 | |
| 3859 | /* |
| 3860 | * +1 entry and +1 shared path-list |
| 3861 | */ |
| 3862 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3863 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3864 | FIB_TEST((PNBR+5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3865 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3866 | FIB_TEST((ENBR+5 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3867 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3868 | |
| 3869 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3870 | &pfx_4_1_1_1_s_32, |
| 3871 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3872 | |
| 3873 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3874 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3875 | FIB_TEST((PNBR+4 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3876 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 3877 | FIB_TEST((ENBR+4 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3878 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3879 | |
| 3880 | /* |
| 3881 | * add a v6 prefix via v4 next-hops |
| 3882 | */ |
| 3883 | fib_prefix_t pfx_2001_s_64 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3884 | .fp_len = 64, |
| 3885 | .fp_proto = FIB_PROTOCOL_IP6, |
| 3886 | .fp_addr = { |
| 3887 | .ip6.as_u64[0] = clib_host_to_net_u64(0x2001000000000000), |
| 3888 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3889 | }; |
| 3890 | fei = fib_table_entry_path_add(0, //default v6 table |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3891 | &pfx_2001_s_64, |
| 3892 | FIB_SOURCE_API, |
| 3893 | FIB_ENTRY_FLAG_NONE, |
| 3894 | DPO_PROTO_IP4, |
| 3895 | &nh_10_10_10_1, |
| 3896 | tm->hw[0]->sw_if_index, |
| 3897 | fib_index, |
| 3898 | 1, |
| 3899 | NULL, |
| 3900 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3901 | |
| 3902 | fei = fib_table_lookup_exact_match(0, &pfx_2001_s_64); |
| 3903 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "2001::/64 present"); |
| 3904 | ai = fib_entry_get_adj(fei); |
| 3905 | adj = adj_get(ai); |
| 3906 | FIB_TEST((adj->lookup_next_index == IP_LOOKUP_NEXT_ARP), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3907 | "2001::/64 via ARP-adj"); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 3908 | FIB_TEST((adj->ia_link == VNET_LINK_IP6), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3909 | "2001::/64 is link type v6"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3910 | FIB_TEST((adj->ia_nh_proto == FIB_PROTOCOL_IP4), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3911 | "2001::/64 ADJ-adj is NH proto v4"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3912 | fib_table_entry_delete(0, &pfx_2001_s_64, FIB_SOURCE_API); |
| 3913 | |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 3914 | /* |
| 3915 | * add a uRPF exempt prefix: |
| 3916 | * test: |
| 3917 | * - it's forwarding is drop |
| 3918 | * - it's uRPF list is not empty |
| 3919 | * - the uRPF list for the default route (it's cover) is empty |
| 3920 | */ |
| 3921 | fei = fib_table_entry_special_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3922 | &pfx_4_1_1_1_s_32, |
| 3923 | FIB_SOURCE_URPF_EXEMPT, |
| 3924 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 3925 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 3926 | FIB_TEST(load_balance_is_drop(dpo), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3927 | "uRPF exempt 4.1.1.1/32 DROP"); |
| 3928 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 1, 0), |
| 3929 | "uRPF list for exempt prefix has itf index 0"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 3930 | fei = fib_table_lookup_exact_match(fib_index, &pfx_0_0_0_0_s_0); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3931 | FIB_TEST(!fib_test_urpf_is_equal(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, 0), |
| 3932 | "uRPF list for 0.0.0.0/0 empty"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 3933 | |
| 3934 | fib_table_entry_delete(fib_index, &pfx_4_1_1_1_s_32, FIB_SOURCE_URPF_EXEMPT); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 3935 | |
| 3936 | /* |
Neale Ranns | 3983ac2 | 2017-03-10 11:53:27 -0800 | [diff] [blame] | 3937 | * An adj-fib that fails the refinement criteria - no connected cover |
| 3938 | */ |
| 3939 | fib_prefix_t pfx_12_10_10_2_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3940 | .fp_len = 32, |
| 3941 | .fp_proto = FIB_PROTOCOL_IP4, |
| 3942 | .fp_addr = { |
| 3943 | /* 12.10.10.2 */ |
| 3944 | .ip4.as_u32 = clib_host_to_net_u32(0x0c0a0a02), |
| 3945 | }, |
Neale Ranns | 3983ac2 | 2017-03-10 11:53:27 -0800 | [diff] [blame] | 3946 | }; |
| 3947 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 3948 | fib_table_entry_path_add(fib_index, |
| 3949 | &pfx_12_10_10_2_s_32, |
| 3950 | FIB_SOURCE_ADJ, |
| 3951 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 3952 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 3953 | &pfx_12_10_10_2_s_32.fp_addr, |
| 3954 | tm->hw[0]->sw_if_index, |
| 3955 | ~0, // invalid fib index |
| 3956 | 1, |
| 3957 | NULL, |
| 3958 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 3983ac2 | 2017-03-10 11:53:27 -0800 | [diff] [blame] | 3959 | |
| 3960 | fei = fib_table_lookup_exact_match(fib_index, &pfx_12_10_10_2_s_32); |
| 3961 | dpo = fib_entry_contribute_ip_forwarding(fei); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3962 | FIB_TEST(dpo_is_drop(dpo), |
| 3963 | "no connected cover adj-fib fails refinement: %U", |
| 3964 | format_dpo_id, dpo, 0); |
Neale Ranns | 3983ac2 | 2017-03-10 11:53:27 -0800 | [diff] [blame] | 3965 | |
| 3966 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3967 | &pfx_12_10_10_2_s_32, |
| 3968 | FIB_SOURCE_ADJ); |
Neale Ranns | 3983ac2 | 2017-03-10 11:53:27 -0800 | [diff] [blame] | 3969 | |
| 3970 | /* |
| 3971 | * An adj-fib that fails the refinement criteria - cover is connected |
| 3972 | * but on a different interface |
| 3973 | */ |
| 3974 | fib_prefix_t pfx_10_10_10_127_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3975 | .fp_len = 32, |
| 3976 | .fp_proto = FIB_PROTOCOL_IP4, |
| 3977 | .fp_addr = { |
| 3978 | /* 10.10.10.127 */ |
| 3979 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a7f), |
| 3980 | }, |
Neale Ranns | 3983ac2 | 2017-03-10 11:53:27 -0800 | [diff] [blame] | 3981 | }; |
| 3982 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 3983 | fib_table_entry_path_add(fib_index, |
| 3984 | &pfx_10_10_10_127_s_32, |
| 3985 | FIB_SOURCE_ADJ, |
| 3986 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 3987 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 3988 | &pfx_10_10_10_127_s_32.fp_addr, |
| 3989 | tm->hw[1]->sw_if_index, |
| 3990 | ~0, // invalid fib index |
| 3991 | 1, |
| 3992 | NULL, |
| 3993 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 3983ac2 | 2017-03-10 11:53:27 -0800 | [diff] [blame] | 3994 | |
| 3995 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_127_s_32); |
| 3996 | dpo = fib_entry_contribute_ip_forwarding(fei); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 3997 | FIB_TEST(dpo_is_drop(dpo), |
| 3998 | "wrong interface adj-fib fails refinement"); |
Neale Ranns | 3983ac2 | 2017-03-10 11:53:27 -0800 | [diff] [blame] | 3999 | |
| 4000 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4001 | &pfx_10_10_10_127_s_32, |
| 4002 | FIB_SOURCE_ADJ); |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4003 | |
| 4004 | /* |
| 4005 | * add a second path to an adj-fib |
| 4006 | * this is a sumiluation of another ARP entry created |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4007 | * on an interface on which the connected prefix does not exist. |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4008 | * The second path fails refinement. Expect to forward through the |
| 4009 | * first. |
| 4010 | */ |
| 4011 | fib_prefix_t pfx_10_10_10_3_s_32 = { |
| 4012 | .fp_len = 32, |
| 4013 | .fp_proto = FIB_PROTOCOL_IP4, |
| 4014 | .fp_addr = { |
| 4015 | /* 10.10.10.3 */ |
| 4016 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a03), |
| 4017 | }, |
| 4018 | }; |
| 4019 | |
| 4020 | ai_03 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 4021 | VNET_LINK_IP4, |
| 4022 | &nh_10_10_10_3, |
| 4023 | tm->hw[0]->sw_if_index); |
| 4024 | |
| 4025 | fib_test_lb_bucket_t ip_o_10_10_10_3 = { |
| 4026 | .type = FT_LB_ADJ, |
| 4027 | .adj = { |
| 4028 | .adj = ai_03, |
| 4029 | }, |
| 4030 | }; |
| 4031 | fei = fib_table_entry_path_add(fib_index, |
| 4032 | &pfx_10_10_10_3_s_32, |
| 4033 | FIB_SOURCE_ADJ, |
| 4034 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4035 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4036 | &nh_10_10_10_3, |
| 4037 | tm->hw[0]->sw_if_index, |
| 4038 | fib_index, |
| 4039 | 1, |
| 4040 | NULL, |
| 4041 | FIB_ROUTE_PATH_FLAG_NONE); |
| 4042 | fei = fib_table_entry_path_add(fib_index, |
| 4043 | &pfx_10_10_10_3_s_32, |
| 4044 | FIB_SOURCE_ADJ, |
| 4045 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4046 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4047 | &nh_12_12_12_12, |
| 4048 | tm->hw[1]->sw_if_index, |
| 4049 | fib_index, |
| 4050 | 1, |
| 4051 | NULL, |
| 4052 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4053 | FIB_TEST(!fib_test_validate_entry(fei, |
| 4054 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 4055 | 1, |
| 4056 | &ip_o_10_10_10_3), |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4057 | "10.10.10.3 via 10.10.10.3/Eth0 only"); |
| 4058 | |
| 4059 | /* |
| 4060 | * remove the path that refines the cover, should go unresolved |
| 4061 | */ |
| 4062 | fib_table_entry_path_remove(fib_index, |
| 4063 | &pfx_10_10_10_3_s_32, |
| 4064 | FIB_SOURCE_ADJ, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4065 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4066 | &nh_10_10_10_3, |
| 4067 | tm->hw[0]->sw_if_index, |
| 4068 | fib_index, |
| 4069 | 1, |
| 4070 | FIB_ROUTE_PATH_FLAG_NONE); |
| 4071 | dpo = fib_entry_contribute_ip_forwarding(fei); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4072 | FIB_TEST(dpo_is_drop(dpo), |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4073 | "wrong interface adj-fib fails refinement"); |
| 4074 | |
| 4075 | /* |
| 4076 | * add back the path that refines the cover |
| 4077 | */ |
| 4078 | fei = fib_table_entry_path_add(fib_index, |
| 4079 | &pfx_10_10_10_3_s_32, |
| 4080 | FIB_SOURCE_ADJ, |
| 4081 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4082 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4083 | &nh_10_10_10_3, |
| 4084 | tm->hw[0]->sw_if_index, |
| 4085 | fib_index, |
| 4086 | 1, |
| 4087 | NULL, |
| 4088 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4089 | FIB_TEST(!fib_test_validate_entry(fei, |
| 4090 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 4091 | 1, |
| 4092 | &ip_o_10_10_10_3), |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4093 | "10.10.10.3 via 10.10.10.3/Eth0 only"); |
| 4094 | |
| 4095 | /* |
| 4096 | * remove the path that does not refine the cover |
| 4097 | */ |
| 4098 | fib_table_entry_path_remove(fib_index, |
| 4099 | &pfx_10_10_10_3_s_32, |
| 4100 | FIB_SOURCE_ADJ, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4101 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4102 | &nh_12_12_12_12, |
| 4103 | tm->hw[1]->sw_if_index, |
| 4104 | fib_index, |
| 4105 | 1, |
| 4106 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4107 | FIB_TEST(!fib_test_validate_entry(fei, |
| 4108 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 4109 | 1, |
| 4110 | &ip_o_10_10_10_3), |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4111 | "10.10.10.3 via 10.10.10.3/Eth0 only"); |
| 4112 | |
| 4113 | /* |
| 4114 | * remove the path that does refine, it's the last path, so |
| 4115 | * the entry should be gone |
| 4116 | */ |
| 4117 | fib_table_entry_path_remove(fib_index, |
| 4118 | &pfx_10_10_10_3_s_32, |
| 4119 | FIB_SOURCE_ADJ, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4120 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4121 | &nh_10_10_10_3, |
| 4122 | tm->hw[0]->sw_if_index, |
| 4123 | fib_index, |
| 4124 | 1, |
| 4125 | FIB_ROUTE_PATH_FLAG_NONE); |
| 4126 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_3_s_32); |
| 4127 | FIB_TEST((fei == FIB_NODE_INDEX_INVALID), "10.10.10.3 gone"); |
| 4128 | |
| 4129 | adj_unlock(ai_03); |
| 4130 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 4131 | /* |
| 4132 | * change the table's flow-hash config - expect the update to propagete to |
| 4133 | * the entries' load-balance objects |
| 4134 | */ |
| 4135 | flow_hash_config_t old_hash_config, new_hash_config; |
| 4136 | |
| 4137 | old_hash_config = fib_table_get_flow_hash_config(fib_index, |
| 4138 | FIB_PROTOCOL_IP4); |
| 4139 | new_hash_config = (IP_FLOW_HASH_SRC_ADDR | |
| 4140 | IP_FLOW_HASH_DST_ADDR); |
| 4141 | |
| 4142 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_1_s_32); |
| 4143 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4144 | lb = load_balance_get(dpo->dpoi_index); |
| 4145 | FIB_TEST((lb->lb_hash_config == old_hash_config), |
| 4146 | "Table and LB hash config match: %U", |
| 4147 | format_ip_flow_hash_config, lb->lb_hash_config); |
| 4148 | |
| 4149 | fib_table_set_flow_hash_config(fib_index, FIB_PROTOCOL_IP4, new_hash_config); |
| 4150 | |
| 4151 | FIB_TEST((lb->lb_hash_config == new_hash_config), |
| 4152 | "Table and LB newhash config match: %U", |
| 4153 | format_ip_flow_hash_config, lb->lb_hash_config); |
Neale Ranns | 3983ac2 | 2017-03-10 11:53:27 -0800 | [diff] [blame] | 4154 | |
| 4155 | /* |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 4156 | * A route via DVR DPO |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 4157 | */ |
| 4158 | fei = fib_table_entry_path_add(fib_index, |
| 4159 | &pfx_10_10_10_3_s_32, |
| 4160 | FIB_SOURCE_API, |
| 4161 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 4162 | DPO_PROTO_IP4, |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 4163 | &zero_addr, |
| 4164 | tm->hw[0]->sw_if_index, |
| 4165 | ~0, |
| 4166 | 1, |
| 4167 | NULL, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 4168 | FIB_ROUTE_PATH_DVR); |
| 4169 | dpo_id_t dvr_dpo = DPO_INVALID; |
| 4170 | dvr_dpo_add_or_lock(tm->hw[0]->sw_if_index, DPO_PROTO_IP4, &dvr_dpo); |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 4171 | fib_test_lb_bucket_t ip_o_l2 = { |
| 4172 | .type = FT_LB_L2, |
| 4173 | .adj = { |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 4174 | .adj = dvr_dpo.dpoi_index, |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 4175 | }, |
| 4176 | }; |
| 4177 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4178 | FIB_TEST(!fib_test_validate_entry(fei, |
| 4179 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 4180 | 1, |
| 4181 | &ip_o_l2), |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 4182 | "10.10.10.3 via L2 on Eth0"); |
| 4183 | fib_table_entry_path_remove(fib_index, |
| 4184 | &pfx_10_10_10_3_s_32, |
| 4185 | FIB_SOURCE_API, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 4186 | DPO_PROTO_IP4, |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 4187 | &zero_addr, |
| 4188 | tm->hw[0]->sw_if_index, |
| 4189 | fib_index, |
| 4190 | 1, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 4191 | FIB_ROUTE_PATH_DVR); |
| 4192 | dpo_reset(&dvr_dpo); |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 4193 | |
| 4194 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4195 | * CLEANUP |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4196 | * remove adj-fibs: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4197 | */ |
| 4198 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4199 | &pfx_10_10_10_1_s_32, |
| 4200 | FIB_SOURCE_ADJ); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4201 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4202 | &pfx_10_10_10_2_s_32, |
| 4203 | FIB_SOURCE_ADJ); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4204 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4205 | fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_1_s_32), |
| 4206 | "10.10.10.1/32 adj-fib removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4207 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4208 | fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_2_s_32), |
| 4209 | "10.10.10.2/32 adj-fib removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4210 | |
| 4211 | /* |
| 4212 | * -2 entries and -2 non-shared path-list |
| 4213 | */ |
| 4214 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4215 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4216 | FIB_TEST((PNBR+2 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4217 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4218 | FIB_TEST((ENBR+2 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4219 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4220 | |
| 4221 | /* |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 4222 | * unlock the adjacencies for which this test provided a rewrite. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4223 | * These are the last locks on these adjs. they should thus go away. |
| 4224 | */ |
| 4225 | adj_unlock(ai_02); |
| 4226 | adj_unlock(ai_01); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 4227 | adj_unlock(ai_12_12_12_12); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4228 | |
| 4229 | FIB_TEST((0 == adj_nbr_db_size()), "ADJ DB size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4230 | adj_nbr_db_size()); |
Neale Ranns | 3dffb1e | 2016-11-01 20:38:53 +0000 | [diff] [blame] | 4231 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4232 | /* |
| 4233 | * CLEANUP |
| 4234 | * remove the interface prefixes |
| 4235 | */ |
| 4236 | local_pfx.fp_len = 32; |
| 4237 | fib_table_entry_special_remove(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4238 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4239 | fei = fib_table_lookup(fib_index, &local_pfx); |
| 4240 | |
| 4241 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4242 | fib_table_lookup_exact_match(fib_index, &local_pfx), |
| 4243 | "10.10.10.10/32 adj-fib removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4244 | |
| 4245 | local_pfx.fp_len = 24; |
| 4246 | fib_table_entry_delete(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4247 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4248 | |
| 4249 | FIB_TEST(FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4250 | fib_table_lookup_exact_match(fib_index, &local_pfx), |
| 4251 | "10.10.10.10/24 adj-fib removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4252 | |
| 4253 | /* |
| 4254 | * -2 entries and -2 non-shared path-list |
| 4255 | */ |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 4256 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4257 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4258 | FIB_TEST((PNBR == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4259 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4260 | FIB_TEST((ENBR == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4261 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4262 | |
| 4263 | /* |
| 4264 | * Last but not least, remove the VRF |
| 4265 | */ |
| 4266 | FIB_TEST((0 == fib_table_get_num_entries(fib_index, |
| 4267 | FIB_PROTOCOL_IP4, |
| 4268 | FIB_SOURCE_API)), |
| 4269 | "NO API Source'd prefixes"); |
| 4270 | FIB_TEST((0 == fib_table_get_num_entries(fib_index, |
| 4271 | FIB_PROTOCOL_IP4, |
| 4272 | FIB_SOURCE_RR)), |
| 4273 | "NO RR Source'd prefixes"); |
| 4274 | FIB_TEST((0 == fib_table_get_num_entries(fib_index, |
| 4275 | FIB_PROTOCOL_IP4, |
| 4276 | FIB_SOURCE_INTERFACE)), |
| 4277 | "NO INterface Source'd prefixes"); |
| 4278 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 4279 | fib_table_unlock(fib_index, FIB_PROTOCOL_IP4, FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4280 | |
| 4281 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4282 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4283 | FIB_TEST((PNBR-5 == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4284 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4285 | FIB_TEST((ENBR-5 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4286 | fib_entry_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4287 | FIB_TEST((ENBR-5 == pool_elts(fib_urpf_list_pool)), "uRPF pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4288 | pool_elts(fib_urpf_list_pool)); |
Neale Ranns | 994dab4 | 2017-04-18 12:56:45 -0700 | [diff] [blame] | 4289 | FIB_TEST((0 == pool_elts(load_balance_map_pool)), "LB-map pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4290 | pool_elts(load_balance_map_pool)); |
Neale Ranns | 994dab4 | 2017-04-18 12:56:45 -0700 | [diff] [blame] | 4291 | FIB_TEST((lb_count == pool_elts(load_balance_pool)), "LB pool size is %d", |
| 4292 | pool_elts(load_balance_pool)); |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 4293 | FIB_TEST((0 == pool_elts(dvr_dpo_pool)), "L2 DPO pool size is %d", |
| 4294 | pool_elts(dvr_dpo_pool)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4295 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4296 | return (res); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4297 | } |
| 4298 | |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 4299 | static int |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4300 | fib_test_v6 (void) |
| 4301 | { |
| 4302 | /* |
| 4303 | * In the default table check for the presence and correct forwarding |
| 4304 | * of the special entries |
| 4305 | */ |
| 4306 | fib_node_index_t dfrt, fei, ai, locked_ai, ai_01, ai_02; |
| 4307 | const dpo_id_t *dpo, *dpo_drop; |
| 4308 | const ip_adjacency_t *adj; |
| 4309 | const receive_dpo_t *rd; |
| 4310 | test_main_t *tm; |
| 4311 | u32 fib_index; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4312 | int ii, res; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4313 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4314 | res = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4315 | FIB_TEST((0 == adj_nbr_db_size()), "ADJ DB size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4316 | adj_nbr_db_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4317 | |
| 4318 | /* via 2001:0:0:1::2 */ |
| 4319 | ip46_address_t nh_2001_2 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4320 | .ip6 = { |
| 4321 | .as_u64 = { |
| 4322 | [0] = clib_host_to_net_u64(0x2001000000000001), |
| 4323 | [1] = clib_host_to_net_u64(0x0000000000000002), |
| 4324 | }, |
| 4325 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4326 | }; |
| 4327 | |
| 4328 | tm = &test_main; |
| 4329 | |
| 4330 | dpo_drop = drop_dpo_get(DPO_PROTO_IP6); |
| 4331 | |
| 4332 | /* Find or create FIB table 11 */ |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 4333 | fib_index = fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP6, 11, |
| 4334 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4335 | |
| 4336 | for (ii = 0; ii < 4; ii++) |
| 4337 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4338 | ip6_main.fib_index_by_sw_if_index[tm->hw[ii]->sw_if_index] = fib_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | fib_prefix_t pfx_0_0 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4342 | .fp_len = 0, |
| 4343 | .fp_proto = FIB_PROTOCOL_IP6, |
| 4344 | .fp_addr = { |
| 4345 | .ip6 = { |
| 4346 | {0, 0}, |
| 4347 | }, |
| 4348 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4349 | }; |
| 4350 | |
| 4351 | dfrt = fib_table_lookup(fib_index, &pfx_0_0); |
| 4352 | FIB_TEST((FIB_NODE_INDEX_INVALID != dfrt), "default route present"); |
| 4353 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(dfrt)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4354 | "Default route is DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4355 | |
| 4356 | dpo = fib_entry_contribute_ip_forwarding(dfrt); |
| 4357 | FIB_TEST((dpo->dpoi_index == ip6_fib_table_fwding_lookup( |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4358 | &ip6_main, |
| 4359 | 1, |
| 4360 | &pfx_0_0.fp_addr.ip6)), |
| 4361 | "default-route; fwd and non-fwd tables match"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4362 | |
| 4363 | // FIXME - check specials. |
| 4364 | |
| 4365 | /* |
| 4366 | * At this stage there is one v4 FIB with 5 routes and two v6 FIBs |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4367 | * each with 2 entries and a v6 mfib with 4 path-lists. |
| 4368 | * All entries are special so no path-list sharing. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4369 | */ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4370 | #define ENPS (5+4) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 4371 | u32 PNPS = (5+4+4); |
| 4372 | /* |
| 4373 | * if the IGMP plugin is loaded this adds two more entries to the v4 MFIB |
| 4374 | */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4375 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB is empty"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4376 | FIB_TEST((PNPS == fib_path_list_pool_size()), "path list pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4377 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4378 | FIB_TEST((ENPS == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4379 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4380 | |
| 4381 | /* |
| 4382 | * add interface routes. |
| 4383 | * validate presence of /64 attached and /128 recieve. |
| 4384 | * test for the presence of the receive address in the glean and local adj |
| 4385 | * |
| 4386 | * receive on 2001:0:0:1::1/128 |
| 4387 | */ |
| 4388 | fib_prefix_t local_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4389 | .fp_len = 64, |
| 4390 | .fp_proto = FIB_PROTOCOL_IP6, |
| 4391 | .fp_addr = { |
| 4392 | .ip6 = { |
| 4393 | .as_u64 = { |
| 4394 | [0] = clib_host_to_net_u64(0x2001000000000001), |
| 4395 | [1] = clib_host_to_net_u64(0x0000000000000001), |
| 4396 | }, |
| 4397 | }, |
| 4398 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4399 | }; |
| 4400 | |
| 4401 | fib_table_entry_update_one_path(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4402 | FIB_SOURCE_INTERFACE, |
| 4403 | (FIB_ENTRY_FLAG_CONNECTED | |
| 4404 | FIB_ENTRY_FLAG_ATTACHED), |
| 4405 | DPO_PROTO_IP6, |
| 4406 | NULL, |
| 4407 | tm->hw[0]->sw_if_index, |
| 4408 | ~0, |
| 4409 | 1, |
| 4410 | NULL, |
| 4411 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4412 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 4413 | |
| 4414 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "attached interface route present"); |
| 4415 | |
| 4416 | ai = fib_entry_get_adj(fei); |
| 4417 | FIB_TEST((FIB_NODE_INDEX_INVALID != ai), "attached interface route adj present"); |
| 4418 | adj = adj_get(ai); |
| 4419 | FIB_TEST((IP_LOOKUP_NEXT_GLEAN == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4420 | "attached interface adj is glean"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4421 | FIB_TEST((0 == ip46_address_cmp(&local_pfx.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4422 | &adj->sub_type.glean.receive_addr)), |
| 4423 | "attached interface adj is receive ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4424 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4425 | FIB_TEST((dpo->dpoi_index == ip6_fib_table_fwding_lookup( |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4426 | &ip6_main, |
| 4427 | 1, |
| 4428 | &local_pfx.fp_addr.ip6)), |
| 4429 | "attached-route; fwd and non-fwd tables match"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4430 | |
| 4431 | local_pfx.fp_len = 128; |
| 4432 | fib_table_entry_update_one_path(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4433 | FIB_SOURCE_INTERFACE, |
| 4434 | (FIB_ENTRY_FLAG_CONNECTED | |
| 4435 | FIB_ENTRY_FLAG_LOCAL), |
| 4436 | DPO_PROTO_IP6, |
| 4437 | NULL, |
| 4438 | tm->hw[0]->sw_if_index, |
| 4439 | ~0, // invalid fib index |
| 4440 | 1, |
| 4441 | NULL, |
| 4442 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4443 | fei = fib_table_lookup(fib_index, &local_pfx); |
| 4444 | |
| 4445 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local interface route present"); |
| 4446 | |
| 4447 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4448 | dpo = load_balance_get_bucket(dpo->dpoi_index, 0); |
| 4449 | FIB_TEST((DPO_RECEIVE == dpo->dpoi_type), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4450 | "local interface adj is local"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4451 | rd = receive_dpo_get(dpo->dpoi_index); |
| 4452 | |
| 4453 | FIB_TEST((0 == ip46_address_cmp(&local_pfx.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4454 | &rd->rd_addr)), |
| 4455 | "local interface adj is receive ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4456 | |
| 4457 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4458 | FIB_TEST((dpo->dpoi_index == ip6_fib_table_fwding_lookup( |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4459 | &ip6_main, |
| 4460 | 1, |
| 4461 | &local_pfx.fp_addr.ip6)), |
| 4462 | "local-route; fwd and non-fwd tables match"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4463 | |
| 4464 | /* |
| 4465 | * +2 entries. +2 unshared path-lists |
| 4466 | */ |
| 4467 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB is empty"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4468 | FIB_TEST((PNPS+2 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4469 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4470 | FIB_TEST((ENPS+2 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4471 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4472 | |
| 4473 | /* |
| 4474 | * Modify the default route to be via an adj not yet known. |
| 4475 | * this sources the defalut route with the API source, which is |
| 4476 | * a higher preference to the DEFAULT_ROUTE source |
| 4477 | */ |
| 4478 | fib_table_entry_path_add(fib_index, &pfx_0_0, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4479 | FIB_SOURCE_API, |
| 4480 | FIB_ENTRY_FLAG_NONE, |
| 4481 | DPO_PROTO_IP6, |
| 4482 | &nh_2001_2, |
| 4483 | tm->hw[0]->sw_if_index, |
| 4484 | ~0, |
| 4485 | 1, |
| 4486 | NULL, |
| 4487 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4488 | fei = fib_table_lookup(fib_index, &pfx_0_0); |
| 4489 | |
| 4490 | FIB_TEST((fei == dfrt), "default route same index"); |
| 4491 | ai = fib_entry_get_adj(fei); |
| 4492 | FIB_TEST((FIB_NODE_INDEX_INVALID != ai), "default route adj present"); |
| 4493 | adj = adj_get(ai); |
| 4494 | FIB_TEST((IP_LOOKUP_NEXT_ARP == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4495 | "adj is incomplete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4496 | FIB_TEST((0 == ip46_address_cmp(&nh_2001_2, &adj->sub_type.nbr.next_hop)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4497 | "adj nbr next-hop ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4498 | |
| 4499 | /* |
| 4500 | * find the adj in the shared db |
| 4501 | */ |
| 4502 | locked_ai = adj_nbr_add_or_lock(FIB_PROTOCOL_IP6, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4503 | VNET_LINK_IP6, |
| 4504 | &nh_2001_2, |
| 4505 | tm->hw[0]->sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4506 | FIB_TEST((locked_ai == ai), "ADJ NBR DB find"); |
| 4507 | adj_unlock(locked_ai); |
| 4508 | |
| 4509 | /* |
| 4510 | * no more entires. +1 shared path-list |
| 4511 | */ |
| 4512 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4513 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4514 | FIB_TEST((PNPS+3 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4515 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4516 | FIB_TEST((ENPS+2 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4517 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4518 | |
| 4519 | /* |
| 4520 | * remove the API source from the default route. We expected |
| 4521 | * the route to remain, sourced by DEFAULT_ROUTE, and hence a DROP |
| 4522 | */ |
| 4523 | fib_table_entry_path_remove(fib_index, &pfx_0_0, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4524 | FIB_SOURCE_API, |
| 4525 | DPO_PROTO_IP6, |
| 4526 | &nh_2001_2, |
| 4527 | tm->hw[0]->sw_if_index, |
| 4528 | ~0, |
| 4529 | 1, |
| 4530 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4531 | fei = fib_table_lookup(fib_index, &pfx_0_0); |
| 4532 | |
| 4533 | FIB_TEST((fei == dfrt), "default route same index"); |
| 4534 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(dfrt)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4535 | "Default route is DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4536 | |
| 4537 | /* |
| 4538 | * no more entires. -1 shared path-list |
| 4539 | */ |
| 4540 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4541 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4542 | FIB_TEST((PNPS+2 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4543 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4544 | FIB_TEST((ENPS+2 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4545 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4546 | |
| 4547 | /* |
| 4548 | * Add an 2 ARP entry => a complete ADJ plus adj-fib. |
| 4549 | */ |
| 4550 | fib_prefix_t pfx_2001_1_2_s_128 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4551 | .fp_len = 128, |
| 4552 | .fp_proto = FIB_PROTOCOL_IP6, |
| 4553 | .fp_addr = { |
| 4554 | .ip6 = { |
| 4555 | .as_u64 = { |
| 4556 | [0] = clib_host_to_net_u64(0x2001000000000001), |
| 4557 | [1] = clib_host_to_net_u64(0x0000000000000002), |
| 4558 | }, |
| 4559 | }, |
| 4560 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4561 | }; |
| 4562 | fib_prefix_t pfx_2001_1_3_s_128 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4563 | .fp_len = 128, |
| 4564 | .fp_proto = FIB_PROTOCOL_IP6, |
| 4565 | .fp_addr = { |
| 4566 | .ip6 = { |
| 4567 | .as_u64 = { |
| 4568 | [0] = clib_host_to_net_u64(0x2001000000000001), |
| 4569 | [1] = clib_host_to_net_u64(0x0000000000000003), |
| 4570 | }, |
| 4571 | }, |
| 4572 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4573 | }; |
| 4574 | u8 eth_addr[] = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4575 | 0xde, 0xde, 0xde, 0xba, 0xba, 0xba, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4576 | }; |
| 4577 | |
| 4578 | ai_01 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP6, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4579 | VNET_LINK_IP6, |
| 4580 | &pfx_2001_1_2_s_128.fp_addr, |
| 4581 | tm->hw[0]->sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4582 | FIB_TEST((FIB_NODE_INDEX_INVALID != ai_01), "adj created"); |
| 4583 | adj = adj_get(ai_01); |
| 4584 | FIB_TEST((IP_LOOKUP_NEXT_ARP == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4585 | "adj is incomplete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4586 | FIB_TEST((0 == ip46_address_cmp(&pfx_2001_1_2_s_128.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4587 | &adj->sub_type.nbr.next_hop)), |
| 4588 | "adj nbr next-hop ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4589 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 4590 | adj_nbr_update_rewrite(ai_01, ADJ_NBR_REWRITE_FLAG_COMPLETE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4591 | fib_test_build_rewrite(eth_addr)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4592 | FIB_TEST((IP_LOOKUP_NEXT_REWRITE == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4593 | "adj is complete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4594 | FIB_TEST((0 == ip46_address_cmp(&pfx_2001_1_2_s_128.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4595 | &adj->sub_type.nbr.next_hop)), |
| 4596 | "adj nbr next-hop ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4597 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4598 | fib_table_entry_path_add(fib_index, |
| 4599 | &pfx_2001_1_2_s_128, |
| 4600 | FIB_SOURCE_ADJ, |
| 4601 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4602 | DPO_PROTO_IP6, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4603 | &pfx_2001_1_2_s_128.fp_addr, |
| 4604 | tm->hw[0]->sw_if_index, |
| 4605 | ~0, |
| 4606 | 1, |
| 4607 | NULL, |
| 4608 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4609 | |
| 4610 | fei = fib_table_lookup(fib_index, &pfx_2001_1_2_s_128); |
| 4611 | ai = fib_entry_get_adj(fei); |
| 4612 | FIB_TEST((ai_01 == ai), "ADJ-FIB resolves via adj"); |
| 4613 | |
| 4614 | eth_addr[5] = 0xb2; |
| 4615 | |
| 4616 | ai_02 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP6, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4617 | VNET_LINK_IP6, |
| 4618 | &pfx_2001_1_3_s_128.fp_addr, |
| 4619 | tm->hw[0]->sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4620 | FIB_TEST((FIB_NODE_INDEX_INVALID != ai_02), "adj created"); |
| 4621 | adj = adj_get(ai_02); |
| 4622 | FIB_TEST((IP_LOOKUP_NEXT_ARP == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4623 | "adj is incomplete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4624 | FIB_TEST((0 == ip46_address_cmp(&pfx_2001_1_3_s_128.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4625 | &adj->sub_type.nbr.next_hop)), |
| 4626 | "adj nbr next-hop ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4627 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 4628 | adj_nbr_update_rewrite(ai_02, ADJ_NBR_REWRITE_FLAG_COMPLETE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4629 | fib_test_build_rewrite(eth_addr)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4630 | FIB_TEST((IP_LOOKUP_NEXT_REWRITE == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4631 | "adj is complete"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4632 | FIB_TEST((0 == ip46_address_cmp(&pfx_2001_1_3_s_128.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4633 | &adj->sub_type.nbr.next_hop)), |
| 4634 | "adj nbr next-hop ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4635 | FIB_TEST((ai_01 != ai_02), "ADJs are different"); |
| 4636 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4637 | fib_table_entry_path_add(fib_index, |
| 4638 | &pfx_2001_1_3_s_128, |
| 4639 | FIB_SOURCE_ADJ, |
| 4640 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4641 | DPO_PROTO_IP6, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 4642 | &pfx_2001_1_3_s_128.fp_addr, |
| 4643 | tm->hw[0]->sw_if_index, |
| 4644 | ~0, |
| 4645 | 1, |
| 4646 | NULL, |
| 4647 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4648 | |
| 4649 | fei = fib_table_lookup(fib_index, &pfx_2001_1_3_s_128); |
| 4650 | ai = fib_entry_get_adj(fei); |
| 4651 | FIB_TEST((ai_02 == ai), "ADJ-FIB resolves via adj"); |
| 4652 | |
| 4653 | /* |
| 4654 | * +2 entries, +2 unshread path-lists. |
| 4655 | */ |
| 4656 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4657 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4658 | FIB_TEST((PNPS+4 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4659 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4660 | FIB_TEST((ENPS+4 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4661 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4662 | |
| 4663 | /* |
| 4664 | * Add a 2 routes via the first ADJ. ensure path-list sharing |
| 4665 | */ |
| 4666 | fib_prefix_t pfx_2001_a_s_64 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4667 | .fp_len = 64, |
| 4668 | .fp_proto = FIB_PROTOCOL_IP6, |
| 4669 | .fp_addr = { |
| 4670 | .ip6 = { |
| 4671 | .as_u64 = { |
| 4672 | [0] = clib_host_to_net_u64(0x200100000000000a), |
| 4673 | [1] = clib_host_to_net_u64(0x0000000000000000), |
| 4674 | }, |
| 4675 | }, |
| 4676 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4677 | }; |
| 4678 | fib_prefix_t pfx_2001_b_s_64 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4679 | .fp_len = 64, |
| 4680 | .fp_proto = FIB_PROTOCOL_IP6, |
| 4681 | .fp_addr = { |
| 4682 | .ip6 = { |
| 4683 | .as_u64 = { |
| 4684 | [0] = clib_host_to_net_u64(0x200100000000000b), |
| 4685 | [1] = clib_host_to_net_u64(0x0000000000000000), |
| 4686 | }, |
| 4687 | }, |
| 4688 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4689 | }; |
| 4690 | |
| 4691 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4692 | &pfx_2001_a_s_64, |
| 4693 | FIB_SOURCE_API, |
| 4694 | FIB_ENTRY_FLAG_NONE, |
| 4695 | DPO_PROTO_IP6, |
| 4696 | &nh_2001_2, |
| 4697 | tm->hw[0]->sw_if_index, |
| 4698 | ~0, |
| 4699 | 1, |
| 4700 | NULL, |
| 4701 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4702 | fei = fib_table_lookup(fib_index, &pfx_2001_a_s_64); |
| 4703 | ai = fib_entry_get_adj(fei); |
| 4704 | FIB_TEST((ai_01 == ai), "2001::a/64 resolves via 2001:0:0:1::1"); |
| 4705 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4706 | &pfx_2001_b_s_64, |
| 4707 | FIB_SOURCE_API, |
| 4708 | FIB_ENTRY_FLAG_NONE, |
| 4709 | DPO_PROTO_IP6, |
| 4710 | &nh_2001_2, |
| 4711 | tm->hw[0]->sw_if_index, |
| 4712 | ~0, |
| 4713 | 1, |
| 4714 | NULL, |
| 4715 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4716 | fei = fib_table_lookup(fib_index, &pfx_2001_b_s_64); |
| 4717 | ai = fib_entry_get_adj(fei); |
| 4718 | FIB_TEST((ai_01 == ai), "2001::b/64 resolves via 2001:0:0:1::1"); |
| 4719 | |
| 4720 | /* |
| 4721 | * +2 entries, +1 shared path-list. |
| 4722 | */ |
| 4723 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4724 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4725 | FIB_TEST((PNPS+5 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4726 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4727 | FIB_TEST((ENPS+6 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4728 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4729 | |
| 4730 | /* |
| 4731 | * add a v4 prefix via a v6 next-hop |
| 4732 | */ |
| 4733 | fib_prefix_t pfx_1_1_1_1_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4734 | .fp_len = 32, |
| 4735 | .fp_proto = FIB_PROTOCOL_IP4, |
| 4736 | .fp_addr = { |
| 4737 | .ip4.as_u32 = 0x01010101, |
| 4738 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4739 | }; |
| 4740 | fei = fib_table_entry_path_add(0, // default table |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4741 | &pfx_1_1_1_1_s_32, |
| 4742 | FIB_SOURCE_API, |
| 4743 | FIB_ENTRY_FLAG_NONE, |
| 4744 | DPO_PROTO_IP6, |
| 4745 | &nh_2001_2, |
| 4746 | tm->hw[0]->sw_if_index, |
| 4747 | ~0, |
| 4748 | 1, |
| 4749 | NULL, |
| 4750 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4751 | FIB_TEST(fei == fib_table_lookup_exact_match(0, &pfx_1_1_1_1_s_32), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4752 | "1.1.1.1/32 o v6 route present"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4753 | ai = fib_entry_get_adj(fei); |
| 4754 | adj = adj_get(ai); |
| 4755 | FIB_TEST((adj->lookup_next_index == IP_LOOKUP_NEXT_ARP), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4756 | "1.1.1.1/32 via ARP-adj"); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 4757 | FIB_TEST((adj->ia_link == VNET_LINK_IP4), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4758 | "1.1.1.1/32 ADJ-adj is link type v4"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4759 | FIB_TEST((adj->ia_nh_proto == FIB_PROTOCOL_IP6), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4760 | "1.1.1.1/32 ADJ-adj is NH proto v6"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4761 | fib_table_entry_delete(0, &pfx_1_1_1_1_s_32, FIB_SOURCE_API); |
| 4762 | |
| 4763 | /* |
| 4764 | * An attached route |
| 4765 | */ |
| 4766 | fib_prefix_t pfx_2001_c_s_64 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4767 | .fp_len = 64, |
| 4768 | .fp_proto = FIB_PROTOCOL_IP6, |
| 4769 | .fp_addr = { |
| 4770 | .ip6 = { |
| 4771 | .as_u64 = { |
| 4772 | [0] = clib_host_to_net_u64(0x200100000000000c), |
| 4773 | [1] = clib_host_to_net_u64(0x0000000000000000), |
| 4774 | }, |
| 4775 | }, |
| 4776 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4777 | }; |
| 4778 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4779 | &pfx_2001_c_s_64, |
| 4780 | FIB_SOURCE_CLI, |
| 4781 | FIB_ENTRY_FLAG_ATTACHED, |
| 4782 | DPO_PROTO_IP6, |
| 4783 | NULL, |
| 4784 | tm->hw[0]->sw_if_index, |
| 4785 | ~0, |
| 4786 | 1, |
| 4787 | NULL, |
| 4788 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4789 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_c_s_64); |
| 4790 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "attached route present"); |
| 4791 | ai = fib_entry_get_adj(fei); |
| 4792 | adj = adj_get(ai); |
| 4793 | FIB_TEST((adj->lookup_next_index == IP_LOOKUP_NEXT_GLEAN), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4794 | "2001:0:0:c/64 attached resolves via glean"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4795 | |
| 4796 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4797 | &pfx_2001_c_s_64, |
| 4798 | FIB_SOURCE_CLI, |
| 4799 | DPO_PROTO_IP6, |
| 4800 | NULL, |
| 4801 | tm->hw[0]->sw_if_index, |
| 4802 | ~0, |
| 4803 | 1, |
| 4804 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4805 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_c_s_64); |
| 4806 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "attached route removed"); |
| 4807 | |
| 4808 | /* |
| 4809 | * Shutdown the interface on which we have a connected and through |
| 4810 | * which the routes are reachable. |
| 4811 | * This will result in the connected, adj-fibs, and routes linking to drop |
| 4812 | * The local/for-us prefix continues to receive. |
| 4813 | */ |
| 4814 | clib_error_t * error; |
| 4815 | |
| 4816 | error = vnet_sw_interface_set_flags(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4817 | tm->hw[0]->sw_if_index, |
| 4818 | ~VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4819 | FIB_TEST((NULL == error), "Interface shutdown OK"); |
| 4820 | |
| 4821 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_b_s_64); |
| 4822 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4823 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4824 | "2001::b/64 resolves via drop"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4825 | |
| 4826 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_a_s_64); |
| 4827 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4828 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4829 | "2001::a/64 resolves via drop"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4830 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_3_s_128); |
| 4831 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4832 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4833 | "2001:0:0:1::3/64 resolves via drop"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4834 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_2_s_128); |
| 4835 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4836 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4837 | "2001:0:0:1::2/64 resolves via drop"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4838 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 4839 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4840 | FIB_TEST(dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4841 | "2001:0:0:1::1/128 not drop"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4842 | local_pfx.fp_len = 64; |
| 4843 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 4844 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4845 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4846 | "2001:0:0:1/64 resolves via drop"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4847 | |
| 4848 | /* |
| 4849 | * no change |
| 4850 | */ |
| 4851 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4852 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4853 | FIB_TEST((PNPS+5 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4854 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4855 | FIB_TEST((ENPS+6 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4856 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4857 | |
| 4858 | /* |
| 4859 | * shutdown one of the other interfaces, then add a connected. |
| 4860 | * and swap one of the routes to it. |
| 4861 | */ |
| 4862 | error = vnet_sw_interface_set_flags(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4863 | tm->hw[1]->sw_if_index, |
| 4864 | ~VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4865 | FIB_TEST((NULL == error), "Interface 1 shutdown OK"); |
| 4866 | |
| 4867 | fib_prefix_t connected_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4868 | .fp_len = 64, |
| 4869 | .fp_proto = FIB_PROTOCOL_IP6, |
| 4870 | .fp_addr = { |
| 4871 | .ip6 = { |
| 4872 | /* 2001:0:0:2::1/64 */ |
| 4873 | .as_u64 = { |
| 4874 | [0] = clib_host_to_net_u64(0x2001000000000002), |
| 4875 | [1] = clib_host_to_net_u64(0x0000000000000001), |
| 4876 | }, |
| 4877 | }, |
| 4878 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4879 | }; |
| 4880 | fib_table_entry_update_one_path(fib_index, &connected_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4881 | FIB_SOURCE_INTERFACE, |
| 4882 | (FIB_ENTRY_FLAG_CONNECTED | |
| 4883 | FIB_ENTRY_FLAG_ATTACHED), |
| 4884 | DPO_PROTO_IP6, |
| 4885 | NULL, |
| 4886 | tm->hw[1]->sw_if_index, |
| 4887 | ~0, |
| 4888 | 1, |
| 4889 | NULL, |
| 4890 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4891 | fei = fib_table_lookup_exact_match(fib_index, &connected_pfx); |
| 4892 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "attached interface route present"); |
| 4893 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4894 | dpo = load_balance_get_bucket(dpo->dpoi_index, 0); |
| 4895 | FIB_TEST(!dpo_cmp(dpo, dpo_drop), |
| 4896 | "2001:0:0:2/64 not resolves via drop"); |
| 4897 | |
| 4898 | connected_pfx.fp_len = 128; |
| 4899 | fib_table_entry_update_one_path(fib_index, &connected_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4900 | FIB_SOURCE_INTERFACE, |
| 4901 | (FIB_ENTRY_FLAG_CONNECTED | |
| 4902 | FIB_ENTRY_FLAG_LOCAL), |
| 4903 | DPO_PROTO_IP6, |
| 4904 | NULL, |
| 4905 | tm->hw[0]->sw_if_index, |
| 4906 | ~0, // invalid fib index |
| 4907 | 1, |
| 4908 | NULL, |
| 4909 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4910 | fei = fib_table_lookup(fib_index, &connected_pfx); |
| 4911 | |
| 4912 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local interface route present"); |
| 4913 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4914 | dpo = load_balance_get_bucket(dpo->dpoi_index, 0); |
| 4915 | FIB_TEST((DPO_RECEIVE == dpo->dpoi_type), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4916 | "local interface adj is local"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4917 | rd = receive_dpo_get(dpo->dpoi_index); |
| 4918 | FIB_TEST((0 == ip46_address_cmp(&connected_pfx.fp_addr, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4919 | &rd->rd_addr)), |
| 4920 | "local interface adj is receive ok"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4921 | |
| 4922 | /* |
| 4923 | * +2 entries, +2 unshared path-lists |
| 4924 | */ |
| 4925 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4926 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4927 | FIB_TEST((PNPS+7 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4928 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 4929 | FIB_TEST((ENPS+8 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4930 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4931 | |
| 4932 | |
| 4933 | /* |
| 4934 | * bring the interface back up. we expected the routes to return |
| 4935 | * to normal forwarding. |
| 4936 | */ |
| 4937 | error = vnet_sw_interface_set_flags(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4938 | tm->hw[0]->sw_if_index, |
| 4939 | VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4940 | FIB_TEST((NULL == error), "Interface bring-up OK"); |
| 4941 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_a_s_64); |
| 4942 | ai = fib_entry_get_adj(fei); |
| 4943 | FIB_TEST((ai_01 == ai), "2001::a/64 resolves via 2001:0:0:1::1"); |
| 4944 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_b_s_64); |
| 4945 | ai = fib_entry_get_adj(fei); |
| 4946 | FIB_TEST((ai_01 == ai), "2001::b/64 resolves via 2001:0:0:1::1"); |
| 4947 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_3_s_128); |
| 4948 | ai = fib_entry_get_adj(fei); |
| 4949 | FIB_TEST((ai_02 == ai), "ADJ-FIB resolves via adj"); |
| 4950 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_2_s_128); |
| 4951 | ai = fib_entry_get_adj(fei); |
| 4952 | FIB_TEST((ai_01 == ai), "ADJ-FIB resolves via adj"); |
| 4953 | local_pfx.fp_len = 64; |
| 4954 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 4955 | ai = fib_entry_get_adj(fei); |
| 4956 | adj = adj_get(ai); |
| 4957 | FIB_TEST((IP_LOOKUP_NEXT_GLEAN == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4958 | "attached interface adj is glean"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 4959 | |
| 4960 | /* |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 4961 | * Same test as above, but this time the HW interface goes down |
| 4962 | */ |
| 4963 | error = vnet_hw_interface_set_flags(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4964 | tm->hw_if_indicies[0], |
| 4965 | ~VNET_HW_INTERFACE_FLAG_LINK_UP); |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 4966 | FIB_TEST((NULL == error), "Interface shutdown OK"); |
| 4967 | |
| 4968 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_b_s_64); |
| 4969 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4970 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4971 | "2001::b/64 resolves via drop"); |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 4972 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_a_s_64); |
| 4973 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4974 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4975 | "2001::a/64 resolves via drop"); |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 4976 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_3_s_128); |
| 4977 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4978 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4979 | "2001:0:0:1::3/128 resolves via drop"); |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 4980 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_2_s_128); |
| 4981 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4982 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4983 | "2001:0:0:1::2/128 resolves via drop"); |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 4984 | local_pfx.fp_len = 128; |
| 4985 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 4986 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4987 | FIB_TEST(dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4988 | "2001:0:0:1::1/128 not drop"); |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 4989 | local_pfx.fp_len = 64; |
| 4990 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 4991 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 4992 | FIB_TEST(!dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4993 | "2001:0:0:1/64 resolves via drop"); |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 4994 | |
| 4995 | error = vnet_hw_interface_set_flags(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 4996 | tm->hw_if_indicies[0], |
| 4997 | VNET_HW_INTERFACE_FLAG_LINK_UP); |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 4998 | FIB_TEST((NULL == error), "Interface bring-up OK"); |
| 4999 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_a_s_64); |
| 5000 | ai = fib_entry_get_adj(fei); |
| 5001 | FIB_TEST((ai_01 == ai), "2001::a/64 resolves via 2001:0:0:1::1"); |
| 5002 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_b_s_64); |
| 5003 | ai = fib_entry_get_adj(fei); |
| 5004 | FIB_TEST((ai_01 == ai), "2001::b/64 resolves via 2001:0:0:1::1"); |
| 5005 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_3_s_128); |
| 5006 | ai = fib_entry_get_adj(fei); |
| 5007 | FIB_TEST((ai_02 == ai), "ADJ-FIB resolves via adj"); |
| 5008 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_2_s_128); |
| 5009 | ai = fib_entry_get_adj(fei); |
| 5010 | FIB_TEST((ai_01 == ai), "ADJ-FIB resolves via adj"); |
| 5011 | local_pfx.fp_len = 64; |
| 5012 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 5013 | ai = fib_entry_get_adj(fei); |
| 5014 | adj = adj_get(ai); |
| 5015 | FIB_TEST((IP_LOOKUP_NEXT_GLEAN == adj->lookup_next_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5016 | "attached interface adj is glean"); |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 5017 | |
| 5018 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5019 | * Delete the interface that the routes reolve through. |
| 5020 | * Again no routes are removed. They all point to drop. |
| 5021 | * |
| 5022 | * This is considered an error case. The control plane should |
| 5023 | * not remove interfaces through which routes resolve, but |
| 5024 | * such things can happen. ALL affected routes will drop. |
| 5025 | */ |
| 5026 | vnet_delete_hw_interface(vnet_get_main(), tm->hw_if_indicies[0]); |
| 5027 | |
| 5028 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_b_s_64); |
| 5029 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5030 | "2001::b/64 resolves via drop"); |
| 5031 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_a_s_64); |
| 5032 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5033 | "2001::b/64 resolves via drop"); |
| 5034 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_3_s_128); |
| 5035 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5036 | "2001:0:0:1::3/64 resolves via drop"); |
| 5037 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_2_s_128); |
| 5038 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5039 | "2001:0:0:1::2/64 resolves via drop"); |
| 5040 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 5041 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5042 | "2001:0:0:1::1/128 is drop"); |
| 5043 | local_pfx.fp_len = 64; |
| 5044 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 5045 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5046 | "2001:0:0:1/64 resolves via drop"); |
| 5047 | |
| 5048 | /* |
| 5049 | * no change |
| 5050 | */ |
| 5051 | FIB_TEST((1 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5052 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 5053 | FIB_TEST((PNPS+7 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5054 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 5055 | FIB_TEST((ENPS+8 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5056 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5057 | |
| 5058 | /* |
| 5059 | * Add the interface back. routes stay unresolved. |
| 5060 | */ |
| 5061 | error = ethernet_register_interface(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5062 | test_interface_device_class.index, |
| 5063 | 0 /* instance */, |
| 5064 | hw_address, |
| 5065 | &tm->hw_if_indicies[0], |
| 5066 | /* flag change */ 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5067 | |
| 5068 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_b_s_64); |
| 5069 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5070 | "2001::b/64 resolves via drop"); |
| 5071 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_a_s_64); |
| 5072 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5073 | "2001::b/64 resolves via drop"); |
| 5074 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_3_s_128); |
| 5075 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5076 | "2001:0:0:1::3/64 resolves via drop"); |
| 5077 | fei = fib_table_lookup_exact_match(fib_index, &pfx_2001_1_2_s_128); |
| 5078 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5079 | "2001:0:0:1::2/64 resolves via drop"); |
| 5080 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 5081 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5082 | "2001:0:0:1::1/128 is drop"); |
| 5083 | local_pfx.fp_len = 64; |
| 5084 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 5085 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 5086 | "2001:0:0:1/64 resolves via drop"); |
| 5087 | |
| 5088 | /* |
| 5089 | * CLEANUP ALL the routes |
| 5090 | */ |
| 5091 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5092 | &pfx_2001_c_s_64, |
| 5093 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5094 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5095 | &pfx_2001_a_s_64, |
| 5096 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5097 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5098 | &pfx_2001_b_s_64, |
| 5099 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5100 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5101 | &pfx_2001_1_3_s_128, |
| 5102 | FIB_SOURCE_ADJ); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5103 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5104 | &pfx_2001_1_2_s_128, |
| 5105 | FIB_SOURCE_ADJ); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5106 | local_pfx.fp_len = 64; |
| 5107 | fib_table_entry_delete(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5108 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5109 | local_pfx.fp_len = 128; |
| 5110 | fib_table_entry_special_remove(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5111 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5112 | connected_pfx.fp_len = 64; |
| 5113 | fib_table_entry_delete(fib_index, &connected_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5114 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5115 | connected_pfx.fp_len = 128; |
| 5116 | fib_table_entry_special_remove(fib_index, &connected_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5117 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5118 | |
| 5119 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5120 | fib_table_lookup_exact_match(fib_index, &pfx_2001_a_s_64)), |
| 5121 | "2001::a/64 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5122 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5123 | fib_table_lookup_exact_match(fib_index, &pfx_2001_b_s_64)), |
| 5124 | "2001::b/64 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5125 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5126 | fib_table_lookup_exact_match(fib_index, &pfx_2001_1_3_s_128)), |
| 5127 | "2001:0:0:1::3/128 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5128 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5129 | fib_table_lookup_exact_match(fib_index, &pfx_2001_1_2_s_128)), |
| 5130 | "2001:0:0:1::3/128 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5131 | local_pfx.fp_len = 64; |
| 5132 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5133 | fib_table_lookup_exact_match(fib_index, &local_pfx)), |
| 5134 | "2001:0:0:1/64 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5135 | local_pfx.fp_len = 128; |
| 5136 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5137 | fib_table_lookup_exact_match(fib_index, &local_pfx)), |
| 5138 | "2001:0:0:1::1/128 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5139 | connected_pfx.fp_len = 64; |
| 5140 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5141 | fib_table_lookup_exact_match(fib_index, &connected_pfx)), |
| 5142 | "2001:0:0:2/64 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5143 | connected_pfx.fp_len = 128; |
| 5144 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5145 | fib_table_lookup_exact_match(fib_index, &connected_pfx)), |
| 5146 | "2001:0:0:2::1/128 removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5147 | |
| 5148 | /* |
| 5149 | * -8 entries. -7 path-lists (1 was shared). |
| 5150 | */ |
| 5151 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5152 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 5153 | FIB_TEST((PNPS == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5154 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 5155 | FIB_TEST((ENPS == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5156 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5157 | |
| 5158 | /* |
| 5159 | * now remove the VRF |
| 5160 | */ |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 5161 | fib_table_unlock(fib_index, FIB_PROTOCOL_IP6, FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5162 | |
| 5163 | FIB_TEST((0 == fib_path_list_db_size()), "path list DB population:%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5164 | fib_path_list_db_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 5165 | FIB_TEST((PNPS-2 == fib_path_list_pool_size()), "path list pool size is%d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5166 | fib_path_list_pool_size()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 5167 | FIB_TEST((ENPS-2 == fib_entry_pool_size()), "entry pool size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5168 | fib_entry_pool_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5169 | |
| 5170 | adj_unlock(ai_02); |
| 5171 | adj_unlock(ai_01); |
| 5172 | |
| 5173 | /* |
| 5174 | * return the interfaces to up state |
| 5175 | */ |
| 5176 | error = vnet_sw_interface_set_flags(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5177 | tm->hw[0]->sw_if_index, |
| 5178 | VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5179 | error = vnet_sw_interface_set_flags(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5180 | tm->hw[1]->sw_if_index, |
| 5181 | VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5182 | |
| 5183 | FIB_TEST((0 == adj_nbr_db_size()), "ADJ DB size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5184 | adj_nbr_db_size()); |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 5185 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5186 | return (res); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5187 | } |
| 5188 | |
| 5189 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5190 | * Test Attached Exports |
| 5191 | */ |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 5192 | static int |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5193 | fib_test_ae (void) |
| 5194 | { |
| 5195 | const dpo_id_t *dpo, *dpo_drop; |
| 5196 | const u32 fib_index = 0; |
| 5197 | fib_node_index_t fei; |
| 5198 | test_main_t *tm; |
| 5199 | ip4_main_t *im; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5200 | int res; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5201 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5202 | res = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5203 | tm = &test_main; |
| 5204 | im = &ip4_main; |
| 5205 | |
| 5206 | FIB_TEST((0 == adj_nbr_db_size()), "ADJ DB size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5207 | adj_nbr_db_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5208 | |
| 5209 | /* |
| 5210 | * add interface routes. We'll assume this works. It's more rigorously |
| 5211 | * tested elsewhere. |
| 5212 | */ |
| 5213 | fib_prefix_t local_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5214 | .fp_len = 24, |
| 5215 | .fp_proto = FIB_PROTOCOL_IP4, |
| 5216 | .fp_addr = { |
| 5217 | .ip4 = { |
| 5218 | /* 10.10.10.10 */ |
| 5219 | .as_u32 = clib_host_to_net_u32(0x0a0a0a0a), |
| 5220 | }, |
| 5221 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5222 | }; |
| 5223 | |
| 5224 | vec_validate(im->fib_index_by_sw_if_index, tm->hw[0]->sw_if_index); |
| 5225 | im->fib_index_by_sw_if_index[tm->hw[0]->sw_if_index] = fib_index; |
| 5226 | |
| 5227 | dpo_drop = drop_dpo_get(DPO_PROTO_IP4); |
| 5228 | |
| 5229 | fib_table_entry_update_one_path(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5230 | FIB_SOURCE_INTERFACE, |
| 5231 | (FIB_ENTRY_FLAG_CONNECTED | |
| 5232 | FIB_ENTRY_FLAG_ATTACHED), |
| 5233 | DPO_PROTO_IP4, |
| 5234 | NULL, |
| 5235 | tm->hw[0]->sw_if_index, |
| 5236 | ~0, |
| 5237 | 1, |
| 5238 | NULL, |
| 5239 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5240 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 5241 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5242 | "attached interface route present"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5243 | |
| 5244 | local_pfx.fp_len = 32; |
| 5245 | fib_table_entry_update_one_path(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5246 | FIB_SOURCE_INTERFACE, |
| 5247 | (FIB_ENTRY_FLAG_CONNECTED | |
| 5248 | FIB_ENTRY_FLAG_LOCAL), |
| 5249 | DPO_PROTO_IP4, |
| 5250 | NULL, |
| 5251 | tm->hw[0]->sw_if_index, |
| 5252 | ~0, // invalid fib index |
| 5253 | 1, |
| 5254 | NULL, |
| 5255 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5256 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 5257 | |
| 5258 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5259 | "local interface route present"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5260 | |
| 5261 | /* |
| 5262 | * Add an 2 ARP entry => a complete ADJ plus adj-fib. |
| 5263 | */ |
| 5264 | fib_prefix_t pfx_10_10_10_1_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5265 | .fp_len = 32, |
| 5266 | .fp_proto = FIB_PROTOCOL_IP4, |
| 5267 | .fp_addr = { |
| 5268 | /* 10.10.10.1 */ |
| 5269 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a01), |
| 5270 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5271 | }; |
| 5272 | fib_node_index_t ai; |
| 5273 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 5274 | fib_table_entry_path_add(fib_index, |
| 5275 | &pfx_10_10_10_1_s_32, |
| 5276 | FIB_SOURCE_ADJ, |
| 5277 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 5278 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 5279 | &pfx_10_10_10_1_s_32.fp_addr, |
| 5280 | tm->hw[0]->sw_if_index, |
| 5281 | ~0, // invalid fib index |
| 5282 | 1, |
| 5283 | NULL, |
| 5284 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5285 | |
| 5286 | fei = fib_table_lookup(fib_index, &pfx_10_10_10_1_s_32); |
| 5287 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib1 created"); |
| 5288 | ai = fib_entry_get_adj(fei); |
| 5289 | |
| 5290 | /* |
| 5291 | * create another FIB table into which routes will be imported |
| 5292 | */ |
| 5293 | u32 import_fib_index1; |
| 5294 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 5295 | import_fib_index1 = fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP4, |
| 5296 | 11, |
| 5297 | FIB_SOURCE_CLI); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5298 | |
| 5299 | /* |
| 5300 | * Add an attached route in the import FIB |
| 5301 | */ |
| 5302 | local_pfx.fp_len = 24; |
| 5303 | fib_table_entry_update_one_path(import_fib_index1, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5304 | &local_pfx, |
| 5305 | FIB_SOURCE_API, |
| 5306 | FIB_ENTRY_FLAG_NONE, |
| 5307 | DPO_PROTO_IP4, |
| 5308 | NULL, |
| 5309 | tm->hw[0]->sw_if_index, |
| 5310 | ~0, // invalid fib index |
| 5311 | 1, |
| 5312 | NULL, |
| 5313 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5314 | fei = fib_table_lookup_exact_match(import_fib_index1, &local_pfx); |
| 5315 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "attached export created"); |
| 5316 | |
| 5317 | /* |
| 5318 | * check for the presence of the adj-fibs in the import table |
| 5319 | */ |
| 5320 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_1_s_32); |
| 5321 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib1 imported"); |
| 5322 | FIB_TEST((ai == fib_entry_get_adj(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5323 | "adj-fib1 Import uses same adj as export"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5324 | |
| 5325 | /* |
| 5326 | * check for the presence of the local in the import table |
| 5327 | */ |
| 5328 | local_pfx.fp_len = 32; |
| 5329 | fei = fib_table_lookup_exact_match(import_fib_index1, &local_pfx); |
| 5330 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local imported"); |
| 5331 | |
| 5332 | /* |
| 5333 | * Add another adj-fin in the export table. Expect this |
| 5334 | * to get magically exported; |
| 5335 | */ |
| 5336 | fib_prefix_t pfx_10_10_10_2_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5337 | .fp_len = 32, |
| 5338 | .fp_proto = FIB_PROTOCOL_IP4, |
| 5339 | .fp_addr = { |
| 5340 | /* 10.10.10.2 */ |
| 5341 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a02), |
| 5342 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5343 | }; |
| 5344 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 5345 | fib_table_entry_path_add(fib_index, |
| 5346 | &pfx_10_10_10_2_s_32, |
| 5347 | FIB_SOURCE_ADJ, |
| 5348 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 5349 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 5350 | &pfx_10_10_10_2_s_32.fp_addr, |
| 5351 | tm->hw[0]->sw_if_index, |
| 5352 | ~0, // invalid fib index |
| 5353 | 1, |
| 5354 | NULL, |
| 5355 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5356 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_2_s_32); |
| 5357 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib2 present"); |
| 5358 | ai = fib_entry_get_adj(fei); |
| 5359 | |
| 5360 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_2_s_32); |
| 5361 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib2 imported"); |
| 5362 | FIB_TEST((ai == fib_entry_get_adj(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5363 | "Import uses same adj as export"); |
Neale Ranns | fa0fb58 | 2016-12-10 21:59:14 +0000 | [diff] [blame] | 5364 | FIB_TEST((FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags(fei)), |
| 5365 | "ADJ-fib2 imported flags %d", |
| 5366 | fib_entry_get_flags(fei)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5367 | |
| 5368 | /* |
| 5369 | * create a 2nd FIB table into which routes will be imported |
| 5370 | */ |
| 5371 | u32 import_fib_index2; |
| 5372 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 5373 | import_fib_index2 = fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP4, 12, |
| 5374 | FIB_SOURCE_CLI); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5375 | |
| 5376 | /* |
| 5377 | * Add an attached route in the import FIB |
| 5378 | */ |
| 5379 | local_pfx.fp_len = 24; |
| 5380 | fib_table_entry_update_one_path(import_fib_index2, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5381 | &local_pfx, |
| 5382 | FIB_SOURCE_API, |
| 5383 | FIB_ENTRY_FLAG_NONE, |
| 5384 | DPO_PROTO_IP4, |
| 5385 | NULL, |
| 5386 | tm->hw[0]->sw_if_index, |
| 5387 | ~0, // invalid fib index |
| 5388 | 1, |
| 5389 | NULL, |
| 5390 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5391 | fei = fib_table_lookup_exact_match(import_fib_index1, &local_pfx); |
| 5392 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "attached export created"); |
| 5393 | |
| 5394 | /* |
| 5395 | * check for the presence of all the adj-fibs and local in the import table |
| 5396 | */ |
| 5397 | fei = fib_table_lookup_exact_match(import_fib_index2, &pfx_10_10_10_1_s_32); |
| 5398 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib1 imported"); |
| 5399 | fei = fib_table_lookup_exact_match(import_fib_index2, &pfx_10_10_10_2_s_32); |
| 5400 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib2 imported"); |
| 5401 | local_pfx.fp_len = 32; |
| 5402 | fei = fib_table_lookup_exact_match(import_fib_index2, &local_pfx); |
| 5403 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local imported"); |
| 5404 | |
| 5405 | /* |
| 5406 | * add a 3rd adj-fib. expect it to be exported to both tables. |
| 5407 | */ |
| 5408 | fib_prefix_t pfx_10_10_10_3_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5409 | .fp_len = 32, |
| 5410 | .fp_proto = FIB_PROTOCOL_IP4, |
| 5411 | .fp_addr = { |
| 5412 | /* 10.10.10.3 */ |
| 5413 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a03), |
| 5414 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5415 | }; |
| 5416 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 5417 | fib_table_entry_path_add(fib_index, |
| 5418 | &pfx_10_10_10_3_s_32, |
| 5419 | FIB_SOURCE_ADJ, |
| 5420 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 5421 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 5422 | &pfx_10_10_10_3_s_32.fp_addr, |
| 5423 | tm->hw[0]->sw_if_index, |
| 5424 | ~0, // invalid fib index |
| 5425 | 1, |
| 5426 | NULL, |
| 5427 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5428 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_3_s_32); |
| 5429 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib3 present"); |
| 5430 | ai = fib_entry_get_adj(fei); |
| 5431 | |
| 5432 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_3_s_32); |
| 5433 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib3 imported to FIB1"); |
| 5434 | FIB_TEST((ai == fib_entry_get_adj(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5435 | "Import uses same adj as export"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5436 | fei = fib_table_lookup_exact_match(import_fib_index2, &pfx_10_10_10_3_s_32); |
| 5437 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib3 imported to FIB2"); |
| 5438 | FIB_TEST((ai == fib_entry_get_adj(fei)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5439 | "Import uses same adj as export"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5440 | |
| 5441 | /* |
| 5442 | * remove the 3rd adj fib. we expect it to be removed from both FIBs |
| 5443 | */ |
| 5444 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5445 | &pfx_10_10_10_3_s_32, |
| 5446 | FIB_SOURCE_ADJ); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5447 | |
| 5448 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_3_s_32); |
| 5449 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "ADJ-fib3 remved"); |
| 5450 | |
| 5451 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_3_s_32); |
| 5452 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "ADJ-fib3 removed from FIB1"); |
| 5453 | |
| 5454 | fei = fib_table_lookup_exact_match(import_fib_index2, &pfx_10_10_10_3_s_32); |
| 5455 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "ADJ-fib3 removed from FIB2"); |
| 5456 | |
| 5457 | /* |
| 5458 | * remove the attached route from the 2nd FIB. expect the imported |
| 5459 | * entires to be removed |
| 5460 | */ |
| 5461 | local_pfx.fp_len = 24; |
| 5462 | fib_table_entry_delete(import_fib_index2, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5463 | &local_pfx, |
| 5464 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5465 | fei = fib_table_lookup_exact_match(import_fib_index2, &local_pfx); |
| 5466 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "attached export removed"); |
| 5467 | |
| 5468 | fei = fib_table_lookup_exact_match(import_fib_index2, &pfx_10_10_10_1_s_32); |
| 5469 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "ADJ-fib1 removed from FIB2"); |
| 5470 | fei = fib_table_lookup_exact_match(import_fib_index2, &pfx_10_10_10_2_s_32); |
| 5471 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "ADJ-fib2 removed from FIB2"); |
| 5472 | local_pfx.fp_len = 32; |
| 5473 | fei = fib_table_lookup_exact_match(import_fib_index2, &local_pfx); |
| 5474 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "local removed from FIB2"); |
| 5475 | |
| 5476 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_1_s_32); |
| 5477 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib1 still in FIB1"); |
| 5478 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_2_s_32); |
| 5479 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib2 still in FIB1"); |
| 5480 | local_pfx.fp_len = 32; |
| 5481 | fei = fib_table_lookup_exact_match(import_fib_index1, &local_pfx); |
| 5482 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local still in FIB1"); |
| 5483 | |
| 5484 | /* |
| 5485 | * modify the route in FIB1 so it is no longer attached. expect the imported |
| 5486 | * entires to be removed |
| 5487 | */ |
| 5488 | local_pfx.fp_len = 24; |
| 5489 | fib_table_entry_update_one_path(import_fib_index1, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5490 | &local_pfx, |
| 5491 | FIB_SOURCE_API, |
| 5492 | FIB_ENTRY_FLAG_NONE, |
| 5493 | DPO_PROTO_IP4, |
| 5494 | &pfx_10_10_10_2_s_32.fp_addr, |
| 5495 | tm->hw[0]->sw_if_index, |
| 5496 | ~0, // invalid fib index |
| 5497 | 1, |
| 5498 | NULL, |
| 5499 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5500 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_1_s_32); |
| 5501 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "ADJ-fib1 removed from FIB1"); |
| 5502 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_2_s_32); |
| 5503 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "ADJ-fib2 removed from FIB1"); |
| 5504 | local_pfx.fp_len = 32; |
| 5505 | fei = fib_table_lookup_exact_match(import_fib_index1, &local_pfx); |
| 5506 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "local removed from FIB1"); |
| 5507 | |
| 5508 | /* |
| 5509 | * modify it back to attached. expect the adj-fibs back |
| 5510 | */ |
| 5511 | local_pfx.fp_len = 24; |
| 5512 | fib_table_entry_update_one_path(import_fib_index1, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5513 | &local_pfx, |
| 5514 | FIB_SOURCE_API, |
| 5515 | FIB_ENTRY_FLAG_NONE, |
| 5516 | DPO_PROTO_IP4, |
| 5517 | NULL, |
| 5518 | tm->hw[0]->sw_if_index, |
| 5519 | ~0, // invalid fib index |
| 5520 | 1, |
| 5521 | NULL, |
| 5522 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5523 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_1_s_32); |
| 5524 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib1 imported in FIB1"); |
| 5525 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_2_s_32); |
| 5526 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib2 imported in FIB1"); |
| 5527 | local_pfx.fp_len = 32; |
| 5528 | fei = fib_table_lookup_exact_match(import_fib_index1, &local_pfx); |
| 5529 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local imported in FIB1"); |
| 5530 | |
| 5531 | /* |
| 5532 | * add a covering attached next-hop for the interface address, so we have |
| 5533 | * a valid adj to find when we check the forwarding tables |
| 5534 | */ |
| 5535 | fib_prefix_t pfx_10_0_0_0_s_8 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5536 | .fp_len = 8, |
| 5537 | .fp_proto = FIB_PROTOCOL_IP4, |
| 5538 | .fp_addr = { |
| 5539 | /* 10.0.0.0 */ |
| 5540 | .ip4.as_u32 = clib_host_to_net_u32(0x0a000000), |
| 5541 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5542 | }; |
| 5543 | |
| 5544 | fei = fib_table_entry_update_one_path(fib_index, |
| 5545 | &pfx_10_0_0_0_s_8, |
| 5546 | FIB_SOURCE_API, |
| 5547 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5548 | DPO_PROTO_IP4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5549 | &pfx_10_10_10_3_s_32.fp_addr, |
| 5550 | tm->hw[0]->sw_if_index, |
| 5551 | ~0, // invalid fib index |
| 5552 | 1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 5553 | NULL, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5554 | FIB_ROUTE_PATH_FLAG_NONE); |
| 5555 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 5556 | |
| 5557 | /* |
| 5558 | * remove the route in the export fib. expect the adj-fibs to be removed |
| 5559 | */ |
| 5560 | local_pfx.fp_len = 24; |
| 5561 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5562 | &local_pfx, |
| 5563 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5564 | |
| 5565 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_1_s_32); |
| 5566 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "Delete export: ADJ-fib1 removed from FIB1"); |
| 5567 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_2_s_32); |
| 5568 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "ADJ-fib2 removed from FIB1"); |
| 5569 | local_pfx.fp_len = 32; |
| 5570 | fei = fib_table_lookup_exact_match(import_fib_index1, &local_pfx); |
| 5571 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "local removed from FIB1"); |
| 5572 | |
| 5573 | /* |
| 5574 | * the adj-fibs in the export VRF are present in the FIB table, |
| 5575 | * but not installed in forwarding, since they have no attached cover. |
| 5576 | * Consequently a lookup in the MTRIE gives the adj for the covering |
| 5577 | * route 10.0.0.0/8. |
| 5578 | */ |
| 5579 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_1_s_32); |
| 5580 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib1 in export"); |
| 5581 | |
| 5582 | index_t lbi; |
| 5583 | lbi = ip4_fib_forwarding_lookup(fib_index, &pfx_10_10_10_1_s_32.fp_addr.ip4); |
| 5584 | FIB_TEST(lbi == dpo->dpoi_index, |
| 5585 | "10.10.10.1 forwards on \n%U not \n%U", |
| 5586 | format_load_balance, lbi, 0, |
| 5587 | format_dpo_id, dpo, 0); |
| 5588 | lbi = ip4_fib_forwarding_lookup(fib_index, &pfx_10_10_10_2_s_32.fp_addr.ip4); |
| 5589 | FIB_TEST(lbi == dpo->dpoi_index, |
| 5590 | "10.10.10.2 forwards on %U", format_dpo_id, dpo, 0); |
| 5591 | lbi = ip4_fib_forwarding_lookup(fib_index, &pfx_10_10_10_3_s_32.fp_addr.ip4); |
| 5592 | FIB_TEST(lbi == dpo->dpoi_index, |
| 5593 | "10.10.10.3 forwards on %U", format_dpo_id, dpo, 0); |
| 5594 | |
| 5595 | /* |
| 5596 | * add the export prefix back, but not as attached. |
| 5597 | * No adj-fibs in export nor import tables |
| 5598 | */ |
| 5599 | local_pfx.fp_len = 24; |
| 5600 | fei = fib_table_entry_update_one_path(fib_index, |
| 5601 | &local_pfx, |
| 5602 | FIB_SOURCE_API, |
| 5603 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5604 | DPO_PROTO_IP4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5605 | &pfx_10_10_10_1_s_32.fp_addr, |
| 5606 | tm->hw[0]->sw_if_index, |
| 5607 | ~0, // invalid fib index |
| 5608 | 1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 5609 | NULL, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5610 | FIB_ROUTE_PATH_FLAG_NONE); |
| 5611 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 5612 | |
| 5613 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_1_s_32); |
| 5614 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "non-attached in export: ADJ-fib1 in export"); |
| 5615 | lbi = ip4_fib_forwarding_lookup(fib_index, &pfx_10_10_10_1_s_32.fp_addr.ip4); |
| 5616 | FIB_TEST(lbi == dpo->dpoi_index, |
| 5617 | "10.10.10.1 forwards on %U", format_dpo_id, dpo, 0); |
| 5618 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_1_s_32); |
| 5619 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib1 in export"); |
| 5620 | lbi = ip4_fib_forwarding_lookup(fib_index, &pfx_10_10_10_2_s_32.fp_addr.ip4); |
| 5621 | FIB_TEST(lbi == dpo->dpoi_index, |
| 5622 | "10.10.10.2 forwards on %U", format_dpo_id, dpo, 0); |
| 5623 | |
| 5624 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_1_s_32); |
| 5625 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "ADJ-fib1 removed from FIB1"); |
| 5626 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_2_s_32); |
| 5627 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "ADJ-fib2 removed from FIB1"); |
| 5628 | local_pfx.fp_len = 32; |
| 5629 | fei = fib_table_lookup_exact_match(import_fib_index1, &local_pfx); |
| 5630 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), "local removed from FIB1"); |
| 5631 | |
| 5632 | /* |
| 5633 | * modify the export prefix so it is attached. expect all covereds to return |
| 5634 | */ |
| 5635 | local_pfx.fp_len = 24; |
| 5636 | fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5637 | &local_pfx, |
| 5638 | FIB_SOURCE_API, |
| 5639 | FIB_ENTRY_FLAG_NONE, |
| 5640 | DPO_PROTO_IP4, |
| 5641 | NULL, |
| 5642 | tm->hw[0]->sw_if_index, |
| 5643 | ~0, // invalid fib index |
| 5644 | 1, |
| 5645 | NULL, |
| 5646 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5647 | |
| 5648 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_1_s_32); |
| 5649 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib1 reinstalled in export"); |
| 5650 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 5651 | FIB_TEST(dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5652 | "Adj-fib1 is not drop in export"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5653 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_2_s_32); |
| 5654 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib2 reinstalled in export"); |
| 5655 | local_pfx.fp_len = 32; |
| 5656 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 5657 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local reinstalled in export"); |
| 5658 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_1_s_32); |
| 5659 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "attached in export: ADJ-fib1 imported"); |
| 5660 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 5661 | FIB_TEST(dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5662 | "Adj-fib1 is not drop in export: %U %U", |
| 5663 | format_dpo_id, dpo, 0, |
| 5664 | format_dpo_id, load_balance_get_bucket(dpo->dpoi_index, 0), 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5665 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_1_s_32); |
| 5666 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib1 imported"); |
| 5667 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_2_s_32); |
| 5668 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib2 imported"); |
| 5669 | local_pfx.fp_len = 32; |
| 5670 | fei = fib_table_lookup_exact_match(import_fib_index1, &local_pfx); |
| 5671 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local imported"); |
| 5672 | |
| 5673 | /* |
| 5674 | * modify the export prefix so connected. no change. |
| 5675 | */ |
| 5676 | local_pfx.fp_len = 24; |
| 5677 | fib_table_entry_update_one_path(fib_index, &local_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5678 | FIB_SOURCE_INTERFACE, |
| 5679 | (FIB_ENTRY_FLAG_CONNECTED | |
| 5680 | FIB_ENTRY_FLAG_ATTACHED), |
| 5681 | DPO_PROTO_IP4, |
| 5682 | NULL, |
| 5683 | tm->hw[0]->sw_if_index, |
| 5684 | ~0, |
| 5685 | 1, |
| 5686 | NULL, |
| 5687 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5688 | |
| 5689 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_1_s_32); |
| 5690 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib1 reinstalled in export"); |
| 5691 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 5692 | FIB_TEST(dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5693 | "Adj-fib1 is not drop in export"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5694 | fei = fib_table_lookup_exact_match(fib_index, &pfx_10_10_10_2_s_32); |
| 5695 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib2 reinstalled in export"); |
| 5696 | local_pfx.fp_len = 32; |
| 5697 | fei = fib_table_lookup_exact_match(fib_index, &local_pfx); |
| 5698 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local reinstalled in export"); |
| 5699 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_1_s_32); |
| 5700 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "attached in export: ADJ-fib1 imported"); |
| 5701 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 5702 | FIB_TEST(dpo_cmp(dpo_drop, load_balance_get_bucket(dpo->dpoi_index, 0)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5703 | "Adj-fib1 is not drop in export"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5704 | fei = fib_table_lookup_exact_match(import_fib_index1, &pfx_10_10_10_2_s_32); |
| 5705 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "ADJ-fib2 imported"); |
| 5706 | local_pfx.fp_len = 32; |
| 5707 | fei = fib_table_lookup_exact_match(import_fib_index1, &local_pfx); |
| 5708 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "local imported"); |
| 5709 | |
| 5710 | /* |
| 5711 | * CLEANUP |
| 5712 | */ |
| 5713 | fib_table_entry_delete(fib_index, |
| 5714 | &pfx_10_0_0_0_s_8, |
| 5715 | FIB_SOURCE_API); |
| 5716 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5717 | &pfx_10_10_10_1_s_32, |
| 5718 | FIB_SOURCE_ADJ); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5719 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5720 | &pfx_10_10_10_2_s_32, |
| 5721 | FIB_SOURCE_ADJ); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5722 | local_pfx.fp_len = 32; |
| 5723 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5724 | &local_pfx, |
| 5725 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5726 | local_pfx.fp_len = 24; |
| 5727 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5728 | &local_pfx, |
| 5729 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5730 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5731 | &local_pfx, |
| 5732 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5733 | local_pfx.fp_len = 24; |
| 5734 | fib_table_entry_delete(import_fib_index1, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5735 | &local_pfx, |
| 5736 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5737 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 5738 | fib_table_unlock(import_fib_index1, FIB_PROTOCOL_IP4, FIB_SOURCE_CLI); |
| 5739 | fib_table_unlock(import_fib_index2, FIB_PROTOCOL_IP4, FIB_SOURCE_CLI); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5740 | |
| 5741 | FIB_TEST((0 == adj_nbr_db_size()), "ADJ DB size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5742 | adj_nbr_db_size()); |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 5743 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5744 | return (res); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 5745 | } |
| 5746 | |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5747 | /* |
| 5748 | * Test Path Preference |
| 5749 | */ |
| 5750 | static int |
| 5751 | fib_test_pref (void) |
| 5752 | { |
| 5753 | test_main_t *tm = &test_main; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5754 | int res; |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5755 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5756 | res = 0; |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5757 | const fib_prefix_t pfx_1_1_1_1_s_32 = { |
| 5758 | .fp_len = 32, |
| 5759 | .fp_proto = FIB_PROTOCOL_IP4, |
| 5760 | .fp_addr = { |
| 5761 | .ip4 = { |
| 5762 | .as_u32 = clib_host_to_net_u32(0x01010101), |
| 5763 | }, |
| 5764 | }, |
| 5765 | }; |
| 5766 | |
| 5767 | /* |
| 5768 | * 2 high, 2 medium and 2 low preference non-recursive paths |
| 5769 | */ |
| 5770 | fib_route_path_t nr_path_hi_1 = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 5771 | .frp_proto = DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5772 | .frp_sw_if_index = tm->hw[0]->sw_if_index, |
| 5773 | .frp_fib_index = ~0, |
| 5774 | .frp_weight = 1, |
| 5775 | .frp_preference = 0, |
| 5776 | .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, |
| 5777 | .frp_addr = { |
| 5778 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a01), |
| 5779 | }, |
| 5780 | }; |
| 5781 | fib_route_path_t nr_path_hi_2 = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 5782 | .frp_proto = DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5783 | .frp_sw_if_index = tm->hw[0]->sw_if_index, |
| 5784 | .frp_fib_index = ~0, |
| 5785 | .frp_weight = 1, |
| 5786 | .frp_preference = 0, |
| 5787 | .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, |
| 5788 | .frp_addr = { |
| 5789 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a02), |
| 5790 | }, |
| 5791 | }; |
| 5792 | fib_route_path_t nr_path_med_1 = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 5793 | .frp_proto = DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5794 | .frp_sw_if_index = tm->hw[1]->sw_if_index, |
| 5795 | .frp_fib_index = ~0, |
| 5796 | .frp_weight = 1, |
| 5797 | .frp_preference = 1, |
| 5798 | .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, |
| 5799 | .frp_addr = { |
| 5800 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0c01), |
| 5801 | }, |
| 5802 | }; |
| 5803 | fib_route_path_t nr_path_med_2 = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 5804 | .frp_proto = DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5805 | .frp_sw_if_index = tm->hw[1]->sw_if_index, |
| 5806 | .frp_fib_index = ~0, |
| 5807 | .frp_weight = 1, |
| 5808 | .frp_preference = 1, |
| 5809 | .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, |
| 5810 | .frp_addr = { |
| 5811 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0c01), |
| 5812 | }, |
| 5813 | }; |
| 5814 | fib_route_path_t nr_path_low_1 = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 5815 | .frp_proto = DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5816 | .frp_sw_if_index = tm->hw[2]->sw_if_index, |
| 5817 | .frp_fib_index = ~0, |
| 5818 | .frp_weight = 1, |
| 5819 | .frp_preference = 2, |
| 5820 | .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, |
| 5821 | .frp_addr = { |
| 5822 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0b01), |
| 5823 | }, |
| 5824 | }; |
| 5825 | fib_route_path_t nr_path_low_2 = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 5826 | .frp_proto = DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5827 | .frp_sw_if_index = tm->hw[2]->sw_if_index, |
| 5828 | .frp_fib_index = ~0, |
| 5829 | .frp_weight = 1, |
| 5830 | .frp_preference = 2, |
| 5831 | .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, |
| 5832 | .frp_addr = { |
| 5833 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0b02), |
| 5834 | }, |
| 5835 | }; |
| 5836 | fib_route_path_t *nr_paths = NULL; |
| 5837 | |
| 5838 | vec_add1(nr_paths, nr_path_hi_1); |
| 5839 | vec_add1(nr_paths, nr_path_hi_2); |
| 5840 | vec_add1(nr_paths, nr_path_med_1); |
| 5841 | vec_add1(nr_paths, nr_path_med_2); |
| 5842 | vec_add1(nr_paths, nr_path_low_1); |
| 5843 | vec_add1(nr_paths, nr_path_low_2); |
| 5844 | |
| 5845 | adj_index_t ai_hi_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 5846 | VNET_LINK_IP4, |
| 5847 | &nr_path_hi_1.frp_addr, |
| 5848 | nr_path_hi_1.frp_sw_if_index); |
| 5849 | adj_index_t ai_hi_2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 5850 | VNET_LINK_IP4, |
| 5851 | &nr_path_hi_2.frp_addr, |
| 5852 | nr_path_hi_2.frp_sw_if_index); |
| 5853 | adj_index_t ai_med_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 5854 | VNET_LINK_IP4, |
| 5855 | &nr_path_med_1.frp_addr, |
| 5856 | nr_path_med_1.frp_sw_if_index); |
| 5857 | adj_index_t ai_med_2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 5858 | VNET_LINK_IP4, |
| 5859 | &nr_path_med_2.frp_addr, |
| 5860 | nr_path_med_2.frp_sw_if_index); |
| 5861 | adj_index_t ai_low_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 5862 | VNET_LINK_IP4, |
| 5863 | &nr_path_low_1.frp_addr, |
| 5864 | nr_path_low_1.frp_sw_if_index); |
| 5865 | adj_index_t ai_low_2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 5866 | VNET_LINK_IP4, |
| 5867 | &nr_path_low_2.frp_addr, |
| 5868 | nr_path_low_2.frp_sw_if_index); |
| 5869 | |
| 5870 | fib_test_lb_bucket_t ip_hi_1 = { |
| 5871 | .type = FT_LB_ADJ, |
| 5872 | .adj = { |
| 5873 | .adj = ai_hi_1, |
| 5874 | }, |
| 5875 | }; |
| 5876 | fib_test_lb_bucket_t ip_hi_2 = { |
| 5877 | .type = FT_LB_ADJ, |
| 5878 | .adj = { |
| 5879 | .adj = ai_hi_2, |
| 5880 | }, |
| 5881 | }; |
| 5882 | fib_test_lb_bucket_t ip_med_1 = { |
| 5883 | .type = FT_LB_ADJ, |
| 5884 | .adj = { |
| 5885 | .adj = ai_med_1, |
| 5886 | }, |
| 5887 | }; |
| 5888 | fib_test_lb_bucket_t ip_med_2 = { |
| 5889 | .type = FT_LB_ADJ, |
| 5890 | .adj = { |
| 5891 | .adj = ai_med_2, |
| 5892 | }, |
| 5893 | }; |
| 5894 | fib_test_lb_bucket_t ip_low_1 = { |
| 5895 | .type = FT_LB_ADJ, |
| 5896 | .adj = { |
| 5897 | .adj = ai_low_1, |
| 5898 | }, |
| 5899 | }; |
| 5900 | fib_test_lb_bucket_t ip_low_2 = { |
| 5901 | .type = FT_LB_ADJ, |
| 5902 | .adj = { |
| 5903 | .adj = ai_low_2, |
| 5904 | }, |
| 5905 | }; |
| 5906 | |
| 5907 | fib_node_index_t fei; |
| 5908 | |
| 5909 | fei = fib_table_entry_path_add2(0, |
| 5910 | &pfx_1_1_1_1_s_32, |
| 5911 | FIB_SOURCE_API, |
| 5912 | FIB_ENTRY_FLAG_NONE, |
| 5913 | nr_paths); |
| 5914 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5915 | FIB_TEST(!fib_test_validate_entry(fei, |
| 5916 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 5917 | 2, |
| 5918 | &ip_hi_1, |
| 5919 | &ip_hi_2), |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5920 | "1.1.1.1/32 via high preference paths"); |
| 5921 | |
| 5922 | /* |
| 5923 | * bring down the interface on which the high preference path lie |
| 5924 | */ |
| 5925 | vnet_sw_interface_set_flags(vnet_get_main(), |
| 5926 | tm->hw[0]->sw_if_index, |
| 5927 | 0); |
| 5928 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5929 | FIB_TEST(!fib_test_validate_entry(fei, |
| 5930 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 5931 | 2, |
| 5932 | &ip_med_1, |
| 5933 | &ip_med_2), |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5934 | "1.1.1.1/32 via medium preference paths"); |
| 5935 | |
| 5936 | /* |
| 5937 | * bring down the interface on which the medium preference path lie |
| 5938 | */ |
| 5939 | vnet_sw_interface_set_flags(vnet_get_main(), |
| 5940 | tm->hw[1]->sw_if_index, |
| 5941 | 0); |
| 5942 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5943 | FIB_TEST(!fib_test_validate_entry(fei, |
| 5944 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 5945 | 2, |
| 5946 | &ip_low_1, |
| 5947 | &ip_low_2), |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5948 | "1.1.1.1/32 via low preference paths"); |
| 5949 | |
| 5950 | /* |
| 5951 | * bring up the interface on which the high preference path lie |
| 5952 | */ |
| 5953 | vnet_sw_interface_set_flags(vnet_get_main(), |
| 5954 | tm->hw[0]->sw_if_index, |
| 5955 | VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
| 5956 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5957 | FIB_TEST(!fib_test_validate_entry(fei, |
| 5958 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 5959 | 2, |
| 5960 | &ip_hi_1, |
| 5961 | &ip_hi_2), |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5962 | "1.1.1.1/32 via high preference paths"); |
| 5963 | |
| 5964 | /* |
| 5965 | * bring up the interface on which the medium preference path lie |
| 5966 | */ |
| 5967 | vnet_sw_interface_set_flags(vnet_get_main(), |
| 5968 | tm->hw[1]->sw_if_index, |
| 5969 | VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
| 5970 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 5971 | FIB_TEST(!fib_test_validate_entry(fei, |
| 5972 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 5973 | 2, |
| 5974 | &ip_hi_1, |
| 5975 | &ip_hi_2), |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 5976 | "1.1.1.1/32 via high preference paths"); |
| 5977 | |
| 5978 | dpo_id_t ip_1_1_1_1 = DPO_INVALID; |
| 5979 | fib_entry_contribute_forwarding(fei, |
| 5980 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 5981 | &ip_1_1_1_1); |
| 5982 | |
| 5983 | /* |
| 5984 | * 3 recursive paths of different preference |
| 5985 | */ |
| 5986 | const fib_prefix_t pfx_1_1_1_2_s_32 = { |
| 5987 | .fp_len = 32, |
| 5988 | .fp_proto = FIB_PROTOCOL_IP4, |
| 5989 | .fp_addr = { |
| 5990 | .ip4 = { |
| 5991 | .as_u32 = clib_host_to_net_u32(0x01010102), |
| 5992 | }, |
| 5993 | }, |
| 5994 | }; |
| 5995 | const fib_prefix_t pfx_1_1_1_3_s_32 = { |
| 5996 | .fp_len = 32, |
| 5997 | .fp_proto = FIB_PROTOCOL_IP4, |
| 5998 | .fp_addr = { |
| 5999 | .ip4 = { |
| 6000 | .as_u32 = clib_host_to_net_u32(0x01010103), |
| 6001 | }, |
| 6002 | }, |
| 6003 | }; |
| 6004 | fei = fib_table_entry_path_add2(0, |
| 6005 | &pfx_1_1_1_2_s_32, |
| 6006 | FIB_SOURCE_API, |
| 6007 | FIB_ENTRY_FLAG_NONE, |
| 6008 | nr_paths); |
| 6009 | dpo_id_t ip_1_1_1_2 = DPO_INVALID; |
| 6010 | fib_entry_contribute_forwarding(fei, |
| 6011 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6012 | &ip_1_1_1_2); |
| 6013 | fei = fib_table_entry_path_add2(0, |
| 6014 | &pfx_1_1_1_3_s_32, |
| 6015 | FIB_SOURCE_API, |
| 6016 | FIB_ENTRY_FLAG_NONE, |
| 6017 | nr_paths); |
| 6018 | dpo_id_t ip_1_1_1_3 = DPO_INVALID; |
| 6019 | fib_entry_contribute_forwarding(fei, |
| 6020 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6021 | &ip_1_1_1_3); |
| 6022 | |
| 6023 | fib_test_lb_bucket_t ip_o_1_1_1_1 = { |
| 6024 | .type = FT_LB_O_LB, |
| 6025 | .lb = { |
| 6026 | .lb = ip_1_1_1_1.dpoi_index, |
| 6027 | }, |
| 6028 | }; |
| 6029 | fib_test_lb_bucket_t ip_o_1_1_1_2 = { |
| 6030 | .type = FT_LB_O_LB, |
| 6031 | .lb = { |
| 6032 | .lb = ip_1_1_1_2.dpoi_index, |
| 6033 | }, |
| 6034 | }; |
| 6035 | fib_test_lb_bucket_t ip_o_1_1_1_3 = { |
| 6036 | .type = FT_LB_O_LB, |
| 6037 | .lb = { |
| 6038 | .lb = ip_1_1_1_3.dpoi_index, |
| 6039 | }, |
| 6040 | }; |
| 6041 | fib_route_path_t r_path_hi = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 6042 | .frp_proto = DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6043 | .frp_sw_if_index = ~0, |
| 6044 | .frp_fib_index = 0, |
| 6045 | .frp_weight = 1, |
| 6046 | .frp_preference = 0, |
| 6047 | .frp_flags = FIB_ROUTE_PATH_RESOLVE_VIA_HOST, |
| 6048 | .frp_addr = pfx_1_1_1_1_s_32.fp_addr, |
| 6049 | }; |
| 6050 | fib_route_path_t r_path_med = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 6051 | .frp_proto = DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6052 | .frp_sw_if_index = ~0, |
| 6053 | .frp_fib_index = 0, |
| 6054 | .frp_weight = 1, |
| 6055 | .frp_preference = 10, |
| 6056 | .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, |
| 6057 | .frp_addr = pfx_1_1_1_2_s_32.fp_addr, |
| 6058 | }; |
| 6059 | fib_route_path_t r_path_low = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 6060 | .frp_proto = DPO_PROTO_IP4, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6061 | .frp_sw_if_index = ~0, |
| 6062 | .frp_fib_index = 0, |
| 6063 | .frp_weight = 1, |
Neale Ranns | a0a908f | 2017-08-01 11:40:03 -0700 | [diff] [blame] | 6064 | .frp_preference = 255, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6065 | .frp_flags = FIB_ROUTE_PATH_RESOLVE_VIA_HOST, |
| 6066 | .frp_addr = pfx_1_1_1_3_s_32.fp_addr, |
| 6067 | }; |
| 6068 | fib_route_path_t *r_paths = NULL; |
| 6069 | |
| 6070 | vec_add1(r_paths, r_path_hi); |
| 6071 | vec_add1(r_paths, r_path_low); |
| 6072 | vec_add1(r_paths, r_path_med); |
| 6073 | |
| 6074 | /* |
| 6075 | * add many recursive so we get the LB MAp created |
| 6076 | */ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6077 | #define N_PFXS 64 |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6078 | fib_prefix_t pfx_r[N_PFXS]; |
Marek Gradzki | af09551 | 2017-08-15 07:38:26 +0200 | [diff] [blame] | 6079 | unsigned int n_pfxs; |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6080 | for (n_pfxs = 0; n_pfxs < N_PFXS; n_pfxs++) |
| 6081 | { |
| 6082 | pfx_r[n_pfxs].fp_len = 32; |
| 6083 | pfx_r[n_pfxs].fp_proto = FIB_PROTOCOL_IP4; |
| 6084 | pfx_r[n_pfxs].fp_addr.ip4.as_u32 = |
| 6085 | clib_host_to_net_u32(0x02000000 + n_pfxs); |
| 6086 | |
| 6087 | fei = fib_table_entry_path_add2(0, |
| 6088 | &pfx_r[n_pfxs], |
| 6089 | FIB_SOURCE_API, |
| 6090 | FIB_ENTRY_FLAG_NONE, |
| 6091 | r_paths); |
| 6092 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6093 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6094 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6095 | 1, |
| 6096 | &ip_o_1_1_1_1), |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6097 | "recursive via high preference paths"); |
| 6098 | |
| 6099 | /* |
| 6100 | * withdraw hig pref resolving entry |
| 6101 | */ |
| 6102 | fib_table_entry_delete(0, |
| 6103 | &pfx_1_1_1_1_s_32, |
| 6104 | FIB_SOURCE_API); |
| 6105 | |
| 6106 | /* suspend so the update walk kicks int */ |
| 6107 | vlib_process_suspend(vlib_get_main(), 1e-5); |
| 6108 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6109 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6110 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6111 | 1, |
| 6112 | &ip_o_1_1_1_2), |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6113 | "recursive via medium preference paths"); |
| 6114 | |
| 6115 | /* |
| 6116 | * withdraw medium pref resolving entry |
| 6117 | */ |
| 6118 | fib_table_entry_delete(0, |
| 6119 | &pfx_1_1_1_2_s_32, |
| 6120 | FIB_SOURCE_API); |
| 6121 | |
| 6122 | /* suspend so the update walk kicks int */ |
| 6123 | vlib_process_suspend(vlib_get_main(), 1e-5); |
| 6124 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6125 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6126 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6127 | 1, |
| 6128 | &ip_o_1_1_1_3), |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6129 | "recursive via low preference paths"); |
| 6130 | |
| 6131 | /* |
| 6132 | * add back paths for next iteration |
| 6133 | */ |
| 6134 | fei = fib_table_entry_update(0, |
| 6135 | &pfx_1_1_1_2_s_32, |
| 6136 | FIB_SOURCE_API, |
| 6137 | FIB_ENTRY_FLAG_NONE, |
| 6138 | nr_paths); |
| 6139 | fei = fib_table_entry_update(0, |
| 6140 | &pfx_1_1_1_1_s_32, |
| 6141 | FIB_SOURCE_API, |
| 6142 | FIB_ENTRY_FLAG_NONE, |
| 6143 | nr_paths); |
| 6144 | |
| 6145 | /* suspend so the update walk kicks int */ |
| 6146 | vlib_process_suspend(vlib_get_main(), 1e-5); |
| 6147 | |
| 6148 | fei = fib_table_lookup_exact_match(0, &pfx_r[n_pfxs]); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6149 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6150 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6151 | 1, |
| 6152 | &ip_o_1_1_1_1), |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6153 | "recursive via high preference paths"); |
| 6154 | } |
| 6155 | |
| 6156 | |
| 6157 | fib_table_entry_delete(0, |
| 6158 | &pfx_1_1_1_1_s_32, |
| 6159 | FIB_SOURCE_API); |
| 6160 | |
| 6161 | /* suspend so the update walk kicks int */ |
| 6162 | vlib_process_suspend(vlib_get_main(), 1e-5); |
| 6163 | |
| 6164 | for (n_pfxs = 0; n_pfxs < N_PFXS; n_pfxs++) |
| 6165 | { |
| 6166 | fei = fib_table_lookup_exact_match(0, &pfx_r[n_pfxs]); |
| 6167 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6168 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6169 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6170 | 1, |
| 6171 | &ip_o_1_1_1_2), |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6172 | "recursive via medium preference paths"); |
| 6173 | } |
| 6174 | for (n_pfxs = 0; n_pfxs < N_PFXS; n_pfxs++) |
| 6175 | { |
| 6176 | fib_table_entry_delete(0, |
| 6177 | &pfx_r[n_pfxs], |
| 6178 | FIB_SOURCE_API); |
| 6179 | } |
| 6180 | |
| 6181 | /* |
| 6182 | * Cleanup |
| 6183 | */ |
| 6184 | fib_table_entry_delete(0, |
| 6185 | &pfx_1_1_1_2_s_32, |
| 6186 | FIB_SOURCE_API); |
| 6187 | fib_table_entry_delete(0, |
| 6188 | &pfx_1_1_1_3_s_32, |
| 6189 | FIB_SOURCE_API); |
| 6190 | |
| 6191 | dpo_reset(&ip_1_1_1_1); |
| 6192 | dpo_reset(&ip_1_1_1_2); |
| 6193 | dpo_reset(&ip_1_1_1_3); |
| 6194 | adj_unlock(ai_low_2); |
| 6195 | adj_unlock(ai_low_1); |
| 6196 | adj_unlock(ai_med_2); |
| 6197 | adj_unlock(ai_med_1); |
| 6198 | adj_unlock(ai_hi_2); |
| 6199 | adj_unlock(ai_hi_1); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6200 | |
| 6201 | return (res); |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 6202 | } |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 6203 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6204 | /* |
| 6205 | * Test the recursive route route handling for GRE tunnels |
| 6206 | */ |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 6207 | static int |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6208 | fib_test_label (void) |
| 6209 | { |
| 6210 | fib_node_index_t fei, ai_mpls_10_10_10_1, ai_v4_10_10_11_1, ai_v4_10_10_11_2, ai_mpls_10_10_11_2, ai_mpls_10_10_11_1; |
| 6211 | const u32 fib_index = 0; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6212 | int lb_count, ii, res; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6213 | test_main_t *tm; |
| 6214 | ip4_main_t *im; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6215 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6216 | res = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6217 | lb_count = pool_elts(load_balance_pool); |
| 6218 | tm = &test_main; |
| 6219 | im = &ip4_main; |
| 6220 | |
| 6221 | /* |
| 6222 | * add interface routes. We'll assume this works. It's more rigorously |
| 6223 | * tested elsewhere. |
| 6224 | */ |
| 6225 | fib_prefix_t local0_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6226 | .fp_len = 24, |
| 6227 | .fp_proto = FIB_PROTOCOL_IP4, |
| 6228 | .fp_addr = { |
| 6229 | .ip4 = { |
| 6230 | /* 10.10.10.10 */ |
| 6231 | .as_u32 = clib_host_to_net_u32(0x0a0a0a0a), |
| 6232 | }, |
| 6233 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6234 | }; |
| 6235 | |
| 6236 | FIB_TEST((0 == adj_nbr_db_size()), "ADJ DB size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6237 | adj_nbr_db_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6238 | |
| 6239 | vec_validate(im->fib_index_by_sw_if_index, tm->hw[0]->sw_if_index); |
| 6240 | im->fib_index_by_sw_if_index[tm->hw[0]->sw_if_index] = fib_index; |
| 6241 | |
| 6242 | fib_table_entry_update_one_path(fib_index, &local0_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6243 | FIB_SOURCE_INTERFACE, |
| 6244 | (FIB_ENTRY_FLAG_CONNECTED | |
| 6245 | FIB_ENTRY_FLAG_ATTACHED), |
| 6246 | DPO_PROTO_IP4, |
| 6247 | NULL, |
| 6248 | tm->hw[0]->sw_if_index, |
| 6249 | ~0, |
| 6250 | 1, |
| 6251 | NULL, |
| 6252 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6253 | fei = fib_table_lookup_exact_match(fib_index, &local0_pfx); |
| 6254 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6255 | "attached interface route present"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6256 | |
| 6257 | local0_pfx.fp_len = 32; |
| 6258 | fib_table_entry_update_one_path(fib_index, &local0_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6259 | FIB_SOURCE_INTERFACE, |
| 6260 | (FIB_ENTRY_FLAG_CONNECTED | |
| 6261 | FIB_ENTRY_FLAG_LOCAL), |
| 6262 | DPO_PROTO_IP4, |
| 6263 | NULL, |
| 6264 | tm->hw[0]->sw_if_index, |
| 6265 | ~0, // invalid fib index |
| 6266 | 1, |
| 6267 | NULL, |
| 6268 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6269 | fei = fib_table_lookup_exact_match(fib_index, &local0_pfx); |
| 6270 | |
| 6271 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6272 | "local interface route present"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6273 | |
| 6274 | fib_prefix_t local1_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6275 | .fp_len = 24, |
| 6276 | .fp_proto = FIB_PROTOCOL_IP4, |
| 6277 | .fp_addr = { |
| 6278 | .ip4 = { |
| 6279 | /* 10.10.11.10 */ |
| 6280 | .as_u32 = clib_host_to_net_u32(0x0a0a0b0a), |
| 6281 | }, |
| 6282 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6283 | }; |
| 6284 | |
| 6285 | vec_validate(im->fib_index_by_sw_if_index, tm->hw[1]->sw_if_index); |
| 6286 | im->fib_index_by_sw_if_index[tm->hw[1]->sw_if_index] = fib_index; |
| 6287 | |
| 6288 | fib_table_entry_update_one_path(fib_index, &local1_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6289 | FIB_SOURCE_INTERFACE, |
| 6290 | (FIB_ENTRY_FLAG_CONNECTED | |
| 6291 | FIB_ENTRY_FLAG_ATTACHED), |
| 6292 | DPO_PROTO_IP4, |
| 6293 | NULL, |
| 6294 | tm->hw[1]->sw_if_index, |
| 6295 | ~0, |
| 6296 | 1, |
| 6297 | NULL, |
| 6298 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6299 | fei = fib_table_lookup_exact_match(fib_index, &local1_pfx); |
| 6300 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6301 | "attached interface route present"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6302 | |
| 6303 | local1_pfx.fp_len = 32; |
| 6304 | fib_table_entry_update_one_path(fib_index, &local1_pfx, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6305 | FIB_SOURCE_INTERFACE, |
| 6306 | (FIB_ENTRY_FLAG_CONNECTED | |
| 6307 | FIB_ENTRY_FLAG_LOCAL), |
| 6308 | DPO_PROTO_IP4, |
| 6309 | NULL, |
| 6310 | tm->hw[1]->sw_if_index, |
| 6311 | ~0, // invalid fib index |
| 6312 | 1, |
| 6313 | NULL, |
| 6314 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6315 | fei = fib_table_lookup_exact_match(fib_index, &local1_pfx); |
| 6316 | |
| 6317 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6318 | "local interface route present"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6319 | |
| 6320 | ip46_address_t nh_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6321 | .ip4 = { |
| 6322 | .as_u32 = clib_host_to_net_u32(0x0a0a0a01), |
| 6323 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6324 | }; |
| 6325 | ip46_address_t nh_10_10_11_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6326 | .ip4 = { |
| 6327 | .as_u32 = clib_host_to_net_u32(0x0a0a0b01), |
| 6328 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6329 | }; |
| 6330 | ip46_address_t nh_10_10_11_2 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6331 | .ip4 = { |
| 6332 | .as_u32 = clib_host_to_net_u32(0x0a0a0b02), |
| 6333 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6334 | }; |
| 6335 | |
| 6336 | ai_v4_10_10_11_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 6337 | VNET_LINK_IP4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6338 | &nh_10_10_11_1, |
| 6339 | tm->hw[1]->sw_if_index); |
| 6340 | ai_v4_10_10_11_2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 6341 | VNET_LINK_IP4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6342 | &nh_10_10_11_2, |
| 6343 | tm->hw[1]->sw_if_index); |
| 6344 | ai_mpls_10_10_10_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 6345 | VNET_LINK_MPLS, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6346 | &nh_10_10_10_1, |
| 6347 | tm->hw[0]->sw_if_index); |
| 6348 | ai_mpls_10_10_11_2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 6349 | VNET_LINK_MPLS, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6350 | &nh_10_10_11_2, |
| 6351 | tm->hw[1]->sw_if_index); |
| 6352 | ai_mpls_10_10_11_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 6353 | VNET_LINK_MPLS, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6354 | &nh_10_10_11_1, |
| 6355 | tm->hw[1]->sw_if_index); |
| 6356 | |
| 6357 | /* |
| 6358 | * Add an etry with one path with a real out-going label |
| 6359 | */ |
| 6360 | fib_prefix_t pfx_1_1_1_1_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6361 | .fp_len = 32, |
| 6362 | .fp_proto = FIB_PROTOCOL_IP4, |
| 6363 | .fp_addr = { |
| 6364 | .ip4.as_u32 = clib_host_to_net_u32(0x01010101), |
| 6365 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6366 | }; |
| 6367 | fib_test_lb_bucket_t l99_eos_o_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6368 | .type = FT_LB_LABEL_O_ADJ, |
| 6369 | .label_o_adj = { |
| 6370 | .adj = ai_mpls_10_10_10_1, |
| 6371 | .label = 99, |
| 6372 | .eos = MPLS_EOS, |
| 6373 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6374 | }; |
| 6375 | fib_test_lb_bucket_t l99_neos_o_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6376 | .type = FT_LB_LABEL_O_ADJ, |
| 6377 | .label_o_adj = { |
| 6378 | .adj = ai_mpls_10_10_10_1, |
| 6379 | .label = 99, |
| 6380 | .eos = MPLS_NON_EOS, |
| 6381 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6382 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 6383 | fib_mpls_label_t *l99 = NULL, fml99 = { |
| 6384 | .fml_value = 99, |
| 6385 | }; |
| 6386 | vec_add1(l99, fml99); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 6387 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6388 | fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6389 | &pfx_1_1_1_1_s_32, |
| 6390 | FIB_SOURCE_API, |
| 6391 | FIB_ENTRY_FLAG_NONE, |
| 6392 | DPO_PROTO_IP4, |
| 6393 | &nh_10_10_10_1, |
| 6394 | tm->hw[0]->sw_if_index, |
| 6395 | ~0, // invalid fib index |
| 6396 | 1, |
| 6397 | l99, |
| 6398 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6399 | |
| 6400 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_1_s_32); |
| 6401 | FIB_TEST((FIB_NODE_INDEX_INVALID != fei), "1.1.1.1/32 created"); |
| 6402 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6403 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6404 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6405 | 1, |
| 6406 | &l99_eos_o_10_10_10_1), |
| 6407 | "1.1.1.1/32 LB 1 bucket via label 99 over 10.10.10.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6408 | |
| 6409 | /* |
| 6410 | * add a path with an implicit NULL label |
| 6411 | */ |
| 6412 | fib_test_lb_bucket_t a_o_10_10_11_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6413 | .type = FT_LB_ADJ, |
| 6414 | .adj = { |
| 6415 | .adj = ai_v4_10_10_11_1, |
| 6416 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6417 | }; |
| 6418 | fib_test_lb_bucket_t a_mpls_o_10_10_11_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6419 | .type = FT_LB_ADJ, |
| 6420 | .adj = { |
| 6421 | .adj = ai_mpls_10_10_11_1, |
| 6422 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6423 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 6424 | fib_mpls_label_t *l_imp_null = NULL, fml_imp_null = { |
| 6425 | .fml_value = MPLS_IETF_IMPLICIT_NULL_LABEL, |
| 6426 | }; |
| 6427 | vec_add1(l_imp_null, fml_imp_null); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6428 | |
| 6429 | fei = fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6430 | &pfx_1_1_1_1_s_32, |
| 6431 | FIB_SOURCE_API, |
| 6432 | FIB_ENTRY_FLAG_NONE, |
| 6433 | DPO_PROTO_IP4, |
| 6434 | &nh_10_10_11_1, |
| 6435 | tm->hw[1]->sw_if_index, |
| 6436 | ~0, // invalid fib index |
| 6437 | 1, |
| 6438 | l_imp_null, |
| 6439 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6440 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6441 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6442 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6443 | 2, |
| 6444 | &l99_eos_o_10_10_10_1, |
| 6445 | &a_o_10_10_11_1), |
| 6446 | "1.1.1.1/32 LB 2 buckets via: " |
| 6447 | "label 99 over 10.10.10.1, " |
| 6448 | "adj over 10.10.11.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6449 | |
| 6450 | /* |
| 6451 | * assign the route a local label |
| 6452 | */ |
| 6453 | fib_table_entry_local_label_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6454 | &pfx_1_1_1_1_s_32, |
| 6455 | 24001); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6456 | |
| 6457 | fib_prefix_t pfx_24001_eos = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6458 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 6459 | .fp_label = 24001, |
| 6460 | .fp_eos = MPLS_EOS, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6461 | }; |
| 6462 | fib_prefix_t pfx_24001_neos = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6463 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 6464 | .fp_label = 24001, |
| 6465 | .fp_eos = MPLS_NON_EOS, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6466 | }; |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 6467 | fib_test_lb_bucket_t disp_o_10_10_11_1 = { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 6468 | .type = FT_LB_MPLS_DISP_PIPE_O_ADJ, |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 6469 | .adj = { |
| 6470 | .adj = ai_v4_10_10_11_1, |
| 6471 | }, |
| 6472 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6473 | |
| 6474 | /* |
| 6475 | * The EOS entry should link to both the paths, |
| 6476 | * and use an ip adj for the imp-null |
| 6477 | * The NON-EOS entry should link to both the paths, |
| 6478 | * and use an mpls adj for the imp-null |
| 6479 | */ |
| 6480 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6481 | &pfx_24001_eos); |
| 6482 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6483 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 6484 | 2, |
| 6485 | &l99_eos_o_10_10_10_1, |
| 6486 | &disp_o_10_10_11_1), |
| 6487 | "24001/eos LB 2 buckets via: " |
| 6488 | "label 99 over 10.10.10.1, " |
| 6489 | "mpls disp adj over 10.10.11.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6490 | |
| 6491 | |
| 6492 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6493 | &pfx_24001_neos); |
| 6494 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6495 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 6496 | 2, |
| 6497 | &l99_neos_o_10_10_10_1, |
| 6498 | &a_mpls_o_10_10_11_1), |
| 6499 | "24001/neos LB 1 bucket via: " |
| 6500 | "label 99 over 10.10.10.1 ", |
| 6501 | "mpls-adj via 10.10.11.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6502 | |
| 6503 | /* |
| 6504 | * add an unlabelled path, this is excluded from the neos chains, |
| 6505 | */ |
| 6506 | fib_test_lb_bucket_t adj_o_10_10_11_2 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6507 | .type = FT_LB_ADJ, |
| 6508 | .adj = { |
| 6509 | .adj = ai_v4_10_10_11_2, |
| 6510 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6511 | }; |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 6512 | fib_test_lb_bucket_t disp_o_10_10_11_2 = { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 6513 | .type = FT_LB_MPLS_DISP_PIPE_O_ADJ, |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 6514 | .adj = { |
| 6515 | .adj = ai_v4_10_10_11_2, |
| 6516 | }, |
| 6517 | }; |
| 6518 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6519 | |
| 6520 | fei = fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6521 | &pfx_1_1_1_1_s_32, |
| 6522 | FIB_SOURCE_API, |
| 6523 | FIB_ENTRY_FLAG_NONE, |
| 6524 | DPO_PROTO_IP4, |
| 6525 | &nh_10_10_11_2, |
| 6526 | tm->hw[1]->sw_if_index, |
| 6527 | ~0, // invalid fib index |
| 6528 | 1, |
| 6529 | NULL, |
| 6530 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6531 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6532 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6533 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6534 | 16, // 3 choices spread over 16 buckets |
| 6535 | &l99_eos_o_10_10_10_1, |
| 6536 | &l99_eos_o_10_10_10_1, |
| 6537 | &l99_eos_o_10_10_10_1, |
| 6538 | &l99_eos_o_10_10_10_1, |
| 6539 | &l99_eos_o_10_10_10_1, |
| 6540 | &l99_eos_o_10_10_10_1, |
| 6541 | &a_o_10_10_11_1, |
| 6542 | &a_o_10_10_11_1, |
| 6543 | &a_o_10_10_11_1, |
| 6544 | &a_o_10_10_11_1, |
| 6545 | &a_o_10_10_11_1, |
| 6546 | &adj_o_10_10_11_2, |
| 6547 | &adj_o_10_10_11_2, |
| 6548 | &adj_o_10_10_11_2, |
| 6549 | &adj_o_10_10_11_2, |
| 6550 | &adj_o_10_10_11_2), |
| 6551 | "1.1.1.1/32 LB 16 buckets via: " |
| 6552 | "label 99 over 10.10.10.1, " |
| 6553 | "adj over 10.10.11.1", |
| 6554 | "adj over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6555 | |
| 6556 | /* |
| 6557 | * get and lock a reference to the non-eos of the via entry 1.1.1.1/32 |
| 6558 | */ |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 6559 | dpo_id_t non_eos_1_1_1_1 = DPO_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6560 | fib_entry_contribute_forwarding(fei, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6561 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 6562 | &non_eos_1_1_1_1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6563 | |
| 6564 | /* |
| 6565 | * n-eos has only the 2 labelled paths |
| 6566 | */ |
| 6567 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6568 | &pfx_24001_neos); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6569 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6570 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6571 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 6572 | 2, |
| 6573 | &l99_neos_o_10_10_10_1, |
| 6574 | &a_mpls_o_10_10_11_1), |
| 6575 | "24001/neos LB 2 buckets via: " |
| 6576 | "label 99 over 10.10.10.1, " |
| 6577 | "adj-mpls over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6578 | |
| 6579 | /* |
| 6580 | * A labelled recursive |
| 6581 | */ |
| 6582 | fib_prefix_t pfx_2_2_2_2_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6583 | .fp_len = 32, |
| 6584 | .fp_proto = FIB_PROTOCOL_IP4, |
| 6585 | .fp_addr = { |
| 6586 | .ip4.as_u32 = clib_host_to_net_u32(0x02020202), |
| 6587 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6588 | }; |
| 6589 | fib_test_lb_bucket_t l1600_eos_o_1_1_1_1 = { |
| 6590 | .type = FT_LB_LABEL_O_LB, |
| 6591 | .label_o_lb = { |
| 6592 | .lb = non_eos_1_1_1_1.dpoi_index, |
| 6593 | .label = 1600, |
| 6594 | .eos = MPLS_EOS, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 6595 | .mode = FIB_MPLS_LSP_MODE_UNIFORM, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6596 | }, |
| 6597 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 6598 | fib_mpls_label_t *l1600 = NULL, fml1600 = { |
| 6599 | .fml_value = 1600, |
| 6600 | .fml_mode = FIB_MPLS_LSP_MODE_UNIFORM, |
| 6601 | }; |
| 6602 | vec_add1(l1600, fml1600); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6603 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 6604 | fei = fib_table_entry_update_one_path(fib_index, |
| 6605 | &pfx_2_2_2_2_s_32, |
| 6606 | FIB_SOURCE_API, |
| 6607 | FIB_ENTRY_FLAG_NONE, |
| 6608 | DPO_PROTO_IP4, |
| 6609 | &pfx_1_1_1_1_s_32.fp_addr, |
| 6610 | ~0, |
| 6611 | fib_index, |
| 6612 | 1, |
| 6613 | l1600, |
| 6614 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6615 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6616 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6617 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6618 | 1, |
| 6619 | &l1600_eos_o_1_1_1_1), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6620 | "2.2.2.2.2/32 LB 1 buckets via: " |
| 6621 | "label 1600 over 1.1.1.1"); |
| 6622 | |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 6623 | dpo_id_t dpo_44 = DPO_INVALID; |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 6624 | index_t urpfi; |
| 6625 | |
| 6626 | fib_entry_contribute_forwarding(fei, FIB_FORW_CHAIN_TYPE_UNICAST_IP4, &dpo_44); |
| 6627 | urpfi = load_balance_get_urpf(dpo_44.dpoi_index); |
| 6628 | |
| 6629 | FIB_TEST(fib_urpf_check(urpfi, tm->hw[0]->sw_if_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6630 | "uRPF check for 2.2.2.2/32 on %d OK", |
| 6631 | tm->hw[0]->sw_if_index); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 6632 | FIB_TEST(fib_urpf_check(urpfi, tm->hw[1]->sw_if_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6633 | "uRPF check for 2.2.2.2/32 on %d OK", |
| 6634 | tm->hw[1]->sw_if_index); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 6635 | FIB_TEST(!fib_urpf_check(urpfi, 99), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6636 | "uRPF check for 2.2.2.2/32 on 99 not-OK", |
| 6637 | 99); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 6638 | |
| 6639 | fib_entry_contribute_forwarding(fei, FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, &dpo_44); |
| 6640 | FIB_TEST(urpfi == load_balance_get_urpf(dpo_44.dpoi_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6641 | "Shared uRPF on IP and non-EOS chain"); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 6642 | |
| 6643 | dpo_reset(&dpo_44); |
| 6644 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6645 | /* |
| 6646 | * we are holding a lock on the non-eos LB of the via-entry. |
| 6647 | * do a PIC-core failover by shutting the link of the via-entry. |
| 6648 | * |
| 6649 | * shut down the link with the valid label |
| 6650 | */ |
| 6651 | vnet_sw_interface_set_flags(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6652 | tm->hw[0]->sw_if_index, |
| 6653 | 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6654 | |
| 6655 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_1_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6656 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6657 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6658 | 2, |
| 6659 | &a_o_10_10_11_1, |
| 6660 | &adj_o_10_10_11_2), |
| 6661 | "1.1.1.1/32 LB 2 buckets via: " |
| 6662 | "adj over 10.10.11.1, ", |
| 6663 | "adj-v4 over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6664 | |
| 6665 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6666 | &pfx_24001_eos); |
| 6667 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6668 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 6669 | 2, |
| 6670 | &disp_o_10_10_11_1, |
| 6671 | &disp_o_10_10_11_2), |
| 6672 | "24001/eos LB 2 buckets via: " |
| 6673 | "mpls-disp adj over 10.10.11.1, ", |
| 6674 | "mpls-disp adj-v4 over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6675 | |
| 6676 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6677 | &pfx_24001_neos); |
| 6678 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6679 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 6680 | 1, |
| 6681 | &a_mpls_o_10_10_11_1), |
| 6682 | "24001/neos LB 1 buckets via: " |
| 6683 | "adj-mpls over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6684 | |
| 6685 | /* |
| 6686 | * test that the pre-failover load-balance has been in-place |
| 6687 | * modified |
| 6688 | */ |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 6689 | dpo_id_t current = DPO_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6690 | fib_entry_contribute_forwarding(fei, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6691 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 6692 | ¤t); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6693 | |
| 6694 | FIB_TEST(!dpo_cmp(&non_eos_1_1_1_1, |
| 6695 | ¤t), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6696 | "PIC-core LB inplace modified %U %U", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6697 | format_dpo_id, &non_eos_1_1_1_1, 0, |
| 6698 | format_dpo_id, ¤t, 0); |
| 6699 | |
| 6700 | dpo_reset(&non_eos_1_1_1_1); |
| 6701 | dpo_reset(¤t); |
| 6702 | |
| 6703 | /* |
| 6704 | * no-shut the link with the valid label |
| 6705 | */ |
| 6706 | vnet_sw_interface_set_flags(vnet_get_main(), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6707 | tm->hw[0]->sw_if_index, |
| 6708 | VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6709 | |
| 6710 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_1_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6711 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6712 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6713 | 16, // 3 choices spread over 16 buckets |
| 6714 | &l99_eos_o_10_10_10_1, |
| 6715 | &l99_eos_o_10_10_10_1, |
| 6716 | &l99_eos_o_10_10_10_1, |
| 6717 | &l99_eos_o_10_10_10_1, |
| 6718 | &l99_eos_o_10_10_10_1, |
| 6719 | &l99_eos_o_10_10_10_1, |
| 6720 | &a_o_10_10_11_1, |
| 6721 | &a_o_10_10_11_1, |
| 6722 | &a_o_10_10_11_1, |
| 6723 | &a_o_10_10_11_1, |
| 6724 | &a_o_10_10_11_1, |
| 6725 | &adj_o_10_10_11_2, |
| 6726 | &adj_o_10_10_11_2, |
| 6727 | &adj_o_10_10_11_2, |
| 6728 | &adj_o_10_10_11_2, |
| 6729 | &adj_o_10_10_11_2), |
| 6730 | "1.1.1.1/32 LB 16 buckets via: " |
| 6731 | "label 99 over 10.10.10.1, " |
| 6732 | "adj over 10.10.11.1", |
| 6733 | "adj-v4 over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6734 | |
| 6735 | |
| 6736 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6737 | &pfx_24001_eos); |
| 6738 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6739 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 6740 | 16, // 3 choices spread over 16 buckets |
| 6741 | &l99_eos_o_10_10_10_1, |
| 6742 | &l99_eos_o_10_10_10_1, |
| 6743 | &l99_eos_o_10_10_10_1, |
| 6744 | &l99_eos_o_10_10_10_1, |
| 6745 | &l99_eos_o_10_10_10_1, |
| 6746 | &l99_eos_o_10_10_10_1, |
| 6747 | &disp_o_10_10_11_1, |
| 6748 | &disp_o_10_10_11_1, |
| 6749 | &disp_o_10_10_11_1, |
| 6750 | &disp_o_10_10_11_1, |
| 6751 | &disp_o_10_10_11_1, |
| 6752 | &disp_o_10_10_11_2, |
| 6753 | &disp_o_10_10_11_2, |
| 6754 | &disp_o_10_10_11_2, |
| 6755 | &disp_o_10_10_11_2, |
| 6756 | &disp_o_10_10_11_2), |
| 6757 | "24001/eos LB 16 buckets via: " |
| 6758 | "label 99 over 10.10.10.1, " |
| 6759 | "MPLS disp adj over 10.10.11.1", |
| 6760 | "MPLS disp adj-v4 over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6761 | |
| 6762 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6763 | &pfx_24001_neos); |
| 6764 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6765 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 6766 | 2, |
| 6767 | &l99_neos_o_10_10_10_1, |
| 6768 | &a_mpls_o_10_10_11_1), |
| 6769 | "24001/neos LB 2 buckets via: " |
| 6770 | "label 99 over 10.10.10.1, " |
| 6771 | "adj-mpls over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6772 | |
| 6773 | /* |
| 6774 | * remove the first path with the valid label |
| 6775 | */ |
| 6776 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6777 | &pfx_1_1_1_1_s_32, |
| 6778 | FIB_SOURCE_API, |
| 6779 | DPO_PROTO_IP4, |
| 6780 | &nh_10_10_10_1, |
| 6781 | tm->hw[0]->sw_if_index, |
| 6782 | ~0, // invalid fib index |
| 6783 | 1, |
| 6784 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6785 | |
| 6786 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_1_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6787 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6788 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6789 | 2, |
| 6790 | &a_o_10_10_11_1, |
| 6791 | &adj_o_10_10_11_2), |
| 6792 | "1.1.1.1/32 LB 2 buckets via: " |
| 6793 | "adj over 10.10.11.1, " |
| 6794 | "adj-v4 over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6795 | |
| 6796 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6797 | &pfx_24001_eos); |
| 6798 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6799 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 6800 | 2, |
| 6801 | &disp_o_10_10_11_1, |
| 6802 | &disp_o_10_10_11_2), |
| 6803 | "24001/eos LB 2 buckets via: " |
| 6804 | "MPLS disp adj over 10.10.11.1, " |
| 6805 | "MPLS disp adj-v4 over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6806 | |
| 6807 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6808 | &pfx_24001_neos); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6809 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6810 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6811 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 6812 | 1, |
| 6813 | &a_mpls_o_10_10_11_1), |
| 6814 | "24001/neos LB 1 buckets via: " |
| 6815 | "adj-mpls over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6816 | |
| 6817 | /* |
| 6818 | * remove the other path with a valid label |
| 6819 | */ |
| 6820 | fib_test_lb_bucket_t bucket_drop = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6821 | .type = FT_LB_DROP, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6822 | }; |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 6823 | fib_test_lb_bucket_t mpls_bucket_drop = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6824 | .type = FT_LB_DROP, |
| 6825 | .special = { |
| 6826 | .adj = DPO_PROTO_MPLS, |
| 6827 | }, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 6828 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6829 | |
| 6830 | fib_table_entry_path_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6831 | &pfx_1_1_1_1_s_32, |
| 6832 | FIB_SOURCE_API, |
| 6833 | DPO_PROTO_IP4, |
| 6834 | &nh_10_10_11_1, |
| 6835 | tm->hw[1]->sw_if_index, |
| 6836 | ~0, // invalid fib index |
| 6837 | 1, |
| 6838 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6839 | |
| 6840 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_1_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6841 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6842 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6843 | 1, |
| 6844 | &adj_o_10_10_11_2), |
| 6845 | "1.1.1.1/32 LB 1 buckets via: " |
| 6846 | "adj over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6847 | |
| 6848 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6849 | &pfx_24001_eos); |
| 6850 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6851 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 6852 | 1, |
| 6853 | &disp_o_10_10_11_2), |
| 6854 | "24001/eos LB 1 buckets via: " |
| 6855 | "MPLS disp adj over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6856 | |
| 6857 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6858 | &pfx_24001_neos); |
| 6859 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6860 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 6861 | 1, |
| 6862 | &mpls_bucket_drop), |
| 6863 | "24001/neos LB 1 buckets via: DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6864 | |
| 6865 | /* |
| 6866 | * add back the path with the valid label |
| 6867 | */ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 6868 | l99 = NULL; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 6869 | vec_add1(l99, fml99); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 6870 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6871 | fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6872 | &pfx_1_1_1_1_s_32, |
| 6873 | FIB_SOURCE_API, |
| 6874 | FIB_ENTRY_FLAG_NONE, |
| 6875 | DPO_PROTO_IP4, |
| 6876 | &nh_10_10_10_1, |
| 6877 | tm->hw[0]->sw_if_index, |
| 6878 | ~0, // invalid fib index |
| 6879 | 1, |
| 6880 | l99, |
| 6881 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6882 | |
| 6883 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_1_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6884 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6885 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6886 | 2, |
| 6887 | &l99_eos_o_10_10_10_1, |
| 6888 | &adj_o_10_10_11_2), |
| 6889 | "1.1.1.1/32 LB 2 buckets via: " |
| 6890 | "label 99 over 10.10.10.1, " |
| 6891 | "adj over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6892 | |
| 6893 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6894 | &pfx_24001_eos); |
| 6895 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6896 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 6897 | 2, |
| 6898 | &l99_eos_o_10_10_10_1, |
| 6899 | &disp_o_10_10_11_2), |
| 6900 | "24001/eos LB 2 buckets via: " |
| 6901 | "label 99 over 10.10.10.1, " |
| 6902 | "MPLS disp adj over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6903 | |
| 6904 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6905 | &pfx_24001_neos); |
| 6906 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6907 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 6908 | 1, |
| 6909 | &l99_neos_o_10_10_10_1), |
| 6910 | "24001/neos LB 1 buckets via: " |
| 6911 | "label 99 over 10.10.10.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6912 | |
| 6913 | /* |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 6914 | * change the local label |
| 6915 | */ |
| 6916 | fib_table_entry_local_label_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6917 | &pfx_1_1_1_1_s_32, |
| 6918 | 25005); |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 6919 | |
| 6920 | fib_prefix_t pfx_25005_eos = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6921 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 6922 | .fp_label = 25005, |
| 6923 | .fp_eos = MPLS_EOS, |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 6924 | }; |
| 6925 | fib_prefix_t pfx_25005_neos = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6926 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 6927 | .fp_label = 25005, |
| 6928 | .fp_eos = MPLS_NON_EOS, |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 6929 | }; |
| 6930 | |
| 6931 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6932 | fib_table_lookup(fib_index, &pfx_24001_eos)), |
| 6933 | "24001/eos removed after label change"); |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 6934 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6935 | fib_table_lookup(fib_index, &pfx_24001_neos)), |
| 6936 | "24001/eos removed after label change"); |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 6937 | |
| 6938 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6939 | &pfx_25005_eos); |
| 6940 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6941 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 6942 | 2, |
| 6943 | &l99_eos_o_10_10_10_1, |
| 6944 | &disp_o_10_10_11_2), |
| 6945 | "25005/eos LB 2 buckets via: " |
| 6946 | "label 99 over 10.10.10.1, " |
| 6947 | "MPLS disp adj over 10.10.11.2"); |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 6948 | |
| 6949 | fei = fib_table_lookup(MPLS_FIB_DEFAULT_TABLE_ID, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6950 | &pfx_25005_neos); |
| 6951 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6952 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 6953 | 1, |
| 6954 | &l99_neos_o_10_10_10_1), |
| 6955 | "25005/neos LB 1 buckets via: " |
| 6956 | "label 99 over 10.10.10.1"); |
Neale Ranns | 1357f3b | 2016-10-16 12:01:42 -0700 | [diff] [blame] | 6957 | |
| 6958 | /* |
| 6959 | * remove the local label. |
| 6960 | * the check that the MPLS entries are gone is done by the fact the |
| 6961 | * MPLS table is no longer present. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6962 | */ |
| 6963 | fib_table_entry_local_label_remove(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6964 | &pfx_1_1_1_1_s_32, |
| 6965 | 25005); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6966 | |
| 6967 | fei = fib_table_lookup(fib_index, &pfx_1_1_1_1_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6968 | FIB_TEST(!fib_test_validate_entry(fei, |
| 6969 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 6970 | 2, |
| 6971 | &l99_eos_o_10_10_10_1, |
| 6972 | &adj_o_10_10_11_2), |
| 6973 | "24001/eos LB 2 buckets via: " |
| 6974 | "label 99 over 10.10.10.1, " |
| 6975 | "adj over 10.10.11.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6976 | |
| 6977 | FIB_TEST((FIB_NODE_INDEX_INVALID == |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6978 | mpls_fib_index_from_table_id(MPLS_FIB_DEFAULT_TABLE_ID)), |
| 6979 | "No more MPLS FIB entries => table removed"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6980 | |
| 6981 | /* |
| 6982 | * add another via-entry for the recursive |
| 6983 | */ |
| 6984 | fib_prefix_t pfx_1_1_1_2_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6985 | .fp_len = 32, |
| 6986 | .fp_proto = FIB_PROTOCOL_IP4, |
| 6987 | .fp_addr = { |
| 6988 | .ip4.as_u32 = clib_host_to_net_u32(0x01010102), |
| 6989 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6990 | }; |
| 6991 | fib_test_lb_bucket_t l101_eos_o_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 6992 | .type = FT_LB_LABEL_O_ADJ, |
| 6993 | .label_o_adj = { |
| 6994 | .adj = ai_mpls_10_10_10_1, |
| 6995 | .label = 101, |
| 6996 | .eos = MPLS_EOS, |
| 6997 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 6998 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 6999 | fib_mpls_label_t *l101 = NULL, fml101 = { |
| 7000 | .fml_value = 101, |
| 7001 | }; |
| 7002 | vec_add1(l101, fml101); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7003 | |
| 7004 | fei = fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7005 | &pfx_1_1_1_2_s_32, |
| 7006 | FIB_SOURCE_API, |
| 7007 | FIB_ENTRY_FLAG_NONE, |
| 7008 | DPO_PROTO_IP4, |
| 7009 | &nh_10_10_10_1, |
| 7010 | tm->hw[0]->sw_if_index, |
| 7011 | ~0, // invalid fib index |
| 7012 | 1, |
| 7013 | l101, |
| 7014 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7015 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7016 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7017 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7018 | 1, |
| 7019 | &l101_eos_o_10_10_10_1), |
| 7020 | "1.1.1.2/32 LB 1 buckets via: " |
| 7021 | "label 101 over 10.10.10.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7022 | |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 7023 | dpo_id_t non_eos_1_1_1_2 = DPO_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7024 | fib_entry_contribute_forwarding(fib_table_lookup(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7025 | &pfx_1_1_1_1_s_32), |
| 7026 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 7027 | &non_eos_1_1_1_1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7028 | fib_entry_contribute_forwarding(fib_table_lookup(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7029 | &pfx_1_1_1_2_s_32), |
| 7030 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 7031 | &non_eos_1_1_1_2); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7032 | |
| 7033 | fib_test_lb_bucket_t l1601_eos_o_1_1_1_2 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7034 | .type = FT_LB_LABEL_O_LB, |
| 7035 | .label_o_lb = { |
| 7036 | .lb = non_eos_1_1_1_2.dpoi_index, |
| 7037 | .label = 1601, |
| 7038 | .eos = MPLS_EOS, |
| 7039 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7040 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 7041 | fib_mpls_label_t *l1601 = NULL, fml1601 = { |
| 7042 | .fml_value = 1601, |
| 7043 | }; |
| 7044 | vec_add1(l1601, fml1601); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 7045 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7046 | l1600_eos_o_1_1_1_1.label_o_lb.lb = non_eos_1_1_1_1.dpoi_index; |
| 7047 | |
| 7048 | fei = fib_table_entry_path_add(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7049 | &pfx_2_2_2_2_s_32, |
| 7050 | FIB_SOURCE_API, |
| 7051 | FIB_ENTRY_FLAG_NONE, |
| 7052 | DPO_PROTO_IP4, |
| 7053 | &pfx_1_1_1_2_s_32.fp_addr, |
| 7054 | ~0, |
| 7055 | fib_index, |
| 7056 | 1, |
| 7057 | l1601, |
| 7058 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7059 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7060 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7061 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7062 | 2, |
| 7063 | &l1600_eos_o_1_1_1_1, |
| 7064 | &l1601_eos_o_1_1_1_2), |
| 7065 | "2.2.2.2/32 LB 2 buckets via: " |
| 7066 | "label 1600 via 1.1,1.1, " |
| 7067 | "label 16001 via 1.1.1.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7068 | |
| 7069 | /* |
| 7070 | * update the via-entry so it no longer has an imp-null path. |
| 7071 | * the LB for the recursive can use an imp-null |
| 7072 | */ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 7073 | l_imp_null = NULL; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 7074 | vec_add1(l_imp_null, fml_imp_null); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 7075 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7076 | fei = fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7077 | &pfx_1_1_1_2_s_32, |
| 7078 | FIB_SOURCE_API, |
| 7079 | FIB_ENTRY_FLAG_NONE, |
| 7080 | DPO_PROTO_IP4, |
| 7081 | &nh_10_10_11_1, |
| 7082 | tm->hw[1]->sw_if_index, |
| 7083 | ~0, // invalid fib index |
| 7084 | 1, |
| 7085 | l_imp_null, |
| 7086 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7087 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7088 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7089 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7090 | 1, |
| 7091 | &a_o_10_10_11_1), |
| 7092 | "1.1.1.2/32 LB 1 buckets via: " |
| 7093 | "adj 10.10.11.1"); |
| 7094 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7095 | fei = fib_table_lookup(fib_index, &pfx_2_2_2_2_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7096 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7097 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7098 | 2, |
| 7099 | &l1600_eos_o_1_1_1_1, |
| 7100 | &l1601_eos_o_1_1_1_2), |
| 7101 | "2.2.2.2/32 LB 2 buckets via: " |
| 7102 | "label 1600 via 1.1,1.1, " |
| 7103 | "label 16001 via 1.1.1.2"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7104 | |
| 7105 | /* |
| 7106 | * update the via-entry so it no longer has labelled paths. |
| 7107 | * the LB for the recursive should exclue this via form its LB |
| 7108 | */ |
| 7109 | fei = fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7110 | &pfx_1_1_1_2_s_32, |
| 7111 | FIB_SOURCE_API, |
| 7112 | FIB_ENTRY_FLAG_NONE, |
| 7113 | DPO_PROTO_IP4, |
| 7114 | &nh_10_10_11_1, |
| 7115 | tm->hw[1]->sw_if_index, |
| 7116 | ~0, // invalid fib index |
| 7117 | 1, |
| 7118 | NULL, |
| 7119 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7120 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7121 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7122 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7123 | 1, |
| 7124 | &a_o_10_10_11_1), |
| 7125 | "1.1.1.2/32 LB 1 buckets via: " |
| 7126 | "adj 10.10.11.1"); |
| 7127 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7128 | fei = fib_table_lookup(fib_index, &pfx_2_2_2_2_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7129 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7130 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7131 | 1, |
| 7132 | &l1600_eos_o_1_1_1_1), |
| 7133 | "2.2.2.2/32 LB 1 buckets via: " |
| 7134 | "label 1600 via 1.1,1.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7135 | |
| 7136 | dpo_reset(&non_eos_1_1_1_1); |
| 7137 | dpo_reset(&non_eos_1_1_1_2); |
| 7138 | |
| 7139 | /* |
| 7140 | * Add a recursive with no out-labels. We expect to use the IP of the via |
| 7141 | */ |
| 7142 | fib_prefix_t pfx_2_2_2_3_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7143 | .fp_len = 32, |
| 7144 | .fp_proto = FIB_PROTOCOL_IP4, |
| 7145 | .fp_addr = { |
| 7146 | .ip4.as_u32 = clib_host_to_net_u32(0x02020203), |
| 7147 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7148 | }; |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 7149 | dpo_id_t ip_1_1_1_1 = DPO_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7150 | |
| 7151 | fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7152 | &pfx_2_2_2_3_s_32, |
| 7153 | FIB_SOURCE_API, |
| 7154 | FIB_ENTRY_FLAG_NONE, |
| 7155 | DPO_PROTO_IP4, |
| 7156 | &pfx_1_1_1_1_s_32.fp_addr, |
| 7157 | ~0, |
| 7158 | fib_index, |
| 7159 | 1, |
| 7160 | NULL, |
| 7161 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7162 | |
| 7163 | fib_entry_contribute_forwarding(fib_table_lookup(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7164 | &pfx_1_1_1_1_s_32), |
| 7165 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7166 | &ip_1_1_1_1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7167 | |
| 7168 | fib_test_lb_bucket_t ip_o_1_1_1_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7169 | .type = FT_LB_O_LB, |
| 7170 | .lb = { |
| 7171 | .lb = ip_1_1_1_1.dpoi_index, |
| 7172 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7173 | }; |
| 7174 | |
| 7175 | fei = fib_table_lookup(fib_index, &pfx_2_2_2_3_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7176 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7177 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7178 | 1, |
| 7179 | &ip_o_1_1_1_1), |
| 7180 | "2.2.2.2.3/32 LB 1 buckets via: " |
| 7181 | "ip 1.1.1.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7182 | |
| 7183 | /* |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7184 | * Add a recursive with an imp-null out-label. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7185 | * We expect to use the IP of the via |
| 7186 | */ |
| 7187 | fib_prefix_t pfx_2_2_2_4_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7188 | .fp_len = 32, |
| 7189 | .fp_proto = FIB_PROTOCOL_IP4, |
| 7190 | .fp_addr = { |
| 7191 | .ip4.as_u32 = clib_host_to_net_u32(0x02020204), |
| 7192 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7193 | }; |
| 7194 | |
| 7195 | fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7196 | &pfx_2_2_2_4_s_32, |
| 7197 | FIB_SOURCE_API, |
| 7198 | FIB_ENTRY_FLAG_NONE, |
| 7199 | DPO_PROTO_IP4, |
| 7200 | &pfx_1_1_1_1_s_32.fp_addr, |
| 7201 | ~0, |
| 7202 | fib_index, |
| 7203 | 1, |
| 7204 | NULL, |
| 7205 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7206 | |
| 7207 | fei = fib_table_lookup(fib_index, &pfx_2_2_2_4_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7208 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7209 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7210 | 1, |
| 7211 | &ip_o_1_1_1_1), |
| 7212 | "2.2.2.2.4/32 LB 1 buckets via: " |
| 7213 | "ip 1.1.1.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7214 | |
| 7215 | dpo_reset(&ip_1_1_1_1); |
| 7216 | |
| 7217 | /* |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 7218 | * Create an entry with a deep label stack |
| 7219 | */ |
| 7220 | fib_prefix_t pfx_2_2_5_5_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7221 | .fp_len = 32, |
| 7222 | .fp_proto = FIB_PROTOCOL_IP4, |
| 7223 | .fp_addr = { |
| 7224 | .ip4.as_u32 = clib_host_to_net_u32(0x02020505), |
| 7225 | }, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 7226 | }; |
| 7227 | fib_test_lb_bucket_t ls_eos_o_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7228 | .type = FT_LB_LABEL_STACK_O_ADJ, |
| 7229 | .label_stack_o_adj = { |
| 7230 | .adj = ai_mpls_10_10_11_1, |
| 7231 | .label_stack_size = 8, |
| 7232 | .label_stack = { |
| 7233 | 200, 201, 202, 203, 204, 205, 206, 207 |
| 7234 | }, |
| 7235 | .eos = MPLS_EOS, |
| 7236 | }, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 7237 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 7238 | fib_mpls_label_t *label_stack = NULL; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 7239 | vec_validate(label_stack, 7); |
| 7240 | for (ii = 0; ii < 8; ii++) |
| 7241 | { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 7242 | label_stack[ii].fml_value = ii + 200; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 7243 | } |
| 7244 | |
| 7245 | fei = fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7246 | &pfx_2_2_5_5_s_32, |
| 7247 | FIB_SOURCE_API, |
| 7248 | FIB_ENTRY_FLAG_NONE, |
| 7249 | DPO_PROTO_IP4, |
| 7250 | &nh_10_10_11_1, |
| 7251 | tm->hw[1]->sw_if_index, |
| 7252 | ~0, // invalid fib index |
| 7253 | 1, |
| 7254 | label_stack, |
| 7255 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 7256 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7257 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7258 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7259 | 1, |
| 7260 | &ls_eos_o_10_10_10_1), |
| 7261 | "2.2.5.5/32 LB 1 buckets via: " |
| 7262 | "adj 10.10.11.1"); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 7263 | fib_table_entry_delete_index(fei, FIB_SOURCE_API); |
| 7264 | |
| 7265 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7266 | * cleanup |
| 7267 | */ |
| 7268 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7269 | &pfx_1_1_1_2_s_32, |
| 7270 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7271 | |
| 7272 | fei = fib_table_lookup(fib_index, &pfx_2_2_2_2_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7273 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7274 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7275 | 1, |
| 7276 | &l1600_eos_o_1_1_1_1), |
| 7277 | "2.2.2.2/32 LB 1 buckets via: " |
| 7278 | "label 1600 via 1.1,1.1"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7279 | |
| 7280 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7281 | &pfx_1_1_1_1_s_32, |
| 7282 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7283 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7284 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7285 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7286 | 1, |
| 7287 | &bucket_drop), |
| 7288 | "2.2.2.2/32 LB 1 buckets via: DROP"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7289 | |
| 7290 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7291 | &pfx_2_2_2_2_s_32, |
| 7292 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7293 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7294 | &pfx_2_2_2_3_s_32, |
| 7295 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7296 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7297 | &pfx_2_2_2_4_s_32, |
| 7298 | FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7299 | |
| 7300 | adj_unlock(ai_mpls_10_10_10_1); |
| 7301 | adj_unlock(ai_mpls_10_10_11_2); |
| 7302 | adj_unlock(ai_v4_10_10_11_1); |
| 7303 | adj_unlock(ai_v4_10_10_11_2); |
| 7304 | adj_unlock(ai_mpls_10_10_11_1); |
| 7305 | |
| 7306 | FIB_TEST((0 == adj_nbr_db_size()), "ADJ DB size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7307 | adj_nbr_db_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7308 | |
| 7309 | local0_pfx.fp_len = 32; |
| 7310 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7311 | &local0_pfx, |
| 7312 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7313 | local0_pfx.fp_len = 24; |
| 7314 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7315 | &local0_pfx, |
| 7316 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7317 | local1_pfx.fp_len = 32; |
| 7318 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7319 | &local1_pfx, |
| 7320 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7321 | local1_pfx.fp_len = 24; |
| 7322 | fib_table_entry_delete(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7323 | &local1_pfx, |
| 7324 | FIB_SOURCE_INTERFACE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7325 | |
| 7326 | /* |
| 7327 | * +1 for the drop LB in the MPLS tables. |
| 7328 | */ |
| 7329 | FIB_TEST(lb_count+1 == pool_elts(load_balance_pool), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7330 | "Load-balance resources freed %d of %d", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7331 | lb_count+1, pool_elts(load_balance_pool)); |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 7332 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7333 | return (res); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7334 | } |
| 7335 | |
| 7336 | #define N_TEST_CHILDREN 4 |
| 7337 | #define PARENT_INDEX 0 |
| 7338 | |
| 7339 | typedef struct fib_node_test_t_ |
| 7340 | { |
| 7341 | fib_node_t node; |
| 7342 | u32 sibling; |
| 7343 | u32 index; |
| 7344 | fib_node_back_walk_ctx_t *ctxs; |
| 7345 | u32 destroyed; |
| 7346 | } fib_node_test_t; |
| 7347 | |
| 7348 | static fib_node_test_t fib_test_nodes[N_TEST_CHILDREN+1]; |
| 7349 | |
| 7350 | #define PARENT() (&fib_test_nodes[PARENT_INDEX].node) |
| 7351 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7352 | #define FOR_EACH_TEST_CHILD(_tc) \ |
| 7353 | for (ii = 1, (_tc) = &fib_test_nodes[1]; \ |
| 7354 | ii < N_TEST_CHILDREN+1; \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7355 | ii++, (_tc) = &fib_test_nodes[ii]) |
| 7356 | |
| 7357 | static fib_node_t * |
| 7358 | fib_test_child_get_node (fib_node_index_t index) |
| 7359 | { |
| 7360 | return (&fib_test_nodes[index].node); |
| 7361 | } |
| 7362 | |
| 7363 | static int fib_test_walk_spawns_walks; |
| 7364 | |
| 7365 | static fib_node_back_walk_rc_t |
| 7366 | fib_test_child_back_walk_notify (fib_node_t *node, |
| 7367 | fib_node_back_walk_ctx_t *ctx) |
| 7368 | { |
| 7369 | fib_node_test_t *tc = (fib_node_test_t*) node; |
| 7370 | |
| 7371 | vec_add1(tc->ctxs, *ctx); |
| 7372 | |
| 7373 | if (1 == fib_test_walk_spawns_walks) |
| 7374 | fib_walk_sync(FIB_NODE_TYPE_TEST, tc->index, ctx); |
| 7375 | if (2 == fib_test_walk_spawns_walks) |
| 7376 | fib_walk_async(FIB_NODE_TYPE_TEST, tc->index, |
| 7377 | FIB_WALK_PRIORITY_HIGH, ctx); |
| 7378 | |
| 7379 | return (FIB_NODE_BACK_WALK_CONTINUE); |
| 7380 | } |
| 7381 | |
| 7382 | static void |
| 7383 | fib_test_child_last_lock_gone (fib_node_t *node) |
| 7384 | { |
| 7385 | fib_node_test_t *tc = (fib_node_test_t *)node; |
| 7386 | |
| 7387 | tc->destroyed = 1; |
| 7388 | } |
| 7389 | |
| 7390 | /** |
| 7391 | * The FIB walk's graph node virtual function table |
| 7392 | */ |
| 7393 | static const fib_node_vft_t fib_test_child_vft = { |
| 7394 | .fnv_get = fib_test_child_get_node, |
| 7395 | .fnv_last_lock = fib_test_child_last_lock_gone, |
| 7396 | .fnv_back_walk = fib_test_child_back_walk_notify, |
| 7397 | }; |
| 7398 | |
| 7399 | /* |
| 7400 | * the function (that should have been static but isn't so I can do this) |
| 7401 | * that processes the walk from the async queue, |
| 7402 | */ |
| 7403 | f64 fib_walk_process_queues(vlib_main_t * vm, |
| 7404 | const f64 quota); |
| 7405 | u32 fib_walk_queue_get_size(fib_walk_priority_t prio); |
| 7406 | |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 7407 | static int |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7408 | fib_test_walk (void) |
| 7409 | { |
| 7410 | fib_node_back_walk_ctx_t high_ctx = {}, low_ctx = {}; |
| 7411 | fib_node_test_t *tc; |
| 7412 | vlib_main_t *vm; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7413 | u32 ii, res; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7414 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7415 | res = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7416 | vm = vlib_get_main(); |
| 7417 | fib_node_register_type(FIB_NODE_TYPE_TEST, &fib_test_child_vft); |
| 7418 | |
| 7419 | /* |
| 7420 | * init a fake node on which we will add children |
| 7421 | */ |
| 7422 | fib_node_init(&fib_test_nodes[PARENT_INDEX].node, |
| 7423 | FIB_NODE_TYPE_TEST); |
| 7424 | |
| 7425 | FOR_EACH_TEST_CHILD(tc) |
| 7426 | { |
| 7427 | fib_node_init(&tc->node, FIB_NODE_TYPE_TEST); |
| 7428 | fib_node_lock(&tc->node); |
| 7429 | tc->ctxs = NULL; |
| 7430 | tc->index = ii; |
| 7431 | tc->sibling = fib_node_child_add(FIB_NODE_TYPE_TEST, |
| 7432 | PARENT_INDEX, |
| 7433 | FIB_NODE_TYPE_TEST, ii); |
| 7434 | } |
| 7435 | |
| 7436 | /* |
| 7437 | * enqueue a walk across the parents children. |
| 7438 | */ |
Neale Ranns | 450cd30 | 2016-11-09 17:49:42 +0000 | [diff] [blame] | 7439 | high_ctx.fnbw_reason = FIB_NODE_BW_REASON_FLAG_RESOLVE; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7440 | |
| 7441 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7442 | FIB_WALK_PRIORITY_HIGH, &high_ctx); |
| 7443 | FIB_TEST(N_TEST_CHILDREN+1 == fib_node_list_get_size(PARENT()->fn_children), |
| 7444 | "Parent has %d children pre-walk", |
| 7445 | fib_node_list_get_size(PARENT()->fn_children)); |
| 7446 | |
| 7447 | /* |
| 7448 | * give the walk a large amount of time so it gets to the end |
| 7449 | */ |
| 7450 | fib_walk_process_queues(vm, 1); |
| 7451 | |
| 7452 | FOR_EACH_TEST_CHILD(tc) |
| 7453 | { |
| 7454 | FIB_TEST(1 == vec_len(tc->ctxs), |
| 7455 | "%d child visitsed %d times", |
| 7456 | ii, vec_len(tc->ctxs)); |
| 7457 | vec_free(tc->ctxs); |
| 7458 | } |
| 7459 | FIB_TEST(0 == fib_walk_queue_get_size(FIB_WALK_PRIORITY_HIGH), |
| 7460 | "Queue is empty post walk"); |
| 7461 | FIB_TEST(N_TEST_CHILDREN == fib_node_list_get_size(PARENT()->fn_children), |
| 7462 | "Parent has %d children post walk", |
| 7463 | fib_node_list_get_size(PARENT()->fn_children)); |
| 7464 | |
| 7465 | /* |
| 7466 | * walk again. should be no increase in the number of visits, since |
| 7467 | * the walk will have terminated. |
| 7468 | */ |
| 7469 | fib_walk_process_queues(vm, 1); |
| 7470 | |
| 7471 | FOR_EACH_TEST_CHILD(tc) |
| 7472 | { |
| 7473 | FIB_TEST(0 == vec_len(tc->ctxs), |
| 7474 | "%d child visitsed %d times", |
| 7475 | ii, vec_len(tc->ctxs)); |
| 7476 | } |
| 7477 | |
| 7478 | /* |
| 7479 | * schedule a low and hig priority walk. expect the high to be performed |
| 7480 | * before the low. |
| 7481 | * schedule the high prio walk first so that it is further from the head |
| 7482 | * of the dependency list. that way it won't merge with the low one. |
| 7483 | */ |
| 7484 | high_ctx.fnbw_reason = FIB_NODE_BW_REASON_FLAG_RESOLVE; |
| 7485 | low_ctx.fnbw_reason = FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE; |
| 7486 | |
| 7487 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7488 | FIB_WALK_PRIORITY_HIGH, &high_ctx); |
| 7489 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7490 | FIB_WALK_PRIORITY_LOW, &low_ctx); |
| 7491 | |
| 7492 | fib_walk_process_queues(vm, 1); |
| 7493 | |
| 7494 | FOR_EACH_TEST_CHILD(tc) |
| 7495 | { |
| 7496 | FIB_TEST(high_ctx.fnbw_reason == tc->ctxs[0].fnbw_reason, |
| 7497 | "%d child visitsed by high prio walk", ii); |
| 7498 | FIB_TEST(low_ctx.fnbw_reason == tc->ctxs[1].fnbw_reason, |
| 7499 | "%d child visitsed by low prio walk", ii); |
| 7500 | vec_free(tc->ctxs); |
| 7501 | } |
| 7502 | FIB_TEST(0 == fib_walk_queue_get_size(FIB_WALK_PRIORITY_HIGH), |
| 7503 | "Queue is empty post prio walk"); |
| 7504 | FIB_TEST(N_TEST_CHILDREN == fib_node_list_get_size(PARENT()->fn_children), |
| 7505 | "Parent has %d children post prio walk", |
| 7506 | fib_node_list_get_size(PARENT()->fn_children)); |
| 7507 | |
| 7508 | /* |
| 7509 | * schedule 2 walks of the same priority that can be megred. |
| 7510 | * expect that each child is thus visited only once. |
| 7511 | */ |
| 7512 | high_ctx.fnbw_reason = FIB_NODE_BW_REASON_FLAG_RESOLVE; |
| 7513 | low_ctx.fnbw_reason = FIB_NODE_BW_REASON_FLAG_RESOLVE; |
| 7514 | |
| 7515 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7516 | FIB_WALK_PRIORITY_HIGH, &high_ctx); |
| 7517 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7518 | FIB_WALK_PRIORITY_HIGH, &low_ctx); |
| 7519 | |
| 7520 | fib_walk_process_queues(vm, 1); |
| 7521 | |
| 7522 | FOR_EACH_TEST_CHILD(tc) |
| 7523 | { |
| 7524 | FIB_TEST(1 == vec_len(tc->ctxs), |
| 7525 | "%d child visitsed %d times during merge walk", |
| 7526 | ii, vec_len(tc->ctxs)); |
| 7527 | vec_free(tc->ctxs); |
| 7528 | } |
| 7529 | FIB_TEST(0 == fib_walk_queue_get_size(FIB_WALK_PRIORITY_HIGH), |
| 7530 | "Queue is empty post merge walk"); |
| 7531 | FIB_TEST(N_TEST_CHILDREN == fib_node_list_get_size(PARENT()->fn_children), |
| 7532 | "Parent has %d children post merge walk", |
| 7533 | fib_node_list_get_size(PARENT()->fn_children)); |
| 7534 | |
| 7535 | /* |
| 7536 | * schedule 2 walks of the same priority that cannot be megred. |
| 7537 | * expect that each child is thus visited twice and in the order |
| 7538 | * in which the walks were scheduled. |
| 7539 | */ |
| 7540 | high_ctx.fnbw_reason = FIB_NODE_BW_REASON_FLAG_RESOLVE; |
| 7541 | low_ctx.fnbw_reason = FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE; |
| 7542 | |
| 7543 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7544 | FIB_WALK_PRIORITY_HIGH, &high_ctx); |
| 7545 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7546 | FIB_WALK_PRIORITY_HIGH, &low_ctx); |
| 7547 | |
| 7548 | fib_walk_process_queues(vm, 1); |
| 7549 | |
| 7550 | FOR_EACH_TEST_CHILD(tc) |
| 7551 | { |
| 7552 | FIB_TEST(high_ctx.fnbw_reason == tc->ctxs[0].fnbw_reason, |
| 7553 | "%d child visitsed by high prio walk", ii); |
| 7554 | FIB_TEST(low_ctx.fnbw_reason == tc->ctxs[1].fnbw_reason, |
| 7555 | "%d child visitsed by low prio walk", ii); |
| 7556 | vec_free(tc->ctxs); |
| 7557 | } |
| 7558 | FIB_TEST(0 == fib_walk_queue_get_size(FIB_WALK_PRIORITY_HIGH), |
| 7559 | "Queue is empty post no-merge walk"); |
| 7560 | FIB_TEST(N_TEST_CHILDREN == fib_node_list_get_size(PARENT()->fn_children), |
| 7561 | "Parent has %d children post no-merge walk", |
| 7562 | fib_node_list_get_size(PARENT()->fn_children)); |
| 7563 | |
| 7564 | /* |
| 7565 | * schedule a walk that makes one one child progress. |
| 7566 | * we do this by giving the queue draining process zero |
| 7567 | * time quanta. it's a do..while loop, so it does something. |
| 7568 | */ |
Neale Ranns | 450cd30 | 2016-11-09 17:49:42 +0000 | [diff] [blame] | 7569 | high_ctx.fnbw_reason = FIB_NODE_BW_REASON_FLAG_RESOLVE; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7570 | |
| 7571 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7572 | FIB_WALK_PRIORITY_HIGH, &high_ctx); |
| 7573 | fib_walk_process_queues(vm, 0); |
| 7574 | |
| 7575 | FOR_EACH_TEST_CHILD(tc) |
| 7576 | { |
| 7577 | if (ii == N_TEST_CHILDREN) |
| 7578 | { |
| 7579 | FIB_TEST(1 == vec_len(tc->ctxs), |
| 7580 | "%d child visitsed %d times in zero quanta walk", |
| 7581 | ii, vec_len(tc->ctxs)); |
| 7582 | } |
| 7583 | else |
| 7584 | { |
| 7585 | FIB_TEST(0 == vec_len(tc->ctxs), |
| 7586 | "%d child visitsed %d times in 0 quanta walk", |
| 7587 | ii, vec_len(tc->ctxs)); |
| 7588 | } |
| 7589 | } |
| 7590 | FIB_TEST(1 == fib_walk_queue_get_size(FIB_WALK_PRIORITY_HIGH), |
| 7591 | "Queue is not empty post zero quanta walk"); |
| 7592 | FIB_TEST(N_TEST_CHILDREN+1 == fib_node_list_get_size(PARENT()->fn_children), |
| 7593 | "Parent has %d children post zero qunta walk", |
| 7594 | fib_node_list_get_size(PARENT()->fn_children)); |
| 7595 | |
| 7596 | /* |
| 7597 | * another one step |
| 7598 | */ |
| 7599 | fib_walk_process_queues(vm, 0); |
| 7600 | |
| 7601 | FOR_EACH_TEST_CHILD(tc) |
| 7602 | { |
| 7603 | if (ii >= N_TEST_CHILDREN-1) |
| 7604 | { |
| 7605 | FIB_TEST(1 == vec_len(tc->ctxs), |
| 7606 | "%d child visitsed %d times in 2nd zero quanta walk", |
| 7607 | ii, vec_len(tc->ctxs)); |
| 7608 | } |
| 7609 | else |
| 7610 | { |
| 7611 | FIB_TEST(0 == vec_len(tc->ctxs), |
| 7612 | "%d child visitsed %d times in 2nd 0 quanta walk", |
| 7613 | ii, vec_len(tc->ctxs)); |
| 7614 | } |
| 7615 | } |
| 7616 | FIB_TEST(1 == fib_walk_queue_get_size(FIB_WALK_PRIORITY_HIGH), |
| 7617 | "Queue is not empty post zero quanta walk"); |
| 7618 | FIB_TEST(N_TEST_CHILDREN+1 == fib_node_list_get_size(PARENT()->fn_children), |
| 7619 | "Parent has %d children post zero qunta walk", |
| 7620 | fib_node_list_get_size(PARENT()->fn_children)); |
| 7621 | |
| 7622 | /* |
| 7623 | * schedule another walk that will catch-up and merge. |
| 7624 | */ |
| 7625 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7626 | FIB_WALK_PRIORITY_HIGH, &high_ctx); |
| 7627 | fib_walk_process_queues(vm, 1); |
| 7628 | |
| 7629 | FOR_EACH_TEST_CHILD(tc) |
| 7630 | { |
| 7631 | if (ii >= N_TEST_CHILDREN-1) |
| 7632 | { |
| 7633 | FIB_TEST(2 == vec_len(tc->ctxs), |
| 7634 | "%d child visitsed %d times in 2nd zero quanta merge walk", |
| 7635 | ii, vec_len(tc->ctxs)); |
| 7636 | vec_free(tc->ctxs); |
| 7637 | } |
| 7638 | else |
| 7639 | { |
| 7640 | FIB_TEST(1 == vec_len(tc->ctxs), |
| 7641 | "%d child visitsed %d times in 2nd 0 quanta merge walk", |
| 7642 | ii, vec_len(tc->ctxs)); |
| 7643 | vec_free(tc->ctxs); |
| 7644 | } |
| 7645 | } |
| 7646 | FIB_TEST(0 == fib_walk_queue_get_size(FIB_WALK_PRIORITY_HIGH), |
| 7647 | "Queue is not empty post 2nd zero quanta merge walk"); |
| 7648 | FIB_TEST(N_TEST_CHILDREN == fib_node_list_get_size(PARENT()->fn_children), |
| 7649 | "Parent has %d children post 2nd zero qunta merge walk", |
| 7650 | fib_node_list_get_size(PARENT()->fn_children)); |
| 7651 | |
| 7652 | /* |
| 7653 | * park a async walk in the middle of the list, then have an sync walk catch |
| 7654 | * it. same expectations as async catches async. |
| 7655 | */ |
Neale Ranns | 450cd30 | 2016-11-09 17:49:42 +0000 | [diff] [blame] | 7656 | high_ctx.fnbw_reason = FIB_NODE_BW_REASON_FLAG_RESOLVE; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7657 | |
| 7658 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7659 | FIB_WALK_PRIORITY_HIGH, &high_ctx); |
| 7660 | |
| 7661 | fib_walk_process_queues(vm, 0); |
| 7662 | fib_walk_process_queues(vm, 0); |
| 7663 | |
| 7664 | fib_walk_sync(FIB_NODE_TYPE_TEST, PARENT_INDEX, &high_ctx); |
| 7665 | |
| 7666 | FOR_EACH_TEST_CHILD(tc) |
| 7667 | { |
| 7668 | if (ii >= N_TEST_CHILDREN-1) |
| 7669 | { |
| 7670 | FIB_TEST(2 == vec_len(tc->ctxs), |
| 7671 | "%d child visitsed %d times in sync catches async walk", |
| 7672 | ii, vec_len(tc->ctxs)); |
| 7673 | vec_free(tc->ctxs); |
| 7674 | } |
| 7675 | else |
| 7676 | { |
| 7677 | FIB_TEST(1 == vec_len(tc->ctxs), |
| 7678 | "%d child visitsed %d times in sync catches async walk", |
| 7679 | ii, vec_len(tc->ctxs)); |
| 7680 | vec_free(tc->ctxs); |
| 7681 | } |
| 7682 | } |
| 7683 | FIB_TEST(0 == fib_walk_queue_get_size(FIB_WALK_PRIORITY_HIGH), |
| 7684 | "Queue is not empty post 2nd zero quanta merge walk"); |
| 7685 | FIB_TEST(N_TEST_CHILDREN == fib_node_list_get_size(PARENT()->fn_children), |
| 7686 | "Parent has %d children post 2nd zero qunta merge walk", |
| 7687 | fib_node_list_get_size(PARENT()->fn_children)); |
| 7688 | |
| 7689 | /* |
| 7690 | * make the parent a child of one of its children, thus inducing a routing loop. |
| 7691 | */ |
| 7692 | fib_test_nodes[PARENT_INDEX].sibling = |
| 7693 | fib_node_child_add(FIB_NODE_TYPE_TEST, |
| 7694 | 1, // the first child |
| 7695 | FIB_NODE_TYPE_TEST, |
| 7696 | PARENT_INDEX); |
| 7697 | |
| 7698 | /* |
| 7699 | * execute a sync walk from the parent. each child visited spawns more sync |
| 7700 | * walks. we expect the walk to terminate. |
| 7701 | */ |
| 7702 | fib_test_walk_spawns_walks = 1; |
| 7703 | |
| 7704 | fib_walk_sync(FIB_NODE_TYPE_TEST, PARENT_INDEX, &high_ctx); |
| 7705 | |
| 7706 | FOR_EACH_TEST_CHILD(tc) |
| 7707 | { |
| 7708 | /* |
| 7709 | * child 1 - which is last in the list - has the loop. |
| 7710 | * the other children a re thus visitsed first. the we meet |
| 7711 | * child 1. we go round the loop again, visting the other children. |
| 7712 | * then we meet the walk in the dep list and bail. child 1 is not visitsed |
| 7713 | * again. |
| 7714 | */ |
| 7715 | if (1 == ii) |
| 7716 | { |
| 7717 | FIB_TEST(1 == vec_len(tc->ctxs), |
| 7718 | "child %d visitsed %d times during looped sync walk", |
| 7719 | ii, vec_len(tc->ctxs)); |
| 7720 | } |
| 7721 | else |
| 7722 | { |
| 7723 | FIB_TEST(2 == vec_len(tc->ctxs), |
| 7724 | "child %d visitsed %d times during looped sync walk", |
| 7725 | ii, vec_len(tc->ctxs)); |
| 7726 | } |
| 7727 | vec_free(tc->ctxs); |
| 7728 | } |
| 7729 | FIB_TEST(N_TEST_CHILDREN == fib_node_list_get_size(PARENT()->fn_children), |
| 7730 | "Parent has %d children post sync loop walk", |
| 7731 | fib_node_list_get_size(PARENT()->fn_children)); |
| 7732 | |
| 7733 | /* |
| 7734 | * the walk doesn't reach the max depth because the infra knows that sync |
| 7735 | * meets sync implies a loop and bails early. |
| 7736 | */ |
| 7737 | FIB_TEST(high_ctx.fnbw_depth == 9, |
| 7738 | "Walk context depth %d post sync loop walk", |
| 7739 | high_ctx.fnbw_depth); |
| 7740 | |
| 7741 | /* |
| 7742 | * execute an async walk of the graph loop, with each child spawns sync walks |
| 7743 | */ |
| 7744 | high_ctx.fnbw_depth = 0; |
| 7745 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7746 | FIB_WALK_PRIORITY_HIGH, &high_ctx); |
| 7747 | |
| 7748 | fib_walk_process_queues(vm, 1); |
| 7749 | |
| 7750 | FOR_EACH_TEST_CHILD(tc) |
| 7751 | { |
| 7752 | /* |
| 7753 | * we don't really care how many times the children are visisted, as long as |
| 7754 | * it is more than once. |
| 7755 | */ |
| 7756 | FIB_TEST(1 <= vec_len(tc->ctxs), |
| 7757 | "child %d visitsed %d times during looped aync spawns sync walk", |
| 7758 | ii, vec_len(tc->ctxs)); |
| 7759 | vec_free(tc->ctxs); |
| 7760 | } |
| 7761 | |
| 7762 | /* |
| 7763 | * execute an async walk of the graph loop, with each child spawns async walks |
| 7764 | */ |
| 7765 | fib_test_walk_spawns_walks = 2; |
| 7766 | high_ctx.fnbw_depth = 0; |
| 7767 | fib_walk_async(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7768 | FIB_WALK_PRIORITY_HIGH, &high_ctx); |
| 7769 | |
| 7770 | fib_walk_process_queues(vm, 1); |
| 7771 | |
| 7772 | FOR_EACH_TEST_CHILD(tc) |
| 7773 | { |
| 7774 | /* |
| 7775 | * we don't really care how many times the children are visisted, as long as |
| 7776 | * it is more than once. |
| 7777 | */ |
| 7778 | FIB_TEST(1 <= vec_len(tc->ctxs), |
| 7779 | "child %d visitsed %d times during looped async spawns async walk", |
| 7780 | ii, vec_len(tc->ctxs)); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7781 | vec_free(tc->ctxs); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7782 | } |
| 7783 | |
| 7784 | |
| 7785 | fib_node_child_remove(FIB_NODE_TYPE_TEST, |
| 7786 | 1, // the first child |
| 7787 | fib_test_nodes[PARENT_INDEX].sibling); |
| 7788 | |
| 7789 | /* |
| 7790 | * cleanup |
| 7791 | */ |
| 7792 | FOR_EACH_TEST_CHILD(tc) |
| 7793 | { |
| 7794 | fib_node_child_remove(FIB_NODE_TYPE_TEST, PARENT_INDEX, |
| 7795 | tc->sibling); |
| 7796 | fib_node_deinit(&tc->node); |
| 7797 | fib_node_unlock(&tc->node); |
| 7798 | } |
| 7799 | fib_node_deinit(PARENT()); |
| 7800 | |
| 7801 | /* |
| 7802 | * The parent will be destroyed when the last lock on it goes. |
| 7803 | * this test ensures all the walk objects are unlocking it. |
| 7804 | */ |
| 7805 | FIB_TEST((1 == fib_test_nodes[PARENT_INDEX].destroyed), |
| 7806 | "Parent was destroyed"); |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 7807 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7808 | return (res); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 7809 | } |
| 7810 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 7811 | /* |
| 7812 | * declaration of the otherwise static callback functions |
| 7813 | */ |
| 7814 | void fib_bfd_notify (bfd_listen_event_e event, |
| 7815 | const bfd_session_t *session); |
| 7816 | void adj_bfd_notify (bfd_listen_event_e event, |
| 7817 | const bfd_session_t *session); |
| 7818 | |
| 7819 | /** |
| 7820 | * Test BFD session interaction with FIB |
| 7821 | */ |
| 7822 | static int |
| 7823 | fib_test_bfd (void) |
| 7824 | { |
| 7825 | fib_node_index_t fei; |
| 7826 | test_main_t *tm; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7827 | int n_feis, res; |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 7828 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7829 | res = 0; |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 7830 | /* via 10.10.10.1 */ |
| 7831 | ip46_address_t nh_10_10_10_1 = { |
| 7832 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a01), |
| 7833 | }; |
| 7834 | /* via 10.10.10.2 */ |
| 7835 | ip46_address_t nh_10_10_10_2 = { |
| 7836 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a02), |
| 7837 | }; |
| 7838 | /* via 10.10.10.10 */ |
| 7839 | ip46_address_t nh_10_10_10_10 = { |
| 7840 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a0a), |
| 7841 | }; |
| 7842 | n_feis = fib_entry_pool_size(); |
| 7843 | |
| 7844 | tm = &test_main; |
| 7845 | |
| 7846 | /* |
| 7847 | * add interface routes. we'll assume this works. it's tested elsewhere |
| 7848 | */ |
| 7849 | fib_prefix_t pfx_10_10_10_10_s_24 = { |
| 7850 | .fp_len = 24, |
| 7851 | .fp_proto = FIB_PROTOCOL_IP4, |
| 7852 | .fp_addr = nh_10_10_10_10, |
| 7853 | }; |
| 7854 | |
| 7855 | fib_table_entry_update_one_path(0, &pfx_10_10_10_10_s_24, |
| 7856 | FIB_SOURCE_INTERFACE, |
| 7857 | (FIB_ENTRY_FLAG_CONNECTED | |
| 7858 | FIB_ENTRY_FLAG_ATTACHED), |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 7859 | DPO_PROTO_IP4, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 7860 | NULL, |
| 7861 | tm->hw[0]->sw_if_index, |
| 7862 | ~0, // invalid fib index |
| 7863 | 1, // weight |
| 7864 | NULL, |
| 7865 | FIB_ROUTE_PATH_FLAG_NONE); |
| 7866 | |
| 7867 | fib_prefix_t pfx_10_10_10_10_s_32 = { |
| 7868 | .fp_len = 32, |
| 7869 | .fp_proto = FIB_PROTOCOL_IP4, |
| 7870 | .fp_addr = nh_10_10_10_10, |
| 7871 | }; |
| 7872 | fib_table_entry_update_one_path(0, &pfx_10_10_10_10_s_32, |
| 7873 | FIB_SOURCE_INTERFACE, |
| 7874 | (FIB_ENTRY_FLAG_CONNECTED | |
| 7875 | FIB_ENTRY_FLAG_LOCAL), |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 7876 | DPO_PROTO_IP4, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 7877 | NULL, |
| 7878 | tm->hw[0]->sw_if_index, |
| 7879 | ~0, // invalid fib index |
| 7880 | 1, // weight |
| 7881 | NULL, |
| 7882 | FIB_ROUTE_PATH_FLAG_NONE); |
| 7883 | |
| 7884 | /* |
| 7885 | * A BFD session via a neighbour we do not yet know |
| 7886 | */ |
| 7887 | bfd_session_t bfd_10_10_10_1 = { |
| 7888 | .udp = { |
| 7889 | .key = { |
| 7890 | .fib_index = 0, |
| 7891 | .peer_addr = nh_10_10_10_1, |
| 7892 | }, |
| 7893 | }, |
| 7894 | .hop_type = BFD_HOP_TYPE_MULTI, |
| 7895 | .local_state = BFD_STATE_init, |
| 7896 | }; |
| 7897 | |
| 7898 | fib_bfd_notify (BFD_LISTEN_EVENT_CREATE, &bfd_10_10_10_1); |
| 7899 | |
| 7900 | /* |
| 7901 | * A new entry will be created that forwards via the adj |
| 7902 | */ |
| 7903 | adj_index_t ai_10_10_10_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 7904 | VNET_LINK_IP4, |
| 7905 | &nh_10_10_10_1, |
| 7906 | tm->hw[0]->sw_if_index); |
| 7907 | fib_prefix_t pfx_10_10_10_1_s_32 = { |
| 7908 | .fp_addr = nh_10_10_10_1, |
| 7909 | .fp_len = 32, |
| 7910 | .fp_proto = FIB_PROTOCOL_IP4, |
| 7911 | }; |
| 7912 | fib_test_lb_bucket_t adj_o_10_10_10_1 = { |
| 7913 | .type = FT_LB_ADJ, |
| 7914 | .adj = { |
| 7915 | .adj = ai_10_10_10_1, |
| 7916 | }, |
| 7917 | }; |
| 7918 | |
| 7919 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_1_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7920 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7921 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7922 | 1, |
| 7923 | &adj_o_10_10_10_1), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 7924 | "BFD sourced %U via %U", |
| 7925 | format_fib_prefix, &pfx_10_10_10_1_s_32, |
| 7926 | format_ip_adjacency, ai_10_10_10_1, FORMAT_IP_ADJACENCY_NONE); |
| 7927 | |
| 7928 | /* |
| 7929 | * Delete the BFD session. Expect the fib_entry to be removed |
| 7930 | */ |
| 7931 | fib_bfd_notify (BFD_LISTEN_EVENT_DELETE, &bfd_10_10_10_1); |
| 7932 | |
| 7933 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_1_s_32); |
| 7934 | FIB_TEST(FIB_NODE_INDEX_INVALID == fei, |
| 7935 | "BFD sourced %U removed", |
| 7936 | format_fib_prefix, &pfx_10_10_10_1_s_32); |
| 7937 | |
| 7938 | /* |
| 7939 | * Add the BFD source back |
| 7940 | */ |
| 7941 | fib_bfd_notify (BFD_LISTEN_EVENT_CREATE, &bfd_10_10_10_1); |
| 7942 | |
| 7943 | /* |
| 7944 | * source the entry via the ADJ fib |
| 7945 | */ |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 7946 | fei = fib_table_entry_path_add(0, |
| 7947 | &pfx_10_10_10_1_s_32, |
| 7948 | FIB_SOURCE_ADJ, |
| 7949 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 7950 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 7951 | &nh_10_10_10_1, |
| 7952 | tm->hw[0]->sw_if_index, |
| 7953 | ~0, // invalid fib index |
| 7954 | 1, |
| 7955 | NULL, |
| 7956 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 7957 | |
| 7958 | /* |
| 7959 | * Delete the BFD session. Expect the fib_entry to remain |
| 7960 | */ |
| 7961 | fib_bfd_notify (BFD_LISTEN_EVENT_DELETE, &bfd_10_10_10_1); |
| 7962 | |
| 7963 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_1_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 7964 | FIB_TEST(!fib_test_validate_entry(fei, |
| 7965 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 7966 | 1, |
| 7967 | &adj_o_10_10_10_1), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 7968 | "BFD sourced %U remains via %U", |
| 7969 | format_fib_prefix, &pfx_10_10_10_1_s_32, |
| 7970 | format_ip_adjacency, ai_10_10_10_1, FORMAT_IP_ADJACENCY_NONE); |
| 7971 | |
| 7972 | /* |
| 7973 | * Add the BFD source back |
| 7974 | */ |
| 7975 | fib_bfd_notify (BFD_LISTEN_EVENT_CREATE, &bfd_10_10_10_1); |
| 7976 | |
| 7977 | /* |
| 7978 | * Create another ADJ FIB |
| 7979 | */ |
| 7980 | fib_prefix_t pfx_10_10_10_2_s_32 = { |
| 7981 | .fp_addr = nh_10_10_10_2, |
| 7982 | .fp_len = 32, |
| 7983 | .fp_proto = FIB_PROTOCOL_IP4, |
| 7984 | }; |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 7985 | fib_table_entry_path_add(0, |
| 7986 | &pfx_10_10_10_2_s_32, |
| 7987 | FIB_SOURCE_ADJ, |
| 7988 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 7989 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 7990 | &nh_10_10_10_2, |
| 7991 | tm->hw[0]->sw_if_index, |
| 7992 | ~0, // invalid fib index |
| 7993 | 1, |
| 7994 | NULL, |
| 7995 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 7996 | /* |
| 7997 | * A BFD session for the new ADJ FIB |
| 7998 | */ |
| 7999 | bfd_session_t bfd_10_10_10_2 = { |
| 8000 | .udp = { |
| 8001 | .key = { |
| 8002 | .fib_index = 0, |
| 8003 | .peer_addr = nh_10_10_10_2, |
| 8004 | }, |
| 8005 | }, |
| 8006 | .hop_type = BFD_HOP_TYPE_MULTI, |
| 8007 | .local_state = BFD_STATE_init, |
| 8008 | }; |
| 8009 | |
| 8010 | fib_bfd_notify (BFD_LISTEN_EVENT_CREATE, &bfd_10_10_10_2); |
| 8011 | |
| 8012 | /* |
| 8013 | * remove the adj-fib source whilst the session is present |
| 8014 | * then add it back |
| 8015 | */ |
| 8016 | fib_table_entry_delete(0, &pfx_10_10_10_2_s_32, FIB_SOURCE_ADJ); |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 8017 | fib_table_entry_path_add(0, |
| 8018 | &pfx_10_10_10_2_s_32, |
| 8019 | FIB_SOURCE_ADJ, |
| 8020 | FIB_ENTRY_FLAG_ATTACHED, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 8021 | DPO_PROTO_IP4, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 8022 | &nh_10_10_10_2, |
| 8023 | tm->hw[0]->sw_if_index, |
| 8024 | ~0, // invalid fib index |
| 8025 | 1, |
| 8026 | NULL, |
| 8027 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8028 | |
| 8029 | /* |
| 8030 | * Before adding a recursive via the BFD tracked ADJ-FIBs, |
| 8031 | * bring one of the sessions UP, leave the other down |
| 8032 | */ |
| 8033 | bfd_10_10_10_1.local_state = BFD_STATE_up; |
| 8034 | fib_bfd_notify (BFD_LISTEN_EVENT_UPDATE, &bfd_10_10_10_1); |
| 8035 | bfd_10_10_10_2.local_state = BFD_STATE_down; |
| 8036 | fib_bfd_notify (BFD_LISTEN_EVENT_UPDATE, &bfd_10_10_10_2); |
| 8037 | |
| 8038 | /* |
| 8039 | * A recursive prefix via both of the ADJ FIBs |
| 8040 | */ |
| 8041 | fib_prefix_t pfx_200_0_0_0_s_24 = { |
| 8042 | .fp_proto = FIB_PROTOCOL_IP4, |
| 8043 | .fp_len = 32, |
| 8044 | .fp_addr = { |
| 8045 | .ip4.as_u32 = clib_host_to_net_u32(0xc8000000), |
| 8046 | }, |
| 8047 | }; |
| 8048 | const dpo_id_t *dpo_10_10_10_1, *dpo_10_10_10_2; |
| 8049 | |
| 8050 | dpo_10_10_10_1 = |
| 8051 | fib_entry_contribute_ip_forwarding( |
| 8052 | fib_table_lookup_exact_match(0, &pfx_10_10_10_1_s_32)); |
| 8053 | dpo_10_10_10_2 = |
| 8054 | fib_entry_contribute_ip_forwarding( |
| 8055 | fib_table_lookup_exact_match(0, &pfx_10_10_10_2_s_32)); |
| 8056 | |
| 8057 | fib_test_lb_bucket_t lb_o_10_10_10_1 = { |
| 8058 | .type = FT_LB_O_LB, |
| 8059 | .lb = { |
| 8060 | .lb = dpo_10_10_10_1->dpoi_index, |
| 8061 | }, |
| 8062 | }; |
| 8063 | fib_test_lb_bucket_t lb_o_10_10_10_2 = { |
| 8064 | .type = FT_LB_O_LB, |
| 8065 | .lb = { |
| 8066 | .lb = dpo_10_10_10_2->dpoi_index, |
| 8067 | }, |
| 8068 | }; |
| 8069 | |
| 8070 | /* |
| 8071 | * A prefix via the adj-fib that is BFD down => DROP |
| 8072 | */ |
| 8073 | fei = fib_table_entry_path_add(0, |
| 8074 | &pfx_200_0_0_0_s_24, |
| 8075 | FIB_SOURCE_API, |
| 8076 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 8077 | DPO_PROTO_IP4, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8078 | &nh_10_10_10_2, |
| 8079 | ~0, // recursive |
| 8080 | 0, // default fib index |
| 8081 | 1, |
| 8082 | NULL, |
| 8083 | FIB_ROUTE_PATH_FLAG_NONE); |
| 8084 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 8085 | "%U resolves via drop", |
| 8086 | format_fib_prefix, &pfx_200_0_0_0_s_24); |
| 8087 | |
| 8088 | /* |
| 8089 | * add a path via the UP BFD adj-fib. |
| 8090 | * we expect that the DOWN BFD ADJ FIB is not used. |
| 8091 | */ |
| 8092 | fei = fib_table_entry_path_add(0, |
| 8093 | &pfx_200_0_0_0_s_24, |
| 8094 | FIB_SOURCE_API, |
| 8095 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 8096 | DPO_PROTO_IP4, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8097 | &nh_10_10_10_1, |
| 8098 | ~0, // recursive |
| 8099 | 0, // default fib index |
| 8100 | 1, |
| 8101 | NULL, |
| 8102 | FIB_ROUTE_PATH_FLAG_NONE); |
| 8103 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8104 | FIB_TEST(!fib_test_validate_entry(fei, |
| 8105 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8106 | 1, |
| 8107 | &lb_o_10_10_10_1), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8108 | "Recursive %U only UP BFD adj-fibs", |
| 8109 | format_fib_prefix, &pfx_200_0_0_0_s_24); |
| 8110 | |
| 8111 | /* |
| 8112 | * Send a BFD state change to UP - both sessions are now up |
| 8113 | * the recursive prefix should LB over both |
| 8114 | */ |
| 8115 | bfd_10_10_10_2.local_state = BFD_STATE_up; |
| 8116 | fib_bfd_notify (BFD_LISTEN_EVENT_UPDATE, &bfd_10_10_10_2); |
| 8117 | |
| 8118 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8119 | FIB_TEST(!fib_test_validate_entry(fei, |
| 8120 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8121 | 2, |
| 8122 | &lb_o_10_10_10_1, |
| 8123 | &lb_o_10_10_10_2), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8124 | "Recursive %U via both UP BFD adj-fibs", |
| 8125 | format_fib_prefix, &pfx_200_0_0_0_s_24); |
| 8126 | |
| 8127 | /* |
| 8128 | * Send a BFD state change to DOWN |
| 8129 | * the recursive prefix should exclude the down |
| 8130 | */ |
| 8131 | bfd_10_10_10_2.local_state = BFD_STATE_down; |
| 8132 | fib_bfd_notify (BFD_LISTEN_EVENT_UPDATE, &bfd_10_10_10_2); |
| 8133 | |
| 8134 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8135 | FIB_TEST(!fib_test_validate_entry(fei, |
| 8136 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8137 | 1, |
| 8138 | &lb_o_10_10_10_1), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8139 | "Recursive %U via only UP", |
| 8140 | format_fib_prefix, &pfx_200_0_0_0_s_24); |
| 8141 | |
| 8142 | /* |
| 8143 | * Delete the BFD session while it is in the DOWN state. |
| 8144 | * FIB should consider the entry's state as back up |
| 8145 | */ |
| 8146 | fib_bfd_notify (BFD_LISTEN_EVENT_DELETE, &bfd_10_10_10_2); |
| 8147 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8148 | FIB_TEST(!fib_test_validate_entry(fei, |
| 8149 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8150 | 2, |
| 8151 | &lb_o_10_10_10_1, |
| 8152 | &lb_o_10_10_10_2), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8153 | "Recursive %U via both UP BFD adj-fibs post down session delete", |
| 8154 | format_fib_prefix, &pfx_200_0_0_0_s_24); |
| 8155 | |
| 8156 | /* |
| 8157 | * Delete the BFD other session while it is in the UP state. |
| 8158 | */ |
| 8159 | fib_bfd_notify (BFD_LISTEN_EVENT_DELETE, &bfd_10_10_10_1); |
| 8160 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8161 | FIB_TEST(!fib_test_validate_entry(fei, |
| 8162 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8163 | 2, |
| 8164 | &lb_o_10_10_10_1, |
| 8165 | &lb_o_10_10_10_2), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8166 | "Recursive %U via both UP BFD adj-fibs post up session delete", |
| 8167 | format_fib_prefix, &pfx_200_0_0_0_s_24); |
| 8168 | |
| 8169 | /* |
| 8170 | * cleaup |
| 8171 | */ |
| 8172 | fib_table_entry_delete(0, &pfx_200_0_0_0_s_24, FIB_SOURCE_API); |
| 8173 | fib_table_entry_delete(0, &pfx_10_10_10_1_s_32, FIB_SOURCE_ADJ); |
| 8174 | fib_table_entry_delete(0, &pfx_10_10_10_2_s_32, FIB_SOURCE_ADJ); |
| 8175 | |
| 8176 | fib_table_entry_delete(0, &pfx_10_10_10_10_s_32, FIB_SOURCE_INTERFACE); |
| 8177 | fib_table_entry_delete(0, &pfx_10_10_10_10_s_24, FIB_SOURCE_INTERFACE); |
| 8178 | |
| 8179 | adj_unlock(ai_10_10_10_1); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8180 | /* |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8181 | * test no-one left behind |
| 8182 | */ |
| 8183 | FIB_TEST((n_feis == fib_entry_pool_size()), "Entries gone"); |
| 8184 | FIB_TEST(0 == adj_nbr_db_size(), "All adjacencies removed"); |
| 8185 | |
| 8186 | /* |
| 8187 | * Single-hop BFD tests |
| 8188 | */ |
| 8189 | bfd_10_10_10_1.hop_type = BFD_HOP_TYPE_SINGLE; |
| 8190 | bfd_10_10_10_1.udp.key.sw_if_index = tm->hw[0]->sw_if_index; |
| 8191 | |
| 8192 | adj_bfd_notify(BFD_LISTEN_EVENT_CREATE, &bfd_10_10_10_1); |
| 8193 | |
| 8194 | ai_10_10_10_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 8195 | VNET_LINK_IP4, |
| 8196 | &nh_10_10_10_1, |
| 8197 | tm->hw[0]->sw_if_index); |
| 8198 | /* |
| 8199 | * whilst the BFD session is not signalled, the adj is up |
| 8200 | */ |
Neale Ranns | 4faab21 | 2018-07-16 06:12:33 -0700 | [diff] [blame] | 8201 | FIB_TEST(!adj_is_up(ai_10_10_10_1), "Adj state down on uninit session"); |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8202 | |
| 8203 | /* |
| 8204 | * bring the BFD session up |
| 8205 | */ |
| 8206 | bfd_10_10_10_1.local_state = BFD_STATE_up; |
| 8207 | adj_bfd_notify(BFD_LISTEN_EVENT_UPDATE, &bfd_10_10_10_1); |
| 8208 | FIB_TEST(adj_is_up(ai_10_10_10_1), "Adj state up on UP session"); |
| 8209 | |
| 8210 | /* |
| 8211 | * bring the BFD session down |
| 8212 | */ |
| 8213 | bfd_10_10_10_1.local_state = BFD_STATE_down; |
| 8214 | adj_bfd_notify(BFD_LISTEN_EVENT_UPDATE, &bfd_10_10_10_1); |
| 8215 | FIB_TEST(!adj_is_up(ai_10_10_10_1), "Adj state down on DOWN session"); |
| 8216 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8217 | /* |
| 8218 | * add an attached next hop FIB entry via the down adj |
| 8219 | */ |
| 8220 | fib_prefix_t pfx_5_5_5_5_s_32 = { |
| 8221 | .fp_addr = { |
| 8222 | .ip4 = { |
| 8223 | .as_u32 = clib_host_to_net_u32(0x05050505), |
| 8224 | }, |
| 8225 | }, |
| 8226 | .fp_len = 32, |
| 8227 | .fp_proto = FIB_PROTOCOL_IP4, |
| 8228 | }; |
| 8229 | |
| 8230 | fei = fib_table_entry_path_add(0, |
| 8231 | &pfx_5_5_5_5_s_32, |
| 8232 | FIB_SOURCE_CLI, |
| 8233 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 8234 | DPO_PROTO_IP4, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8235 | &nh_10_10_10_1, |
| 8236 | tm->hw[0]->sw_if_index, |
| 8237 | ~0, // invalid fib index |
| 8238 | 1, |
| 8239 | NULL, |
| 8240 | FIB_ROUTE_PATH_FLAG_NONE); |
| 8241 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 8242 | "%U resolves via drop", |
| 8243 | format_fib_prefix, &pfx_5_5_5_5_s_32); |
| 8244 | |
| 8245 | /* |
| 8246 | * Add a path via an ADJ that is up |
| 8247 | */ |
| 8248 | adj_index_t ai_10_10_10_2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 8249 | VNET_LINK_IP4, |
| 8250 | &nh_10_10_10_2, |
| 8251 | tm->hw[0]->sw_if_index); |
| 8252 | |
| 8253 | fib_test_lb_bucket_t adj_o_10_10_10_2 = { |
| 8254 | .type = FT_LB_ADJ, |
| 8255 | .adj = { |
| 8256 | .adj = ai_10_10_10_2, |
| 8257 | }, |
| 8258 | }; |
| 8259 | adj_o_10_10_10_1.adj.adj = ai_10_10_10_1; |
| 8260 | |
| 8261 | fei = fib_table_entry_path_add(0, |
| 8262 | &pfx_5_5_5_5_s_32, |
| 8263 | FIB_SOURCE_CLI, |
| 8264 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 8265 | DPO_PROTO_IP4, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8266 | &nh_10_10_10_2, |
| 8267 | tm->hw[0]->sw_if_index, |
| 8268 | ~0, // invalid fib index |
| 8269 | 1, |
| 8270 | NULL, |
| 8271 | FIB_ROUTE_PATH_FLAG_NONE); |
| 8272 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8273 | FIB_TEST(!fib_test_validate_entry(fei, |
| 8274 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8275 | 1, |
| 8276 | &adj_o_10_10_10_2), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8277 | "BFD sourced %U via %U", |
| 8278 | format_fib_prefix, &pfx_5_5_5_5_s_32, |
| 8279 | format_ip_adjacency, ai_10_10_10_2, FORMAT_IP_ADJACENCY_NONE); |
| 8280 | |
| 8281 | /* |
| 8282 | * Bring up the down session - should now LB |
| 8283 | */ |
| 8284 | bfd_10_10_10_1.local_state = BFD_STATE_up; |
| 8285 | adj_bfd_notify(BFD_LISTEN_EVENT_UPDATE, &bfd_10_10_10_1); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8286 | FIB_TEST(!fib_test_validate_entry(fei, |
| 8287 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8288 | 2, |
| 8289 | &adj_o_10_10_10_1, |
| 8290 | &adj_o_10_10_10_2), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8291 | "BFD sourced %U via noth adjs", |
| 8292 | format_fib_prefix, &pfx_5_5_5_5_s_32); |
| 8293 | |
| 8294 | /* |
| 8295 | * remove the BFD session state from the adj |
| 8296 | */ |
| 8297 | adj_bfd_notify(BFD_LISTEN_EVENT_DELETE, &bfd_10_10_10_1); |
| 8298 | |
| 8299 | /* |
| 8300 | * clean-up |
| 8301 | */ |
| 8302 | fib_table_entry_delete(0, &pfx_5_5_5_5_s_32, FIB_SOURCE_CLI); |
| 8303 | adj_unlock(ai_10_10_10_1); |
| 8304 | adj_unlock(ai_10_10_10_2); |
| 8305 | |
| 8306 | /* |
| 8307 | * test no-one left behind |
| 8308 | */ |
| 8309 | FIB_TEST((n_feis == fib_entry_pool_size()), "Entries gone"); |
| 8310 | FIB_TEST(0 == adj_nbr_db_size(), "All adjacencies removed"); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8311 | |
| 8312 | return (res); |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 8313 | } |
| 8314 | |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 8315 | static int |
| 8316 | lfib_test (void) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8317 | { |
| 8318 | const mpls_label_t deag_label = 50; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8319 | adj_index_t ai_mpls_10_10_10_1; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 8320 | dpo_id_t dpo = DPO_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8321 | const u32 lfib_index = 0; |
| 8322 | const u32 fib_index = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8323 | const dpo_id_t *dpo1; |
| 8324 | fib_node_index_t lfe; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8325 | lookup_dpo_t *lkd; |
| 8326 | int lb_count, res; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8327 | test_main_t *tm; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8328 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8329 | res = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8330 | tm = &test_main; |
| 8331 | lb_count = pool_elts(load_balance_pool); |
| 8332 | |
| 8333 | FIB_TEST((0 == adj_nbr_db_size()), "ADJ DB size is %d", |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8334 | adj_nbr_db_size()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8335 | |
| 8336 | /* |
| 8337 | * MPLS enable an interface so we get the MPLS table created |
| 8338 | */ |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 8339 | mpls_table_create(MPLS_FIB_DEFAULT_TABLE_ID, FIB_SOURCE_API, NULL); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8340 | mpls_sw_interface_enable_disable(&mpls_main, |
| 8341 | tm->hw[0]->sw_if_index, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 8342 | 1, 1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8343 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8344 | ip46_address_t nh_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8345 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a01), |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8346 | }; |
| 8347 | ai_mpls_10_10_10_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 8348 | VNET_LINK_MPLS, |
| 8349 | &nh_10_10_10_1, |
| 8350 | tm->hw[0]->sw_if_index); |
| 8351 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8352 | /* |
| 8353 | * Test the specials stack properly. |
| 8354 | */ |
| 8355 | fib_prefix_t exp_null_v6_pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8356 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 8357 | .fp_eos = MPLS_EOS, |
| 8358 | .fp_label = MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL, |
| 8359 | .fp_payload_proto = DPO_PROTO_IP6, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8360 | }; |
| 8361 | lfe = fib_table_lookup(lfib_index, &exp_null_v6_pfx); |
| 8362 | FIB_TEST((FIB_NODE_INDEX_INVALID != lfe), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8363 | "%U/%U present", |
| 8364 | format_mpls_unicast_label, MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL, |
| 8365 | format_mpls_eos_bit, MPLS_EOS); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8366 | fib_entry_contribute_forwarding(lfe, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8367 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 8368 | &dpo); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8369 | dpo1 = load_balance_get_bucket(dpo.dpoi_index, 0); |
| 8370 | lkd = lookup_dpo_get(dpo1->dpoi_index); |
| 8371 | |
| 8372 | FIB_TEST((fib_index == lkd->lkd_fib_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8373 | "%U/%U is deag in %d %U", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8374 | format_mpls_unicast_label, deag_label, |
| 8375 | format_mpls_eos_bit, MPLS_EOS, |
| 8376 | lkd->lkd_fib_index, |
| 8377 | format_dpo_id, &dpo, 0); |
| 8378 | FIB_TEST((LOOKUP_INPUT_DST_ADDR == lkd->lkd_input), |
| 8379 | "%U/%U is dst deag", |
| 8380 | format_mpls_unicast_label, deag_label, |
| 8381 | format_mpls_eos_bit, MPLS_EOS); |
| 8382 | FIB_TEST((LOOKUP_TABLE_FROM_INPUT_INTERFACE == lkd->lkd_table), |
| 8383 | "%U/%U is lookup in interface's table", |
| 8384 | format_mpls_unicast_label, deag_label, |
| 8385 | format_mpls_eos_bit, MPLS_EOS); |
| 8386 | FIB_TEST((DPO_PROTO_IP6 == lkd->lkd_proto), |
| 8387 | "%U/%U is %U dst deag", |
| 8388 | format_mpls_unicast_label, deag_label, |
| 8389 | format_mpls_eos_bit, MPLS_EOS, |
| 8390 | format_dpo_proto, lkd->lkd_proto); |
| 8391 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8392 | /* |
| 8393 | * A route deag route for EOS |
| 8394 | */ |
| 8395 | fib_prefix_t pfx = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8396 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 8397 | .fp_eos = MPLS_EOS, |
| 8398 | .fp_label = deag_label, |
| 8399 | .fp_payload_proto = DPO_PROTO_IP4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8400 | }; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8401 | mpls_disp_dpo_t *mdd; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8402 | lfe = fib_table_entry_path_add(lfib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8403 | &pfx, |
| 8404 | FIB_SOURCE_CLI, |
| 8405 | FIB_ENTRY_FLAG_NONE, |
| 8406 | DPO_PROTO_IP4, |
| 8407 | &zero_addr, |
| 8408 | ~0, |
| 8409 | fib_index, |
| 8410 | 1, |
| 8411 | NULL, |
| 8412 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8413 | |
| 8414 | FIB_TEST((lfe == fib_table_lookup(lfib_index, &pfx)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8415 | "%U/%U present", |
| 8416 | format_mpls_unicast_label, deag_label, |
| 8417 | format_mpls_eos_bit, MPLS_EOS); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8418 | |
| 8419 | fib_entry_contribute_forwarding(lfe, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8420 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 8421 | &dpo); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8422 | dpo1 = load_balance_get_bucket(dpo.dpoi_index, 0); |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 8423 | mdd = mpls_disp_dpo_get(dpo1->dpoi_index); |
| 8424 | |
| 8425 | FIB_TEST((FIB_MPLS_LSP_MODE_PIPE == mdd->mdd_mode), |
| 8426 | "%U/%U disp is pipe mode", |
| 8427 | format_mpls_unicast_label, deag_label, |
| 8428 | format_mpls_eos_bit, MPLS_EOS); |
| 8429 | |
| 8430 | lkd = lookup_dpo_get(mdd->mdd_dpo.dpoi_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8431 | |
| 8432 | FIB_TEST((fib_index == lkd->lkd_fib_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8433 | "%U/%U is deag in %d %U", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8434 | format_mpls_unicast_label, deag_label, |
| 8435 | format_mpls_eos_bit, MPLS_EOS, |
| 8436 | lkd->lkd_fib_index, |
| 8437 | format_dpo_id, &dpo, 0); |
| 8438 | FIB_TEST((LOOKUP_INPUT_DST_ADDR == lkd->lkd_input), |
| 8439 | "%U/%U is dst deag", |
| 8440 | format_mpls_unicast_label, deag_label, |
| 8441 | format_mpls_eos_bit, MPLS_EOS); |
| 8442 | FIB_TEST((DPO_PROTO_IP4 == lkd->lkd_proto), |
| 8443 | "%U/%U is %U dst deag", |
| 8444 | format_mpls_unicast_label, deag_label, |
| 8445 | format_mpls_eos_bit, MPLS_EOS, |
| 8446 | format_dpo_proto, lkd->lkd_proto); |
| 8447 | |
| 8448 | fib_table_entry_delete_index(lfe, FIB_SOURCE_CLI); |
| 8449 | |
| 8450 | FIB_TEST((FIB_NODE_INDEX_INVALID == fib_table_lookup(lfib_index, |
| 8451 | &pfx)), |
| 8452 | "%U/%U not present", |
| 8453 | format_mpls_unicast_label, deag_label, |
| 8454 | format_mpls_eos_bit, MPLS_EOS); |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 8455 | dpo_reset(&dpo); |
| 8456 | |
| 8457 | /* |
| 8458 | * A route deag route for EOS with LSP mode uniform |
| 8459 | */ |
| 8460 | fib_mpls_label_t *l_pops = NULL, l_pop = { |
| 8461 | .fml_value = MPLS_LABEL_POP, |
| 8462 | .fml_mode = FIB_MPLS_LSP_MODE_UNIFORM, |
| 8463 | }; |
| 8464 | vec_add1(l_pops, l_pop); |
| 8465 | lfe = fib_table_entry_path_add(lfib_index, |
| 8466 | &pfx, |
| 8467 | FIB_SOURCE_CLI, |
| 8468 | FIB_ENTRY_FLAG_NONE, |
| 8469 | DPO_PROTO_IP4, |
| 8470 | &zero_addr, |
| 8471 | ~0, |
| 8472 | fib_index, |
| 8473 | 1, |
| 8474 | l_pops, |
| 8475 | FIB_ROUTE_PATH_FLAG_NONE); |
| 8476 | |
| 8477 | FIB_TEST((lfe == fib_table_lookup(lfib_index, &pfx)), |
| 8478 | "%U/%U present", |
| 8479 | format_mpls_unicast_label, deag_label, |
| 8480 | format_mpls_eos_bit, MPLS_EOS); |
| 8481 | |
| 8482 | fib_entry_contribute_forwarding(lfe, |
| 8483 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 8484 | &dpo); |
| 8485 | dpo1 = load_balance_get_bucket(dpo.dpoi_index, 0); |
| 8486 | mdd = mpls_disp_dpo_get(dpo1->dpoi_index); |
| 8487 | |
| 8488 | FIB_TEST((FIB_MPLS_LSP_MODE_UNIFORM == mdd->mdd_mode), |
| 8489 | "%U/%U disp is uniform mode", |
| 8490 | format_mpls_unicast_label, deag_label, |
| 8491 | format_mpls_eos_bit, MPLS_EOS); |
| 8492 | |
| 8493 | lkd = lookup_dpo_get(mdd->mdd_dpo.dpoi_index); |
| 8494 | |
| 8495 | FIB_TEST((fib_index == lkd->lkd_fib_index), |
| 8496 | "%U/%U is deag in %d %U", |
| 8497 | format_mpls_unicast_label, deag_label, |
| 8498 | format_mpls_eos_bit, MPLS_EOS, |
| 8499 | lkd->lkd_fib_index, |
| 8500 | format_dpo_id, &dpo, 0); |
| 8501 | FIB_TEST((LOOKUP_INPUT_DST_ADDR == lkd->lkd_input), |
| 8502 | "%U/%U is dst deag", |
| 8503 | format_mpls_unicast_label, deag_label, |
| 8504 | format_mpls_eos_bit, MPLS_EOS); |
| 8505 | FIB_TEST((DPO_PROTO_IP4 == lkd->lkd_proto), |
| 8506 | "%U/%U is %U dst deag", |
| 8507 | format_mpls_unicast_label, deag_label, |
| 8508 | format_mpls_eos_bit, MPLS_EOS, |
| 8509 | format_dpo_proto, lkd->lkd_proto); |
| 8510 | |
| 8511 | fib_table_entry_delete_index(lfe, FIB_SOURCE_CLI); |
| 8512 | |
| 8513 | FIB_TEST((FIB_NODE_INDEX_INVALID == fib_table_lookup(lfib_index, |
| 8514 | &pfx)), |
| 8515 | "%U/%U not present", |
| 8516 | format_mpls_unicast_label, deag_label, |
| 8517 | format_mpls_eos_bit, MPLS_EOS); |
| 8518 | dpo_reset(&dpo); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8519 | |
| 8520 | /* |
| 8521 | * A route deag route for non-EOS |
| 8522 | */ |
| 8523 | pfx.fp_eos = MPLS_NON_EOS; |
| 8524 | lfe = fib_table_entry_path_add(lfib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8525 | &pfx, |
| 8526 | FIB_SOURCE_CLI, |
| 8527 | FIB_ENTRY_FLAG_NONE, |
| 8528 | DPO_PROTO_IP4, |
| 8529 | &zero_addr, |
| 8530 | ~0, |
| 8531 | lfib_index, |
| 8532 | 1, |
| 8533 | NULL, |
| 8534 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8535 | |
| 8536 | FIB_TEST((lfe == fib_table_lookup(lfib_index, &pfx)), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8537 | "%U/%U present", |
| 8538 | format_mpls_unicast_label, deag_label, |
| 8539 | format_mpls_eos_bit, MPLS_NON_EOS); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8540 | |
| 8541 | fib_entry_contribute_forwarding(lfe, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8542 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 8543 | &dpo); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8544 | dpo1 = load_balance_get_bucket(dpo.dpoi_index, 0); |
| 8545 | lkd = lookup_dpo_get(dpo1->dpoi_index); |
| 8546 | |
| 8547 | FIB_TEST((fib_index == lkd->lkd_fib_index), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8548 | "%U/%U is deag in %d %U", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8549 | format_mpls_unicast_label, deag_label, |
| 8550 | format_mpls_eos_bit, MPLS_NON_EOS, |
| 8551 | lkd->lkd_fib_index, |
| 8552 | format_dpo_id, &dpo, 0); |
| 8553 | FIB_TEST((LOOKUP_INPUT_DST_ADDR == lkd->lkd_input), |
| 8554 | "%U/%U is dst deag", |
| 8555 | format_mpls_unicast_label, deag_label, |
| 8556 | format_mpls_eos_bit, MPLS_NON_EOS); |
| 8557 | |
| 8558 | FIB_TEST((DPO_PROTO_MPLS == lkd->lkd_proto), |
| 8559 | "%U/%U is %U dst deag", |
| 8560 | format_mpls_unicast_label, deag_label, |
| 8561 | format_mpls_eos_bit, MPLS_NON_EOS, |
| 8562 | format_dpo_proto, lkd->lkd_proto); |
| 8563 | |
| 8564 | fib_table_entry_delete_index(lfe, FIB_SOURCE_CLI); |
| 8565 | |
| 8566 | FIB_TEST((FIB_NODE_INDEX_INVALID == fib_table_lookup(lfib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8567 | &pfx)), |
| 8568 | "%U/%U not present", |
| 8569 | format_mpls_unicast_label, deag_label, |
| 8570 | format_mpls_eos_bit, MPLS_EOS); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8571 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8572 | dpo_reset(&dpo); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8573 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8574 | /* |
| 8575 | * An MPLS x-connect |
| 8576 | */ |
| 8577 | fib_prefix_t pfx_1200 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8578 | .fp_len = 21, |
| 8579 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 8580 | .fp_label = 1200, |
| 8581 | .fp_eos = MPLS_NON_EOS, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8582 | }; |
| 8583 | fib_test_lb_bucket_t neos_o_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8584 | .type = FT_LB_LABEL_STACK_O_ADJ, |
| 8585 | .label_stack_o_adj = { |
| 8586 | .adj = ai_mpls_10_10_10_1, |
| 8587 | .label_stack_size = 4, |
| 8588 | .label_stack = { |
| 8589 | 200, 300, 400, 500, |
| 8590 | }, |
| 8591 | .eos = MPLS_NON_EOS, |
| 8592 | }, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8593 | }; |
| 8594 | dpo_id_t neos_1200 = DPO_INVALID; |
| 8595 | dpo_id_t ip_1200 = DPO_INVALID; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 8596 | fib_mpls_label_t *l200 = NULL; |
| 8597 | u32 ii; |
| 8598 | for (ii = 0; ii < 4; ii++) |
| 8599 | { |
| 8600 | fib_mpls_label_t fml = { |
| 8601 | .fml_value = 200 + (ii * 100), |
| 8602 | }; |
| 8603 | vec_add1(l200, fml); |
| 8604 | }; |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8605 | |
| 8606 | lfe = fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8607 | &pfx_1200, |
| 8608 | FIB_SOURCE_API, |
| 8609 | FIB_ENTRY_FLAG_NONE, |
| 8610 | DPO_PROTO_IP4, |
| 8611 | &nh_10_10_10_1, |
| 8612 | tm->hw[0]->sw_if_index, |
| 8613 | ~0, // invalid fib index |
| 8614 | 1, |
| 8615 | l200, |
| 8616 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8617 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8618 | FIB_TEST(!fib_test_validate_entry(lfe, |
| 8619 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 8620 | 1, |
| 8621 | &neos_o_10_10_10_1), |
| 8622 | "1200/0 LB 1 buckets via: " |
| 8623 | "adj 10.10.11.1"); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8624 | |
| 8625 | /* |
| 8626 | * A recursive route via the MPLS x-connect |
| 8627 | */ |
| 8628 | fib_prefix_t pfx_2_2_2_3_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8629 | .fp_len = 32, |
| 8630 | .fp_proto = FIB_PROTOCOL_IP4, |
| 8631 | .fp_addr = { |
| 8632 | .ip4.as_u32 = clib_host_to_net_u32(0x02020203), |
| 8633 | }, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8634 | }; |
| 8635 | fib_route_path_t *rpaths = NULL, rpath = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 8636 | .frp_proto = DPO_PROTO_MPLS, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8637 | .frp_local_label = 1200, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8638 | .frp_eos = MPLS_NON_EOS, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8639 | .frp_sw_if_index = ~0, // recurive |
| 8640 | .frp_fib_index = 0, // Default MPLS fib |
| 8641 | .frp_weight = 1, |
| 8642 | .frp_flags = FIB_ROUTE_PATH_FLAG_NONE, |
| 8643 | .frp_label_stack = NULL, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8644 | }; |
| 8645 | vec_add1(rpaths, rpath); |
| 8646 | |
| 8647 | fib_table_entry_path_add2(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8648 | &pfx_2_2_2_3_s_32, |
| 8649 | FIB_SOURCE_API, |
| 8650 | FIB_ENTRY_FLAG_NONE, |
| 8651 | rpaths); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8652 | |
| 8653 | /* |
| 8654 | * A labelled recursive route via the MPLS x-connect |
| 8655 | */ |
| 8656 | fib_prefix_t pfx_2_2_2_4_s_32 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8657 | .fp_len = 32, |
| 8658 | .fp_proto = FIB_PROTOCOL_IP4, |
| 8659 | .fp_addr = { |
| 8660 | .ip4.as_u32 = clib_host_to_net_u32(0x02020204), |
| 8661 | }, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8662 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 8663 | fib_mpls_label_t *l999 = NULL, fml_999 = { |
| 8664 | .fml_value = 999, |
| 8665 | }; |
| 8666 | vec_add1(l999, fml_999); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8667 | rpaths[0].frp_label_stack = l999, |
| 8668 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8669 | fib_table_entry_path_add2(fib_index, |
| 8670 | &pfx_2_2_2_4_s_32, |
| 8671 | FIB_SOURCE_API, |
| 8672 | FIB_ENTRY_FLAG_NONE, |
| 8673 | rpaths); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8674 | |
| 8675 | fib_entry_contribute_forwarding(fib_table_lookup(fib_index, &pfx_1200), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8676 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8677 | &ip_1200); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8678 | fib_entry_contribute_forwarding(fib_table_lookup(fib_index, &pfx_1200), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8679 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 8680 | &neos_1200); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8681 | |
| 8682 | fib_test_lb_bucket_t ip_o_1200 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8683 | .type = FT_LB_O_LB, |
| 8684 | .lb = { |
| 8685 | .lb = ip_1200.dpoi_index, |
| 8686 | }, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8687 | }; |
| 8688 | fib_test_lb_bucket_t mpls_o_1200 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8689 | .type = FT_LB_LABEL_O_LB, |
| 8690 | .label_o_lb = { |
| 8691 | .lb = neos_1200.dpoi_index, |
| 8692 | .label = 999, |
| 8693 | .eos = MPLS_EOS, |
| 8694 | }, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8695 | }; |
| 8696 | |
| 8697 | lfe = fib_table_lookup(fib_index, &pfx_2_2_2_3_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8698 | FIB_TEST(!fib_test_validate_entry(lfe, |
| 8699 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8700 | 1, |
| 8701 | &ip_o_1200), |
| 8702 | "2.2.2.2.3/32 LB 1 buckets via: label 1200 EOS"); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8703 | lfe = fib_table_lookup(fib_index, &pfx_2_2_2_4_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8704 | FIB_TEST(!fib_test_validate_entry(lfe, |
| 8705 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8706 | 1, |
| 8707 | &mpls_o_1200), |
| 8708 | "2.2.2.2.4/32 LB 1 buckets via: label 1200 non-EOS"); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8709 | |
| 8710 | fib_table_entry_delete(fib_index, &pfx_1200, FIB_SOURCE_API); |
| 8711 | fib_table_entry_delete(fib_index, &pfx_2_2_2_3_s_32, FIB_SOURCE_API); |
| 8712 | fib_table_entry_delete(fib_index, &pfx_2_2_2_4_s_32, FIB_SOURCE_API); |
| 8713 | |
| 8714 | dpo_reset(&neos_1200); |
| 8715 | dpo_reset(&ip_1200); |
| 8716 | |
| 8717 | /* |
| 8718 | * A recursive via a label that does not exist |
| 8719 | */ |
| 8720 | fib_test_lb_bucket_t bucket_drop = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8721 | .type = FT_LB_DROP, |
| 8722 | .special = { |
| 8723 | .adj = DPO_PROTO_IP4, |
| 8724 | }, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 8725 | }; |
| 8726 | fib_test_lb_bucket_t mpls_bucket_drop = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8727 | .type = FT_LB_DROP, |
| 8728 | .special = { |
| 8729 | .adj = DPO_PROTO_MPLS, |
| 8730 | }, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8731 | }; |
| 8732 | |
| 8733 | rpaths[0].frp_label_stack = NULL; |
| 8734 | lfe = fib_table_entry_path_add2(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8735 | &pfx_2_2_2_4_s_32, |
| 8736 | FIB_SOURCE_API, |
| 8737 | FIB_ENTRY_FLAG_NONE, |
| 8738 | rpaths); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8739 | |
| 8740 | fib_entry_contribute_forwarding(fib_table_lookup(fib_index, &pfx_1200), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8741 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8742 | &ip_1200); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8743 | ip_o_1200.lb.lb = ip_1200.dpoi_index; |
| 8744 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8745 | FIB_TEST(!fib_test_validate_entry(lfe, |
| 8746 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8747 | 1, |
| 8748 | &bucket_drop), |
| 8749 | "2.2.2.2.4/32 LB 1 buckets via: drop"); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8750 | lfe = fib_table_lookup(fib_index, &pfx_1200); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8751 | FIB_TEST(!fib_test_validate_entry(lfe, |
| 8752 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 8753 | 1, |
| 8754 | &bucket_drop), |
| 8755 | "1200/neos LB 1 buckets via: ip4-DROP"); |
| 8756 | FIB_TEST(!fib_test_validate_entry(lfe, |
| 8757 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
| 8758 | 1, |
| 8759 | &mpls_bucket_drop), |
| 8760 | "1200/neos LB 1 buckets via: mpls-DROP"); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8761 | |
| 8762 | fib_table_entry_delete(fib_index, &pfx_2_2_2_4_s_32, FIB_SOURCE_API); |
| 8763 | |
| 8764 | dpo_reset(&ip_1200); |
| 8765 | |
| 8766 | /* |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8767 | * An rx-interface route. |
| 8768 | * like the tail of an mcast LSP |
| 8769 | */ |
| 8770 | dpo_id_t idpo = DPO_INVALID; |
| 8771 | |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 8772 | interface_rx_dpo_add_or_lock(DPO_PROTO_IP4, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8773 | tm->hw[0]->sw_if_index, |
| 8774 | &idpo); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8775 | |
| 8776 | fib_prefix_t pfx_2500 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8777 | .fp_len = 21, |
| 8778 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 8779 | .fp_label = 2500, |
| 8780 | .fp_eos = MPLS_EOS, |
| 8781 | .fp_payload_proto = DPO_PROTO_IP4, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8782 | }; |
| 8783 | fib_test_lb_bucket_t rx_intf_0 = { |
| 8784 | .type = FT_LB_INTF, |
| 8785 | .adj = { |
| 8786 | .adj = idpo.dpoi_index, |
| 8787 | }, |
| 8788 | }; |
| 8789 | |
| 8790 | lfe = fib_table_entry_update_one_path(fib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8791 | &pfx_2500, |
| 8792 | FIB_SOURCE_API, |
| 8793 | FIB_ENTRY_FLAG_NONE, |
| 8794 | DPO_PROTO_IP4, |
| 8795 | NULL, |
| 8796 | tm->hw[0]->sw_if_index, |
| 8797 | ~0, // invalid fib index |
| 8798 | 0, |
| 8799 | NULL, |
| 8800 | FIB_ROUTE_PATH_INTF_RX); |
| 8801 | FIB_TEST(!fib_test_validate_entry(lfe, |
| 8802 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 8803 | 1, |
| 8804 | &rx_intf_0), |
| 8805 | "2500 rx-interface 0"); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8806 | fib_table_entry_delete(fib_index, &pfx_2500, FIB_SOURCE_API); |
| 8807 | |
| 8808 | /* |
| 8809 | * An MPLS mulicast entry |
| 8810 | */ |
| 8811 | fib_prefix_t pfx_3500 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8812 | .fp_len = 21, |
| 8813 | .fp_proto = FIB_PROTOCOL_MPLS, |
| 8814 | .fp_label = 3500, |
| 8815 | .fp_eos = MPLS_EOS, |
| 8816 | .fp_payload_proto = DPO_PROTO_IP4, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8817 | }; |
| 8818 | fib_test_rep_bucket_t mc_0 = { |
| 8819 | .type = FT_REP_LABEL_O_ADJ, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8820 | .label_o_adj = { |
| 8821 | .adj = ai_mpls_10_10_10_1, |
| 8822 | .label = 3300, |
| 8823 | .eos = MPLS_EOS, |
| 8824 | }, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8825 | }; |
| 8826 | fib_test_rep_bucket_t mc_intf_0 = { |
| 8827 | .type = FT_REP_INTF, |
| 8828 | .adj = { |
| 8829 | .adj = idpo.dpoi_index, |
| 8830 | }, |
| 8831 | }; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 8832 | fib_mpls_label_t *l3300 = NULL, fml_3300 = { |
| 8833 | .fml_value = 3300, |
| 8834 | }; |
| 8835 | vec_add1(l3300, fml_3300); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8836 | |
| 8837 | lfe = fib_table_entry_update_one_path(lfib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8838 | &pfx_3500, |
| 8839 | FIB_SOURCE_API, |
| 8840 | FIB_ENTRY_FLAG_MULTICAST, |
| 8841 | DPO_PROTO_IP4, |
| 8842 | &nh_10_10_10_1, |
| 8843 | tm->hw[0]->sw_if_index, |
| 8844 | ~0, // invalid fib index |
| 8845 | 1, |
| 8846 | l3300, |
| 8847 | FIB_ROUTE_PATH_FLAG_NONE); |
| 8848 | FIB_TEST(!fib_test_validate_entry(lfe, |
| 8849 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 8850 | 1, |
| 8851 | &mc_0), |
| 8852 | "3500 via replicate over 10.10.10.1"); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8853 | |
| 8854 | /* |
| 8855 | * MPLS Bud-node. Add a replication via an interface-receieve path |
| 8856 | */ |
| 8857 | lfe = fib_table_entry_path_add(lfib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8858 | &pfx_3500, |
| 8859 | FIB_SOURCE_API, |
| 8860 | FIB_ENTRY_FLAG_MULTICAST, |
| 8861 | DPO_PROTO_IP4, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8862 | NULL, |
| 8863 | tm->hw[0]->sw_if_index, |
| 8864 | ~0, // invalid fib index |
| 8865 | 0, |
| 8866 | NULL, |
| 8867 | FIB_ROUTE_PATH_INTF_RX); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8868 | FIB_TEST(!fib_test_validate_entry(lfe, |
| 8869 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 8870 | 2, |
| 8871 | &mc_0, |
| 8872 | &mc_intf_0), |
| 8873 | "3500 via replicate over 10.10.10.1 and interface-rx"); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8874 | |
| 8875 | /* |
| 8876 | * Add a replication via an interface-free for-us path |
| 8877 | */ |
| 8878 | fib_test_rep_bucket_t mc_disp = { |
| 8879 | .type = FT_REP_DISP_MFIB_LOOKUP, |
| 8880 | .adj = { |
| 8881 | .adj = idpo.dpoi_index, |
| 8882 | }, |
| 8883 | }; |
| 8884 | lfe = fib_table_entry_path_add(lfib_index, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8885 | &pfx_3500, |
| 8886 | FIB_SOURCE_API, |
| 8887 | FIB_ENTRY_FLAG_MULTICAST, |
| 8888 | DPO_PROTO_IP4, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8889 | NULL, |
| 8890 | 5, // rpf-id |
| 8891 | 0, // default table |
| 8892 | 0, |
| 8893 | NULL, |
| 8894 | FIB_ROUTE_PATH_RPF_ID); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8895 | FIB_TEST(!fib_test_validate_entry(lfe, |
| 8896 | FIB_FORW_CHAIN_TYPE_MPLS_EOS, |
| 8897 | 3, |
| 8898 | &mc_0, |
| 8899 | &mc_disp, |
| 8900 | &mc_intf_0), |
| 8901 | "3500 via replicate over 10.10.10.1 and interface-rx"); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8902 | |
| 8903 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8904 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 8905 | fib_table_entry_delete(fib_index, &pfx_3500, FIB_SOURCE_API); |
| 8906 | dpo_reset(&idpo); |
| 8907 | |
| 8908 | /* |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8909 | * cleanup |
| 8910 | */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8911 | mpls_sw_interface_enable_disable(&mpls_main, |
| 8912 | tm->hw[0]->sw_if_index, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 8913 | 0, 1); |
| 8914 | mpls_table_delete(MPLS_FIB_DEFAULT_TABLE_ID, FIB_SOURCE_API); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8915 | |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 8916 | FIB_TEST(0 == pool_elts(mpls_disp_dpo_pool), |
| 8917 | "mpls_disp_dpo resources freed %d of %d", |
| 8918 | 0, pool_elts(mpls_disp_dpo_pool)); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8919 | FIB_TEST(lb_count == pool_elts(load_balance_pool), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8920 | "Load-balance resources freed %d of %d", |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 8921 | lb_count, pool_elts(load_balance_pool)); |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 8922 | FIB_TEST(0 == pool_elts(interface_rx_dpo_pool), |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8923 | "interface_rx_dpo resources freed %d of %d", |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 8924 | 0, pool_elts(interface_rx_dpo_pool)); |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 8925 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8926 | return (res); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 8927 | } |
| 8928 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8929 | static int |
| 8930 | fib_test_inherit (void) |
| 8931 | { |
| 8932 | fib_node_index_t fei; |
| 8933 | test_main_t *tm; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8934 | int n_feis, res; |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8935 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8936 | res = 0; |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8937 | n_feis = fib_entry_pool_size(); |
| 8938 | tm = &test_main; |
| 8939 | |
| 8940 | const ip46_address_t nh_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8941 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a01), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8942 | }; |
| 8943 | const ip46_address_t nh_10_10_10_2 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8944 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a02), |
| 8945 | }; |
| 8946 | const ip46_address_t nh_10_10_10_3 = { |
| 8947 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a03), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8948 | }; |
| 8949 | const ip46_address_t nh_10_10_10_16 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8950 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a10), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8951 | }; |
| 8952 | const ip46_address_t nh_10_10_10_20 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8953 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a14), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8954 | }; |
| 8955 | const ip46_address_t nh_10_10_10_21 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8956 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a15), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8957 | }; |
| 8958 | const ip46_address_t nh_10_10_10_22 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8959 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a16), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8960 | }; |
| 8961 | const ip46_address_t nh_10_10_10_255 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8962 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0aff), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8963 | }; |
| 8964 | const ip46_address_t nh_10_10_10_0 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8965 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0a00), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8966 | }; |
| 8967 | const ip46_address_t nh_10_10_0_0 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8968 | .ip4.as_u32 = clib_host_to_net_u32(0x0a0a0000), |
| 8969 | }; |
| 8970 | const ip46_address_t nh_11_11_11_11 = { |
| 8971 | .ip4.as_u32 = clib_host_to_net_u32(0x0b0b0b0b), |
| 8972 | }; |
| 8973 | const ip46_address_t nh_11_11_11_0 = { |
| 8974 | .ip4.as_u32 = clib_host_to_net_u32(0x0b0b0b00), |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8975 | }; |
| 8976 | |
| 8977 | /* |
| 8978 | * prefixes at the base of a sub-tree |
| 8979 | */ |
| 8980 | const fib_prefix_t pfx_10_10_10_21_s_32 = { |
| 8981 | .fp_len = 32, |
| 8982 | .fp_proto = FIB_PROTOCOL_IP4, |
| 8983 | .fp_addr = nh_10_10_10_21, |
| 8984 | }; |
| 8985 | const fib_prefix_t pfx_10_10_10_22_s_32 = { |
| 8986 | .fp_len = 32, |
| 8987 | .fp_proto = FIB_PROTOCOL_IP4, |
| 8988 | .fp_addr = nh_10_10_10_22, |
| 8989 | }; |
| 8990 | const fib_prefix_t pfx_10_10_10_255_s_32 = { |
| 8991 | .fp_len = 32, |
| 8992 | .fp_proto = FIB_PROTOCOL_IP4, |
| 8993 | .fp_addr = nh_10_10_10_255, |
| 8994 | }; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8995 | const u32 N_PLS = fib_path_list_pool_size(); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 8996 | |
| 8997 | fib_table_entry_special_add(0, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 8998 | &pfx_10_10_10_21_s_32, |
| 8999 | FIB_SOURCE_CLI, |
| 9000 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9001 | fib_table_entry_special_add(0, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9002 | &pfx_10_10_10_22_s_32, |
| 9003 | FIB_SOURCE_CLI, |
| 9004 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9005 | fib_table_entry_special_add(0, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9006 | &pfx_10_10_10_255_s_32, |
| 9007 | FIB_SOURCE_CLI, |
| 9008 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9009 | |
| 9010 | /* |
| 9011 | * source an entry that pushes its state down the sub-tree |
| 9012 | */ |
| 9013 | const fib_prefix_t pfx_10_10_10_16_s_28 = { |
| 9014 | .fp_len = 28, |
| 9015 | .fp_proto = FIB_PROTOCOL_IP4, |
| 9016 | .fp_addr = nh_10_10_10_16, |
| 9017 | }; |
| 9018 | fib_table_entry_update_one_path(0, |
| 9019 | &pfx_10_10_10_16_s_28, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9020 | FIB_SOURCE_API, |
| 9021 | FIB_ENTRY_FLAG_COVERED_INHERIT, |
| 9022 | DPO_PROTO_IP4, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9023 | &nh_10_10_10_1, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9024 | tm->hw[0]->sw_if_index, |
| 9025 | ~0, |
| 9026 | 1, |
| 9027 | NULL, |
| 9028 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9029 | |
| 9030 | /* |
| 9031 | * this covering entry and all those below it should have |
| 9032 | * the same forwarding information. |
| 9033 | */ |
| 9034 | adj_index_t ai_10_10_10_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 9035 | VNET_LINK_IP4, |
| 9036 | &nh_10_10_10_1, |
| 9037 | tm->hw[0]->sw_if_index); |
| 9038 | fib_test_lb_bucket_t adj_o_10_10_10_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9039 | .type = FT_LB_ADJ, |
| 9040 | .adj = { |
| 9041 | .adj = ai_10_10_10_1, |
| 9042 | }, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9043 | }; |
| 9044 | |
| 9045 | fei = fib_table_lookup(0, &pfx_10_10_10_16_s_28); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9046 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9047 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9048 | 1, |
| 9049 | &adj_o_10_10_10_1), |
| 9050 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9051 | format_fib_prefix, &pfx_10_10_10_16_s_28); |
| 9052 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9053 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9054 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9055 | 1, |
| 9056 | &adj_o_10_10_10_1), |
| 9057 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9058 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9059 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_22_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9060 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9061 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9062 | 1, |
| 9063 | &adj_o_10_10_10_1), |
| 9064 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9065 | format_fib_prefix, &pfx_10_10_10_22_s_32); |
| 9066 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_255_s_32); |
| 9067 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 9068 | "%U resolves via drop", |
| 9069 | format_fib_prefix, &pfx_10_10_10_255_s_32); |
| 9070 | |
| 9071 | /* |
| 9072 | * remove the inherting cover - covereds go back to drop |
| 9073 | */ |
| 9074 | fib_table_entry_delete(0, &pfx_10_10_10_16_s_28, FIB_SOURCE_API); |
| 9075 | |
| 9076 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
| 9077 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 9078 | "%U resolves via drop", |
| 9079 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9080 | |
| 9081 | /* |
| 9082 | * source an entry that pushes its state down the sub-tree |
| 9083 | */ |
| 9084 | const fib_prefix_t pfx_10_10_10_0_s_24 = { |
| 9085 | .fp_len = 24, |
| 9086 | .fp_proto = FIB_PROTOCOL_IP4, |
| 9087 | .fp_addr = nh_10_10_10_0, |
| 9088 | }; |
| 9089 | fib_table_entry_update_one_path(0, |
| 9090 | &pfx_10_10_10_0_s_24, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9091 | FIB_SOURCE_API, |
| 9092 | FIB_ENTRY_FLAG_COVERED_INHERIT, |
| 9093 | DPO_PROTO_IP4, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9094 | &nh_10_10_10_1, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9095 | tm->hw[0]->sw_if_index, |
| 9096 | ~0, |
| 9097 | 1, |
| 9098 | NULL, |
| 9099 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9100 | |
| 9101 | /* |
| 9102 | * whole sub-tree now covered |
| 9103 | */ |
| 9104 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_0_s_24); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9105 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9106 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9107 | 1, |
| 9108 | &adj_o_10_10_10_1), |
| 9109 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9110 | format_fib_prefix, &pfx_10_10_10_0_s_24); |
| 9111 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9112 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9113 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9114 | 1, |
| 9115 | &adj_o_10_10_10_1), |
| 9116 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9117 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9118 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_22_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9119 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9120 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9121 | 1, |
| 9122 | &adj_o_10_10_10_1), |
| 9123 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9124 | format_fib_prefix, &pfx_10_10_10_22_s_32); |
| 9125 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_255_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9126 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9127 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9128 | 1, |
| 9129 | &adj_o_10_10_10_1), |
| 9130 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9131 | format_fib_prefix, &pfx_10_10_10_255_s_32); |
| 9132 | |
| 9133 | /* |
| 9134 | * insert a more specific into the sub-tree - expect inheritance |
| 9135 | * this one is directly covered by the root |
| 9136 | */ |
| 9137 | fib_table_entry_special_add(0, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9138 | &pfx_10_10_10_16_s_28, |
| 9139 | FIB_SOURCE_CLI, |
| 9140 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9141 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_16_s_28); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9142 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9143 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9144 | 1, |
| 9145 | &adj_o_10_10_10_1), |
| 9146 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9147 | format_fib_prefix, &pfx_10_10_10_16_s_28); |
| 9148 | |
| 9149 | /* |
| 9150 | * insert a more specific into the sub-tree - expect inheritance |
| 9151 | * this one is indirectly covered by the root |
| 9152 | */ |
| 9153 | const fib_prefix_t pfx_10_10_10_20_s_30 = { |
| 9154 | .fp_len = 30, |
| 9155 | .fp_proto = FIB_PROTOCOL_IP4, |
| 9156 | .fp_addr = nh_10_10_10_20, |
| 9157 | }; |
| 9158 | fib_table_entry_special_add(0, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9159 | &pfx_10_10_10_20_s_30, |
| 9160 | FIB_SOURCE_CLI, |
| 9161 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9162 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_20_s_30); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9163 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9164 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9165 | 1, |
| 9166 | &adj_o_10_10_10_1), |
| 9167 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9168 | format_fib_prefix, &pfx_10_10_10_20_s_30); |
| 9169 | |
| 9170 | /* |
| 9171 | * remove the prefix from the middle of the sub-tree |
| 9172 | * the inherited source will be the only one remaining - expect |
| 9173 | * it to be withdrawn and hence the prefix is removed. |
| 9174 | */ |
| 9175 | fib_table_entry_special_remove(0, |
| 9176 | &pfx_10_10_10_20_s_30, |
| 9177 | FIB_SOURCE_CLI); |
| 9178 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_20_s_30); |
| 9179 | FIB_TEST((FIB_NODE_INDEX_INVALID == fei), |
| 9180 | "%U gone", |
| 9181 | format_fib_prefix, &pfx_10_10_10_20_s_30); |
| 9182 | |
| 9183 | /* |
| 9184 | * inheriting source is modifed - expect the modification to be present |
| 9185 | * throughout the sub-tree |
| 9186 | */ |
| 9187 | adj_index_t ai_10_10_10_2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 9188 | VNET_LINK_IP4, |
| 9189 | &nh_10_10_10_2, |
| 9190 | tm->hw[0]->sw_if_index); |
| 9191 | fib_test_lb_bucket_t adj_o_10_10_10_2 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9192 | .type = FT_LB_ADJ, |
| 9193 | .adj = { |
| 9194 | .adj = ai_10_10_10_2, |
| 9195 | }, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9196 | }; |
| 9197 | |
| 9198 | fib_table_entry_update_one_path(0, |
| 9199 | &pfx_10_10_10_0_s_24, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9200 | FIB_SOURCE_API, |
| 9201 | FIB_ENTRY_FLAG_COVERED_INHERIT, |
| 9202 | DPO_PROTO_IP4, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9203 | &nh_10_10_10_2, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9204 | tm->hw[0]->sw_if_index, |
| 9205 | ~0, |
| 9206 | 1, |
| 9207 | NULL, |
| 9208 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9209 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9210 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9211 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9212 | 1, |
| 9213 | &adj_o_10_10_10_2), |
| 9214 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9215 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9216 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_22_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9217 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9218 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9219 | 1, |
| 9220 | &adj_o_10_10_10_2), |
| 9221 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9222 | format_fib_prefix, &pfx_10_10_10_22_s_32); |
| 9223 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_255_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9224 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9225 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9226 | 1, |
| 9227 | &adj_o_10_10_10_2), |
| 9228 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9229 | format_fib_prefix, &pfx_10_10_10_255_s_32); |
| 9230 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_0_s_24); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9231 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9232 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9233 | 1, |
| 9234 | &adj_o_10_10_10_2), |
| 9235 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9236 | format_fib_prefix, &pfx_10_10_10_0_s_24); |
| 9237 | |
| 9238 | /* |
| 9239 | * add the source that replaces inherited state. |
| 9240 | * inheriting source is not the best, so it doesn't push state. |
| 9241 | */ |
| 9242 | fib_table_entry_update_one_path(0, |
| 9243 | &pfx_10_10_10_0_s_24, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9244 | FIB_SOURCE_PLUGIN_HI, |
| 9245 | FIB_ENTRY_FLAG_NONE, |
| 9246 | DPO_PROTO_IP4, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9247 | &nh_10_10_10_1, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9248 | tm->hw[0]->sw_if_index, |
| 9249 | ~0, |
| 9250 | 1, |
| 9251 | NULL, |
| 9252 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9253 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_0_s_24); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9254 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9255 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9256 | 1, |
| 9257 | &adj_o_10_10_10_1), |
| 9258 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9259 | format_fib_prefix, &pfx_10_10_10_0_s_24); |
| 9260 | |
| 9261 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
| 9262 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 9263 | "%U resolves via drop", |
| 9264 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9265 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_22_s_32); |
| 9266 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 9267 | "%U resolves via drop", |
| 9268 | format_fib_prefix, &pfx_10_10_10_22_s_32); |
| 9269 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_255_s_32); |
| 9270 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 9271 | "%U resolves via drop", |
| 9272 | format_fib_prefix, &pfx_10_10_10_255_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9273 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_16_s_28); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9274 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 9275 | "%U resolves via drop", |
| 9276 | format_fib_prefix, &pfx_10_10_10_16_s_28); |
| 9277 | |
| 9278 | /* |
| 9279 | * withdraw the higher priority source and expect the inherited to return |
| 9280 | * throughout the sub-tree |
| 9281 | */ |
| 9282 | fib_table_entry_delete(0, &pfx_10_10_10_0_s_24, FIB_SOURCE_PLUGIN_HI); |
| 9283 | |
| 9284 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9285 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9286 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9287 | 1, |
| 9288 | &adj_o_10_10_10_2), |
| 9289 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9290 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9291 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_22_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9292 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9293 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9294 | 1, |
| 9295 | &adj_o_10_10_10_2), |
| 9296 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9297 | format_fib_prefix, &pfx_10_10_10_22_s_32); |
| 9298 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_255_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9299 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9300 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9301 | 1, |
| 9302 | &adj_o_10_10_10_2), |
| 9303 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9304 | format_fib_prefix, &pfx_10_10_10_255_s_32); |
| 9305 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_0_s_24); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9306 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9307 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9308 | 1, |
| 9309 | &adj_o_10_10_10_2), |
| 9310 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9311 | format_fib_prefix, &pfx_10_10_10_0_s_24); |
| 9312 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_16_s_28); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9313 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9314 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9315 | 1, |
| 9316 | &adj_o_10_10_10_2), |
| 9317 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9318 | format_fib_prefix, &pfx_10_10_10_16_s_28); |
| 9319 | |
| 9320 | /* |
| 9321 | * source a covered entry in the sub-tree with the same inherting source |
| 9322 | * - expect that it now owns the sub-tree and thus over-rides its cover |
| 9323 | */ |
| 9324 | fib_table_entry_update_one_path(0, |
| 9325 | &pfx_10_10_10_16_s_28, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9326 | FIB_SOURCE_API, |
| 9327 | FIB_ENTRY_FLAG_COVERED_INHERIT, |
| 9328 | DPO_PROTO_IP4, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9329 | &nh_10_10_10_1, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9330 | tm->hw[0]->sw_if_index, |
| 9331 | ~0, |
| 9332 | 1, |
| 9333 | NULL, |
| 9334 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9335 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_16_s_28); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9336 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9337 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9338 | 1, |
| 9339 | &adj_o_10_10_10_1), |
| 9340 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9341 | format_fib_prefix, &pfx_10_10_10_16_s_28); |
| 9342 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_22_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9343 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9344 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9345 | 1, |
| 9346 | &adj_o_10_10_10_1), |
| 9347 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9348 | format_fib_prefix, &pfx_10_10_10_22_s_32); |
| 9349 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9350 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9351 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9352 | 1, |
| 9353 | &adj_o_10_10_10_1), |
| 9354 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9355 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9356 | |
| 9357 | /* these two unaffected by the sub-tree change */ |
| 9358 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_255_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9359 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9360 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9361 | 1, |
| 9362 | &adj_o_10_10_10_2), |
| 9363 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9364 | format_fib_prefix, &pfx_10_10_10_255_s_32); |
| 9365 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_0_s_24); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9366 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9367 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9368 | 1, |
| 9369 | &adj_o_10_10_10_2), |
| 9370 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9371 | format_fib_prefix, &pfx_10_10_10_0_s_24); |
| 9372 | |
| 9373 | /* |
| 9374 | * removes the more specific, expect the /24 to now re-owns the sub-tree |
| 9375 | */ |
| 9376 | fib_table_entry_delete(0, &pfx_10_10_10_16_s_28, FIB_SOURCE_API); |
| 9377 | |
| 9378 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9379 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9380 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9381 | 1, |
| 9382 | &adj_o_10_10_10_2), |
| 9383 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9384 | format_fib_prefix, &pfx_10_10_10_16_s_28); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9385 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9386 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9387 | 1, |
| 9388 | &adj_o_10_10_10_2), |
| 9389 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9390 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9391 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_22_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9392 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9393 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9394 | 1, |
| 9395 | &adj_o_10_10_10_2), |
| 9396 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9397 | format_fib_prefix, &pfx_10_10_10_22_s_32); |
| 9398 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_255_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9399 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9400 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9401 | 1, |
| 9402 | &adj_o_10_10_10_2), |
| 9403 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9404 | format_fib_prefix, &pfx_10_10_10_255_s_32); |
| 9405 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_0_s_24); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9406 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9407 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9408 | 1, |
| 9409 | &adj_o_10_10_10_2), |
| 9410 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9411 | format_fib_prefix, &pfx_10_10_10_0_s_24); |
| 9412 | /* |
| 9413 | * modify the /24. expect the new forwarding to be pushed down |
| 9414 | */ |
| 9415 | fib_table_entry_update_one_path(0, |
| 9416 | &pfx_10_10_10_0_s_24, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9417 | FIB_SOURCE_API, |
| 9418 | FIB_ENTRY_FLAG_COVERED_INHERIT, |
| 9419 | DPO_PROTO_IP4, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9420 | &nh_10_10_10_1, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9421 | tm->hw[0]->sw_if_index, |
| 9422 | ~0, |
| 9423 | 1, |
| 9424 | NULL, |
| 9425 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9426 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9427 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9428 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9429 | 1, |
| 9430 | &adj_o_10_10_10_1), |
| 9431 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9432 | format_fib_prefix, &pfx_10_10_10_16_s_28); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9433 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9434 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9435 | 1, |
| 9436 | &adj_o_10_10_10_1), |
| 9437 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9438 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9439 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_22_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9440 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9441 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9442 | 1, |
| 9443 | &adj_o_10_10_10_1), |
| 9444 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9445 | format_fib_prefix, &pfx_10_10_10_22_s_32); |
| 9446 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_255_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9447 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9448 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9449 | 1, |
| 9450 | &adj_o_10_10_10_1), |
| 9451 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9452 | format_fib_prefix, &pfx_10_10_10_255_s_32); |
| 9453 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_0_s_24); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9454 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9455 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9456 | 1, |
| 9457 | &adj_o_10_10_10_1), |
| 9458 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9459 | format_fib_prefix, &pfx_10_10_10_0_s_24); |
| 9460 | |
| 9461 | /* |
| 9462 | * add an entry less specific to /24. it should not own the /24's tree |
| 9463 | */ |
| 9464 | const fib_prefix_t pfx_10_10_0_0_s_16 = { |
| 9465 | .fp_len = 16, |
| 9466 | .fp_proto = FIB_PROTOCOL_IP4, |
| 9467 | .fp_addr = nh_10_10_0_0, |
| 9468 | }; |
| 9469 | fib_table_entry_update_one_path(0, |
| 9470 | &pfx_10_10_0_0_s_16, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9471 | FIB_SOURCE_API, |
| 9472 | FIB_ENTRY_FLAG_COVERED_INHERIT, |
| 9473 | DPO_PROTO_IP4, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9474 | &nh_10_10_10_2, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9475 | tm->hw[0]->sw_if_index, |
| 9476 | ~0, |
| 9477 | 1, |
| 9478 | NULL, |
| 9479 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9480 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9481 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9482 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9483 | 1, |
| 9484 | &adj_o_10_10_10_1), |
| 9485 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9486 | format_fib_prefix, &pfx_10_10_10_16_s_28); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9487 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_22_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9488 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9489 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9490 | 1, |
| 9491 | &adj_o_10_10_10_1), |
| 9492 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9493 | format_fib_prefix, &pfx_10_10_10_22_s_32); |
| 9494 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_255_s_32); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9495 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9496 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9497 | 1, |
| 9498 | &adj_o_10_10_10_1), |
| 9499 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9500 | format_fib_prefix, &pfx_10_10_10_255_s_32); |
| 9501 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_0_s_24); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9502 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9503 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9504 | 1, |
| 9505 | &adj_o_10_10_10_1), |
| 9506 | "%U via 10.10.10.1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9507 | format_fib_prefix, &pfx_10_10_10_0_s_24); |
| 9508 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_0_0_s_16); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9509 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9510 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9511 | 1, |
| 9512 | &adj_o_10_10_10_2), |
| 9513 | "%U via 10.10.10.2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9514 | format_fib_prefix, &pfx_10_10_0_0_s_16); |
| 9515 | |
| 9516 | /* |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9517 | * Add/remove an interposer source to a new /32 |
| 9518 | */ |
| 9519 | const fib_prefix_t pfx_11_11_11_11_s_32 = { |
| 9520 | .fp_len = 32, |
| 9521 | .fp_proto = FIB_PROTOCOL_IP4, |
| 9522 | .fp_addr = nh_11_11_11_11, |
| 9523 | }; |
| 9524 | |
| 9525 | fib_table_entry_update_one_path(0, |
| 9526 | &pfx_11_11_11_11_s_32, |
| 9527 | FIB_SOURCE_API, |
| 9528 | FIB_ENTRY_FLAG_NONE, |
| 9529 | DPO_PROTO_IP4, |
| 9530 | &nh_10_10_10_3, |
| 9531 | tm->hw[0]->sw_if_index, |
| 9532 | ~0, |
| 9533 | 1, |
| 9534 | NULL, |
| 9535 | FIB_ROUTE_PATH_FLAG_NONE); |
| 9536 | |
| 9537 | dpo_id_t interposer = DPO_INVALID; |
| 9538 | fib_mpls_label_t *l99 = NULL, fml_99 = { |
| 9539 | .fml_value = 99, |
| 9540 | }; |
| 9541 | vec_add1(l99, fml_99); |
| 9542 | |
| 9543 | mpls_label_dpo_create(l99, |
| 9544 | MPLS_EOS, |
| 9545 | DPO_PROTO_IP4, |
| 9546 | MPLS_LABEL_DPO_FLAG_NONE, |
| 9547 | punt_dpo_get(DPO_PROTO_MPLS), |
| 9548 | &interposer); |
| 9549 | |
| 9550 | adj_index_t ai_10_10_10_3 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, |
| 9551 | VNET_LINK_IP4, |
| 9552 | &nh_10_10_10_3, |
| 9553 | tm->hw[0]->sw_if_index); |
| 9554 | fib_test_lb_bucket_t adj_o_10_10_10_3 = { |
| 9555 | .type = FT_LB_ADJ, |
| 9556 | .adj = { |
| 9557 | .adj = ai_10_10_10_3, |
| 9558 | }, |
| 9559 | }; |
| 9560 | fib_test_lb_bucket_t l99_o_10_10_10_3 = { |
| 9561 | .type = FT_LB_LABEL_O_ADJ, |
| 9562 | .label_o_adj = { |
| 9563 | .adj = ai_10_10_10_3, |
| 9564 | .label = 99, |
| 9565 | .eos = MPLS_EOS, |
| 9566 | }, |
| 9567 | }; |
| 9568 | |
| 9569 | fei = fib_table_entry_special_dpo_add(0, |
| 9570 | &pfx_11_11_11_11_s_32, |
| 9571 | FIB_SOURCE_SPECIAL, |
| 9572 | FIB_ENTRY_FLAG_INTERPOSE, |
| 9573 | &interposer); |
| 9574 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9575 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9576 | 1, |
| 9577 | &l99_o_10_10_10_3), |
| 9578 | "%U via interposer adj", |
| 9579 | format_fib_prefix,&pfx_11_11_11_11_s_32); |
| 9580 | |
| 9581 | fib_table_entry_special_remove(0, |
| 9582 | &pfx_11_11_11_11_s_32, |
| 9583 | FIB_SOURCE_SPECIAL); |
| 9584 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9585 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9586 | 1, |
| 9587 | &adj_o_10_10_10_3), |
| 9588 | "%U via 10.10.10.1", |
| 9589 | format_fib_prefix, &pfx_11_11_11_11_s_32); |
| 9590 | |
| 9591 | /* |
| 9592 | * remove and re-add the second best API source while the interpose |
| 9593 | * is present |
| 9594 | */ |
| 9595 | fei = fib_table_entry_special_dpo_add(0, |
| 9596 | &pfx_11_11_11_11_s_32, |
| 9597 | FIB_SOURCE_SPECIAL, |
| 9598 | FIB_ENTRY_FLAG_INTERPOSE, |
| 9599 | &interposer); |
| 9600 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9601 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9602 | 1, |
| 9603 | &l99_o_10_10_10_3), |
| 9604 | "%U via interposer adj", |
| 9605 | format_fib_prefix,&pfx_11_11_11_11_s_32); |
| 9606 | |
| 9607 | FIB_TEST(2 == pool_elts(mpls_label_dpo_pool), |
| 9608 | "MPLS label pool: %d", |
| 9609 | pool_elts(mpls_label_dpo_pool)); |
| 9610 | |
| 9611 | fib_table_entry_delete(0, &pfx_11_11_11_11_s_32, FIB_SOURCE_API); |
| 9612 | |
| 9613 | /* |
| 9614 | * the interpose does not get stacked when there are not valid paths |
| 9615 | */ |
| 9616 | fib_test_lb_bucket_t bucket_drop = { |
| 9617 | .type = FT_LB_DROP, |
| 9618 | .special = { |
| 9619 | .adj = DPO_PROTO_IP4, |
| 9620 | }, |
| 9621 | }; |
| 9622 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9623 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9624 | 1, |
| 9625 | &bucket_drop), |
| 9626 | "%U via drop", |
| 9627 | format_fib_prefix,&pfx_11_11_11_11_s_32); |
| 9628 | |
| 9629 | fib_table_entry_update_one_path(0, |
| 9630 | &pfx_11_11_11_11_s_32, |
| 9631 | FIB_SOURCE_API, |
| 9632 | FIB_ENTRY_FLAG_NONE, |
| 9633 | DPO_PROTO_IP4, |
| 9634 | &nh_10_10_10_3, |
| 9635 | tm->hw[0]->sw_if_index, |
| 9636 | ~0, |
| 9637 | 1, |
| 9638 | NULL, |
| 9639 | FIB_ROUTE_PATH_FLAG_NONE); |
| 9640 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9641 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9642 | 1, |
| 9643 | &l99_o_10_10_10_3), |
| 9644 | "%U via interposer adj", |
| 9645 | format_fib_prefix,&pfx_11_11_11_11_s_32); |
| 9646 | fib_table_entry_delete(0, &pfx_11_11_11_11_s_32, FIB_SOURCE_API); |
| 9647 | |
| 9648 | /* |
| 9649 | * add a cover for the interposed entry, so that we test it selects |
| 9650 | * the covers forwarding. |
| 9651 | */ |
| 9652 | const fib_prefix_t pfx_11_11_11_0_s_24 = { |
| 9653 | .fp_len = 24, |
| 9654 | .fp_proto = FIB_PROTOCOL_IP4, |
| 9655 | .fp_addr = nh_11_11_11_0, |
| 9656 | }; |
| 9657 | fib_table_entry_update_one_path(0, |
| 9658 | &pfx_11_11_11_0_s_24, |
| 9659 | FIB_SOURCE_API, |
| 9660 | FIB_ENTRY_FLAG_NONE, |
| 9661 | DPO_PROTO_IP4, |
| 9662 | &nh_10_10_10_3, |
| 9663 | tm->hw[0]->sw_if_index, |
| 9664 | ~0, |
| 9665 | 1, |
| 9666 | NULL, |
| 9667 | FIB_ROUTE_PATH_FLAG_NONE); |
| 9668 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9669 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9670 | 1, |
| 9671 | &l99_o_10_10_10_3), |
| 9672 | "%U via interposer adj", |
| 9673 | format_fib_prefix,&pfx_11_11_11_11_s_32); |
| 9674 | |
| 9675 | /* |
| 9676 | * multiple interpose sources on the same entry. Only the high |
| 9677 | * priority source gets to add the interpose. |
| 9678 | */ |
| 9679 | dpo_id_t interposer2 = DPO_INVALID; |
| 9680 | fib_mpls_label_t *l100 = NULL, fml_100 = { |
| 9681 | .fml_value = 100, |
| 9682 | }; |
| 9683 | vec_add1(l100, fml_100); |
| 9684 | |
| 9685 | mpls_label_dpo_create(l100, |
| 9686 | MPLS_EOS, |
| 9687 | DPO_PROTO_IP4, |
| 9688 | MPLS_LABEL_DPO_FLAG_NONE, |
| 9689 | punt_dpo_get(DPO_PROTO_MPLS), |
| 9690 | &interposer2); |
| 9691 | |
| 9692 | fei = fib_table_entry_special_dpo_add(0, |
| 9693 | &pfx_11_11_11_11_s_32, |
| 9694 | FIB_SOURCE_CLASSIFY, |
| 9695 | FIB_ENTRY_FLAG_INTERPOSE, |
| 9696 | &interposer2); |
| 9697 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9698 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9699 | 1, |
| 9700 | &l99_o_10_10_10_3), |
| 9701 | "%U via interposer label 99", |
| 9702 | format_fib_prefix,&pfx_11_11_11_11_s_32); |
| 9703 | |
| 9704 | fib_test_lb_bucket_t l100_o_10_10_10_3 = { |
| 9705 | .type = FT_LB_LABEL_O_ADJ, |
| 9706 | .label_o_adj = { |
| 9707 | .adj = ai_10_10_10_3, |
| 9708 | .label = 100, |
| 9709 | .eos = MPLS_EOS, |
| 9710 | }, |
| 9711 | }; |
| 9712 | |
| 9713 | fib_table_entry_delete(0, &pfx_11_11_11_11_s_32, FIB_SOURCE_SPECIAL); |
| 9714 | |
| 9715 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9716 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9717 | 1, |
| 9718 | &l100_o_10_10_10_3), |
| 9719 | "%U via interposer label 99", |
| 9720 | format_fib_prefix,&pfx_11_11_11_11_s_32); |
| 9721 | |
| 9722 | fib_table_entry_delete(0, &pfx_11_11_11_0_s_24, FIB_SOURCE_API); |
| 9723 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9724 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9725 | 1, |
| 9726 | &bucket_drop), |
| 9727 | "%U via drop", |
| 9728 | format_fib_prefix,&pfx_11_11_11_11_s_32); |
| 9729 | fib_table_entry_delete(0, &pfx_11_11_11_11_s_32, FIB_SOURCE_CLASSIFY); |
| 9730 | |
| 9731 | /* |
| 9732 | * update a source to/from interpose. |
| 9733 | */ |
| 9734 | /* fib_table_entry_update_one_path(0, */ |
| 9735 | /* &pfx_11_11_11_0_s_24, */ |
| 9736 | /* FIB_SOURCE_API, */ |
| 9737 | /* FIB_ENTRY_FLAG_NONE, */ |
| 9738 | /* DPO_PROTO_IP4, */ |
| 9739 | /* &nh_10_10_10_3, */ |
| 9740 | /* tm->hw[0]->sw_if_index, */ |
| 9741 | /* ~0, */ |
| 9742 | /* 1, */ |
| 9743 | /* NULL, */ |
| 9744 | /* FIB_ROUTE_PATH_FLAG_NONE); */ |
| 9745 | /* fei = fib_table_entry_special_dpo_add(0, */ |
| 9746 | /* &pfx_11_11_11_11_s_32, */ |
| 9747 | /* FIB_SOURCE_API, */ |
| 9748 | /* FIB_ENTRY_FLAG_INTERPOSE, */ |
| 9749 | /* &interposer); */ |
| 9750 | /* FIB_TEST(!fib_test_validate_entry(fei, */ |
| 9751 | /* FIB_FORW_CHAIN_TYPE_UNICAST_IP4, */ |
| 9752 | /* 1, */ |
| 9753 | /* &l99_o_10_10_10_3), */ |
| 9754 | /* "%U via interposer label 99", */ |
| 9755 | /* format_fib_prefix,&pfx_11_11_11_11_s_32); */ |
| 9756 | |
| 9757 | /* FIB_TEST(3 == pool_elts(mpls_label_dpo_pool), */ |
| 9758 | /* "MPLS label pool: %d", */ |
| 9759 | /* pool_elts(mpls_label_dpo_pool)); */ |
| 9760 | /* FIB_TEST((2 == mpls_label_dpo_get(interposer.dpoi_index)->mld_locks), */ |
| 9761 | /* "Interposer %d locks", */ |
| 9762 | /* mpls_label_dpo_get(interposer.dpoi_index)->mld_locks); */ |
| 9763 | |
| 9764 | /* fib_table_entry_update_one_path(0, */ |
| 9765 | /* &pfx_11_11_11_11_s_32, */ |
| 9766 | /* FIB_SOURCE_API, */ |
| 9767 | /* FIB_ENTRY_FLAG_NONE, */ |
| 9768 | /* DPO_PROTO_IP4, */ |
| 9769 | /* &nh_10_10_10_2, */ |
| 9770 | /* tm->hw[0]->sw_if_index, */ |
| 9771 | /* ~0, */ |
| 9772 | /* 1, */ |
| 9773 | /* NULL, */ |
| 9774 | /* FIB_ROUTE_PATH_FLAG_NONE); */ |
| 9775 | /* FIB_TEST(!fib_test_validate_entry(fei, */ |
| 9776 | /* FIB_FORW_CHAIN_TYPE_UNICAST_IP4, */ |
| 9777 | /* 1, */ |
| 9778 | /* &adj_o_10_10_10_2), */ |
| 9779 | /* "%U via 10.10.10.2", */ |
| 9780 | /* format_fib_prefix,&pfx_11_11_11_11_s_32); */ |
| 9781 | |
| 9782 | /* FIB_TEST((1 == mpls_label_dpo_get(interposer.dpoi_index)->mld_locks), */ |
| 9783 | /* "Interposer %d locks", */ |
| 9784 | /* mpls_label_dpo_get(interposer.dpoi_index)->mld_locks); */ |
| 9785 | /* FIB_TEST(2 == pool_elts(mpls_label_dpo_pool), */ |
| 9786 | /* "MPLS label pool: %d", */ |
| 9787 | /* pool_elts(mpls_label_dpo_pool)); */ |
| 9788 | |
| 9789 | /* fei = fib_table_entry_special_dpo_add(0, */ |
| 9790 | /* &pfx_11_11_11_11_s_32, */ |
| 9791 | /* FIB_SOURCE_API, */ |
| 9792 | /* FIB_ENTRY_FLAG_INTERPOSE, */ |
| 9793 | /* &interposer); */ |
| 9794 | /* FIB_TEST(!fib_test_validate_entry(fei, */ |
| 9795 | /* FIB_FORW_CHAIN_TYPE_UNICAST_IP4, */ |
| 9796 | /* 1, */ |
| 9797 | /* &l99_o_10_10_10_3), */ |
| 9798 | /* "%U via interposer label 99", */ |
| 9799 | /* format_fib_prefix,&pfx_11_11_11_11_s_32); */ |
| 9800 | |
| 9801 | /* fib_table_entry_delete(0, &pfx_11_11_11_11_s_32, FIB_SOURCE_API); */ |
| 9802 | |
| 9803 | /* |
| 9804 | * Add/remove an interposer source from the top of the subtrie. The |
| 9805 | * interposer source is not inherited. |
| 9806 | */ |
| 9807 | fib_table_entry_update_one_path(0, |
| 9808 | &pfx_10_10_10_0_s_24, |
| 9809 | FIB_SOURCE_API, |
| 9810 | FIB_ENTRY_FLAG_COVERED_INHERIT, |
| 9811 | DPO_PROTO_IP4, |
| 9812 | &nh_10_10_10_3, |
| 9813 | tm->hw[0]->sw_if_index, |
| 9814 | ~0, |
| 9815 | 1, |
| 9816 | NULL, |
| 9817 | FIB_ROUTE_PATH_FLAG_NONE); |
| 9818 | fei = fib_table_entry_special_dpo_add(0, |
| 9819 | &pfx_10_10_10_0_s_24, |
| 9820 | FIB_SOURCE_SPECIAL, |
| 9821 | FIB_ENTRY_FLAG_INTERPOSE, |
| 9822 | &interposer); |
| 9823 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9824 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9825 | 1, |
| 9826 | &l99_o_10_10_10_3), |
| 9827 | "%U via interposer label", |
| 9828 | format_fib_prefix,&pfx_10_10_10_0_s_24); |
| 9829 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
| 9830 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9831 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9832 | 1, |
| 9833 | &bucket_drop), |
| 9834 | "%U via drop", |
| 9835 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9836 | |
| 9837 | fib_table_entry_special_remove(0, |
| 9838 | &pfx_10_10_10_0_s_24, |
| 9839 | FIB_SOURCE_SPECIAL); |
| 9840 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_0_s_24); |
| 9841 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9842 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9843 | 1, |
| 9844 | &adj_o_10_10_10_3), |
| 9845 | "%U via 10.10.10.1", |
| 9846 | format_fib_prefix, &pfx_10_10_10_0_s_24); |
| 9847 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
| 9848 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9849 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9850 | 1, |
| 9851 | &adj_o_10_10_10_3), |
| 9852 | "%U via via 10.10.10.1", |
| 9853 | format_fib_prefix, &pfx_10_10_10_21_s_32); |
| 9854 | |
| 9855 | /* |
| 9856 | * Add/remove an interposer source from the top of the subtrie. The |
| 9857 | * interposer source is inherited. |
| 9858 | */ |
| 9859 | fei = fib_table_entry_special_dpo_add(0, |
| 9860 | &pfx_10_10_10_0_s_24, |
| 9861 | FIB_SOURCE_SPECIAL, |
| 9862 | (FIB_ENTRY_FLAG_COVERED_INHERIT | |
| 9863 | FIB_ENTRY_FLAG_INTERPOSE), |
| 9864 | &interposer); |
| 9865 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9866 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9867 | 1, |
| 9868 | &l99_o_10_10_10_3), |
| 9869 | "%U via interposer label", |
| 9870 | format_fib_prefix,&pfx_10_10_10_0_s_24); |
| 9871 | |
| 9872 | /* interposer gets forwarding from the drop cli source */ |
| 9873 | fei = fib_table_lookup_exact_match(0, &pfx_10_10_10_21_s_32); |
| 9874 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9875 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9876 | 1, |
| 9877 | &bucket_drop), |
| 9878 | "%U via drop", |
| 9879 | format_fib_prefix,&pfx_10_10_10_21_s_32); |
| 9880 | |
| 9881 | fib_table_entry_update_one_path(0, |
| 9882 | &pfx_10_10_10_21_s_32, |
| 9883 | FIB_SOURCE_API, |
| 9884 | FIB_ENTRY_FLAG_NONE, |
| 9885 | DPO_PROTO_IP4, |
| 9886 | &nh_10_10_10_3, |
| 9887 | tm->hw[0]->sw_if_index, |
| 9888 | ~0, |
| 9889 | 1, |
| 9890 | NULL, |
| 9891 | FIB_ROUTE_PATH_FLAG_NONE); |
| 9892 | fib_table_entry_delete(0, &pfx_10_10_10_21_s_32, FIB_SOURCE_CLI); |
| 9893 | /* interposer gets forwarding from the API source */ |
| 9894 | FIB_TEST(!fib_test_validate_entry(fei, |
| 9895 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4, |
| 9896 | 1, |
| 9897 | &l99_o_10_10_10_3), |
| 9898 | "%U via interposer label", |
| 9899 | format_fib_prefix,&pfx_10_10_10_21_s_32); |
| 9900 | |
| 9901 | /* |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9902 | * cleanup |
| 9903 | */ |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9904 | fib_table_entry_delete(0, &pfx_10_10_10_22_s_32, FIB_SOURCE_CLI); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9905 | fib_table_entry_delete(0, &pfx_10_10_10_21_s_32, FIB_SOURCE_API); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9906 | fib_table_entry_delete(0, &pfx_10_10_10_16_s_28, FIB_SOURCE_CLI); |
| 9907 | fib_table_entry_delete(0, &pfx_10_10_10_255_s_32, FIB_SOURCE_CLI); |
| 9908 | fib_table_entry_delete(0, &pfx_10_10_10_0_s_24, FIB_SOURCE_API); |
| 9909 | fib_table_entry_delete(0, &pfx_10_10_0_0_s_16, FIB_SOURCE_API); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9910 | fib_table_entry_delete(0, &pfx_10_10_10_0_s_24, FIB_SOURCE_SPECIAL); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9911 | adj_unlock(ai_10_10_10_1); |
| 9912 | adj_unlock(ai_10_10_10_2); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9913 | adj_unlock(ai_10_10_10_3); |
| 9914 | dpo_reset(&interposer); |
| 9915 | dpo_reset(&interposer2); |
| 9916 | FIB_TEST(0 == pool_elts(mpls_label_dpo_pool), |
| 9917 | "MPLS label pool empty: %d", |
| 9918 | pool_elts(mpls_label_dpo_pool)); |
| 9919 | FIB_TEST(0 == adj_nbr_db_size(), "All adjacencies removed"); |
| 9920 | FIB_TEST(N_PLS == fib_path_list_pool_size(), |
| 9921 | "number of path-lists: %d = %d", |
| 9922 | N_PLS, fib_path_list_pool_size()); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9923 | |
| 9924 | /* |
| 9925 | * test the v6 tree walk. |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9926 | * a /64 that covers everything. a /96 that covers one /128 |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9927 | * a second /128 covered only by the /64. |
| 9928 | */ |
| 9929 | const fib_prefix_t pfx_2001_s_64 = { |
| 9930 | .fp_len = 64, |
| 9931 | .fp_proto = FIB_PROTOCOL_IP6, |
| 9932 | .fp_addr = { |
| 9933 | .ip6 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9934 | .as_u64 = { |
| 9935 | [0] = clib_host_to_net_u64(0x2001000000000000), |
| 9936 | [1] = clib_host_to_net_u64(0x0000000000000000), |
| 9937 | }, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9938 | }, |
| 9939 | }, |
| 9940 | }; |
| 9941 | const fib_prefix_t pfx_2001_1_s_96 = { |
| 9942 | .fp_len = 96, |
| 9943 | .fp_proto = FIB_PROTOCOL_IP6, |
| 9944 | .fp_addr = { |
| 9945 | .ip6 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9946 | .as_u64 = { |
| 9947 | [0] = clib_host_to_net_u64(0x2001000000000000), |
| 9948 | [1] = clib_host_to_net_u64(0x1000000000000000), |
| 9949 | }, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9950 | }, |
| 9951 | }, |
| 9952 | }; |
| 9953 | const fib_prefix_t pfx_2001_1_1_s_128 = { |
| 9954 | .fp_len = 128, |
| 9955 | .fp_proto = FIB_PROTOCOL_IP6, |
| 9956 | .fp_addr = { |
| 9957 | .ip6 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9958 | .as_u64 = { |
| 9959 | [0] = clib_host_to_net_u64(0x2001000000000000), |
| 9960 | [1] = clib_host_to_net_u64(0x1000000000000001), |
| 9961 | }, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9962 | }, |
| 9963 | }, |
| 9964 | }; |
| 9965 | const fib_prefix_t pfx_2001_0_1_s_128 = { |
| 9966 | .fp_len = 128, |
| 9967 | .fp_proto = FIB_PROTOCOL_IP6, |
| 9968 | .fp_addr = { |
| 9969 | .ip6 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 9970 | .as_u64 = { |
| 9971 | [0] = clib_host_to_net_u64(0x2001000000000000), |
| 9972 | [1] = clib_host_to_net_u64(0x0000000000000001), |
| 9973 | }, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 9974 | }, |
| 9975 | }, |
| 9976 | }; |
| 9977 | const ip46_address_t nh_3000_1 = { |
| 9978 | .ip6 = { |
| 9979 | .as_u64 = { |
| 9980 | [0] = clib_host_to_net_u64(0x3000000000000000), |
| 9981 | [1] = clib_host_to_net_u64(0x0000000000000001), |
| 9982 | }, |
| 9983 | }, |
| 9984 | }; |
| 9985 | const ip46_address_t nh_3000_2 = { |
| 9986 | .ip6 = { |
| 9987 | .as_u64 = { |
| 9988 | [0] = clib_host_to_net_u64(0x3000000000000000), |
| 9989 | [1] = clib_host_to_net_u64(0x0000000000000002), |
| 9990 | }, |
| 9991 | }, |
| 9992 | }; |
| 9993 | adj_index_t ai_3000_1 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP6, |
| 9994 | VNET_LINK_IP6, |
| 9995 | &nh_3000_1, |
| 9996 | tm->hw[0]->sw_if_index); |
| 9997 | adj_index_t ai_3000_2 = adj_nbr_add_or_lock(FIB_PROTOCOL_IP6, |
| 9998 | VNET_LINK_IP6, |
| 9999 | &nh_3000_2, |
| 10000 | tm->hw[0]->sw_if_index); |
| 10001 | fib_test_lb_bucket_t adj_o_3000_1 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10002 | .type = FT_LB_ADJ, |
| 10003 | .adj = { |
| 10004 | .adj = ai_3000_1, |
| 10005 | }, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10006 | }; |
| 10007 | fib_test_lb_bucket_t adj_o_3000_2 = { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10008 | .type = FT_LB_ADJ, |
| 10009 | .adj = { |
| 10010 | .adj = ai_3000_2, |
| 10011 | }, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10012 | }; |
| 10013 | |
| 10014 | fib_table_entry_special_add(0, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10015 | &pfx_2001_0_1_s_128, |
| 10016 | FIB_SOURCE_CLI, |
| 10017 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10018 | fib_table_entry_special_add(0, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10019 | &pfx_2001_1_1_s_128, |
| 10020 | FIB_SOURCE_CLI, |
| 10021 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10022 | |
| 10023 | /* |
| 10024 | * /96 has inherited forwarding pushed down to its covered /128 |
| 10025 | */ |
| 10026 | fib_table_entry_update_one_path(0, |
| 10027 | &pfx_2001_1_s_96, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10028 | FIB_SOURCE_API, |
| 10029 | FIB_ENTRY_FLAG_COVERED_INHERIT, |
| 10030 | DPO_PROTO_IP6, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10031 | &nh_3000_1, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10032 | tm->hw[0]->sw_if_index, |
| 10033 | ~0, |
| 10034 | 1, |
| 10035 | NULL, |
| 10036 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10037 | fei = fib_table_lookup_exact_match(0, &pfx_2001_1_s_96); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10038 | FIB_TEST(!fib_test_validate_entry(fei, |
| 10039 | FIB_FORW_CHAIN_TYPE_UNICAST_IP6, |
| 10040 | 1, |
| 10041 | &adj_o_3000_1), |
| 10042 | "%U via 3000::1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10043 | format_fib_prefix, &pfx_2001_1_s_96); |
| 10044 | fei = fib_table_lookup_exact_match(0, &pfx_2001_1_1_s_128); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10045 | FIB_TEST(!fib_test_validate_entry(fei, |
| 10046 | FIB_FORW_CHAIN_TYPE_UNICAST_IP6, |
| 10047 | 1, |
| 10048 | &adj_o_3000_1), |
| 10049 | "%U via 3000::1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10050 | format_fib_prefix, &pfx_2001_1_1_s_128); |
| 10051 | fei = fib_table_lookup_exact_match(0, &pfx_2001_0_1_s_128); |
| 10052 | FIB_TEST(load_balance_is_drop(fib_entry_contribute_ip_forwarding(fei)), |
| 10053 | "%U resolves via drop", |
| 10054 | format_fib_prefix, &pfx_2001_0_1_s_128); |
| 10055 | |
| 10056 | /* |
| 10057 | * /64 has inherited forwarding pushed down to all, but the /96 |
| 10058 | * and its sub-tree remain unaffected. |
| 10059 | */ |
| 10060 | fib_table_entry_update_one_path(0, |
| 10061 | &pfx_2001_s_64, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10062 | FIB_SOURCE_API, |
| 10063 | FIB_ENTRY_FLAG_COVERED_INHERIT, |
| 10064 | DPO_PROTO_IP6, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10065 | &nh_3000_2, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10066 | tm->hw[0]->sw_if_index, |
| 10067 | ~0, |
| 10068 | 1, |
| 10069 | NULL, |
| 10070 | FIB_ROUTE_PATH_FLAG_NONE); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10071 | |
| 10072 | fei = fib_table_lookup_exact_match(0, &pfx_2001_s_64); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10073 | FIB_TEST(!fib_test_validate_entry(fei, |
| 10074 | FIB_FORW_CHAIN_TYPE_UNICAST_IP6, |
| 10075 | 1, |
| 10076 | &adj_o_3000_2), |
| 10077 | "%U via 3000::2", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10078 | format_fib_prefix, &pfx_2001_s_64); |
| 10079 | fei = fib_table_lookup_exact_match(0, &pfx_2001_0_1_s_128); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10080 | FIB_TEST(!fib_test_validate_entry(fei, |
| 10081 | FIB_FORW_CHAIN_TYPE_UNICAST_IP6, |
| 10082 | 1, |
| 10083 | &adj_o_3000_2), |
| 10084 | "%U via 3000::1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10085 | format_fib_prefix, &pfx_2001_0_1_s_128); |
| 10086 | |
| 10087 | fei = fib_table_lookup_exact_match(0, &pfx_2001_1_s_96); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10088 | FIB_TEST(!fib_test_validate_entry(fei, |
| 10089 | FIB_FORW_CHAIN_TYPE_UNICAST_IP6, |
| 10090 | 1, |
| 10091 | &adj_o_3000_1), |
| 10092 | "%U via 3000::1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10093 | format_fib_prefix, &pfx_2001_1_s_96); |
| 10094 | fei = fib_table_lookup_exact_match(0, &pfx_2001_1_1_s_128); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10095 | FIB_TEST(!fib_test_validate_entry(fei, |
| 10096 | FIB_FORW_CHAIN_TYPE_UNICAST_IP6, |
| 10097 | 1, |
| 10098 | &adj_o_3000_1), |
| 10099 | "%U via 3000::1", |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10100 | format_fib_prefix, &pfx_2001_1_1_s_128); |
| 10101 | |
| 10102 | /* |
| 10103 | * Cleanup |
| 10104 | */ |
| 10105 | fib_table_entry_delete(0, &pfx_2001_0_1_s_128, FIB_SOURCE_CLI); |
| 10106 | fib_table_entry_delete(0, &pfx_2001_1_1_s_128, FIB_SOURCE_CLI); |
| 10107 | fib_table_entry_delete(0, &pfx_2001_s_64, FIB_SOURCE_API); |
| 10108 | fib_table_entry_delete(0, &pfx_2001_1_s_96, FIB_SOURCE_API); |
| 10109 | adj_unlock(ai_3000_1); |
| 10110 | adj_unlock(ai_3000_2); |
| 10111 | |
| 10112 | /* |
| 10113 | * test no-one left behind |
| 10114 | */ |
| 10115 | FIB_TEST((n_feis == fib_entry_pool_size()), "Entries gone"); |
| 10116 | FIB_TEST(0 == adj_nbr_db_size(), "All adjacencies removed"); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10117 | |
| 10118 | return (res); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10119 | } |
| 10120 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10121 | static clib_error_t * |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10122 | fib_test (vlib_main_t * vm, |
| 10123 | unformat_input_t * input, |
| 10124 | vlib_cli_command_t * cmd_arg) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10125 | { |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 10126 | int res; |
| 10127 | |
| 10128 | res = 0; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10129 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10130 | fib_test_mk_intf(4); |
| 10131 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 10132 | if (unformat (input, "debug")) |
| 10133 | { |
| 10134 | fib_test_do_debug = 1; |
| 10135 | } |
| 10136 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10137 | if (unformat (input, "ip4")) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10138 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10139 | res += fib_test_v4(); |
| 10140 | } |
| 10141 | else if (unformat (input, "ip6")) |
| 10142 | { |
| 10143 | res += fib_test_v6(); |
| 10144 | } |
| 10145 | else if (unformat (input, "ip")) |
| 10146 | { |
| 10147 | res += fib_test_v4(); |
| 10148 | res += fib_test_v6(); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10149 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10150 | else if (unformat (input, "label")) |
| 10151 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10152 | res += fib_test_label(); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10153 | } |
| 10154 | else if (unformat (input, "ae")) |
| 10155 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10156 | res += fib_test_ae(); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10157 | } |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 10158 | else if (unformat (input, "pref")) |
| 10159 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10160 | res += fib_test_pref(); |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 10161 | } |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 10162 | else if (unformat (input, "lfib")) |
| 10163 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10164 | res += lfib_test(); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 10165 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10166 | else if (unformat (input, "walk")) |
| 10167 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10168 | res += fib_test_walk(); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10169 | } |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 10170 | else if (unformat (input, "bfd")) |
| 10171 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10172 | res += fib_test_bfd(); |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 10173 | } |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10174 | else if (unformat (input, "inherit")) |
| 10175 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10176 | res += fib_test_inherit(); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10177 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10178 | else |
| 10179 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10180 | res += fib_test_v4(); |
| 10181 | res += fib_test_v6(); |
| 10182 | res += fib_test_ae(); |
| 10183 | res += fib_test_bfd(); |
| 10184 | res += fib_test_pref(); |
| 10185 | res += fib_test_label(); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 10186 | res += fib_test_inherit(); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10187 | res += lfib_test(); |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 10188 | |
| 10189 | /* |
| 10190 | * fib-walk process must be disabled in order for the walk tests to work |
| 10191 | */ |
| 10192 | fib_walk_process_disable(); |
| 10193 | res += fib_test_walk(); |
| 10194 | fib_walk_process_enable(); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10195 | } |
| 10196 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 10197 | fflush(NULL); |
Neale Ranns | 0ebe8d7 | 2016-12-08 19:48:11 +0000 | [diff] [blame] | 10198 | if (res) |
| 10199 | { |
| 10200 | return clib_error_return(0, "FIB Unit Test Failed"); |
| 10201 | } |
| 10202 | else |
| 10203 | { |
| 10204 | return (NULL); |
| 10205 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10206 | } |
| 10207 | |
| 10208 | VLIB_CLI_COMMAND (test_fib_command, static) = { |
| 10209 | .path = "test fib", |
| 10210 | .short_help = "fib unit tests - DO NOT RUN ON A LIVE SYSTEM", |
| 10211 | .function = fib_test, |
| 10212 | }; |
| 10213 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 10214 | clib_error_t * |
| 10215 | fib_test_init (vlib_main_t *vm) |
| 10216 | { |
| 10217 | return 0; |
| 10218 | } |
| 10219 | |
| 10220 | VLIB_INIT_FUNCTION (fib_test_init); |