summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/scenario_test/route_server_policy_test.py217
1 files changed, 13 insertions, 204 deletions
diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py
index 758bba14..1d372619 100644
--- a/test/scenario_test/route_server_policy_test.py
+++ b/test/scenario_test/route_server_policy_test.py
@@ -2225,137 +2225,6 @@ class InPolicyAccept(object):
@register_scenario
-class InPolicySetCommunity(object):
- """
- No.33 in-policy set community action
- ----------------
- e1 ->r1(community=65100:10) -> o | -> q1-rib -> | -> r1(community=65100:10, 65100:20), r2 --> q1
- r2(192.168.10.0/24) -> o | |
- | -> q2-rib -> | -> r1(community=65100:10, 65100:20), r2 --> q2
- ----------------
- """
- @staticmethod
- def boot(env):
- lookup_scenario('ImportPolicy').boot(env)
-
- @staticmethod
- def setup(env):
- g1 = env.g1
- e1 = env.e1
- q1 = env.q1
- q2 = env.q2
- cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
-
- g1.set_bgp_defined_set(cs0)
-
- st0 = {'Name': 'st0',
- 'Conditions':{'BgpConditions':{'MatchCommunitySet':{'CommunitySet': 'cs0'}}},
- 'Actions': {'RouteDisposition': {'AcceptRoute': True},
- 'BgpActions': {'SetCommunity': {'Options': 'ADD',
- 'SetCommunityMethod': {'Communities': ['65100:20']}}}}}
-
- policy = {'name': 'policy0',
- 'type': 'in',
- 'statements': [st0]}
- g1.add_policy(policy, e1)
-
- e1.add_route('192.168.100.0/24', community=['65100:10'])
- e1.add_route('192.168.10.0/24')
-
- for c in [e1, q1, q2]:
- g1.wait_for(BGP_FSM_ESTABLISHED, c)
-
- @staticmethod
- def check(env):
- g1 = env.g1
- e1 = env.e1
- q1 = env.q1
- q2 = env.q2
- wait_for(lambda: len(g1.get_adj_rib_in(e1)) == 2)
- wait_for(lambda: len(g1.get_local_rib(q1)) == 2)
- wait_for(lambda: len(g1.get_adj_rib_out(q1)) == 2)
- wait_for(lambda: len(q1.get_global_rib()) == 2)
- wait_for(lambda: len(g1.get_local_rib(q2)) == 2)
- wait_for(lambda: len(g1.get_adj_rib_out(q2)) == 2)
- wait_for(lambda: len(q2.get_global_rib()) == 2)
-
- @staticmethod
- def check2(env):
- g1 = env.g1
- q1 = env.q1
- q2 = env.q2
- for q in [q1, q2]:
- adj_out = g1.get_adj_rib_out(q, prefix='192.168.100.0/24')
- env.assertTrue(len(adj_out) == 1)
- env.assertTrue(community_exists(adj_out[0], '65100:10'))
- env.assertTrue(community_exists(adj_out[0], '65100:20'))
-
- adj_out = g1.get_adj_rib_out(q, prefix='192.168.10.0/24')
- env.assertTrue(len(adj_out) == 1)
- env.assertFalse(community_exists(adj_out[0], '65100:10'))
- env.assertFalse(community_exists(adj_out[0], '65100:20'))
-
-
-@register_scenario
-class InPolicyMedAdd(object):
- """
- No.34 in-policy med add action
- -----------------
- e1 -> r1(med=300) -> o | -> q1-rib -> | -> r1(med=400), r2 --> q1
- r2(192.168.10.0/24) -> o | |
- | -> q2-rib -> | -> r1(med=400), r2 --> q2
- -----------------
- """
- @staticmethod
- def boot(env):
- lookup_scenario('ImportPolicy').boot(env)
-
- @staticmethod
- def setup(env):
- g1 = env.g1
- e1 = env.e1
- q1 = env.q1
- q2 = env.q2
- cs0 = {'CommunitySets': {'CommunitySetList': [{'CommunitySetName': 'cs0', 'CommunityList': [{'Community': '65100:10'}]}]}}
-
- g1.set_bgp_defined_set(cs0)
-
- st0 = {'Name': 'st0',
- 'Conditions':{'BgpConditions':{'MatchCommunitySet':{'CommunitySet': 'cs0'}}},
- 'Actions': {'RouteDisposition': {'AcceptRoute': True},
- 'BgpActions': {'SetMed': '+100'}}}
-
- policy = {'name': 'policy0',
- 'type': 'in',
- 'statements': [st0]}
- g1.add_policy(policy, e1)
-
- e1.add_route('192.168.100.0/24', community=['65100:10'])
- e1.add_route('192.168.10.0/24')
-
- for c in [e1, q1, q2]:
- g1.wait_for(BGP_FSM_ESTABLISHED, c)
-
- @staticmethod
- def check(env):
- lookup_scenario('InPolicySetCommunity').check(env)
-
- @staticmethod
- def check2(env):
- g1 = env.g1
- q1 = env.q1
- q2 = env.q2
- for q in [q1, q2]:
- adj_out = g1.get_adj_rib_out(q, prefix='192.168.100.0/24')
- env.assertTrue(len(adj_out) == 1)
- env.assertTrue(metric(adj_out[0]) == 100)
-
- adj_out = g1.get_adj_rib_out(q, prefix='192.168.10.0/24')
- env.assertTrue(len(adj_out) == 1)
- env.assertTrue(metric(adj_out[0]) == -1)
-
-
-@register_scenario
class InPolicyUpdate(object):
"""
No.35 in-policy update test
@@ -2482,76 +2351,6 @@ class InPolicyUpdate(object):
@register_scenario
-class InPolicyAsPathPrepend(object):
- """
- No.36 aspath prepend action import
- --------------------------------
- e1 ->(aspath=[65001])-> | -> p1-rib -> p1-adj-rib-out | -> p1
- | |
- | -> p2-rib -> p2-adj-rib-out | -> p2
- | apply action |
- --------------------------------
- """
- @staticmethod
- def boot(env):
- lookup_scenario("ImportPolicy").boot(env)
-
- @staticmethod
- def setup(env):
- g1 = env.g1
- e1 = env.e1
- q1 = env.q1
- q2 = env.q2
-
- p0 = {'IpPrefix': '192.168.20.0/24'}
-
- ps0 = {'PrefixSetName': 'ps0',
- 'PrefixList': [p0]}
- g1.set_prefix_set(ps0)
-
- st0 = {'Name': 'st0',
- 'Conditions': {'MatchPrefixSet': {'PrefixSet': ps0['PrefixSetName']}},
- 'Actions': {'RouteDisposition': {'AcceptRoute': True},
- 'BgpActions': {'SetAsPathPrepend': {'RepeatN': 5, 'As': "65005"}}}}
-
- policy = {'name': 'policy0',
- 'type': 'import',
- 'statements': [st0]}
- g1.add_policy(policy, q2)
-
- e1.add_route('192.168.20.0/24')
- e1.add_route('192.168.200.0/24')
-
- for c in [e1, q1, q2]:
- g1.wait_for(BGP_FSM_ESTABLISHED, c)
-
- @staticmethod
- def check(env):
- lookup_scenario('InPolicySetCommunity').check(env)
-
- @staticmethod
- def check2(env):
- g1 = env.g1
- e1 = env.e1
- q1 = env.q1
- q2 = env.q2
- path = g1.get_adj_rib_out(q1, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
-
- path = g1.get_adj_rib_out(q1, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
-
- path = g1.get_local_rib(q2, prefix='192.168.20.0/24')[0]['paths'][0]
- env.assertTrue(path['as_path'] == [65005]*5 + [e1.asn])
-
- path = g1.get_adj_rib_out(q2, prefix='192.168.20.0/24')[0]
- env.assertTrue(path['as_path'] == [65005]*5 + [e1.asn])
-
- path = g1.get_adj_rib_out(q2, prefix='192.168.200.0/24')[0]
- env.assertTrue(path['as_path'] == [e1.asn])
-
-
-@register_scenario
class ExportPolicyAsPathPrepend(object):
"""
No.37 aspath prepend action export
@@ -2597,7 +2396,17 @@ class ExportPolicyAsPathPrepend(object):
@staticmethod
def check(env):
- lookup_scenario('InPolicySetCommunity').check(env)
+ g1 = env.g1
+ e1 = env.e1
+ q1 = env.q1
+ q2 = env.q2
+ wait_for(lambda: len(g1.get_adj_rib_in(e1)) == 2)
+ wait_for(lambda: len(g1.get_local_rib(q1)) == 2)
+ wait_for(lambda: len(g1.get_adj_rib_out(q1)) == 2)
+ wait_for(lambda: len(q1.get_global_rib()) == 2)
+ wait_for(lambda: len(g1.get_local_rib(q2)) == 2)
+ wait_for(lambda: len(g1.get_adj_rib_out(q2)) == 2)
+ wait_for(lambda: len(q2.get_global_rib()) == 2)
@staticmethod
def check2(env):
@@ -2668,7 +2477,7 @@ class ImportPolicyAsPathPrependLastAS(object):
@staticmethod
def check(env):
- lookup_scenario('InPolicySetCommunity').check(env)
+ lookup_scenario('ExportPolicyAsPathPrepend').check(env)
@staticmethod
def check2(env):
@@ -2739,7 +2548,7 @@ class ExportPolicyAsPathPrependLastAS(object):
@staticmethod
def check(env):
- lookup_scenario('InPolicySetCommunity').check(env)
+ lookup_scenario('ExportPolicyAsPathPrepend').check(env)
@staticmethod
def check2(env):