diff options
author | Damjan Marion <damarion@cisco.com> | 2017-04-20 11:43:56 +0200 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2017-04-20 12:57:33 +0000 |
commit | 48009e4c5732180ecc951ac6359b9b96d38b8dc2 (patch) | |
tree | d370b842a5be1eb47c4aed5fcae76a659eaa9224 /extras/vagrant | |
parent | 686c1c8454803e48d45428a720f129f24dc981f7 (diff) |
Move vagrant stuff to extras/
Change-Id: I7e3d6ecc3f23d862004c273e23e36e234ceb6015
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'extras/vagrant')
-rw-r--r-- | extras/vagrant/.gitignore | 1 | ||||
-rw-r--r-- | extras/vagrant/README | 28 | ||||
-rw-r--r-- | extras/vagrant/Vagrantfile | 113 | ||||
-rw-r--r-- | extras/vagrant/WELCOME | 61 | ||||
-rwxr-xr-x | extras/vagrant/build.sh | 74 | ||||
-rwxr-xr-x | extras/vagrant/clearinterfaces.sh | 17 | ||||
-rw-r--r-- | extras/vagrant/env.sh | 6 | ||||
-rw-r--r-- | extras/vagrant/install.sh | 30 | ||||
-rwxr-xr-x | extras/vagrant/run.sh | 23 | ||||
-rwxr-xr-x | extras/vagrant/update.sh | 48 |
10 files changed, 401 insertions, 0 deletions
diff --git a/extras/vagrant/.gitignore b/extras/vagrant/.gitignore new file mode 100644 index 00000000..a977916f --- /dev/null +++ b/extras/vagrant/.gitignore @@ -0,0 +1 @@ +.vagrant/ diff --git a/extras/vagrant/README b/extras/vagrant/README new file mode 100644 index 00000000..238c90ce --- /dev/null +++ b/extras/vagrant/README @@ -0,0 +1,28 @@ +INTRO: + +This is a vagrant environment for VPP. + +VPP currently works under Linux and has support for: + +- Ubuntu 14.04, Ubuntu 16.04 and Centos7.2 + +The VM builds VPP from source which can be located at /vpp + +VM PARTICULARS: +This vagrant environment creates a VM based on environment variables found in ./env.sh +To use, edit env.sh then + source ./env.sh + vagrant up + +By default, the VM created is/has: +- Ubuntu 14.04 +- 2 vCPUs +- 4G of RAM +- 2 NICs (1 x NAT - host access, 1 x VPP DPDK enabled) + +PROVIDERS: + +Supported vagrant providers are: + +- Virtualbox, VMware Fusion/Workstation, Libvirt + diff --git a/extras/vagrant/Vagrantfile b/extras/vagrant/Vagrantfile new file mode 100644 index 00000000..b463d646 --- /dev/null +++ b/extras/vagrant/Vagrantfile @@ -0,0 +1,113 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + + # Pick the right distro and bootstrap, default is ubuntu1604 + distro = ( ENV['VPP_VAGRANT_DISTRO'] || "ubuntu1604") + if distro == 'centos7' + config.vm.box = "puppetlabs/centos-7.2-64-nocm" + config.ssh.insert_key = false + elsif distro == 'ubuntu1404' + config.vm.box = "puppetlabs/ubuntu-14.04-64-nocm" + else + config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm" + end + config.vm.box_check_update = false + + config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"update.sh") + config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"build.sh"), :args => "/vpp vagrant" + + post_build = ( ENV['VPP_VAGRANT_POST_BUILD'] ) + if post_build == "test" + config.vm.provision "shell", inline: "echo Testing VPP; cd /vpp; make test" + elsif post_build == "install" + config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"install.sh"), :args => "/vpp" + config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"clearinterfaces.sh") + config.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"run.sh") + end + + # Add .gnupg dir in so folks can sign patches + # Note, as gnupg puts socket files in that dir, we have + # to be cautious and make sure we are dealing with a plain file + homedir = File.expand_path("~/") + Dir["#{homedir}/.gnupg/**/*"].each do |fname| + if File.file?(fname) + destname = fname.sub(Regexp.escape("#{homedir}/"),'') + config.vm.provision "file", source: fname, destination: destname + end + end + + # Copy in the .gitconfig if it exists + if File.file?(File.expand_path("~/.gitconfig")) + config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig" + end + + # vagrant-cachier caches apt/yum etc to speed subsequent + # vagrant up + # to enable, run + # vagrant plugin install vagrant-cachier + # + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :box + end + + # Define some physical ports for your VMs to be used by DPDK + nics = (ENV['VPP_VAGRANT_NICS'] || "2").to_i(10) + for i in 1..nics + config.vm.network "private_network", type: "dhcp" + end + + # use http proxy if avaiable + if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf") + config.proxy.http = ENV['http_proxy'] + config.proxy.https = ENV['https_proxy'] + config.proxy.no_proxy = "localhost,127.0.0.1" + end + + vmcpu=(ENV['VPP_VAGRANT_VMCPU'] || 2) + vmram=(ENV['VPP_VAGRANT_VMRAM'] || 4096) + + config.ssh.forward_agent = true + config.ssh.forward_x11 = true + + config.vm.provider "virtualbox" do |vb| + vb.customize ["modifyvm", :id, "--ioapic", "on"] + vb.memory = "#{vmram}" + vb.cpus = "#{vmcpu}" + + # rsync the vpp directory if provision hasn't happened yet + unless File.exist? (".vagrant/machines/default/virtualbox/action_provision") + config.vm.synced_folder "../../", "/vpp", type: "rsync", + rsync__auto: false, + rsync__exclude: [ + "build-root/build*/", + "build-root/install*/", + "build-root/images*/", + "build-root/*.deb", + "build-root/*.rpm", + "build-root/*.changes", + "build-root/python", + "build-root/deb/debian/*.dkms", + "build-root/deb/debian/*.install", + "build-root/deb/debian/changes", + "build-root/tools"] + end + + #support for the SSE4.x instruction is required in some versions of VB. + vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"] + vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"] + end + config.vm.provider "vmware_fusion" do |fusion,override| + fusion.vmx["memsize"] = "#{vmram}" + fusion.vmx["numvcpus"] = "#{vmcpu}" + end + config.vm.provider "libvirt" do |lv| + lv.memory = "#{vmram}" + lv.cpus = "#{vmcpu}" + end + config.vm.provider "vmware_workstation" do |vws,override| + vws.vmx["memsize"] = "#{vmram}" + vws.vmx["numvcpus"] = "#{vmcpu}" + end +end diff --git a/extras/vagrant/WELCOME b/extras/vagrant/WELCOME new file mode 100644 index 00000000..eb6aa2fd --- /dev/null +++ b/extras/vagrant/WELCOME @@ -0,0 +1,61 @@ +VPP has now been built, installed, and started. + +To give it a spin, we can create a tap interface and try a simple ping +(with trace). + +Make sure you have run: + +$ vagrant ssh + +To get to the vagrant VM: + +vagrant@localhost:~$ + +Confirm that vpp is running with + +vagrant@localhost:~$ sudo status vpp +vpp start/running, process 25202 + +To create the tap: + +vagrant@localhost:~$ sudo vppctl tap connect foobar +Created tap-0 for Linux tap 'foobar' +vagrant@localhost:~$ sudo vppctl show int + +To assign it an ip address (and 'up' the interface): + +vagrant@localhost:~$ sudo vppctl set int ip address tap-0 192.168.1.1/24 +vagrant@localhost:~$ sudo vppctl set int state tap-0 up + +To turn on packet tracing for the tap interface: +vagrant@localhost:~$ sudo vppctl trace add tapcli-rx 10 + +Now, to set up and try the other end: +vagrant@localhost:~$ sudo ip addr add 192.168.1.2/24 dev foobar +vagrant@localhost:~$ ping -c 3 192.168.1.1 + +To look at the trace: +vagrant@localhost:~$ sudo vppctl show trace + +And to stop tracing: + +vagrant@localhost:~$ sudo vppctl clear trace + +Other fun things to look at: + +The vlib packet processing graph: +vagrant@localhost:~$ sudo vppctl show vlib graph + +which will produce output like: + + Name Next Previous +ip4-icmp-input error-punt [0] ip4-local + ip4-icmp-echo-request [1] + vpe-icmp4-oam [2] + +To read this, the first column (Name) is the name of the node. +The second column (Next) is the name of the children of that node. +The third column (Previous) is the name of the parents of this node. + +To see this README again: +cat /vagrant/README diff --git a/extras/vagrant/build.sh b/extras/vagrant/build.sh new file mode 100755 index 00000000..76838e28 --- /dev/null +++ b/extras/vagrant/build.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# Get Command Line arguements if present +VPP_DIR=$1 +if [ "x$1" != "x" ]; then + VPP_DIR=$1 +else + VPP_DIR=`dirname $0`/../../ +fi + +if [ "x$2" != "x" ]; then + SUDOCMD="sudo -H -u $2" +fi +echo 0:$0 +echo 1:$1 +echo 2:$2 +echo VPP_DIR: $VPP_DIR +echo SUDOCMD: $SUDOCMD + +# Figure out what system we are running on +if [ -f /etc/lsb-release ];then + . /etc/lsb-release +elif [ -f /etc/redhat-release ];then + sudo yum install -y redhat-lsb + DISTRIB_ID=`lsb_release -si` + DISTRIB_RELEASE=`lsb_release -sr` + DISTRIB_CODENAME=`lsb_release -sc` + DISTRIB_DESCRIPTION=`lsb_release -sd` +fi +KERNEL_OS=`uname -o` +KERNEL_MACHINE=`uname -m` +KERNEL_RELEASE=`uname -r` +KERNEL_VERSION=`uname -v` + +echo KERNEL_OS: $KERNEL_OS +echo KERNEL_MACHINE: $KERNEL_MACHINE +echo KERNEL_RELEASE: $KERNEL_RELEASE +echo KERNEL_VERSION: $KERNEL_VERSION +echo DISTRIB_ID: $DISTRIB_ID +echo DISTRIB_RELEASE: $DISTRIB_RELEASE +echo DISTRIB_CODENAME: $DISTRIB_CODENAME +echo DISTRIB_DESCRIPTION: $DISTRIB_DESCRIPTION + +# Install dependencies +cd $VPP_DIR +make UNATTENDED=yes install-dep + +# Really really clean things up so we can be sure +# that the build works even when switching distros +$SUDOCMD make wipe +(cd build-root/;$SUDOCMD make distclean) +rm -f build-root/.bootstrap.ok + +if [ $DISTRIB_ID == "CentOS" ]; then + echo rpm -V apr-devel + rpm -V apr-devel + if [ $? != 0 ]; then sudo yum reinstall -y apr-devel;fi + echo rpm -V ganglia-devel + rpm -V ganglia-devel + if [ $? != 0 ]; then sudo yum reinstall -y ganglia-devel;fi + echo rpm -V libconfuse-devel + rpm -V libconfuse-devel + if [ $? != 0 ]; then sudo yum reinstall -y libconfuse-devel;fi +fi + +# Build and install packaging +$SUDOCMD make bootstrap +if [ $DISTRIB_ID == "Ubuntu" ]; then + $SUDOCMD make pkg-deb +elif [ $DISTRIB_ID == "CentOS" ]; then + (cd $VPP_DIR/vnet ;$SUDOCMD aclocal;$SUDOCMD automake -a) + $SUDOCMD make pkg-rpm +fi + diff --git a/extras/vagrant/clearinterfaces.sh b/extras/vagrant/clearinterfaces.sh new file mode 100755 index 00000000..78f6705c --- /dev/null +++ b/extras/vagrant/clearinterfaces.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Capture all the interface IPs, in case we need them later +ip -o addr show > ~vagrant/ifconfiga +chown vagrant:vagrant ~vagrant/ifconfiga + +# Disable all ethernet interfaces other than the default route +# interface so VPP will use those interfaces. The VPP auto-blacklist +# algorithm prevents the use of any physical interface contained in the +# routing table (i.e. "route --inet --inet6") preventing the theft of +# the management ethernet interface by VPP from the kernel. +for intf in $(ls /sys/class/net) ; do + if [ -d /sys/class/net/$intf/device ] && + [ "$(route --inet --inet6 | grep default | grep $intf)" == "" ] ; then + ifconfig $intf down + fi +done diff --git a/extras/vagrant/env.sh b/extras/vagrant/env.sh new file mode 100644 index 00000000..f0edfd88 --- /dev/null +++ b/extras/vagrant/env.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +export VPP_VAGRANT_DISTRO="ubuntu1404" +export VPP_VAGRANT_NICS=2 +export VPP_VAGRANT_VMCPU=4 +export VPP_VAGRANT_VMRAM=4096 diff --git a/extras/vagrant/install.sh b/extras/vagrant/install.sh new file mode 100644 index 00000000..a53faa4d --- /dev/null +++ b/extras/vagrant/install.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Get Command Line arguements if present +VPP_DIR=$1 +if [ "x$1" != "x" ]; then + VPP_DIR=$1 +else + VPP_DIR=`dirname $0`/../../ +fi + +# Figure out what system we are running on +if [ -f /etc/lsb-release ];then + . /etc/lsb-release +elif [ -f /etc/redhat-release ];then + sudo yum install -y redhat-lsb + DISTRIB_ID=`lsb_release -si` + DISTRIB_RELEASE=`lsb_release -sr` + DISTRIB_CODENAME=`lsb_release -sc` + DISTRIB_DESCRIPTION=`lsb_release -sd` +fi +echo DISTRIB_ID: $DISTRIB_ID +echo DISTRIB_RELEASE: $DISTRIB_RELEASE +echo DISTRIB_CODENAME: $DISTRIB_CODENAME +echo DISTRIB_DESCRIPTION: $DISTRIB_DESCRIPTION + +if [ $DISTRIB_ID == "Ubuntu" ]; then + (cd ${VPP_DIR}/build-root/;sudo dpkg -i *.deb) +elif [ $DISTRIB_ID == "CentOS" ]; then + (cd ${VPP_DIR}/build-root/;sudo rpm -Uvh *.rpm) +fi
\ No newline at end of file diff --git a/extras/vagrant/run.sh b/extras/vagrant/run.sh new file mode 100755 index 00000000..1cd33826 --- /dev/null +++ b/extras/vagrant/run.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Figure out what system we are running on +if [ -f /etc/lsb-release ];then + . /etc/lsb-release +elif [ -f /etc/redhat-release ];then + yum install -y redhat-lsb + DISTRIB_ID=`lsb_release -si` + DISTRIB_RELEASE=`lsb_release -sr` + DISTRIB_CODENAME=`lsb_release -sc` + DISTRIB_DESCRIPTION=`lsb_release -sd` +fi + +if [ $DISTRIB_ID == "CentOS" ]; then + # Install uio-pci-generic + modprobe uio_pci_generic +fi +echo "Starting VPP..." +if [ $DISTRIB_ID == "Ubuntu" ] && [ $DISTRIB_CODENAME = "trusty" ] ; then + start vpp +else + service vpp start +fi diff --git a/extras/vagrant/update.sh b/extras/vagrant/update.sh new file mode 100755 index 00000000..f4139d74 --- /dev/null +++ b/extras/vagrant/update.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Make sure that we get the hugepages we need on provision boot +# Note: The package install should take care of this at the end +# But sometimes after all the work of provisioning, we can't +# get the requested number of hugepages without rebooting. +# So do it here just in case +sysctl -w vm.nr_hugepages=1024 +HUGEPAGES=`sysctl -n vm.nr_hugepages` +if [ $HUGEPAGES != 1024 ]; then + echo "ERROR: Unable to get 1024 hugepages, only got $HUGEPAGES. Cannot finish." + exit +fi + +# Figure out what system we are running on +if [ -f /etc/lsb-release ];then + . /etc/lsb-release +elif [ -f /etc/redhat-release ];then + yum install -y redhat-lsb + DISTRIB_ID=`lsb_release -si` + DISTRIB_RELEASE=`lsb_release -sr` + DISTRIB_CODENAME=`lsb_release -sc` + DISTRIB_DESCRIPTION=`lsb_release -sd` +fi + +# Do initial setup for the system +if [ $DISTRIB_ID == "Ubuntu" ]; then + + export DEBIAN_PRIORITY=critical + export DEBIAN_FRONTEND=noninteractive + export DEBCONF_NONINTERACTIVE_SEEN=true + APT_OPTS="--assume-yes --no-install-suggests --no-install-recommends -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\"" + + # Standard update + upgrade dance + apt-get update ${APT_OPTS} >/dev/null + apt-get upgrade ${APT_OPTS} >/dev/null + + # Fix the silly notion that /bin/sh should point to dash by pointing it to bash + + update-alternatives --install /bin/sh sh /bin/bash 100 + + # Install useful but non-mandatory tools + apt-get install -y emacs x11-utils git-review gdb gdbserver +elif [ $DISTRIB_ID == "CentOS" ]; then + # Standard update + upgrade dance + yum check-update + yum update -y +fi |