diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-17 20:01:22 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-07-05 04:57:27 +0900 |
commit | f48c4deaa19ca8b36d87a0d71776bc29b7e17ebe (patch) | |
tree | 169474793f5afba6db03d9743a3ab747b6a0d7a7 | |
parent | 87f0b0bdc52945ae98ef6d44b7f118216bde95ca (diff) |
test: add addpath_test.py
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | .travis.yml | 5 | ||||
-rw-r--r-- | test/lib/base.py | 14 | ||||
-rw-r--r-- | test/lib/exabgp.py | 10 | ||||
-rw-r--r-- | test/lib/gobgp.py | 7 | ||||
-rw-r--r-- | test/lib/quagga.py | 3 | ||||
-rw-r--r-- | test/scenario_test/addpath_test.py | 77 |
6 files changed, 107 insertions, 9 deletions
diff --git a/.travis.yml b/.travis.yml index 2814e5b0..17a91b87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -173,6 +173,11 @@ matrix: sudo: required services: - docker + - env: + - TEST=addpath_test.py + sudo: required + services: + - docker cache: pip: true diff --git a/test/lib/base.py b/test/lib/base.py index 0421e9d7..6306ccf6 100644 --- a/test/lib/base.py +++ b/test/lib/base.py @@ -311,7 +311,7 @@ class BGPContainer(Container): flowspec=False, bridge='', reload_config=True, as2=False, graceful_restart=None, local_as=None, prefix_limit=None, v6=False, llgr=None, vrf='', interface='', allow_as_in=0, - remove_private_as=None, replace_peer_as=False): + remove_private_as=None, replace_peer_as=False, addpath=False): neigh_addr = '' local_addr = '' it = itertools.product(self.ip_addrs, peer.ip_addrs) @@ -355,7 +355,8 @@ class BGPContainer(Container): 'vrf': vrf, 'allow_as_in': allow_as_in, 'remove_private_as': remove_private_as, - 'replace_peer_as': replace_peer_as} + 'replace_peer_as': replace_peer_as, + 'addpath': addpath} if self.is_running and reload_config: self.create_config() self.reload_config() @@ -378,8 +379,10 @@ class BGPContainer(Container): def add_route(self, route, rf='ipv4', attribute=None, aspath=None, community=None, med=None, extendedcommunity=None, nexthop=None, matchs=None, thens=None, - local_pref=None, reload_config=True): - self.routes[route] = {'prefix': route, + local_pref=None, identifier=None, reload_config=True): + if route not in self.routes: + self.routes[route] = [] + self.routes[route].append({'prefix': route, 'rf': rf, 'attr': attribute, 'next-hop': nexthop, @@ -388,8 +391,9 @@ class BGPContainer(Container): 'med': med, 'local-pref': local_pref, 'extended-community': extendedcommunity, + 'identifier': identifier, 'matchs': matchs, - 'thens': thens} + 'thens': thens}) if self.is_running and reload_config: self.create_config() self.reload_config() diff --git a/test/lib/exabgp.py b/test/lib/exabgp.py index dbf8f023..efc39ac1 100644 --- a/test/lib/exabgp.py +++ b/test/lib/exabgp.py @@ -19,6 +19,7 @@ import time from fabric import colors from fabric.api import local +from itertools import chain from lib.base import ( BGPContainer, @@ -92,7 +93,10 @@ class ExaBGPContainer(BGPContainer): if info['passive']: cmd << ' passive;' - routes = [r for r in self.routes.values() if r['rf'] == 'ipv4' or r['rf'] == 'ipv6'] + if info['addpath']: + cmd << ' add-path send/receive;' + + routes = [r for r in chain.from_iterable(self.routes.itervalues()) if r['rf'] == 'ipv4' or r['rf'] == 'ipv6'] if len(routes) > 0: cmd << ' static {' @@ -114,11 +118,13 @@ class ExaBGPContainer(BGPContainer): r << 'extended-community [{0}]'.format(route['extended-community']) if route['attr']: r << 'attribute [ {0} ]'.format(route['attr']) + if route['identifier']: + r << 'path-information {0}'.format(route['identifier']) cmd << '{0};'.format(str(r)) cmd << ' }' - routes = [r for r in self.routes.itervalues() if 'flowspec' in r['rf']] + routes = [r for r in chain.from_iterable(self.routes.itervalues()) if 'flowspec' in r['rf']] if len(routes) > 0: cmd << ' flow {' for route in routes: diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py index 26847c77..a54428e3 100644 --- a/test/lib/gobgp.py +++ b/test/lib/gobgp.py @@ -398,6 +398,11 @@ class GoBGPContainer(BGPContainer): n['route-reflector'] = {'config': {'route-reflector-client': True, 'route-reflector-cluster-id': cluster_id}} + if info['addpath']: + n['add-paths'] = {'config' : {'receive': True, + 'send-max': 16}} + + if len(info.get('default-policy', [])) + len(info.get('policies', [])) > 0: n['apply-policy'] = {'config': {}} @@ -495,7 +500,7 @@ class GoBGPContainer(BGPContainer): for d in daemon: cmd = '/usr/bin/pkill {0} -SIGHUP'.format(d) self.local(cmd) - for v in self.routes.itervalues(): + for v in chain.from_iterable(self.routes.itervalues()): if v['rf'] == 'ipv4' or v['rf'] == 'ipv6': r = CmdBuffer(' ') r << 'gobgp global -a {0}'.format(v['rf']) diff --git a/test/lib/quagga.py b/test/lib/quagga.py index e7b9f9bf..d37c2dbc 100644 --- a/test/lib/quagga.py +++ b/test/lib/quagga.py @@ -17,6 +17,7 @@ from __future__ import absolute_import from fabric import colors from fabric.utils import indent +from itertools import chain import netaddr from lib.base import ( @@ -191,7 +192,7 @@ class QuaggaBGPContainer(BGPContainer): c << 'neighbor {0} activate'.format(n_addr) c << 'exit-address-family' - for route in self.routes.itervalues(): + for route in chain.from_iterable(self.routes.itervalues()): if route['rf'] == 'ipv4': c << 'network {0}'.format(route['prefix']) elif route['rf'] == 'ipv6': diff --git a/test/scenario_test/addpath_test.py b/test/scenario_test/addpath_test.py new file mode 100644 index 00000000..82b848a6 --- /dev/null +++ b/test/scenario_test/addpath_test.py @@ -0,0 +1,77 @@ +# Copyright (C) 2016 Nippon Telegraph and Telephone Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +from fabric.api import local +from lib import base +from lib.base import BGP_FSM_ESTABLISHED +from lib.gobgp import * +from lib.exabgp import * +import sys +import os +import time +import nose +from lib.noseplugin import OptionParser, parser_option +from itertools import combinations + + +class GoBGPTestBase(unittest.TestCase): + + @classmethod + def setUpClass(cls): + gobgp_ctn_image_name = parser_option.gobgp_image + base.TEST_PREFIX = parser_option.test_prefix + + g1 = GoBGPContainer(name='g1', asn=65000, router_id='192.168.0.1', + ctn_image_name=gobgp_ctn_image_name, + log_level=parser_option.gobgp_log_level) + e1 = ExaBGPContainer(name='e1', asn=65000, router_id='192.168.0.2') + + ctns = [g1, e1] + + e1.add_route(route='192.168.100.0/24', identifier=10, aspath=[100, 200, 300]) + e1.add_route(route='192.168.100.0/24', identifier=20, aspath=[100, 200]) + e1.add_route(route='192.168.100.0/24', identifier=30, aspath=[100]) + + initial_wait_time = max(ctn.run() for ctn in ctns) + + time.sleep(initial_wait_time) + + g1.add_peer(e1, addpath=True) + e1.add_peer(g1, addpath=True) + cls.g1 = g1 + cls.e1 = e1 + + # test each neighbor state is turned establish + def test_01_neighbor_established(self): + self.g1.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=self.e1) + + # test three routes are installed to the rib due to add-path feature + def test_02_check_g1_global_rib(self): + rib = self.g1.get_global_rib() + self.assertTrue(len(rib) == 1) + self.assertTrue(len(rib[0]['paths']) == 3) + +if __name__ == '__main__': + if os.geteuid() is not 0: + print "you are not root." + sys.exit(1) + output = local("which docker 2>&1 > /dev/null ; echo $?", capture=True) + if int(output) is not 0: + print "docker not found" + sys.exit(1) + + nose.main(argv=sys.argv, addplugins=[OptionParser()], + defaultTest=sys.argv[0]) |