github.com/osrg/gobgp@v2.0.0+incompatible/test/scenario_test/route_server_test2.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 from __future__ import absolute_import 17 18 import sys 19 import time 20 import unittest 21 22 from fabric.api import local 23 import nose 24 25 from lib.noseplugin import OptionParser, parser_option 26 27 from lib import base 28 from lib.base import BGP_FSM_ESTABLISHED 29 from lib.gobgp import GoBGPContainer 30 from lib.exabgp import ExaBGPContainer 31 32 33 class GoBGPTestBase(unittest.TestCase): 34 35 wait_per_retry = 5 36 retry_limit = 15 37 38 @classmethod 39 def setUpClass(cls): 40 gobgp_ctn_image_name = parser_option.gobgp_image 41 base.TEST_PREFIX = parser_option.test_prefix 42 43 g1 = GoBGPContainer(name='g1', asn=65000, router_id='192.168.0.1', 44 ctn_image_name=gobgp_ctn_image_name, 45 log_level=parser_option.gobgp_log_level) 46 g2 = GoBGPContainer(name='g2', asn=65001, router_id='192.168.0.2', 47 ctn_image_name=gobgp_ctn_image_name) 48 e1 = ExaBGPContainer(name='e1', asn=65002, router_id='192.168.0.3') 49 50 ctns = [g1, g2, e1] 51 cls.clients = {cli.name: cli for cli in (g2, e1)} 52 53 initial_wait_time = max(ctn.run() for ctn in ctns) 54 time.sleep(initial_wait_time) 55 56 for cli in cls.clients.values(): 57 # Omit "passwd" to avoid a issue on ExaBGP version 4.0.5: 58 # https://github.com/Exa-Networks/exabgp/issues/766 59 g1.add_peer(cli, is_rs_client=True, passive=True, prefix_limit=10) 60 cli.add_peer(g1) 61 62 # advertise a route from route-server-clients 63 g2.add_route('10.0.0.0/24') 64 e1.add_route('10.0.1.0/24') 65 66 cls.gobgp = g1 67 68 # test each neighbor state is turned establish 69 def test_01_neighbor_established(self): 70 for cli in self.clients.values(): 71 self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=cli) 72 73 def test_02_add_neighbor(self): 74 e2 = ExaBGPContainer(name='e2', asn=65001, router_id='192.168.0.4') 75 time.sleep(e2.run()) 76 self.gobgp.add_peer(e2, is_rs_client=True) 77 e2.add_peer(self.gobgp) 78 79 self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=e2) 80 self.clients[e2.name] = e2 81 82 def test_03_check_neighbor_rib(self): 83 rib = self.gobgp.get_local_rib(self.clients['e2']) 84 self.assertEqual(len(rib), 1) 85 self.assertEqual(len(rib[0]['paths']), 1) 86 path = rib[0]['paths'][0] 87 self.assertTrue(65001 not in path['aspath']) 88 89 def test_04_withdraw_path(self): 90 self.clients['g2'].local('gobgp global rib del 10.0.0.0/24') 91 time.sleep(1) 92 afisafis = self.gobgp.get_neighbor(self.clients['g2'])['afi_safis'] 93 advertised = 0 94 for afisafi in afisafis: 95 s = afisafi.get('state') 96 advertised += s.get('advertised') 97 self.assertEqual(s.get('accepted'), None) # means info['accepted'] == 0 98 self.assertEqual(s.get('received'), None) # means info['received'] == 0 99 100 self.assertEqual(advertised, 1) 101 102 103 if __name__ == '__main__': 104 output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True) 105 if int(output) is not 0: 106 print "docker not found" 107 sys.exit(1) 108 109 nose.main(argv=sys.argv, addplugins=[OptionParser()], 110 defaultTest=sys.argv[0])