diff options
author | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2015-07-01 16:06:24 +0900 |
---|---|---|
committer | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2015-07-01 16:25:34 +0900 |
commit | 1adfa485d578af59b653c9b2d141b12a97e89fb7 (patch) | |
tree | 2a6a483317c32fd2b5e8e4670b5df92aa85eac65 /test | |
parent | d045cdf59eb033ac7893bc2d65eab7f305648480 (diff) |
scenario_test: add the test of med actioin
Diffstat (limited to 'test')
-rw-r--r-- | test/scenario_test/gobgp_test.py | 26 | ||||
-rw-r--r-- | test/scenario_test/policy/policy_generator.go | 133 | ||||
-rw-r--r-- | test/scenario_test/quagga_access.py | 20 | ||||
-rw-r--r-- | test/scenario_test/route_server_policy_test.py | 439 |
4 files changed, 586 insertions, 32 deletions
diff --git a/test/scenario_test/gobgp_test.py b/test/scenario_test/gobgp_test.py index 452b7f7a..1333afad 100644 --- a/test/scenario_test/gobgp_test.py +++ b/test/scenario_test/gobgp_test.py @@ -321,6 +321,32 @@ class GoBGPTestBase(unittest.TestCase): return False + # get route information on quagga + def check_med(self, neighbor_address, target_addr, med, retry=3, interval=-1, af=IPv4): + if interval < 0: + interval = self.wait_per_retry + print "check route %s on quagga : %s" % (target_addr, neighbor_address) + retry_count = 0 + + while True: + tn = qaccess.login(neighbor_address) + result = qaccess.check_med(tn, target_addr, med, af) + qaccess.logout(tn) + + if result: + return True + else: + print "target path %s with med %s is none" % (target_addr, med) + + retry_count += 1 + if retry_count > retry: + break + else: + print "wait (" + str(interval) + " seconds)" + time.sleep(interval) + + return False + def compare_rib_with_quagga_configs(self, rib_owner_addr, local_rib): for quagga_config in self.quagga_configs: diff --git a/test/scenario_test/policy/policy_generator.go b/test/scenario_test/policy/policy_generator.go index 62dab150..8336c8f8 100644 --- a/test/scenario_test/policy/policy_generator.go +++ b/test/scenario_test/policy/policy_generator.go @@ -473,6 +473,51 @@ func createPolicyConfig() *config.RoutingPolicy { }, } + st_medReplace := config.Statement{ + Name: "st_medReplace", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: true, + BgpActions: config.BgpActions{ + SetMed: "100", + }, + }, + } + + st_medAdd := config.Statement{ + Name: "st_medAdd", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: true, + BgpActions: config.BgpActions{ + SetMed: "+100", + }, + }, + } + + st_medSub := config.Statement{ + Name: "st_medSub", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: true, + BgpActions: config.BgpActions{ + SetMed: "-100", + }, + }, + } + st_distribute_reject := config.Statement{ Name: "st_community_distriibute", Conditions: config.Conditions{ @@ -516,6 +561,21 @@ func createPolicyConfig() *config.RoutingPolicy { }, } + st_distribute_med_add := config.Statement{ + Name: "st_distribute_med_add", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: true, + BgpActions: config.BgpActions{ + SetMed: "+100", + }, + }, + } + test_01_import_policy_initial := config.PolicyDefinition{ Name: "test_01_import_policy_initial", StatementList: []config.Statement{st0}, @@ -656,28 +716,64 @@ func createPolicyConfig() *config.RoutingPolicy { StatementList: []config.Statement{st_comNull}, } - test_25_distribute_reject := config.PolicyDefinition{ - Name: "test_25_distribute_reject", + + test_25_med_replace_action_import := config.PolicyDefinition{ + Name: "test_25_med_replace_action_import", + StatementList: []config.Statement{st_medReplace}, + } + + test_26_med_add_action_import := config.PolicyDefinition{ + Name: "test_26_med_add_action_import", + StatementList: []config.Statement{st_medAdd}, + } + + test_27_med_subtract_action_import := config.PolicyDefinition{ + Name: "test_27_med_subtract_action_import", + StatementList: []config.Statement{st_medSub}, + } + + test_28_med_replace_action_export := config.PolicyDefinition{ + Name: "test_28_med_replace_action_export", + StatementList: []config.Statement{st_medReplace}, + } + + test_29_med_add_action_export := config.PolicyDefinition{ + Name: "test_29_med_add_action_export", + StatementList: []config.Statement{st_medAdd}, + } + + test_30_med_subtract_action_export := config.PolicyDefinition{ + Name: "test_30_med_subtract_action_export", + StatementList: []config.Statement{st_medSub}, + } + + test_31_distribute_reject := config.PolicyDefinition{ + Name: "test_31_distribute_reject", StatementList: []config.Statement{st_distribute_reject}, } - test_26_distribute_accept := config.PolicyDefinition{ - Name: "test_26_distribute_accept", + test_32_distribute_accept := config.PolicyDefinition{ + Name: "test_32_distribute_accept", StatementList: []config.Statement{st_distribute_accept}, } - test_27_distribute_set_community_action := config.PolicyDefinition{ - Name: "test_27_distribute_set_community_action", + test_33_distribute_set_community_action := config.PolicyDefinition{ + Name: "test_33_distribute_set_community_action", StatementList: []config.Statement{st_distribute_comm_add}, } - test_28_distribute_policy_update := config.PolicyDefinition{ - Name: "test_28_distribute_policy_update", + test_34_distribute_set_med_action := config.PolicyDefinition{ + Name: "test_34_distribute_set_med_action", + StatementList: []config.Statement{st_distribute_med_add}, + } + + test_35_distribute_policy_update := config.PolicyDefinition{ + Name: "test_35_distribute_policy_update", StatementList: []config.Statement{st1}, } - test_28_distribute_policy_update_softreset := config.PolicyDefinition{ - Name: "test_28_distribute_policy_update_softreset", + test_35_distribute_policy_update_softreset := config.PolicyDefinition{ + Name: "test_35_distribute_policy_update_softreset", StatementList: []config.Statement{st2}, } @@ -722,11 +818,18 @@ func createPolicyConfig() *config.RoutingPolicy { test_22_community_replace_action_export, test_23_community_remove_action_export, test_24_community_null_action_export, - test_25_distribute_reject, - test_26_distribute_accept, - test_27_distribute_set_community_action, - test_28_distribute_policy_update, - test_28_distribute_policy_update_softreset, + test_25_med_replace_action_import, + test_26_med_add_action_import, + test_27_med_subtract_action_import, + test_28_med_replace_action_export, + test_29_med_add_action_export, + test_30_med_subtract_action_export, + test_31_distribute_reject, + test_32_distribute_accept, + test_33_distribute_set_community_action, + test_34_distribute_set_med_action, + test_35_distribute_policy_update, + test_35_distribute_policy_update_softreset, }, } return p diff --git a/test/scenario_test/quagga_access.py b/test/scenario_test/quagga_access.py index 634dc439..a04ccd59 100644 --- a/test/scenario_test/quagga_access.py +++ b/test/scenario_test/quagga_access.py @@ -144,6 +144,7 @@ def lookup_prefix(tn, prefix, af): return paths + def check_community(tn, addr, community, af=IPv4): if af == IPv4: tn.write("show ip bgp community " + community + "\n") @@ -157,4 +158,21 @@ def check_community(tn, addr, community, af=IPv4): if addr in line: return True - return False
\ No newline at end of file + return False + + +def check_med(tn, addr, med, af=IPv4): + if af == IPv4: + tn.write("show ip bgp " + addr[0] + "\n") + elif af == IPv6: + tn.write("show bgp ipv6 " + addr[0] + "\n") + else: + print "invalid af: ", af + return + result = tn.read_until("bgpd#") + for line in result.split("\n"): + if "metric" in line: + if str(med) in line.split()[3]: + return True + + return False diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py index 337105b4..737c9a05 100644 --- a/test/scenario_test/route_server_policy_test.py +++ b/test/scenario_test/route_server_policy_test.py @@ -1646,6 +1646,340 @@ class GoBGPTest(GoBGPTestBase): self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:10', retry=0)) + """ + import-policy test + --------------------------------------- + exabgp ->(med=300)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_25_med_replace_action_import(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] + community = '65100:10' + as_path = reduce(lambda a,b: a + " " + b, asns) + med = "300" + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community, med=med) + e.write() + + self.quagga_num = 2 + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + w = self.wait_per_retry + + # policy:test_25_med_replace_action_import which replace 100 in its med attr + # is attached to peer2(10.0.0.2)'s import-policy. + self.setup_config(peer2, "test_25_med_replace_action_import", "import", add_exabgp=True) + 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) + 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 local-rib in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=0) + self.assertIsNotNone(path) + attrs = [x for x in path[0]['attrs'] if 'metric' in x] + self.assertTrue(100 == attrs[0]['metric']) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2, prefix1, retry=self.retry_count_common) + self.assertIsNotNone(qpath) + self.assertTrue(self.check_med(peer2, prefix1.split('/'), 100, retry=0)) + + """ + import-policy test + --------------------------------------- + exabgp ->(med=300)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_26_med_add_action_import(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] + community = '65100:10' + as_path = reduce(lambda a,b: a + " " + b, asns) + med = "300" + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community, med=med) + e.write() + + self.quagga_num = 2 + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + w = self.wait_per_retry + + # policy:test_26_med_add_action_import which add 100 in its med attr + # is attached to peer2(10.0.0.2)'s import-policy. + self.setup_config(peer2, "test_26_med_add_action_import", "import", add_exabgp=True) + 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) + 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 local-rib in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=0) + self.assertIsNotNone(path) + attrs = [x for x in path[0]['attrs'] if 'metric' in x] + self.assertTrue(400 == attrs[0]['metric']) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2, prefix1, retry=self.retry_count_common) + self.assertIsNotNone(qpath) + self.assertTrue(self.check_med(peer2, prefix1.split('/'), 400, retry=0)) + + """ + import-policy test + --------------------------------------- + exabgp ->(med=300)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_27_med_subtract_action_import(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] + community = '65100:10' + as_path = reduce(lambda a,b: a + " " + b, asns) + med = "300" + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community, med=med) + e.write() + + self.quagga_num = 2 + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + w = self.wait_per_retry + + # policy:test_27_med_subtract_action_import which subtract 100 in its med attr + # is attached to peer2(10.0.0.2)'s import-policy. + self.setup_config(peer2, "test_27_med_subtract_action_import", "import", add_exabgp=True) + 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) + 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 local-rib in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=0) + self.assertIsNotNone(path) + attrs = [x for x in path[0]['attrs'] if 'metric' in x] + self.assertTrue(200 == attrs[0]['metric']) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2, prefix1, retry=self.retry_count_common) + self.assertIsNotNone(qpath) + self.assertTrue(self.check_med(peer2, prefix1.split('/'), 200, retry=0)) + + """ + export-policy test + --------------------------------------- + exabgp ->(med=300)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_28_med_replace_action_export(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] + community = '65100:10' + as_path = reduce(lambda a,b: a + " " + b, asns) + med = "300" + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community, med=med) + e.write() + + + self.quagga_num = 2 + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + w = self.wait_per_retry + + # policy:test_28_med_replace_action_export which replace 100 in its med attr + # is attached to peer2(10.0.0.2)'s export-policy. + self.setup_config(peer2, "test_28_med_replace_action_export", "export", add_exabgp=True) + 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) + 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 local-rib in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=1) + self.assertIsNotNone(path) + attrs = [x for x in path[0]['attrs'] if 'metric' in x] + self.assertFalse(100 == attrs[0]['metric']) + # check adj-rib-out + path = self.get_adj_rib_out(peer2, prefix1, retry=1) + attrs = [x for x in path['attrs'] if 'metric' in x] + self.assertTrue(100 == attrs[0]['metric']) + + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + self.assertIsNotNone(qpath) + self.assertTrue(self.check_med(peer2, prefix1.split('/'), 100, retry=0)) + + """ + export-policy test + --------------------------------------- + exabgp ->(med=300)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_29_med_add_action_export(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] + community = '65100:10' + as_path = reduce(lambda a,b: a + " " + b, asns) + med = "300" + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community, med=med) + e.write() + + + self.quagga_num = 2 + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + w = self.wait_per_retry + + # policy:test_29_med_add_action_export which add 100 in its med attr + # is attached to peer2(10.0.0.2)'s export-policy. + self.setup_config(peer2, "test_29_med_add_action_export", "export", add_exabgp=True) + 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) + 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 local-rib in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=1) + self.assertIsNotNone(path) + attrs = [x for x in path[0]['attrs'] if 'metric' in x] + self.assertFalse(400 == attrs[0]['metric']) + # check adj-rib-out + path = self.get_adj_rib_out(peer2, prefix1, retry=1) + attrs = [x for x in path['attrs'] if 'metric' in x] + self.assertTrue(400 == attrs[0]['metric']) + + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + self.assertIsNotNone(qpath) + self.assertTrue(self.check_med(peer2, prefix1.split('/'), 400, retry=0)) + + """ + export-policy test + --------------------------------------- + exabgp ->(med=300)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_30_med_subtract_action_export(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] + community = '65100:10' + as_path = reduce(lambda a,b: a + " " + b, asns) + med = "300" + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community, med=med) + e.write() + + + self.quagga_num = 2 + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + w = self.wait_per_retry + + # policy:test_30_med_subtract_action_export which subtract 100 in its med attr + # is attached to peer2(10.0.0.2)'s export-policy. + self.setup_config(peer2, "test_30_med_subtract_action_export", "export", add_exabgp=True) + 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) + 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 local-rib in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=1) + self.assertIsNotNone(path) + attrs = [x for x in path[0]['attrs'] if 'metric' in x] + self.assertFalse(200 == attrs[0]['metric']) + # check adj-rib-out + path = self.get_adj_rib_out(peer2, prefix1, retry=1) + attrs = [x for x in path['attrs'] if 'metric' in x] + self.assertTrue(200 == attrs[0]['metric']) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + self.assertIsNotNone(qpath) + self.assertTrue(self.check_med(peer2, prefix1.split('/'), 200, retry=0)) """ distribute-policy test @@ -1655,7 +1989,7 @@ class GoBGPTest(GoBGPTestBase): | -> peer2-rib -> | -> r2 --> peer2 --------------------- """ - def test_25_distribute_reject(self): + def test_31_distribute_reject(self): # generate exabgp configuration file r1 = "192.168.100.0/24" @@ -1678,9 +2012,9 @@ class GoBGPTest(GoBGPTestBase): exabgp = "10.0.0.100" w = self.wait_per_retry - # policy:test_25_distribute_reject which rejects routes that have community=65100:10 + # policy:test_31_distribute_reject which rejects routes that have community=65100:10 # is attached to exabgp(10.0.0.100)'s distribute policy. - self.setup_config(exabgp, "test_25_distribute_reject", "distribute", add_exabgp=True) + self.setup_config(exabgp, "test_31_distribute_reject", "distribute", add_exabgp=True) self.initialize() addresses = self.get_neighbor_address(self.gobgp_config) @@ -1724,7 +2058,7 @@ class GoBGPTest(GoBGPTestBase): | -> peer2-rib -> | -> r2 --> peer2 --------------------- """ - def test_26_distribute_accept(self): + def test_32_distribute_accept(self): # generate exabgp configuration file r1 = "192.168.100.0/24" r2 = "192.168.10.0/24" @@ -1746,9 +2080,9 @@ class GoBGPTest(GoBGPTestBase): exabgp = "10.0.0.100" w = self.wait_per_retry - # policy:test_26_distribute_accept which accepts 192.168.10.0/24 + # policy:test_32_distribute_accept which accepts 192.168.10.0/24 # is attached to exabgp(10.0.0.100)'s distribute policy. - self.setup_config(exabgp, "test_26_distribute_accept", "distribute", add_exabgp=True, defaultReject=True) + self.setup_config(exabgp, "test_32_distribute_accept", "distribute", add_exabgp=True, defaultReject=True) self.initialize() addresses = self.get_neighbor_address(self.gobgp_config) @@ -1784,7 +2118,6 @@ class GoBGPTest(GoBGPTestBase): self.assertIsNotNone(qpath) - """ distribute-policy test --------------------- @@ -1793,7 +2126,7 @@ class GoBGPTest(GoBGPTestBase): | -> peer2-rib -> | -> r1(community=65100:10, 65100:20), r2 --> peer2 --------------------- """ - def test_27_distribute_set_community_action(self): + def test_33_distribute_set_community_action(self): # generate exabgp configuration file r1 = "192.168.100.0/24" @@ -1816,9 +2149,9 @@ class GoBGPTest(GoBGPTestBase): exabgp = "10.0.0.100" w = self.wait_per_retry - # policy:test_27_distribute_set_community_action which set community + # policy:test_33_distribute_set_community_action which set community # attr is attached to exabgp(10.0.0.100)'s distribute policy. - self.setup_config(exabgp, "test_27_distribute_set_community_action", "distribute", add_exabgp=True) + self.setup_config(exabgp, "test_33_distribute_set_community_action", "distribute", add_exabgp=True) self.initialize() addresses = self.get_neighbor_address(self.gobgp_config) @@ -1859,6 +2192,79 @@ class GoBGPTest(GoBGPTestBase): self.assertTrue(self.check_community(peer2, r1.split('/')[0], '65100:20', retry=0)) + """ + distribute-policy test + --------------------- + exabgp ->r1(med=300) -> o | -> peer1-rib -> | -> r1(med=400), r2 --> peer1 + r2(192.168.10.0/24) -> o | | + | -> peer2-rib -> | -> r1(med=400), r2 --> peer2 + --------------------- + """ + def test_34_distribute_set_med_action(self): + + # generate exabgp configuration file + r1 = "192.168.100.0/24" + r2 = "192.168.10.0/24" + asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] + community = ' 65100:10 ' + as_path = reduce(lambda a, b: a + " " + b, asns) + med = "300" + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(r1, aspath=as_path, community=community, med=med) + e.add_route(r2, aspath='65100') + e.write() + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + exabgp = "10.0.0.100" + w = self.wait_per_retry + + # policy:test_34_distribute_set_med_action which subtract 100 in its med attr + # is attached to peer2(10.0.0.2)'s distribute-policy. + self.setup_config(exabgp, "test_34_distribute_set_med_action", "distribute", add_exabgp=True) + 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, r1, retry=self.retry_count_common, interval=w) + self.assertIsNotNone(path) + + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer1, r1, retry=self.retry_count_common, interval=w) + self.assertIsNotNone(qpath) + + path = self.get_paths_in_localrib(peer2, r1, retry=self.retry_count_common, interval=w) + self.assertIsNotNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2, r1, retry=self.retry_count_common, interval=w) + self.assertIsNotNone(qpath) + + path = self.get_paths_in_localrib(peer1, r2, retry=self.retry_count_common, interval=w) + self.assertIsNotNone(path) + + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer1, r2, retry=self.retry_count_common, interval=w) + self.assertIsNotNone(qpath) + + path = self.get_paths_in_localrib(peer2, r2, retry=self.retry_count_common, interval=w) + self.assertIsNotNone(path) + + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer2, r2, retry=self.retry_count_common, interval=w) + self.assertIsNotNone(qpath) + + # check show ip bgp on peer2(quagga2) + self.assertTrue(self.check_med(peer1, r1.split('/'), 400, retry=0)) + self.assertTrue(self.check_med(peer2, r1.split('/'), 400, retry=0)) + + """ import-policy test @@ -1884,7 +2290,7 @@ class GoBGPTest(GoBGPTestBase): | ->(r1,r3)-> rib ->(r1,r3)-> adj-rib-out | ->(r1,r3)-> peer3 ------------------------------------------------- """ - def test_28_distribute_policy_update(self): + def test_35_distribute_policy_update(self): # initialize test environment @@ -1899,7 +2305,7 @@ class GoBGPTest(GoBGPTestBase): # policy:test_28_distribute_policy_update which rejects routes # 192.168.20.0/24, 192.168.200.0/24 from peer2 is attached to peer2. # After policy's update, 192.168.200.0/24 can go through. - self.setup_config(peer2, "test_28_distribute_policy_update", "distribute") + self.setup_config(peer2, "test_35_distribute_policy_update", "distribute") self.initialize() # add other network @@ -1953,7 +2359,7 @@ class GoBGPTest(GoBGPTestBase): # update policy print "update_policy_config" - self.set_policy(peer2, "distribute", "test_28_distribute_policy_update_softreset") + self.set_policy(peer2, "distribute", "test_35_distribute_policy_update_softreset") time.sleep(self.initial_wait_time) # soft reset @@ -2010,11 +2416,12 @@ neighbor 10.0.255.1 { self.config_name = config_name print >> self.o, self.basic_conf_begin - def add_route(self, prefix, aspath='', community=''): + def add_route(self, prefix, aspath='', community='', med='0'): 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 + 'community': community, + 'med': med} + r = "route %(prefix)s next-hop 10.0.0.100 as-path [%(aspath)s] community [%(community)s] med %(med)s;" % value print >> self.o, r def write(self): |