diff options
author | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2015-02-03 11:28:55 +0900 |
---|---|---|
committer | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2015-02-03 11:28:55 +0900 |
commit | d57e6bec0a6dc8eb19cbf912e3bc93a3331df1ce (patch) | |
tree | 308ddc89242a189c7a14db1874d7ff673931fb0d /test/scenario_test | |
parent | 8b754377a3ce9c8463748418ad9a851e59b00a9e (diff) |
scenario_test: add scenario test using the quagga of ipv4 and ipv6
Diffstat (limited to 'test/scenario_test')
-rw-r--r-- | test/scenario_test/docker_control.py | 150 | ||||
-rw-r--r-- | test/scenario_test/peer_info.py | 24 | ||||
-rw-r--r-- | test/scenario_test/quagga-rsconfig.go | 99 | ||||
-rw-r--r-- | test/scenario_test/quagga_access.py | 13 | ||||
-rw-r--r-- | test/scenario_test/route_server_ipv4_v6_test.py | 239 | ||||
-rw-r--r-- | test/scenario_test/route_server_test.py | 45 |
6 files changed, 486 insertions, 84 deletions
diff --git a/test/scenario_test/docker_control.py b/test/scenario_test/docker_control.py index baff3109..0cfc8361 100644 --- a/test/scenario_test/docker_control.py +++ b/test/scenario_test/docker_control.py @@ -18,22 +18,42 @@ import re import os GOBGP_CONTAINER_NAME = "gobgp" -GOBGP_ADDRESS = "10.0.255.1/16" +GOBGP_ADDRESS_0 = {"IPv4": "10.0.255.1", + "IPv6": "2001::0:192:168:255:1"} +GOBGP_ADDRESS_1 = {"IPv4": "11.0.255.1", + "IPv6": "2001::1:192:168:255:1"} +GOBGP_ADDRESS_2 = {"IPv4": "12.0.255.1", + "IPv6": "2001::2:192:168:255:1"} GOBGP_CONFIG_FILE = "gobgpd.conf" EXABGP_CONTAINER_NAME = "exabgp" EXABGP_ADDRESS = "10.0.0.100/16" EXABGP_CONFDIR = "/etc/exabgp/" EXABGP_LOG_FILE = "exabgpd.log" -BRIDGE_ADDRESS = "10.0.255.2" CONFIG_DIR = "/usr/local/gobgp" CONFIG_DIRR = "/usr/local/gobgp/" CONFIG_DIRRR = "/usr/local/gobgp/*" STARTUP_FILE_NAME = "gobgp_startup.sh" STARTUP_FILE = "/mnt/" + STARTUP_FILE_NAME -BRIDGE_0 = {"BRIDGE_NAME": "br0", "BRIDGE_ADDRESS": "10.0.255.2"} -BRIDGE_1 = {"BRIDGE_NAME": "br1", "BRIDGE_ADDRESS": "11.0.255.2"} -BRIDGE_2 = {"BRIDGE_NAME": "br2", "BRIDGE_ADDRESS": "12.0.255.2"} + +IP_VERSION = "IPv4" +IF_CONFIG_OPTION = {"IPv4": "inet", "IPv6": "inet6"} +BRIDGE_0 = {"BRIDGE_NAME": "br0", + "IPv4": "10.0.255.2", + "IPv6": "2001::0:192:168:255:2"} +BRIDGE_1 = {"BRIDGE_NAME": "br1", + "IPv4": "11.0.255.2", + "IPv6": "2001::1:192:168:255:2"} +BRIDGE_2 = {"BRIDGE_NAME": "br2", + "IPv4": "12.0.255.2", + "IPv6": "2001::2:192:168:255:2"} BRIDGES = [BRIDGE_0, BRIDGE_1, BRIDGE_2] + +BASE_NET = {BRIDGE_0["BRIDGE_NAME"]: {"IPv4": "10.0.0.", "IPv6": "2001::0:192:168:0:"}, + BRIDGE_1["BRIDGE_NAME"]: {"IPv4": "11.0.0.", "IPv6": "2001::1:192:168:0:"}, + BRIDGE_2["BRIDGE_NAME"]: {"IPv4": "12.0.0.", "IPv6": "2001::2:192:168:0:"}} + +BASE_MASK = {"IPv4": "/16", "IPv6": "/64"} + A_PART_OF_CURRENT_DIR = "/test/scenario_test" @@ -94,7 +114,7 @@ def go_path_check(): return go_path_exist -def docker_container_checks(): +def docker_container_check(): container_exists = False outbuf = local("docker ps -a", capture=True) docker_ps = outbuf.split('\n') @@ -106,6 +126,17 @@ def docker_container_checks(): return container_exists +def bridge_setting_check(): + setting_exists = False + for bridge in BRIDGES: + sysfs_name = "/sys/class/net/" + bridge["BRIDGE_NAME"] + if os.path.exists(sysfs_name): + setting_exists = True + return setting_exists + return setting_exists + + + def docker_containers_get(): containers = [] cmd = "docker ps -a | awk '{print $NF}'" @@ -117,9 +148,9 @@ def docker_containers_get(): return containers -def docker_container_set_ipaddress(bridge, quagga_name, address): +def docker_container_set_ipaddress(bridge, name, address): cmd = "pipework " + bridge["BRIDGE_NAME"] + " -i eth-" + bridge["BRIDGE_NAME"]\ - + " " + quagga_name + " " + address + + " " + name + " " + address local(cmd, capture=True) @@ -128,8 +159,7 @@ def docker_container_run_quagga(quagga_num, bridge): cmd = "docker run --privileged=true -v " + CONFIG_DIR + "/" + quagga_name +\ ":/etc/quagga --name " + quagga_name + " -id osrg/quagga" local(cmd, capture=True) - aff_net = bridge["BRIDGE_NAME"][-1] - quagga_address = "1" + aff_net + ".0.0." + str(quagga_num) + "/16" + quagga_address = BASE_NET[bridge["BRIDGE_NAME"]][IP_VERSION] + str(quagga_num) + BASE_MASK[IP_VERSION] docker_container_set_ipaddress(bridge, quagga_name, quagga_address) @@ -137,7 +167,7 @@ def docker_container_run_gobgp(bridge): cmd = "docker run --privileged=true -v " + CONFIG_DIR + ":/mnt -d --name "\ + GOBGP_CONTAINER_NAME + " -id osrg/gobgp" local(cmd, capture=True) - docker_container_set_ipaddress(bridge, GOBGP_CONTAINER_NAME, GOBGP_ADDRESS) + docker_container_set_ipaddress(bridge, GOBGP_CONTAINER_NAME, GOBGP_ADDRESS_0[IP_VERSION] + BASE_MASK[IP_VERSION]) def docker_container_run_exabgp(bridge): @@ -210,9 +240,6 @@ def docker_containers_destroy(): def docker_container_quagga_append(quagga_num, bridge): print "start append docker container." docker_container_run_quagga(quagga_num, bridge) - cmd = "docker exec gobgp /usr/bin/pkill gobgp -SIGHUP" - local(cmd, capture=True) - print "complete append docker container." def docker_container_quagga_removed(quagga_num): @@ -222,12 +249,16 @@ def docker_container_quagga_removed(quagga_num): print "complete removed docker container." -def bridge_setting_for_docker_connection(): - bridge_unsetting_for_docker_connection() - for bridge in BRIDGES: +def bridge_setting_for_docker_connection(bridges): + # bridge_unsetting_for_docker_connection() + for bridge in bridges: cmd = "brctl addbr " + bridge["BRIDGE_NAME"] local(cmd, capture=True) - cmd = "ifconfig " + bridge["BRIDGE_NAME"] + " " + bridge["BRIDGE_ADDRESS"] + if IP_VERSION == "IPv6": + cmd = "ifconfig " + bridge["BRIDGE_NAME"] + " " + IF_CONFIG_OPTION[IP_VERSION] +\ + " add " + bridge[IP_VERSION] + BASE_MASK[IP_VERSION] + else: + cmd = "ifconfig " + bridge["BRIDGE_NAME"] + " " + bridge[IP_VERSION] local(cmd, capture=True) cmd = "ifconfig " + bridge["BRIDGE_NAME"] + " up" local(cmd, capture=True) @@ -261,7 +292,7 @@ def get_notification_from_exabgp_log(): return err_mgs -def make_config(quagga_num, go_path): +def make_config(quagga_num, go_path, bridge): if go_path != "": print "specified go path is [ " + go_path + " ]." if os.path.isdir(go_path): @@ -269,11 +300,12 @@ def make_config(quagga_num, go_path): else: print "specified go path do not use." pwd = local("pwd", capture=True) - cmd = go_path + "go run " + pwd + "/quagga-rsconfig.go -n " + str(quagga_num) + " -c /usr/local/gobgp" + cmd = go_path + "go run " + pwd + "/quagga-rsconfig.go -n " + str(quagga_num) +\ + " -c /usr/local/gobgp -v " + IP_VERSION + " -i " + bridge["BRIDGE_NAME"][-1] local(cmd, capture=True) -def make_config_append(quagga_num, go_path): +def make_config_append(quagga_num, go_path, bridge): if go_path != "": print "specified go path is [ " + go_path + " ]." if os.path.isdir(go_path): @@ -281,21 +313,67 @@ def make_config_append(quagga_num, go_path): else: print "specified go path do not use." pwd = local("pwd", capture=True) - cmd = go_path + "go run " + pwd + "/quagga-rsconfig.go -a " + str(quagga_num) + " -c /usr/local/gobgp" + cmd = go_path + "go run " + pwd + "/quagga-rsconfig.go -a " + str(quagga_num) +\ + " -c /usr/local/gobgp -v " + IP_VERSION + " -i " + bridge["BRIDGE_NAME"][-1] local(cmd, capture=True) +def reload_config(): + cmd = "docker exec gobgp /usr/bin/pkill gobgp -SIGHUP" + local(cmd, capture=True) + print "complete append docker container." + + def init_test_env_executor(quagga_num, use_local, go_path): print "start initialization of test environment." - if docker_container_checks(): + if docker_container_check() or bridge_setting_check(): + print "gobgp test environment already exists." + print "so that remake gobgp test environment." + docker_containers_destroy() + + print "make gobgp test environment." + bridge_setting_for_docker_connection(BRIDGES) + make_config(quagga_num, go_path, BRIDGE_0) + + # run each docker container + for num in range(1, quagga_num + 1): + docker_container_run_quagga(num, BRIDGE_0) + docker_container_run_gobgp(BRIDGE_0) + + # execute local gobgp program in the docker container if the input option is local + if use_local: + print "execute gobgp program in local machine." + pwd = local("pwd", capture=True) + if A_PART_OF_CURRENT_DIR in pwd: + gobgp_path = re.sub(A_PART_OF_CURRENT_DIR, "", pwd) + cmd = "cp -r " + gobgp_path + " " + CONFIG_DIRR + local(cmd, capture=True) + make_startup_file_use_local_gobgp() + else: + print "scenario_test directory is not." + print "execute gobgp program of osrg/master in github." + make_startup_file() + else: + print "execute gobgp program of osrg/master in github." + make_startup_file() + + start_gobgp() + + print "complete initialization of test environment." + + +def init_ipv6_test_env_executor(quagga_num, use_local, go_path): + print "start initialization of test environment." + + if docker_container_check() or bridge_setting_check(): print "gobgp test environment already exists." print "so that remake gobgp test environment." docker_containers_destroy() print "make gobgp test environment." - bridge_setting_for_docker_connection() - make_config(quagga_num, go_path) + bridge_setting_for_docker_connection([BRIDGE_0]) + make_config(quagga_num, go_path, BRIDGE_0) # run each docker container for num in range(1, quagga_num + 1): @@ -326,13 +404,14 @@ def init_test_env_executor(quagga_num, use_local, go_path): def init_malformed_test_env_executor(conf_file, use_local): print "start initialization of exabgp test environment." - if docker_container_checks(): + + if docker_container_check() or bridge_setting_check(): print "gobgp test environment already exists." print "so that remake gobgp test environment." docker_containers_destroy() print "make gobgp test environment." - bridge_setting_for_docker_connection() + bridge_setting_for_docker_connection(BRIDGES) pwd = local("pwd", capture=True) gobgp_file = pwd + "/exabgp_test_conf/gobgpd.conf" cmd = "cp " + gobgp_file + " " + CONFIG_DIRR @@ -370,9 +449,21 @@ def init_malformed_test_env_executor(conf_file, use_local): def docker_container_quagga_append_executor(quagga_num, go_path): - make_config_append(quagga_num, go_path) + make_config_append(quagga_num, go_path, BRIDGE_0) docker_container_quagga_append(quagga_num, BRIDGE_0) + reload_config() + +def docker_container_ipv6_quagga_append_executor(quagga_nums, go_path): + print "append ipv6 quagga container." + global IP_VERSION + IP_VERSION = "IPv6" + bridge_setting_for_docker_connection([BRIDGE_1]) + docker_container_set_ipaddress(BRIDGE_1, GOBGP_CONTAINER_NAME, GOBGP_ADDRESS_1[IP_VERSION] + BASE_MASK[IP_VERSION]) + for quagga_num in quagga_nums: + make_config_append(quagga_num, go_path, BRIDGE_1) + docker_container_quagga_append(quagga_num, BRIDGE_1) + reload_config() def docker_container_quagga_removed_executor(quagga_num): docker_container_quagga_removed(quagga_num) @@ -380,9 +471,10 @@ def docker_container_quagga_removed_executor(quagga_num): def docker_container_make_bestpath_env_executor(append_quagga_num, go_path): print "start make bestpath environment" - make_config_append(append_quagga_num, go_path) + make_config_append(append_quagga_num, go_path, BRIDGE_1) append_quagga_name = "q" + str(append_quagga_num) docker_container_quagga_append(append_quagga_num, BRIDGE_1) + reload_config() docker_container_set_ipaddress(BRIDGE_1, "q2", "11.0.0.2/16") docker_container_set_ipaddress(BRIDGE_2, append_quagga_name, "12.0.0.20/16") docker_container_set_ipaddress(BRIDGE_2, "q3", "12.0.0.3/16") diff --git a/test/scenario_test/peer_info.py b/test/scenario_test/peer_info.py new file mode 100644 index 00000000..00490d09 --- /dev/null +++ b/test/scenario_test/peer_info.py @@ -0,0 +1,24 @@ +class Peer: + def __init__(self, peer_ip, peer_id, peer_as, ip_version): + # def __init__(self, peer_ip, peer_id, peer_as): + self.peer_ip = peer_ip + self.peer_id = peer_id + self.peer_as = peer_as + self.ip_version = ip_version + self.neighbors = [] + self.destinations = {} + + +class Destination: + def __init__(self, prefix): + self.prefix = prefix + self.paths = [] + + +class Path: + def __init__(self, network, nexthop): + self.network = network + self.nexthop = nexthop + self.origin = None + self.as_path = [] + self.metric = None
\ No newline at end of file diff --git a/test/scenario_test/quagga-rsconfig.go b/test/scenario_test/quagga-rsconfig.go index bede8326..870c5d60 100644 --- a/test/scenario_test/quagga-rsconfig.go +++ b/test/scenario_test/quagga-rsconfig.go @@ -13,6 +13,16 @@ import ( "path/filepath" ) +var serverAddress = make(map[string]string) +var baseNeighborAddress = make(map[string]string) +var baseNeighborNetwork = make(map[string]string) +var baseNeighborNetMask = make(map[string]string) + +const ( + IPv4 = "IPv4" + IPv6 = "IPv6" +) + type QuaggaConfig struct { id int config *config.NeighborType @@ -29,21 +39,48 @@ func NewQuaggaConfig(id int, gConfig *config.GlobalType, myConfig *config.Neighb } } -func (qt *QuaggaConfig) Config() *bytes.Buffer { +func (qt *QuaggaConfig) IPv4Config() *bytes.Buffer { buf := bytes.NewBuffer(nil) + buf.WriteString(fmt.Sprintf("! my address %s\n", qt.config.NeighborAddress)) + buf.WriteString("! my ip_version IPv4\n") + buf.WriteString("hostname bgpd\n") + buf.WriteString("password zebra\n") + buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.PeerAs)) + buf.WriteString(fmt.Sprintf("bgp router-id 192.168.0.%d\n", qt.id)) + buf.WriteString(fmt.Sprintf("network %s%d%s\n", baseNeighborNetwork["IPv4"], qt.id, baseNeighborNetMask["IPv4"])) + buf.WriteString(fmt.Sprintf("neighbor %s remote-as %d\n", qt.serverIP, qt.gobgpConfig.As)) + buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.AuthPassword)) + buf.WriteString("log file /var/log/quagga/bgpd.log\n") + + return buf +} +func (qt *QuaggaConfig) IPv6Config() *bytes.Buffer { + buf := bytes.NewBuffer(nil) + buf.WriteString(fmt.Sprintf("! my address %s\n", qt.config.NeighborAddress)) + buf.WriteString("! my ip_version IPv6\n") buf.WriteString("hostname bgpd\n") buf.WriteString("password zebra\n") buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.PeerAs)) buf.WriteString(fmt.Sprintf("bgp router-id 192.168.0.%d\n", qt.id)) - buf.WriteString(fmt.Sprintf("network 192.168.%d.0/24\n", qt.id)) + buf.WriteString("no bgp default ipv4-unicast\n") buf.WriteString(fmt.Sprintf("neighbor %s remote-as %d\n", qt.serverIP, qt.gobgpConfig.As)) buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.AuthPassword)) - buf.WriteString("log file /var/log/quagga/bgpd.log") + buf.WriteString("address-family ipv6\n") + buf.WriteString(fmt.Sprintf("network %s%d%s\n", baseNeighborNetwork["IPv6"], qt.id, baseNeighborNetMask["IPv6"])) + buf.WriteString(fmt.Sprintf("neighbor %s activate\n", qt.serverIP)) + buf.WriteString(fmt.Sprintf("neighbor %s route-map IPV6-OUT out\n", qt.serverIP)) + buf.WriteString("exit-address-family\n") + buf.WriteString("ipv6 prefix-list pl-ipv6 seq 10 permit any\n") + buf.WriteString("route-map IPV6-OUT permit 10\n") + buf.WriteString("match ipv6 address prefix-list pl-ipv6\n") + buf.WriteString(fmt.Sprintf("set ipv6 next-hop global %s\n", qt.config.NeighborAddress)) + buf.WriteString("log file /var/log/quagga/bgpd.log\n") + return buf } -func create_config_files(nr int, outputDir string) { +func create_config_files(nr int, outputDir string, IPVersion string) { quaggaConfigList := make([]*QuaggaConfig, 0) gobgpConf := config.BgpType{ @@ -56,14 +93,19 @@ func create_config_files(nr int, outputDir string) { for i := 1; i < nr+1; i++ { c := config.NeighborType{ PeerAs: 65000 + uint32(i), - NeighborAddress: net.ParseIP(fmt.Sprintf("10.0.0.%d", i)), + NeighborAddress: net.ParseIP(fmt.Sprintf("%s%d", baseNeighborAddress[IPVersion], i)), AuthPassword: fmt.Sprintf("hoge%d", i), } gobgpConf.NeighborList = append(gobgpConf.NeighborList, c) - q := NewQuaggaConfig(i, &gobgpConf.Global, &c, net.ParseIP("10.0.255.1")) + q := NewQuaggaConfig(i, &gobgpConf.Global, &c, net.ParseIP(serverAddress[IPVersion])) quaggaConfigList = append(quaggaConfigList, q) os.Mkdir(fmt.Sprintf("%s/q%d", outputDir, i), 0755) - err := ioutil.WriteFile(fmt.Sprintf("%s/q%d/bgpd.conf", outputDir, i), q.Config().Bytes(), 0644) + var err error + if IPVersion == "IPv6" { + err = ioutil.WriteFile(fmt.Sprintf("%s/q%d/bgpd.conf", outputDir, i), q.IPv6Config().Bytes(), 0644) + } else { + err = ioutil.WriteFile(fmt.Sprintf("%s/q%d/bgpd.conf", outputDir, i), q.IPv4Config().Bytes(), 0644) + } if err != nil { log.Fatal(err) } @@ -79,7 +121,8 @@ func create_config_files(nr int, outputDir string) { } } -func append_config_files(ar int, outputDir string) { +func append_config_files(ar int, outputDir string, IPVersion string) { + gobgpConf := config.BgpType{ Global: config.GlobalType{ As: 65000, @@ -87,14 +130,18 @@ func append_config_files(ar int, outputDir string) { }, } c := config.NeighborType{ - PeerAs: 65000 + uint32(ar), - - NeighborAddress: net.ParseIP(fmt.Sprintf("10.0.0.%d", ar)), + PeerAs: 65000 + uint32(ar), + NeighborAddress: net.ParseIP(fmt.Sprintf("%s%d", baseNeighborAddress[IPVersion], ar)), AuthPassword: fmt.Sprintf("hoge%d", ar), } - q := NewQuaggaConfig(ar, &gobgpConf.Global, &c, net.ParseIP("10.0.255.1")) + q := NewQuaggaConfig(ar, &gobgpConf.Global, &c, net.ParseIP(serverAddress[IPVersion])) os.Mkdir(fmt.Sprintf("%s/q%d", outputDir, ar), 0755) - err := ioutil.WriteFile(fmt.Sprintf("%s/q%d/bgpd.conf", outputDir, ar), q.Config().Bytes(), 0644) + var err error + if IPVersion == "IPv6" { + err = ioutil.WriteFile(fmt.Sprintf("%s/q%d/bgpd.conf", outputDir, ar), q.IPv6Config().Bytes(), 0644) + } else { + err = ioutil.WriteFile(fmt.Sprintf("%s/q%d/bgpd.conf", outputDir, ar), q.IPv4Config().Bytes(), 0644) + } if err != nil { log.Fatal(err) } @@ -115,14 +162,17 @@ func append_config_files(ar int, outputDir string) { func main() { var opts struct { - ClientNumber int `short:"n" long:"client-number" description:"specfying the number of clients" default:"8"` - OutputDir string `short:"c" long:"output" description:"specifing the output directory"` - AppendClient int `short:"a" long:"append" description:"specifing the add client number" default:"0"` + ClientNumber int `short:"n" long:"client-number" description:"specfying the number of clients" default:"8"` + OutputDir string `short:"c" long:"output" description:"specifing the output directory"` + AppendClient int `short:"a" long:"append" description:"specifing the add client number" default:"0"` + IPVersion string `short:"v" long:"ip-version" description:"specifing the use ip version" default:"IPv4"` + NetIdentifier int `short:"i" long:"net-identifer" description:"specifing the use network identifier" default:"0"` } parser := flags.NewParser(&opts, flags.Default) _, err := parser.Parse() if err != nil { + fmt.Print(err) os.Exit(1) } @@ -134,12 +184,25 @@ func main() { } } + if opts.IPVersion == IPv6 { + serverAddress[IPv6] = fmt.Sprintf("2001::%d:192:168:255:1", opts.NetIdentifier) + baseNeighborAddress[IPv6] = fmt.Sprintf("2001::%d:192:168:0:", opts.NetIdentifier) + baseNeighborNetwork[IPv6] = "2001:0:10:" + baseNeighborNetMask[IPv6] = "::/64" + } else { + opts.IPVersion = IPv4 + serverAddress[IPv4] = fmt.Sprintf("1%d.0.255.1", opts.NetIdentifier) + baseNeighborAddress[IPv4] = fmt.Sprintf("1%d.0.0.", opts.NetIdentifier) + baseNeighborNetwork[IPv4] = "192.168." + baseNeighborNetMask[IPv4] = ".0/24" + } + if opts.AppendClient == 0 { - create_config_files(opts.ClientNumber, opts.OutputDir) + create_config_files(opts.ClientNumber, opts.OutputDir, opts.IPVersion) } else { if _, err := os.Stat(fmt.Sprintf("%s/gobgpd.conf", opts.OutputDir)); os.IsNotExist(err) { log.Fatal(err) } - append_config_files(opts.AppendClient, opts.OutputDir) + append_config_files(opts.AppendClient, opts.OutputDir, opts.IPVersion) } } diff --git a/test/scenario_test/quagga_access.py b/test/scenario_test/quagga_access.py index df2eb938..1e51afaf 100644 --- a/test/scenario_test/quagga_access.py +++ b/test/scenario_test/quagga_access.py @@ -82,7 +82,13 @@ def show_rib(tn): tn.write("show ip bgp\n") tn.read_until(" Network Next Hop Metric LocPrf Weight Path") rib = tn.read_until("bgpd#") - # print header + return rib_parser(rib) + + +def show_ipv6_rib(tn): + tn.write("show bgp ipv6\n") + tn.read_until(" Network Next Hop Metric LocPrf Weight Path") + rib = tn.read_until("bgpd#") return rib_parser(rib) @@ -90,6 +96,7 @@ def clear_ip_bgp(tn): tn.write("clear ip bgp *\n") tn.read_until("bgpd#") + def rib_parser(rib): lines = rib.split("\n") paths = [] @@ -99,10 +106,6 @@ def rib_parser(rib): elems = line.split() path['Network'] = elems[1] path['Next Hop'] = elems[2] - # path['Metric'] = elems[3] - # path['LocPrf'] = elems[4] - # path['Weight'] = elems[5] - # path['Path'] = elems[6] if len(path) > 0: paths.append(path) return paths diff --git a/test/scenario_test/route_server_ipv4_v6_test.py b/test/scenario_test/route_server_ipv4_v6_test.py new file mode 100644 index 00000000..8fbfafd0 --- /dev/null +++ b/test/scenario_test/route_server_ipv4_v6_test.py @@ -0,0 +1,239 @@ +# Copyright (C) 2014 Nippon Telegraph and Telephone Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +import requests +import json +import toml +import os +import time +import sys +import nose +import quagga_access as qaccess +from peer_info import Peer +from peer_info import Destination +from peer_info import Path +from ciscoconfparse import CiscoConfParse +import docker_control as fab +from noseplugin import OptionParser +from noseplugin import parser_option + + +class GoBGPIPv6Test(unittest.TestCase): + + gobgp_ip = "10.0.255.1" + gobgp_port = "8080" + base_dir = "/usr/local/gobgp/" + gobgp_config_file = "/usr/local/gobgp/gobgpd.conf" + gobgp_config = None + quagga_num = 2 + append_quagga = 10 + remove_quagga = 10 + append_quagga_best = 20 + sleep_time = 20 + + def __init__(self, *args, **kwargs): + super(GoBGPIPv6Test, self).__init__(*args, **kwargs) + + def setUp(self): + self.quagga_configs = [] + + # test each neighbor state is turned establish + def test_01_ipv4_ipv6_neighbor_established(self): + print "test_ipv4_ipv6_neighbor_established" + + use_local = parser_option.use_local + go_path = parser_option.go_path + fab.init_ipv6_test_env_executor(self.quagga_num, use_local, go_path) + time.sleep(self.sleep_time) + print "please wait" + fab.docker_container_ipv6_quagga_append_executor([3, 4], go_path) + print "please wait" + time.sleep(self.sleep_time) + if self.check_load_config() is False: + return + + addresses = self.get_neighbor_address(self.gobgp_config) + + for address in addresses: + # get neighbor state and remote ip from gobgp connections + print "check of [ " + address[0] + " : " + address[1] + " ]" + url = "http://" + self.gobgp_ip + ":" + self.gobgp_port + "/v1/bgp/neighbor/" + address[0] + r = requests.get(url) + neighbor = json.loads(r.text) + state = neighbor['info']['bgp_state'] + remote_ip = neighbor['conf']['remote_ip'] + self.assertEqual(address[0], remote_ip) + self.assertEqual(state, "BGP_FSM_ESTABLISHED") + + def test_02_ipv4_ipv6_received_route(self): + print "test_ipv4_ipv6_received_route" + if self.check_load_config() is False: + return + + for address in self.get_neighbor_address(self.gobgp_config): + print "check of [ " + address[0] + " : " + address[1] + " ]" + # get local-rib per peer + url = "http://" + self.gobgp_ip + ":" + self.gobgp_port + "/v1/bgp/neighbor/" + address[0] + "/local-rib" + r = requests.get(url) + local_rib = json.loads(r.text) + + for quagga_config in self.quagga_configs: + # print quagga_config.peer_ip + " : " + address[0] + " | " + quagga_config.ip_version + " : " + address[1] + if quagga_config.peer_ip == address[0] or quagga_config.ip_version != address[1]: + for c_dest in quagga_config.destinations.itervalues(): + # print "config : ", c_dest.prefix, "my ip or different ip version!!!" + g_dests = local_rib['Destinations'] + exist_n = 0 + for g_dest in g_dests: + # print "gobgp : ", g_dest['Prefix'] + if c_dest.prefix == g_dest['Prefix']: + exist_n += 1 + self.assertEqual(exist_n, 0) + else: + for c_dest in quagga_config.destinations.itervalues(): + # print "config : ", c_dest.prefix" + g_dests = local_rib['Destinations'] + exist_n = 0 + for g_dest in g_dests: + # print "gobgp : ", g_dest['Prefix'] + if c_dest.prefix == g_dest['Prefix']: + exist_n += 1 + self.assertEqual(exist_n, 1) + + def test_03_advertising_route(self): + print "test_advertising_route" + if self.check_load_config() is False: + return + + for address in self.get_neighbor_address(self.gobgp_config): + print "check of [ " + address[0] + " : " + address[1] + " ]" + tn = qaccess.login(address[0]) + if address[1] == "IPv6": + q_rib = qaccess.show_ipv6_rib(tn) + else: + q_rib = qaccess.show_rib(tn) + for quagga_config in self.quagga_configs: + if quagga_config.peer_ip == address[0] or quagga_config.ip_version != address[1]: + for c_dest in quagga_config.destinations.itervalues(): + exist_n = 0 + for c_path in c_dest.paths: + # print "conf : ", c_path.network, c_path.nexthop, "my ip or different ip version!!!" + for q_path in q_rib: + # print "quag : ", q_path['Network'], q_path['Next Hop'] + if "0.0.0.0" == q_path['Next Hop'] or "::" == q_path['Next Hop']: + continue + if c_path.network.split("/")[0] == q_path['Network']: + exist_n += 1 + self.assertEqual(exist_n, 0) + + else: + for c_dest in quagga_config.destinations.itervalues(): + exist_n = 0 + for c_path in c_dest.paths: + # print "conf : ", c_path.network, c_path.nexthop + for q_path in q_rib: + # print "quag : ", q_path['Network'], q_path['Next Hop'] + if quagga_config.ip_version != "IPv6": + c_path.network = c_path.network.split("/")[0] + if c_path.network == q_path['Network'] and c_path.nexthop == q_path['Next Hop']: + exist_n += 1 + self.assertEqual(exist_n, 1) + + def load_gobgp_config(self): + try: + self.gobgp_config = toml.loads(open(self.gobgp_config_file).read()) + except IOError, (errno, strerror): + print "I/O error(%s): %s" % (errno, strerror) + + # load configration from quagga(bgpd.conf) + def load_quagga_config(self): + dirs = [] + try: + content = os.listdir(self.base_dir) + for item in content: + if "q" != item[0]: + continue + if os.path.isdir(os.path.join(self.base_dir, item)): + dirs.append(item) + except OSError, (errno, strerror): + print "I/O error(%s): %s" % (errno, strerror) + + for dir in dirs: + config_path = self.base_dir + dir + "/bgpd.conf" + config = CiscoConfParse(config_path) + + peer_ip = config.find_objects(r"^!\smy\saddress")[0].text.split(" ")[3] + peer_ip_version = config.find_objects(r"^!\smy\sip_version")[0].text.split(" ")[3] + peer_id = config.find_objects(r"^bgp\srouter-id")[0].text.split(" ")[2] + peer_as = config.find_objects(r"^router\sbgp")[0].text.split(" ")[2] + quagga_config = Peer(peer_ip, peer_id, peer_as, peer_ip_version) + + networks = config.find_objects(r"^network") + if len(networks) == 0: + continue + for network in networks: + elems = network.text.split(" ") + prefix = elems[1].split("/")[0] + network = elems[1] + nexthop = peer_ip + path = Path(network, nexthop) + dest = Destination(prefix) + dest.paths.append(path) + quagga_config.destinations[prefix] = dest + + neighbors = config.find_objects(r"^neighbor\s.*\sremote-as") + if len(neighbors) == 0: + continue + for neighbor in neighbors: + elems = neighbor.text.split(" ") + neighbor = Peer(elems[1], None, elems[3], None) + quagga_config.neighbors.append(neighbor) + self.quagga_configs.append(quagga_config) + + # get address of each neighbor from gobpg configration + def get_neighbor_address(self, config): + address = [] + neighbors_config = config['NeighborList'] + for neighbor_config in neighbors_config: + neighbor_ip = neighbor_config['NeighborAddress'] + address_version = "IPv4" + if ":" in neighbor_ip: + address_version = "IPv6" + neighbor_ip_info = [neighbor_ip, address_version] + address.append(neighbor_ip_info) + return address + + def check_load_config(self): + self.load_gobgp_config() + self.load_quagga_config() + if self.gobgp_config is None: + print "Failed to read the gobgp configuration file" + return False + if len(self.quagga_configs) == 0: + print "Failed to read the quagga configuration file" + return False + return True + + +if __name__ == '__main__': + if fab.test_user_check() is False: + print "you are not root." + sys.exit(1) + if fab.docker_pkg_check() is False: + print "not install docker package." + sys.exit(1) + + nose.main(argv=sys.argv, addplugins=[OptionParser()], defaultTest=sys.argv[0]) diff --git a/test/scenario_test/route_server_test.py b/test/scenario_test/route_server_test.py index 36bac41a..7f6eb9c3 100644 --- a/test/scenario_test/route_server_test.py +++ b/test/scenario_test/route_server_test.py @@ -22,6 +22,9 @@ import time import sys import nose import quagga_access as qaccess +from peer_info import Peer +from peer_info import Destination +from peer_info import Path from ciscoconfparse import CiscoConfParse import docker_control as fab from noseplugin import OptionParser @@ -395,7 +398,6 @@ class GoBGPTest(unittest.TestCase): return self.assertEqual(ans_nexthop, rep_nexthop) - def load_gobgp_config(self): try: self.gobgp_config = toml.loads(open(self.gobgp_config_file).read()) @@ -418,10 +420,12 @@ class GoBGPTest(unittest.TestCase): for dir in dirs: config_path = self.base_dir + dir + "/bgpd.conf" config = CiscoConfParse(config_path) - peer_ip = "10.0.0." + str(dir).replace("q", "") - peer_id = config.find_objects(r"^bgp\srouter-id")[0].text - peer_as = config.find_objects(r"^router\sbgp")[0].text - quagga_config = Peer(peer_ip, peer_id, peer_as) + + peer_ip = config.find_objects(r"^!\smy\saddress")[0].text.split(" ")[3] + peer_ip_version = config.find_objects(r"^!\smy\sip_version")[0].text.split(" ")[3] + peer_id = config.find_objects(r"^bgp\srouter-id")[0].text.split(" ")[2] + peer_as = config.find_objects(r"^router\sbgp")[0].text.split(" ")[2] + quagga_config = Peer(peer_ip, peer_id, peer_as, peer_ip_version) networks = config.find_objects(r"^network") if len(networks) == 0: @@ -435,15 +439,17 @@ class GoBGPTest(unittest.TestCase): dest = Destination(prefix) dest.paths.append(path) quagga_config.destinations[prefix] = dest + # print "prefix: " + prefix + # print "network: " + network + # print "nexthop: " + nexthop neighbors = config.find_objects(r"^neighbor\s.*\sremote-as") if len(neighbors) == 0: continue for neighbor in neighbors: elems = neighbor.text.split(" ") - neighbor = Peer(elems[1], None, elems[3]) + neighbor = Peer(elems[1], None, elems[3], None) quagga_config.neighbors.append(neighbor) - self.quagga_configs.append(quagga_config) # get address of each neighbor from gobpg configration @@ -467,29 +473,6 @@ class GoBGPTest(unittest.TestCase): return True -class Peer: - def __init__(self, peer_ip, peer_id, peer_as): - self.peer_ip = peer_ip - self.peer_id = peer_id - self.peer_as = peer_as - self.neighbors = [] - self.destinations = {} - - -class Destination: - def __init__(self, prefix): - self.prefix = prefix - self.paths = [] - - -class Path: - def __init__(self, network, nexthop): - self.network = network - self.nexthop = nexthop - self.origin = None - self.as_path = [] - self.metric = None - if __name__ == '__main__': if fab.test_user_check() is False: print "you are not root." @@ -497,7 +480,5 @@ if __name__ == '__main__': if fab.docker_pkg_check() is False: print "not install docker package." sys.exit(1) - if fab.go_path_check() is False: - print "can not find path of go" nose.main(argv=sys.argv, addplugins=[OptionParser()], defaultTest=sys.argv[0]) |