summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/scenario_test/lib/base.py5
-rw-r--r--test/scenario_test/lib/gobgp.py8
-rw-r--r--test/scenario_test/route_reflector_test.py129
-rwxr-xr-xtest/scenario_test/run_all_tests.sh4
4 files changed, 142 insertions, 4 deletions
diff --git a/test/scenario_test/lib/base.py b/test/scenario_test/lib/base.py
index 1bba6f5b..7f73516b 100644
--- a/test/scenario_test/lib/base.py
+++ b/test/scenario_test/lib/base.py
@@ -224,6 +224,9 @@ class BGPContainer(Container):
self.policies = {}
super(BGPContainer, self).__init__(name, ctn_image_name)
+ def __repr__(self):
+ return str({'name':self.name, 'asn':self.asn, 'router_id':self.router_id})
+
def run(self):
self.create_config()
super(BGPContainer, self).run()
@@ -231,7 +234,7 @@ class BGPContainer(Container):
def add_peer(self, peer, passwd=None, evpn=False, is_rs_client=False,
policies=None, passive=False,
- is_rr_client=False, cluster_id='',
+ is_rr_client=False, cluster_id=None,
flowspec=False):
neigh_addr = ''
local_addr = ''
diff --git a/test/scenario_test/lib/gobgp.py b/test/scenario_test/lib/gobgp.py
index aed7f16d..04b89ffe 100644
--- a/test/scenario_test/lib/gobgp.py
+++ b/test/scenario_test/lib/gobgp.py
@@ -186,9 +186,11 @@ class GoBGPContainer(BGPContainer):
n['RouteServer'] = {'RouteServerConfig': {'RouteServerClient': True}}
if info['is_rr_client']:
- clusterId = info['cluster_id']
- n['RouteReflector'] = {'RouteReflectorClient': True,
- 'RouteReflectorClusterId': clusterId}
+ clusterId = self.router_id
+ if 'cluster_id' in info and info['cluster_id'] is not None:
+ clusterId = info['cluster_id']
+ n['RouteReflector'] = {'RouteReflectorConfig' : {'RouteReflectorClient': True,
+ 'RouteReflectorClusterId': clusterId}}
f = lambda typ: [p for p in info['policies'].itervalues() if p['type'] == typ]
import_policies = f('import')
diff --git a/test/scenario_test/route_reflector_test.py b/test/scenario_test/route_reflector_test.py
new file mode 100644
index 00000000..7650a4ac
--- /dev/null
+++ b/test/scenario_test/route_reflector_test.py
@@ -0,0 +1,129 @@
+# Copyright (C) 2015 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.gobgp import *
+from lib.quagga import *
+import sys
+import os
+import time
+import nose
+from noseplugin import OptionParser, parser_option
+from itertools import combinations
+
+def wait_for(f, timeout=120):
+ interval = 1
+ count = 0
+ while True:
+ if f():
+ return
+
+ time.sleep(interval)
+ count += interval
+ if count >= timeout:
+ raise Exception('timeout')
+
+
+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)
+ q1 = QuaggaBGPContainer(name='q1', asn=65000, router_id='192.168.0.2')
+ q2 = QuaggaBGPContainer(name='q2', asn=65000, router_id='192.168.0.3')
+ q3 = QuaggaBGPContainer(name='q3', asn=65000, router_id='192.168.0.4')
+ q4 = QuaggaBGPContainer(name='q4', asn=65000, router_id='192.168.0.5')
+
+ qs = [q1, q2, q3, q4]
+ ctns = [g1, q1, q2, q3, q4]
+
+ # advertise a route from q1, q2
+ for idx, c in enumerate(qs):
+ route = '10.0.{0}.0/24'.format(idx+1)
+ c.add_route(route)
+
+ initial_wait_time = max(ctn.run() for ctn in ctns)
+
+ time.sleep(initial_wait_time)
+
+ br01 = Bridge(name='br01', subnet='192.168.10.0/24')
+ [br01.addif(ctn) for ctn in ctns]
+
+ # g1 as a route reflector
+ g1.add_peer(q1, is_rr_client=True)
+ q1.add_peer(g1)
+ g1.add_peer(q2, is_rr_client=True)
+ q2.add_peer(g1)
+ g1.add_peer(q3)
+ q3.add_peer(g1)
+ g1.add_peer(q4)
+ q4.add_peer(g1)
+
+ cls.gobgp = g1
+ cls.quaggas = {'q1': q1, 'q2': q2, 'q3': q3, 'q4': q4}
+ cls.bridges = {'br01': br01}
+
+ # test each neighbor state is turned establish
+ def test_01_neighbor_established(self):
+ for q in self.quaggas.itervalues():
+ self.gobgp.wait_for(expected_state=BGP_FSM_ESTABLISHED, peer=q)
+
+ def test_02_check_gobgp_global_rib(self):
+ for q in self.quaggas.itervalues():
+ # paths expected to exist in gobgp's global rib
+ def f():
+ routes = q.routes.keys()
+ global_rib = [p['prefix'] for p in self.gobgp.get_global_rib()]
+ for p in global_rib:
+ if p in routes:
+ routes.remove(p)
+
+ return len(routes) == 0
+ wait_for(f)
+
+ def test_03_check_gobgp_adj_rib_out(self):
+ for q in self.quaggas.itervalues():
+ paths = [p['nlri']['prefix'] for p in self.gobgp.get_adj_rib_out(q)]
+ for qq in self.quaggas.itervalues():
+ if q == qq:
+ continue
+ if self.gobgp.peers[q]['is_rr_client']:
+ for p in qq.routes.keys():
+ self.assertTrue(p in paths)
+ else:
+ for p in qq.routes.keys():
+ if self.gobgp.peers[qq]['is_rr_client']:
+ self.assertTrue(p in paths)
+ else:
+ self.assertFalse(p in paths)
+
+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])
diff --git a/test/scenario_test/run_all_tests.sh b/test/scenario_test/run_all_tests.sh
index 87999c91..d6f72d54 100755
--- a/test/scenario_test/run_all_tests.sh
+++ b/test/scenario_test/run_all_tests.sh
@@ -55,6 +55,10 @@ PIDS=("${PIDS[@]}" $!)
sudo -E python flow_spec_test.py --gobgp-image $GOBGP_IMAGE --test-prefix flow -s -x --with-xunit --xunit-file=${WS}/nosetest_flow.xml &
PIDS=("${PIDS[@]}" $!)
+# flowspec test
+sudo -E python route_reflector_test.py --gobgp-image $GOBGP_IMAGE --test-prefix rr -s -x --with-xunit --xunit-file=${WS}/nosetest_rr.xml &
+PIDS=("${PIDS[@]}" $!)
+
# route server malformed message test
NUM=$(sudo -E python route_server_malformed_test.py -s 2> /dev/null | awk '/invalid/{print $NF}')
PARALLEL_NUM=10