Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 47be38e6

History | View | Annotate | Download (21.3 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 -P )"
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 -P)"
19
case $BUILD_DIR in
20
  $MININET_DIR/*) BUILD_DIR=$MININET_DIR;; # currect directory is a subdirectory
21
  *) BUILD_DIR=$BUILD_DIR;;
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
fi
47
test -e /etc/fedora-release && DIST="Fedora"
48
if [ "$DIST" = "Fedora" ]; then
49
    install='sudo yum -y install'
50
    remove='sudo yum -y erase'
51
    pkginst='sudo rpm -ivh'
52
    # Prereqs for this script
53
    if ! which lsb_release &> /dev/null; then
54
        $install redhat-lsb-core
55
    fi
56
fi
57
if which lsb_release &> /dev/null; then
58
    DIST=`lsb_release -is`
59
    RELEASE=`lsb_release -rs`
60
    CODENAME=`lsb_release -cs`
61
fi
62
echo "Detected Linux distribution: $DIST $RELEASE $CODENAME $ARCH"
63

    
64
# Kernel params
65

    
66
KERNEL_NAME=`uname -r`
67
KERNEL_HEADERS=kernel-headers-${KERNEL_NAME}
68

    
69
if ! echo $DIST | egrep 'Ubuntu|Debian|Fedora'; then
70
    echo "Install.sh currently only supports Ubuntu, Debian and Fedora."
71
    exit 1
72
fi
73

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

    
77

    
78
# Determine whether version $1 >= version $2
79
# usage: if version_ge 1.20 1.2.3; then echo "true!"; fi
80
function version_ge {
81
    # sort -V sorts by *version number*
82
    latest=`printf "$1\n$2" | sort -V | tail -1`
83
    # If $1 is latest version, then $1 >= $2
84
    [ "$1" == "$latest" ]
85
}
86

    
87

    
88
# Kernel Deb pkg to be removed:
89
KERNEL_IMAGE_OLD=linux-image-2.6.26-33-generic
90

    
91
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
92

    
93
OVS_RELEASE=1.4.0
94
OVS_PACKAGE_LOC=https://github.com/downloads/mininet/mininet
95
OVS_BUILDSUFFIX=-ignore # was -2
96
OVS_PACKAGE_NAME=ovs-$OVS_RELEASE-core-$DIST_LC-$RELEASE-$ARCH$OVS_BUILDSUFFIX.tar
97
OVS_TAG=v$OVS_RELEASE
98

    
99
OF13_SWITCH_REV=${OF13_SWITCH_REV:-""}
100

    
101

    
102
function kernel {
103
    echo "Install Mininet-compatible kernel if necessary"
104
    sudo apt-get update
105
    $install linux-image-$KERNEL_NAME
106
}
107

    
108
function kernel_clean {
109
    echo "Cleaning kernel..."
110

    
111
    # To save disk space, remove previous kernel
112
    if ! $remove $KERNEL_IMAGE_OLD; then
113
        echo $KERNEL_IMAGE_OLD not installed.
114
    fi
115

    
116
    # Also remove downloaded packages:
117
    rm -f $HOME/linux-headers-* $HOME/linux-image-*
118
}
119

    
120
# Install Mininet deps
121
function mn_deps {
122
    echo "Installing Mininet dependencies"
123
    if [ "$DIST" = "Fedora" ]; then
124
        $install gcc make socat psmisc xterm openssh-clients iperf \
125
            iproute telnet python-setuptools libcgroup-tools \
126
            ethtool help2man pyflakes pylint python-pep8
127
    else
128
        $install gcc make socat psmisc xterm ssh iperf iproute telnet \
129
            python-setuptools cgroup-bin ethtool help2man \
130
            pyflakes pylint pep8
131
    fi
132

    
133
    echo "Installing Mininet core"
134
    pushd $MININET_DIR/mininet
135
    sudo make install
136
    popd
137
}
138

    
139
# Install Mininet developer dependencies
140
function mn_dev {
141
    echo "Installing Mininet developer dependencies"
142
    $install doxygen doxypy texlive-fonts-recommended
143
}
144

    
145
# The following will cause a full OF install, covering:
146
# -user switch
147
# The instructions below are an abbreviated version from
148
# http://www.openflowswitch.org/wk/index.php/Debian_Install
149
function of {
150
    echo "Installing OpenFlow reference implementation..."
151
    cd $BUILD_DIR
152
    $install autoconf automake libtool make gcc
153
    if [ "$DIST" = "Fedora" ]; then
154
        $install git pkgconfig glibc-devel
155
    else
156
        $install git-core autotools-dev pkg-config libc6-dev
157
    fi
158
    git clone git://openflowswitch.org/openflow.git
159
    cd $BUILD_DIR/openflow
160

    
161
    # Patch controller to handle more than 16 switches
162
    patch -p1 < $MININET_DIR/mininet/util/openflow-patches/controller.patch
163

    
164
    # Resume the install:
165
    ./boot.sh
166
    ./configure
167
    make
168
    sudo make install
169
    cd $BUILD_DIR
170
}
171

    
172
function of13 {
173
    echo "Installing OpenFlow 1.3 soft switch implementation..."
174
    cd $BUILD_DIR/
175
    $install  git-core autoconf automake autotools-dev pkg-config \
176
        make gcc g++ libtool libc6-dev cmake libpcap-dev libxerces-c2-dev  \
177
        unzip libpcre3-dev flex bison libboost-dev
178

    
179
    if [ ! -d "ofsoftswitch13" ]; then
180
        git clone https://github.com/CPqD/ofsoftswitch13.git
181
        if [[ -n "$OF13_SWITCH_REV" ]]; then
182
            cd ofsoftswitch13
183
            git checkout ${OF13_SWITCH_REV}
184
            cd ..
185
        fi
186
    fi
187

    
188
    # Install netbee
189
    NBEESRC="nbeesrc-jan-10-2013"
190
    NBEEURL=${NBEEURL:-http://www.nbee.org/download/}
191
    wget -nc ${NBEEURL}${NBEESRC}.zip
192
    unzip ${NBEESRC}.zip
193
    cd ${NBEESRC}/src
194
    cmake .
195
    make
196
    cd $BUILD_DIR/
197
    sudo cp ${NBEESRC}/bin/libn*.so /usr/local/lib
198
    sudo ldconfig
199
    sudo cp -R ${NBEESRC}/include/ /usr/
200

    
201
    # Resume the install:
202
    cd $BUILD_DIR/ofsoftswitch13
203
    ./boot.sh
204
    ./configure
205
    make
206
    sudo make install
207
    cd $BUILD_DIR
208
}
209

    
210

    
211
function wireshark {
212
    echo "Installing Wireshark"
213
    if [ "$DIST" = "Fedora" ]; then
214
        $install wireshark wireshark-gnome
215
    else
216
        $install wireshark tshark
217
    fi
218

    
219
    echo "Checking Wireshark version"
220
    WSVER=`wireshark -v | egrep -o '[0-9\.]+' | head -1`
221
    if version_ge $WSVER 1.12; then
222
        echo "Wireshark version $WSVER >= 1.12 - returning"
223
        return
224
    fi
225

    
226
    echo "Cloning LoxiGen and building openflow.lua dissector"
227
    cd $BUILD_DIR
228
    git clone https://github.com/floodlight/loxigen.git
229
    cd loxigen
230
    make wireshark
231

    
232
    # Copy into plugin directory
233
    # libwireshark0/ on 11.04; libwireshark1/ on later
234
    WSDIR=`find /usr/lib -type d -name 'libwireshark*' | head -1`
235
    WSPLUGDIR=$WSDIR/plugins/
236
    PLUGIN=loxi_output/wireshark/openflow.lua
237
    sudo cp $PLUGIN $WSPLUGDIR
238
    echo "Copied openflow plugin $PLUGIN to $WSPLUGDIR"
239

    
240
    # Copy coloring rules: OF is white-on-blue:
241
    mkdir -p $HOME/.wireshark
242
    cp $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
243

    
244
    cd $BUILD_DIR
245
}
246

    
247

    
248
# Install Open vSwitch specific version Ubuntu package
249
function ubuntuOvs {
250
    echo "Creating and Installing Open vSwitch packages..."
251

    
252
    OVS_SRC=$BUILD_DIR/openvswitch
253
    OVS_TARBALL_LOC=http://openvswitch.org/releases
254

    
255
    if [ "$DIST" = "Ubuntu" ] && version_ge $RELEASE 12.04; then
256
        rm -rf $OVS_SRC
257
        mkdir -p $OVS_SRC
258
        cd $OVS_SRC
259

    
260
        if wget $OVS_TARBALL_LOC/openvswitch-$OVS_RELEASE.tar.gz 2> /dev/null; then
261
            tar xzf openvswitch-$OVS_RELEASE.tar.gz
262
        else
263
            echo "Failed to find OVS at $OVS_TARBALL_LOC/openvswitch-$OVS_RELEASE.tar.gz"
264
            cd $BUILD_DIR
265
            return
266
        fi
267

    
268
        # Remove any old packages
269
        $remove openvswitch-common openvswitch-datapath-dkms openvswitch-controller \
270
                openvswitch-pki openvswitch-switch
271

    
272
        # Get build deps
273
        $install build-essential fakeroot debhelper autoconf automake libssl-dev \
274
                 pkg-config bzip2 openssl python-all procps python-qt4 \
275
                 python-zopeinterface python-twisted-conch dkms
276

    
277
        # Build OVS
278
        cd $BUILD_DIR/openvswitch/openvswitch-$OVS_RELEASE
279
                DEB_BUILD_OPTIONS='parallel=2 nocheck' fakeroot debian/rules binary
280
        cd ..
281
        $pkginst openvswitch-common_$OVS_RELEASE*.deb openvswitch-datapath-dkms_$OVS_RELEASE*.deb \
282
                 openvswitch-pki_$OVS_RELEASE*.deb openvswitch-switch_$OVS_RELEASE*.deb
283
        if $pkginst openvswitch-controller_$OVS_RELEASE*.deb; then
284
            echo "Ignoring error installing openvswitch-controller"
285
        fi
286

    
287
        modinfo openvswitch
288
        sudo ovs-vsctl show
289
        # Switch can run on its own, but
290
        # Mininet should control the controller
291
        # This appears to only be an issue on Ubuntu/Debian
292
        if sudo service openvswitch-controller stop; then
293
            echo "Stopped running controller"
294
        fi
295
        if [ -e /etc/init.d/openvswitch-controller ]; then
296
            sudo update-rc.d openvswitch-controller disable
297
        fi
298
    else
299
        echo "Failed to install Open vSwitch.  OS must be Ubuntu >= 12.04"
300
            cd $BUILD_DIR
301
            return
302
    fi
303
}
304

    
305

    
306
# Install Open vSwitch
307

    
308
function ovs {
309
    echo "Installing Open vSwitch..."
310

    
311
    if [ "$DIST" == "Fedora" ]; then
312
        $install openvswitch openvswitch-controller
313
        return
314
    fi
315

    
316
    # Manually installing openvswitch-datapath may be necessary
317
    # for manually built kernel .debs using Debian's defective kernel
318
    # packaging, which doesn't yield usable headers.
319
    if ! dpkg --get-selections | grep openvswitch-datapath; then
320
        # If you've already installed a datapath, assume you
321
        # know what you're doing and don't need dkms datapath.
322
        # Otherwise, install it.
323
        $install openvswitch-datapath-dkms
324
    fi
325

    
326
    $install openvswitch-switch openvswitch-controller
327

    
328
    # Switch can run on its own, but
329
    # Mininet should control the controller
330
    # This appears to only be an issue on Ubuntu/Debian
331
    if sudo service openvswitch-controller stop; then
332
        echo "Stopped running controller"
333
    fi
334
    if [ -e /etc/init.d/openvswitch-controller ]; then
335
        sudo update-rc.d openvswitch-controller disable
336
    fi
337
}
338

    
339
function remove_ovs {
340
    pkgs=`dpkg --get-selections | grep openvswitch | awk '{ print $1;}'`
341
    echo "Removing existing Open vSwitch packages:"
342
    echo $pkgs
343
    if ! $remove $pkgs; then
344
        echo "Not all packages removed correctly"
345
    fi
346
    # For some reason this doesn't happen
347
    if scripts=`ls /etc/init.d/*openvswitch* 2>/dev/null`; then
348
        echo $scripts
349
        for s in $scripts; do
350
            s=$(basename $s)
351
            echo SCRIPT $s
352
            sudo service $s stop
353
            sudo rm -f /etc/init.d/$s
354
            sudo update-rc.d -f $s remove
355
        done
356
    fi
357
    echo "Done removing OVS"
358
}
359

    
360
function ivs {
361
    echo "Installing Indigo Virtual Switch..."
362

    
363
    IVS_SRC=$BUILD_DIR/ivs
364

    
365
    # Install dependencies
366
    $install git pkg-config gcc make libnl-3-dev libnl-route-3-dev libnl-genl-3-dev
367

    
368
    # Install IVS from source
369
    cd $BUILD_DIR
370
    git clone git://github.com/floodlight/ivs $IVS_SRC --recursive
371
    cd $IVS_SRC
372
    make
373
    sudo make install
374
}
375

    
376
# Install NOX with tutorial files
377
function nox {
378
    echo "Installing NOX w/tutorial files..."
379

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

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

    
401
    # Apply patches
402
    git checkout -b tutorial-destiny
403
    git am $MININET_DIR/mininet/util/nox-patches/*tutorial-port-nox-destiny*.patch
404
    if [ "$DIST" = "Ubuntu" ] && version_ge $RELEASE 12.04; then
405
        git am $MININET_DIR/mininet/util/nox-patches/*nox-ubuntu12-hacks.patch
406
    fi
407

    
408
    # Build
409
    ./boot.sh
410
    mkdir build
411
    cd build
412
    ../configure
413
    make -j3
414
    #make check
415

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

    
419
    # To verify this install:
420
    #cd ~/noxcore/build/src
421
    #./nox_core -v -i ptcp:
422
}
423

    
424
# Install NOX Classic/Zaku for OpenFlow 1.3
425
function nox13 {
426
    echo "Installing NOX w/tutorial files..."
427

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

    
439
    # Fetch NOX destiny
440
    cd $BUILD_DIR/
441
    git clone https://github.com/CPqD/nox13oflib.git
442
    cd nox13oflib
443

    
444
    # Build
445
    ./boot.sh
446
    mkdir build
447
    cd build
448
    ../configure
449
    make -j3
450
    #make check
451

    
452
    # To verify this install:
453
    #cd ~/nox13oflib/build/src
454
    #./nox_core -v -i ptcp:
455
}
456

    
457

    
458
# "Install" POX
459
function pox {
460
    echo "Installing POX into $BUILD_DIR/pox..."
461
    cd $BUILD_DIR
462
    git clone https://github.com/noxrepo/pox.git
463
}
464

    
465
# Install OFtest
466
function oftest {
467
    echo "Installing oftest..."
468

    
469
    # Install deps:
470
    $install tcpdump python-scapy
471

    
472
    # Install oftest:
473
    cd $BUILD_DIR/
474
    git clone git://github.com/floodlight/oftest
475
}
476

    
477
# Install cbench
478
function cbench {
479
    echo "Installing cbench..."
480

    
481
    if [ "$DIST" = "Fedora" ]; then
482
        $install net-snmp-devel libpcap-devel libconfig-devel
483
    else
484
        $install libsnmp-dev libpcap-dev libconfig-dev
485
    fi
486
    cd $BUILD_DIR/
487
    git clone git://gitosis.stanford.edu/oflops.git
488
    cd oflops
489
    sh boot.sh || true # possible error in autoreconf, so run twice
490
    sh boot.sh
491
    ./configure --with-openflow-src-dir=$BUILD_DIR/openflow
492
    make
493
    sudo make install || true # make install fails; force past this
494
}
495

    
496
function vm_other {
497
    echo "Doing other Mininet VM setup tasks..."
498

    
499
    # Remove avahi-daemon, which may cause unwanted discovery packets to be
500
    # sent during tests, near link status changes:
501
    echo "Removing avahi-daemon"
502
    $remove avahi-daemon
503

    
504
    # was: Disable IPv6.  Add to /etc/modprobe.d/blacklist:
505
    #echo "Attempting to disable IPv6"
506
    #if [ "$DIST" = "Ubuntu" ]; then
507
    #    BLACKLIST=/etc/modprobe.d/blacklist.conf
508
    #else
509
    #    BLACKLIST=/etc/modprobe.d/blacklist
510
    #fi
511
    #sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
512

    
513
    # Disable IPv6
514
    if ! grep 'disable IPv6' /etc/sysctl.conf; then
515
        echo 'Disabling IPv6'
516
        echo '
517
# Mininet: disable IPv6
518
net.ipv6.conf.all.disable_ipv6 = 1
519
net.ipv6.conf.default.disable_ipv6 = 1
520
net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
521
    fi
522
    # Disabling IPv6 breaks X11 forwarding via ssh
523
    line='AddressFamily inet'
524
    file='/etc/ssh/sshd_config'
525
    echo "Adding $line to $file"
526
    if ! grep "$line" $file > /dev/null; then
527
        echo "$line" | sudo tee -a $file > /dev/null
528
    fi
529

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

    
533
    # Install tcpdump, cmd-line packet dump tool.  Also install gitk,
534
    # a graphical git history viewer.
535
    $install tcpdump gitk
536

    
537
    # Install common text editors
538
    $install vim nano emacs
539

    
540
    # Install NTP
541
    $install ntp
542

    
543
    # Set git to colorize everything.
544
    git config --global color.diff auto
545
    git config --global color.status auto
546
    git config --global color.branch auto
547

    
548
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
549
    if [ "$DIST" = "Debian" ]; then
550
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
551
    fi
552

    
553
    # Clean unneeded debs:
554
    rm -f ~/linux-headers-* ~/linux-image-*
555
}
556

    
557
# Script to copy built OVS kernel module to where modprobe will
558
# find them automatically.  Removes the need to keep an environment variable
559
# for insmod usage, and works nicely with multiple kernel versions.
560
#
561
# The downside is that after each recompilation of OVS you'll need to
562
# re-run this script.  If you're using only one kernel version, then it may be
563
# a good idea to use a symbolic link in place of the copy below.
564
function modprobe {
565
    echo "Setting up modprobe for OVS kmod..."
566
    set +o nounset
567
    if [ -z "$OVS_KMODS" ]; then
568
      echo "OVS_KMODS not set. Aborting."
569
    else
570
      sudo cp $OVS_KMODS $DRIVERS_DIR
571
      sudo depmod -a ${KERNEL_NAME}
572
    fi
573
    set -o nounset
574
}
575

    
576
function all {
577
    if [ "$DIST" = "Fedora" ]; then
578
        printf "\nFedora 18+ support (still work in progress):\n"
579
        printf " * Fedora 18+ has kernel 3.10 RPMS in the updates repositories\n"
580
        printf " * Fedora 18+ has openvswitch 1.10 RPMS in the updates repositories\n"
581
        printf " * the install.sh script options [-bfnpvw] should work.\n"
582
        printf " * for a basic setup just try:\n"
583
        printf "       install.sh -fnpv\n\n"
584
        exit 3
585
    fi
586
    echo "Installing all packages except for -eix (doxypy, ivs, nox-classic)..."
587
    kernel
588
    mn_deps
589
    # Skip mn_dev (doxypy/texlive/fonts/etc.) because it's huge
590
    # mn_dev
591
    of
592
    wireshark
593
    ovs
594
    # We may add ivs once it's more mature
595
    # ivs
596
    # NOX-classic is deprecated, but you can install it manually if desired.
597
    # nox
598
    pox
599
    oftest
600
    cbench
601
    echo "Enjoy Mininet!"
602
}
603

    
604
# Restore disk space and remove sensitive files before shipping a VM.
605
function vm_clean {
606
    echo "Cleaning VM..."
607
    sudo apt-get clean
608
    sudo apt-get autoremove
609
    sudo rm -rf /tmp/*
610
    sudo rm -rf openvswitch*.tar.gz
611

    
612
    # Remove sensistive files
613
    history -c  # note this won't work if you have multiple bash sessions
614
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
615
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
616
    sudo rm -f ~/.ssh/authorized_keys*
617

    
618
    # Remove Mininet files
619
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
620
    #sudo rm -f /usr/bin/mnexec
621

    
622
    # Clear optional dev script for SSH keychain load on boot
623
    rm -f ~/.bash_profile
624

    
625
    # Clear git changes
626
    git config --global user.name "None"
627
    git config --global user.email "None"
628

    
629
    # Note: you can shrink the .vmdk in vmware using
630
    # vmware-vdiskmanager -k *.vmdk
631
    echo "Zeroing out disk blocks for efficient compaction..."
632
    time sudo dd if=/dev/zero of=/tmp/zero bs=1M
633
    sync ; sleep 1 ; sync ; sudo rm -f /tmp/zero
634

    
635
}
636

    
637
function usage {
638
    printf '\nUsage: %s [-abcdfhikmnprtvVwx03]\n\n' $(basename $0) >&2
639

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

    
646
    printf 'options:\n' >&2
647
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
648
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
649
    printf -- ' -c: (C)lean up after kernel install\n' >&2
650
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2
651
    printf -- ' -e: install Mininet d(E)veloper dependencies\n' >&2
652
    printf -- ' -f: install Open(F)low\n' >&2
653
    printf -- ' -h: print this (H)elp message\n' >&2
654
    printf -- ' -i: install (I)ndigo Virtual Switch\n' >&2
655
    printf -- ' -k: install new (K)ernel\n' >&2
656
    printf -- ' -m: install Open vSwitch kernel (M)odule from source dir\n' >&2
657
    printf -- ' -n: install Mini(N)et dependencies + core files\n' >&2
658
    printf -- ' -p: install (P)OX OpenFlow Controller\n' >&2
659
    printf -- ' -r: remove existing Open vSwitch packages\n' >&2
660
    printf -- ' -s <dir>: place dependency (S)ource/build trees in <dir>\n' >&2
661
    printf -- ' -t: complete o(T)her Mininet VM setup tasks\n' >&2
662
    printf -- ' -v: install Open (V)switch\n' >&2
663
    printf -- ' -V <version>: install a particular version of Open (V)switch on Ubuntu\n' >&2
664
    printf -- ' -w: install OpenFlow (W)ireshark dissector\n' >&2
665
    printf -- ' -x: install NO(X) Classic OpenFlow controller\n' >&2
666
    printf -- ' -0: (default) -0[fx] installs OpenFlow 1.0 versions\n' >&2
667
    printf -- ' -3: -3[fx] installs OpenFlow 1.3 versions\n' >&2
668
    exit 2
669
}
670

    
671
OF_VERSION=1.0
672

    
673
if [ $# -eq 0 ]
674
then
675
    all
676
else
677
    while getopts 'abcdefhikmnprs:tvV:wx03' OPTION
678
    do
679
      case $OPTION in
680
      a)    all;;
681
      b)    cbench;;
682
      c)    kernel_clean;;
683
      d)    vm_clean;;
684
      e)    mn_dev;;
685
      f)    case $OF_VERSION in
686
            1.0) of;;
687
            1.3) of13;;
688
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
689
            esac;;
690
      h)    usage;;
691
      i)    ivs;;
692
      k)    kernel;;
693
      m)    modprobe;;
694
      n)    mn_deps;;
695
      p)    pox;;
696
      r)    remove_ovs;;
697
      s)    mkdir -p $OPTARG; # ensure the directory is created
698
            BUILD_DIR="$( cd -P "$OPTARG" && pwd )"; # get the full path
699
            echo "Dependency installation directory: $BUILD_DIR";;
700
      t)    vm_other;;
701
      v)    ovs;;
702
      V)    OVS_RELEASE=$OPTARG;
703
            ubuntuOvs;;
704
      w)    wireshark;;
705
      x)    case $OF_VERSION in
706
            1.0) nox;;
707
            1.3) nox13;;
708
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
709
            esac;;
710
      0)    OF_VERSION=1.0;;
711
      3)    OF_VERSION=1.3;;
712
      ?)    usage;;
713
      esac
714
    done
715
    shift $(($OPTIND - 1))
716
fi