| #!/bin/bash |
| # |
| # Automated integration testing for the Named Data Networking Forwarding Daemon. |
| # Part of the Named Data Networking project <https://named-data.net> |
| # |
| # -- |
| # |
| # Copyright (c) 2014-2020, Regents of the University of California, |
| # Arizona Board of Regents, |
| # Colorado State University, |
| # University Pierre & Marie Curie, Sorbonne University, |
| # Washington University in St. Louis, |
| # Beijing Institute of Technology, |
| # The University of Memphis. |
| # |
| # This file is part of NFD (Named Data Networking Forwarding Daemon). |
| # See AUTHORS.md for complete list of NFD authors and contributors. |
| # |
| # NFD is free software: you can redistribute it and/or modify it under the terms |
| # of the GNU General Public License as published by the Free Software Foundation, |
| # either version 3 of the License, or (at your option) any later version. |
| # |
| # NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| # PURPOSE. See the GNU General Public License for more details. |
| # |
| # You should have received a copy of the GNU General Public License along with |
| # NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| # |
| # Author: Eric Newberry <enewberry@cs.ucla.edu> |
| |
| run_docker() { |
| # Pull docker image if not available |
| echo "Updating docker image..." |
| docker pull ubuntu:18.04 |
| |
| # Clean up any existing containers, networks, or folders |
| echo "Cleaning any prior runs..." |
| for host in A B C D router template; do |
| docker stop nfd-integ-${host} |
| docker rm nfd-integ-${host} |
| done |
| docker image rm nfd-integ |
| docker network rm nfd-integ-ABC-switch |
| docker network rm nfd-integ-AtoRouter |
| docker network rm nfd-integ-DtoRouter |
| |
| # Create and export template |
| echo "Creating template container..." |
| docker run -itd --name nfd-integ-template --mount type=bind,source="$(pwd)",target="/integ" ubuntu:18.04 bash |
| docker exec -it nfd-integ-template /integ/docker_helpers/prepare_template.sh |
| docker commit nfd-integ-template nfd-integ:latest |
| docker stop nfd-integ-template |
| docker rm nfd-integ-template |
| |
| # Set up network bridges |
| echo "Setting up networks..." |
| docker network create --ipv6 --subnet 192.168.1.0/24 --subnet fd01::/64 nfd-integ-ABC-switch |
| docker network create --ipv6 --subnet 192.168.2.0/24 --subnet fd02::/64 nfd-integ-AtoRouter |
| docker network create --ipv6 --subnet 192.168.3.0/24 --subnet fd03::/64 nfd-integ-DtoRouter |
| |
| # Start containers |
| echo "Starting containers..." |
| for host in A B C D; do |
| docker run -itd --privileged --name nfd-integ-${host} --mount type=bind,source="$(pwd)",target="/integ" nfd-integ bash |
| done |
| docker run -itd --privileged --name nfd-integ-router --mount type=bind,source="$(pwd)",target="/integ" ubuntu:18.04 bash |
| |
| # Connect containers to networks |
| echo "Connecting containers to networks..." |
| docker network connect nfd-integ-ABC-switch nfd-integ-A --ip 192.168.1.3 --ip6 fd01::3 |
| docker network connect nfd-integ-AtoRouter nfd-integ-A --ip 192.168.2.2 --ip6 fd02::2 |
| docker network connect nfd-integ-ABC-switch nfd-integ-B --ip 192.168.1.2 --ip6 fd01::2 |
| docker network connect nfd-integ-ABC-switch nfd-integ-C --ip 192.168.1.4 --ip6 fd01::4 |
| docker network connect nfd-integ-DtoRouter nfd-integ-D --ip 192.168.3.3 --ip6 fd03::3 |
| docker network connect nfd-integ-AtoRouter nfd-integ-router --ip 192.168.2.3 --ip6 fd02::3 |
| docker network connect nfd-integ-DtoRouter nfd-integ-router --ip 192.168.3.2 --ip6 fd03::2 |
| |
| # Start SSH |
| echo "Starting SSH..." |
| for host in A B C D; do |
| docker exec -it nfd-integ-${host} service ssh start |
| done |
| |
| # Set up specific nodes |
| echo "Performing container-specific configuration steps..." |
| docker exec -it nfd-integ-A /integ/docker_helpers/setup_A.sh |
| docker exec -it nfd-integ-D /integ/docker_helpers/setup_D.sh |
| docker exec -it nfd-integ-router /integ/docker_helpers/setup_router.sh |
| |
| # Run tests |
| echo "Running tests..." |
| docker exec -it nfd-integ-A sudo -i -u integ /integ/docker_helpers/run_tests.sh |
| |
| # Collect logs |
| echo "Collecting logs..." |
| for host in A B C D; do |
| docker exec -it nfd-integ-${host} sudo -i -u integ /integ/collect-logs.sh docker ${host} |
| done |
| |
| # Stop and remove containers |
| echo "Stopping containers..." |
| for host in A B C D router; do |
| docker stop nfd-integ-${host} |
| docker rm nfd-integ-${host} |
| done |
| |
| # Clean up |
| echo "Cleaning up..." |
| docker image rm nfd-integ |
| docker network rm nfd-integ-ABC-switch |
| docker network rm nfd-integ-AtoRouter |
| docker network rm nfd-integ-DtoRouter |
| } |
| |
| run_vbox() { |
| vagrant up template |
| vagrant ssh template -c "sudo apt-get clean" |
| vagrant package --output nfd-integ.box template |
| vagrant box remove nfd-integ |
| vagrant box add --name nfd-integ nfd-integ.box |
| |
| vagrant up router A B C D |
| |
| vagrant ssh A -c "cd integration-tests && ./run_tests.py test_all 2>&1 | tee run.log" |
| for host in A B C D; do |
| vagrant ssh ${host} -c "integration-tests/collect-logs.sh vbox ${host}" |
| done |
| |
| vagrant destroy -f |
| |
| vagrant box remove nfd-integ |
| rm -f nfd-integ.box |
| } |
| |
| case ${1} in |
| docker|vbox) |
| ;; |
| *) |
| echo "Usage: ${0} docker|vbox" |
| exit 1 |
| ;; |
| esac |
| |
| # Perform steps common to both environments |
| rm -rf logs prepare temp |
| mkdir -p logs/{A,B,C,D} temp |
| ssh-keygen -t ecdsa -f temp/sshkey -q -N "" |
| |
| # Setup and run using environment-specific steps |
| run_${1} |
| |
| # Clean up |
| rm -rf prepare temp |