diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-05-25 11:33:21 +0900 |
---|---|---|
committer | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-05-27 21:04:43 +0900 |
commit | 497412e120d80844e55c79fbe47ce62fbec26edc (patch) | |
tree | e0cdfc6061454ae87aecee30d5d659a267cbdedb /test/scenario_test | |
parent | 637b5f9ba663b739de54069d91b1d87ddd3b4855 (diff) |
scenario_test: add policy test cases for new action and conditions
Diffstat (limited to 'test/scenario_test')
-rw-r--r-- | test/scenario_test/constant.py | 2 | ||||
-rw-r--r-- | test/scenario_test/docker_control.py | 41 | ||||
-rw-r--r-- | test/scenario_test/gobgp_test.py | 28 | ||||
-rw-r--r-- | test/scenario_test/quagga-rsconfig.go | 528 | ||||
-rw-r--r-- | test/scenario_test/quagga_access.py | 17 | ||||
-rw-r--r-- | test/scenario_test/route_server_policy_test.py | 992 |
6 files changed, 1502 insertions, 106 deletions
diff --git a/test/scenario_test/constant.py b/test/scenario_test/constant.py index a5132022..ebcf897c 100644 --- a/test/scenario_test/constant.py +++ b/test/scenario_test/constant.py @@ -33,6 +33,7 @@ EXABGP_CONTAINER_NAME = "exabgp" EXABGP_ADDRESS = "10.0.0.100/16" EXABGP_CONFDIR = SHARE_VOLUME + "/exabgp_test_conf" EXABGP_LOG_FILE = "exabgpd.log" +EXABGP_COMMON_CONF = "exabgp-gobgp-common.conf" STARTUP_FILE_NAME = "gobgp_startup.sh" STARTUP_FILE = SHARE_VOLUME + "/" + STARTUP_FILE_NAME INSTALL_FILE_NAME = "gobgp_install.sh" @@ -59,6 +60,7 @@ BASE_MASK = {IPv4: "/16", IPv6: "/64"} A_PART_OF_CURRENT_DIR = "/test/scenario_test" + ADJ_RIB_IN = "adj-in" ADJ_RIB_OUT = "adj-out" LOCAL_RIB = "local" diff --git a/test/scenario_test/docker_control.py b/test/scenario_test/docker_control.py index ec2d8397..13118ea8 100644 --- a/test/scenario_test/docker_control.py +++ b/test/scenario_test/docker_control.py @@ -278,7 +278,7 @@ def get_notification_from_exabgp_log(): return err_mgs -def make_config(quagga_num, go_path, bridge, peer_opts=""): +def make_config(quagga_num, go_path, bridge, peer_opts="", policy_pattern=""): if go_path != "": print "specified go path is [ " + go_path + " ]." if os.path.isdir(go_path): @@ -286,8 +286,13 @@ def make_config(quagga_num, go_path, bridge, peer_opts=""): else: print "specified go path do not use." pwd = local("pwd", capture=True) + + pp = '' + if policy_pattern: + pp = " -p " + policy_pattern + cmd = go_path + "go run " + pwd + "/quagga-rsconfig.go -n " + str(quagga_num) +\ - " -c /tmp/gobgp -v " + IP_VERSION + " -i " + bridge["BRIDGE_NAME"][-1] + " " + peer_opts + " -c /tmp/gobgp -v " + IP_VERSION + pp +" -i " + bridge["BRIDGE_NAME"][-1] + " " + peer_opts local(cmd, capture=True) @@ -319,7 +324,7 @@ def update_policy_config(go_path, policy_pattern=""): reload_config() -def make_config_append(quagga_num, go_path, bridge, peer_opts=""): +def make_config_append(quagga_num, go_path, bridge, peer_opts="", policy_pattern=""): if go_path != "": print "specified go path is [ " + go_path + " ]." if os.path.isdir(go_path): @@ -327,8 +332,13 @@ def make_config_append(quagga_num, go_path, bridge, peer_opts=""): else: print "specified go path do not use." pwd = local("pwd", capture=True) + + pp = '' + if policy_pattern: + pp = " -p " + policy_pattern + 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 + " -c /tmp/gobgp -v " + IP_VERSION + pp +" -i " + bridge["BRIDGE_NAME"][-1] + " " + peer_opts local(cmd, capture=True) @@ -390,7 +400,8 @@ def init_test_env_executor(quagga_num, use_local, go_path, log_debug=False, is_r print "complete initialization of test environment." -def init_policy_test_env_executor(quagga_num, use_local, go_path, log_debug=False, policy="", use_ipv6=False): +def init_policy_test_env_executor(quagga_num, use_local, go_path, log_debug=False, policy="", + use_ipv6=False, use_exabgp=False): print "start initialization of test environment." if docker_container_check() or bridge_setting_check(): @@ -404,13 +415,23 @@ def init_policy_test_env_executor(quagga_num, use_local, go_path, log_debug=Fals if use_ipv6: global IP_VERSION IP_VERSION = IPv6 + else: + global IP_VERSION + IP_VERSION = IPv4 bridge_setting_for_docker_connection(BRIDGES) - make_config_with_policy(quagga_num, go_path, BRIDGE_0, policy_pattern=policy) + make_config(quagga_num, go_path, BRIDGE_0, policy_pattern=policy) # run gobgp docker container docker_container_run_gobgp(BRIDGE_0) + if use_exabgp: + # run exabgp + make_config_append(100, go_path, BRIDGE_0, peer_opts="--none-peer", policy_pattern=policy) + docker_container_run_exabgp(BRIDGE_0) + cmd = "docker exec exabgp cp -rf " + SHARE_VOLUME + "/exabgp /root/" + local(cmd, capture=True) + # set log option opt = "-l debug" if log_debug else "" @@ -425,8 +446,8 @@ def init_policy_test_env_executor(quagga_num, use_local, go_path, log_debug=Fals local(cmd, capture=True) make_install_file(use_local=True) else: - print "scenario_test directory is not." - print "execute gobgp program of osrg/master in github." + print "local gobgp dosen't exist." + print "get the latest master gobgp from github." make_install_file() else: print "execute gobgp program of osrg/master in github." @@ -439,6 +460,10 @@ def init_policy_test_env_executor(quagga_num, use_local, go_path, log_debug=Fals for num in range(1, quagga_num + 1): docker_container_run_quagga(num, BRIDGE_0) + # start exabgp + if use_exabgp: + start_exabgp(EXABGP_COMMON_CONF) + print "complete initialization of test environment." diff --git a/test/scenario_test/gobgp_test.py b/test/scenario_test/gobgp_test.py index 4fc39ffc..030bf9c4 100644 --- a/test/scenario_test/gobgp_test.py +++ b/test/scenario_test/gobgp_test.py @@ -297,6 +297,34 @@ class GoBGPTestBase(unittest.TestCase): print "route : %s is none" % target_prefix return None + + # get route information on quagga + def check_community(self, neighbor_address, target_addr, community, 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_community(tn, target_addr, community, af) + qaccess.logout(tn) + + if result: + return True + else: + print "target path %s with community %s is none" % (target_addr, community) + + 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/quagga-rsconfig.go b/test/scenario_test/quagga-rsconfig.go index 577c1f83..0551959f 100644 --- a/test/scenario_test/quagga-rsconfig.go +++ b/test/scenario_test/quagga-rsconfig.go @@ -98,10 +98,7 @@ func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bo }, } - var binding *PolicyBinding - if policyPattern != "" { - binding = bindPolicy(policyPattern) - } + var policyConf *config.RoutingPolicy for i := 1; i < nr+1; i++ { c := config.Neighbor{ @@ -114,17 +111,7 @@ func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bo PeerType: config.PEER_TYPE_EXTERNAL, } - if binding != nil { - ip := net.ParseIP(binding.NeighborAddress) - if ip.String() == c.NeighborAddress.String() { - ap := config.ApplyPolicy{ - ImportPolicies: binding.ImportPolicyNames, - ExportPolicies: binding.ExportPolicyNames, - } - c.ApplyPolicy = ap - } - - } + policyConf = bindPolicy(&c, policyPattern) gobgpConf.NeighborList = append(gobgpConf.NeighborList, c) if !nonePeer { @@ -146,8 +133,8 @@ func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bo var buffer bytes.Buffer encoder := toml.NewEncoder(&buffer) encoder.Encode(gobgpConf) - if binding != nil { - encoder.Encode(binding.Policy) + if policyConf != nil { + encoder.Encode(policyConf) } err := ioutil.WriteFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), buffer.Bytes(), 0644) @@ -156,7 +143,7 @@ func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bo } } -func append_config_files(ar int, outputDir string, IPVersion string, nonePeer bool, normalBGP bool) { +func append_config_files(ar int, outputDir string, IPVersion string, noQuagga bool, normalBGP bool, policyPattern string) { gobgpConf := config.Bgp{ Global: config.Global{ @@ -173,7 +160,10 @@ func append_config_files(ar int, outputDir string, IPVersion string, nonePeer bo Timers: config.Timers{HoldTime: 30, KeepaliveInterval: 10, IdleHoldTimeAfterReset: 10}, PeerType: config.PEER_TYPE_EXTERNAL, } - if !nonePeer { + + bindPolicy(&c, policyPattern) + + if !noQuagga { q := NewQuaggaConfig(ar, &gobgpConf.Global, &c, net.ParseIP(serverAddress[IPVersion])) os.Mkdir(fmt.Sprintf("%s/q%d", outputDir, ar), 0755) var err error @@ -195,6 +185,17 @@ func append_config_files(ar int, outputDir string, IPVersion string, nonePeer bo var buffer bytes.Buffer encoder := toml.NewEncoder(&buffer) encoder.Encode(newConf) + + policyConf := &config.RoutingPolicy{} + _, p_err := toml.DecodeFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), policyConf) + if p_err != nil { + log.Fatal(p_err) + } + + if policyConf != nil && len(policyConf.PolicyDefinitionList) != 0 { + encoder.Encode(policyConf) + } + e_err := ioutil.WriteFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), buffer.Bytes(), 0644) if e_err != nil { log.Fatal(e_err) @@ -265,32 +266,79 @@ func createPolicyConfig() *config.RoutingPolicy { }}, } - ns0 := config.NeighborSet{ - NeighborSetName: "ns0", + nsPeer2 := config.NeighborSet{ + NeighborSetName: "nsPeer2", NeighborInfoList: []config.NeighborInfo{ config.NeighborInfo{ Address: net.ParseIP("10.0.0.2"), }}, } - ns1 := config.NeighborSet{ - NeighborSetName: "ns1", + nsPeer2V6 := config.NeighborSet{ + NeighborSetName: "nsPeer2V6", NeighborInfoList: []config.NeighborInfo{ config.NeighborInfo{ Address: net.ParseIP("2001::0:192:168:0:2"), }}, } + nsExabgp := config.NeighborSet{ + NeighborSetName: "nsExabgp", + NeighborInfoList: []config.NeighborInfo{ + config.NeighborInfo{ + Address: net.ParseIP("10.0.0.100"), + }}, + } + + psExabgp := config.PrefixSet{ + PrefixSetName: "psExabgp", + PrefixList: []config.Prefix{ + config.Prefix{ + Address: net.ParseIP("192.168.100.0"), + Masklength: 24, + MasklengthRange: "16..24", + }}, + } + + aspathFrom := config.AsPathSet{ + AsPathSetName: "aspathFrom", + AsPathSetMembers: []string{"^65100"}, + } + + aspathAny := config.AsPathSet{ + AsPathSetName: "aspAny", + AsPathSetMembers: []string{"65098"}, + } + + aspathOrigin := config.AsPathSet{ + AsPathSetName: "aspOrigin", + AsPathSetMembers: []string{"65091$"}, + } + + aspathOnly := config.AsPathSet{ + AsPathSetName: "aspOnly", + AsPathSetMembers: []string{"^65100$"}, + } + + comStr := config.CommunitySet{ + CommunitySetName: "comStr", + CommunityMembers: []string{"65100:10"}, + } + + comRegExp := config.CommunitySet{ + CommunitySetName: "comRegExp", + CommunityMembers: []string{"6[0-9]+:[0-9]+"}, + } + st0 := config.Statement{ Name: "st0", Conditions: config.Conditions{ MatchPrefixSet: "ps0", - MatchNeighborSet: "ns0", + MatchNeighborSet: "nsPeer2", MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, }, Actions: config.Actions{ AcceptRoute: false, - RejectRoute: true, }, } @@ -298,12 +346,11 @@ func createPolicyConfig() *config.RoutingPolicy { Name: "st1", Conditions: config.Conditions{ MatchPrefixSet: "ps1", - MatchNeighborSet: "ns0", + MatchNeighborSet: "nsPeer2", MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, }, Actions: config.Actions{ AcceptRoute: false, - RejectRoute: true, }, } @@ -311,12 +358,11 @@ func createPolicyConfig() *config.RoutingPolicy { Name: "st3", Conditions: config.Conditions{ MatchPrefixSet: "ps3", - MatchNeighborSet: "ns1", + MatchNeighborSet: "nsPeer2V6", MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, }, Actions: config.Actions{ AcceptRoute: false, - RejectRoute: true, }, } @@ -324,44 +370,297 @@ func createPolicyConfig() *config.RoutingPolicy { Name: "st4", Conditions: config.Conditions{ MatchPrefixSet: "ps4", - MatchNeighborSet: "ns1", + MatchNeighborSet: "nsPeer2V6", MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, }, Actions: config.Actions{ AcceptRoute: false, - RejectRoute: true, }, } - pd0 := config.PolicyDefinition{ - Name: "policy0", + st_aspathlen := config.Statement{ + Name: "st_aspathlen", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + BgpConditions: config.BgpConditions{ + AsPathLength: config.AsPathLength{ + Operator: "ge", + Value: 10, + }, + }, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + }, + } + + st_aspathFrom := config.Statement{ + Name: "st_aspathlen", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + BgpConditions: config.BgpConditions{ + MatchAsPathSet: "aspathFrom", + }, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + }, + } + + st_aspathAny := config.Statement{ + Name: "st_aspathlen", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + BgpConditions: config.BgpConditions{ + MatchAsPathSet: "aspAny", + }, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + }, + } + + st_aspathOrigin := config.Statement{ + Name: "st_aspathlen", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + BgpConditions: config.BgpConditions{ + MatchAsPathSet: "aspOrigin", + }, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + }, + } + + st_aspathOnly := config.Statement{ + Name: "st_aspathlen", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + BgpConditions: config.BgpConditions{ + MatchAsPathSet: "aspOnly", + }, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + }, + } + + st_comStr := config.Statement{ + Name: "st_community", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + BgpConditions: config.BgpConditions{ + MatchCommunitySet: "comStr", + }, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + }, + } + + st_comRegExp := config.Statement{ + Name: "st_community_regexp", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + BgpConditions: config.BgpConditions{ + MatchCommunitySet: "comRegExp", + }, + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + }, + } + + st_comAdd := config.Statement{ + Name: "st_community_regexp", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + 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", + }, + }, + }, + } + + st_comReplace := config.Statement{ + Name: "st_community_regexp", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + 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", "65100:30"}, + Options: "REPLACE", + }, + }, + }, + } + + st_comRemove := config.Statement{ + Name: "st_community_regexp", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + 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", "65100:30"}, + Options: "REMOVE", + }, + }, + }, + } + + st_comNull := config.Statement{ + Name: "st_community_regexp", + Conditions: config.Conditions{ + MatchPrefixSet: "psExabgp", + MatchNeighborSet: "nsExabgp", + 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{}, + Options: "NULL", + }, + }, + }, + } + + pdImportV4 := config.PolicyDefinition{ + Name: "policy_use_ps0", StatementList: []config.Statement{st0}, } - pd1 := config.PolicyDefinition{ - Name: "policy1", + pdExportV4 := config.PolicyDefinition{ + Name: "policy_use_ps1", StatementList: []config.Statement{st1}, } - pd2 := config.PolicyDefinition{ - Name: "policy2", + pdImportV6 := config.PolicyDefinition{ + Name: "policy_use_ps3", StatementList: []config.Statement{st3}, } - pd3 := config.PolicyDefinition{ - Name: "policy3", + pdExportV6 := config.PolicyDefinition{ + Name: "policy_use_ps4", StatementList: []config.Statement{st4}, } + pdAspathlen := config.PolicyDefinition{ + Name: "policy_aspathlen", + StatementList: []config.Statement{st_aspathlen}, + } + + pdaspathFrom := config.PolicyDefinition{ + Name: "policy_aspathFrom", + StatementList: []config.Statement{st_aspathFrom}, + } + + pdaspathAny := config.PolicyDefinition{ + Name: "policy_aspathAny", + StatementList: []config.Statement{st_aspathAny}, + } + + pdaspathOrigin := config.PolicyDefinition{ + Name: "policy_aspathOrigin", + StatementList: []config.Statement{st_aspathOrigin}, + } + + pdaspathOnly := config.PolicyDefinition{ + Name: "policy_aspathOnly", + StatementList: []config.Statement{st_aspathOnly}, + } + + pdCommunity := config.PolicyDefinition{ + Name: "policy_community", + StatementList: []config.Statement{st_comStr}, + } + + pdCommunityRegExp := config.PolicyDefinition{ + Name: "policy_community_regexp", + StatementList: []config.Statement{st_comRegExp}, + } + + pdCommunityAdd := config.PolicyDefinition{ + Name: "policy_community_add", + StatementList: []config.Statement{st_comAdd}, + } + + pdCommunityReplace := config.PolicyDefinition{ + Name: "policy_community_replace", + StatementList: []config.Statement{st_comReplace}, + } + + pdCommunityRemove := config.PolicyDefinition{ + Name: "policy_community_remove", + StatementList: []config.Statement{st_comRemove}, + } + + pdCommunityNull := config.PolicyDefinition{ + Name: "policy_community_null", + StatementList: []config.Statement{st_comNull}, + } + ds := config.DefinedSets{ - PrefixSetList: []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5}, - NeighborSetList: []config.NeighborSet{ns0, ns1}, + PrefixSetList: []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5, psExabgp}, + NeighborSetList: []config.NeighborSet{nsPeer2, nsPeer2V6, nsExabgp}, + BgpDefinedSets: config.BgpDefinedSets{ + AsPathSetList: []config.AsPathSet{aspathFrom, aspathAny, aspathOrigin, aspathOnly}, + CommunitySetList: []config.CommunitySet{comStr, comRegExp}, + }, } p := &config.RoutingPolicy{ - DefinedSets: ds, - PolicyDefinitionList: []config.PolicyDefinition{pd0, pd1, pd2, pd3}, + DefinedSets: ds, + PolicyDefinitionList: []config.PolicyDefinition{pdImportV4, pdExportV4, pdImportV6, pdExportV6, + pdAspathlen, pdaspathFrom, pdaspathAny, pdaspathOrigin, pdaspathOnly, + pdCommunity, pdCommunityRegExp, pdCommunityAdd, pdCommunityReplace, pdCommunityRemove, pdCommunityNull}, } + return p } @@ -385,7 +684,7 @@ func updatePolicyConfig(outputDir string, pattern string) { Name: "st2", Conditions: config.Conditions{ MatchPrefixSet: "ps2", - MatchNeighborSet: "ns0", + MatchNeighborSet: "nsPeer2", MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, }, Actions: config.Actions{ @@ -398,7 +697,7 @@ func updatePolicyConfig(outputDir string, pattern string) { Name: "st5", Conditions: config.Conditions{ MatchPrefixSet: "ps5", - MatchNeighborSet: "ns1", + MatchNeighborSet: "nsPeer2V6", MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, }, Actions: config.Actions{ @@ -407,11 +706,11 @@ func updatePolicyConfig(outputDir string, pattern string) { }, } - if pattern == "p3" || pattern == "p4" { + if pattern == "test_03_import_policy_update" || pattern == "test_04_export_policy_update" { policyConf.PolicyDefinitionList[1].StatementList = []config.Statement{st2} } - if pattern == "p7" || pattern == "p8" { + if pattern == "test_07_import_policy_update" || pattern == "test_08_export_policy_update" { policyConf.PolicyDefinitionList[3].StatementList = []config.Statement{st5} } @@ -434,51 +733,130 @@ type PolicyBinding struct { ExportPolicyNames []string } -func bindPolicy(pattern string) *PolicyBinding { +func getPolicyBinding(pattern string) *PolicyBinding { var pb *PolicyBinding = &PolicyBinding{Policy: createPolicyConfig()} switch pattern { - case "p1": + case "test_01_import_policy_initial": pb.NeighborAddress = "10.0.0.3" - pb.ImportPolicyNames = []string{"policy0"} + pb.ImportPolicyNames = []string{"policy_use_ps0"} pb.ExportPolicyNames = nil - case "p2": + case "test_02_export_policy_initial": pb.NeighborAddress = "10.0.0.3" pb.ImportPolicyNames = nil - pb.ExportPolicyNames = []string{"policy0"} + pb.ExportPolicyNames = []string{"policy_use_ps0"} - case "p3": + case "test_03_import_policy_update": pb.NeighborAddress = "10.0.0.3" - pb.ImportPolicyNames = []string{"policy1"} + pb.ImportPolicyNames = []string{"policy_use_ps1"} pb.ExportPolicyNames = nil - case "p4": + case "test_04_export_policy_update": pb.NeighborAddress = "10.0.0.3" pb.ImportPolicyNames = nil - pb.ExportPolicyNames = []string{"policy1"} + pb.ExportPolicyNames = []string{"policy_use_ps1"} - case "p5": + case "test_05_import_policy_initial_ipv6": pb.NeighborAddress = "2001::0:192:168:0:3" - pb.ImportPolicyNames = []string{"policy2"} + pb.ImportPolicyNames = []string{"policy_use_ps3"} pb.ExportPolicyNames = nil - case "p6": + case "test_06_export_policy_initial_ipv6": pb.NeighborAddress = "2001::0:192:168:0:3" pb.ImportPolicyNames = nil - pb.ExportPolicyNames = []string{"policy2"} + pb.ExportPolicyNames = []string{"policy_use_ps3"} - case "p7": + case "test_07_import_policy_update": pb.NeighborAddress = "2001::0:192:168:0:3" - pb.ImportPolicyNames = []string{"policy3"} + pb.ImportPolicyNames = []string{"policy_use_ps4"} pb.ExportPolicyNames = nil - case "p8": + case "test_08_export_policy_update": pb.NeighborAddress = "2001::0:192:168:0:3" pb.ImportPolicyNames = nil - pb.ExportPolicyNames = []string{"policy3"} + pb.ExportPolicyNames = []string{"policy_use_ps4"} + + case "test_09_aspath_length_condition_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_aspathlen"} + pb.ExportPolicyNames = nil + + case "test_10_aspath_from_condition_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_aspathFrom"} + pb.ExportPolicyNames = nil + + case "test_11_aspath_any_condition_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_aspathAny"} + pb.ExportPolicyNames = nil + + case "test_12_aspath_origin_condition_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_aspathOrigin"} + pb.ExportPolicyNames = nil + + case "test_13_aspath_only_condition_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_aspathOnly"} + pb.ExportPolicyNames = nil + + case "test_14_aspath_only_condition_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_aspathOnly"} + pb.ExportPolicyNames = nil + + case "test_15_community_condition_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_community"} + pb.ExportPolicyNames = nil + + case "test_16_community_condition_regexp_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_community_regexp"} + pb.ExportPolicyNames = nil + + case "test_17_community_add_action_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_community_add"} + pb.ExportPolicyNames = nil + + case "test_18_community_replace_action_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_community_replace"} + pb.ExportPolicyNames = nil + + case "test_19_community_remove_action_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_community_remove"} + pb.ExportPolicyNames = nil + + case "test_20_community_null_action_import": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = []string{"policy_community_null"} + pb.ExportPolicyNames = nil + + case "test_21_community_add_action_export": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = nil + pb.ExportPolicyNames = []string{"policy_community_add"} + + case "test_22_community_replace_action_export": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = nil + pb.ExportPolicyNames = []string{"policy_community_replace"} + + case "test_23_community_remove_action_export": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = nil + pb.ExportPolicyNames = []string{"policy_community_remove"} + case "test_24_community_null_action_export": + pb.NeighborAddress = "10.0.0.2" + pb.ImportPolicyNames = nil + pb.ExportPolicyNames = []string{"policy_community_null"} default: pb = nil } @@ -487,6 +865,26 @@ func bindPolicy(pattern string) *PolicyBinding { } +func bindPolicy(c *config.Neighbor, policyPattern string) *config.RoutingPolicy { + var binding *PolicyBinding + if policyPattern != "" { + binding = getPolicyBinding(policyPattern) + } + + if binding != nil { + ip := net.ParseIP(binding.NeighborAddress) + if ip.String() == c.NeighborAddress.String() { + ap := config.ApplyPolicy{ + ImportPolicies: binding.ImportPolicyNames, + ExportPolicies: binding.ExportPolicyNames, + } + c.ApplyPolicy = ap + return binding.Policy + } + } + return nil +} + func main() { var opts struct { ClientNumber int `short:"n" long:"client-number" description:"specfying the number of clients" default:"8"` @@ -537,7 +935,7 @@ func main() { if opts.UpdatePolicy { updatePolicyConfig(opts.OutputDir, opts.PolicyPattern) } else { - append_config_files(opts.AppendClient, opts.OutputDir, opts.IPVersion, opts.NonePeer, opts.NormalBGP) + append_config_files(opts.AppendClient, opts.OutputDir, opts.IPVersion, opts.NonePeer, opts.NormalBGP, opts.PolicyPattern) } } } diff --git a/test/scenario_test/quagga_access.py b/test/scenario_test/quagga_access.py index f29cb301..634dc439 100644 --- a/test/scenario_test/quagga_access.py +++ b/test/scenario_test/quagga_access.py @@ -142,4 +142,19 @@ def lookup_prefix(tn, prefix, af): path['Next Hop'] = nexthop paths.append(path) - return paths
\ No newline at end of file + return paths + +def check_community(tn, addr, community, af=IPv4): + if af == IPv4: + tn.write("show ip bgp community " + community + "\n") + elif af == IPv6: + tn.write("show bgp ipv6 community " + community + "\n") + else: + print "invalid af: ", af + return + result = tn.read_until("bgpd#") + for line in result.split("\n"): + if addr in line: + return True + + return False
\ No newline at end of file diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py index 47b2abc6..f673747d 100644 --- a/test/scenario_test/route_server_policy_test.py +++ b/test/scenario_test/route_server_policy_test.py @@ -22,27 +22,41 @@ from noseplugin import OptionParser from noseplugin import parser_option from gobgp_test import GoBGPTestBase from constant import * +from fabric.api import local class GoBGPTest(GoBGPTestBase): quagga_num = 3 + retry_count_common = 2 + initial_wait_time = 5 def __init__(self, *args, **kwargs): super(GoBGPTest, self).__init__(*args, **kwargs) + + def setUp(self): + self.quagga_configs = [] + self.use_ipv6_gobgp = False + self.use_exa_bgp = False + self.retry_count_common = 2 + self.initial_wait_time = 5 + + def initialize(self, policy_pattern=None): use_local = parser_option.use_local go_path = parser_option.go_path log_debug = parser_option.gobgp_log_debug + fab.init_policy_test_env_executor(self.quagga_num, use_local, go_path, log_debug, policy=policy_pattern, - use_ipv6=self.use_ipv6_gobgp) + use_ipv6=self.use_ipv6_gobgp, + use_exabgp=self.use_exa_bgp) print "please wait " + str(self.initial_wait_time) + " second" time.sleep(self.initial_wait_time) - self.assertTrue(self.check_load_config()) + """ import-policy test --------------------------------------- @@ -56,7 +70,7 @@ class GoBGPTest(GoBGPTestBase): # initialize test environment # policy_pattern:p1 attaches a policy to reject route 192.168.0.0/16 (16...24) # coming from peer2(10.0.0.2) to peer3(10.0.0.3)'s import-policy. - self.initialize(policy_pattern="p1") + self.initialize(policy_pattern="test_01_import_policy_initial") addresses = self.get_neighbor_address(self.gobgp_config) self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") @@ -64,16 +78,16 @@ class GoBGPTest(GoBGPTestBase): peer2 = "10.0.0.2" peer3 = "10.0.0.3" prefix1 = "192.168.2.0/24" - path = self.get_paths_in_localrib(peer1, prefix1, retry=3) + 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=3) + qpath = self.get_route(peer1,prefix1, retry=self.retry_count_common) print qpath self.assertIsNotNone(qpath) # check adj-rib-out in peer2 - path = self.get_adj_rib_in(peer2, prefix1, retry=3) + path = self.get_adj_rib_in(peer2, prefix1, retry=self.retry_count_common) # print path self.assertIsNotNone(path) @@ -82,7 +96,7 @@ class GoBGPTest(GoBGPTestBase): self.assertIsNone(path) # check show ip bgp on peer1(quagga3) - qpath = self.get_route(peer3,prefix1, retry=3) + qpath = self.get_route(peer3,prefix1, retry=self.retry_count_common) # print qpath self.assertIsNone(qpath) @@ -100,7 +114,7 @@ class GoBGPTest(GoBGPTestBase): # initialize test environment # policy_pattern:p1 attaches a policy to reject route 192.168.0.0/16 (16...24) # coming from peer2(10.0.0.2) to peer3(10.0.0.3)'s export-policy. - self.initialize(policy_pattern="p2") + self.initialize(policy_pattern="test_02_export_policy_initial") addresses = self.get_neighbor_address(self.gobgp_config) self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") @@ -109,12 +123,12 @@ class GoBGPTest(GoBGPTestBase): peer3 = "10.0.0.3" prefix1 = "192.168.2.0/24" - paths = self.get_paths_in_localrib(peer1, prefix1, retry=3) + paths = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common) # print paths self.assertIsNotNone(paths) # check show ip bgp on peer1(quagga1) - qpath = self.get_route(peer1, prefix1, retry=3) + qpath = self.get_route(peer1, prefix1, retry=self.retry_count_common) # print qpath self.assertIsNotNone(qpath) @@ -132,7 +146,7 @@ class GoBGPTest(GoBGPTestBase): self.assertIsNone(path) # check show ip bgp on peer1(quagga3) - qpath = self.get_route(peer3,prefix1, retry=3) + qpath = self.get_route(peer3,prefix1, retry=self.retry_count_common) # print qpath self.assertIsNone(qpath) @@ -166,7 +180,7 @@ class GoBGPTest(GoBGPTestBase): # policy_pattern:p3 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 import-policy. - self.initialize(policy_pattern="p3") + self.initialize(policy_pattern="test_03_import_policy_update") peer1 = "10.0.0.1" peer2 = "10.0.0.2" @@ -226,7 +240,7 @@ class GoBGPTest(GoBGPTestBase): # update policy print "update_policy_config" - fab.update_policy_config(parser_option.go_path, policy_pattern="p3") + fab.update_policy_config(parser_option.go_path, policy_pattern="test_03_import_policy_update") time.sleep(self.initial_wait_time) # soft reset @@ -274,7 +288,7 @@ 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="p4") + self.initialize(policy_pattern="test_04_export_policy_update") peer1 = "10.0.0.1" peer2 = "10.0.0.2" @@ -345,7 +359,7 @@ class GoBGPTest(GoBGPTestBase): # update policy print "update_policy_config" - fab.update_policy_config(parser_option.go_path, policy_pattern="p4") + fab.update_policy_config(parser_option.go_path, policy_pattern="test_04_export_policy_update") time.sleep(self.initial_wait_time) # soft reset @@ -375,7 +389,7 @@ class GoBGPTest(GoBGPTestBase): | | | ->x peer3-rib | -------------------------------------------------- - """ + """ def test_05_import_policy_initial_ipv6(self): # initialize test environment @@ -383,7 +397,7 @@ class GoBGPTest(GoBGPTestBase): # 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="p5") + 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") @@ -394,18 +408,15 @@ class GoBGPTest(GoBGPTestBase): r1 = "2001:0:10:2::/64" w = self.wait_per_retry - # path = util.get_paths_in_localrib(peer1, r1, retry=3, interval=w, rf=IPv6) - path = self.get_paths_in_localrib(peer1, r1, retry=3, af=IPv6, interval=w) + path = self.get_paths_in_localrib(peer1, r1, retry=self.retry_count_common, af=IPv6, interval=w) self.assertIsNotNone(path) # check show ip bgp on peer1(quagga1) - # qpath = util.get_route(peer1, r1_pref, retry=3, interval=w, rf=IPv6) - qpath = self.get_route(peer1, r1, retry=3, af=IPv6) + qpath = self.get_route(peer1, r1, retry=self.retry_count_common, af=IPv6) self.assertIsNotNone(qpath) # check adj-rib-out in peer2 - # path = util.get_adj_rib_in(base_url, peer2, r1_pref, retry=3, interval=w, rf=IPv6) - path = self.get_adj_rib_in(peer2, r1, retry=3, af=IPv6) + path = self.get_adj_rib_in(peer2, r1, retry=self.retry_count_common, af=IPv6) # print path self.assertIsNotNone(path) @@ -415,8 +426,7 @@ class GoBGPTest(GoBGPTestBase): self.assertIsNone(path) # check show ip bgp on peer1(quagga3) - # qpath = util.get_route(peer3, r1_pref, retry=3, interval=w, rf=IPv6) - qpath = self.get_route(peer3, r1, retry=3, interval=w, af=IPv6) + qpath = self.get_route(peer3, r1, retry=self.retry_count_common, interval=w, af=IPv6) print qpath self.assertIsNone(qpath) @@ -436,7 +446,7 @@ class GoBGPTest(GoBGPTestBase): # 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="p6") + 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") @@ -446,13 +456,13 @@ class GoBGPTest(GoBGPTestBase): r1 = "2001:0:10:2::/64" w = self.wait_per_retry - paths = self.get_paths_in_localrib(peer1, r1, retry=3, interval=w, af=IPv6) + paths = self.get_paths_in_localrib(peer1, r1, retry=self.retry_count_common, interval=w, af=IPv6) # print paths self.assertIsNotNone(paths) # check show ip bgp on peer1(quagga1) - qpath = self.get_route(peer1, r1, retry=3, interval=w, af=IPv6) + qpath = self.get_route(peer1, r1, retry=self.retry_count_common, interval=w, af=IPv6) # print qpath self.assertIsNotNone(qpath) @@ -470,7 +480,7 @@ class GoBGPTest(GoBGPTestBase): self.assertIsNone(path) # check show ip bgp on peer1(quagga3) - qpath = self.get_route(peer3, r1, retry=3, interval=w, af=IPv6) + qpath = self.get_route(peer3, r1, retry=self.retry_count_common, interval=w, af=IPv6) # print qpath self.assertIsNone(qpath) @@ -506,7 +516,7 @@ class GoBGPTest(GoBGPTestBase): # 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="p7") + self.initialize(policy_pattern="test_07_import_policy_update") peer1 = "2001::192:168:0:1" peer2 = "2001::192:168:0:2" @@ -569,7 +579,7 @@ class GoBGPTest(GoBGPTestBase): # update policy print "update_policy_config" - fab.update_policy_config(parser_option.go_path, policy_pattern="p7") + fab.update_policy_config(parser_option.go_path, policy_pattern="test_07_import_policy_update") time.sleep(self.initial_wait_time) # soft reset @@ -618,7 +628,7 @@ class GoBGPTest(GoBGPTestBase): # 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="p8") + self.initialize(policy_pattern="test_08_export_policy_update") peer1 = "2001::192:168:0:1" peer2 = "2001::192:168:0:2" @@ -715,6 +725,924 @@ class GoBGPTest(GoBGPTestBase): self.assertTrue(path_exists_in_routing_table(peer3, r3)) + """ + import-policy test + --------------------------------------- + exabgp ->(aspath_length=10)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | ->x peer2-rib | + --------------------------------------- + + """ + def test_09_aspath_length_condition_import(self): + + # initialize test environment + # policy_pattern:p9 attaches a policy to reject a path whose aspath length is greater than or equal 10 + # to peer2(10.0.0.2)'s import-policy. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path) + + self.quagga_num = 2 + self.use_exa_bgp = True + + 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" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + # print path + self.assertIsNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + # print qpath + self.assertIsNone(qpath) + + + """ + import-policy test + --------------------------------------- + exabgp ->(aspath=[65100,...])->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | ->x peer2-rib | + --------------------------------------- + + """ + def test_10_aspath_from_condition_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy to reject a path that is from 65100 + # to peer2(10.0.0.2)'s import-policy. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + # print path + self.assertIsNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + # print qpath + self.assertIsNone(qpath) + + + """ + import-policy test + --------------------------------------- + exabgp ->(aspath=[...65098,...])->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | ->x peer2-rib | + --------------------------------------- + + """ + def test_11_aspath_any_condition_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy to reject a path that contains 65098 in its aspath attr + # to peer2(10.0.0.2)'s import-policy. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + # print path + self.assertIsNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + # print qpath + self.assertIsNone(qpath) + + """ + import-policy test + --------------------------------------- + exabgp ->(aspath=[...,65090])->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | ->x peer2-rib | + --------------------------------------- + + """ + def test_12_aspath_origin_condition_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy for rejecting a path that has 65090 at last in its aspath attr + # to peer2(10.0.0.2)'s import-policy. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + # print path + self.assertIsNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + # print qpath + self.assertIsNone(qpath) + + + """ + import-policy test + --------------------------------------- + exabgp -> (aspath=[65100]) -> | -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | ->x peer2-rib | + --------------------------------------- + + """ + def test_13_aspath_only_condition_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy for rejecting a path that has only 65100 in its aspath attr + # to peer2(10.0.0.2)'s import-policy. + + # 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 + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + # print path + self.assertIsNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + # print qpath + self.assertIsNone(qpath) + + + """ + import-policy test + --------------------------------------- + exabgp ->(aspath=[...,65090])->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + --------------------------------------- + This case check if policy passes the path to peer2 because of condition mismatch. + """ + def test_14_aspath_only_condition_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy for rejecting a path that has 65090 at last in its aspath attr + # to peer2(10.0.0.2)'s import-policy. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + print path + self.assertIsNotNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + print qpath + self.assertIsNotNone(qpath) + + + """ + import-policy test + --------------------------------------- + exabgp ->(community=65100:10)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | ->x peer2-rib | + --------------------------------------- + """ + def test_15_community_condition_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy for rejecting a path that has 65100:10 in its community attr + # to peer2(10.0.0.2)'s import-policy. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path, community=community) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + # print path + self.assertIsNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + # print qpath + self.assertIsNone(qpath) + + + """ + import-policy test + --------------------------------------- + exabgp ->(community=65100:10)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | ->x peer2-rib | + --------------------------------------- + """ + def test_16_community_condition_regexp_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy for rejecting a path that has 65100:10 in its community attr + # to peer2(10.0.0.2)'s import-policy. + # this policy uses a regexp as the community condition. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path, community=community) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=0) + # print path + self.assertIsNone(path) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + # print qpath + self.assertIsNone(qpath) + + """ + import-policy test + --------------------------------------- + exabgp ->(community=65100:10)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_17_community_add_action_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy for addition community 65100:10 to its community attr + # to peer2(10.0.0.2)'s import-policy. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path, community=community) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # 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 'communites' in x ] + self.assertTrue((65100 << 16 | 20) in attrs[0]['communites']) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + print qpath + self.assertIsNotNone(qpath) + self.assertTrue(self.check_community(peer2, prefix1.split('/')[0], '65100:20')) + + + """ + import-policy test + --------------------------------------- + exabgp ->(community=65100:10)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_18_community_replace_action_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy to replace community 65100:10 in its community attr + # to peer2(10.0.0.2)'s import-policy. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path, community=community) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # 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 'communites' in x ] + self.assertTrue((65100 << 16 | 20) in attrs[0]['communites']) + self.assertTrue((65100 << 16 | 30) in attrs[0]['communites']) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + print qpath + self.assertIsNotNone(qpath) + self.assertTrue(self.check_community(peer2, prefix1.split('/')[0], '65100:20')) + self.assertTrue(self.check_community(peer2, prefix1.split('/')[0], '65100:30')) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:10', retry=1)) + + """ + import-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 | + --------------------------------------- + """ + def test_19_community_remove_action_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy to remove community 65100:20 65100:30 in its community attr + # to peer2(10.0.0.2)'s import-policy. + + # generate exabgp configuration file + prefix1 = "192.168.100.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) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # 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 'communites' in x ] + self.assertTrue((65100 << 16 | 20) not in attrs[0]['communites']) + self.assertTrue((65100 << 16 | 30) not in attrs[0]['communites']) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + print qpath + self.assertIsNotNone(qpath) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:20', retry=1)) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:30', retry=1)) + self.assertTrue(self.check_community(peer2, prefix1.split('/')[0], '65100:10', retry=1)) + + + """ + import-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 | + --------------------------------------- + """ + def test_20_community_null_action_import(self): + + # initialize test environment + # policy_pattern:AspFrom attaches a policy to remove its community attr + # to peer2(10.0.0.2)'s import-policy. + + # generate exabgp configuration file + prefix1 = "192.168.100.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) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # 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 'communites' in x ] + self.assertFalse('communites' in attrs) + # self.assertTrue((65100 << 16 | 20) not in attrs[0]['communites']) + # self.assertTrue((65100 << 16 | 30) not in attrs[0]['communites']) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + print qpath + self.assertIsNotNone(qpath) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:20', retry=1)) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:30', retry=1)) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:10', retry=1)) + + """ + import-policy test + --------------------------------------- + exabgp ->(community=65100:10)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_21_community_add_action_export(self): + + # initialize test environment + # policy_pattern:CommunityAddEXP attaches a policy to add community 65100:20 into its community attr + # to peer2(10.0.0.2)'s export-policy. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path, community=community) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # 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 'communites' in x ] + self.assertFalse((65100 << 16 | 20) in attrs[0]['communites']) + # check out-rib + path = self.get_adj_rib_out(peer2, prefix1, retry=0) + print path + attrs = [x for x in path['attrs'] if 'communites' in x ] + self.assertTrue((65100 << 16 | 20) in attrs[0]['communites']) + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + print qpath + self.assertIsNotNone(qpath) + self.assertTrue(self.check_community(peer2, prefix1.split('/')[0], '65100:20')) + + + """ + import-policy test + --------------------------------------- + exabgp ->(community=65100:10)->| -> peer1-rib -> peer1-adj-rib-out | --> peer1 + | | + | -> peer2-rib -> peer2-adj-rib-out | --> peer2 + | apply action | + --------------------------------------- + """ + def test_22_community_replace_action_export(self): + + # initialize test environment + # policy_pattern:CommunityReplaceEXP attaches a policy to replace its community + # with 65100:20 and 65100:30 in its community attr to peer2(10.0.0.2)'s export-policy. + + # 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) + generate_exabgp_config(prefix1, aspath=as_path, community=community) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # 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 'communites' in x ] + self.assertFalse((65100 << 16 | 20) in attrs[0]['communites']) + self.assertFalse((65100 << 16 | 30) in attrs[0]['communites']) + # check out-rib + path = self.get_adj_rib_out(peer2, prefix1, retry=1) + print path + attrs = [x for x in path['attrs'] if 'communites' in x ] + self.assertTrue((65100 << 16 | 20) in attrs[0]['communites']) + self.assertTrue((65100 << 16 | 30) in attrs[0]['communites']) + + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + print qpath + self.assertIsNotNone(qpath) + self.assertTrue(self.check_community(peer2, prefix1.split('/')[0], '65100:20')) + self.assertTrue(self.check_community(peer2, prefix1.split('/')[0], '65100:30')) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:10', retry=1)) + + """ + import-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 | + --------------------------------------- + """ + def test_23_community_remove_action_export(self): + + # initialize test environment + # policy_pattern:CommunityRemoveEXP attaches a policy to remove 65100:20 and 65100:30 + # in its community attr to peer2(10.0.0.2)'s import-policy. + + # generate exabgp configuration file + prefix1 = "192.168.100.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) + + self.quagga_num = 2 + self.use_exa_bgp = True + self.use_ipv6_gobgp = False + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # check adj-rib-out in peer2 + path = self.get_paths_in_localrib(peer2, prefix1,retry=1) + print path + self.assertIsNotNone(path) + attrs = [x for x in path[0]['attrs'] if 'communites' in x ] + 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) + print path + attrs = [x for x in path['attrs'] if 'communites' in x ] + self.assertFalse((65100 << 16 | 20) in attrs[0]['communites']) + self.assertFalse((65100 << 16 | 30) in attrs[0]['communites']) + + + # check show ip bgp on peer2(quagga2) + qpath = self.get_route(peer2,prefix1, retry=self.retry_count_common) + print qpath + self.assertIsNotNone(qpath) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:20', retry=1)) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:30', retry=1)) + self.assertTrue(self.check_community(peer2, prefix1.split('/')[0], '65100:10', retry=1)) + + + """ + import-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 | + --------------------------------------- + """ + def test_24_community_null_action_export(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" + 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 + + 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") + + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + + 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) + print qpath + self.assertIsNotNone(qpath) + + # 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 '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) + print path + 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) + print qpath + self.assertIsNotNone(qpath) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:20', retry=1)) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:30', retry=1)) + self.assertFalse(self.check_community(peer2, prefix1.split('/')[0], '65100:10', retry=1)) + + +def generate_exabgp_config(pref, aspath='', community=''): + value = {'prefix': pref, + 'aspath': aspath, + 'community': community} + + 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() + + +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; + + family { + inet unicast; + } + static { + # static routes + route %(prefix)s next-hop 10.0.0.100 as-path [%(aspath)s] community [%(community)s]; + } +} +''' + if __name__ == '__main__': if fab.test_user_check() is False: print "you are not root." |