Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 136c9591

History | View | Annotate | Download (21.5 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 install_wireshark {
212
    if ! which wireshark; then
213
        echo "Installing Wireshark"
214
        if [ "$DIST" = "Fedora" ]; then
215
            $install wireshark wireshark-gnome
216
        else
217
            $install wireshark tshark
218
        fi
219
    fi
220

    
221
    # Copy coloring rules: OF is white-on-blue:
222
    echo "Optionally installing wireshark color filters"
223
    mkdir -p $HOME/.wireshark
224
    cp -n $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
225

    
226
    echo "Checking Wireshark version"
227
    WSVER=`wireshark -v | egrep -o -m 1 '[0-9\.]+' | head -1`
228
    if version_ge $WSVER 1.12; then
229
        echo "Wireshark version $WSVER >= 1.12 - returning"
230
        return
231
    fi
232

    
233
    echo "Cloning LoxiGen and building openflow.lua dissector"
234
    cd $BUILD_DIR
235
    git clone https://github.com/floodlight/loxigen.git
236
    cd loxigen
237
    make wireshark
238

    
239
    # Copy into plugin directory
240
    # libwireshark0/ on 11.04; libwireshark1/ on later
241
    WSDIR=`find /usr/lib -type d -name 'libwireshark*' | head -1`
242
    WSPLUGDIR=$WSDIR/plugins/
243
    PLUGIN=loxi_output/wireshark/openflow.lua
244
    sudo cp $PLUGIN $WSPLUGDIR
245
    echo "Copied openflow plugin $PLUGIN to $WSPLUGDIR"
246

    
247
    cd $BUILD_DIR
248
}
249

    
250

    
251
# Install Open vSwitch specific version Ubuntu package
252
function ubuntuOvs {
253
    echo "Creating and Installing Open vSwitch packages..."
254

    
255
    OVS_SRC=$BUILD_DIR/openvswitch
256
    OVS_TARBALL_LOC=http://openvswitch.org/releases
257

    
258
    if [ "$DIST" = "Ubuntu" ] && version_ge $RELEASE 12.04; then
259
        rm -rf $OVS_SRC
260
        mkdir -p $OVS_SRC
261
        cd $OVS_SRC
262

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

    
271
        # Remove any old packages
272
        $remove openvswitch-common openvswitch-datapath-dkms openvswitch-controller \
273
                openvswitch-pki openvswitch-switch
274

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

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

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

    
308

    
309
# Install Open vSwitch
310

    
311
function ovs {
312
    echo "Installing Open vSwitch..."
313

    
314
    if [ "$DIST" == "Fedora" ]; then
315
        $install openvswitch openvswitch-controller
316
        return
317
    fi
318

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

    
329
    $install openvswitch-switch openvswitch-controller
330

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

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

    
363
function ivs {
364
    echo "Installing Indigo Virtual Switch..."
365

    
366
    IVS_SRC=$BUILD_DIR/ivs
367

    
368
    # Install dependencies
369
    $install git pkg-config gcc make libnl-3-dev libnl-route-3-dev libnl-genl-3-dev
370

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

    
379
# Install NOX with tutorial files
380
function nox {
381
    echo "Installing NOX w/tutorial files..."
382

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

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

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

    
411
    # Build
412
    ./boot.sh
413
    mkdir build
414
    cd build
415
    ../configure
416
    make -j3
417
    #make check
418

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

    
422
    # To verify this install:
423
    #cd ~/noxcore/build/src
424
    #./nox_core -v -i ptcp:
425
}
426

    
427
# Install NOX Classic/Zaku for OpenFlow 1.3
428
function nox13 {
429
    echo "Installing NOX w/tutorial files..."
430

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

    
442
    # Fetch NOX destiny
443
    cd $BUILD_DIR/
444
    git clone https://github.com/CPqD/nox13oflib.git
445
    cd nox13oflib
446

    
447
    # Build
448
    ./boot.sh
449
    mkdir build
450
    cd build
451
    ../configure
452
    make -j3
453
    #make check
454

    
455
    # To verify this install:
456
    #cd ~/nox13oflib/build/src
457
    #./nox_core -v -i ptcp:
458
}
459

    
460

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

    
468
# Install OFtest
469
function oftest {
470
    echo "Installing oftest..."
471

    
472
    # Install deps:
473
    $install tcpdump python-scapy
474

    
475
    # Install oftest:
476
    cd $BUILD_DIR/
477
    git clone git://github.com/floodlight/oftest
478
}
479

    
480
# Install cbench
481
function cbench {
482
    echo "Installing cbench..."
483

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

    
499
function vm_other {
500
    echo "Doing other Mininet VM setup tasks..."
501

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

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

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

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

    
536
    # Install tcpdump, cmd-line packet dump tool.  Also install gitk,
537
    # a graphical git history viewer.
538
    $install tcpdump gitk
539

    
540
    # Install common text editors
541
    $install vim nano emacs
542

    
543
    # Install NTP
544
    $install ntp
545

    
546
    # Set git to colorize everything.
547
    git config --global color.diff auto
548
    git config --global color.status auto
549
    git config --global color.branch auto
550

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

    
556
    # Clean unneeded debs:
557
    rm -f ~/linux-headers-* ~/linux-image-*
558
}
559

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

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

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

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

    
621
    # Remove Mininet files
622
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
623
    #sudo rm -f /usr/bin/mnexec
624

    
625
    # Clear optional dev script for SSH keychain load on boot
626
    rm -f ~/.bash_profile
627

    
628
    # Clear git changes
629
    git config --global user.name "None"
630
    git config --global user.email "None"
631

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

    
638
}
639

    
640
function usage {
641
    printf '\nUsage: %s [-abcdfhikmnprtvVwx03]\n\n' $(basename $0) >&2
642

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

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

    
674
OF_VERSION=1.0
675

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