diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-08-19 11:39:46 +0900 |
---|---|---|
committer | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-08-19 17:31:29 +0900 |
commit | fb91965dd47045339a78f2231169a9d32be52985 (patch) | |
tree | 91e6785c25bb3d1c753352615884d529b077ff5c | |
parent | 34c10c943f9b581285316f529a982d69bf9d8fd5 (diff) |
scenario_test: add ext-community action test
-rw-r--r-- | policy/policy.go | 9 | ||||
-rw-r--r-- | table/path.go | 3 | ||||
-rw-r--r-- | test/scenario_test/gobgp_test.py | 10 | ||||
-rw-r--r-- | test/scenario_test/policy/policy_generator.go | 45 | ||||
-rw-r--r-- | test/scenario_test/quagga_access.py | 19 | ||||
-rw-r--r-- | test/scenario_test/route_server_policy_test.py | 272 |
6 files changed, 335 insertions, 23 deletions
diff --git a/policy/policy.go b/policy/policy.go index 4755860a..a07dbc4a 100644 --- a/policy/policy.go +++ b/policy/policy.go @@ -69,7 +69,6 @@ func NewPolicy(pd config.PolicyDefinition, ds config.DefinedSets) *Policy { } for _, statement := range stmtList { - fmt.Println(statement.Conditions.BgpConditions) conditions := make([]Condition, 0) // prefix match @@ -1109,6 +1108,14 @@ func (a *CommunityAction) apply(path *table.Path) *table.Path { func (a *CommunityAction) extApply(path *table.Path) *table.Path { path.SetExtCommunities(a.ext, false) + + log.WithFields(log.Fields{ + "Topic": "Policy", + "Action": "extended community", + "Values": a.ext, + "Method": a.action, + }).Debug("extended community action applied") + return path } diff --git a/table/path.go b/table/path.go index f4f1893b..bc982cec 100644 --- a/table/path.go +++ b/table/path.go @@ -524,10 +524,11 @@ func (path *Path) SetExtCommunities(values []byte, doReplace bool) { exts = append(exts, e) values = values[8:] } - _, attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES) + idx, attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES) if attr != nil { l := attr.(*bgp.PathAttributeExtendedCommunities).Value l = append(l, exts...) + path.pathAttrs[idx] = bgp.NewPathAttributeExtendedCommunities(l) } else { path.pathAttrs = append(path.pathAttrs, bgp.NewPathAttributeExtendedCommunities(exts)) } diff --git a/test/scenario_test/gobgp_test.py b/test/scenario_test/gobgp_test.py index 45f36f1e..34a94c7d 100644 --- a/test/scenario_test/gobgp_test.py +++ b/test/scenario_test/gobgp_test.py @@ -231,7 +231,7 @@ class GoBGPTestBase(unittest.TestCase): if len(g_dest) > 0: assert len(g_dest) == 1 d = g_dest[0] - return d['paths'] + return d['paths'][0] else: retry_count += 1 if retry_count > retry: @@ -326,7 +326,7 @@ class GoBGPTestBase(unittest.TestCase): # get route information on quagga - def check_community(self, neighbor_address, target_addr, community, retry=3, interval=-1, af=IPv4): + def check_community(self, neighbor_address, target_addr, community, retry=3, interval=-1, af=IPv4, extended=False): if interval < 0: interval = self.wait_per_retry print "check route %s on quagga : %s" % (target_addr, neighbor_address) @@ -334,7 +334,11 @@ class GoBGPTestBase(unittest.TestCase): while True: tn = qaccess.login(neighbor_address) - result = qaccess.check_community(tn, target_addr, community, af) + result = False + if extended: + result = qaccess.check_ext_community(tn, target_addr, community, af) + else: + result = qaccess.check_community(tn, target_addr, community, af) qaccess.logout(tn) if result: diff --git a/test/scenario_test/policy/policy_generator.go b/test/scenario_test/policy/policy_generator.go index 4d94b470..8209c704 100644 --- a/test/scenario_test/policy/policy_generator.go +++ b/test/scenario_test/policy/policy_generator.go @@ -326,6 +326,18 @@ func createPolicyConfig() *config.RoutingPolicy { st_only_prefix_condition_accept := createStatement("st_only_prefix_condition_accept", "psExabgp", "", true) + st_extcomAdd := createStatement("st_extcommunity_add", "psExabgp", "nsExabgp", true) + st_extcomAdd.Actions.BgpActions.SetExtCommunity.SetExtCommunityMethod.Communities = []string{"0:2:0xfd:0xe8:0:0:0:1"} + st_extcomAdd.Actions.BgpActions.SetExtCommunity.Options = "ADD" + + st_extcomAdd_append := createStatement("st_extcommunity_add_append", "psExabgp", "nsExabgp", true) + st_extcomAdd_append.Actions.BgpActions.SetExtCommunity.SetExtCommunityMethod.Communities = []string{"0:2:0xfe:0x4c:0:0:0:0x64"} + st_extcomAdd_append.Actions.BgpActions.SetExtCommunity.Options = "ADD" + + st_extcomAdd_multiple := createStatement("st_extcommunity_add_multiple", "psExabgp", "nsExabgp", true) + st_extcomAdd_multiple.Actions.BgpActions.SetExtCommunity.SetExtCommunityMethod.Communities = []string{"0:2:0xfe:0x4c:0:0:0:0x64", "0:2:0:0x64:0:0:0:0x64"} + st_extcomAdd_multiple.Actions.BgpActions.SetExtCommunity.Options = "ADD" + test_01_import_policy_initial := config.PolicyDefinition{ Name: "test_01_import_policy_initial", Statements: config.Statements{ @@ -655,6 +667,35 @@ func createPolicyConfig() *config.RoutingPolicy { }, } + test_43_extcommunity_add_action_import := config.PolicyDefinition{ + Name: "test_43_extcommunity_add_action_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_extcomAdd}, + }, + } + + test_44_extcommunity_add_action_append_import := config.PolicyDefinition{ + Name: "test_44_extcommunity_add_action_append_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_extcomAdd_append}, + }, + } + + test_45_extcommunity_add_action_multiple_import := config.PolicyDefinition{ + Name: "test_45_extcommunity_add_action_multiple_import", + Statements: config.Statements{ + StatementList: []config.Statement{st_extcomAdd_multiple}, + }, + } + + test_46_extcommunity_add_action_export := config.PolicyDefinition{ + Name: "test_46_extcommunity_add_action_export", + Statements: config.Statements{ + StatementList: []config.Statement{st_extcomAdd}, + }, + } + + ds := config.DefinedSets{} ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5, ps6, psExabgp} ds.NeighborSets.NeighborSetList = []config.NeighborSet{nsPeer2, nsPeer2V6, nsExabgp} @@ -713,6 +754,10 @@ func createPolicyConfig() *config.RoutingPolicy { test_40_ecommunity_origin_condition_import, test_41_ecommunity_target_condition_export, test_42_only_prefix_condition_accept, + test_43_extcommunity_add_action_import, + test_44_extcommunity_add_action_append_import, + test_45_extcommunity_add_action_multiple_import, + test_46_extcommunity_add_action_export, }, }, } diff --git a/test/scenario_test/quagga_access.py b/test/scenario_test/quagga_access.py index 8e011398..51008b02 100644 --- a/test/scenario_test/quagga_access.py +++ b/test/scenario_test/quagga_access.py @@ -172,6 +172,25 @@ def check_community(tn, addr, community, af=IPv4): return False +def check_ext_community(tn, addr, community, af=IPv4): + if af == IPv4: + tn.write("show ip bgp " + addr + "\n") + elif af == IPv6: + tn.write("show bgp ipv6 " + addr + "\n") + else: + print "invalid af: ", af + return + result = tn.read_until("bgpd#") + for line in result.split("\n"): + if "Extended Community:" in line: + extcomms = line.split()[2:] + for e in extcomms: + if community == e: + return True + + return False + + def check_med(tn, addr, med, af=IPv4): if af == IPv4: tn.write("show ip bgp " + addr[0] + "\n") diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py index 3ff08a1e..f6625ac7 100644 --- a/test/scenario_test/route_server_policy_test.py +++ b/test/scenario_test/route_server_policy_test.py @@ -1228,8 +1228,9 @@ class GoBGPTest(GoBGPTestBase): # check adj-rib-out in peer2 path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + print(path) self.assertIsNotNone(path) - attrs = [x for x in path[0]['attrs'] if 'communities' in x ] + attrs = [x for x in path['attrs'] if 'communities' in x ] self.assertTrue((65100 << 16 | 20) in attrs[0]['communities']) # check show ip bgp on peer2(quagga2) @@ -1283,7 +1284,7 @@ class GoBGPTest(GoBGPTestBase): # 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 'communities' in x ] + attrs = [x for x in path['attrs'] if 'communities' in x ] self.assertTrue((65100 << 16 | 20) in attrs[0]['communities']) self.assertTrue((65100 << 16 | 30) in attrs[0]['communities']) @@ -1339,7 +1340,7 @@ class GoBGPTest(GoBGPTestBase): # 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 'communities' in x ] + attrs = [x for x in path['attrs'] if 'communities' in x ] self.assertTrue((65100 << 16 | 20) not in attrs[0]['communities']) self.assertTrue((65100 << 16 | 30) not in attrs[0]['communities']) @@ -1397,7 +1398,7 @@ class GoBGPTest(GoBGPTestBase): # 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 'communities' in x ] + attrs = [x for x in path['attrs'] if 'communities' in x ] self.assertFalse('communities' in attrs) # check show ip bgp on peer2(quagga2) @@ -1452,7 +1453,7 @@ class GoBGPTest(GoBGPTestBase): # 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 'communities' in x ] + attrs = [x for x in path['attrs'] if 'communities' in x ] self.assertFalse((65100 << 16 | 20) in attrs[0]['communities']) # check out-rib path = self.get_adj_rib_out(peer2, prefix1, retry=0) @@ -1511,7 +1512,7 @@ class GoBGPTest(GoBGPTestBase): # 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 'communities' in x ] + attrs = [x for x in path['attrs'] if 'communities' in x ] self.assertFalse((65100 << 16 | 20) in attrs[0]['communities']) self.assertFalse((65100 << 16 | 30) in attrs[0]['communities']) # check out-rib @@ -1574,7 +1575,7 @@ class GoBGPTest(GoBGPTestBase): # check adj-rib-out in peer2 path = self.get_paths_in_localrib(peer2, prefix1, retry=1) self.assertIsNotNone(path) - attrs = [x for x in path[0]['attrs'] if 'communities' in x ] + attrs = [x for x in path['attrs'] if 'communities' in x ] self.assertTrue((65100 << 16 | 20) in attrs[0]['communities']) self.assertTrue((65100 << 16 | 30) in attrs[0]['communities']) # check out-rib @@ -1638,7 +1639,7 @@ class GoBGPTest(GoBGPTestBase): # 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 'communities' in x ] + attrs = [x for x in path['attrs'] if 'communities' in x ] self.assertTrue((65100 << 16 | 10) in attrs[0]['communities']) self.assertTrue((65100 << 16 | 20) in attrs[0]['communities']) self.assertTrue((65100 << 16 | 30) in attrs[0]['communities']) @@ -1700,7 +1701,7 @@ class GoBGPTest(GoBGPTestBase): # 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] + attrs = [x for x in path['attrs'] if 'metric' in x] self.assertTrue(100 == attrs[0]['metric']) # check show ip bgp on peer2(quagga2) @@ -1753,7 +1754,7 @@ class GoBGPTest(GoBGPTestBase): # 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] + attrs = [x for x in path['attrs'] if 'metric' in x] self.assertTrue(400 == attrs[0]['metric']) # check show ip bgp on peer2(quagga2) @@ -1806,7 +1807,7 @@ class GoBGPTest(GoBGPTestBase): # 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] + attrs = [x for x in path['attrs'] if 'metric' in x] self.assertTrue(200 == attrs[0]['metric']) # check show ip bgp on peer2(quagga2) @@ -1860,7 +1861,7 @@ class GoBGPTest(GoBGPTestBase): # 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] + attrs = [x for x in path['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) @@ -1919,7 +1920,7 @@ class GoBGPTest(GoBGPTestBase): # 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] + attrs = [x for x in path['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) @@ -1978,7 +1979,7 @@ class GoBGPTest(GoBGPTestBase): # 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] + attrs = [x for x in path['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) @@ -2430,7 +2431,7 @@ class GoBGPTest(GoBGPTestBase): self.initialize() def get_asseq(target): - attrs = [p for p in target[0]['attrs'] if p['type'] == 2] + attrs = [p for p in target['attrs'] if p['type'] == 2] path_asns = [a['asns'] for a in attrs[0]['as_paths'] if a['segment_type'] == 2] return path_asns[0] @@ -2507,7 +2508,7 @@ class GoBGPTest(GoBGPTestBase): self.initialize() def get_asseq(target): - attrs = [p for p in target[0]['attrs'] if p['type'] == 2] + attrs = [p for p in target['attrs'] if p['type'] == 2] path_asns = [a['asns'] for a in attrs[0]['as_paths'] if a['segment_type'] == 2] return path_asns[0] @@ -2581,7 +2582,7 @@ class GoBGPTest(GoBGPTestBase): self.initialize() def get_asseq(target): - attrs = [p for p in target[0]['attrs'] if p['type'] == 2] + attrs = [p for p in target['attrs'] if p['type'] == 2] path_asns = [a['asns'] for a in attrs[0]['as_paths'] if a['segment_type'] == 2] return path_asns[0] @@ -2659,7 +2660,7 @@ class GoBGPTest(GoBGPTestBase): self.initialize() def get_asseq(target): - attrs = [p for p in target[0]['attrs'] if p['type'] == 2] + attrs = [p for p in target['attrs'] if p['type'] == 2] path_asns = [a['asns'] for a in attrs[0]['as_paths'] if a['segment_type'] == 2] return path_asns[0] @@ -2872,6 +2873,241 @@ class GoBGPTest(GoBGPTestBase): qpath = self.get_route(peer2, r2, retry=self.retry_count_common, interval=w) self.assertIsNone(qpath) + """ + import-policy test + --------------------------------------- + exabgp ->(extcommunity=none) ->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | add ext-community | + --------------------------------------- + """ + def test_43_extcommunity_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) ] + as_path = reduce(lambda a,b: a + " " + b, asns) + + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path) + e.write() + + self.quagga_num = 2 + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + w = self.wait_per_retry + + # policy:test_43_extcommunity_add_action_import which adds extended community 65000:1 + # is attached to peer2(10.0.0.2)'s import-policy. + self.setup_config(peer2, "test_43_extcommunity_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 localrib in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + self.assertIsNotNone(path) + attrs = [x for x in path['attrs'] if x['type'] == 16] + self.assertEqual(len(attrs), 1) + extcomm_value = attrs[0]['value'][0] + self.assertEqual(extcomm_value['type'], 0) + self.assertEqual(extcomm_value['subtype'], 2) + self.assertEqual(extcomm_value['value'], "65000:1") + + # 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_community(peer2, prefix1.split('/')[0], 'RT:65000:1', retry=0, extended=True)) + + + """ + import-policy test + -------------------------------------- + exabgp ->(extcommunity=RT:65000:1) ->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | add ext-community | + --------------------------------------- + """ + def test_44_extcommunity_add_action_append_import(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] + as_path = reduce(lambda a,b: a + " " + b, asns) + extcomm = 'target:65000:1' + + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, extcommunity=extcomm) + e.write() + + self.quagga_num = 2 + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + w = self.wait_per_retry + + # policy:test_44_extcommunity_add_action_append_import which adds extended community 65100:100 + # is attached to peer2(10.0.0.2)'s import-policy. + self.setup_config(peer2, "test_44_extcommunity_add_action_append_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 localrib in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + self.assertIsNotNone(path) + attrs = [x for x in path['attrs'] if x['type'] == 16] + self.assertEqual(len(attrs), 1) + extcomm_result = [str(e['type']) + ':' + str(e['subtype']) + ':' + e['value'] for e in attrs[0]['value']] + self.assertEqual(len(extcomm_result), 2) + self.assertTrue('0:2:65000:1' in extcomm_result) + self.assertTrue('0:2:65100:100' in extcomm_result) + + # 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_community(peer2, prefix1.split('/')[0], 'RT:65000:1', retry=0, extended=True)) + self.assertTrue(self.check_community(peer2, prefix1.split('/')[0], 'RT:65100:100', retry=0, extended=True)) + + + """ + import-policy test + --------------------------------------- + exabgp ->(extcommunity=none) ->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | add ext-community | + --------------------------------------- + """ + def test_45_extcommunity_add_action_multiple_import(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] + as_path = reduce(lambda a,b: a + " " + b, asns) + + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path) + e.write() + + self.quagga_num = 2 + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + w = self.wait_per_retry + + # policy:test_45_extcommunity_add_action_multiple_import which adds extended community RT:65100:100 and RT:100:100 + # is attached to peer2(10.0.0.2)'s export-policy. + self.setup_config(peer2, "test_45_extcommunity_add_action_multiple_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 localrib in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + self.assertIsNotNone(path) + attrs = [x for x in path['attrs'] if x['type'] == 16] + self.assertEqual(len(attrs), 1) + extcomm_result = [str(e['type']) + ':' + str(e['subtype']) + ':' + e['value'] for e in attrs[0]['value']] + self.assertEqual(len(extcomm_result), 2) + self.assertTrue('0:2:65100:100' in extcomm_result) + self.assertTrue('0:2:100:100' in extcomm_result) + + # 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_community(peer2, prefix1.split('/')[0], 'RT:65100:100', retry=0, extended=True)) + self.assertTrue(self.check_community(peer2, prefix1.split('/')[0], 'RT:100:100', retry=0, extended=True)) + + + """ + export-policy test + --------------------------------------- + exabgp ->(extcommunity=none) ->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | add ext-community | + --------------------------------------- + """ + def test_46_extcommunity_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) ] + as_path = reduce(lambda a,b: a + " " + b, asns) + + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path) + e.write() + + self.quagga_num = 2 + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + # policy:test_46_extcommunity_add_action_export which adds extended community 65000:1 + # is attached to peer2(10.0.0.2)'s export-policy. + self.setup_config(peer2, "test_46_extcommunity_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 localrib in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=self.retry_count_common) + self.assertIsNotNone(path) + attrs = [x for x in path['attrs'] if x['type'] == 16] + self.assertEqual(len(attrs), 0) + + # check adj-rib-out + path = self.get_adj_rib_out(peer2, prefix1, retry=self.retry_count_common) + self.assertIsNotNone(path) + attrs = [x for x in path['attrs'] if x['type'] == 16] + self.assertEqual(len(attrs), 1) + extcomm_value = attrs[0]['value'][0] + self.assertEqual(extcomm_value['type'], 0) + self.assertEqual(extcomm_value['subtype'], 2) + self.assertEqual(extcomm_value['value'], "65000:1") + + # 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_community(peer2, prefix1.split('/')[0], 'RT:65000:1', retry=0, extended=True)) + class ExabgpConfig(object): |