blob: 1fb94666fc4b66d0028801e92d8c3d9e7461b015 [file] [log] [blame]
Eric Newberry0af79b62020-04-29 00:55:16 -07001#!/bin/bash
2#
3# Automated integration testing for the Named Data Networking Forwarding Daemon.
4# Part of the Named Data Networking project <https://named-data.net>
5#
6# --
7#
8# Copyright (c) 2014-2020, Regents of the University of California,
9# Arizona Board of Regents,
10# Colorado State University,
11# University Pierre & Marie Curie, Sorbonne University,
12# Washington University in St. Louis,
13# Beijing Institute of Technology,
14# The University of Memphis.
15#
16# This file is part of NFD (Named Data Networking Forwarding Daemon).
17# See AUTHORS.md for complete list of NFD authors and contributors.
18#
19# NFD is free software: you can redistribute it and/or modify it under the terms
20# of the GNU General Public License as published by the Free Software Foundation,
21# either version 3 of the License, or (at your option) any later version.
22#
23# NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
24# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
25# PURPOSE. See the GNU General Public License for more details.
26#
27# You should have received a copy of the GNU General Public License along with
28# NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
29#
30# Author: Eric Newberry <enewberry@cs.ucla.edu>
31
32run_docker() {
33 # Pull docker image if not available
34 echo "Updating docker image..."
35 docker pull ubuntu:18.04
36
37 # Clean up any existing containers, networks, or folders
38 echo "Cleaning any prior runs..."
39 for host in A B C D router template; do
40 docker stop nfd-integ-${host}
41 docker rm nfd-integ-${host}
42 done
43 docker image rm nfd-integ
44 docker network rm nfd-integ-ABC-switch
45 docker network rm nfd-integ-AtoRouter
46 docker network rm nfd-integ-DtoRouter
47
48 # Create and export template
49 echo "Creating template container..."
50 docker run -itd --name nfd-integ-template --mount type=bind,source="$(pwd)",target="/integ" ubuntu:18.04 bash
51 docker exec -it nfd-integ-template /integ/docker_helpers/prepare_template.sh
52 docker commit nfd-integ-template nfd-integ:latest
53 docker stop nfd-integ-template
54 docker rm nfd-integ-template
55
56 # Set up network bridges
57 echo "Setting up networks..."
58 docker network create --ipv6 --subnet 192.168.1.0/24 --subnet fd01::/64 nfd-integ-ABC-switch
59 docker network create --ipv6 --subnet 192.168.2.0/24 --subnet fd02::/64 nfd-integ-AtoRouter
60 docker network create --ipv6 --subnet 192.168.3.0/24 --subnet fd03::/64 nfd-integ-DtoRouter
61
62 # Start containers
63 echo "Starting containers..."
64 for host in A B C D; do
65 docker run -itd --privileged --name nfd-integ-${host} --mount type=bind,source="$(pwd)",target="/integ" nfd-integ bash
66 done
67 docker run -itd --privileged --name nfd-integ-router --mount type=bind,source="$(pwd)",target="/integ" ubuntu:18.04 bash
68
69 # Connect containers to networks
70 echo "Connecting containers to networks..."
71 docker network connect nfd-integ-ABC-switch nfd-integ-A --ip 192.168.1.3 --ip6 fd01::3
72 docker network connect nfd-integ-AtoRouter nfd-integ-A --ip 192.168.2.2 --ip6 fd02::2
73 docker network connect nfd-integ-ABC-switch nfd-integ-B --ip 192.168.1.2 --ip6 fd01::2
74 docker network connect nfd-integ-ABC-switch nfd-integ-C --ip 192.168.1.4 --ip6 fd01::4
75 docker network connect nfd-integ-DtoRouter nfd-integ-D --ip 192.168.3.3 --ip6 fd03::3
76 docker network connect nfd-integ-AtoRouter nfd-integ-router --ip 192.168.2.3 --ip6 fd02::3
77 docker network connect nfd-integ-DtoRouter nfd-integ-router --ip 192.168.3.2 --ip6 fd03::2
78
79 # Start SSH
80 echo "Starting SSH..."
81 for host in A B C D; do
82 docker exec -it nfd-integ-${host} service ssh start
83 done
84
85 # Set up specific nodes
86 echo "Performing container-specific configuration steps..."
87 docker exec -it nfd-integ-A /integ/docker_helpers/setup_A.sh
88 docker exec -it nfd-integ-D /integ/docker_helpers/setup_D.sh
89 docker exec -it nfd-integ-router /integ/docker_helpers/setup_router.sh
90
91 # Run tests
92 echo "Running tests..."
93 docker exec -it nfd-integ-A sudo -i -u integ /integ/docker_helpers/run_tests.sh
94
95 # Collect logs
96 echo "Collecting logs..."
97 for host in A B C D; do
98 docker exec -it nfd-integ-${host} sudo -i -u integ /integ/collect-logs.sh docker ${host}
99 done
100
101 # Stop and remove containers
102 echo "Stopping containers..."
103 for host in A B C D router; do
104 docker stop nfd-integ-${host}
105 docker rm nfd-integ-${host}
106 done
107
108 # Clean up
109 echo "Cleaning up..."
110 docker image rm nfd-integ
111 docker network rm nfd-integ-ABC-switch
112 docker network rm nfd-integ-AtoRouter
113 docker network rm nfd-integ-DtoRouter
114}
115
116run_vbox() {
117 vagrant up template
118 vagrant ssh template -c "sudo apt-get clean"
119 vagrant package --output nfd-integ.box template
120 vagrant box remove nfd-integ
121 vagrant box add --name nfd-integ nfd-integ.box
122
123 vagrant up router A B C D
124
125 vagrant ssh A -c "cd integration-tests && ./run_tests.py test_all 2>&1 | tee run.log"
126 for host in A B C D; do
127 vagrant ssh ${host} -c "integration-tests/collect-logs.sh vbox ${host}"
128 done
129
130 vagrant destroy -f
131
132 vagrant box remove nfd-integ
133 rm -f nfd-integ.box
134}
135
136case ${1} in
137 docker|vbox)
138 ;;
139 *)
140 echo "Usage: ${0} docker|vbox"
141 exit 1
142 ;;
143esac
144
145# Perform steps common to both environments
146rm -rf logs prepare temp
147mkdir -p logs/{A,B,C,D} temp
148ssh-keygen -t ecdsa -f temp/sshkey -q -N ""
149
150# Setup and run using environment-specific steps
151run_${1}
152
153# Clean up
154rm -rf prepare temp