summaryrefslogtreecommitdiffhomepage
path: root/test/scenario_test/route_server_policy_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/scenario_test/route_server_policy_test.py')
-rw-r--r--test/scenario_test/route_server_policy_test.py236
1 files changed, 216 insertions, 20 deletions
diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py
index edcf7d7b..190c30fc 100644
--- a/test/scenario_test/route_server_policy_test.py
+++ b/test/scenario_test/route_server_policy_test.py
@@ -18,6 +18,7 @@ import sys
import nose
import quagga_access as qaccess
import docker_control as fab
+import StringIO
from noseplugin import OptionParser
from noseplugin import parser_option
from gobgp_test import GoBGPTestBase
@@ -34,7 +35,6 @@ def print_elapsed_time(f):
return wrapped
-
class GoBGPTest(GoBGPTestBase):
quagga_num = 3
@@ -53,27 +53,34 @@ class GoBGPTest(GoBGPTestBase):
self.initial_wait_time = 1
self.wait_per_retry = 3
+ if fab.docker_container_check() or fab.bridge_setting_check():
+ print "gobgp test environment already exists. clean up..."
+ fab.docker_containers_destroy(False, False)
+
@classmethod
@print_elapsed_time
def setUpClass(cls):
print 'prepare gobgp'
- fab.prepare_gobgp(parser_option.gobgp_log_debug, parser_option.use_local)
+ cls.go_path = parser_option.go_path
+ cls.use_local = parser_option.use_local
+ cls.log_debug = parser_option.gobgp_log_debug
+ fab.prepare_gobgp(cls.log_debug, cls.use_local)
+ fab.build_config_tools(cls.go_path)
@print_elapsed_time
- def initialize(self, policy_pattern=None):
- use_local = parser_option.use_local
- go_path = parser_option.go_path
- log_debug = parser_option.gobgp_log_debug
-
- fab.init_policy_test_env_executor(self.quagga_num, use_local, go_path,
- log_debug, policy=policy_pattern,
+ def initialize(self):
+ fab.init_policy_test_env_executor(self.quagga_num,
use_ipv6=self.use_ipv6_gobgp,
use_exabgp=self.use_exa_bgp)
print "please wait " + str(self.initial_wait_time) + " second"
time.sleep(self.initial_wait_time)
self.assertTrue(self.check_load_config())
+ @print_elapsed_time
+ def setup_config(self, peer, policy_name, target):
+ fab.make_config(self.quagga_num, self.go_path, BRIDGE_0, use_compiled=True)
+ fab.update_policy_config(self.go_path, peer, policy_name, target)
"""
import-policy test
@@ -88,9 +95,7 @@ class GoBGPTest(GoBGPTestBase):
# initialize test environment
# policy_pattern:p1 attaches a policy to reject route 192.168.0.0/16 (16...24)
# coming from peer2(10.0.0.2) to peer3(10.0.0.3)'s import-policy.
- self.initialize(policy_pattern="test_01_import_policy_initial")
- addresses = self.get_neighbor_address(self.gobgp_config)
- self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED")
+
peer1 = "10.0.0.1"
peer2 = "10.0.0.2"
@@ -98,7 +103,14 @@ class GoBGPTest(GoBGPTestBase):
prefix1 = "192.168.2.0/24"
w = self.wait_per_retry
- path = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common)
+ self.setup_config(peer3, "test_01_import_policy_initial", "import")
+ self.initialize()
+
+ addresses = self.get_neighbor_address(self.gobgp_config)
+ self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED")
+
+
+ path = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common, interval=w)
self.assertIsNotNone(path)
# check show ip bgp on peer1(quagga1)
@@ -130,17 +142,19 @@ class GoBGPTest(GoBGPTestBase):
# initialize test environment
# policy_pattern:p1 attaches a policy to reject route 192.168.0.0/16 (16...24)
# coming from peer2(10.0.0.2) to peer3(10.0.0.3)'s export-policy.
- self.initialize(policy_pattern="test_02_export_policy_initial")
- addresses = self.get_neighbor_address(self.gobgp_config)
- self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED")
-
peer1 = "10.0.0.1"
peer2 = "10.0.0.2"
peer3 = "10.0.0.3"
prefix1 = "192.168.2.0/24"
w = self.wait_per_retry
- paths = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common)
+ self.setup_config(peer3, "test_02_export_policy_initial", "export")
+ self.initialize()
+
+ addresses = self.get_neighbor_address(self.gobgp_config)
+ self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED")
+
+ paths = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common, interval=w)
self.assertIsNotNone(paths)
# check show ip bgp on peer1(quagga1)
@@ -192,7 +206,6 @@ class GoBGPTest(GoBGPTestBase):
# policy_pattern:p3 attaches a policy to reject route
# 192.168.2.0/24, 192.168.20.0/24, 192.168.200.0/24
# coming from peer2(10.0.0.2) to peer3(10.0.0.3)'s import-policy.
- self.initialize(policy_pattern="test_03_import_policy_update")
peer1 = "10.0.0.1"
peer2 = "10.0.0.2"
@@ -202,6 +215,9 @@ class GoBGPTest(GoBGPTestBase):
r3 = "192.168.200.0/24"
w = self.wait_per_retry
+ self.setup_config(peer3, "test_03_import_policy_update", "import")
+ self.initialize()
+
# add other network
tn = qaccess.login(peer2)
print "add network 192.168.20.0/24"
@@ -253,7 +269,8 @@ class GoBGPTest(GoBGPTestBase):
# update policy
print "update_policy_config"
- fab.update_policy_config(parser_option.go_path, policy_pattern="test_03_import_policy_update")
+ fab.update_policy_config(self.go_path, peer3, "test_03_import_policy_update_softreset", "import", isReplace=True)
+ fab.reload_config()
time.sleep(self.initial_wait_time)
# soft reset
@@ -749,6 +766,9 @@ class GoBGPTest(GoBGPTestBase):
as_path = reduce(lambda a,b: a + " " + b, asns)
generate_exabgp_config(prefix1, aspath=as_path)
+
+ #make_config_append(100, go_path, BRIDGE_0, peer_opts="--none-peer")
+
self.quagga_num = 2
self.use_exa_bgp = True
@@ -1571,6 +1591,137 @@ class GoBGPTest(GoBGPTestBase):
self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:10', retry=0))
+ """
+ distribute-policy test
+ ---------------------
+ exabgp ->r1(community=65100:10) -> x | -> peer1-rib -> | -> r2 --> peer1
+ r2(192.168.2.0/24) -> o | |
+ | -> peer2-rib -> | -> r2 --> peer2
+ | |
+ ---------------------
+ """
+ def test_25_distribute_reject(self):
+
+ # initialize test environment
+ # policy_pattern:CommunityNullEXP attaches a policy to remove its community attr
+ # to peer2(10.0.0.2)'s export-policy.
+
+ # generate exabgp configuration file
+ r1 = "192.168.100.0/24"
+ r2 = "192.168.2.0/24"
+ asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ]
+ community = ' 65100:10 65100:20 65100:30 '
+ as_path = reduce(lambda a,b: a + " " + b, asns)
+
+ e = ExabgpConfig(EXABGP_COMMON_CONF)
+ e.add_route(r1, aspath=as_path, community=community)
+ e.add_route(r2, aspath=['65100'])
+ e.write()
+
+
+
+
+ self.quagga_num = 2
+ self.use_exa_bgp = True
+ self.use_ipv6_gobgp = False
+
+ self.initialize(policy_pattern="test_25_distribute_reject")
+ addresses = self.get_neighbor_address(self.gobgp_config)
+ self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED")
+
+ peer1 = "10.0.0.1"
+ peer2 = "10.0.0.2"
+
+ path = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common)
+ self.assertIsNotNone(path)
+
+ # check show ip bgp on peer1(quagga1)
+ qpath = self.get_route(peer1,prefix1, retry=self.retry_count_common)
+ self.assertIsNotNone(qpath)
+
+ # check adj-rib-out in peer2
+ path = self.get_paths_in_localrib(peer2, prefix1, retry=0)
+ self.assertIsNotNone(path)
+ attrs = [x for x in path[0]['attrs'] if 'communites' in x ]
+ self.assertTrue((65100 << 16 | 10) in attrs[0]['communites'])
+ self.assertTrue((65100 << 16 | 20) in attrs[0]['communites'])
+ self.assertTrue((65100 << 16 | 30) in attrs[0]['communites'])
+ # check out-rib
+ path = self.get_adj_rib_out(peer2, prefix1, retry=1)
+ attrs = [x for x in path['attrs'] if 'communites' in x ]
+ self.assertFalse('communites' in attrs)
+
+ # check show ip bgp on peer2(quagga2)
+ qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common)
+ self.assertIsNotNone(qpath)
+ self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:20', retry=0))
+ self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:30', retry=0))
+ self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:10', retry=0))
+
+
+
+ """
+ distribute-policy test
+ ---------------------------------------
+ exabgp ->(community=65100:10)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1
+ (community=65100:20) | |
+ (community=65100:30) | -> peer2-rib -> peer2-adj-rib-out | --> peer2
+ | apply action |
+ ---------------------------------------
+ """
+ def test_26_distribute_modify_community(self):
+
+ # initialize test environment
+ # policy_pattern:CommunityNullEXP attaches a policy to remove its community attr
+ # to peer2(10.0.0.2)'s export-policy.
+
+ # generate exabgp configuration file
+ prefix1 = "192.168.100.0/24"
+ asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ]
+ community = ' 65100:10 65100:20 65100:30 '
+ as_path = reduce(lambda a,b: a + " " + b, asns)
+ generate_exabgp_config(prefix1, aspath=as_path, community=community)
+
+
+ self.quagga_num = 2
+ self.use_exa_bgp = True
+ self.use_ipv6_gobgp = False
+
+ self.initialize(policy_pattern="test_24_community_null_action_export")
+ addresses = self.get_neighbor_address(self.gobgp_config)
+ self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED")
+
+ peer1 = "10.0.0.1"
+ peer2 = "10.0.0.2"
+
+ path = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common)
+ self.assertIsNotNone(path)
+
+ # check show ip bgp on peer1(quagga1)
+ qpath = self.get_route(peer1,prefix1, retry=self.retry_count_common)
+ self.assertIsNotNone(qpath)
+
+ # check adj-rib-out in peer2
+ path = self.get_paths_in_localrib(peer2, prefix1, retry=0)
+ self.assertIsNotNone(path)
+ attrs = [x for x in path[0]['attrs'] if 'communites' in x ]
+ self.assertTrue((65100 << 16 | 10) in attrs[0]['communites'])
+ self.assertTrue((65100 << 16 | 20) in attrs[0]['communites'])
+ self.assertTrue((65100 << 16 | 30) in attrs[0]['communites'])
+ # check out-rib
+ path = self.get_adj_rib_out(peer2, prefix1, retry=1)
+ attrs = [x for x in path['attrs'] if 'communites' in x ]
+ self.assertFalse('communites' in attrs)
+
+ # check show ip bgp on peer2(quagga2)
+ qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common)
+ self.assertIsNotNone(qpath)
+ self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:20', retry=0))
+ self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:30', retry=0))
+ self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:10', retry=0))
+
+
+
def generate_exabgp_config(pref, aspath='', community=''):
value = {'prefix': pref,
'aspath': aspath,
@@ -1603,6 +1754,51 @@ neighbor 10.0.255.1 {
}
'''
+class ExabgpConfig(object):
+
+ basic_conf_begin = '''
+neighbor 10.0.255.1 {
+ router-id 192.168.0.7;
+ local-address 10.0.0.100;
+ local-as 65100;
+ peer-as 65000;
+ hold-time 90;
+ md5 "hoge100";
+ graceful-restart;
+
+ family {
+ inet unicast;
+ }
+ static {
+ # static routes
+'''
+
+ basic_conf_end = '''
+ }
+}
+'''
+
+ def __init__(self, config_name):
+ self.o = StringIO.StringIO()
+ self.config_name = config_name
+ print self.basic_conf_begin >> self.o
+
+ def add_route(self, prefix, aspath='', community=''):
+ value = {'prefix': prefix,
+ 'aspath': aspath,
+ 'community': community}
+ r = "route %(prefix)s next-hop 10.0.0.100 as-path [%(aspath)s] community [%(community)s];" % value
+ print r >> self.o
+
+ def write(self):
+ print self.basic_conf_end >> self.o
+ pwd = local("pwd", capture=True)
+ conf_dir = pwd + "/exabgp_test_conf"
+
+ with open(conf_dir + "/" + self.config_name, 'w') as f:
+ f.write(self.o.getvalue())
+
+
if __name__ == '__main__':
if fab.test_user_check() is False:
print "you are not root."