From 1332ae53b2484cb713f1e8b1ae6c041174057770 Mon Sep 17 00:00:00 2001 From: Hiroshi Yokoi Date: Thu, 23 Apr 2015 15:21:46 +0900 Subject: scenario_test: add ipv6 policy test --- gobgp/main.go | 10 +- test/scenario_test/docker_control.py | 9 +- test/scenario_test/gobgp_test.py | 44 +-- test/scenario_test/quagga-rsconfig.go | 124 +++++++- test/scenario_test/quagga_access.py | 32 +- test/scenario_test/route_server_policy_test.py | 395 ++++++++++++++++++++++++- 6 files changed, 570 insertions(+), 44 deletions(-) diff --git a/gobgp/main.go b/gobgp/main.go index 0ea34a9d..b77122b5 100644 --- a/gobgp/main.go +++ b/gobgp/main.go @@ -132,7 +132,15 @@ func (p peers) Less(i, j int) bool { func connGrpc() *grpc.ClientConn { timeout := grpc.WithTimeout(time.Second) - conn, err := grpc.Dial(fmt.Sprintf("%s:%d", globalOpts.Host, globalOpts.Port), timeout) + + // determine IP address version + host := net.ParseIP(globalOpts.Host) + target := fmt.Sprintf("%s:%d", globalOpts.Host, globalOpts.Port) + if host.To4() == nil { + target = fmt.Sprintf("[%s]:%d", globalOpts.Host, globalOpts.Port) + } + + conn, err := grpc.Dial(target, timeout) if err != nil { fmt.Println(err) os.Exit(1) diff --git a/test/scenario_test/docker_control.py b/test/scenario_test/docker_control.py index 3db00712..ec2d8397 100644 --- a/test/scenario_test/docker_control.py +++ b/test/scenario_test/docker_control.py @@ -340,7 +340,7 @@ def change_exabgp_version(): def reload_config(): cmd = "docker exec gobgp /usr/bin/pkill gobgpd -SIGHUP" local(cmd, capture=True) - print "complete append docker container." + print "gobgp config reloaded." def init_test_env_executor(quagga_num, use_local, go_path, log_debug=False, is_route_server=True): @@ -390,7 +390,7 @@ 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=""): +def init_policy_test_env_executor(quagga_num, use_local, go_path, log_debug=False, policy="", use_ipv6=False): print "start initialization of test environment." if docker_container_check() or bridge_setting_check(): @@ -400,6 +400,11 @@ def init_policy_test_env_executor(quagga_num, use_local, go_path, log_debug=Fals print "make gobgp policy test environment." create_config_dir() + + if use_ipv6: + global IP_VERSION + IP_VERSION = IPv6 + bridge_setting_for_docker_connection(BRIDGES) make_config_with_policy(quagga_num, go_path, BRIDGE_0, policy_pattern=policy) diff --git a/test/scenario_test/gobgp_test.py b/test/scenario_test/gobgp_test.py index 5498275e..4fc39ffc 100644 --- a/test/scenario_test/gobgp_test.py +++ b/test/scenario_test/gobgp_test.py @@ -29,6 +29,7 @@ import quagga_access as qaccess class GoBGPTestBase(unittest.TestCase): gobgp_ip = GOBGP_IP + gobgp_ipv6 = GOBGP_ADDRESS_0[IPv6] gobgp_port = "8080" base_dir = CONFIG_DIRR gobgp_config_file = CONFIG_DIRR + "gobgpd.conf" @@ -43,6 +44,7 @@ class GoBGPTestBase(unittest.TestCase): def setUp(self): self.quagga_configs = [] + self.use_ipv6_gobgp = False def get_neighbor_state(self, neighbor_address): print "check neighbor state for %s" % (neighbor_address) @@ -187,7 +189,12 @@ class GoBGPTestBase(unittest.TestCase): def ask_gobgp(self, what, who="", af="ipv4"): af = "-a %s" % af - cmd = "%s/%s -j -u %s -p %s " % (CONFIG_DIR, CLI_CMD, self.gobgp_ip, self.gobgp_port) + + gobgp_ip = self.gobgp_ip + if self.use_ipv6_gobgp: + gobgp_ip = self.gobgp_ipv6 + + cmd = "%s/%s -j -u %s -p %s " % (CONFIG_DIR, CLI_CMD, gobgp_ip, self.gobgp_port) if what == GLOBAL_RIB: cmd += " ".join([what, af]) elif what == NEIGHBOR: @@ -198,16 +205,21 @@ class GoBGPTestBase(unittest.TestCase): result = json.loads(j) return result - def soft_reset(self, neighbor_address, route_family, type="in"): - cmd = "%s/%s -j -u %s -p %s " % (CONFIG_DIR, CLI_CMD, self.gobgp_ip, self.gobgp_port) + def soft_reset(self, neighbor_address, af, type="in"): + + gobgp_ip = self.gobgp_ip + if self.use_ipv6_gobgp: + gobgp_ip = self.gobgp_ipv6 + + cmd = "%s/%s -j -u %s -p %s " % (CONFIG_DIR, CLI_CMD, gobgp_ip, self.gobgp_port) cmd += "neighbor %s " % neighbor_address - cmd += "softreset%s -a %s" % (type, route_family) + cmd += "softreset%s -a %s" % (type, af) local(cmd) - def get_paths_in_localrib(self, neighbor_address, target_prefix, retry=3, interval=5): + def get_paths_in_localrib(self, neighbor_address, target_prefix, af="ipv4", retry=3, interval=5): retry_count = 0 while True: - local_rib = self.ask_gobgp(LOCAL_RIB, neighbor_address) + local_rib = self.ask_gobgp(LOCAL_RIB, neighbor_address, af) g_dest = [dest for dest in local_rib if dest['prefix'] == target_prefix] if len(g_dest) > 0: assert len(g_dest) == 1 @@ -225,22 +237,22 @@ class GoBGPTestBase(unittest.TestCase): print "destination is none" return None - def get_adj_rib_in(self, neighbor_address, target_prefix, retry=3, interval=-1): + def get_adj_rib_in(self, neighbor_address, target_prefix, retry=3, interval=-1, af=IPv4): if interval < 0: interval = self.wait_per_retry - return self.get_adj_rib(neighbor_address, target_prefix, retry, interval, type=ADJ_RIB_IN) + return self.get_adj_rib(neighbor_address, target_prefix, af, retry, interval, type=ADJ_RIB_IN) - def get_adj_rib_out(self, neighbor_address, target_prefix, retry=3, interval=-1): + def get_adj_rib_out(self, neighbor_address, target_prefix, retry=3, interval=-1, af=IPv4): if interval < 0: interval = self.wait_per_retry - return self.get_adj_rib(neighbor_address, target_prefix, retry, interval, type=ADJ_RIB_OUT) + return self.get_adj_rib(neighbor_address, target_prefix, af, retry, interval, type=ADJ_RIB_OUT) - def get_adj_rib(self, neighbor_address, target_prefix, retry, interval, type=ADJ_RIB_IN): + def get_adj_rib(self, neighbor_address, target_prefix, af, retry, interval, type=ADJ_RIB_IN): retry_count = 0 while True: - rib = self.ask_gobgp(type, neighbor_address) + rib = self.ask_gobgp(type, neighbor_address, af) paths = [p for p in rib if p['nlri']['prefix'] == target_prefix] if len(paths) > 0: @@ -260,20 +272,18 @@ class GoBGPTestBase(unittest.TestCase): # get route information on quagga - def get_routing_table(self, neighbor_address, target_prefix, retry=3, interval=-1): + def get_route(self, neighbor_address, target_prefix, retry=3, interval=-1, af=IPv4): if interval < 0: interval = self.wait_per_retry print "check route %s on quagga : %s" % (target_prefix, neighbor_address) retry_count = 0 - # quagga cli doesn't show prefix's netmask - quagga_prefix = target_prefix.split('/')[0] while True: tn = qaccess.login(neighbor_address) - q_rib = qaccess.show_rib(tn) + q_rib = qaccess.lookup_prefix(tn, target_prefix, af) qaccess.logout(tn) for q_path in q_rib: - if quagga_prefix == q_path['Network']: + if target_prefix == q_path['Network']: return q_path retry_count += 1 diff --git a/test/scenario_test/quagga-rsconfig.go b/test/scenario_test/quagga-rsconfig.go index 2f64ce7b..577c1f83 100644 --- a/test/scenario_test/quagga-rsconfig.go +++ b/test/scenario_test/quagga-rsconfig.go @@ -115,8 +115,8 @@ func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bo } if binding != nil { - - if binding.NeighborAddress == c.NeighborAddress.String() { + ip := net.ParseIP(binding.NeighborAddress) + if ip.String() == c.NeighborAddress.String() { ap := config.ApplyPolicy{ ImportPolicies: binding.ImportPolicyNames, ExportPolicies: binding.ExportPolicyNames, @@ -234,6 +234,37 @@ func createPolicyConfig() *config.RoutingPolicy { }}, } + ps3 := config.PrefixSet{ + PrefixSetName: "ps3", + PrefixList: []config.Prefix{ + config.Prefix{ + Address: net.ParseIP("2001:0:10:2::"), + Masklength: 64, + MasklengthRange: "64..128", + }}, + } + + ps4 := config.PrefixSet{ + PrefixSetName: "ps4", + PrefixList: []config.Prefix{ + config.Prefix{ + Address: net.ParseIP("2001:0:10:20::"), + Masklength: 64, + }, config.Prefix{ + Address: net.ParseIP("2001:0:10:200::"), + Masklength: 64, + }}, + } + + ps5 := config.PrefixSet{ + PrefixSetName: "ps5", + PrefixList: []config.Prefix{ + config.Prefix{ + Address: net.ParseIP("2001:0:10:20::"), + Masklength: 64, + }}, + } + ns0 := config.NeighborSet{ NeighborSetName: "ns0", NeighborInfoList: []config.NeighborInfo{ @@ -242,9 +273,12 @@ func createPolicyConfig() *config.RoutingPolicy { }}, } - ds := config.DefinedSets{ - PrefixSetList: []config.PrefixSet{ps0, ps1, ps2}, - NeighborSetList: []config.NeighborSet{ns0}, + ns1 := config.NeighborSet{ + NeighborSetName: "ns1", + NeighborInfoList: []config.NeighborInfo{ + config.NeighborInfo{ + Address: net.ParseIP("2001::0:192:168:0:2"), + }}, } st0 := config.Statement{ @@ -273,6 +307,32 @@ func createPolicyConfig() *config.RoutingPolicy { }, } + st3 := config.Statement{ + Name: "st3", + Conditions: config.Conditions{ + MatchPrefixSet: "ps3", + MatchNeighborSet: "ns1", + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + RejectRoute: true, + }, + } + + st4 := config.Statement{ + Name: "st4", + Conditions: config.Conditions{ + MatchPrefixSet: "ps4", + MatchNeighborSet: "ns1", + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + RejectRoute: true, + }, + } + pd0 := config.PolicyDefinition{ Name: "policy0", StatementList: []config.Statement{st0}, @@ -283,9 +343,24 @@ func createPolicyConfig() *config.RoutingPolicy { StatementList: []config.Statement{st1}, } + pd2 := config.PolicyDefinition{ + Name: "policy2", + StatementList: []config.Statement{st3}, + } + + pd3 := config.PolicyDefinition{ + Name: "policy3", + StatementList: []config.Statement{st4}, + } + + ds := config.DefinedSets{ + PrefixSetList: []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5}, + NeighborSetList: []config.NeighborSet{ns0, ns1}, + } + p := &config.RoutingPolicy{ DefinedSets: ds, - PolicyDefinitionList: []config.PolicyDefinition{pd0, pd1}, + PolicyDefinitionList: []config.PolicyDefinition{pd0, pd1, pd2, pd3}, } return p } @@ -319,10 +394,27 @@ func updatePolicyConfig(outputDir string, pattern string) { }, } + st5 := config.Statement{ + Name: "st5", + Conditions: config.Conditions{ + MatchPrefixSet: "ps5", + MatchNeighborSet: "ns1", + MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL, + }, + Actions: config.Actions{ + AcceptRoute: false, + RejectRoute: true, + }, + } + if pattern == "p3" || pattern == "p4" { policyConf.PolicyDefinitionList[1].StatementList = []config.Statement{st2} } + if pattern == "p7" || pattern == "p8" { + policyConf.PolicyDefinitionList[3].StatementList = []config.Statement{st5} + } + var buffer bytes.Buffer encoder := toml.NewEncoder(&buffer) encoder.Encode(newConf) @@ -367,6 +459,26 @@ func bindPolicy(pattern string) *PolicyBinding { pb.ImportPolicyNames = nil pb.ExportPolicyNames = []string{"policy1"} + case "p5": + pb.NeighborAddress = "2001::0:192:168:0:3" + pb.ImportPolicyNames = []string{"policy2"} + pb.ExportPolicyNames = nil + + case "p6": + pb.NeighborAddress = "2001::0:192:168:0:3" + pb.ImportPolicyNames = nil + pb.ExportPolicyNames = []string{"policy2"} + + case "p7": + pb.NeighborAddress = "2001::0:192:168:0:3" + pb.ImportPolicyNames = []string{"policy3"} + pb.ExportPolicyNames = nil + + case "p8": + pb.NeighborAddress = "2001::0:192:168:0:3" + pb.ImportPolicyNames = nil + pb.ExportPolicyNames = []string{"policy3"} + default: pb = nil } diff --git a/test/scenario_test/quagga_access.py b/test/scenario_test/quagga_access.py index a42e5eab..f29cb301 100644 --- a/test/scenario_test/quagga_access.py +++ b/test/scenario_test/quagga_access.py @@ -27,6 +27,7 @@ def login(host): tn.read_until("Password: ") tn.write(PASSWORD + "\n") tn.write("enable\n") + tn.read_until("bgpd#") return tn @@ -54,10 +55,16 @@ def add_neighbor_metric(tn, as_number, neighbor_address, metric): tn.read_until("bgpd#") -def add_network(tn, as_number, network): +def add_network(tn, as_number, network, use_ipv6=False): tn.write("configure terminal\n") tn.write("router bgp "+str(as_number)+"\n") - tn.write("network "+ network + " \n") + if use_ipv6: + tn.write("address-family ipv6\n") + tn.write("network "+ network + " \n") + tn.write("exit\n") + else: + tn.write("network "+ network + " \n") + tn.write("exit\n") tn.write("exit\n") tn.read_until("bgpd#") @@ -115,3 +122,24 @@ def rib_parser(rib): paths.append(path) return paths + +def lookup_prefix(tn, prefix, af): + if af == IPv4: + tn.write("show ip bgp " + prefix + "\n") + elif af == IPv6: + tn.write("show bgp ipv6 " + prefix + "\n") + else: + print "invalid af: ", af + return + + info = tn.read_until("bgpd#") + paths = [] + for line in info.split("\n"): + path = {} + if "from" in line: + nexthop = line.split()[0] + path['Network'] = prefix + path['Next Hop'] = nexthop + paths.append(path) + + return paths \ 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 7c2e0456..47b2abc6 100644 --- a/test/scenario_test/route_server_policy_test.py +++ b/test/scenario_test/route_server_policy_test.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest -import os import time import sys import nose @@ -25,13 +23,6 @@ from noseplugin import parser_option from gobgp_test import GoBGPTestBase from constant import * -peer1 = "10.0.0.1" -peer2 = "10.0.0.2" -peer3 = "10.0.0.3" - -prefix1 = "192.168.2.0/24" -prefix2 = "192.168.20.0/24" -prefix3 = "192.168.200.0/24" class GoBGPTest(GoBGPTestBase): @@ -44,7 +35,9 @@ class GoBGPTest(GoBGPTestBase): 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) + fab.init_policy_test_env_executor(self.quagga_num, use_local, go_path, + log_debug, policy=policy_pattern, + use_ipv6=self.use_ipv6_gobgp) print "please wait " + str(self.initial_wait_time) + " second" time.sleep(self.initial_wait_time) @@ -67,11 +60,15 @@ class GoBGPTest(GoBGPTestBase): 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" + peer3 = "10.0.0.3" + prefix1 = "192.168.2.0/24" path = self.get_paths_in_localrib(peer1, prefix1, retry=3) self.assertIsNotNone(path) # check show ip bgp on peer1(quagga1) - qpath = self.get_routing_table(peer1,prefix1, retry=3) + qpath = self.get_route(peer1,prefix1, retry=3) print qpath self.assertIsNotNone(qpath) @@ -85,7 +82,7 @@ class GoBGPTest(GoBGPTestBase): self.assertIsNone(path) # check show ip bgp on peer1(quagga3) - qpath = self.get_routing_table(peer3,prefix1, retry=3) + qpath = self.get_route(peer3,prefix1, retry=3) # print qpath self.assertIsNone(qpath) @@ -107,12 +104,17 @@ class GoBGPTest(GoBGPTestBase): 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" + peer3 = "10.0.0.3" + prefix1 = "192.168.2.0/24" + paths = self.get_paths_in_localrib(peer1, prefix1, retry=3) # print paths self.assertIsNotNone(paths) # check show ip bgp on peer1(quagga1) - qpath = self.get_routing_table(peer1, prefix1, retry=3) + qpath = self.get_route(peer1, prefix1, retry=3) # print qpath self.assertIsNotNone(qpath) @@ -130,7 +132,7 @@ class GoBGPTest(GoBGPTestBase): self.assertIsNone(path) # check show ip bgp on peer1(quagga3) - qpath = self.get_routing_table(peer3,prefix1, retry=3) + qpath = self.get_route(peer3,prefix1, retry=3) # print qpath self.assertIsNone(qpath) @@ -166,6 +168,13 @@ class GoBGPTest(GoBGPTestBase): # coming from peer2(10.0.0.2) to peer3(10.0.0.3)'s import-policy. self.initialize(policy_pattern="p3") + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + peer3 = "10.0.0.3" + prefix1 = "192.168.2.0/24" + prefix2 = "192.168.20.0/24" + prefix3 = "192.168.200.0/24" + # add other network tn = qaccess.login(peer2) print "add network 192.168.20.0/24" @@ -184,7 +193,7 @@ class GoBGPTest(GoBGPTestBase): return paths is not None def path_exists_in_routing_table(peer, prefix,r=10): - qpath = self.get_routing_table(peer, prefix, retry=r) + qpath = self.get_route(peer, prefix, retry=r) return qpath is not None def path_exists_in_adj_rib_in(peer, prefix,r=10): @@ -267,6 +276,13 @@ class GoBGPTest(GoBGPTestBase): # coming from peer2(10.0.0.2) to peer3(10.0.0.3)'s export-policy. self.initialize(policy_pattern="p4") + peer1 = "10.0.0.1" + peer2 = "10.0.0.2" + peer3 = "10.0.0.3" + prefix1 = "192.168.2.0/24" + prefix2 = "192.168.20.0/24" + prefix3 = "192.168.200.0/24" + # add other network tn = qaccess.login(peer2) print "add network 192.168.20.0/24" @@ -285,7 +301,7 @@ class GoBGPTest(GoBGPTestBase): return paths is not None def path_exists_in_routing_table(peer, prefix,r=10): - qpath = self.get_routing_table(peer, prefix, retry=r) + qpath = self.get_route(peer, prefix, retry=r) return qpath is not None def path_exists_in_adj_rib_in(peer, prefix,r=10): @@ -351,6 +367,353 @@ class GoBGPTest(GoBGPTestBase): self.assertFalse(path_exists_in_routing_table(peer3, prefix2,r=3)) self.assertTrue(path_exists_in_routing_table(peer3, prefix3)) + """ + import-policy test + r1=2001:0:10:2::/64 + -------------------------------------------------- + peer2 ->(r1)-> | ->(r1)-> peer1-rib ->(r1)-> peer1-adj-rib-out | ->(r1)-> peer1 + | | + | ->x peer3-rib | + -------------------------------------------------- + """ + def test_05_import_policy_initial_ipv6(self): + + # initialize test environment + # 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="p5") + + 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" + peer3 = "2001::192:168:0:3" + 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) + 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) + 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) + # print path + self.assertIsNotNone(path) + + # path = util.get_paths_in_localrib(base_url, peer3, r1, retry=0, interval=w, rf=IPv6) + path = self.get_paths_in_localrib(peer3, r1, retry=0, af=IPv6) + # print path + 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) + print qpath + self.assertIsNone(qpath) + + + """ + export-policy test + r1=2001:0:10:2::/64 + -------------------------------------------------- + peer2 ->(r1)-> | ->(r1)-> peer1-rib ->(r1)-> peer1-adj-rib-out | ->(r1)-> peer1 + | | + | ->(r1)-> peer3-rib ->x peer3-adj-rib-out | + -------------------------------------------------- + """ + def test_06_export_policy_initial_ipv6(self): + + # 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="p6") + 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" + peer3 = "2001::192:168:0:3" + 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) + + # print paths + self.assertIsNotNone(paths) + + # check show ip bgp on peer1(quagga1) + qpath = self.get_route(peer1, r1, retry=3, interval=w, af=IPv6) + # print qpath + self.assertIsNotNone(qpath) + + # check adj-rib-out in peer2 + path = self.get_adj_rib_in(peer2, r1, retry=1, interval=w, af=IPv6) + # print path + self.assertIsNotNone(path) + + path = self.get_paths_in_localrib(peer3, r1, af=IPv6) + # print path + self.assertIsNotNone(path) + + path = self.get_adj_rib_out(peer3, r1, retry=1, interval=w, af=IPv6) + # print path + self.assertIsNone(path) + + # check show ip bgp on peer1(quagga3) + qpath = self.get_route(peer3, r1, retry=3, interval=w, af=IPv6) + # print qpath + self.assertIsNone(qpath) + + + """ + import-policy test + r1=2001:0:10:2::/64 + r2=2001:0:10:20::/64 + r3=2001:0:10:200::/64 + ------------------------------------------------- + |peer1 | + peer2 ->(r1,r2,r3)-> | ->(r1,r2,r3)-> rib ->(r1,r2,r3)-> adj-rib-out | ->(r1,r2,r3)-> peer1 + | | + |peer3 | + | ->(r1)-> rib ->(r1)-> adj-rib-out | ->(r1)-> peer3 + ------------------------------------------------- + | + update gobgp.conf + | + V + ------------------------------------------------- + |peer1 | + peer2 ->(r1,r2,r3)-> | ->(r1,r2,r3)-> rib ->(r1,r2,r3)-> adj-rib-out | ->(r1,r2,r3)-> peer1 + | | + |peer3 | + | ->(r1,r3)-> rib ->(r1,r3)-> adj-rib-out | ->(r1,r3)-> peer3 + ------------------------------------------------- + """ + def test_07_import_policy_update(self): + # initialize test environment + # policy_pattern:p7 attaches a policy to reject route + # 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="p7") + + peer1 = "2001::192:168:0:1" + peer2 = "2001::192:168:0:2" + peer3 = "2001::192:168:0:3" + r1 = "2001:0:10:2::/64" + r2 = "2001:0:10:20::/64" + r3 = "2001:0:10:200::/64" + + w = self.wait_per_retry + + # add other network + tn = qaccess.login(peer2) + print "add network 2001:0:10:20::/64" + qaccess.add_network(tn, 65002, r2, use_ipv6=True) + print "add network 2001:0:10:200::/64" + qaccess.add_network(tn, 65002, r3, use_ipv6=True) + qaccess.logout(tn) + + addresses = self.get_neighbor_address(self.gobgp_config) + self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + + time.sleep(self.initial_wait_time) + + def path_exists_in_localrib(peer, prefix, r=10): + paths = self.get_paths_in_localrib(peer, prefix, + retry=r, interval=w, af=IPv6) + return paths is not None + + def path_exists_in_routing_table(peer, prefix, r=10): + qpath = self.get_route(peer, prefix, retry=r, interval=w, af=IPv6) + return qpath is not None + + def path_exists_in_adj_rib_in(peer, prefix, r=10): + path = self.get_adj_rib_in(peer, prefix, + retry=r, interval=w, af=IPv6) + return path is not None + + self.assertTrue(path_exists_in_localrib(peer1, r1)) + self.assertTrue(path_exists_in_localrib(peer1, r2)) + self.assertTrue(path_exists_in_localrib(peer1, r3)) + + self.assertTrue(path_exists_in_localrib(peer3, r1)) + self.assertFalse(path_exists_in_localrib(peer3, r2, r=3)) + self.assertFalse(path_exists_in_localrib(peer3, r3, r=0)) + + # check show ip bgp on peer1(quagga1) + self.assertTrue(path_exists_in_routing_table(peer1, r1)) + self.assertTrue(path_exists_in_routing_table(peer1, r2)) + self.assertTrue(path_exists_in_routing_table(peer1, r3)) + + # check show ip bgp on peer3(quagga3) + self.assertTrue(path_exists_in_routing_table(peer3, r1)) + self.assertFalse(path_exists_in_routing_table(peer3, r2, r=3)) + self.assertFalse(path_exists_in_routing_table(peer3, r3, r=0)) + + # check adj-rib-out in peer2 + self.assertTrue(path_exists_in_adj_rib_in(peer2, r1)) + self.assertTrue(path_exists_in_adj_rib_in(peer2, r2)) + self.assertTrue(path_exists_in_adj_rib_in(peer2, r3)) + + # update policy + print "update_policy_config" + fab.update_policy_config(parser_option.go_path, policy_pattern="p7") + time.sleep(self.initial_wait_time) + + # soft reset + print "soft_reset" + self.soft_reset(peer2, IPv6) + + # check local-rib + self.assertTrue(path_exists_in_localrib(peer3, r1)) + self.assertFalse(path_exists_in_localrib(peer3, r2, r=3)) + self.assertTrue(path_exists_in_localrib(peer3, r3)) + + # check show ip bgp on peer3(quagga3) + self.assertTrue(path_exists_in_routing_table(peer3, r1)) + self.assertFalse(path_exists_in_routing_table(peer3, r2, r=0)) + self.assertTrue(path_exists_in_routing_table(peer3, r3)) + + """ + export-policy test + r1=2001:0:10:2::/64 + r2=2001:0:10:20::/64 + r3=2001:0:10:200::/64 + ------------------------------------------------- + |peer1 | + peer2 ->(r1,r2,r3)-> | ->(r1,r2,r3)-> rib ->(r1,r2,r3)-> adj-rib-out | ->(r1,r2,r3)-> peer1 + | | + |peer3 | + | ->(r1,r2,r3)-> rib ->(r1)-> adj-rib-out | ->(r1)-> peer3 + ------------------------------------------------- + | + update gobgp.conf + | + V + ------------------------------------------------- + |peer1 | + peer2 ->(r1,r2,r3)-> | ->(r1,r2,r3)-> rib ->(r1,r2,r3)-> adj-rib-out | ->(r1,r2,r3)-> peer1 + | | + |peer3 | + | ->(r1,r2,r3)-> rib ->(r1,r3)-> adj-rib-out | ->(r1,r3)-> peer3 + ------------------------------------------------- + """ + @nose.tools.nottest + def test_08_export_policy_update(self): + # initialize test environment + # policy_pattern:p8 attaches a policy to reject route + # 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="p8") + + peer1 = "2001::192:168:0:1" + peer2 = "2001::192:168:0:2" + peer3 = "2001::192:168:0:3" + r1 = "2001:0:10:2::/64" + r2 = "2001:0:10:20::/64" + r3 = "2001:0:10:200::/64" + w = self.wait_per_retry + + # add other network + tn = qaccess.login(peer2) + print "add network 2001:0:10:20::/64" + qaccess.add_network(tn, 65002, r2, use_ipv6=True) + print "add network 2001:0:10:200::/64" + qaccess.add_network(tn, 65002, r3, use_ipv6=True) + qaccess.logout(tn) + + addresses = self.get_neighbor_address(self.gobgp_config) + self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED") + + time.sleep(self.initial_wait_time) + + def path_exists_in_localrib(peer, prefix, r=10): + paths = self.get_paths_in_localrib(peer, prefix, + retry=r, interval=w, af=IPv6) + return paths is not None + + def path_exists_in_routing_table(peer, prefix, r=10): + qpath = self.get_route(peer, prefix, retry=r, interval=w, af=IPv6) + return qpath is not None + + def path_exists_in_adj_rib_in(peer, prefix, r=10): + path = self.get_adj_rib_in(peer, prefix, + retry=r, interval=w, af=IPv6) + return path is not None + + def path_exists_in_adj_rib_out(peer, prefix, r=10): + path = self.get_adj_rib_out(peer, prefix, + retry=r, interval=w, af=IPv6) + return path is not None + + self.assertTrue(path_exists_in_localrib(peer1, r1)) + self.assertTrue(path_exists_in_localrib(peer1, r2)) + self.assertTrue(path_exists_in_localrib(peer1, r3)) + + # check peer3 local-rib + self.assertTrue(path_exists_in_localrib(peer3, r1)) + self.assertTrue(path_exists_in_localrib(peer3, r2)) + self.assertTrue(path_exists_in_localrib(peer3, r3)) + + # check peer3 rib-out + self.assertTrue(path_exists_in_adj_rib_out(peer3, r1)) + self.assertFalse(path_exists_in_adj_rib_out(peer3, r2, r=3)) + self.assertFalse(path_exists_in_adj_rib_out(peer3, r3, r=3)) + + # check show ip bgp on peer1(quagga1) + self.assertTrue(path_exists_in_routing_table(peer1, r1)) + self.assertTrue(path_exists_in_routing_table(peer1, r2)) + self.assertTrue(path_exists_in_routing_table(peer1, r3)) + + # check show ip bgp on peer3(quagga3) + self.assertTrue(path_exists_in_routing_table(peer3, r1)) + self.assertFalse(path_exists_in_routing_table(peer3, r2, r=3)) + self.assertFalse(path_exists_in_routing_table(peer3, r3, r=0)) + + # check adj-rib-out in peer2 + self.assertTrue(path_exists_in_adj_rib_in(peer2, r1)) + self.assertTrue(path_exists_in_adj_rib_in(peer2, r2)) + self.assertTrue(path_exists_in_adj_rib_in(peer2, r3)) + + # update policy + print "update_policy_config" + fab.update_policy_config(parser_option.go_path, policy_pattern="p8") + time.sleep(self.initial_wait_time) + + # soft reset + print "soft_reset" + self.soft_reset(peer2, "ipv6") + + # check local-rib + self.assertTrue(path_exists_in_localrib(peer3, r1)) + self.assertTrue(path_exists_in_localrib(peer3, r2)) + self.assertTrue(path_exists_in_localrib(peer3, r3)) + + # check local-adj-out-rib + self.assertTrue(path_exists_in_adj_rib_out(peer3, r1)) + self.assertFalse(path_exists_in_adj_rib_out(peer3, r2, r=3)) + # Currently this test fails because of export_policy handling + self.assertTrue(path_exists_in_adj_rib_out(peer3, r3)) + + # check show ip bgp on peer3(quagga3) + self.assertTrue(path_exists_in_routing_table(peer3, r1)) + self.assertFalse(path_exists_in_routing_table(peer3, r2, r=3)) + self.assertTrue(path_exists_in_routing_table(peer3, r3)) + if __name__ == '__main__': if fab.test_user_check() is False: -- cgit v1.2.3