Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 3e70b01e

History | View | Annotate | Download (20.8 KB)

1
#!/usr/bin/env bash
2

    
3
# Mininet install script for Ubuntu (and Debian Lenny)
4
# Brandon Heller (brandonh@stanford.edu)
5

    
6
# Fail on error
7
set -e
8

    
9
# Fail on unset var usage
10
set -o nounset
11

    
12
# Get directory containing mininet folder
13
MININET_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"
14

    
15
# Set up build directory, which by default is the working directory
16
#  unless the working directory is a subdirectory of mininet, 
17
#  in which case we use the directory containing mininet
18
BUILD_DIR=$PWD
19
case $PWD in
20
  $MININET_DIR/*) BUILD_DIR=$MININET_DIR;; # currect directory is a subdirectory
21
  *) BUILD_DIR=$PWD;;
22
esac
23

    
24
# Location of CONFIG_NET_NS-enabled kernel(s)
25
KERNEL_LOC=http://www.openflow.org/downloads/mininet
26

    
27
# Attempt to identify Linux release
28

    
29
DIST=Unknown
30
RELEASE=Unknown
31
CODENAME=Unknown
32
ARCH=`uname -m`
33
if [ "$ARCH" = "x86_64" ]; then ARCH="amd64"; fi
34
if [ "$ARCH" = "i686" ]; then ARCH="i386"; fi
35

    
36
test -e /etc/debian_version && DIST="Debian"
37
grep Ubuntu /etc/lsb-release &> /dev/null && DIST="Ubuntu"
38
if [ "$DIST" = "Ubuntu" ] || [ "$DIST" = "Debian" ]; then
39
    install='sudo apt-get -y install'
40
    remove='sudo apt-get -y remove'
41
    pkginst='sudo dpkg -i'
42
    # Prereqs for this script
43
    if ! which lsb_release &> /dev/null; then
44
        $install lsb-release
45
    fi
46
    if ! which bc &> /dev/null; then
47
        $install bc
48
    fi
49
fi
50
if which lsb_release &> /dev/null; then
51
    DIST=`lsb_release -is`
52
    RELEASE=`lsb_release -rs`
53
    CODENAME=`lsb_release -cs`
54
fi
55
echo "Detected Linux distribution: $DIST $RELEASE $CODENAME $ARCH"
56

    
57
# Kernel params
58

    
59
if [ "$DIST" = "Ubuntu" ]; then
60
    if [ "$RELEASE" = "10.04" ]; then
61
        KERNEL_NAME='3.0.0-15-generic'
62
    else
63
        KERNEL_NAME=`uname -r`
64
    fi
65
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}
66
elif [ "$DIST" = "Debian" ] && [ "$ARCH" = "i386" ] && [ "$CODENAME" = "lenny" ]; then
67
    KERNEL_NAME=2.6.33.1-mininet
68
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
69
    KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
70
else
71
    echo "Install.sh currently only supports Ubuntu and Debian Lenny i386."
72
    exit 1
73
fi
74

    
75
# More distribution info
76
DIST_LC=`echo $DIST | tr [A-Z] [a-z]` # as lower case
77

    
78
# Kernel Deb pkg to be removed:
79
KERNEL_IMAGE_OLD=linux-image-2.6.26-33-generic
80

    
81
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
82

    
83
OVS_RELEASE=1.4.0
84
OVS_PACKAGE_LOC=https://github.com/downloads/mininet/mininet
85
OVS_BUILDSUFFIX=-ignore # was -2
86
OVS_PACKAGE_NAME=ovs-$OVS_RELEASE-core-$DIST_LC-$RELEASE-$ARCH$OVS_BUILDSUFFIX.tar
87
OVS_SRC=$BUILD_DIR/openvswitch
88
OVS_TAG=v$OVS_RELEASE
89
OVS_BUILD=$OVS_SRC/build-$KERNEL_NAME
90
OVS_KMODS=($OVS_BUILD/datapath/linux/{openvswitch_mod.ko,brcompat_mod.ko})
91

    
92
function kernel {
93
    echo "Install Mininet-compatible kernel if necessary"
94
    sudo apt-get update
95
    if [ "$DIST" = "Ubuntu" ] &&  [ "$RELEASE" = "10.04" ]; then
96
        $install linux-image-$KERNEL_NAME
97
    elif [ "$DIST" = "Debian" ]; then
98
        # The easy approach: download pre-built linux-image and linux-headers packages:
99
        wget -c $KERNEL_LOC/$KERNEL_HEADERS
100
        wget -c $KERNEL_LOC/$KERNEL_IMAGE
101

    
102
        # Install custom linux headers and image:
103
        $pkginst $KERNEL_IMAGE $KERNEL_HEADERS
104

    
105
        # The next two steps are to work around a bug in newer versions of
106
        # kernel-package, which fails to add initrd images with the latest kernels.
107
        # See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525032
108
        # Generate initrd image if the .deb didn't install it:
109
        if ! test -e /boot/initrd.img-${KERNEL_NAME}; then
110
            sudo update-initramfs -c -k ${KERNEL_NAME}
111
        fi
112

    
113
        # Ensure /boot/grub/menu.lst boots with initrd image:
114
        sudo update-grub
115

    
116
        # The default should be the new kernel. Otherwise, you may need to modify
117
        # /boot/grub/menu.lst to set the default to the entry corresponding to the
118
        # kernel you just installed.
119
    fi
120
}
121

    
122
function kernel_clean {
123
    echo "Cleaning kernel..."
124

    
125
    # To save disk space, remove previous kernel
126
    if ! $remove $KERNEL_IMAGE_OLD; then
127
        echo $KERNEL_IMAGE_OLD not installed.
128
    fi
129

    
130
    # Also remove downloaded packages:
131
    rm -f $HOME/linux-headers-* $HOME/linux-image-*
132
}
133

    
134
# Install Mininet deps
135
function mn_deps {
136
    echo "Installing Mininet dependencies"
137
    $install gcc make socat psmisc xterm ssh iperf iproute telnet \
138
        python-setuptools cgroup-bin ethtool help2man \
139
        pyflakes pylint pep8
140

    
141
    # Add sysctl parameters as noted in the INSTALL file to increase kernel
142
    # limits to support larger setups:
143
    if ! grep Mininet /etc/sysctl.conf; then
144
        echo "Adding Mininet sysctl settings"
145
        sudo su -c "cat $MININET_DIR/mininet/util/sysctl_addon >> /etc/sysctl.conf"
146
    fi
147
    # Load new sysctl settings:
148
    sudo sysctl -p
149

    
150
    echo "Installing Mininet core"
151
    pushd $MININET_DIR/mininet
152
    sudo make install
153
    popd
154
}
155

    
156
# The following will cause a full OF install, covering:
157
# -user switch
158
# The instructions below are an abbreviated version from
159
# http://www.openflowswitch.org/wk/index.php/Debian_Install
160
# ... modified to use Debian Lenny rather than unstable.
161
function of {
162
    echo "Installing OpenFlow reference implementation..."
163
    cd $BUILD_DIR/
164
    $install git-core autoconf automake autotools-dev pkg-config \
165
		make gcc libtool libc6-dev
166
    git clone git://openflowswitch.org/openflow.git
167
    cd $BUILD_DIR/openflow
168

    
169
    # Patch controller to handle more than 16 switches
170
    patch -p1 < $MININET_DIR/mininet/util/openflow-patches/controller.patch
171

    
172
    # Resume the install:
173
    ./boot.sh
174
    ./configure
175
    make
176
    sudo make install
177
    cd $BUILD_DIR
178
}
179

    
180
function of13 {
181
    echo "Installing OpenFlow 1.3 soft switch implementation..."
182
    cd $BUILD_DIR/
183
    $install  git-core autoconf automake autotools-dev pkg-config \
184
        make gcc g++ libtool libc6-dev cmake libpcap-dev libxerces-c2-dev  \
185
        unzip libpcre3-dev flex bison libboost-dev
186

    
187
    if [ ! -d "ofsoftswitch13" ]; then
188
        git clone https://github.com/CPqD/ofsoftswitch13.git
189
        if [[ -n "$OF13_SWITCH_REV" ]]; then
190
            cd ofsoftswitch13
191
            git checkout ${OF13_SWITCH_REV}
192
            cd ..
193
        fi
194
    fi
195

    
196
    # Install netbee
197
    NBEESRC="nbeesrc-jan-10-2013"
198
    NBEEURL=${NBEEURL:-http://www.nbee.org/download/}
199
    wget -nc ${NBEEURL}${NBEESRC}.zip
200
    unzip ${NBEESRC}.zip
201
    cd ${NBEESRC}/src
202
    cmake .
203
    make
204
    cd $BUILD_DIR/
205
    sudo cp ${NBEESRC}/bin/libn*.so /usr/local/lib
206
    sudo ldconfig
207
    sudo cp -R ${NBEESRC}/include/ /usr/
208

    
209
    # Resume the install:
210
    cd $BUILD_DIR/ofsoftswitch13
211
    ./boot.sh
212
    ./configure
213
    make
214
    sudo make install
215
    cd $BUILD_DIR
216
}
217

    
218
function wireshark {
219
    echo "Installing Wireshark dissector..."
220

    
221
    sudo apt-get install -y wireshark tshark libgtk2.0-dev
222

    
223
    if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" != "10.04" ]; then
224
        # Install newer version
225
        sudo apt-get install -y scons mercurial libglib2.0-dev
226
        sudo apt-get install -y libwiretap-dev libwireshark-dev
227
        cd $BUILD_DIR
228
        hg clone https://bitbucket.org/barnstorm/of-dissector
229
        cd of-dissector
230
        if [[ -n "$WS_DISSECTOR_REV" ]]; then
231
            hg checkout ${WS_DISSECTOR_REV}
232
        fi
233
        cd src
234
        export WIRESHARK=/usr/include/wireshark
235
        scons
236
        # libwireshark0/ on 11.04; libwireshark1/ on later
237
        WSDIR=`ls -d /usr/lib/wireshark/libwireshark* | head -1`
238
        WSPLUGDIR=$WSDIR/plugins/
239
        sudo cp openflow.so $WSPLUGDIR
240
        echo "Copied openflow plugin to $WSPLUGDIR"
241
    else
242
        # Install older version from reference source
243
        cd $BUILD_DIR/openflow/utilities/wireshark_dissectors/openflow
244
        make
245
        sudo make install
246
    fi
247

    
248
    # Copy coloring rules: OF is white-on-blue:
249
    mkdir -p $HOME/.wireshark
250
    cp $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
251
}
252

    
253

    
254
# Install Open vSwitch
255
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
256

    
257
function ovs {
258
    echo "Installing Open vSwitch..."
259

    
260
    # Required for module build/dkms install
261
    $install $KERNEL_HEADERS
262

    
263
    ovspresent=0
264

    
265
    # First see if we have packages
266
    # XXX wget -c seems to fail from github/amazon s3
267
    cd /tmp
268
    if wget $OVS_PACKAGE_LOC/$OVS_PACKAGE_NAME 2> /dev/null; then
269
	$install patch dkms fakeroot python-argparse
270
        tar xf $OVS_PACKAGE_NAME
271
        orig=`tar tf $OVS_PACKAGE_NAME`
272
        # Now install packages in reasonable dependency order
273
        order='dkms common pki openvswitch-switch brcompat controller'
274
        pkgs=""
275
        for p in $order; do
276
            pkg=`echo "$orig" | grep $p`
277
	    # Annoyingly, things seem to be missing without this flag
278
            $pkginst --force-confmiss $pkg
279
        done
280
        ovspresent=1
281
    fi
282

    
283
    # Otherwise try distribution's OVS packages
284
    if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 11.10` = 1 ]; then
285
        if ! dpkg --get-selections | grep openvswitch-datapath; then
286
            # If you've already installed a datapath, assume you
287
            # know what you're doing and don't need dkms datapath.
288
            # Otherwise, install it.
289
            $install openvswitch-datapath-dkms
290
        fi
291
	if $install openvswitch-switch openvswitch-controller; then
292
            echo "Ignoring error installing openvswitch-controller"
293
        fi
294
        ovspresent=1
295
    fi
296

    
297
    # Switch can run on its own, but
298
    # Mininet should control the controller
299
    if [ -e /etc/init.d/openvswitch-controller ]; then
300
        if sudo service openvswitch-controller stop; then
301
            echo "Stopped running controller"
302
        fi
303
        sudo update-rc.d openvswitch-controller disable
304
    fi
305

    
306
    if [ $ovspresent = 1 ]; then
307
        echo "Done (hopefully) installing packages"
308
        cd $BUILD_DIR
309
        return
310
    fi
311

    
312
    # Otherwise attempt to install from source
313

    
314
    $install pkg-config gcc make python-dev libssl-dev libtool
315

    
316
    if [ "$DIST" = "Debian" ]; then
317
        if [ "$CODENAME" = "lenny" ]; then
318
            $install git-core
319
            # Install Autoconf 2.63+ backport from Debian Backports repo:
320
            # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
321
            sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
322
            sudo apt-get update
323
            sudo apt-get -y --force-yes install debian-backports-keyring
324
            sudo apt-get -y --force-yes -t lenny-backports install autoconf
325
        fi
326
    else
327
        $install git
328
    fi
329

    
330
    # Install OVS from release
331
    cd $BUILD_DIR/
332
    git clone git://openvswitch.org/openvswitch $OVS_SRC
333
    cd $OVS_SRC
334
    git checkout $OVS_TAG
335
    ./boot.sh
336
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
337
    if [ ! -e $BUILDDIR ]; then
338
        echo "Creating build sdirectory $BUILDDIR"
339
        sudo mkdir -p $BUILDDIR
340
    fi
341
    opts="--with-linux=$BUILDDIR"
342
    mkdir -p $OVS_BUILD
343
    cd $OVS_BUILD
344
    ../configure $opts
345
    make
346
    sudo make install
347

    
348
    modprobe
349
}
350

    
351
function remove_ovs {
352
    pkgs=`dpkg --get-selections | grep openvswitch | awk '{ print $1;}'`
353
    echo "Removing existing Open vSwitch packages:"
354
    echo $pkgs
355
    if ! $remove $pkgs; then
356
        echo "Not all packages removed correctly"
357
    fi
358
    # For some reason this doesn't happen
359
    if scripts=`ls /etc/init.d/*openvswitch* 2>/dev/null`; then
360
        echo $scripts
361
        for s in $scripts; do
362
            s=$(basename $s)
363
            echo SCRIPT $s
364
            sudo service $s stop
365
            sudo rm -f /etc/init.d/$s
366
            sudo update-rc.d -f $s remove
367
        done
368
    fi
369
    echo "Done removing OVS"
370
}
371

    
372
# Install NOX with tutorial files
373
function nox {
374
    echo "Installing NOX w/tutorial files..."
375

    
376
    # Install NOX deps:
377
    $install autoconf automake g++ libtool python python-twisted \
378
		swig libssl-dev make
379
    if [ "$DIST" = "Debian" ]; then
380
        $install libboost1.35-dev
381
    elif [ "$DIST" = "Ubuntu" ]; then
382
        $install python-dev libboost-dev
383
        $install libboost-filesystem-dev
384
        $install libboost-test-dev
385
    fi
386
    # Install NOX optional deps:
387
    $install libsqlite3-dev python-simplejson
388

    
389
    # Fetch NOX destiny
390
    cd $BUILD_DIR/
391
    git clone https://github.com/noxrepo/nox-classic.git noxcore
392
    cd noxcore
393
    if ! git checkout -b destiny remotes/origin/destiny ; then
394
        echo "Did not check out a new destiny branch - assuming current branch is destiny"
395
    fi
396

    
397
    # Apply patches
398
    git checkout -b tutorial-destiny
399
    git am $MININET_DIR/mininet/util/nox-patches/*tutorial-port-nox-destiny*.patch
400
    if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 12.04` = 1 ]; then
401
        git am $MININET_DIR/mininet/util/nox-patches/*nox-ubuntu12-hacks.patch
402
    fi
403

    
404
    # Build
405
    ./boot.sh
406
    mkdir build
407
    cd build
408
    ../configure
409
    make -j3
410
    #make check
411

    
412
    # Add NOX_CORE_DIR env var:
413
    sed -i -e 's|# for examples$|&\nexport NOX_CORE_DIR=$BUILD_DIR/noxcore/build/src|' ~/.bashrc
414

    
415
    # To verify this install:
416
    #cd ~/noxcore/build/src
417
    #./nox_core -v -i ptcp:
418
}
419

    
420
# Install NOX Classic/Zaku for OpenFlow 1.3
421
function nox13 {
422
    echo "Installing NOX w/tutorial files..."
423

    
424
    # Install NOX deps:
425
    $install autoconf automake g++ libtool python python-twisted \
426
        swig libssl-dev make
427
    if [ "$DIST" = "Debian" ]; then
428
        $install libboost1.35-dev
429
    elif [ "$DIST" = "Ubuntu" ]; then
430
        $install python-dev libboost-dev
431
        $install libboost-filesystem-dev
432
        $install libboost-test-dev
433
    fi
434

    
435
    # Fetch NOX destiny
436
    cd $BUILD_DIR/
437
    git clone https://github.com/CPqD/nox13oflib.git
438
    cd nox13oflib
439

    
440
    # Build
441
    ./boot.sh
442
    mkdir build
443
    cd build
444
    ../configure
445
    make -j3
446
    #make check
447

    
448
    # To verify this install:
449
    #cd ~/nox13oflib/build/src
450
    #./nox_core -v -i ptcp:
451
}
452

    
453

    
454
# "Install" POX
455
function pox {
456
    echo "Installing POX into $BUILD_DIR/pox..."
457
    cd $BUILD_DIR
458
    git clone https://github.com/noxrepo/pox.git
459
}
460

    
461
# Install OFtest
462
function oftest {
463
    echo "Installing oftest..."
464

    
465
    # Install deps:
466
    $install tcpdump python-scapy
467

    
468
    # Install oftest:
469
    cd $BUILD_DIR/
470
    git clone git://github.com/floodlight/oftest
471
}
472

    
473
# Install cbench
474
function cbench {
475
    echo "Installing cbench..."
476

    
477
    $install libsnmp-dev libpcap-dev libconfig-dev
478
    cd $BUILD_DIR/
479
    git clone git://openflow.org/oflops.git
480
    cd oflops
481
    sh boot.sh || true # possible error in autoreconf, so run twice
482
    sh boot.sh
483
    ./configure --with-openflow-src-dir=$BUILD_DIR/openflow
484
    make
485
    sudo make install || true # make install fails; force past this
486
}
487

    
488
function vm_other {
489
    echo "Doing other Mininet VM setup tasks..."
490

    
491
    # Remove avahi-daemon, which may cause unwanted discovery packets to be
492
    # sent during tests, near link status changes:
493
    echo "Removing avahi-daemon"
494
    $remove avahi-daemon
495

    
496
    # was: Disable IPv6.  Add to /etc/modprobe.d/blacklist:
497
    #echo "Attempting to disable IPv6"
498
    #if [ "$DIST" = "Ubuntu" ]; then
499
    #    BLACKLIST=/etc/modprobe.d/blacklist.conf
500
    #else
501
    #    BLACKLIST=/etc/modprobe.d/blacklist
502
    #fi
503
    #sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
504

    
505
    # Disable IPv6
506
    if ! grep 'disable IPv6' /etc/sysctl.conf; then
507
        echo 'Disabling IPv6'
508
        echo '
509
# Mininet: disable IPv6
510
net.ipv6.conf.all.disable_ipv6 = 1
511
net.ipv6.conf.default.disable_ipv6 = 1
512
net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
513
    fi
514
    # Disabling IPv6 breaks X11 forwarding via ssh
515
    line='AddressFamily inet'
516
    file='/etc/ssh/sshd_config'
517
    echo "Adding $line to $file"
518
    if ! grep "$line" $file > /dev/null; then
519
        echo "$line" | sudo tee -a $file > /dev/null
520
    fi
521

    
522
    # Enable command auto completion using sudo; modify ~/.bashrc:
523
    sed -i -e 's|# for examples$|&\ncomplete -cf sudo|' ~/.bashrc
524

    
525
    # Install tcpdump, cmd-line packet dump tool.  Also install gitk,
526
    # a graphical git history viewer.
527
    $install tcpdump gitk
528

    
529
    # Install common text editors
530
    $install vim nano emacs
531

    
532
    # Install NTP
533
    $install ntp
534

    
535
    # Set git to colorize everything.
536
    git config --global color.diff auto
537
    git config --global color.status auto
538
    git config --global color.branch auto
539

    
540
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
541
    if [ "$DIST" = "Debian" ]; then
542
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
543
    fi
544

    
545
    # Clean unneeded debs:
546
    rm -f ~/linux-headers-* ~/linux-image-*
547
}
548

    
549
# Script to copy built OVS kernel module to where modprobe will
550
# find them automatically.  Removes the need to keep an environment variable
551
# for insmod usage, and works nicely with multiple kernel versions.
552
#
553
# The downside is that after each recompilation of OVS you'll need to
554
# re-run this script.  If you're using only one kernel version, then it may be
555
# a good idea to use a symbolic link in place of the copy below.
556
function modprobe {
557
    echo "Setting up modprobe for OVS kmod..."
558

    
559
    sudo cp $OVS_KMODS $DRIVERS_DIR
560
    sudo depmod -a ${KERNEL_NAME}
561
}
562

    
563
function all {
564
    echo "Running all commands..."
565
    kernel
566
    mn_deps
567
    of
568
    wireshark
569
    ovs
570
    # NOX-classic is deprecated, but you can install it manually if desired.
571
    # nox
572
    pox
573
    oftest
574
    cbench
575
    echo "Enjoy Mininet!"
576
}
577

    
578
# Restore disk space and remove sensitive files before shipping a VM.
579
function vm_clean {
580
    echo "Cleaning VM..."
581
    sudo apt-get clean
582
    sudo apt-get autoremove
583
    sudo rm -rf /tmp/*
584
    sudo rm -rf openvswitch*.tar.gz
585

    
586
    # Remove sensistive files
587
    history -c  # note this won't work if you have multiple bash sessions
588
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
589
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
590
    sudo rm -f ~/.ssh/authorized_keys*
591

    
592
    # Remove Mininet files
593
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
594
    #sudo rm -f /usr/bin/mnexec
595

    
596
    # Clear optional dev script for SSH keychain load on boot
597
    rm -f ~/.bash_profile
598

    
599
    # Clear git changes
600
    git config --global user.name "None"
601
    git config --global user.email "None"
602

    
603
    # Note: you can shrink the .vmdk in vmware using
604
    # vmware-vdiskmanager -k *.vmdk
605
    echo "Zeroing out disk blocks for efficient compaction..."
606
    time sudo dd if=/dev/zero of=/tmp/zero bs=1M
607
    sync ; sleep 1 ; sync ; sudo rm -f /tmp/zero
608

    
609
}
610

    
611
function usage {
612
    printf '\nUsage: %s [-abcdfhkmnprtvwx03]\n\n' $(basename $0) >&2
613

    
614
    printf 'This install script attempts to install useful packages\n' >&2
615
    printf 'for Mininet. It should (hopefully) work on Ubuntu 11.10+\n' >&2
616
    printf 'If you run into trouble, try\n' >&2
617
    printf 'installing one thing at a time, and looking at the \n' >&2
618
    printf 'specific installation function in this script.\n\n' >&2
619

    
620
    printf 'options:\n' >&2
621
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
622
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
623
    printf -- ' -c: (C)lean up after kernel install\n' >&2
624
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2
625
    printf -- ' -f: install open(F)low\n' >&2
626
    printf -- ' -h: print this (H)elp message\n' >&2
627
    printf -- ' -k: install new (K)ernel\n' >&2
628
    printf -- ' -m: install Open vSwitch kernel (M)odule from source dir\n' >&2
629
    printf -- ' -n: install mini(N)et dependencies + core files\n' >&2
630
    printf -- ' -p: install (P)OX OpenFlow Controller\n' >&2
631
    printf -- ' -r: remove existing Open vSwitch packages\n' >&2
632
    printf -- ' -t: complete o(T)her Mininet VM setup tasks\n' >&2
633
    printf -- ' -v: install open (V)switch\n' >&2
634
    printf -- ' -w: install OpenFlow (w)ireshark dissector\n' >&2
635
    printf -- ' -x: install NO(X) Classic OpenFlow controller\n' >&2
636
    printf -- ' -0: (default) -0[fx] installs OpenFlow 1.0 versions\n' >&2
637
    printf -- ' -3: -3[fx] installs OpenFlow 1.3 versions\n' >&2
638
    printf -- ' -i < directory >: sets the (I)nstallation directory for Mininet dependencies\n' >&2
639
    exit 2
640
}
641

    
642
OF_VERSION=1.0
643

    
644
if [ $# -eq 0 ]
645
then
646
    all
647
else
648
    while getopts 'abcdfhkmnprtvwx03i:' OPTION
649
    do
650
      case $OPTION in
651
      a)    all;;
652
      b)    cbench;;
653
      c)    kernel_clean;;
654
      d)    vm_clean;;
655
      f)    case $OF_VERSION in
656
            1.0) of;;
657
            1.3) of13;;
658
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
659
            esac;;
660
      h)    usage;;
661
      k)    kernel;;
662
      m)    modprobe;;
663
      n)    mn_deps;;
664
      p)    pox;;
665
      r)    remove_ovs;;
666
      t)    vm_other;;
667
      v)    ovs;;
668
      w)    wireshark;;
669
      x)    case $OF_VERSION in
670
            1.0) nox;;
671
            1.3) nox13;;
672
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
673
            esac;;
674
      0)    OF_VERSION=1.0;;
675
      3)    OF_VERSION=1.3;;
676
      i)    mkdir -p $OPTARG; # ensure the directory is created
677
            BUILD_DIR="$( cd -P "$OPTARG" && pwd )"; # get the full path of the directory
678
            echo "Dependency installation directory: $BUILD_DIR";;
679
      ?)    usage;;
680
      esac
681
    done
682
    shift $(($OPTIND - 1))
683
fi