diff options
Diffstat (limited to 'test/scenario_test')
-rw-r--r-- | test/scenario_test/constant.py | 73 | ||||
-rw-r--r-- | test/scenario_test/docker_control.py | 566 | ||||
-rw-r--r-- | test/scenario_test/gobgp_test.py | 452 | ||||
-rw-r--r-- | test/scenario_test/peer_info.py | 39 | ||||
-rw-r--r-- | test/scenario_test/quagga-rsconfig.go | 249 | ||||
-rw-r--r-- | test/scenario_test/quagga_access.py | 208 |
6 files changed, 0 insertions, 1587 deletions
diff --git a/test/scenario_test/constant.py b/test/scenario_test/constant.py deleted file mode 100644 index 33572c8d..00000000 --- a/test/scenario_test/constant.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (C) 2015 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. - - -IPv4 = 'ipv4' -IPv6 = 'ipv6' -GOBGP_IP = "10.0.255.1" -GOBGP_CONTAINER_NAME = "gobgp" -GOBGP_ADDRESS_0 = {IPv4: GOBGP_IP, - 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" -CONFIG_DIR = "/tmp/gobgp" -CONFIG_DIRR = "/tmp/gobgp/" -SHARE_VOLUME = "/root/share_volume" -CLI_CMD = "docker exec gobgp /go/bin/gobgp" -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" -INSTALL_FILE = SHARE_VOLUME + "/" + INSTALL_FILE_NAME - -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" - - -ADJ_RIB_IN = "adj-in" -ADJ_RIB_OUT = "adj-out" -LOCAL_RIB = "local" -GLOBAL_RIB = "global rib" -NEIGHBOR = "neighbor" -POLICY = "policy" - -BGP_ATTR_TYPE_AS_PATH= 2 -BGP_ATTR_TYPE_MED = 4 -BGP_ATTR_TYPE_COMMUNITIES = 8 diff --git a/test/scenario_test/docker_control.py b/test/scenario_test/docker_control.py deleted file mode 100644 index 3232f566..00000000 --- a/test/scenario_test/docker_control.py +++ /dev/null @@ -1,566 +0,0 @@ -# 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. - -from fabric.api import local -import re -import os -import time -from constant import * - -def test_user_check(): - root = False - outbuf = local("echo $USER", capture=True) - user = outbuf - if user == "root": - root = True - - return root - - -def install_docker_and_tools(): - print "start install packages of test environment." - if test_user_check() is False: - print "you are not root" - return - - local("apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys " - "36A1D7869245C8950F966E92D8576A8BA88D21E9", capture=True) - local('sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"', - capture=True) - local("apt-get update", capture=True) - local("apt-get install -y --force-yes lxc-docker-1.3.2", capture=True) - local("ln -sf /usr/bin/docker.io /usr/local/bin/docker", capture=True) - local("gpasswd -a `whoami` docker", capture=True) - local("apt-get install -y --force-yes emacs23-nox", capture=True) - local("apt-get install -y --force-yes wireshark", capture=True) - local("apt-get install -y --force-yes iputils-arping", capture=True) - local("apt-get install -y --force-yes bridge-utils", capture=True) - local("apt-get install -y --force-yes tcpdump", capture=True) - local("apt-get install -y --force-yes lv", capture=True) - local("wget https://raw.github.com/jpetazzo/pipework/master/pipework -O /usr/local/bin/pipework", - capture=True) - local("chmod 755 /usr/local/bin/pipework", capture=True) - local("docker pull osrg/quagga", capture=True) - local("docker pull osrg/gobgp", capture=True) - local("docker pull osrg/exabgp", capture=True) - - -def docker_pkg_check(): - docker_exists = False - outbuf = local("dpkg -l | grep docker | awk '{print $2}'", capture=True) - dpkg_list = outbuf.split('\n') - for dpkg in dpkg_list: - if "lxc-docker" in dpkg: - docker_exists = True - return docker_exists - - -def go_path_check(): - go_path_exist = False - outbuf = local("echo `which go`", capture=True) - if "go" in outbuf: - go_path_exist = True - return go_path_exist - - -def docker_container_check(): - container_exists = False - outbuf = local("docker ps -a", capture=True) - docker_ps = outbuf.split('\n') - for container in docker_ps: - container_name = container.split()[-1] - if (container_name == GOBGP_CONTAINER_NAME) or \ - (container_name == EXABGP_CONTAINER_NAME) or ("q" in container_name): - container_exists = True - 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}'" - outbuf = local(cmd, capture=True) - docker_ps = outbuf.split('\n') - for container in docker_ps: - if container != "NAMES": - containers.append(container.split()[-1]) - return containers - - -def docker_container_set_ipaddress(bridge, name, address): - cmd = "pipework " + bridge["BRIDGE_NAME"] + " -i e" + bridge["BRIDGE_NAME"]\ - + " " + name + " " + address - local(cmd, capture=True) - - -def docker_container_run_quagga(quagga_num, bridge): - quagga_name = "q" + str(quagga_num) - cmd = "docker run --privileged=true -v " + CONFIG_DIR + "/" + quagga_name +\ - ":/etc/quagga --name " + quagga_name + " -id osrg/quagga" - local(cmd, capture=True) - 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) - # restart the quagga after the docker container has become IP reachable - cmd = 'docker kill --signal="HUP" ' + quagga_name - local(cmd, capture=True) - - -def docker_container_run_gobgp(bridge, image='osrg/gobgp'): - cmd = "docker run --privileged=true -v " + CONFIG_DIR + ":" + SHARE_VOLUME + " -d --name "\ - + GOBGP_CONTAINER_NAME + " -id " + image - local(cmd, capture=True) - docker_container_set_ipaddress(bridge, GOBGP_CONTAINER_NAME, GOBGP_ADDRESS_0[IP_VERSION] + BASE_MASK[IP_VERSION]) - - -def docker_container_run_exabgp(bridge): - pwd = local("pwd", capture=True) - test_pattern_dir = pwd + "/exabgp_test_conf" - cmd = "cp -r " + test_pattern_dir + " " + CONFIG_DIRR - local(cmd, capture=True) - cmd = "docker run --privileged=true -v " + CONFIG_DIR + ":" + SHARE_VOLUME + " -d --name "\ - + EXABGP_CONTAINER_NAME + " -id osrg/exabgp" - local(cmd, capture=True) - docker_container_set_ipaddress(bridge, EXABGP_CONTAINER_NAME, EXABGP_ADDRESS) - - -def change_owner_to_root(target): - cmd = "chown -R root:root " + target - local(cmd, capture=True) - - -def create_config_dir(): - cmd = "mkdir " + CONFIG_DIR - local(cmd, capture=True) - - -def recreate_conf_dir(dirname): - cmd = "rm -rf " + dirname - local(cmd, capture=True) - cmd = "mkdir " + dirname - local(cmd, capture=True) - - -def make_startup_file(log_opt=""): - file_buff = '#!/bin/bash' + '\n' - file_buff += "cd /go/bin" + '\n' - file_buff += "./gobgpd -f " + SHARE_VOLUME + "/gobgpd.conf " + log_opt + " > " + SHARE_VOLUME + "/gobgpd.log 2>&1 " - - cmd = "echo \"" + file_buff + "\" > " + CONFIG_DIR + "/" + STARTUP_FILE_NAME - local(cmd, capture=True) - cmd = "chmod 755 " + CONFIG_DIRR + STARTUP_FILE_NAME - local(cmd, capture=True) - - -def make_install_file(): - file_buff = '#!/bin/bash' + '\n' - file_buff += 'rm -rf /go/src/github.com/osrg/gobgp' + '\n' - file_buff += 'cp -r ' + SHARE_VOLUME + '/gobgp /go/src/github.com/osrg/' + '\n' - file_buff += 'go get github.com/osrg/gobgp/gobgpd' + '\n' - file_buff += 'go get github.com/osrg/gobgp/gobgp' + '\n' - cmd = "echo \"" + file_buff + "\" > " + CONFIG_DIR + "/" + INSTALL_FILE_NAME - local(cmd, capture=True) - cmd = "chmod 755 " + CONFIG_DIRR + INSTALL_FILE_NAME - local(cmd, capture=True) - - -def docker_container_stop_quagga(quagga): - if docker_check_running(quagga): - cmd = "docker stop " + quagga - local(cmd, capture=True) - - cmd = "docker rm " + quagga - local(cmd, capture=True) - cmd = "rm -rf " + CONFIG_DIRR + quagga - local(cmd, capture=True) - - -def docker_container_stop_gobgp(remove=True): - if docker_check_running(GOBGP_CONTAINER_NAME): - cmd = "docker stop --time=0 " + GOBGP_CONTAINER_NAME - local(cmd, capture=True) - - if remove: - cmd = "docker rm " + GOBGP_CONTAINER_NAME - local(cmd, capture=True) - - -def docker_container_stop_exabgp(): - if docker_check_running(EXABGP_CONTAINER_NAME): - cmd = "docker stop --time=0 " + EXABGP_CONTAINER_NAME - local(cmd, capture=True) - - cmd = "docker rm " + EXABGP_CONTAINER_NAME - local(cmd, capture=True) - - -def docker_containers_destroy(gobgp_remove=True, confdir_remove=True): - containers = docker_containers_get() - for container in containers: - if re.match(r'q[0-9][0-9]*', container) is not None: - docker_container_stop_quagga(container) - if container == GOBGP_CONTAINER_NAME: - docker_container_stop_gobgp(remove=gobgp_remove) - if container == EXABGP_CONTAINER_NAME: - docker_container_stop_exabgp() - bridge_unsetting_for_docker_connection() - if confdir_remove: - cmd = "rm -rf " + CONFIG_DIRR - local(cmd, capture=True) - - -def docker_check_running(cname): - cmd = "docker ps | awk '{print $NF}'" - outbuf = local(cmd, capture=True) - docker_ps = outbuf.split('\n') - if cname in docker_ps: - return True - - -def docker_container_quagga_append(quagga_num, bridge): - print "start append docker container." - docker_container_run_quagga(quagga_num, bridge) - - -def docker_container_quagga_removed(quagga_num): - print "start removed docker container." - quagga = "q" + str(quagga_num) - docker_container_stop_quagga(quagga) - print "complete removed docker container." - - -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) - 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) - - -def bridge_unsetting_for_docker_connection(): - for bridge in BRIDGES: - sysfs_name = "/sys/class/net/" + bridge["BRIDGE_NAME"] - if os.path.exists(sysfs_name): - cmd = "ifconfig " + bridge["BRIDGE_NAME"] + " down" - local(cmd, capture=True) - cmd = "brctl delbr " + bridge["BRIDGE_NAME"] - local(cmd, capture=True) - - -def build_gobgp(): - cmd = "docker exec gobgp " + INSTALL_FILE - local(cmd, capture=True) - - -def start_gobgp(build=False): - if build: - build_gobgp() - cmd = "docker exec -d gobgp " + STARTUP_FILE - local(cmd, capture=True) - - -def start_exabgp(conf_file): - # run exabgp docker container - docker_container_run_exabgp(BRIDGE_0) - - cmd = "docker exec exabgp cp -f " + SHARE_VOLUME + "/exabgp_test_conf/exabgp.env /root/exabgp/etc/exabgp/exabgp.env" - local(cmd, capture=True) - conf_path = EXABGP_CONFDIR + "/" + conf_file - cmd = "docker exec exabgp /root/exabgp/sbin/exabgp " + conf_path + " > /dev/null 2>&1 &" - local(cmd, capture=True) - - -def stop_exabgp(): - docker_container_stop_exabgp() - log_path = CONFIG_DIRR + EXABGP_LOG_FILE - clean_log(log_path) - - -def clean_log(file_path): - cmd = ": > " + file_path - local(cmd, capture=True) - - -def get_notification_from_exabgp_log(): - log_path = CONFIG_DIRR + EXABGP_LOG_FILE - cmd = "grep notification " + log_path + " | head -1" - err_mgs = local(cmd, capture=True) - return err_mgs - - -def make_config(quagga_num, go_path, bridge, peer_opts="", use_compiled=False, ipver=''): - if go_path != "": - print "specified go path is [ " + go_path + " ]." - if os.path.isdir(go_path): - go_path += "/" - else: - print "specified go path do not use." - pwd = local("pwd", capture=True) - - tool = go_path + "go run " + pwd + "/quagga-rsconfig.go " - if use_compiled: - tool = pwd + "/quagga-rsconfig " - - # I want to avoid a global variable. - ip_version = ipver if ipver else IP_VERSION - cmd = tool + " -n " + str(quagga_num) +\ - " -c /tmp/gobgp -v " + ip_version + " -i " + bridge["BRIDGE_NAME"][-1] + " " + peer_opts - local(cmd, capture=True) - - -def update_policy_config(go_path, neighbor, policy_name, target, isReplace=False, defaultReject=False): - if go_path != "": - print "specified go path is [ " + go_path + " ]." - if os.path.isdir(go_path): - go_path += "/" - else: - print "specified go path is not used." - - pwd = local("pwd", capture=True) - replace = ' -r' if isReplace else '' - reject = ' -j' if defaultReject else '' - cmd = pwd + "/policy_generator -d /tmp/gobgp -n " + neighbor + " -t " + target + " -p " + policy_name + replace + reject - local(cmd, capture=True) - # reload_config() - - -def make_config_append(quagga_num, go_path, bridge, peer_opts="", use_compiled=False, ipver=''): - if go_path != "": - print "specified go path is [ " + go_path + " ]." - if os.path.isdir(go_path): - go_path += "/" - else: - print "specified go path do not use." - pwd = local("pwd", capture=True) - ip_version = ipver if ipver else IP_VERSION - - tool = go_path + "go run " + pwd + "/quagga-rsconfig.go " - if use_compiled: - tool = pwd + "/quagga-rsconfig " - - cmd = tool + " -a " + str(quagga_num) +\ - " -c /tmp/gobgp -v " + ip_version + " -i " + bridge["BRIDGE_NAME"][-1] + " " + peer_opts - local(cmd, capture=True) - - -def reload_config(): - cmd = "docker exec gobgp /usr/bin/pkill gobgpd -SIGHUP" - local(cmd, capture=True) - print "gobgp config reloaded." - - -def build_config_tools(go_path): - if go_path != "": - print "specified go path is [ " + go_path + " ]." - if os.path.isdir(go_path): - go_path += "/" - else: - print "the specified go path is not directory.." - - pwd = local("pwd", capture=True) - cmd = go_path + "go build " + pwd + "/quagga-rsconfig.go" - local(cmd, capture=True) - cmd = go_path + "go build " + pwd + "/policy/policy_generator.go" - local(cmd, capture=True) - - -def prepare_gobgp(log_debug, image='osrg/gobgp'): - - # cleanup gobgp container - containers = docker_containers_get() - if GOBGP_CONTAINER_NAME in containers: - docker_container_stop_gobgp(remove=True) - recreate_conf_dir(CONFIG_DIRR) - # set log option - opt = "-l debug" if log_debug else "" - do_build = False - make_startup_file(log_opt=opt) - change_owner_to_root(CONFIG_DIR) - cmd = "docker run --privileged=true -v " + CONFIG_DIR + ":" + SHARE_VOLUME + " -d --name " \ - + GOBGP_CONTAINER_NAME + " -id " + image - local(cmd, capture=True) - if do_build: - build_gobgp() - - -def init_test_env_executor(quagga_num, image, go_path, log_debug=False, is_route_server=True): - 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." - create_config_dir() - bridge_setting_for_docker_connection(BRIDGES) - make_config(quagga_num, go_path, BRIDGE_0, ("" if is_route_server else "--normal-bgp")) - - # run gobgp docker container - docker_container_run_gobgp(BRIDGE_0, image) - - # set log option - opt = "-l debug" if log_debug else "" - do_build = False - # execute local gobgp program in the docker container if the input option is local - make_startup_file(log_opt=opt) - change_owner_to_root(CONFIG_DIR) - start_gobgp(build=do_build) - - # run quagga docker container - for num in range(1, quagga_num + 1): - docker_container_run_quagga(num, BRIDGE_0) - - print "complete initialization of test environment." - - -def init_policy_test_env_executor(quagga_num, use_ipv6=False, use_exabgp=False): - print "start initialization of test environment." - - global IP_VERSION - IP_VERSION = IPv6 if use_ipv6 else IPv4 - - bridge_setting_for_docker_connection(BRIDGES) - - cmd = "docker start %s" % GOBGP_CONTAINER_NAME - local(cmd, capture=True) - docker_container_set_ipaddress(BRIDGE_0, GOBGP_CONTAINER_NAME, GOBGP_ADDRESS_0[IP_VERSION] + BASE_MASK[IP_VERSION]) - - if use_exabgp: - # run exabgp - start_exabgp(EXABGP_COMMON_CONF) - - start_gobgp() - - # run quagga docker container - for num in range(1, quagga_num + 1): - docker_container_run_quagga(num, BRIDGE_0) - - print "complete initialization of test environment." - - -def init_ipv6_test_env_executor(quagga_num, image, go_path, log_debug=False): - 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." - create_config_dir() - bridge_setting_for_docker_connection([BRIDGE_0]) - make_config(quagga_num, go_path, BRIDGE_0) - - # run gobgp docker container - docker_container_run_gobgp(BRIDGE_0, image) - - # set log option - opt = "-l debug" if log_debug else "" - do_build = False - make_startup_file(log_opt=opt) - change_owner_to_root(CONFIG_DIR) - start_gobgp(do_build) - - # run quagga docker container - for num in range(1, quagga_num + 1): - docker_container_run_quagga(num, BRIDGE_0) - - print "complete initialization of test environment." - - -def init_malformed_test_env_executor(image, go_path, exabgp_path, log_debug=False): - print "start initialization of exabgp 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." - peer_opts = "--none-peer" - create_config_dir() - bridge_setting_for_docker_connection(BRIDGES) - make_config(1, go_path, BRIDGE_0) - make_config_append(100, go_path, BRIDGE_0, peer_opts) - - # run gobgp docker container - docker_container_run_gobgp(BRIDGE_0, image) - - # set log option - opt = "-l debug" if log_debug else "" - do_build = False - make_startup_file(log_opt=opt) - change_owner_to_root(CONFIG_DIR) - - if exabgp_path != "": - cmd = "cp -rf %s %s" % (exabgp_path, CONFIG_DIR) - local(cmd, capture=True) - cmd = "docker exec exabgp cp -rf " + SHARE_VOLUME + "/exabgp /root/" - local(cmd, capture=True) - - start_gobgp(do_build) - - # run quagga docker container - docker_container_run_quagga(1, BRIDGE_0) - - -def docker_container_quagga_append_executor(quagga_num, go_path, is_route_server=True): - make_config_append(quagga_num, go_path, BRIDGE_0, ("" if is_route_server else "--normal-bgp")) - 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) - - -def docker_container_make_bestpath_env_executor(append_quagga_num, go_path, is_route_server=True): - print "start make bestpath environment" - make_config_append(append_quagga_num, go_path, BRIDGE_1, ("" if is_route_server else "--normal-bgp")) - 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/gobgp_test.py b/test/scenario_test/gobgp_test.py deleted file mode 100644 index 34a94c7d..00000000 --- a/test/scenario_test/gobgp_test.py +++ /dev/null @@ -1,452 +0,0 @@ -# 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 -from fabric.api import local -import json -import toml -import os -import time -from ciscoconfparse import CiscoConfParse -from peer_info import Peer -from peer_info import Destination -from peer_info import Path -from constant import * -import quagga_access as qaccess - -class GoBGPTestBase(unittest.TestCase): - - gobgp_ip = GOBGP_IP - gobgp_ipv6 = GOBGP_ADDRESS_0[IPv6] - base_dir = CONFIG_DIRR - gobgp_config_file = CONFIG_DIRR + "gobgpd.conf" - gobgp_config = None - initial_wait_time = 10 - wait_per_retry = 5 - retry_limit = (60 - initial_wait_time) / wait_per_retry - dest_check_limit = 3 - - def __init__(self, *args, **kwargs): - super(GoBGPTestBase, self).__init__(*args, **kwargs) - - 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) - state = None - try: - neighbor = self.ask_gobgp(NEIGHBOR, neighbor_address) - state = neighbor['info']['bgp_state'] - remote_ip = neighbor['conf']['remote_ip'] - assert remote_ip == neighbor_address - return state - except Exception as e: - print e - return state - - def retry_routine_for_state(self, addresses, allow_state): - in_prepare_quagga = True - retry_count = 0 - while in_prepare_quagga: - if retry_count != 0: - print "please wait more (" + str(self.wait_per_retry) + " second)" - time.sleep(self.wait_per_retry) - if retry_count >= self.retry_limit: - print "retry limit" - break - retry_count += 1 - success_count = 0 - for address in addresses: - # get neighbor state and remote ip from gobgp connections - state = self.get_neighbor_state(address) - if state == allow_state: - success_count += 1 - if success_count == len(addresses): - in_prepare_quagga = False - - def retry_routine_for_bestpath(self, check_address, target_network, ans_nexthop): - # get rib - if check_address == "": - rib = self.ask_gobgp(GLOBAL_RIB) - else: - rib = self.ask_gobgp(LOCAL_RIB, check_address) - - target_exist = False - for g_dest in rib: - best_path_idx = g_dest['best_path_idx'] if 'best_path_idx' in g_dest else 0 - if target_network == g_dest['prefix']: - target_exist = True - g_paths = g_dest['paths'] - idx = 0 - if len(g_paths) < 2: - print "target path has not been bestpath selected yet." - print "please wait more (" + str(self.wait_per_retry) + " second)" - time.sleep(self.wait_per_retry) - self.retry_routine_for_bestpath(check_address, target_network, ans_nexthop) - return - for g_path in g_paths: - print "best_path_Idx: " + str(best_path_idx) + ", idx: " + str(idx) - print g_dest - print "pre: ", g_dest['prefix'], "net: ", g_path['nlri']['prefix'], "next: ", g_path['nexthop'] - if str(best_path_idx) == str(idx): - rep_nexthop = g_path['nexthop'] - idx += 1 - if target_exist is False: - print "target path has not been receive yet." - print "please wait more (" + str(self.wait_per_retry) + " second)" - time.sleep(self.wait_per_retry) - self.retry_routine_for_bestpath(check_address, target_network, ans_nexthop) - return - self.assertEqual(ans_nexthop, rep_nexthop) - - def extract_bgp_section(self): - with open(self.gobgp_config_file) as f: - dst = '' - for line in f: - if 'DefinedSets' in line: - break - dst += line - - return dst.encode('utf8') - - def load_gobgp_config(self): - try: - t = self.extract_bgp_section() - self.gobgp_config = toml.loads(t) - 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(" ") - network = elems[1] - nexthop = peer_ip - path = Path(network, nexthop) - dest = Destination(network) - dest.paths.append(path) - quagga_config.destinations[network] = 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], 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['Neighbors']['NeighborList'] - for neighbor_config in neighbors_config: - neighbor_ip = neighbor_config['NeighborConfig']['NeighborAddress'] - address.append(neighbor_ip) - 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 - - def ask_gobgp(self, what, who="", af="ipv4"): - af = "-a %s" % af - cmd = "%s -j " % CLI_CMD - if what == GLOBAL_RIB: - cmd += " ".join([what, af]) - elif what == NEIGHBOR: - cmd += " ".join([NEIGHBOR, who]) - else: - cmd += " ".join([NEIGHBOR, who, what, af]) - j = local(cmd, capture=True) - result = json.loads(j) - return result - - def soft_reset(self, neighbor_address, af, type="in"): - cmd = "%s -j " % CLI_CMD - cmd += "neighbor %s " % neighbor_address - cmd += "softreset%s -a %s" % (type, af) - local(cmd) - - def set_policy(self, peer, target, policy_name, default_accept=True): - default_policy = "ACCEPT" if default_accept else "REJECT" - cmd = "%s " % CLI_CMD - cmd += NEIGHBOR + " %s " % peer - cmd += POLICY + " add %s %s %s" % (target, policy_name, default_policy) - local(cmd) - - def get_paths_in_localrib(self, neighbor_address, target_prefix, af="ipv4", retry=3, interval=5): - retry_count = 0 - while True: - 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 - d = g_dest[0] - return d['paths'][0] - else: - retry_count += 1 - if retry_count > retry: - break - else: - print "destination is none : %s" % neighbor_address - print "please wait more (" + str(interval) + " second)" - time.sleep(interval) - - print "destination is none" - return None - - 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, af, retry, interval, type=ADJ_RIB_IN) - - - 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, af, retry, interval, type=ADJ_RIB_OUT) - - - 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, af) - paths = [p for p in rib if p['prefix'] == target_prefix] - - if len(paths) > 0: - assert len(paths) == 1 - assert len(paths[0]['paths']) == 1 - return paths[0]['paths'][0] - else: - retry_count += 1 - if retry_count > retry: - break - else: - print "adj_rib_%s is none" % type - print "wait (" + str(interval) + " seconds)" - time.sleep(interval) - - print "adj_rib_%s is none" % type - return None - - # quagga login check - def try_login_quagga(self, peer, retry=3, interval=1): - print "try login to quagga : %s" % peer - if interval < 0: - interval = self.wait_per_retry - retry_count = 0 - while True: - try: - tn = qaccess.login(peer) - return tn - except: - retry_count += 1 - if retry_count > retry: - break - print "failed to login to %s" % peer - print "wait (" + str(interval) + " seconds)" - time.sleep(interval) - return None - - - # get route information on quagga - 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 - - while True: - tn = qaccess.login(neighbor_address) - q_rib = qaccess.lookup_prefix(tn, target_prefix, af) - qaccess.logout(tn) - for q_path in q_rib: - if target_prefix == q_path['Network']: - return q_path - - retry_count += 1 - if retry_count > retry: - break - else: - print "target_prefix %s is none" % target_prefix - print "wait (" + str(interval) + " seconds)" - time.sleep(interval) - - 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, extended=False): - 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 = False - if extended: - result = qaccess.check_ext_community(tn, target_addr, community, af) - else: - 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 - - - # get route information on quagga - def check_med(self, neighbor_address, target_addr, med, 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_med(tn, target_addr, med, af) - qaccess.logout(tn) - - if result: - return True - else: - print "target path %s with med %s is none" % (target_addr, med) - - 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: - if quagga_config.peer_ip == rib_owner_addr: - # check local_rib doesn't contain own destinations. - for destination in quagga_config.destinations.itervalues(): - for rib_destination in local_rib: - if destination.prefix == rib_destination['prefix']: - return False - - else: - # check local_rib contains destinations that other quaggas - # advertised. - for destination in quagga_config.destinations.itervalues(): - found = False - for rib_destination in local_rib: - if destination.prefix == rib_destination['prefix']: - found = True - break - - if not found: - return False - - return True - - def compare_route_with_quagga_configs(self, address, quagga_rib, route_server=True): - for quagga_config in self.quagga_configs: - for destination in quagga_config.destinations.itervalues(): - for path in destination.paths: - network = path.network.split("/")[0] - - if quagga_config.peer_ip == address: - nexthop = "0.0.0.0" - else: - if route_server: - nexthop = path.nexthop - else: - nexthop = self.gobgp_ip - - found = False - for quagga_path in quagga_rib: - if network == quagga_path['Network'] and nexthop == quagga_path['Next Hop']: - found = True - break - if not found: - return False - - return True - - def compare_global_rib_with_quagga_configs(self, rib): - for quagga_config in self.quagga_configs: - peer_ip = quagga_config.peer_ip - for d in quagga_config.destinations.itervalues(): - for p in d.paths: - print "check of %s's route %s existence in gobgp global rib" % ( - peer_ip, p.network) - exist = False - for dst in rib: - for path in dst['paths']: - if path['nlri']['prefix'] == p.network: - exist = True - if exist: - is_nexthop_same = path['nexthop'] == p.nexthop - if not is_nexthop_same: - return False - if not exist: - return False - return True diff --git a/test/scenario_test/peer_info.py b/test/scenario_test/peer_info.py deleted file mode 100644 index 5a965f7b..00000000 --- a/test/scenario_test/peer_info.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (C) 2015 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. - - -class Peer: - def __init__(self, peer_ip, peer_id, peer_as, ip_version): - 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 diff --git a/test/scenario_test/quagga-rsconfig.go b/test/scenario_test/quagga-rsconfig.go deleted file mode 100644 index 60ae9fd0..00000000 --- a/test/scenario_test/quagga-rsconfig.go +++ /dev/null @@ -1,249 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "github.com/BurntSushi/toml" - "github.com/jessevdk/go-flags" - "github.com/osrg/gobgp/config" - "io/ioutil" - "log" - "net" - "os" - "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.Neighbor - gobgpConfig *config.Global - serverIP net.IP -} - -func NewQuaggaConfig(id int, gConfig *config.Global, myConfig *config.Neighbor, server net.IP) *QuaggaConfig { - return &QuaggaConfig{ - id: id, - config: myConfig, - gobgpConfig: gConfig, - serverIP: server, - } -} - -func (qt *QuaggaConfig) IPv4Config() *bytes.Buffer { - buf := bytes.NewBuffer(nil) - buf.WriteString(fmt.Sprintf("! my address %s\n", qt.config.NeighborConfig.NeighborAddress)) - buf.WriteString(fmt.Sprintf("! my ip_version %s\n", IPv4)) - buf.WriteString("hostname bgpd\n") - buf.WriteString("password zebra\n") - buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.NeighborConfig.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.GlobalConfig.As)) - buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.NeighborConfig.AuthPassword)) - buf.WriteString("debug bgp as4\n") - buf.WriteString("debug bgp fsm\n") - buf.WriteString("debug bgp updates\n") - buf.WriteString("debug bgp events\n") - 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.NeighborConfig.NeighborAddress)) - buf.WriteString(fmt.Sprintf("! my ip_version %s\n", IPv6)) - buf.WriteString("hostname bgpd\n") - buf.WriteString("password zebra\n") - buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.NeighborConfig.PeerAs)) - buf.WriteString(fmt.Sprintf("bgp router-id 192.168.0.%d\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.GlobalConfig.As)) - buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.NeighborConfig.AuthPassword)) - 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.NeighborConfig.NeighborAddress)) - buf.WriteString("debug bgp as4\n") - buf.WriteString("debug bgp fsm\n") - buf.WriteString("debug bgp updates\n") - buf.WriteString("debug bgp events\n") - buf.WriteString("log file /var/log/quagga/bgpd.log\n") - - return buf -} - -func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bool, normalBGP bool) { - quaggaConfigList := make([]*QuaggaConfig, 0) - - gobgpConf := config.Bgp{} - gobgpConf.Global.GlobalConfig.As = 65000 - gobgpConf.Global.GlobalConfig.RouterId = net.ParseIP("192.168.255.1") - - for i := 1; i < nr+1; i++ { - - c := config.Neighbor{} - c.NeighborConfig.PeerAs = 65000 + uint32(i) - c.NeighborConfig.NeighborAddress = net.ParseIP(fmt.Sprintf("%s%d", baseNeighborAddress[IPVersion], i)) - c.NeighborConfig.AuthPassword = fmt.Sprintf("hoge%d", i) - c.Transport.TransportConfig.PassiveMode = true - c.RouteServer.RouteServerConfig.RouteServerClient = !normalBGP - - timers := config.Timers{} - timers.TimersConfig.HoldTime = 30 - timers.TimersConfig.KeepaliveInterval = 10 - timers.TimersConfig.IdleHoldTimeAfterReset = 10 - - c.Timers = timers - c.NeighborConfig.PeerType = config.PEER_TYPE_EXTERNAL - - gobgpConf.Neighbors.NeighborList = append(gobgpConf.Neighbors.NeighborList, c) - if !nonePeer { - q := NewQuaggaConfig(i, &gobgpConf.Global, &c, net.ParseIP(serverAddress[IPVersion])) - quaggaConfigList = append(quaggaConfigList, q) - os.Mkdir(fmt.Sprintf("%s/q%d", outputDir, i), 0755) - 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) - } - } - } - - var buffer bytes.Buffer - encoder := toml.NewEncoder(&buffer) - encoder.Encode(gobgpConf) - - err := ioutil.WriteFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), buffer.Bytes(), 0644) - if err != nil { - log.Fatal(err) - } -} - -func append_config_files(ar int, outputDir string, IPVersion string, noQuagga bool, normalBGP bool) { - - gobgpConf := config.Bgp{} - gobgpConf.Global.GlobalConfig.As = 65000 - gobgpConf.Global.GlobalConfig.RouterId = net.ParseIP("192.168.255.1") - - c := config.Neighbor{} - c.NeighborConfig.PeerAs = 65000 + uint32(ar) - c.NeighborConfig.NeighborAddress = net.ParseIP(fmt.Sprintf("%s%d", baseNeighborAddress[IPVersion], ar)) - c.NeighborConfig.AuthPassword = fmt.Sprintf("hoge%d", ar) - c.RouteServer.RouteServerConfig.RouteServerClient = !normalBGP - c.Transport.TransportConfig.PassiveMode = true - - timers := config.Timers{} - timers.TimersConfig.HoldTime = 30 - timers.TimersConfig.KeepaliveInterval = 10 - timers.TimersConfig.IdleHoldTimeAfterReset = 10 - - c.Timers = timers - c.NeighborConfig.PeerType = config.PEER_TYPE_EXTERNAL - - 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 - 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) - } - } - newConf := config.Bgp{} - _, d_err := toml.DecodeFile(fmt.Sprintf("%s/gobgpd.conf", outputDir), &newConf) - if d_err != nil { - log.Fatal(d_err) - } - newConf.Neighbors.NeighborList = append(newConf.Neighbors.NeighborList, c) - 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.PolicyDefinitions.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) - } -} - -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"` - 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"` - NonePeer bool `long:"none-peer" description:"disable make quagga config"` - NormalBGP bool `long:"normal-bgp" description:"generate normal bgp server configuration"` - } - parser := flags.NewParser(&opts, flags.Default) - _, err := parser.Parse() - if err != nil { - fmt.Print(err) - os.Exit(1) - } - if opts.OutputDir == "" { - opts.OutputDir, _ = filepath.Abs(".") - } else { - if _, err := os.Stat(opts.OutputDir); os.IsNotExist(err) { - os.Mkdir(opts.OutputDir, 0755) - } - } - - 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" - } - - isCreateMode := opts.AppendClient == 0 - - if isCreateMode { - create_config_files(opts.ClientNumber, opts.OutputDir, opts.IPVersion, opts.NonePeer, opts.NormalBGP) - } 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, opts.IPVersion, opts.NonePeer, opts.NormalBGP) - } -} diff --git a/test/scenario_test/quagga_access.py b/test/scenario_test/quagga_access.py deleted file mode 100644 index 51008b02..00000000 --- a/test/scenario_test/quagga_access.py +++ /dev/null @@ -1,208 +0,0 @@ -# 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 sys -import telnetlib -from constant import * - -PASSWORD = "zebra" -CONN_PASSWORD = "hogehoge" -QLPORT = 2605 - - -def login(host): - tn = telnetlib.Telnet(host, QLPORT) - tn.read_until("Password: ") - tn.write(PASSWORD + "\n") - tn.write("enable\n") - tn.read_until("bgpd#") - return tn - - -def logout(tn): - tn.write("exit\n") - tn.read_all() - - -def add_neighbor(tn, as_number, neighbor_address, remote_as): - tn.write("configure terminal\n") - tn.write("router bgp "+str(as_number)+"\n") - tn.write("neighbor " + neighbor_address + " remote-as " + remote_as + "\n") - tn.write("neighbor " + neighbor_address + " password " + CONN_PASSWORD + "\n") - tn.write("exit\n") - tn.write("exit\n") - tn.read_until("bgpd#") - - -def add_neighbor_metric(tn, as_number, neighbor_address, metric): - tn.write("configure terminal\n") - tn.write("router bgp "+str(as_number)+"\n") - tn.write("neighbor " + neighbor_address + " route-map MED" + metric + " out\n") - tn.write("exit\n") - tn.write("exit\n") - tn.read_until("bgpd#") - - -def add_network(tn, as_number, network, use_ipv6=False): - tn.write("configure terminal\n") - tn.write("router bgp "+str(as_number)+"\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#") - - -def add_metric(tn, metric, network): - tn.write("configure terminal\n") - tn.write("access-list 1 permit " + network + " 0.0.0.255\n") - tn.write("route-map MED" + metric + " permit 10\n") - tn.write("match ip address 1\n") - tn.write("set metric " + metric + "\n") - tn.write("route-map MED" + metric + " permit 10\n") - tn.write("set metric\n") - tn.read_until("bgpd(config-route-map)#") - tn.write("exit\n") - tn.write("exit\n") - return tn - - -def show_config(tn): - tn.write("show run\n") - print tn.read_until("bgpd#") - tn.write("exit\n") - print tn.read_all() - - -def show_rib(tn, af=IPv4): - if af == IPv4: - tn.write("show ip bgp\n") - elif af == IPv6: - tn.write("show bgp ipv6\n") - else: - print "invalid af: ", af - return - tn.read_until(" Network Next Hop Metric LocPrf Weight Path") - rib = tn.read_until("bgpd#") - return rib_parser(rib) - - -def clear_ip_bgp(tn): - tn.write("clear ip bgp *\n") - tn.read_until("bgpd#") - - -def rib_parser(rib): - lines = rib.split("\n") - paths = [] - for line in lines: - path = {} - if line[0] == "*": - elems = line.split() - path['Network'] = elems[1] - path['Next Hop'] = elems[2] - if len(path) > 0: - 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#") - lines = info.split("\n") - paths = [] - - if len(lines) > 1 and "BGP routing table entry for " + prefix in lines[1]: - idx_nw = -1 - nexthop = '' - # check if the prefix is originated route by its own or not. - for idx, line in enumerate(lines): - if "from" in line: - nexthop = line.split()[0] - idx_nw = idx - if nexthop == "0.0.0.0": - return paths - - path = {} - path['aspath'] = lines[idx_nw - 1].strip().split(" ") - path['Network'] = prefix - path['Next Hop'] = nexthop - paths.append(path) - - 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 - - -def check_ext_community(tn, addr, community, af=IPv4): - if af == IPv4: - tn.write("show ip bgp " + addr + "\n") - elif af == IPv6: - tn.write("show bgp ipv6 " + addr + "\n") - else: - print "invalid af: ", af - return - result = tn.read_until("bgpd#") - for line in result.split("\n"): - if "Extended Community:" in line: - extcomms = line.split()[2:] - for e in extcomms: - if community == e: - return True - - return False - - -def check_med(tn, addr, med, af=IPv4): - if af == IPv4: - tn.write("show ip bgp " + addr[0] + "\n") - elif af == IPv6: - tn.write("show bgp ipv6 " + addr[0] + "\n") - else: - print "invalid af: ", af - return - result = tn.read_until("bgpd#") - for line in result.split("\n"): - if "metric" in line: - if str(med) in line.split()[3]: - return True - - return False |