diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-11-07 19:08:34 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-11-07 19:08:34 -0800 |
commit | 0af24ff85d4e30a513a2de4821afdf1873642f45 (patch) | |
tree | 4f7eefd181c0854a78011587a03fd9b5556e223a | |
parent | a30b3c2126054f448c21adb56361357249665ddf (diff) |
test: add change of best paths from ibgp and ebgp
gobgp has two ibgp peers and one ebgp.
1. the best path is from ebgp so advertise it to ibgp peers.
2. one of ibgp peer sends the same path so now the path from ibgp
becomes best.
3. gobgp doesn't advertise it to another ibgp and needs to withdraw
the best from ebgp.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | test/lib/base.py | 13 | ||||
-rw-r--r-- | test/scenario_test/ibgp_router_test.py | 48 |
2 files changed, 61 insertions, 0 deletions
diff --git a/test/lib/base.py b/test/lib/base.py index 5f73b45d..d23cc0d7 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -47,6 +47,19 @@ BGP_ATTR_TYPE_EXTENDED_COMMUNITIES = 16 env.abort_exception = RuntimeError output.stderr = False +def wait_for_completion(f, timeout=120): + interval = 1 + count = 0 + while True: + if f(): + return + + time.sleep(interval) + count += interval + if count >= timeout: + raise Exception('timeout') + + def try_several_times(f, t=3, s=1): e = None for i in range(t): diff --git a/test/scenario_test/ibgp_router_test.py b/test/scenario_test/ibgp_router_test.py index 2dc68072..abcd95d0 100644 --- a/test/scenario_test/ibgp_router_test.py +++ b/test/scenario_test/ibgp_router_test.py @@ -16,6 +16,7 @@ import unittest from fabric.api import local from lib import base +from lib.base import wait_for_completion from lib.gobgp import * from lib.quagga import * import sys @@ -234,6 +235,53 @@ class GoBGPTestBase(unittest.TestCase): # only gobgp's locally generated routes must exists self.assertTrue(len(paths) == len(self.gobgp.routes)) + def test_15_add_ebgp_peer(self): + q4 = QuaggaBGPContainer(name='q4', asn=65001, router_id='192.168.0.5') + self.quaggas['q4'] = q4 + + prefix = '10.0.4.0/24' + q4.add_route(prefix) + + initial_wait_time = q4.run() + time.sleep(initial_wait_time) + self.gobgp.add_peer(q4) + q4.add_peer(self.gobgp) + + self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q4) + + q1 = self.quaggas['q1'] + q2 = self.quaggas['q2'] + for q in [q1, q2]: + def f(): + return prefix in [p['nlri']['prefix'] for p in self.gobgp.get_adj_rib_out(q)] + wait_for_completion(f) + + def f(): + return len(q2.get_global_rib(prefix)) == 1 + wait_for_completion(f) + + def test_16_add_best_path_from_ibgp(self): + q1 = self.quaggas['q1'] + q2 = self.quaggas['q2'] + + prefix = '10.0.4.0/24' + q1.add_route(prefix) + + def f(): + l = self.gobgp.get_global_rib(prefix) + return len(l) == 1 and len(l[0]['paths']) == 2 + wait_for_completion(f) + + def f(): + return prefix not in [p['nlri']['prefix'] for p in self.gobgp.get_adj_rib_out(q2)] + wait_for_completion(f) + + def f(): + l = q2.get_global_rib(prefix) + # route from ibgp so aspath should be empty + return len(l) == 1 and len(l[0]['aspath']) == 0 + wait_for_completion(f) + if __name__ == '__main__': if os.geteuid() is not 0: |