diff options
-rw-r--r-- | server/server.go | 5 | ||||
-rw-r--r-- | test/scenario_test/constant.py | 1 | ||||
-rw-r--r-- | test/scenario_test/docker_control.py | 24 | ||||
-rw-r--r-- | test/scenario_test/gobgp_test.py | 7 | ||||
-rw-r--r-- | test/scenario_test/policy/policy_generator.go | 120 | ||||
-rw-r--r-- | test/scenario_test/route_server_policy_test.py | 579 |
6 files changed, 484 insertions, 252 deletions
diff --git a/server/server.go b/server/server.go index 08831efa..fb957cac 100644 --- a/server/server.go +++ b/server/server.go @@ -276,7 +276,6 @@ func (server *BgpServer) Serve() { senderMsgs = append(senderMsgs, m...) } case pl := <-server.policyUpdateCh: - log.Info("handle policy update ") server.handlePolicy(pl) } } @@ -383,6 +382,8 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg { func applyPolicies(peer *Peer, loc *LocalRib, d Direction, pathList []*table.Path) []*table.Path { var defaultPolicy config.DefaultPolicyType + ret := make([]*table.Path, 0, len(pathList)) + switch d { case POLICY_DIRECTION_EXPORT: defaultPolicy = loc.defaultExportPolicy @@ -395,9 +396,9 @@ func applyPolicies(peer *Peer, loc *LocalRib, d Direction, pathList []*table.Pat "Topic": "Server", "Key": peer.config.NeighborAddress, }).Error("direction is not specified.") + return ret } - ret := make([]*table.Path, 0, len(pathList)) for _, path := range pathList { if !path.IsWithdraw { var applied bool = false diff --git a/test/scenario_test/constant.py b/test/scenario_test/constant.py index 3b447813..65908a4f 100644 --- a/test/scenario_test/constant.py +++ b/test/scenario_test/constant.py @@ -66,3 +66,4 @@ ADJ_RIB_OUT = "adj-out" LOCAL_RIB = "local" GLOBAL_RIB = "global rib" NEIGHBOR = "neighbor" +POLICY = "policy" diff --git a/test/scenario_test/docker_control.py b/test/scenario_test/docker_control.py index f3d24fdd..056d43cd 100644 --- a/test/scenario_test/docker_control.py +++ b/test/scenario_test/docker_control.py @@ -315,7 +315,7 @@ def get_notification_from_exabgp_log(): return err_mgs -def make_config(quagga_num, go_path, bridge, peer_opts="", use_compiled=False): +def make_config(quagga_num, go_path, bridge, peer_opts="", use_compiled=False, ipver=''): if go_path != "": print "specified go path is [ " + go_path + " ]." if os.path.isdir(go_path): @@ -328,12 +328,14 @@ def make_config(quagga_num, go_path, bridge, peer_opts="", use_compiled=False): if use_compiled: tool = pwd + "/quagga-rsconfig " + # I want to avoid a global variable. + ip_version = ipver if ipver else IP_VERSION cmd = tool + " -n " + str(quagga_num) +\ - " -c /tmp/gobgp -v " + IP_VERSION + " -i " + bridge["BRIDGE_NAME"][-1] + " " + peer_opts + " -c /tmp/gobgp -v " + ip_version + " -i " + bridge["BRIDGE_NAME"][-1] + " " + peer_opts local(cmd, capture=True) -def update_policy_config(go_path, neighbor, policy_name, target, isReplace=False): +def update_policy_config(go_path, neighbor, policy_name, target, isReplace=False, defaultReject=False): if go_path != "": print "specified go path is [ " + go_path + " ]." if os.path.isdir(go_path): @@ -343,12 +345,13 @@ def update_policy_config(go_path, neighbor, policy_name, target, isReplace=False pwd = local("pwd", capture=True) replace = ' -r' if isReplace else '' - cmd = pwd + "/policy_generator -d /tmp/gobgp -n " + neighbor + " -t " + target + " -p " + policy_name + replace + reject = ' -j' if defaultReject else '' + cmd = pwd + "/policy_generator -d /tmp/gobgp -n " + neighbor + " -t " + target + " -p " + policy_name + replace + reject local(cmd, capture=True) # reload_config() -def make_config_append(quagga_num, go_path, bridge, peer_opts=""): +def make_config_append(quagga_num, go_path, bridge, peer_opts="", use_compiled=False, ipver=''): if go_path != "": print "specified go path is [ " + go_path + " ]." if os.path.isdir(go_path): @@ -356,9 +359,14 @@ def make_config_append(quagga_num, go_path, bridge, peer_opts=""): else: print "specified go path do not use." pwd = local("pwd", capture=True) + ip_version = ipver if ipver else IP_VERSION - cmd = go_path + "go run " + pwd + "/quagga-rsconfig.go -a " + str(quagga_num) +\ - " -c /tmp/gobgp -v " + IP_VERSION + " -i " + bridge["BRIDGE_NAME"][-1] + " " + peer_opts + tool = go_path + "go run " + pwd + "/quagga-rsconfig.go " + if use_compiled: + tool = pwd + "/quagga-rsconfig " + + cmd = tool + " -a " + str(quagga_num) +\ + " -c /tmp/gobgp -v " + ip_version + " -i " + bridge["BRIDGE_NAME"][-1] + " " + peer_opts local(cmd, capture=True) @@ -379,7 +387,7 @@ def build_config_tools(go_path): pwd = local("pwd", capture=True) cmd = go_path + "go build " + pwd + "/quagga-rsconfig.go" local(cmd, capture=True) - cmd = go_path + "go build " + pwd + "/policy_generator.go" + cmd = go_path + "go build " + pwd + "/policy/policy_generator.go" local(cmd, capture=True) diff --git a/test/scenario_test/gobgp_test.py b/test/scenario_test/gobgp_test.py index 78a29823..e416db2c 100644 --- a/test/scenario_test/gobgp_test.py +++ b/test/scenario_test/gobgp_test.py @@ -205,6 +205,13 @@ class GoBGPTestBase(unittest.TestCase): cmd += "softreset%s -a %s" % (type, af) local(cmd) + def set_policy(self, peer, target, policy_name, default_accept=True): + default_policy = "ACCEPT" if default_accept else "REJECT" + cmd = "%s " % CLI_CMD + cmd += NEIGHBOR + " %s " % peer + cmd += POLICY + " add %s %s %s" % (target, policy_name, default_policy) + local(cmd) + def get_paths_in_localrib(self, neighbor_address, target_prefix, af="ipv4", retry=3, interval=5): retry_count = 0 while True: diff --git a/test/scenario_test/policy/policy_generator.go b/test/scenario_test/policy/policy_generator.go index f72eb5c8..a4f70d0e 100644 --- a/test/scenario_test/policy/policy_generator.go +++ b/test/scenario_test/policy/policy_generator.go @@ -12,8 +12,7 @@ import ( "os" ) - -func bindPolicy(outputDir, peer, target, policyName string, isReplace bool) { +func bindPolicy(outputDir, peer, target, policyName string, isReplace bool, defaultReject bool) { newConf := config.Bgp{} _, d_err := toml.DecodeFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), &newConf) @@ -33,28 +32,37 @@ func bindPolicy(outputDir, peer, target, policyName string, isReplace bool) { } else { ap.ImportPolicies = append(ap.ImportPolicies, policyName) } + if defaultReject { + ap.DefaultImportPolicy = 1 + } case "export": if isReplace { ap.ExportPolicies = []string{policyName} } else { ap.ExportPolicies = append(ap.ExportPolicies, policyName) } + if defaultReject { + ap.DefaultExportPolicy = 1 + } case "distribute": if isReplace { ap.DistributePolicies = []string{policyName} } else { ap.DistributePolicies = append(ap.DistributePolicies, policyName) } + if defaultReject { + ap.DefaultDistributePolicy = 1 + } } newConf.NeighborList[idx] = neighbor } } policyConf := createPolicyConfig() - var buffer bytes.Buffer - encoder := toml.NewEncoder(&buffer) - encoder.Encode(newConf) - encoder.Encode(policyConf) + var buffer bytes.Buffer + encoder := toml.NewEncoder(&buffer) + encoder.Encode(newConf) + encoder.Encode(policyConf) e_err := ioutil.WriteFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), buffer.Bytes(), 0644) if e_err != nil { @@ -126,6 +134,15 @@ func createPolicyConfig() *config.RoutingPolicy { }}, } + ps6 := config.PrefixSet{ + PrefixSetName: "ps6", + PrefixList: []config.Prefix{ + config.Prefix{ + Address: net.ParseIP("192.168.10.0"), + Masklength: 24, + }}, + } + nsPeer2 := config.NeighborSet{ NeighborSetName: "nsPeer2", NeighborInfoList: []config.NeighborInfo{ @@ -456,6 +473,49 @@ func createPolicyConfig() *config.RoutingPolicy { }, } + st_distribute_reject := config.Statement{ + Name: "st_community_distriibute", + Conditions: config.Conditions{ + BgpConditions: config.BgpConditions{ + MatchCommunitySet: "comStr", + }, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + }, + } + + st_distribute_accept := config.Statement{ + Name: "st_distriibute_accept", + Conditions: config.Conditions{ + MatchPrefixSet: "ps6", + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: true, + }, + } + + + st_distribute_comm_add := config.Statement{ + Name: "st_distribute_comm_add", + Conditions: config.Conditions{ + BgpConditions: config.BgpConditions{ + MatchCommunitySet: "comStr", + }, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: true, + BgpActions: config.BgpActions{ + SetCommunity: config.SetCommunity{ + Communities: []string{"65100:20"}, + Options: "ADD", + }, + }, + }, + } test_01_import_policy_initial := config.PolicyDefinition{ Name: "test_01_import_policy_initial", @@ -597,8 +657,23 @@ func createPolicyConfig() *config.RoutingPolicy { StatementList: []config.Statement{st_comNull}, } + test_25_distribute_reject := config.PolicyDefinition{ + Name: "test_25_distribute_reject", + StatementList: []config.Statement{st_distribute_reject}, + } + + test_26_distribute_accept := config.PolicyDefinition{ + Name: "test_26_distribute_accept", + StatementList: []config.Statement{st_distribute_accept}, + } + + test_27_distribute_set_community_action := config.PolicyDefinition{ + Name: "test_27_distribute_set_community_action", + StatementList: []config.Statement{st_distribute_comm_add}, + } + ds := config.DefinedSets{ - PrefixSetList: []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5, psExabgp}, + PrefixSetList: []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5, ps6, psExabgp}, NeighborSetList: []config.NeighborSet{nsPeer2, nsPeer2V6, nsExabgp}, BgpDefinedSets: config.BgpDefinedSets{ AsPathSetList: []config.AsPathSet{aspathFrom, aspathAny, aspathOrigin, aspathOnly}, @@ -615,20 +690,20 @@ func createPolicyConfig() *config.RoutingPolicy { test_03_import_policy_update_softreset, test_04_export_policy_update, test_04_export_policy_update_softreset, - test_05_import_policy_initial_ipv6, + test_05_import_policy_initial_ipv6, test_06_export_policy_initial_ipv6, - test_07_import_policy_update, + test_07_import_policy_update, test_07_import_policy_update_softreset, - test_08_export_policy_update, + test_08_export_policy_update, test_08_export_policy_update_softreset, - test_09_aspath_length_condition_import, - test_10_aspath_from_condition_import, + test_09_aspath_length_condition_import, + test_10_aspath_from_condition_import, test_11_aspath_any_condition_import, - test_12_aspath_origin_condition_import, - test_13_aspath_only_condition_import, - test_14_aspath_only_condition_import, - test_15_community_condition_import, - test_16_community_condition_regexp_import, + test_12_aspath_origin_condition_import, + test_13_aspath_only_condition_import, + test_14_aspath_only_condition_import, + test_15_community_condition_import, + test_16_community_condition_regexp_import, test_17_community_add_action_import, test_18_community_replace_action_import, test_19_community_remove_action_import, @@ -637,19 +712,22 @@ 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, + }, } return p } - func main() { var opts struct { OutputDir string `short:"d" long:"output" description:"specifing the output directory"` - Neighbor string `short:"n" long:"neighbor" description:"neighbor ip adress to which add policy config"` + Neighbor string `short:"n" long:"neighbor" description:"neighbor ip adress to which add policy config"` Target string `short:"t" long:"target" description:"target such as export or import to which add policy"` PolicyName string `short:"p" long:"policy" description:"policy name bound to peer"` Replace bool `short:"r" long:"replace" description:"Replace existing policy with new one" default:"false"` + Reject bool `short:"j" long:"reject" description:"Set default policy reject" default:"false"` } parser := flags.NewParser(&opts, flags.Default) @@ -663,5 +741,5 @@ func main() { log.Fatal(err) } - bindPolicy(opts.OutputDir, opts.Neighbor, opts.Target, opts.PolicyName, opts.Replace) + bindPolicy(opts.OutputDir, opts.Neighbor, opts.Target, opts.PolicyName, opts.Replace, opts.Reject) } diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py index 190c30fc..ced52e56 100644 --- a/test/scenario_test/route_server_policy_test.py +++ b/test/scenario_test/route_server_policy_test.py @@ -45,6 +45,7 @@ class GoBGPTest(GoBGPTestBase): super(GoBGPTest, self).__init__(*args, **kwargs) + @print_elapsed_time def setUp(self): self.quagga_configs = [] self.use_ipv6_gobgp = False @@ -78,9 +79,21 @@ class GoBGPTest(GoBGPTestBase): 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) + def setup_config(self, peer, policy_name, target, add_exabgp=False, defaultReject=False): + ipver = IPv4 if not self.use_ipv6_gobgp else IPv6 + fab.make_config(self.quagga_num, self.go_path, BRIDGE_0, use_compiled=True, ipver=ipver) + + if add_exabgp: + self.setup_exabgp() + + fab.update_policy_config(self.go_path, peer, policy_name, target, defaultReject=defaultReject) + + @print_elapsed_time + def setup_exabgp(self): + self.use_exa_bgp = True + ipver = IPv4 if not self.use_ipv6_gobgp else IPv6 + fab.make_config_append(100, self.go_path, BRIDGE_0, peer_opts="--none-peer", use_compiled=True, ipver=ipver) + """ import-policy test @@ -269,8 +282,7 @@ class GoBGPTest(GoBGPTestBase): # update policy print "update_policy_config" - fab.update_policy_config(self.go_path, peer3, "test_03_import_policy_update_softreset", "import", isReplace=True) - fab.reload_config() + self.set_policy(peer3, "import", "test_03_import_policy_update_softreset") time.sleep(self.initial_wait_time) # soft reset @@ -318,7 +330,6 @@ class GoBGPTest(GoBGPTestBase): # policy_pattern:p4 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 export-policy. - self.initialize(policy_pattern="test_04_export_policy_update") peer1 = "10.0.0.1" peer2 = "10.0.0.2" @@ -328,6 +339,9 @@ class GoBGPTest(GoBGPTestBase): r3 = "192.168.200.0/24" w = self.wait_per_retry + self.setup_config(peer3, "test_04_export_policy_update", "export") + self.initialize() + # add other network tn = qaccess.login(peer2) print "add network 192.168.20.0/24" @@ -390,7 +404,7 @@ class GoBGPTest(GoBGPTestBase): # update policy print "update_policy_config" - fab.update_policy_config(parser_option.go_path, policy_pattern="test_04_export_policy_update") + self.set_policy(peer3, "export", "test_04_export_policy_update_softreset") time.sleep(self.initial_wait_time) # soft reset @@ -427,11 +441,7 @@ class GoBGPTest(GoBGPTestBase): # policy_pattern:p5 attaches a policy to reject route 2001:0:10:2:: (64...128) # coming from peer2(2001::192:168:0:2) to peer3(2001::192:168:0:3)'s # import-policy. - self.use_ipv6_gobgp = True - self.initialize(policy_pattern="test_05_import_policy_initial_ipv6") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") peer1 = "2001::192:168:0:1" peer2 = "2001::192:168:0:2" @@ -439,6 +449,13 @@ class GoBGPTest(GoBGPTestBase): r1 = "2001:0:10:2::/64" w = self.wait_per_retry + self.use_ipv6_gobgp = True + self.setup_config(peer3, "test_05_import_policy_initial_ipv6", "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, r1, retry=self.retry_count_common, af=IPv6, interval=w) self.assertIsNotNone(path) @@ -472,10 +489,6 @@ class GoBGPTest(GoBGPTestBase): # initialize test environment # policy_pattern:p6 attaches a policy to reject route 2001:0:10:2:: (64...128) # coming from peer2(2001::192:168:0:2) to peer3(2001::192:168:0:3)'s export-policy. - self.use_ipv6_gobgp = True - self.initialize(policy_pattern="test_06_export_policy_initial_ipv6") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") peer1 = "2001::192:168:0:1" peer2 = "2001::192:168:0:2" @@ -483,6 +496,13 @@ class GoBGPTest(GoBGPTestBase): r1 = "2001:0:10:2::/64" w = self.wait_per_retry + self.use_ipv6_gobgp = True + self.setup_config(peer3, "test_06_export_policy_initial_ipv6", "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, r1, retry=self.retry_count_common, interval=w, af=IPv6) self.assertIsNotNone(paths) @@ -535,8 +555,6 @@ class GoBGPTest(GoBGPTestBase): # 2001:0:10:2::/64, 2001:0:10:20::/64, 2001:0:10:200::/64 # coming from peer2(2001::192:168:0:2) to peer3(2001::192:168:0:3)'s # import-policy. - self.use_ipv6_gobgp = True - self.initialize(policy_pattern="test_07_import_policy_update") peer1 = "2001::192:168:0:1" peer2 = "2001::192:168:0:2" @@ -544,9 +562,12 @@ class GoBGPTest(GoBGPTestBase): r1 = "2001:0:10:2::/64" r2 = "2001:0:10:20::/64" r3 = "2001:0:10:200::/64" - w = self.wait_per_retry + self.use_ipv6_gobgp = True + self.setup_config(peer3, "test_07_import_policy_update", "import") + self.initialize() + # add other network tn = qaccess.login(peer2) print "add network 2001:0:10:20::/64" @@ -599,7 +620,7 @@ class GoBGPTest(GoBGPTestBase): # update policy print "update_policy_config" - fab.update_policy_config(parser_option.go_path, policy_pattern="test_07_import_policy_update") + self.set_policy(peer3, "import", "test_07_import_policy_update_softreset") time.sleep(self.initial_wait_time) # soft reset @@ -647,8 +668,6 @@ class GoBGPTest(GoBGPTestBase): # 2001:0:10:2::/64, 2001:0:10:20::/64, 2001:0:10:200::/64 # coming from peer2(2001::192:168:0:2) to peer3(2001::192:168:0:3)'s # export-policy. - self.use_ipv6_gobgp = True - self.initialize(policy_pattern="test_08_export_policy_update") peer1 = "2001::192:168:0:1" peer2 = "2001::192:168:0:2" @@ -658,6 +677,10 @@ class GoBGPTest(GoBGPTestBase): r3 = "2001:0:10:200::/64" w = self.wait_per_retry + self.use_ipv6_gobgp = True + self.setup_config(peer3, "test_08_export_policy_update", "export") + self.initialize() + # add other network tn = qaccess.login(peer2) print "add network 2001:0:10:20::/64" @@ -721,7 +744,7 @@ class GoBGPTest(GoBGPTestBase): # update policy print "update_policy_config" - fab.update_policy_config(parser_option.go_path, policy_pattern="p8") + self.set_policy(peer3, "export", "test_08_export_policy_update_softreset") time.sleep(self.initial_wait_time) # soft reset @@ -764,22 +787,22 @@ class GoBGPTest(GoBGPTestBase): 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) - generate_exabgp_config(prefix1, aspath=as_path) + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path) + e.write() - #make_config_append(100, go_path, BRIDGE_0, peer_opts="--none-peer") + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + w = self.wait_per_retry self.quagga_num = 2 - self.use_exa_bgp = True + self.setup_config(peer2, "test_09_aspath_length_condition_import", "import", add_exabgp=True) + self.initialize() - self.initialize(policy_pattern="test_09_aspath_length_condition_import") 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" - w = self.wait_per_retry - path = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common) self.assertIsNotNone(path) @@ -816,20 +839,23 @@ class GoBGPTest(GoBGPTestBase): 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) - generate_exabgp_config(prefix1, aspath=as_path) - self.quagga_num = 2 - self.use_exa_bgp = True - self.use_ipv6_gobgp = False + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path) + e.write() - self.initialize(policy_pattern="test_10_aspath_from_condition_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" w = self.wait_per_retry + self.setup_config(peer2, "test_10_aspath_from_condition_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) @@ -865,20 +891,23 @@ class GoBGPTest(GoBGPTestBase): 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) - generate_exabgp_config(prefix1, aspath=as_path) - self.quagga_num = 2 - self.use_exa_bgp = True - self.use_ipv6_gobgp = False + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path) + e.write() - self.initialize(policy_pattern="test_11_aspath_any_condition_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" w = self.wait_per_retry + self.setup_config(peer2, "test_11_aspath_any_condition_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) @@ -913,20 +942,23 @@ class GoBGPTest(GoBGPTestBase): 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) - generate_exabgp_config(prefix1, aspath=as_path) - self.quagga_num = 2 - self.use_exa_bgp = True - self.use_ipv6_gobgp = False + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path) + e.write() - self.initialize(policy_pattern="test_12_aspath_origin_condition_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" w = self.wait_per_retry + self.setup_config(peer2, "test_12_aspath_origin_condition_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) @@ -961,20 +993,23 @@ class GoBGPTest(GoBGPTestBase): # generate exabgp configuration file prefix1 = "192.168.100.0/24" asn = '65100' - generate_exabgp_config(prefix1, aspath=asn) - self.quagga_num = 2 - self.use_exa_bgp = True - self.use_ipv6_gobgp = False + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=asn) + e.write() - self.initialize(policy_pattern="test_13_aspath_only_condition_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" w = self.wait_per_retry + self.setup_config(peer2, "test_13_aspath_only_condition_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) @@ -1010,18 +1045,22 @@ class GoBGPTest(GoBGPTestBase): 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) - generate_exabgp_config(prefix1, aspath=as_path) - self.quagga_num = 2 - self.use_exa_bgp = True - self.use_ipv6_gobgp = False + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path) + e.write() - self.initialize(policy_pattern="test_14_aspath_only_condition_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" + w = self.wait_per_retry + + self.setup_config(peer2, "test_14_aspath_only_condition_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) @@ -1058,20 +1097,23 @@ class GoBGPTest(GoBGPTestBase): asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] community = '65100:10' 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 + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community) + e.write() - self.initialize(policy_pattern="test_15_community_condition_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" w = self.wait_per_retry + self.setup_config(peer2, "test_15_community_condition_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) @@ -1108,20 +1150,23 @@ class GoBGPTest(GoBGPTestBase): asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] community = '65100:10' 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 + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community) + e.write() - self.initialize(policy_pattern="test_16_community_condition_regexp_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" w = self.wait_per_retry + self.setup_config(peer2, "test_16_community_condition_regexp_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) @@ -1158,18 +1203,22 @@ class GoBGPTest(GoBGPTestBase): asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] community = '65100:10' 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 + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community) + e.write() - self.initialize(policy_pattern="test_17_community_add_action_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" + w = self.wait_per_retry + + self.setup_config(peer2, "test_17_community_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) @@ -1210,18 +1259,22 @@ class GoBGPTest(GoBGPTestBase): asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] community = '65100:10' 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 + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community) + e.write() - self.initialize(policy_pattern="test_18_community_replace_action_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" + w = self.wait_per_retry + + self.setup_config(peer2, "test_18_community_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) @@ -1264,18 +1317,22 @@ class GoBGPTest(GoBGPTestBase): 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 + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community) + e.write() - self.initialize(policy_pattern="test_19_community_remove_action_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" + w = self.wait_per_retry + + self.setup_config(peer2, "test_19_community_remove_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) @@ -1320,18 +1377,22 @@ class GoBGPTest(GoBGPTestBase): 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 + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community) + e.write() - self.initialize(policy_pattern="test_20_community_null_action_import") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" + w = self.wait_per_retry + + self.setup_config(peer2, "test_20_community_null_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) @@ -1373,18 +1434,22 @@ class GoBGPTest(GoBGPTestBase): asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] community = '65100:10' 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 + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community) + e.write() - self.initialize(policy_pattern="test_21_community_add_action_export") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" + w = self.wait_per_retry + + self.setup_config(peer2, "test_21_community_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) @@ -1429,18 +1494,22 @@ class GoBGPTest(GoBGPTestBase): asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ] community = '65100:10' 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 + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community) + e.write() - self.initialize(policy_pattern="test_22_community_replace_action_export") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" + w = self.wait_per_retry + + self.setup_config(peer2, "test_22_community_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) @@ -1489,18 +1558,22 @@ class GoBGPTest(GoBGPTestBase): 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 + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community) + e.write() - self.initialize(policy_pattern="test_23_community_remove_action_export") - addresses = self.get_neighbor_address(self.gobgp_config) - self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" + w = self.wait_per_retry + + self.setup_config(peer2, "test_23_community_remove_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) @@ -1551,18 +1624,22 @@ class GoBGPTest(GoBGPTestBase): 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 + e = ExabgpConfig(EXABGP_COMMON_CONF) + e.add_route(prefix1, aspath=as_path, community=community) + e.write() - 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") + self.quagga_num = 2 peer1 = "10.0.0.1" peer2 = "10.0.0.2" + w = self.wait_per_retry + + self.setup_config(peer2, "test_24_community_null_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) @@ -1591,13 +1668,13 @@ 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 | | + r2(192.168.10.0/24) -> o | | | -> peer2-rib -> | -> r2 --> peer2 - | | --------------------- """ def test_25_distribute_reject(self): @@ -1608,151 +1685,211 @@ class GoBGPTest(GoBGPTestBase): # generate exabgp configuration file r1 = "192.168.100.0/24" - r2 = "192.168.2.0/24" + r2 = "192.168.10.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) + 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.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") + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + exabgp = "10.0.0.100" + w = self.wait_per_retry + + self.setup_config(exabgp, "test_25_distribute_reject", "distribute", add_exabgp=True) + self.initialize() + 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) + path = self.get_paths_in_localrib(peer1, r1, retry=self.retry_count_common, interval=w) + self.assertIsNone(path) + + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer1, r1, retry=self.retry_count_common, interval=w) + self.assertIsNone(qpath) + + path = self.get_paths_in_localrib(peer2, r1, retry=self.retry_count_common, interval=w) + self.assertIsNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2, r1, retry=self.retry_count_common, interval=w) + self.assertIsNone(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,prefix1, retry=self.retry_count_common) + qpath = self.get_route(peer1, r2, retry=self.retry_count_common, interval=w) self.assertIsNotNone(qpath) - # check adj-rib-out in peer2 - path = self.get_paths_in_localrib(peer2, prefix1, retry=0) + path = self.get_paths_in_localrib(peer2, r2, retry=self.retry_count_common, interval=w) 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) + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer2, r2, retry=self.retry_count_common, interval=w) 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 | - --------------------------------------- + --------------------- + exabgp ->r1(community=65100:10) -> x | -> peer1-rib -> | -> r2 --> peer1 + r2(192.168.10.0/24) -> o | | + | -> peer2-rib -> | -> r2 --> peer2 + --------------------- """ - def test_26_distribute_modify_community(self): + def test_26_distribute_accept(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" + 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 65100:20 65100:30 ' - as_path = reduce(lambda a,b: a + " " + b, asns) - generate_exabgp_config(prefix1, aspath=as_path, community=community) + 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_24_community_null_action_export") + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + exabgp = "10.0.0.100" + w = self.wait_per_retry + + self.setup_config(exabgp, "test_26_distribute_accept", "distribute", add_exabgp=True, defaultReject=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.assertIsNone(path) + + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer1, r1, retry=self.retry_count_common, interval=w) + self.assertIsNone(qpath) + + path = self.get_paths_in_localrib(peer2, r1, retry=self.retry_count_common, interval=w) + self.assertIsNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2, r1, retry=self.retry_count_common, interval=w) + self.assertIsNone(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) + + + + """ + distribute-policy test + --------------------- + exabgp ->r1(community=65100:10) -> o | -> peer1-rib -> | -> r1(community=65100:10, 65100:20), r2 --> peer1 + r2(192.168.10.0/24) -> o | | + | -> peer2-rib -> | -> r1(community=65100:10, 65100:20), r2 --> peer2 + --------------------- + """ + def test_27_distribute_set_community_action(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.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) + + 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 + peer1 = "10.0.0.1" peer2 = "10.0.0.2" + exabgp = "10.0.0.100" + w = self.wait_per_retry - path = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common) + self.setup_config(exabgp, "test_27_distribute_set_community_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,prefix1, retry=self.retry_count_common) + qpath = self.get_route(peer1, r1, retry=self.retry_count_common, interval=w) self.assertIsNotNone(qpath) - # check adj-rib-out in peer2 - path = self.get_paths_in_localrib(peer2, prefix1, retry=0) + path = self.get_paths_in_localrib(peer2, r1, retry=self.retry_count_common, interval=w) 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) + qpath = self.get_route(peer2, r1, retry=self.retry_count_common, interval=w) 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)) - + path = self.get_paths_in_localrib(peer1, r2, retry=self.retry_count_common, interval=w) + self.assertIsNotNone(path) -def generate_exabgp_config(pref, aspath='', community=''): - value = {'prefix': pref, - 'aspath': aspath, - 'community': community} + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer1, r2, retry=self.retry_count_common, interval=w) + self.assertIsNotNone(qpath) - pwd = local("pwd", capture=True) - conf_dir = pwd + "/exabgp_test_conf" - f = open(conf_dir+ "/" + EXABGP_COMMON_CONF, 'w') - f.write(EXABGP_COMMON_TEMPLATE % value) - f.close() + 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) -EXABGP_COMMON_TEMPLATE = ''' -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; + # check show ip bgp on peer2(quagga2) + self.assertTrue(self.check_community(peer1, r1.split('/')[0], '65100:10', retry=0)) + self.assertTrue(self.check_community(peer1, r1.split('/')[0], '65100:20', retry=0)) + self.assertTrue(self.check_community(peer2, r1.split('/')[0], '65100:10', retry=0)) + self.assertTrue(self.check_community(peer2, r1.split('/')[0], '65100:20', retry=0)) - family { - inet unicast; - } - static { - # static routes - route %(prefix)s next-hop 10.0.0.100 as-path [%(aspath)s] community [%(community)s]; - } -} -''' class ExabgpConfig(object): @@ -1781,17 +1918,17 @@ neighbor 10.0.255.1 { def __init__(self, config_name): self.o = StringIO.StringIO() self.config_name = config_name - print self.basic_conf_begin >> self.o + print >> self.o, self.basic_conf_begin 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 + print >> self.o, r def write(self): - print self.basic_conf_end >> self.o + print >> self.o, self.basic_conf_end pwd = local("pwd", capture=True) conf_dir = pwd + "/exabgp_test_conf" |