From c120e3789712bc5f734ca4c5e241167ef9cb0743 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Wed, 1 Feb 2012 15:29:53 -0800 Subject: [PATCH 1/5] Try to make format mostly consistent. No tabs for the moment, although we could switch to smart tabs (i.e. tab for indent, space for align.) --- util/install.sh | 304 ++++++++++++++++++++++++------------------------ 1 file changed, 155 insertions(+), 149 deletions(-) diff --git a/util/install.sh b/util/install.sh index e15c426..ef76354 100755 --- a/util/install.sh +++ b/util/install.sh @@ -40,48 +40,50 @@ OVS_DIR=~/openvswitch OVS_KMOD=openvswitch_mod.ko function kernel { - echo "Install Mininet-compatible kernel" - sudo apt-get update + echo "Install Mininet-compatible kernel" + sudo apt-get update if [ "$DIST" = "Debian" ]; then - - # The easy approach: download pre-built linux-image and linux-headers packages: - wget -c $KERNEL_LOC/$KERNEL_HEADERS - wget -c $KERNEL_LOC/$KERNEL_IMAGE + + # The easy approach: download pre-built linux-image and linux-headers packages: + wget -c $KERNEL_LOC/$KERNEL_HEADERS + wget -c $KERNEL_LOC/$KERNEL_IMAGE - #Install custom linux headers and image: - sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS + # Install custom linux headers and image: + sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS - # The next two steps are to work around a bug in newer versions of - # kernel-package, which fails to add initrd images with the latest kernels. - # See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525032 - # Generate initrd image if the .deb didn't install it: - if ! test -e /boot/initrd.img-${KERNEL_NAME}; then - sudo update-initramfs -c -k ${KERNEL_NAME} - fi - - # Ensure /boot/grub/menu.lst boots with initrd image: - sudo update-grub + # The next two steps are to work around a bug in newer versions of + # kernel-package, which fails to add initrd images with the latest kernels. + # See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525032 + # Generate initrd image if the .deb didn't install it: + if ! test -e /boot/initrd.img-${KERNEL_NAME}; then + sudo update-initramfs -c -k ${KERNEL_NAME} + fi + + # Ensure /boot/grub/menu.lst boots with initrd image: + sudo update-grub - # The default should be the new kernel. Otherwise, you may need to modify /boot/grub/menu.lst to set the default to the entry corresponding to the kernel you just installed. + # The default should be the new kernel. Otherwise, you may need to modify + # /boot/grub/menu.lst to set the default to the entry corresponding to the + # kernel you just installed. fi } function kernel_clean { - echo "Cleaning kernel..." + echo "Cleaning kernel..." - # To save disk space, remove previous kernel - sudo apt-get -y remove $KERNEL_IMAGE_OLD + # To save disk space, remove previous kernel + sudo apt-get -y remove $KERNEL_IMAGE_OLD - #Also remove downloaded packages: - rm -f ~/linux-headers-* ~/linux-image-* + # Also remove downloaded packages: + rm -f ~/linux-headers-* ~/linux-image-* } # Install Mininet deps function mn_deps { - echo "Installing Mininet dependencies" - sudo aptitude install -y gcc make screen psmisc xterm ssh iperf iproute \ + echo "Installing Mininet dependencies" + sudo aptitude install -y gcc make screen psmisc xterm ssh iperf iproute \ python-setuptools python-networkx if [ "$DIST" = "Ubuntu" ] && [ "`lsb_release -sr`" = "10.04" ]; then @@ -89,11 +91,12 @@ function mn_deps { sudo easy_install --upgrade networkx fi - #Add sysctl parameters as noted in the INSTALL file to increase kernel limits to support larger setups: - sudo su -c "cat $HOME/mininet/util/sysctl_addon >> /etc/sysctl.conf" + # Add sysctl parameters as noted in the INSTALL file to increase kernel + # limits to support larger setups: + sudo su -c "cat $HOME/mininet/util/sysctl_addon >> /etc/sysctl.conf" - #Load new sysctl settings: - sudo sysctl -p + # Load new sysctl settings: + sudo sysctl -p echo "Installing Mininet core" pushd ~/mininet @@ -108,53 +111,55 @@ function mn_deps { # http://www.openflowswitch.org/wk/index.php/Debian_Install # ... modified to use Debian Lenny rather than unstable. function of { - echo "Installing OpenFlow and its tools..." + echo "Installing OpenFlow and its tools..." - cd ~/ - sudo apt-get install -y git-core automake m4 pkg-config libtool make libc6-dev autoconf autotools-dev gcc - git clone git://openflowswitch.org/openflow.git - cd ~/openflow + cd ~/ + sudo apt-get install -y git-core automake m4 pkg-config libtool \ + make libc6-dev autoconf autotools-dev gcc + git clone git://openflowswitch.org/openflow.git + cd ~/openflow # Patch controller to handle more than 16 switches patch -p1 < ~/mininet/util/openflow-patches/controller.patch - # Resume the install: - ./boot.sh - ./configure - make - sudo make install + # Resume the install: + ./boot.sh + ./configure + make + sudo make install - # Install dissector: - sudo apt-get install -y wireshark libgtk2.0-dev - cd ~/openflow/utilities/wireshark_dissectors/openflow - make - sudo make install + # Install dissector: + sudo apt-get install -y wireshark libgtk2.0-dev + cd ~/openflow/utilities/wireshark_dissectors/openflow + make + sudo make install - # Copy coloring rules: OF is white-on-blue: - mkdir -p ~/.wireshark - cp ~/mininet/util/colorfilters ~/.wireshark + # Copy coloring rules: OF is white-on-blue: + mkdir -p ~/.wireshark + cp ~/mininet/util/colorfilters ~/.wireshark - # Remove avahi-daemon, which may cause unwanted discovery packets to be sent during tests, near link status changes: - sudo apt-get remove -y avahi-daemon + # Remove avahi-daemon, which may cause unwanted discovery packets to be + # sent during tests, near link status changes: + sudo apt-get remove -y avahi-daemon - # Disable IPv6. Add to /etc/modprobe.d/blacklist: + # Disable IPv6. Add to /etc/modprobe.d/blacklist: if [ "$DIST" = "Ubuntu" ]; then BLACKLIST=/etc/modprobe.d/blacklist.conf else BLACKLIST=/etc/modprobe.d/blacklist fi - sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST" + sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST" } # Install OpenVSwitch # Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files. function ovs { - echo "Installing OpenVSwitch..." + echo "Installing OpenVSwitch..." if [ "$DIST" = "Debian" ]; then sudo aptitude -y install pkg-config gcc make git-core python-dev libssl-dev - #Install Autoconf 2.63+ backport from Debian Backports repo: - #Instructions from http://backports.org/dokuwiki/doku.php?id=instructions + # Install Autoconf 2.63+ backport from Debian Backports repo: + # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list" sudo apt-get update sudo apt-get -y --force-yes install debian-backports-keyring @@ -165,29 +170,30 @@ function ovs { sudo apt-get -y install $KERNEL_HEADERS fi - #Install OVS from release - cd ~/ - git clone git://openvswitch.org/openvswitch - cd $OVS_DIR + # Install OVS from release + cd ~/ + git clone git://openvswitch.org/openvswitch + cd $OVS_DIR git checkout $OVS_RELEASE - ./boot.sh + ./boot.sh BUILDDIR=/lib/modules/${KERNEL_NAME}/build if [ ! -e $BUILDDIR ]; then echo "Creating build sdirectory $BUILDDIR" sudo mkdir -p $BUILDDIR fi opts="--with-l26=$BUILDDIR" - ./configure $opts - make - sudo make install + ./configure $opts + make + sudo make install } # Install NOX with tutorial files function nox { - echo "Installing NOX w/tutorial files..." + echo "Installing NOX w/tutorial files..." - #Install NOX deps: - sudo apt-get -y install autoconf automake g++ libtool python python-twisted swig libxerces-c2-dev libssl-dev make + # Install NOX deps: + sudo apt-get -y install autoconf automake g++ libtool python python-twisted \ + swig libxerces-c2-dev libssl-dev make if [ "$DIST" = "Debian" ]; then sudo apt-get -y install libboost1.35-dev elif [ "$DIST" = "Ubuntu" ]; then @@ -195,31 +201,31 @@ function nox { sudo apt-get -y install libboost-filesystem-dev sudo apt-get -y install libboost-test-dev fi - #Install NOX optional deps: - sudo apt-get install -y libsqlite3-dev python-simplejson + # Install NOX optional deps: + sudo apt-get install -y libsqlite3-dev python-simplejson - #Install NOX: - cd ~/ - git clone git://openflowswitch.org/nox-tutorial noxcore - cd noxcore + # Install NOX: + cd ~/ + git clone git://openflowswitch.org/nox-tutorial noxcore + cd noxcore - # With later autoconf versions this doesn't quite work: - ./boot.sh --apps-core || true + # With later autoconf versions this doesn't quite work: + ./boot.sh --apps-core || true if [ "$DIST" = "Debian" ]; then # So use this instead: autoreconf --install --force fi - mkdir build - cd build - ../configure --with-python=yes + mkdir build + cd build + ../configure --with-python=yes make - #make check + #make check - # Add NOX_CORE_DIR env var: - sed -i -e 's|# for examples$|&\nexport NOX_CORE_DIR=~/noxcore/build/src|' ~/.bashrc + # Add NOX_CORE_DIR env var: + sed -i -e 's|# for examples$|&\nexport NOX_CORE_DIR=~/noxcore/build/src|' ~/.bashrc - # To verify this install: - #cd ~/noxcore/build/src + # To verify this install: + #cd ~/noxcore/build/src #./nox_core -v -i ptcp: } @@ -227,10 +233,10 @@ function nox { function oftest { echo "Installing oftest..." - #Install deps: + # Install deps: sudo apt-get install -y tcpdump python-scapy - #Install oftest: + # Install oftest: cd ~/ git clone git://openflow.org/oftest cd oftest @@ -254,27 +260,27 @@ function cbench { } function other { - echo "Doing other setup tasks..." + echo "Doing other setup tasks..." - #Enable command auto completion using sudo; modify ~/.bashrc: - sed -i -e 's|# for examples$|&\ncomplete -cf sudo|' ~/.bashrc + # Enable command auto completion using sudo; modify ~/.bashrc: + sed -i -e 's|# for examples$|&\ncomplete -cf sudo|' ~/.bashrc - #Install tcpdump and tshark, cmd-line packet dump tools. Also install gitk, - #a graphical git history viewer. - sudo apt-get install -y tcpdump tshark gitk + # Install tcpdump and tshark, cmd-line packet dump tools. Also install gitk, + # a graphical git history viewer. + sudo apt-get install -y tcpdump tshark gitk - #Install common text editors + # Install common text editors sudo apt-get install -y vim nano emacs - #Install NTP + # Install NTP sudo apt-get install -y ntp - #Set git to colorize everything. - git config --global color.diff auto - git config --global color.status auto - git config --global color.branch auto + # Set git to colorize everything. + git config --global color.diff auto + git config --global color.status auto + git config --global color.branch auto - #Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1: + # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1: if [ "$DIST" = "Debian" ]; then sudo sed -i -e 's/^timeout.*$/timeout 1/' /boot/grub/menu.lst fi @@ -291,56 +297,56 @@ function other { # re-run this script. If you're using only one kernel version, then it may be # a good idea to use a symbolic link in place of the copy below. function modprobe { - echo "Setting up modprobe for OVS kmod..." + echo "Setting up modprobe for OVS kmod..." - sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR - sudo depmod -a ${KERNEL_NAME} + sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR + sudo depmod -a ${KERNEL_NAME} } function all { - echo "Running all commands..." + echo "Running all commands..." if [ "$DIST" != "Ubuntu" ]; then # Ubuntu ships with Mininet-compatible kernel kernel fi - mn_deps - of - ovs + mn_deps + of + ovs modprobe - nox - oftest - cbench - other - echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages." - echo "Enjoy Mininet!" + nox + oftest + cbench + other + echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages." + echo "Enjoy Mininet!" } # Restore disk space and remove sensitive files before shipping a VM. function vm_clean { - echo "Cleaning VM..." - sudo apt-get clean - sudo rm -rf /tmp/* - sudo rm -rf openvswitch*.tar.gz + echo "Cleaning VM..." + sudo apt-get clean + sudo rm -rf /tmp/* + sudo rm -rf openvswitch*.tar.gz - # Remove sensistive files - history -c # note this won't work if you have multiple bash sessions - rm -f ~/.bash_history # need to clear in memory and remove on disk - rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts - sudo rm -f ~/.ssh/authorized_keys2 + # Remove sensistive files + history -c # note this won't work if you have multiple bash sessions + rm -f ~/.bash_history # need to clear in memory and remove on disk + rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts + sudo rm -f ~/.ssh/authorized_keys* - # Remove Mininet files - #sudo rm -f /lib/modules/python2.5/site-packages/mininet* - #sudo rm -f /usr/bin/mnexec + # Remove Mininet files + #sudo rm -f /lib/modules/python2.5/site-packages/mininet* + #sudo rm -f /usr/bin/mnexec - # Clear optional dev script for SSH keychain load on boot - rm -f ~/.bash_profile + # Clear optional dev script for SSH keychain load on boot + rm -f ~/.bash_profile - # Clear git changes - git config --global user.name "None" - git config --global user.email "None" + # Clear git changes + git config --global user.name "None" + git config --global user.email "None" - # Remove mininet install script - rm -f install-mininet.sh + # Remove mininet install script + rm -f install-mininet.sh } function usage { @@ -372,25 +378,25 @@ function usage { if [ $# -eq 0 ] then - all + all else - while getopts 'abcdfhkmntvx' OPTION - do - case $OPTION in - a) all;; - b) cbench;; - c) kernel_clean;; - d) vm_clean;; - f) of;; - h) usage;; - k) kernel;; - m) modprobe;; - n) mn_deps;; - t) other;; - v) ovs;; - x) nox;; - ?) usage;; - esac - done - shift $(($OPTIND - 1)) + while getopts 'abcdfhkmntvx' OPTION + do + case $OPTION in + a) all;; + b) cbench;; + c) kernel_clean;; + d) vm_clean;; + f) of;; + h) usage;; + k) kernel;; + m) modprobe;; + n) mn_deps;; + t) other;; + v) ovs;; + x) nox;; + ?) usage;; + esac + done + shift $(($OPTIND - 1)) fi From 7e79d1351cd29636f3977799b8f027a248b5d775 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Fri, 3 Feb 2012 18:26:24 -0800 Subject: [PATCH 2/5] Changes (OVS 1.2.2, NOX destiny) for installation on Ubuntu 11.10 oneiric. --- util/install.sh | 56 ++-- ...1-OpenFlow-tutorial-port-nox-destiny.patch | 298 ++++++++++++++++++ util/nox-patches/README | 1 + 3 files changed, 330 insertions(+), 25 deletions(-) create mode 100644 util/nox-patches/0001-OpenFlow-tutorial-port-nox-destiny.patch create mode 100644 util/nox-patches/README diff --git a/util/install.sh b/util/install.sh index ef76354..292bd26 100755 --- a/util/install.sh +++ b/util/install.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Mininet install script for Debian +# Mininet install script for Ubuntu (and Debian Lenny) # Brandon Heller (brandonh@stanford.edu) # Fail on error @@ -35,9 +35,10 @@ KERNEL_IMAGE_OLD=linux-image-2.6.26-2-686 DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net -OVS_RELEASE=v1.1.1 -OVS_DIR=~/openvswitch -OVS_KMOD=openvswitch_mod.ko +OVS_RELEASE=v1.2.2 +OVS_SRC=~/openvswitch +OVS_BUILD=$OVS_SRC/build-$KERNEL_NAME +OVS_KMODS=($OVS_BUILD/datapath/linux/{openvswitch_mod.ko,brcompat_mod.ko}) function kernel { echo "Install Mininet-compatible kernel" @@ -151,12 +152,12 @@ function of { sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST" } -# Install OpenVSwitch +# Install Open vSwitch # Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files. function ovs { - echo "Installing OpenVSwitch..." + echo "Installing Open vSwitch..." - if [ "$DIST" = "Debian" ]; then + if [ "$DIST" = "Debian" && `lsb-release -c` == "lenny" ]; then sudo aptitude -y install pkg-config gcc make git-core python-dev libssl-dev # Install Autoconf 2.63+ backport from Debian Backports repo: # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions @@ -173,7 +174,7 @@ function ovs { # Install OVS from release cd ~/ git clone git://openvswitch.org/openvswitch - cd $OVS_DIR + cd $OVS_SRC git checkout $OVS_RELEASE ./boot.sh BUILDDIR=/lib/modules/${KERNEL_NAME}/build @@ -181,10 +182,14 @@ function ovs { echo "Creating build sdirectory $BUILDDIR" sudo mkdir -p $BUILDDIR fi - opts="--with-l26=$BUILDDIR" - ./configure $opts + opts="--with-linux=$BUILDDIR" + mkdir -p $OVS_BUILD + cd $OVS_BUILD + ../configure $opts make sudo make install + # openflowd is deprecated, but for now copy it in + sudo cp tests/test-openflowd /usr/local/bin/ovs-openflowd } # Install NOX with tutorial files @@ -193,7 +198,7 @@ function nox { # Install NOX deps: sudo apt-get -y install autoconf automake g++ libtool python python-twisted \ - swig libxerces-c2-dev libssl-dev make + swig libssl-dev make if [ "$DIST" = "Debian" ]; then sudo apt-get -y install libboost1.35-dev elif [ "$DIST" = "Ubuntu" ]; then @@ -204,21 +209,22 @@ function nox { # Install NOX optional deps: sudo apt-get install -y libsqlite3-dev python-simplejson - # Install NOX: + # Fetch NOX destiny cd ~/ - git clone git://openflowswitch.org/nox-tutorial noxcore + git clone git://noxrepo.org/nox noxcore cd noxcore + git checkout -b destiny remotes/origin/destiny - # With later autoconf versions this doesn't quite work: - ./boot.sh --apps-core || true - if [ "$DIST" = "Debian" ]; then - # So use this instead: - autoreconf --install --force - fi + # Apply patches + git checkout -b tutorial-destiny + git am ~/mininet/util/nox-patches/*.patch + + # Build + ./boot.sh mkdir build cd build - ../configure --with-python=yes - make + ../configure + make -j3 #make check # Add NOX_CORE_DIR env var: @@ -299,7 +305,7 @@ function other { function modprobe { echo "Setting up modprobe for OVS kmod..." - sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR + sudo cp $OVS_KMODS $DRIVERS_DIR sudo depmod -a ${KERNEL_NAME} } @@ -353,11 +359,11 @@ function usage { printf 'Usage: %s [-acdfhkmntvxy]\n\n' $(basename $0) >&2 printf 'This install script attempts to install useful packages\n' >&2 - printf 'for Mininet. It should (hopefully) work on Ubuntu 10.04 and\n' >&2 - printf 'Debian 5.0 (Lenny). If you run into trouble, try\n' >&2 + printf 'for Mininet. It should (hopefully) work on Ubuntu 10.04, 11.10\n' >&2 + printf 'and Debian 5.0 (Lenny). If you run into trouble, try\n' >&2 printf 'installing one thing at a time, and looking at the \n' >&2 printf 'specific installation function in this script.\n\n' >&2 - + printf 'options:\n' >&2 printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2 printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2 diff --git a/util/nox-patches/0001-OpenFlow-tutorial-port-nox-destiny.patch b/util/nox-patches/0001-OpenFlow-tutorial-port-nox-destiny.patch new file mode 100644 index 0000000..881fc55 --- /dev/null +++ b/util/nox-patches/0001-OpenFlow-tutorial-port-nox-destiny.patch @@ -0,0 +1,298 @@ +From 5c9610ffb88c89b0f36359ad3c7547831482a3ff Mon Sep 17 00:00:00 2001 +From: Bob Lantz +Date: Fri, 3 Feb 2012 14:48:58 -0800 +Subject: [PATCH] OpenFlow tutorial port nox-destiny. + +--- + src/nox/coreapps/examples/Makefile.am | 2 +- + src/nox/coreapps/examples/tutorial/Makefile.am | 25 ++++ + src/nox/coreapps/examples/tutorial/meta.json | 12 ++ + src/nox/coreapps/examples/tutorial/pytutorial.py | 67 +++++++++++ + src/nox/coreapps/examples/tutorial/tutorial.cc | 134 ++++++++++++++++++++++ + 5 files changed, 239 insertions(+), 1 deletions(-) + create mode 100644 src/nox/coreapps/examples/tutorial/Makefile.am + create mode 100644 src/nox/coreapps/examples/tutorial/__init__.py + create mode 100644 src/nox/coreapps/examples/tutorial/meta.json + create mode 100644 src/nox/coreapps/examples/tutorial/pytutorial.py + create mode 100644 src/nox/coreapps/examples/tutorial/tutorial.cc + +diff --git a/src/nox/coreapps/examples/Makefile.am b/src/nox/coreapps/examples/Makefile.am +index 126f32e..1a0458c 100644 +--- a/src/nox/coreapps/examples/Makefile.am ++++ b/src/nox/coreapps/examples/Makefile.am +@@ -1,6 +1,6 @@ + include ../../../Make.vars + +-SUBDIRS = t ++SUBDIRS = tutorial t + + EXTRA_DIST =\ + meta.json\ +diff --git a/src/nox/coreapps/examples/tutorial/Makefile.am b/src/nox/coreapps/examples/tutorial/Makefile.am +new file mode 100644 +index 0000000..51cf921 +--- /dev/null ++++ b/src/nox/coreapps/examples/tutorial/Makefile.am +@@ -0,0 +1,25 @@ ++include ../../../../Make.vars ++ ++EXTRA_DIST =\ ++ meta.xml \ ++ __init__.py \ ++ pytutorial.py ++ ++if PY_ENABLED ++AM_CPPFLAGS += $(PYTHON_CPPFLAGS) ++endif # PY_ENABLED ++ ++pkglib_LTLIBRARIES = \ ++ tutorial.la ++ ++tutorial_la_CPPFLAGS = $(AM_CPPFLAGS) -I $(top_srcdir)/src/nox -I $(top_srcdir)/src/nox/coreapps/ ++tutorial_la_SOURCES = tutorial.cc ++tutorial_la_LDFLAGS = -module -export-dynamic ++ ++NOX_RUNTIMEFILES = meta.json \ ++ __init__.py \ ++ pytutorial.py ++ ++all-local: nox-all-local ++clean-local: nox-clean-local ++install-exec-hook: nox-install-local +diff --git a/src/nox/coreapps/examples/tutorial/__init__.py b/src/nox/coreapps/examples/tutorial/__init__.py +new file mode 100644 +index 0000000..e69de29 +diff --git a/src/nox/coreapps/examples/tutorial/meta.json b/src/nox/coreapps/examples/tutorial/meta.json +new file mode 100644 +index 0000000..7a9f227 +--- /dev/null ++++ b/src/nox/coreapps/examples/tutorial/meta.json +@@ -0,0 +1,12 @@ ++{ ++ "components": [ ++ { ++ "name": "tutorial", ++ "library": "tutorial" ++ }, ++ { ++ "name": "pytutorial", ++ "python": "nox.coreapps.examples.tutorial.pytutorial" ++ } ++ ] ++} +diff --git a/src/nox/coreapps/examples/tutorial/pytutorial.py b/src/nox/coreapps/examples/tutorial/pytutorial.py +new file mode 100644 +index 0000000..1e21c0b +--- /dev/null ++++ b/src/nox/coreapps/examples/tutorial/pytutorial.py +@@ -0,0 +1,67 @@ ++# Tutorial Controller ++# Starts as a hub, and your job is to turn this into a learning switch. ++ ++import logging ++ ++from nox.lib.core import * ++import nox.lib.openflow as openflow ++from nox.lib.packet.ethernet import ethernet ++from nox.lib.packet.packet_utils import mac_to_str, mac_to_int ++ ++log = logging.getLogger('nox.coreapps.tutorial.pytutorial') ++ ++ ++class pytutorial(Component): ++ ++ def __init__(self, ctxt): ++ Component.__init__(self, ctxt) ++ # Use this table to store MAC addresses in the format of your choice; ++ # Functions already imported, including mac_to_str, and mac_to_int, ++ # should prove useful for converting the byte array provided by NOX ++ # for packet MAC destination fields. ++ # This table is initialized to empty when your module starts up. ++ self.mac_to_port = {} # key: MAC addr; value: port ++ ++ def learn_and_forward(self, dpid, inport, packet, buf, bufid): ++ """Learn MAC src port mapping, then flood or send unicast.""" ++ ++ # Initial hub behavior: flood packet out everything but input port. ++ # Comment out the line below when starting the exercise. ++ self.send_openflow(dpid, bufid, buf, openflow.OFPP_FLOOD, inport) ++ ++ # Starter psuedocode for learning switch exercise below: you'll need to ++ # replace each pseudocode line with more specific Python code. ++ ++ # Learn the port for the source MAC ++ #self.mac_to_port = ++ #if (destination MAC of the packet is known): ++ # Send unicast packet to known output port ++ #self.send_openflow( ) ++ # Later, only after learning controller works: ++ # push down flow entry and remove the send_openflow command above. ++ #self.install_datapath_flow( ) ++ #else: ++ #flood packet out everything but the input port ++ #self.send_openflow(dpid, bufid, buf, openflow.OFPP_FLOOD, inport) ++ ++ def packet_in_callback(self, dpid, inport, reason, len, bufid, packet): ++ """Packet-in handler""" ++ if not packet.parsed: ++ log.debug('Ignoring incomplete packet') ++ else: ++ self.learn_and_forward(dpid, inport, packet, packet.arr, bufid) ++ ++ return CONTINUE ++ ++ def install(self): ++ self.register_for_packet_in(self.packet_in_callback) ++ ++ def getInterface(self): ++ return str(pytutorial) ++ ++def getFactory(): ++ class Factory: ++ def instance(self, ctxt): ++ return pytutorial(ctxt) ++ ++ return Factory() +diff --git a/src/nox/coreapps/examples/tutorial/tutorial.cc b/src/nox/coreapps/examples/tutorial/tutorial.cc +new file mode 100644 +index 0000000..e7240cc +--- /dev/null ++++ b/src/nox/coreapps/examples/tutorial/tutorial.cc +@@ -0,0 +1,134 @@ ++#include "component.hh" ++#include "config.h" ++#include "packet-in.hh" ++#include "flow.hh" ++#include "assert.hh" ++#include "netinet++/ethernetaddr.hh" ++#include "netinet++/ethernet.hh" ++#include ++#include ++#ifdef LOG4CXX_ENABLED ++#include ++#include "log4cxx/logger.h" ++#else ++#include "vlog.hh" ++#endif ++ ++using namespace std; ++using namespace vigil; ++using namespace vigil::container; ++ ++namespace ++{ ++ static Vlog_module lg("tutorial"); ++ ++ /** Learning switch. ++ */ ++ class tutorial ++ : public Component ++ { ++ public: ++ /** Constructor. ++ */ ++ tutorial(const Context* c, const json_object* node) ++ : Component(c) ++ { } ++ ++ /** Configuration. ++ * Add handler for packet-in event. ++ */ ++ void configure(const Configuration*) ++ { ++ register_handler ++ (boost::bind(&tutorial::handle, this, _1)); ++ } ++ ++ /** Just simply install. ++ */ ++ void install() ++ { ++ lg.dbg(" Install called "); ++ } ++ ++ /** Function to setup flow. ++ */ ++ void setup_flow(Flow& flow, datapathid datapath_id , ++ uint32_t buffer_id, uint16_t out_port) ++ { ++ ofp_flow_mod* ofm; ++ size_t size = sizeof *ofm + sizeof(ofp_action_output); ++ boost::shared_array raw_of(new char[size]); ++ ofm = (ofp_flow_mod*) raw_of.get(); ++ ++ ofm->header.version = OFP_VERSION; ++ ofm->header.type = OFPT_FLOW_MOD; ++ ofm->header.length = htons(size); ++ ofm->match.wildcards = htonl(0); ++ ofm->match.in_port = htons(flow.in_port); ++ ofm->match.dl_vlan = flow.dl_vlan; ++ memcpy(ofm->match.dl_src, flow.dl_src.octet, sizeof ofm->match.dl_src); ++ memcpy(ofm->match.dl_dst, flow.dl_dst.octet, sizeof ofm->match.dl_dst); ++ ofm->match.dl_type = flow.dl_type; ++ ofm->match.nw_src = flow.nw_src; ++ ofm->match.nw_dst = flow.nw_dst; ++ ofm->match.nw_proto = flow.nw_proto; ++ ofm->match.tp_src = flow.tp_src; ++ ofm->match.tp_dst = flow.tp_dst; ++ ofm->command = htons(OFPFC_ADD); ++ ofm->buffer_id = htonl(buffer_id); ++ ofm->idle_timeout = htons(5); ++ ofm->hard_timeout = htons(OFP_FLOW_PERMANENT); ++ ofm->priority = htons(OFP_DEFAULT_PRIORITY); ++ ofp_action_output& action = *((ofp_action_output*)ofm->actions); ++ memset(&action, 0, sizeof(ofp_action_output)); ++ action.type = htons(OFPAT_OUTPUT); ++ action.len = htons(sizeof(ofp_action_output)); ++ action.max_len = htons(0); ++ action.port = htons(out_port); ++ send_openflow_command(datapath_id, &ofm->header, true); ++ } ++ ++ /** Function to handle packets. ++ * @param datapath_id datapath id of switch ++ * @param in_port port packet is received ++ * @param buffer_id buffer id of packet ++ * @param source source mac address in host order ++ * @param destination destination mac address in host order ++ */ ++ void handle_packet(datapathid datapath_id, uint16_t in_port, uint32_t buffer_id, ++ uint64_t source, uint64_t destination) ++ { ++ send_openflow_packet(datapath_id, buffer_id, OFPP_FLOOD, ++ in_port, true); ++ } ++ ++ /** Packet-on handler. ++ */ ++ Disposition handle(const Event& e) ++ { ++ const Packet_in_event& pi = assert_cast(e); ++ uint32_t buffer_id = pi.buffer_id; ++ Flow flow(pi.in_port, *pi.get_buffer()); ++ ++ // drop LLDP packets ++ if (flow.dl_type == ethernet::LLDP) ++ return CONTINUE; ++ ++ // pass handle of unicast packet, else flood ++ if (!flow.dl_src.is_multicast()) ++ handle_packet(pi.datapath_id, pi.in_port, buffer_id, ++ flow.dl_src.hb_long(), flow.dl_dst.hb_long()); ++ else ++ send_openflow_packet(pi.datapath_id, buffer_id, OFPP_FLOOD, ++ pi.in_port, true); ++ ++ return CONTINUE; ++ } ++ ++ private: ++}; ++ ++REGISTER_COMPONENT(container::Simple_component_factory, ++ tutorial); ++ ++} // unnamed namespace +-- +1.7.5.4 + diff --git a/util/nox-patches/README b/util/nox-patches/README new file mode 100644 index 0000000..5c8dce8 --- /dev/null +++ b/util/nox-patches/README @@ -0,0 +1 @@ +This patch adds the OpenFlow tutorial module source code to nox-destiny. From 8d1444a9140f10e9ee7d3ae48a32669b3910f4f7 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Sat, 4 Feb 2012 01:10:40 -0800 Subject: [PATCH 3/5] Fix for 10.04 whose default kernel doesn't have CONFIG_NET_NS enabled. --- util/install.sh | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/util/install.sh b/util/install.sh index 292bd26..33e5d89 100755 --- a/util/install.sh +++ b/util/install.sh @@ -11,8 +11,22 @@ set -o nounset # Location of CONFIG_NET_NS-enabled kernel(s) KERNEL_LOC=http://www.openflow.org/downloads/mininet +# Attempt to identify Linux release + +DIST=Unknown +RELEASE=Unknown +CODENAME=Unknown test -e /etc/debian_version && DIST="Debian" grep Ubuntu /etc/lsb-release &> /dev/null && DIST="Ubuntu" +if [ "$DIST" = "Ubuntu" ] || [ "$DIST" = "Debian" ]; then + sudo apt-get install -y lsb-release +fi +if which lsb_release &> /dev/null; then + DIST=`lsb_release -is` + RELEASE=`lsb_release -rs` + CODENAME=`lsb_release -cs` +fi +echo "Detected Linux distribution: $DIST $RELEASE $CODENAME" # Kernel params @@ -21,14 +35,17 @@ if [ "$DIST" = "Debian" ]; then KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb elif [ "$DIST" = "Ubuntu" ]; then - KERNEL_NAME=`uname -r` + if [ "$RELEASE" = "10.04" ]; then + KERNEL_NAME='3.0.0-15-generic' + else + KERNEL_NAME=`uname -r` + fi KERNEL_HEADERS=linux-headers-${KERNEL_NAME} else echo "Install.sh currently only supports Ubuntu and Debian." exit 1 fi -echo "Detected Linux distribution: $DIST" # Kernel Deb pkg to be removed: KERNEL_IMAGE_OLD=linux-image-2.6.26-2-686 @@ -41,11 +58,9 @@ OVS_BUILD=$OVS_SRC/build-$KERNEL_NAME OVS_KMODS=($OVS_BUILD/datapath/linux/{openvswitch_mod.ko,brcompat_mod.ko}) function kernel { - echo "Install Mininet-compatible kernel" + echo "Install Mininet-compatible kernel if necessary" sudo apt-get update - if [ "$DIST" = "Debian" ]; then - # The easy approach: download pre-built linux-image and linux-headers packages: wget -c $KERNEL_LOC/$KERNEL_HEADERS wget -c $KERNEL_LOC/$KERNEL_IMAGE @@ -68,7 +83,9 @@ function kernel { # /boot/grub/menu.lst to set the default to the entry corresponding to the # kernel you just installed. fi - + if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" = "10.04" ]; then + sudo apt-get -y install linux-image-$KERNEL_NAME + fi } function kernel_clean { @@ -87,7 +104,7 @@ function mn_deps { sudo aptitude install -y gcc make screen psmisc xterm ssh iperf iproute \ python-setuptools python-networkx - if [ "$DIST" = "Ubuntu" ] && [ "`lsb_release -sr`" = "10.04" ]; then + if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" = "10.04" ]; then echo "Upgrading networkx to avoid deprecation warning" sudo easy_install --upgrade networkx fi @@ -157,7 +174,7 @@ function of { function ovs { echo "Installing Open vSwitch..." - if [ "$DIST" = "Debian" && `lsb-release -c` == "lenny" ]; then + if [ "$DIST" = "Debian" ] && [ "$CODENAME" == "lenny" ]; then sudo aptitude -y install pkg-config gcc make git-core python-dev libssl-dev # Install Autoconf 2.63+ backport from Debian Backports repo: # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions @@ -311,10 +328,7 @@ function modprobe { function all { echo "Running all commands..." - if [ "$DIST" != "Ubuntu" ]; then - # Ubuntu ships with Mininet-compatible kernel - kernel - fi + kernel mn_deps of ovs From 28f46c8d2d9b34d3831eb286ff2a6d49b7875284 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Mon, 12 Mar 2012 16:12:38 -0700 Subject: [PATCH 4/5] Pass code check. --- .pylint | 2 +- examples/miniedit.py | 2 +- mininet/node.py | 14 +++++++------- mininet/util.py | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.pylint b/.pylint index 4c4b48b..85c2153 100644 --- a/.pylint +++ b/.pylint @@ -53,7 +53,7 @@ disable-msg-cat=IR #enable-msg= # Disable the message(s) with the given id(s). -disable-msg=W0704,C0103,W0231,E1102,W0511,W0142,R0902,R0903,R0904,R0913,R0914,R0801 +disable=W0704,C0103,W0231,E1102,W0511,W0142,R0902,R0903,R0904,R0913,R0914,R0801,I0011 [REPORTS] diff --git a/examples/miniedit.py b/examples/miniedit.py index 172a1f4..bd4908d 100755 --- a/examples/miniedit.py +++ b/examples/miniedit.py @@ -602,7 +602,7 @@ class MiniEdit( Frame ): cleanUpScreens() self.net = None - def xterm( self, ignore=None ): + def xterm( self, _ignore=None ): "Make an xterm when a button is pressed." if ( self.selection is None or self.net is None or diff --git a/mininet/node.py b/mininet/node.py index 8286466..8ebb676 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -116,19 +116,19 @@ class Node( object ): self.shell = None # Subshell I/O, commands and control - def read( self, bytes=1024 ): + def read( self, maxbytes=1024 ): """Buffered read from node, non-blocking. - bytes: maximum number of bytes to return""" + maxbytes: maximum number of bytes to return""" count = len( self.readbuf ) - if count < bytes: - data = os.read( self.stdout.fileno(), bytes - count ) + if count < maxbytes: + data = os.read( self.stdout.fileno(), maxbytes - count ) self.readbuf += data - if bytes >= len( self.readbuf ): + if maxbytes >= len( self.readbuf ): result = self.readbuf self.readbuf = '' else: - result = self.readbuf[ :bytes ] - self.readbuf = self.readbuf[ bytes: ] + result = self.readbuf[ :maxbytes ] + self.readbuf = self.readbuf[ maxbytes: ] return result def readline( self ): diff --git a/mininet/util.py b/mininet/util.py index 75065ea..d78db43 100644 --- a/mininet/util.py +++ b/mininet/util.py @@ -136,13 +136,13 @@ def createLink( node1, node2, port1=None, port2=None ): # IP and Mac address formatting and parsing -def _colonHex( val, bytes ): +def _colonHex( val, count ): """Generate colon-hex string. val: input as unsigned int - bytes: number of bytes to convert + count: number of bytes to convert returns: chStr colon-hex string""" pieces = [] - for i in range( bytes - 1, -1, -1 ): + for i in range( count - 1, -1, -1 ): piece = ( ( 0xff << ( i * 8 ) ) & val ) >> ( i * 8 ) pieces.append( '%02x' % piece ) chStr = ':'.join( pieces ) From 5562e66a2dd88f17144e572bfbf27aef393abef3 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Mon, 12 Mar 2012 16:14:00 -0700 Subject: [PATCH 5/5] Ignore build, dist and emacs backup~ files. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 1d4a3fe..92e57eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ mnexec *.pyc +*~ mininet.egg-info +build +dist