Vagrant provisioning and script to run integration tests

refs #2436

Change-Id: I43b2fc77a9f79df1512a180df0c0051a2797eac0
diff --git a/.gitignore b/.gitignore
index d1ba9e9..c97141c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
 *.pyc
 */logs
 test_interest_loop/keys
+logs
+temp
diff --git a/Vagrantfile b/Vagrantfile
new file mode 100644
index 0000000..3edc96b
--- /dev/null
+++ b/Vagrantfile
@@ -0,0 +1,102 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
+VAGRANTFILE_API_VERSION = "2"
+
+$setup = <<SCRIPT
+sudo apt-get update -qq
+sudo apt-get install -y python
+SCRIPT
+
+$setup_integ = <<SCRIPT
+cp -R /vagrant integration-tests
+cd integration-tests && ./install_apps.py install_all 2>&1 | tee install.log
+SCRIPT
+
+$setup_ssh = <<SCRIPT
+mkdir -p ~/.ssh
+cp /vagrant/temp/sshkey ~/.ssh/id_rsa
+cp /vagrant/temp/sshkey.pub ~/.ssh/id_rsa.pub
+cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
+chown -R vagrant:vagrant ~/.ssh
+chmod -R 700 ~/.ssh
+SCRIPT
+
+$setup_a = <<SCRIPT
+cat > ~/.ssh/config <<EOF
+Host 192.168.*.*
+    StrictHostKeyChecking no
+EOF
+
+sudo ip route add 192.168.3.0/24 via 192.168.2.3
+sudo ip -6 addr add fd01::3/64 dev eth1
+sudo ip -6 addr add fd02::2/64 dev eth2
+sudo ip -6 route add fd03::/64 via fd02::3
+SCRIPT
+
+$setup_d = <<SCRIPT
+ip route add 192.168.2.0/24 via 192.168.3.2
+ip -6 addr add fd03::3/64 dev eth1
+ip -6 route add fd02::/64 via fd03::2
+SCRIPT
+
+$setup_router = <<SCRIPT
+echo 1 > /proc/sys/net/ipv4/ip_forward
+echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
+ip -6 addr add fd02::3/64 dev eth1
+ip -6 addr add fd03::2/64 dev eth2
+SCRIPT
+
+Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
+  config.vm.box = "ubuntu/precise64"
+
+  config.vm.provider "virtualbox" do |vb|
+    vb.memory = "4096"
+    vb.cpus = "4"
+    vb.customize ["storagectl", :id, "--name", "SATAController", "--hostiocache", "off"]
+  end
+
+  config.vm.define "A" do |a|
+    a.vm.network "private_network", ip: "192.168.1.3", virtualbox__intnet: "ABC-switch"
+    a.vm.network "private_network", ip: "192.168.2.2", virtualbox__intnet: "AtoRouter"
+    a.vm.provision "shell", inline: $setup, privileged: false
+    a.vm.provision "shell", inline: $setup_a, privileged: false
+    a.vm.provision "shell", inline: $setup_ssh, privileged: false
+    a.vm.provision "shell", inline: $setup_integ, privileged: false
+  end
+
+  config.vm.define "B" do |b|
+    b.vm.network "private_network", ip: "192.168.1.2", virtualbox__intnet: "ABC-switch"
+    b.vm.provision "shell", inline: $setup, privileged: false
+    b.vm.provision "shell", inline: "ip -6 addr add fd01::2/64 dev eth1"
+    b.vm.provision "shell", inline: $setup_ssh, privileged: false
+    b.vm.provision "shell", inline: $setup_integ, privileged: false
+  end
+
+  config.vm.define "C" do |c|
+    c.vm.network "private_network", ip: "192.168.1.4", virtualbox__intnet: "ABC-switch"
+    c.vm.provision "shell", inline: $setup, privileged: false
+    c.vm.provision "shell", inline: "ip -6 addr add fd01::4/64 dev eth1"
+    c.vm.provision "shell", inline: $setup_ssh, privileged: false
+    c.vm.provision "shell", inline: $setup_integ, privileged: false
+  end
+
+  config.vm.define "D" do |d|
+    d.vm.network "private_network", ip: "192.168.3.3", virtualbox__intnet: "DtoRouter"
+    d.vm.provision "shell", inline: $setup, privileged: false
+    d.vm.provision "shell", inline: $setup_d
+    d.vm.provision "shell", inline: $setup_ssh, privileged: false
+    d.vm.provision "shell", inline: $setup_integ, privileged: false
+  end
+
+  config.vm.define "router" do |router|
+    router.vm.network "private_network", ip: "192.168.2.3", virtualbox__intnet: "AtoRouter"
+    router.vm.network "private_network", ip: "192.168.3.2", virtualbox__intnet: "DtoRouter"
+    router.vm.provision "shell", inline: $setup_router
+    router.vm.provider "virtualbox" do |vb|
+      vb.memory = "128"
+      vb.cpus = "1"
+    end
+  end
+end
diff --git a/collect-logs.sh b/collect-logs.sh
new file mode 100755
index 0000000..e594479
--- /dev/null
+++ b/collect-logs.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+cd integration-tests
+tar cf - --ignore-failed-read --exclude='.vagrant*' $(git status -s -uall --porcelain --ignored | awk '$1!="D" && $2!~"\.pyc$"{print $2}') | tar xf - -C /vagrant/logs/$1
diff --git a/multi-host.conf b/multi-host.conf
index 0991872..8a06cd1 100644
--- a/multi-host.conf
+++ b/multi-host.conf
@@ -11,22 +11,21 @@
 # IPv4: /24
 # IPv6: /64
 #
