github.com/osrg/gobgp/v3@v3.30.0/test/scenario_test/rtc_test.py (about) 1 # Copyright (C) 2016 Nippon Telegraph and Telephone Corporation. 2 # 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 12 # implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 17 from itertools import combinations 18 import sys 19 import time 20 import unittest 21 22 import collections 23 collections.Callable = collections.abc.Callable 24 25 import nose 26 27 from lib.noseplugin import OptionParser, parser_option 28 29 from lib import base 30 from lib.base import BGP_FSM_ESTABLISHED, local 31 from lib.gobgp import GoBGPContainer 32 33 34 class GoBGPTestBase(unittest.TestCase): 35 36 def assert_adv_count(self, src, dst, rf, count): 37 self.assertEqual(count, len(src.get_adj_rib_out(dst, rf=rf))) 38 self.assertEqual(count, len(dst.get_adj_rib_in(src, rf=rf))) 39 40 def assert_upd_count(self, src, dst, sent, received): 41 messages = src.get_neighbor(dst)['state']['messages'] 42 self.assertEqual(messages['sent'].get('update', 0), sent) 43 self.assertEqual(messages['received'].get('update', 0), received) 44 45 @classmethod 46 def setUpClass(cls): 47 # +----+ +----+ 48 # | g1 |----(iBGP)----| g2 | 49 # +----+ +----+ 50 gobgp_ctn_image_name = parser_option.gobgp_image 51 base.TEST_PREFIX = parser_option.test_prefix 52 53 g1 = GoBGPContainer(name='g1', asn=65000, router_id='192.168.0.1', 54 ctn_image_name=gobgp_ctn_image_name, 55 log_level=parser_option.gobgp_log_level) 56 g2 = GoBGPContainer(name='g2', asn=65000, router_id='192.168.0.2', 57 ctn_image_name=gobgp_ctn_image_name, 58 log_level=parser_option.gobgp_log_level) 59 60 time.sleep(max(ctn.run() for ctn in [g1, g2])) 61 62 g1.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 63 g1.local("gobgp vrf add vrf2 rd 200:200 rt both 200:200") 64 g2.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 65 g2.local("gobgp vrf add vrf3 rd 300:300 rt both 300:300") 66 67 g1.local("gobgp vrf vrf1 rib add 10.0.0.0/24") 68 g1.local("gobgp vrf vrf2 rib add 10.0.0.0/24") 69 g2.local("gobgp vrf vrf1 rib add 20.0.0.0/24") 70 g2.local("gobgp vrf vrf3 rib add 20.0.0.0/24") 71 72 cls.g1 = g1 73 cls.g2 = g2 74 75 # Test the problem which was reported on #1682 76 # https://github.com/osrg/gobgp/issues/1682 77 def test_01_neighbor_estabslihed_with_conflict_rtc_config(self): 78 self.g1.add_peer(self.g2, vpn=True, passwd='rtc', graceful_restart=True) 79 self.g2.add_peer(self.g1, vpn=False, passwd='rtc', graceful_restart=True) 80 self.g1.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g2) 81 82 # test each neighbor state is turned establish 83 def test_02_neighbor_established(self): 84 self.g2.update_peer(self.g1, vpn=True, passwd='rtc', graceful_restart=True) 85 self.g1.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g2) 86 87 def test_03_check_adj_rib(self): 88 # VRF<#> g1 g2 89 # 1 (*) (*) 90 # 2 (*) 91 # 3 (*) 92 # 93 # ( ): Empty VRF (*): VRF with a route 94 self.assert_adv_count(self.g1, self.g2, 'rtc', 2) 95 self.assert_adv_count(self.g1, self.g2, 'ipv4-l3vpn', 1) 96 97 self.assert_adv_count(self.g2, self.g1, 'rtc', 2) 98 self.assert_adv_count(self.g2, self.g1, 'ipv4-l3vpn', 1) 99 100 def test_04_add_vrf(self): 101 # VRF<#> g1 g2 102 # 1 (*) (*) 103 # 2 (*) 104 # 3 ( ) (*) 105 self.g1.local("gobgp vrf add vrf3 rd 300:300 rt both 300:300") 106 time.sleep(1) 107 108 self.assert_adv_count(self.g1, self.g2, 'rtc', 3) 109 self.assert_adv_count(self.g1, self.g2, 'ipv4-l3vpn', 1) 110 111 self.assert_adv_count(self.g2, self.g1, 'rtc', 2) 112 self.assert_adv_count(self.g2, self.g1, 'ipv4-l3vpn', 2) 113 114 def test_05_add_route_on_vrf(self): 115 # VRF<#> g1 g2 116 # 1 (*) (*) 117 # 2 (*) 118 # 3 (*) (*) 119 self.g1.local("gobgp vrf vrf3 rib add 10.0.0.0/24") 120 time.sleep(1) 121 122 self.assert_adv_count(self.g1, self.g2, 'rtc', 3) 123 self.assert_adv_count(self.g1, self.g2, 'ipv4-l3vpn', 2) 124 125 self.assert_adv_count(self.g2, self.g1, 'rtc', 2) 126 self.assert_adv_count(self.g2, self.g1, 'ipv4-l3vpn', 2) 127 128 def test_06_del_route_on_vrf(self): 129 # VRF<#> g1 g2 130 # 1 (*) (*) 131 # 2 (*) 132 # 3 ( ) (*) 133 self.g1.local("gobgp vrf vrf3 rib del 10.0.0.0/24") 134 time.sleep(1) 135 136 self.assert_adv_count(self.g1, self.g2, 'rtc', 3) 137 self.assert_adv_count(self.g1, self.g2, 'ipv4-l3vpn', 1) 138 139 self.assert_adv_count(self.g2, self.g1, 'rtc', 2) 140 self.assert_adv_count(self.g2, self.g1, 'ipv4-l3vpn', 2) 141 142 def test_07_del_vrf(self): 143 # VRF<#> g1 g2 144 # 1 (*) (*) 145 # 2 (*) 146 # 3 (*) 147 self.g1.local("gobgp vrf del vrf3") 148 time.sleep(1) 149 150 self.assert_adv_count(self.g1, self.g2, 'rtc', 2) 151 self.assert_adv_count(self.g1, self.g2, 'ipv4-l3vpn', 1) 152 153 self.assert_adv_count(self.g2, self.g1, 'rtc', 2) 154 self.assert_adv_count(self.g2, self.g1, 'ipv4-l3vpn', 1) 155 156 def test_08_del_vrf_with_route(self): 157 # VRF<#> g1 g2 158 # 1 (*) 159 # 2 (*) 160 # 3 (*) 161 self.g1.local("gobgp vrf del vrf1") 162 time.sleep(1) 163 164 self.assert_adv_count(self.g1, self.g2, 'rtc', 1) 165 self.assert_adv_count(self.g1, self.g2, 'ipv4-l3vpn', 0) 166 167 self.assert_adv_count(self.g2, self.g1, 'rtc', 2) 168 self.assert_adv_count(self.g2, self.g1, 'ipv4-l3vpn', 0) 169 170 def test_09_cleanup(self): 171 self.g1.local("gobgp vrf del vrf2") 172 self.g2.local("gobgp vrf del vrf1") 173 self.g2.local("gobgp vrf del vrf3") 174 175 def test_10_rr_setup(self): 176 # +------+ 177 # | g3 | 178 # +------| (RR) |------+ 179 # | +------+ | 180 # (iBGP) (iBGP) 181 # | | 182 # +-------------+ +-------------+ 183 # | g4 | | g5 | 184 # | (RR Client) | | (RR Client) | 185 # +-------------+ +-------------+ 186 gobgp_ctn_image_name = parser_option.gobgp_image 187 g3 = GoBGPContainer(name='g3', asn=65000, router_id='192.168.0.3', 188 ctn_image_name=gobgp_ctn_image_name, 189 log_level=parser_option.gobgp_log_level) 190 g4 = GoBGPContainer(name='g4', asn=65000, router_id='192.168.0.4', 191 ctn_image_name=gobgp_ctn_image_name, 192 log_level=parser_option.gobgp_log_level) 193 g5 = GoBGPContainer(name='g5', asn=65000, router_id='192.168.0.5', 194 ctn_image_name=gobgp_ctn_image_name, 195 log_level=parser_option.gobgp_log_level) 196 197 time.sleep(max(ctn.run() for ctn in [g3, g4, g5])) 198 199 g3.add_peer(g4, vpn=True, is_rr_client=True) 200 g4.add_peer(g3, vpn=True) 201 202 g3.add_peer(g5, vpn=True, is_rr_client=True) 203 g5.add_peer(g3, vpn=True) 204 205 g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g4) 206 g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g5) 207 208 self.__class__.g3 = g3 209 self.__class__.g4 = g4 210 self.__class__.g5 = g5 211 212 def test_11_rr_check_adj_rib_from_rr(self): 213 # VRF<#> g3 g4 g5 214 # 1 ( ) ( ) 215 # 2 216 # 3 217 self.g4.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 218 self.g5.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 219 time.sleep(1) 220 221 # Check the counts of the sent UPDATE messages in order to detect the 222 # infinite RTC UPDATE loop. 223 # https://github.com/osrg/gobgp/issues/1630 224 self.assert_upd_count(self.g4, self.g3, sent=1, received=2) 225 self.assert_upd_count(self.g5, self.g3, sent=1, received=2) 226 227 def check_rtc(client): 228 rib = self.g3.get_adj_rib_out(client, rf='rtc') 229 self.assertEqual(1, len(rib)) 230 path = rib[0] 231 self.assertEqual(self.g3.peers[client]['local_addr'].split('/')[0], path['nexthop']) 232 ids = [attr['value'] for attr in path['attrs'] if attr['type'] == base.BGP_ATTR_TYPE_ORIGINATOR_ID] 233 self.assertEqual(1, len(ids)) 234 self.assertEqual(self.g3.router_id, ids[0]) 235 236 check_rtc(self.g4) 237 check_rtc(self.g5) 238 239 # VRF<#> g3 g4 g5 240 # 1 (*) (*) 241 # 2 242 # 3 243 self.g4.local("gobgp vrf vrf1 rib add 40.0.0.0/24") 244 self.g5.local("gobgp vrf vrf1 rib add 50.0.0.0/24") 245 time.sleep(1) 246 247 def check_ipv4_l3vpn(client): 248 rib = self.g3.get_adj_rib_out(client, rf='ipv4-l3vpn') 249 self.assertEqual(1, len(rib)) 250 path = rib[0] 251 self.assertNotEqual(self.g3.peers[client]['local_addr'].split('/')[0], path['nexthop']) 252 ids = [attr['value'] for attr in path['attrs'] if attr['type'] == base.BGP_ATTR_TYPE_ORIGINATOR_ID] 253 self.assertEqual(1, len(ids)) 254 self.assertNotEqual(client.router_id, ids[0]) 255 256 check_ipv4_l3vpn(self.g4) 257 check_ipv4_l3vpn(self.g5) 258 259 def test_12_rr_add_vrf(self): 260 # VRF<#> g3 g4 g5 261 # 1 (*) (*) 262 # 2 ( ) 263 # 3 264 self.g4.local("gobgp vrf add vrf2 rd 200:200 rt both 200:200") 265 time.sleep(1) 266 267 self.assert_adv_count(self.g4, self.g3, 'rtc', 2) 268 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 1) 269 270 self.assert_adv_count(self.g3, self.g4, 'rtc', 2) 271 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 1) 272 273 self.assert_adv_count(self.g5, self.g3, 'rtc', 1) 274 self.assert_adv_count(self.g5, self.g3, 'ipv4-l3vpn', 1) 275 276 self.assert_adv_count(self.g3, self.g5, 'rtc', 2) 277 self.assert_adv_count(self.g3, self.g5, 'ipv4-l3vpn', 1) 278 279 def test_13_rr_add_route_on_vrf(self): 280 # VRF<#> g3 g4 g5 281 # 1 (*) (*) 282 # 2 (*) 283 # 3 284 self.g4.local("gobgp vrf vrf2 rib add 40.0.0.0/24") 285 time.sleep(1) 286 287 self.assert_adv_count(self.g4, self.g3, 'rtc', 2) 288 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 2) 289 290 self.assert_adv_count(self.g3, self.g4, 'rtc', 2) 291 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 1) 292 293 self.assert_adv_count(self.g5, self.g3, 'rtc', 1) 294 self.assert_adv_count(self.g5, self.g3, 'ipv4-l3vpn', 1) 295 296 self.assert_adv_count(self.g3, self.g5, 'rtc', 2) 297 self.assert_adv_count(self.g3, self.g5, 'ipv4-l3vpn', 1) 298 299 def test_14_rr_del_vrf_with_route(self): 300 # VRF<#> g3 g4 g5 301 # 1 (*) 302 # 2 (*) 303 # 3 304 self.g4.local("gobgp vrf del vrf1") 305 time.sleep(1) 306 307 self.assert_adv_count(self.g4, self.g3, 'rtc', 1) 308 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 1) 309 310 self.assert_adv_count(self.g3, self.g4, 'rtc', 2) 311 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 0) 312 313 self.assert_adv_count(self.g5, self.g3, 'rtc', 1) 314 self.assert_adv_count(self.g5, self.g3, 'ipv4-l3vpn', 1) 315 316 self.assert_adv_count(self.g3, self.g5, 'rtc', 2) 317 self.assert_adv_count(self.g3, self.g5, 'ipv4-l3vpn', 0) 318 319 def test_15_rr_cleanup(self): 320 self.g4.local("gobgp vrf del vrf2") 321 self.g5.local("gobgp vrf del vrf1") 322 323 def test_20_rr_and_non_rr_setup(self): 324 # +----------+ +----------+ 325 # | g1 |---(iBGP)---| g2 | 326 # | (Non RR | | (Non RR | 327 # | Client) | | Client) | 328 # +----------+ +----------+ 329 # | | 330 # +--(iBGP)--+ +--(iBGP)--+ 331 # | | 332 # +------+ 333 # | g3 | 334 # +------| (RR) |------+ 335 # | +------+ | 336 # (iBGP) (iBGP) 337 # | | 338 # +-------------+ +-------------+ 339 # | g4 | | g5 | 340 # | (RR Client) | | (RR Client) | 341 # +-------------+ +-------------+ 342 self.g3.add_peer(self.g1, vpn=True) 343 self.g1.add_peer(self.g3, vpn=True) 344 self.g3.add_peer(self.g2, vpn=True) 345 self.g2.add_peer(self.g3, vpn=True) 346 347 self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g1) 348 self.g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.g2) 349 350 def test_21_rr_and_non_rr_add_vrf_on_rr_clients(self): 351 # VRF<#> g1 g2 g3 g4 g5 352 # 1 (*) (*) 353 # 2 354 # 3 355 self.g4.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 356 self.g5.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 357 self.g4.local("gobgp vrf vrf1 rib add 40.0.0.0/24") 358 self.g5.local("gobgp vrf vrf1 rib add 50.0.0.0/24") 359 time.sleep(1) 360 361 self.assert_adv_count(self.g4, self.g3, 'rtc', 1) 362 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 1) 363 364 self.assert_adv_count(self.g3, self.g1, 'rtc', 1) 365 self.assert_adv_count(self.g3, self.g1, 'ipv4-l3vpn', 0) 366 367 self.assert_adv_count(self.g1, self.g3, 'rtc', 0) 368 self.assert_adv_count(self.g1, self.g3, 'ipv4-l3vpn', 0) 369 370 self.assert_adv_count(self.g3, self.g4, 'rtc', 1) 371 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 1) 372 373 def test_22_rr_and_non_rr_add_vrf_on_non_rr_client(self): 374 # VRF<#> g1 g2 g3 g4 g5 375 # 1 (*) (*) (*) 376 # 2 377 # 3 378 self.g1.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 379 self.g1.local("gobgp vrf vrf1 rib add 10.0.0.0/24") 380 time.sleep(1) 381 382 self.assert_adv_count(self.g4, self.g3, 'rtc', 1) 383 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 1) 384 385 self.assert_adv_count(self.g5, self.g3, 'rtc', 1) 386 self.assert_adv_count(self.g5, self.g3, 'ipv4-l3vpn', 1) 387 388 self.assert_adv_count(self.g3, self.g1, 'rtc', 1) 389 self.assert_adv_count(self.g3, self.g1, 'ipv4-l3vpn', 2) 390 391 self.assert_adv_count(self.g3, self.g2, 'rtc', 1) 392 self.assert_adv_count(self.g3, self.g2, 'ipv4-l3vpn', 0) 393 394 self.assert_adv_count(self.g1, self.g3, 'rtc', 1) 395 self.assert_adv_count(self.g1, self.g3, 'ipv4-l3vpn', 1) 396 397 self.assert_adv_count(self.g2, self.g3, 'rtc', 0) 398 self.assert_adv_count(self.g2, self.g3, 'ipv4-l3vpn', 0) 399 400 self.assert_adv_count(self.g3, self.g4, 'rtc', 1) 401 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 2) 402 403 self.assert_adv_count(self.g3, self.g5, 'rtc', 1) 404 self.assert_adv_count(self.g3, self.g5, 'ipv4-l3vpn', 2) 405 406 def test_23_rr_and_non_rr_add_another_vrf_on_non_rr_client(self): 407 # VRF<#> g1 g2 g3 g4 g5 408 # 1 (*) (*) (*) 409 # 2 (*) 410 # 3 411 self.g2.local("gobgp vrf add vrf2 rd 200:200 rt both 200:200") 412 self.g2.local("gobgp vrf vrf2 rib add 20.0.0.0/24") 413 time.sleep(1) 414 415 self.assert_adv_count(self.g4, self.g3, 'rtc', 1) 416 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 1) 417 418 self.assert_adv_count(self.g5, self.g3, 'rtc', 1) 419 self.assert_adv_count(self.g5, self.g3, 'ipv4-l3vpn', 1) 420 421 self.assert_adv_count(self.g3, self.g1, 'rtc', 1) 422 self.assert_adv_count(self.g3, self.g1, 'ipv4-l3vpn', 2) 423 424 self.assert_adv_count(self.g3, self.g2, 'rtc', 1) 425 self.assert_adv_count(self.g3, self.g2, 'ipv4-l3vpn', 0) 426 427 self.assert_adv_count(self.g1, self.g3, 'rtc', 1) 428 self.assert_adv_count(self.g1, self.g3, 'ipv4-l3vpn', 1) 429 430 self.assert_adv_count(self.g2, self.g3, 'rtc', 1) 431 self.assert_adv_count(self.g2, self.g3, 'ipv4-l3vpn', 0) 432 433 self.assert_adv_count(self.g3, self.g4, 'rtc', 2) 434 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 2) 435 436 self.assert_adv_count(self.g3, self.g5, 'rtc', 2) 437 self.assert_adv_count(self.g3, self.g5, 'ipv4-l3vpn', 2) 438 439 def test_24_rr_and_non_rr_add_another_vrf_on_rr_client(self): 440 # VRF<#> g1 g2 g3 g4 g5 441 # 1 (*) (*) (*) 442 # 2 (*) (*) 443 # 3 444 self.g4.local("gobgp vrf add vrf2 rd 200:200 rt both 200:200") 445 self.g4.local("gobgp vrf vrf2 rib add 40.0.0.0/24") 446 time.sleep(1) 447 448 self.assert_adv_count(self.g4, self.g3, 'rtc', 2) 449 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 2) 450 451 self.assert_adv_count(self.g5, self.g3, 'rtc', 1) 452 self.assert_adv_count(self.g5, self.g3, 'ipv4-l3vpn', 1) 453 454 self.assert_adv_count(self.g3, self.g1, 'rtc', 2) 455 self.assert_adv_count(self.g3, self.g1, 'ipv4-l3vpn', 2) 456 457 self.assert_adv_count(self.g3, self.g2, 'rtc', 2) 458 self.assert_adv_count(self.g3, self.g2, 'ipv4-l3vpn', 1) 459 460 self.assert_adv_count(self.g1, self.g3, 'rtc', 1) 461 self.assert_adv_count(self.g1, self.g3, 'ipv4-l3vpn', 1) 462 463 self.assert_adv_count(self.g2, self.g3, 'rtc', 1) 464 self.assert_adv_count(self.g2, self.g3, 'ipv4-l3vpn', 1) 465 466 self.assert_adv_count(self.g3, self.g4, 'rtc', 2) 467 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 3) 468 469 self.assert_adv_count(self.g3, self.g5, 'rtc', 2) 470 self.assert_adv_count(self.g3, self.g5, 'ipv4-l3vpn', 2) 471 472 def test_25_rr_and_non_rr_clenup(self): 473 self.g1.local("gobgp vrf del vrf1") 474 self.g2.local("gobgp vrf del vrf2") 475 self.g4.local("gobgp vrf del vrf1") 476 self.g4.local("gobgp vrf del vrf2") 477 self.g5.local("gobgp vrf del vrf1") 478 479 def test_30_ebgp_setup(self): 480 # +----+ +----+ 481 # | g6 |----(eBGP)----| g7 | 482 # +----+ +----+ 483 gobgp_ctn_image_name = parser_option.gobgp_image 484 g6 = GoBGPContainer(name='g6', asn=65001, router_id='192.168.0.6', 485 ctn_image_name=gobgp_ctn_image_name, 486 log_level=parser_option.gobgp_log_level) 487 g7 = GoBGPContainer(name='g7', asn=65002, router_id='192.168.0.7', 488 ctn_image_name=gobgp_ctn_image_name, 489 log_level=parser_option.gobgp_log_level) 490 491 time.sleep(max(ctn.run() for ctn in [g6, g7])) 492 493 g6.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 494 g6.local("gobgp vrf add vrf2 rd 200:200 rt both 200:200") 495 g7.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 496 g7.local("gobgp vrf add vrf3 rd 300:300 rt both 300:300") 497 498 g6.local("gobgp vrf vrf1 rib add 60.0.0.0/24") 499 g6.local("gobgp vrf vrf2 rib add 60.0.0.0/24") 500 g7.local("gobgp vrf vrf1 rib add 70.0.0.0/24") 501 g7.local("gobgp vrf vrf3 rib add 70.0.0.0/24") 502 503 for a, b in combinations([g6, g7], 2): 504 a.add_peer(b, vpn=True, passwd='rtc', graceful_restart=True) 505 b.add_peer(a, vpn=True, passwd='rtc', graceful_restart=True) 506 507 g6.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g7) 508 509 self.__class__.g6 = g6 510 self.__class__.g7 = g7 511 512 def test_31_ebgp_check_adj_rib(self): 513 # VRF<#> g6 g7 514 # 1 (*) (*) 515 # 2 (*) 516 # 3 (*) 517 self.assert_adv_count(self.g6, self.g7, 'rtc', 2) 518 self.assert_adv_count(self.g6, self.g7, 'ipv4-l3vpn', 1) 519 520 self.assert_adv_count(self.g7, self.g6, 'rtc', 2) 521 self.assert_adv_count(self.g7, self.g6, 'ipv4-l3vpn', 1) 522 523 def test_32_ebgp_add_vrf(self): 524 # VRF<#> g6 g7 525 # 1 (*) (*) 526 # 2 (*) 527 # 3 ( ) (*) 528 self.g6.local("gobgp vrf add vrf3 rd 300:300 rt both 300:300") 529 time.sleep(1) 530 531 self.assert_adv_count(self.g6, self.g7, 'rtc', 3) 532 self.assert_adv_count(self.g6, self.g7, 'ipv4-l3vpn', 1) 533 534 self.assert_adv_count(self.g7, self.g6, 'rtc', 2) 535 self.assert_adv_count(self.g7, self.g6, 'ipv4-l3vpn', 2) 536 537 def test_33_ebgp_add_route_on_vrf(self): 538 # VRF<#> g6 g7 539 # 1 (*) (*) 540 # 2 (*) 541 # 3 (*) (*) 542 self.g6.local("gobgp vrf vrf3 rib add 60.0.0.0/24") 543 time.sleep(1) 544 545 self.assert_adv_count(self.g6, self.g7, 'rtc', 3) 546 self.assert_adv_count(self.g6, self.g7, 'ipv4-l3vpn', 2) 547 548 self.assert_adv_count(self.g7, self.g6, 'rtc', 2) 549 self.assert_adv_count(self.g7, self.g6, 'ipv4-l3vpn', 2) 550 551 def test_34_ebgp_del_route_on_vrf(self): 552 # VRF<#> g6 g7 553 # 1 (*) (*) 554 # 2 (*) 555 # 3 ( ) (*) 556 self.g6.local("gobgp vrf vrf3 rib del 60.0.0.0/24") 557 time.sleep(1) 558 559 self.assert_adv_count(self.g6, self.g7, 'rtc', 3) 560 self.assert_adv_count(self.g6, self.g7, 'ipv4-l3vpn', 1) 561 562 self.assert_adv_count(self.g7, self.g6, 'rtc', 2) 563 self.assert_adv_count(self.g7, self.g6, 'ipv4-l3vpn', 2) 564 565 def test_35_ebgp_del_vrf(self): 566 # VRF<#> g6 g7 567 # 1 (*) (*) 568 # 2 (*) 569 # 3 (*) 570 self.g6.local("gobgp vrf del vrf3") 571 time.sleep(1) 572 573 self.assert_adv_count(self.g6, self.g7, 'rtc', 2) 574 self.assert_adv_count(self.g6, self.g7, 'ipv4-l3vpn', 1) 575 576 self.assert_adv_count(self.g7, self.g6, 'rtc', 2) 577 self.assert_adv_count(self.g7, self.g6, 'ipv4-l3vpn', 1) 578 579 def test_36_ebgp_del_vrf_with_route(self): 580 # VRF<#> g6 g7 581 # 1 (*) 582 # 2 (*) 583 # 3 (*) 584 self.g6.local("gobgp vrf del vrf1") 585 time.sleep(1) 586 587 self.assert_adv_count(self.g6, self.g7, 'rtc', 1) 588 self.assert_adv_count(self.g6, self.g7, 'ipv4-l3vpn', 0) 589 590 self.assert_adv_count(self.g7, self.g6, 'rtc', 2) 591 self.assert_adv_count(self.g7, self.g6, 'ipv4-l3vpn', 0) 592 593 def test_37_ebgp_cleanup(self): 594 self.g6.local("gobgp vrf del vrf2") 595 self.g7.local("gobgp vrf del vrf1") 596 self.g7.local("gobgp vrf del vrf3") 597 598 def test_40_ibgp_ebgp_setup(self): 599 # +----------+ +----------+ 600 # | g1 |---(iBGP)---| g2 | 601 # | (Non RR | | (Non RR | 602 # | Client) | | Client) | 603 # +----------+ +----------+ 604 # | | 605 # +--(iBGP)--+ +--(iBGP)--+ 606 # | | 607 # +------+ +----+ +----+ 608 # | g3 |----------(eBGP)----| g6 |----(eBGP)----| g7 | 609 # +------| (RR) |------+ +----+ +----+ 610 # | +------+ | 611 # (iBGP) (iBGP) 612 # | | 613 # +-------------+ +-------------+ 614 # | g4 | | g5 | 615 # | (RR Client) | | (RR Client) | 616 # +-------------+ +-------------+ 617 g1, g2, g3, g4, g5, g6, g7 = ( 618 self.g1, self.g2, self.g3, self.g4, self.g5, self.g6, self.g7) 619 g3.add_peer(g6, vpn=True) 620 g6.add_peer(g3, vpn=True) 621 622 g1.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 623 g2.local("gobgp vrf add vrf2 rd 200:200 rt both 200:200") 624 # g3 (RR) 625 g4.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 626 g5.local("gobgp vrf add vrf2 rd 200:200 rt both 200:200") 627 g6.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 628 g7.local("gobgp vrf add vrf3 rd 300:300 rt both 300:300") 629 630 g1.local("gobgp vrf vrf1 rib add 10.0.0.0/24") 631 g2.local("gobgp vrf vrf2 rib add 20.0.0.0/24") 632 # g3 (RR) 633 g4.local("gobgp vrf vrf1 rib add 40.0.0.0/24") 634 g5.local("gobgp vrf vrf2 rib add 50.0.0.0/24") 635 g6.local("gobgp vrf vrf1 rib add 60.0.0.0/24") 636 g7.local("gobgp vrf vrf3 rib add 70.0.0.0/24") 637 638 g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g6) 639 640 def test_41_ibgp_ebgp_check_adj_rib(self): 641 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 642 # 1 (*) (*) | (*) 643 # 2 (*) (*) | 644 # 3 | (*) 645 self.assert_adv_count(self.g3, self.g6, 'rtc', 2) 646 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 2) 647 648 self.assert_adv_count(self.g6, self.g3, 'rtc', 2) 649 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 1) 650 651 def test_42_01_ibgp_ebgp_add_vrf_on_rr_client(self): 652 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 653 # 1 (*) (*) | (*) 654 # 2 (*) (*) | 655 # 3 ( ) | (*) 656 self.g5.local("gobgp vrf add vrf3 rd 300:300 rt both 300:300") 657 time.sleep(1) 658 659 self.assert_adv_count(self.g3, self.g6, 'rtc', 3) 660 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 2) 661 662 self.assert_adv_count(self.g6, self.g3, 'rtc', 2) 663 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 2) 664 665 def test_42_02_ibgp_ebgp_add_route_on_vrf_on_rr_client(self): 666 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 667 # 1 (*) (*) | (*) 668 # 2 (*) (*) | 669 # 3 (*) | (*) 670 self.g5.local("gobgp vrf vrf3 rib add 50.0.0.0/24") 671 time.sleep(1) 672 673 self.assert_adv_count(self.g3, self.g6, 'rtc', 3) 674 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 3) 675 676 self.assert_adv_count(self.g6, self.g3, 'rtc', 2) 677 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 2) 678 679 def test_42_03_ibgp_ebgp_del_route_on_vrf_on_rr_client(self): 680 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 681 # 1 (*) (*) | (*) 682 # 2 (*) (*) | 683 # 3 ( ) | (*) 684 self.g5.local("gobgp vrf vrf3 rib del 50.0.0.0/24") 685 time.sleep(1) 686 687 self.assert_adv_count(self.g3, self.g6, 'rtc', 3) 688 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 2) 689 690 self.assert_adv_count(self.g6, self.g3, 'rtc', 2) 691 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 2) 692 693 def test_42_04_ibgp_ebgp_del_vrf_on_rr_client(self): 694 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 695 # 1 (*) (*) | (*) 696 # 2 (*) (*) | 697 # 3 | (*) 698 self.g5.local("gobgp vrf del vrf3") 699 time.sleep(2) 700 701 self.assert_adv_count(self.g3, self.g6, 'rtc', 2) 702 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 2) 703 704 self.assert_adv_count(self.g6, self.g3, 'rtc', 2) 705 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 1) 706 707 def test_43_01_ibgp_ebgp_add_vrf_on_non_rr_client(self): 708 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 709 # 1 (*) (*) | (*) 710 # 2 (*) (*) | 711 # 3 ( ) | (*) 712 self.g1.local("gobgp vrf add vrf3 rd 300:300 rt both 300:300") 713 time.sleep(1) 714 715 self.assert_adv_count(self.g3, self.g6, 'rtc', 3) 716 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 2) 717 718 self.assert_adv_count(self.g6, self.g3, 'rtc', 2) 719 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 2) 720 721 def test_43_02_ibgp_ebgp_add_route_on_vrf_on_non_rr_client(self): 722 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 723 # 1 (*) (*) | (*) 724 # 2 (*) (*) | 725 # 3 (*) | (*) 726 self.g1.local("gobgp vrf vrf3 rib add 10.0.0.0/24") 727 time.sleep(1) 728 729 self.assert_adv_count(self.g3, self.g6, 'rtc', 3) 730 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 3) 731 732 self.assert_adv_count(self.g6, self.g3, 'rtc', 2) 733 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 2) 734 735 def test_43_03_ibgp_ebgp_del_route_on_vrf_on_non_rr_client(self): 736 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 737 # 1 (*) (*) | (*) 738 # 2 (*) (*) | 739 # 3 ( ) | (*) 740 self.g1.local("gobgp vrf vrf3 rib del 10.0.0.0/24") 741 time.sleep(1) 742 743 self.assert_adv_count(self.g3, self.g6, 'rtc', 3) 744 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 2) 745 746 self.assert_adv_count(self.g6, self.g3, 'rtc', 2) 747 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 2) 748 749 def test_43_04_ibgp_ebgp_del_vrf_on_non_rr_client(self): 750 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 751 # 1 (*) (*) | (*) 752 # 2 (*) (*) | 753 # 3 | (*) 754 self.g1.local("gobgp vrf del vrf3") 755 time.sleep(2) 756 757 self.assert_adv_count(self.g3, self.g6, 'rtc', 2) 758 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 2) 759 760 self.assert_adv_count(self.g6, self.g3, 'rtc', 2) 761 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 1) 762 763 def test_44_01_ibgp_ebgp_add_vrf_on_ebgp_peer(self): 764 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 765 # 1 (*) (*) | (*) 766 # 2 (*) (*) | ( ) 767 # 3 | (*) 768 self.g7.local("gobgp vrf add vrf2 rd 200:200 rt both 200:200") 769 time.sleep(1) 770 771 self.assert_adv_count(self.g3, self.g6, 'rtc', 2) 772 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 4) 773 774 self.assert_adv_count(self.g6, self.g3, 'rtc', 3) 775 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 1) 776 777 def test_44_02_ibgp_ebgp_add_route_on_ebgp_peer(self): 778 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 779 # 1 (*) (*) | (*) 780 # 2 (*) (*) | (*) 781 # 3 | (*) 782 self.g7.local("gobgp vrf vrf2 rib add 70.0.0.0/24") 783 time.sleep(1) 784 785 self.assert_adv_count(self.g3, self.g6, 'rtc', 2) 786 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 4) 787 788 self.assert_adv_count(self.g6, self.g3, 'rtc', 3) 789 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 2) 790 791 def test_44_03_ibgp_ebgp_del_route_on_vrf_on_ebgp_peer(self): 792 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 793 # 1 (*) (*) | (*) 794 # 2 (*) (*) | ( ) 795 # 3 | (*) 796 self.g7.local("gobgp vrf vrf2 rib del 70.0.0.0/24") 797 time.sleep(1) 798 799 self.assert_adv_count(self.g3, self.g6, 'rtc', 2) 800 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 4) 801 802 self.assert_adv_count(self.g6, self.g3, 'rtc', 3) 803 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 1) 804 805 def test_44_04_ibgp_ebgp_del_vrf_on_ebgp_peer(self): 806 # VRF<#> g1 g2 g3 g4 g5 | g6 g7 807 # 1 (*) (*) | (*) 808 # 2 (*) (*) | 809 # 3 | (*) 810 self.g7.local("gobgp vrf del vrf2") 811 time.sleep(2) 812 813 self.assert_adv_count(self.g3, self.g6, 'rtc', 2) 814 self.assert_adv_count(self.g3, self.g6, 'ipv4-l3vpn', 2) 815 816 self.assert_adv_count(self.g6, self.g3, 'rtc', 2) 817 self.assert_adv_count(self.g6, self.g3, 'ipv4-l3vpn', 1) 818 819 def test_45_ibgp_ebgp_cleanup(self): 820 self.g1.local("gobgp vrf del vrf1") 821 self.g2.local("gobgp vrf del vrf2") 822 self.g4.local("gobgp vrf del vrf1") 823 self.g5.local("gobgp vrf del vrf2") 824 self.g6.local("gobgp vrf del vrf1") 825 self.g7.local("gobgp vrf del vrf3") 826 827 def test_50_rr_addpath_setup(self): 828 # Test cases for the infinite RTC UPDATE message loop: 829 # https://github.com/osrg/gobgp/issues/1688#issuecomment-391456615 830 # https://github.com/osrg/gobgp/pull/1703 831 832 # +------+ 833 # | g3 | 834 # +------| (RR) |------+ 835 # | +------+ | 836 # (iBGP+Add-Paths) (iBGP+Add-Paths) 837 # | | 838 # +-------------+ +-------------+ 839 # | g4 | | g5 | 840 # | (RR Client) | | (RR Client) | 841 # +-------------+ +-------------+ 842 g3, g4, g5 = self.g3, self.g4, self.g5 843 844 g3.update_peer(g4, vpn=True, addpath=16, is_rr_client=True) 845 g4.update_peer(g3, vpn=True, addpath=16) 846 847 g3.update_peer(g5, vpn=True, addpath=16, is_rr_client=True) 848 g5.update_peer(g3, vpn=True, addpath=16) 849 850 g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g4) 851 g3.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=g5) 852 853 def test_51_rr_addpath_check_adj_rib_from_rr(self): 854 # VRF<#> g3 g4 g5 855 # 1 ( ) ( ) 856 # 2 857 # 3 858 self.g4.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 859 self.g5.local("gobgp vrf add vrf1 rd 100:100 rt both 100:100") 860 time.sleep(1) 861 862 # Check the counts of the sent UPDATE messages in order to detect the 863 # infinite RTC UPDATE loop. 864 self.assert_upd_count(self.g4, self.g3, sent=1, received=2) 865 self.assert_upd_count(self.g5, self.g3, sent=1, received=2) 866 867 def check_rtc(client): 868 rib = self.g3.get_adj_rib_out(client, rf='rtc') 869 self.assertEqual(1, len(rib)) 870 path = rib[0] 871 self.assertEqual(self.g3.peers[client]['local_addr'].split('/')[0], path['nexthop']) 872 ids = [attr['value'] for attr in path['attrs'] if attr['type'] == base.BGP_ATTR_TYPE_ORIGINATOR_ID] 873 self.assertEqual(1, len(ids)) 874 self.assertEqual(self.g3.router_id, ids[0]) 875 876 check_rtc(self.g4) 877 check_rtc(self.g5) 878 879 # VRF<#> g3 g4 g5 880 # 1 (*) (*) 881 # 2 882 # 3 883 self.g4.local("gobgp vrf vrf1 rib add 40.0.0.0/24") 884 self.g5.local("gobgp vrf vrf1 rib add 50.0.0.0/24") 885 time.sleep(1) 886 887 def check_ipv4_l3vpn(client): 888 rib = self.g3.get_adj_rib_out(client, rf='ipv4-l3vpn') 889 self.assertEqual(1, len(rib)) 890 path = rib[0] 891 self.assertNotEqual(self.g3.peers[client]['local_addr'].split('/')[0], path['nexthop']) 892 ids = [attr['value'] for attr in path['attrs'] if attr['type'] == base.BGP_ATTR_TYPE_ORIGINATOR_ID] 893 self.assertEqual(1, len(ids)) 894 self.assertNotEqual(client.router_id, ids[0]) 895 896 check_ipv4_l3vpn(self.g4) 897 check_ipv4_l3vpn(self.g5) 898 899 def test_52_rr_addpath_add_vrf(self): 900 # VRF<#> g3 g4 g5 901 # 1 (*) (*) 902 # 2 ( ) 903 # 3 904 self.g4.local("gobgp vrf add vrf2 rd 200:200 rt both 200:200") 905 time.sleep(1) 906 907 self.assert_adv_count(self.g4, self.g3, 'rtc', 2) 908 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 1) 909 910 self.assert_adv_count(self.g3, self.g4, 'rtc', 2) 911 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 1) 912 913 self.assert_adv_count(self.g5, self.g3, 'rtc', 1) 914 self.assert_adv_count(self.g5, self.g3, 'ipv4-l3vpn', 1) 915 916 self.assert_adv_count(self.g3, self.g5, 'rtc', 2) 917 self.assert_adv_count(self.g3, self.g5, 'ipv4-l3vpn', 1) 918 919 def test_53_rr_addpath_add_route_on_vrf(self): 920 # VRF<#> g3 g4 g5 921 # 1 (*) (*) 922 # 2 (*) 923 # 3 924 self.g4.local("gobgp vrf vrf2 rib add 40.0.0.0/24") 925 time.sleep(1) 926 927 self.assert_adv_count(self.g4, self.g3, 'rtc', 2) 928 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 2) 929 930 self.assert_adv_count(self.g3, self.g4, 'rtc', 2) 931 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 1) 932 933 self.assert_adv_count(self.g5, self.g3, 'rtc', 1) 934 self.assert_adv_count(self.g5, self.g3, 'ipv4-l3vpn', 1) 935 936 self.assert_adv_count(self.g3, self.g5, 'rtc', 2) 937 self.assert_adv_count(self.g3, self.g5, 'ipv4-l3vpn', 1) 938 939 def test_54_rr_addpath_del_route_on_vrf(self): 940 # Related issue: 941 # https://github.com/osrg/gobgp/issues/1688 942 943 # VRF<#> g3 g4 g5 944 # 1 ( ) (*) 945 # 2 (*) 946 # 3 947 self.g4.local("gobgp vrf vrf1 rib del 40.0.0.0/24") 948 time.sleep(1) 949 950 self.assert_adv_count(self.g4, self.g3, 'rtc', 2) 951 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 1) 952 953 self.assert_adv_count(self.g3, self.g4, 'rtc', 2) 954 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 1) 955 956 self.assert_adv_count(self.g5, self.g3, 'rtc', 1) 957 self.assert_adv_count(self.g5, self.g3, 'ipv4-l3vpn', 1) 958 959 self.assert_adv_count(self.g3, self.g5, 'rtc', 2) 960 self.assert_adv_count(self.g3, self.g5, 'ipv4-l3vpn', 0) 961 962 def test_55_rr_addpath_del_vrf_with_route(self): 963 # VRF<#> g3 g4 g5 964 # 1 (*) 965 # 2 (*) 966 # 3 967 self.g4.local("gobgp vrf del vrf1") 968 time.sleep(1) 969 970 self.assert_adv_count(self.g4, self.g3, 'rtc', 1) 971 self.assert_adv_count(self.g4, self.g3, 'ipv4-l3vpn', 1) 972 973 self.assert_adv_count(self.g3, self.g4, 'rtc', 2) 974 self.assert_adv_count(self.g3, self.g4, 'ipv4-l3vpn', 0) 975 976 self.assert_adv_count(self.g5, self.g3, 'rtc', 1) 977 self.assert_adv_count(self.g5, self.g3, 'ipv4-l3vpn', 1) 978 979 self.assert_adv_count(self.g3, self.g5, 'rtc', 2) 980 self.assert_adv_count(self.g3, self.g5, 'ipv4-l3vpn', 0) 981 982 def test_56_rr_addpath_cleanup(self): 983 self.g4.local("gobgp vrf del vrf2") 984 self.g5.local("gobgp vrf del vrf1") 985 986 987 if __name__ == '__main__': 988 output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True) 989 if int(output) != 0: 990 print("docker not found") 991 sys.exit(1) 992 993 nose.main(argv=sys.argv, addplugins=[OptionParser()], 994 defaultTest=sys.argv[0])