diff options
-rw-r--r-- | test/scenario_test/policy/policy_generator.go | 97 | ||||
-rw-r--r-- | test/scenario_test/quagga_access.py | 23 | ||||
-rw-r--r-- | test/scenario_test/route_server_policy_test.py | 305 |
3 files changed, 400 insertions, 25 deletions
diff --git a/test/scenario_test/policy/policy_generator.go b/test/scenario_test/policy/policy_generator.go index 8336c8f8..0d81fadc 100644 --- a/test/scenario_test/policy/policy_generator.go +++ b/test/scenario_test/policy/policy_generator.go @@ -3,13 +3,14 @@ package main import ( "bytes" "fmt" - "github.com/BurntSushi/toml" - "github.com/jessevdk/go-flags" - "github.com/osrg/gobgp/config" "io/ioutil" "log" "net" "os" + + "github.com/BurntSushi/toml" + "github.com/jessevdk/go-flags" + "github.com/osrg/gobgp/config" ) func bindPolicy(outputDir, peer, target, policyName string, isReplace bool, defaultReject bool) { @@ -478,7 +479,7 @@ func createPolicyConfig() *config.RoutingPolicy { Conditions: config.Conditions{ MatchPrefixSet: "psExabgp", MatchNeighborSet: "nsExabgp", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, }, Actions: config.Actions{ AcceptRoute: true, @@ -493,7 +494,7 @@ func createPolicyConfig() *config.RoutingPolicy { Conditions: config.Conditions{ MatchPrefixSet: "psExabgp", MatchNeighborSet: "nsExabgp", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, }, Actions: config.Actions{ AcceptRoute: true, @@ -508,7 +509,7 @@ func createPolicyConfig() *config.RoutingPolicy { Conditions: config.Conditions{ MatchPrefixSet: "psExabgp", MatchNeighborSet: "nsExabgp", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, }, Actions: config.Actions{ AcceptRoute: true, @@ -566,7 +567,7 @@ func createPolicyConfig() *config.RoutingPolicy { Conditions: config.Conditions{ MatchPrefixSet: "psExabgp", MatchNeighborSet: "nsExabgp", - MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, }, Actions: config.Actions{ AcceptRoute: true, @@ -576,6 +577,42 @@ func createPolicyConfig() *config.RoutingPolicy { }, } + st_asprepend := config.Statement{ + Name: "st_asprepend", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: true, + BgpActions: config.BgpActions{ + SetAsPathPrepend: config.SetAsPathPrepend{ + As: "65005", + RepeatN: 5, + }, + }, + }, + } + + st_asprepend_lastas := config.Statement{ + Name: "st_asprepend_lastas", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: true, + BgpActions: config.BgpActions{ + SetAsPathPrepend: config.SetAsPathPrepend{ + As: "last-as", + RepeatN: 5, + }, + }, + }, + } + test_01_import_policy_initial := config.PolicyDefinition{ Name: "test_01_import_policy_initial", StatementList: []config.Statement{st0}, @@ -716,7 +753,6 @@ func createPolicyConfig() *config.RoutingPolicy { StatementList: []config.Statement{st_comNull}, } - test_25_med_replace_action_import := config.PolicyDefinition{ Name: "test_25_med_replace_action_import", StatementList: []config.Statement{st_medReplace}, @@ -767,18 +803,37 @@ func createPolicyConfig() *config.RoutingPolicy { 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_35_distribute_policy_update := config.PolicyDefinition{ + Name: "test_35_distribute_policy_update", + StatementList: []config.Statement{st1}, + } - test_35_distribute_policy_update_softreset := config.PolicyDefinition{ - Name: "test_35_distribute_policy_update_softreset", - StatementList: []config.Statement{st2}, - } + test_35_distribute_policy_update_softreset := config.PolicyDefinition{ + Name: "test_35_distribute_policy_update_softreset", + StatementList: []config.Statement{st2}, + } + test_36_aspath_prepend_action_import := config.PolicyDefinition{ + Name: "test_36_aspath_prepend_action_import", + StatementList: []config.Statement{st_asprepend}, + } + + test_37_aspath_prepend_action_export := config.PolicyDefinition{ + Name: "test_37_aspath_prepend_action_export", + StatementList: []config.Statement{st_asprepend}, + } + + test_38_aspath_prepend_action_lastas_import := config.PolicyDefinition{ + Name: "test_38_aspath_prepend_action_lastas_import", + StatementList: []config.Statement{st_asprepend_lastas}, + } + + test_39_aspath_prepend_action_lastas_export := config.PolicyDefinition{ + Name: "test_39_aspath_prepend_action_lastas_export", + StatementList: []config.Statement{st_asprepend_lastas}, + } - ds := config.DefinedSets{ + ds := config.DefinedSets{ PrefixSetList: []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5, ps6, psExabgp}, NeighborSetList: []config.NeighborSet{nsPeer2, nsPeer2V6, nsExabgp}, BgpDefinedSets: config.BgpDefinedSets{ @@ -828,8 +883,12 @@ func createPolicyConfig() *config.RoutingPolicy { 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, + test_35_distribute_policy_update, + test_35_distribute_policy_update_softreset, + test_36_aspath_prepend_action_import, + test_37_aspath_prepend_action_export, + test_38_aspath_prepend_action_lastas_import, + test_39_aspath_prepend_action_lastas_export, }, } return p diff --git a/test/scenario_test/quagga_access.py b/test/scenario_test/quagga_access.py index a04ccd59..8e011398 100644 --- a/test/scenario_test/quagga_access.py +++ b/test/scenario_test/quagga_access.py @@ -133,14 +133,25 @@ def lookup_prefix(tn, prefix, af): return info = tn.read_until("bgpd#") + lines = info.split("\n") paths = [] - for line in info.split("\n"): + + if len(lines) > 1 and "BGP routing table entry for " + prefix in lines[1]: + idx_nw = -1 + nexthop = '' + # check if the prefix is originated route by its own or not. + for idx, line in enumerate(lines): + if "from" in line: + nexthop = line.split()[0] + idx_nw = idx + if nexthop == "0.0.0.0": + return paths + path = {} - if "from" in line: - nexthop = line.split()[0] - path['Network'] = prefix - path['Next Hop'] = nexthop - paths.append(path) + path['aspath'] = lines[idx_nw - 1].strip().split(" ") + path['Network'] = prefix + path['Next Hop'] = nexthop + paths.append(path) return paths diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py index cfbdddd3..e4cd6750 100644 --- a/test/scenario_test/route_server_policy_test.py +++ b/test/scenario_test/route_server_policy_test.py @@ -2387,6 +2387,311 @@ class GoBGPTest(GoBGPTestBase): self.assertTrue(path_exists_in_routing_table(peer3, r3)) + + """ + import-policy test + --------------------------------------- + exabgp ->(aspath=[65100 65099 65000])->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_36_aspath_prepend_action_import(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100', '65099', '65000'] + 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_36_aspath_prepend_action_import which prepends asnumber 65005 + # 5 times is attached to peer2(10.0.0.2)'s export-policy. + self.setup_config(peer2, "test_36_aspath_prepend_action_import", "import", add_exabgp=True) + self.initialize() + + def get_asseq(target): + attrs = [p for p in target[0]['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] + + 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 aspath + asseq = get_asseq(path) + expected = [int(n) for n in asns] + self.assertListEqual(asseq, expected) + + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer1,prefix1, retry=self.retry_count_common) + self.assertIsNotNone(qpath) + + # check as path + path_asns = qpath['aspath'] + expected = asns + self.assertListEqual(path_asns, expected) + + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=0) + self.assertIsNotNone(path) + + # check aspath + asseq = get_asseq(path) + expected = [int(n) for n in ['65005'] * 5 + asns ] + self.assertListEqual(asseq, expected) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2, prefix1, retry=self.retry_count_common) + self.assertIsNotNone(path) + + print(qpath) + + # check as path + path_asns = qpath['aspath'] + expected = ['65005'] * 5 + asns + self.assertListEqual(path_asns, expected) + + + """ + export-policy test + --------------------------------------- + exabgp ->(aspath=[65100 65099 65000])->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_37_aspath_prepend_action_export(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100', '65099', '65000'] + 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_37_aspath_prepend_action_export which prepends asnumber 65005 + # 5 times is attached to peer2(10.0.0.2)'s export-policy. + self.setup_config(peer2, "test_37_aspath_prepend_action_export", "export", add_exabgp=True) + self.initialize() + + def get_asseq(target): + attrs = [p for p in target[0]['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] + + 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 aspath + asseq = get_asseq(path) + expected = [int(n) for n in asns] + self.assertListEqual(asseq, expected) + + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer1,prefix1, retry=self.retry_count_common) + self.assertIsNotNone(qpath) + + # check as path + path_asns = qpath['aspath'] + expected = asns + self.assertListEqual(path_asns, expected) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=0) + self.assertIsNotNone(path) + + # check aspath + asseq = get_asseq(path) + expected = [int(n) for n in asns] + self.assertListEqual(asseq, expected) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2, prefix1, retry=self.retry_count_common) + self.assertIsNotNone(path) + + # check as path + path_asns = qpath['aspath'] + expected = ['65005'] * 5 + asns + self.assertListEqual(path_asns, expected) + + + """ + import-policy test + --------------------------------------- + exabgp ->(aspath=[65100 65099 65000])->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_38_aspath_prepend_action_lastas_import(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100', '65099', '65000'] + 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_38_aspath_prepend_action_lastas_import which prepends + # the leftmost asnumber 5 times is attached to peer2(10.0.0.2)'s import-policy. + self.setup_config(peer2, "test_38_aspath_prepend_action_lastas_import", "import", add_exabgp=True) + self.initialize() + + def get_asseq(target): + attrs = [p for p in target[0]['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] + + 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 aspath + asseq = get_asseq(path) + expected = [int(n) for n in asns] + self.assertListEqual(asseq, expected) + + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer1,prefix1, retry=self.retry_count_common) + self.assertIsNotNone(qpath) + + # check as path + path_asns = qpath['aspath'] + expected = asns + self.assertListEqual(path_asns, expected) + + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=0) + self.assertIsNotNone(path) + + # check aspath + asseq = get_asseq(path) + expected = [int(n) for n in ['65100'] * 5 + asns] + self.assertListEqual(asseq, expected) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2, prefix1, retry=self.retry_count_common) + self.assertIsNotNone(path) + + print(qpath) + + # check as path + path_asns = qpath['aspath'] + expected = ['65100'] * 5 + asns + self.assertListEqual(path_asns, expected) + + + + """ + export-policy test + --------------------------------------- + exabgp ->(aspath=[65100 65099 65000])->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_39_aspath_prepend_action_lastas_export(self): + + # generate exabgp configuration file + prefix1 = "192.168.100.0/24" + asns = ['65100', '65099', '65000'] + 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_39_aspath_prepend_action_lastas_export which prepends + # the leftmost asnumber 5 times is attached to peer2(10.0.0.2)'s export-policy. + self.setup_config(peer2, "test_39_aspath_prepend_action_lastas_export", "export", add_exabgp=True) + self.initialize() + + def get_asseq(target): + attrs = [p for p in target[0]['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] + + 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 aspath + asseq = get_asseq(path) + expected = [int(n) for n in asns] + self.assertListEqual(asseq, expected) + + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer1, prefix1, retry=self.retry_count_common) + self.assertIsNotNone(qpath) + + # check as path + path_asns = qpath['aspath'] + expected = asns + self.assertListEqual(path_asns, expected) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1, retry=0) + self.assertIsNotNone(path) + + # check aspath + asseq = get_asseq(path) + expected = [int(n) for n in asns] + self.assertListEqual(asseq, expected) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2, prefix1, retry=self.retry_count_common) + self.assertIsNotNone(path) + + # check as path + path_asns = qpath['aspath'] + expected = ['65100'] * 5 + asns + self.assertListEqual(path_asns, expected) + + + class ExabgpConfig(object): basic_conf_begin = ''' |