-CTRL_B=b.integ.ndn-routing.emulab.net
-CTRL_C=c.integ.ndn-routing.emulab.net
-CTRL_D=d.integ.ndn-routing.emulab.net
-CTRL_R=r.integ.ndn-routing.emulab.net
-IP4_A1=10.0.0.2
-IP4_B1=10.0.0.1
-IP4_C1=10.0.0.3
-IP4_A2=10.1.0.1
-IP4_R1=10.1.0.2
-IP4_R2=10.2.0.1
-IP4_D1=10.2.0.2
-IP6_A1=fd8c:edca:0f3c:10f4::2
-IP6_B1=fd8c:edca:0f3c:10f4::1
-IP6_C1=fd8c:edca:0f3c:10f4::3
-IP6_A2=fd8c:edca:0f3c:10f5::9
-IP6_R1=fd8c:edca:0f3c:10f5::a
-IP6_R2=fd8c:edca:0f3c:10f6::11
-IP6_D1=fd8c:edca:0f3c:10f6::12
-
+CTRL_B=192.168.1.2
+CTRL_C=192.168.1.4
+CTRL_D=192.168.3.3
+CTRL_R=192.168.2.3
+IP4_A1=192.168.1.3
+IP4_B1=192.168.1.2
+IP4_C1=192.168.1.4
+IP4_A2=192.168.2.2
+IP4_R1=192.168.2.3
+IP4_R2=192.168.3.2
+IP4_D1=192.168.3.3
+IP6_A1=fd01::3
+IP6_B1=fd01::2
+IP6_C1=fd01::4
+IP6_A2=fd02::2
+IP6_R1=fd02::3
+IP6_R2=fd03::2
+IP6_D1=fd03::3
diff --git a/run-vagrant-tests.sh b/run-vagrant-tests.sh
new file mode 100755
index 0000000..7a03e1e
--- /dev/null
+++ b/run-vagrant-tests.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+# Automated integration testing for the Named Data Networking Forwarding Daemon.
+# Part of the Named Data Networking project <http://named-data.net>
+#
+# --
+#
+# Copyright (c) 2014-2015,  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@email.arizona.edu>
+
+mkdir -p logs/A logs/B logs/C logs/D
+mkdir -p temp
+ssh-keygen -b 2048 -t rsa -f temp/sshkey -q -N ""
+
+vagrant up
+
+vagrant ssh A -c "cd integration-tests && ./run_tests.py test_all 2>&1 | tee run.log"
+vagrant ssh A -c "integration-tests/collect-logs.sh A"
+vagrant ssh B -c "integration-tests/collect-logs.sh B"
+vagrant ssh C -c "integration-tests/collect-logs.sh C"
+vagrant ssh D -c "integration-tests/collect-logs.sh D"
+
+vagrant destroy -f
+
+rm -Rf temp