github.com/osrg/gobgp/v3@v3.30.0/test/scenario_test/route_server_as2_test.py (about) 1 # Copyright (C) 2015 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 import unittest 18 import sys 19 import time 20 21 import collections 22 collections.Callable = collections.abc.Callable 23 24 import nose 25 26 from lib.noseplugin import OptionParser, parser_option 27 28 from lib import base 29 from lib.base import ( 30 BGP_FSM_IDLE, 31 BGP_FSM_ESTABLISHED, 32 local, 33 ) 34 from lib.gobgp import GoBGPContainer 35 from lib.exabgp import ExaBGPContainer 36 37 38 class GoBGPTestBase(unittest.TestCase): 39 40 wait_per_retry = 5 41 retry_limit = 10 42 43 @classmethod 44 def setUpClass(cls): 45 gobgp_ctn_image_name = parser_option.gobgp_image 46 base.TEST_PREFIX = parser_option.test_prefix 47 48 g1 = GoBGPContainer(name='g1', asn=65000, router_id='192.168.0.1', 49 ctn_image_name=gobgp_ctn_image_name, 50 log_level=parser_option.gobgp_log_level) 51 52 rs_clients = [ 53 ExaBGPContainer(name='q{0}'.format(i + 1), asn=(65001 + i), 54 router_id='192.168.0.{0}'.format(i + 2)) 55 for i in range(4)] 56 ctns = [g1] + rs_clients 57 58 initial_wait_time = max(ctn.run() for ctn in ctns) 59 time.sleep(initial_wait_time) 60 61 for i, rs_client in enumerate(rs_clients): 62 g1.add_peer(rs_client, is_rs_client=True) 63 as2 = False 64 if i > 1: 65 as2 = True 66 rs_client.add_peer(g1, as2=as2) 67 68 # advertise a route from route-server-clients 69 for idx, rs_client in enumerate(rs_clients): 70 route = '10.0.{0}.0/24'.format(idx + 1) 71 rs_client.add_route(route) 72 if idx < 2: 73 route = '10.0.10.0/24' 74 rs_client.add_route(route) 75 76 cls.gobgp = g1 77 cls.quaggas = {x.name: x for x in rs_clients} 78 79 # test each neighbor state is turned establish 80 def test_01_neighbor_established(self): 81 for q in self.quaggas.values(): 82 self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q) 83 84 def test_02_check_gobgp_local_rib(self): 85 for rs_client in self.quaggas.values(): 86 done = False 87 for _ in range(self.retry_limit): 88 if done: 89 break 90 91 state = self.gobgp.get_neighbor_state(rs_client) 92 self.assertEqual(state, BGP_FSM_ESTABLISHED) 93 local_rib = self.gobgp.get_local_rib(rs_client) 94 if len(local_rib) < (len(self.quaggas) - 1): 95 time.sleep(self.wait_per_retry) 96 continue 97 98 self.assertEqual(len(local_rib), 4) 99 done = True 100 101 if done: 102 continue 103 # should not reach here 104 raise AssertionError 105 106 def test_03_stop_q2_and_check_neighbor_status(self): 107 q2 = self.quaggas['q2'] 108 q2.remove() 109 self.gobgp.wait_for(expected_state=BGP_FSM_IDLE, peer=q2) 110 111 112 if __name__ == '__main__': 113 output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True) 114 if int(output) != 0: 115 print("docker not found") 116 sys.exit(1) 117 118 nose.main(argv=sys.argv, addplugins=[OptionParser()], 119 defaultTest=sys.argv[0])