From: Girish Sukhatankar Date: Thu, 30 Jun 2016 01:44:01 +0000 (-0600) Subject: Add Vagrantfile for L2Switch tutorial X-Git-Tag: release/boron~4 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=371e6a1aa5a25129be1a40bac5b84cfe210462d1;p=integration%2Fpackaging.git Add Vagrantfile for L2Switch tutorial Defines a Vagrant env with OpenDaylight, OVS and Mininet, with ODL's L2Switch and DLUX features installed and DLUX's port forwarded to the host. A user should be able to `vagrant up` this box, wait for provisioning, connect to `localhost:8181/index.html`, login with `admin`/`admin` and see ODL DLUX using L2Switch to show a Mininet topology. Change-Id: Ifb717d64aedd62be066934aeb22339ce9fb5791e Signed-off-by: Girish Sukhatankar Signed-off-by: Daniel Farrell --- diff --git a/tutorials/l2switch/Vagrantfile b/tutorials/l2switch/Vagrantfile new file mode 100644 index 0000000..a99dde4 --- /dev/null +++ b/tutorials/l2switch/Vagrantfile @@ -0,0 +1,74 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Vagrantfile API/syntax version. +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + + # Configure VM RAM and CPU for VirtualBox. Change this to meet your needs. + config.vm.provider :virtualbox do |virtualbox| + virtualbox.memory = 4096 + virtualbox.cpus = 1 + end + + # Configure VM RAM and CPU for LibVirt. Change this to meet your needs. + config.vm.provider :libvirt do |libvirt| + libvirt.memory = 4096 + libvirt.cpus = 1 + end + + # NFS is fragile, disable it and use rsync + config.nfs.functional = false + + # Box that installs the L2switch Tutorial + config.vm.define "l2switch" do |l2switch| + # Build Vagrant box based on Fedora 23 + l2switch.vm.box = "fedora/23-cloud-base" + + # Forward ODL's web GUI (DLUX) port so it's accessible on the host machine + l2switch.vm.network "forwarded_port", guest: 8181, host: 8181 + + # Add ODL RPM repo config to correct location in box filesystem + # Repo configs are provided by upstream OpenDaylight Integration/Packaging + l2switch.vm.provision "shell", inline: "curl --silent -o /etc/yum.repos.d/opendaylight-42-release.repo \"https://git.opendaylight.org/gerrit/gitweb?p=integration/packaging.git;a=blob_plain;f=rpm/example_repo_configs/opendaylight-42-release.repo;hb=refs/heads/master\"" + + # Install ODL using the RPM repo config added above + l2switch.vm.provision "shell", inline: "dnf install -y opendaylight" + + # Start ODL's service via systemd + l2switch.vm.provision "shell", inline: "systemctl start opendaylight" + + # Modify bashrc to set JAVA path + l2switch.vm.provision "shell", inline: "echo 'export JAVA_HOME=/usr/lib/jvm/default-java' >> /etc/bashrc" + + # Install git and sshpass + l2switch.vm.provision "shell", inline: "dnf install -y git sshpass" + + # NB: Recent versions of OpenSSH, shipped with Fedora, don't support ssh-dss + # as an auth protocol. ODL seems offers ssh-dss by default. To SSH to the + # Karaf shell, tell SSH to accept ssh-dss or set this default. + # ssh -p 8101 -oHostKeyAlgorithms=+ssh-dss karaf@localhost + l2switch.vm.provision "shell", inline: "echo 'HostKeyAlgorithms=+ssh-dss' >> /etc/ssh/ssh_config" + + # Install ODL Karaf features required for DLUX and L2Switch + # Config management tools do this by adding features to featuresBoot in + # /opt/opendaylight/etc/org.apache.karaf.features.cfg + # A human user would typically SSH into ODL's Karaf shell, as we're demoing + l2switch.vm.provision "shell", inline: "sshpass -p karaf ssh -tt -p 8101 -o StrictHostKeyChecking=no karaf@localhost feature:install odl-l2switch-switch-ui" + + # Install Open vSwitch + l2switch.vm.provision "shell", inline: "dnf install -y openvswitch" + + # Start Open vSwitch + l2switch.vm.provision "shell", inline: "sudo /usr/share/openvswitch/scripts/ovs-ctl restart" + + # Install Mininet + l2switch.vm.provision "shell", inline: "git clone git://github.com/mininet/mininet" + l2switch.vm.provision "shell", inline: "cd mininet;git checkout -b 2.2.1 2.2.1;cd .." + l2switch.vm.provision "shell", inline: "mininet/util/install.sh -nf" + + # Create a sample Mininet Topology using mininet.py + l2switch.vm.provision "shell", path: "mininet.py" + end +end diff --git a/tutorials/l2switch/mininet.py b/tutorials/l2switch/mininet.py new file mode 100755 index 0000000..e4fa12f --- /dev/null +++ b/tutorials/l2switch/mininet.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +"""Creates a Mininet topology based on examples in the main Mininet documentation.""" + +import time + +from mininet.topo import Topo +from mininet.net import Mininet +from mininet.log import setLogLevel +from mininet.node import RemoteController + + +class SingleSwitchTopo(Topo): + """Single switch connected to n hosts.""" + def build(self, n=2): + switch = self.addSwitch("s1") + # Python's range(N) generates 0..N-1 + for h in range(n): + host = self.addHost("h%s" % (h + 1)) + self.addLink(host, switch) + + +def simple_test(): + """Create and test a simple network.""" + topo = SingleSwitchTopo(n=4) + net = Mininet(topo=topo, controller=None) + net.addController("c0", controller=RemoteController, ip="127.0.0.1", port=6633) + net.start() + time.sleep(10) + print "Testing network connectivity" + net.pingAll() + +if __name__ == "__main__": + # Tell mininet to print useful information + setLogLevel("info") + simple_test()