Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 15c1a0e5

History | View | Annotate | Download (21.9 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
# Command-line versions overrides that simplify custom VM creation
93
# To use, pass in the vars on the cmd line before install.sh, e.g.
94
# WS_DISSECTOR_REV=pre-ws-1.10.0 install.sh -w
95
WS_DISSECTOR_REV=${WS_DISSECTOR_REV:-""}
96
OF13_SWITCH_REV=${OF13_SWITCH_REV:-""}
97

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

    
108
        # Install custom linux headers and image:
109
        $pkginst $KERNEL_IMAGE $KERNEL_HEADERS
110

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

    
119
        # Ensure /boot/grub/menu.lst boots with initrd image:
120
        sudo update-grub
121

    
122
        # The default should be the new kernel. Otherwise, you may need to modify
123
        # /boot/grub/menu.lst to set the default to the entry corresponding to the
124
        # kernel you just installed.
125
    fi
126
}
127

    
128
function kernel_clean {
129
    echo "Cleaning kernel..."
130

    
131
    # To save disk space, remove previous kernel
132
    if ! $remove $KERNEL_IMAGE_OLD; then
133
        echo $KERNEL_IMAGE_OLD not installed.
134
    fi
135

    
136
    # Also remove downloaded packages:
137
    rm -f $HOME/linux-headers-* $HOME/linux-image-*
138
}
139

    
140
# Install Mininet deps
141
function mn_deps {
142
    echo "Installing Mininet dependencies"
143
    $install gcc make socat psmisc xterm ssh iperf iproute telnet \
144
        python-setuptools cgroup-bin ethtool help2man \
145
        pyflakes pylint pep8
146

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

    
156
    echo "Installing Mininet core"
157
    pushd $MININET_DIR/mininet
158
    sudo make install
159
    popd
160
}
161

    
162
# Install Mininet developer dependencies
163
function mn_dev {
164
    echo "Installing Mininet developer dependencies"
165
    $install doxygen doxypy texlive-fonts-recommended
166
}
167

    
168
# The following will cause a full OF install, covering:
169
# -user switch
170
# The instructions below are an abbreviated version from
171
# http://www.openflowswitch.org/wk/index.php/Debian_Install
172
# ... modified to use Debian Lenny rather than unstable.
173
function of {
174
    echo "Installing OpenFlow reference implementation..."
175
    cd $BUILD_DIR/
176
    $install git-core autoconf automake autotools-dev pkg-config \
177
		make gcc libtool libc6-dev
178
    git clone git://openflowswitch.org/openflow.git
179
    cd $BUILD_DIR/openflow
180

    
181
    # Patch controller to handle more than 16 switches
182
    patch -p1 < $MININET_DIR/mininet/util/openflow-patches/controller.patch
183

    
184
    # Resume the install:
185
    ./boot.sh
186
    ./configure
187
    make
188
    sudo make install
189
    cd $BUILD_DIR
190
}
191

    
192
function of13 {
193
    echo "Installing OpenFlow 1.3 soft switch implementation..."
194
    cd $BUILD_DIR/
195
    $install  git-core autoconf automake autotools-dev pkg-config \
196
        make gcc g++ libtool libc6-dev cmake libpcap-dev libxerces-c2-dev  \
197
        unzip libpcre3-dev flex bison libboost-dev
198

    
199
    if [ ! -d "ofsoftswitch13" ]; then
200
        git clone https://github.com/CPqD/ofsoftswitch13.git
201
        if [[ -n "$OF13_SWITCH_REV" ]]; then
202
            cd ofsoftswitch13
203
            git checkout ${OF13_SWITCH_REV}
204
            cd ..
205
        fi
206
    fi
207

    
208
    # Install netbee
209
    NBEESRC="nbeesrc-jan-10-2013"
210
    NBEEURL=${NBEEURL:-http://www.nbee.org/download/}
211
    wget -nc ${NBEEURL}${NBEESRC}.zip
212
    unzip ${NBEESRC}.zip
213
    cd ${NBEESRC}/src
214
    cmake .
215
    make
216
    cd $BUILD_DIR/
217
    sudo cp ${NBEESRC}/bin/libn*.so /usr/local/lib
218
    sudo ldconfig
219
    sudo cp -R ${NBEESRC}/include/ /usr/
220

    
221
    # Resume the install:
222
    cd $BUILD_DIR/ofsoftswitch13
223
    ./boot.sh
224
    ./configure
225
    make
226
    sudo make install
227
    cd $BUILD_DIR
228
}
229

    
230
function wireshark_version_check {
231
    # Check Wireshark version
232
    WS=$(which wireshark)
233
    WS_VER_PATCH=(1 10) # targetting wireshark 1.10.0
234
    WS_VER=($($WS --version | sed 's/[a-z ]*\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1 \2 \3/'))
235
    if [ "${WS_VER[0]}" -lt "${WS_VER_PATCH[0]}" ] ||
236
       [[ "${WS_VER[0]}" -le "${WS_VER_PATCH[0]}" && "${WS_VER[1]}" -lt "${WS_VER_PATCH[1]}" ]]
237
    then
238
        # pre-1.10.0 wireshark
239
        echo "Setting revision: pre-ws-1.10.0"
240
        WS_DISSECTOR_REV="pre-ws-1.10.0" 
241
    fi
242
}
243

    
244
function wireshark {
245
    echo "Installing Wireshark dissector..."
246

    
247
    sudo apt-get install -y wireshark tshark libgtk2.0-dev
248

    
249
    if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" != "10.04" ]; then
250
        # Install newer version
251
        sudo apt-get install -y scons mercurial libglib2.0-dev
252
        sudo apt-get install -y libwiretap-dev libwireshark-dev
253
        cd $BUILD_DIR
254
        hg clone https://bitbucket.org/barnstorm/of-dissector
255
        if [[ -z "$WS_DISSECTOR_REV" ]]; then
256
            wireshark_version_check
257
        fi
258
        cd of-dissector
259
        if [[ -n "$WS_DISSECTOR_REV" ]]; then
260
            hg checkout ${WS_DISSECTOR_REV}
261
        fi
262
        # Build dissector
263
        cd src
264
        export WIRESHARK=/usr/include/wireshark
265
        scons
266
        # libwireshark0/ on 11.04; libwireshark1/ on later
267
        WSDIR=`ls -d /usr/lib/wireshark/libwireshark* | head -1`
268
        WSPLUGDIR=$WSDIR/plugins/
269
        sudo cp openflow.so $WSPLUGDIR
270
        echo "Copied openflow plugin to $WSPLUGDIR"
271
    else
272
        # Install older version from reference source
273
        cd $BUILD_DIR/openflow/utilities/wireshark_dissectors/openflow
274
        make
275
        sudo make install
276
    fi
277

    
278
    # Copy coloring rules: OF is white-on-blue:
279
    mkdir -p $HOME/.wireshark
280
    cp $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
281
}
282

    
283

    
284
# Install Open vSwitch
285
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
286

    
287
function ovs {
288
    echo "Installing Open vSwitch..."
289

    
290
    # Required for module build/dkms install
291
    $install $KERNEL_HEADERS
292

    
293
    ovspresent=0
294

    
295
    # First see if we have packages
296
    # XXX wget -c seems to fail from github/amazon s3
297
    cd /tmp
298
    if wget $OVS_PACKAGE_LOC/$OVS_PACKAGE_NAME 2> /dev/null; then
299
	$install patch dkms fakeroot python-argparse
300
        tar xf $OVS_PACKAGE_NAME
301
        orig=`tar tf $OVS_PACKAGE_NAME`
302
        # Now install packages in reasonable dependency order
303
        order='dkms common pki openvswitch-switch brcompat controller'
304
        pkgs=""
305
        for p in $order; do
306
            pkg=`echo "$orig" | grep $p`
307
	    # Annoyingly, things seem to be missing without this flag
308
            $pkginst --force-confmiss $pkg
309
        done
310
        ovspresent=1
311
    fi
312

    
313
    # Otherwise try distribution's OVS packages
314
    if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 11.10` = 1 ]; then
315
        if ! dpkg --get-selections | grep openvswitch-datapath; then
316
            # If you've already installed a datapath, assume you
317
            # know what you're doing and don't need dkms datapath.
318
            # Otherwise, install it.
319
            $install openvswitch-datapath-dkms
320
        fi
321
	if $install openvswitch-switch openvswitch-controller; then
322
            echo "Ignoring error installing openvswitch-controller"
323
        fi
324
        ovspresent=1
325
    fi
326

    
327
    # Switch can run on its own, but
328
    # Mininet should control the controller
329
    if [ -e /etc/init.d/openvswitch-controller ]; then
330
        if sudo service openvswitch-controller stop; then
331
            echo "Stopped running controller"
332
        fi
333
        sudo update-rc.d openvswitch-controller disable
334
    fi
335

    
336
    if [ $ovspresent = 1 ]; then
337
        echo "Done (hopefully) installing packages"
338
        cd $BUILD_DIR
339
        return
340
    fi
341

    
342
    # Otherwise attempt to install from source
343

    
344
    $install pkg-config gcc make python-dev libssl-dev libtool
345

    
346
    if [ "$DIST" = "Debian" ]; then
347
        if [ "$CODENAME" = "lenny" ]; then
348
            $install git-core
349
            # Install Autoconf 2.63+ backport from Debian Backports repo:
350
            # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
351
            sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
352
            sudo apt-get update
353
            sudo apt-get -y --force-yes install debian-backports-keyring
354
            sudo apt-get -y --force-yes -t lenny-backports install autoconf
355
        fi
356
    else
357
        $install git
358
    fi
359

    
360
    # Install OVS from release
361
    cd $BUILD_DIR/
362
    git clone git://openvswitch.org/openvswitch $OVS_SRC
363
    cd $OVS_SRC
364
    git checkout $OVS_TAG
365
    ./boot.sh
366
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
367
    if [ ! -e $BUILDDIR ]; then
368
        echo "Creating build sdirectory $BUILDDIR"
369
        sudo mkdir -p $BUILDDIR
370
    fi
371
    opts="--with-linux=$BUILDDIR"
372
    mkdir -p $OVS_BUILD
373
    cd $OVS_BUILD
374
    ../configure $opts
375
    make
376
    sudo make install
377

    
378
    modprobe
379
}
380

    
381
function remove_ovs {
382
    pkgs=`dpkg --get-selections | grep openvswitch | awk '{ print $1;}'`
383
    echo "Removing existing Open vSwitch packages:"
384
    echo $pkgs
385
    if ! $remove $pkgs; then
386
        echo "Not all packages removed correctly"
387
    fi
388
    # For some reason this doesn't happen
389
    if scripts=`ls /etc/init.d/*openvswitch* 2>/dev/null`; then
390
        echo $scripts
391
        for s in $scripts; do
392
            s=$(basename $s)
393
            echo SCRIPT $s
394
            sudo service $s stop
395
            sudo rm -f /etc/init.d/$s
396
            sudo update-rc.d -f $s remove
397
        done
398
    fi
399
    echo "Done removing OVS"
400
}
401

    
402
# Install NOX with tutorial files
403
function nox {
404
    echo "Installing NOX w/tutorial files..."
405

    
406
    # Install NOX deps:
407
    $install autoconf automake g++ libtool python python-twisted \
408
		swig libssl-dev make
409
    if [ "$DIST" = "Debian" ]; then
410
        $install libboost1.35-dev
411
    elif [ "$DIST" = "Ubuntu" ]; then
412
        $install python-dev libboost-dev
413
        $install libboost-filesystem-dev
414
        $install libboost-test-dev
415
    fi
416
    # Install NOX optional deps:
417
    $install libsqlite3-dev python-simplejson
418

    
419
    # Fetch NOX destiny
420
    cd $BUILD_DIR/
421
    git clone https://github.com/noxrepo/nox-classic.git noxcore
422
    cd noxcore
423
    if ! git checkout -b destiny remotes/origin/destiny ; then
424
        echo "Did not check out a new destiny branch - assuming current branch is destiny"
425
    fi
426

    
427
    # Apply patches
428
    git checkout -b tutorial-destiny
429
    git am $MININET_DIR/mininet/util/nox-patches/*tutorial-port-nox-destiny*.patch
430
    if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 12.04` = 1 ]; then
431
        git am $MININET_DIR/mininet/util/nox-patches/*nox-ubuntu12-hacks.patch
432
    fi
433

    
434
    # Build
435
    ./boot.sh
436
    mkdir build
437
    cd build
438
    ../configure
439
    make -j3
440
    #make check
441

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

    
445
    # To verify this install:
446
    #cd ~/noxcore/build/src
447
    #./nox_core -v -i ptcp:
448
}
449

    
450
# Install NOX Classic/Zaku for OpenFlow 1.3
451
function nox13 {
452
    echo "Installing NOX w/tutorial files..."
453

    
454
    # Install NOX deps:
455
    $install autoconf automake g++ libtool python python-twisted \
456
        swig libssl-dev make
457
    if [ "$DIST" = "Debian" ]; then
458
        $install libboost1.35-dev
459
    elif [ "$DIST" = "Ubuntu" ]; then
460
        $install python-dev libboost-dev
461
        $install libboost-filesystem-dev
462
        $install libboost-test-dev
463
    fi
464

    
465
    # Fetch NOX destiny
466
    cd $BUILD_DIR/
467
    git clone https://github.com/CPqD/nox13oflib.git
468
    cd nox13oflib
469

    
470
    # Build
471
    ./boot.sh
472
    mkdir build
473
    cd build
474
    ../configure
475
    make -j3
476
    #make check
477

    
478
    # To verify this install:
479
    #cd ~/nox13oflib/build/src
480
    #./nox_core -v -i ptcp:
481
}
482

    
483

    
484
# "Install" POX
485
function pox {
486
    echo "Installing POX into $BUILD_DIR/pox..."
487
    cd $BUILD_DIR
488
    git clone https://github.com/noxrepo/pox.git
489
}
490

    
491
# Install OFtest
492
function oftest {
493
    echo "Installing oftest..."
494

    
495
    # Install deps:
496
    $install tcpdump python-scapy
497

    
498
    # Install oftest:
499
    cd $BUILD_DIR/
500
    git clone git://github.com/floodlight/oftest
501
}
502

    
503
# Install cbench
504
function cbench {
505
    echo "Installing cbench..."
506

    
507
    $install libsnmp-dev libpcap-dev libconfig-dev
508
    cd $BUILD_DIR/
509
    git clone git://openflow.org/oflops.git
510
    cd oflops
511
    sh boot.sh || true # possible error in autoreconf, so run twice
512
    sh boot.sh
513
    ./configure --with-openflow-src-dir=$BUILD_DIR/openflow
514
    make
515
    sudo make install || true # make install fails; force past this
516
}
517

    
518
function vm_other {
519
    echo "Doing other Mininet VM setup tasks..."
520

    
521
    # Remove avahi-daemon, which may cause unwanted discovery packets to be
522
    # sent during tests, near link status changes:
523
    echo "Removing avahi-daemon"
524
    $remove avahi-daemon
525

    
526
    # was: Disable IPv6.  Add to /etc/modprobe.d/blacklist:
527
    #echo "Attempting to disable IPv6"
528
    #if [ "$DIST" = "Ubuntu" ]; then
529
    #    BLACKLIST=/etc/modprobe.d/blacklist.conf
530
    #else
531
    #    BLACKLIST=/etc/modprobe.d/blacklist
532
    #fi
533
    #sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
534

    
535
    # Disable IPv6
536
    if ! grep 'disable IPv6' /etc/sysctl.conf; then
537
        echo 'Disabling IPv6'
538
        echo '
539
# Mininet: disable IPv6
540
net.ipv6.conf.all.disable_ipv6 = 1
541
net.ipv6.conf.default.disable_ipv6 = 1
542
net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
543
    fi
544
    # Disabling IPv6 breaks X11 forwarding via ssh
545
    line='AddressFamily inet'
546
    file='/etc/ssh/sshd_config'
547
    echo "Adding $line to $file"
548
    if ! grep "$line" $file > /dev/null; then
549
        echo "$line" | sudo tee -a $file > /dev/null
550
    fi
551

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

    
555
    # Install tcpdump, cmd-line packet dump tool.  Also install gitk,
556
    # a graphical git history viewer.
557
    $install tcpdump gitk
558

    
559
    # Install common text editors
560
    $install vim nano emacs
561

    
562
    # Install NTP
563
    $install ntp
564

    
565
    # Set git to colorize everything.
566
    git config --global color.diff auto
567
    git config --global color.status auto
568
    git config --global color.branch auto
569

    
570
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
571
    if [ "$DIST" = "Debian" ]; then
572
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
573
    fi
574

    
575
    # Clean unneeded debs:
576
    rm -f ~/linux-headers-* ~/linux-image-*
577
}
578

    
579
# Script to copy built OVS kernel module to where modprobe will
580
# find them automatically.  Removes the need to keep an environment variable
581
# for insmod usage, and works nicely with multiple kernel versions.
582
#
583
# The downside is that after each recompilation of OVS you'll need to
584
# re-run this script.  If you're using only one kernel version, then it may be
585
# a good idea to use a symbolic link in place of the copy below.
586
function modprobe {
587
    echo "Setting up modprobe for OVS kmod..."
588

    
589
    sudo cp $OVS_KMODS $DRIVERS_DIR
590
    sudo depmod -a ${KERNEL_NAME}
591
}
592

    
593
function all {
594
    echo "Running all commands..."
595
    kernel
596
    mn_deps
597
    mn_dev
598
    of
599
    wireshark
600
    ovs
601
    # NOX-classic is deprecated, but you can install it manually if desired.
602
    # nox
603
    pox
604
    oftest
605
    cbench
606
    echo "Enjoy Mininet!"
607
}
608

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

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

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

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

    
630
    # Clear git changes
631
    git config --global user.name "None"
632
    git config --global user.email "None"
633

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

    
640
}
641

    
642
function usage {
643
    printf '\nUsage: %s [-abcdfhkmnprtvwx03]\n\n' $(basename $0) >&2
644

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

    
651
    printf 'options:\n' >&2
652
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
653
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
654
    printf -- ' -c: (C)lean up after kernel install\n' >&2
655
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2
656
    printf -- ' -f: install open(F)low\n' >&2
657
    printf -- ' -h: print this (H)elp message\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 -- ' -e: install mininet d(E)veloper dependencies\n' >&2
662
    printf -- ' -p: install (P)OX OpenFlow Controller\n' >&2
663
    printf -- ' -r: remove existing Open vSwitch packages\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 -- ' -w: install OpenFlow (w)ireshark dissector\n' >&2
667
    printf -- ' -x: install NO(X) Classic OpenFlow controller\n' >&2
668
    printf -- ' -0: (default) -0[fx] installs OpenFlow 1.0 versions\n' >&2
669
    printf -- ' -3: -3[fx] installs OpenFlow 1.3 versions\n' >&2
670
    printf -- ' -i < directory >: sets the (I)nstallation directory for Mininet dependencies\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 'abcdefhkmnprtvwx03i:' OPTION
681
    do
682
      case $OPTION in
683
      a)    all;;
684
      b)    cbench;;
685
      c)    kernel_clean;;
686
      d)    vm_clean;;
687
      f)    case $OF_VERSION in
688
            1.0) of;;
689
            1.3) of13;;
690
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
691
            esac;;
692
      h)    usage;;
693
      k)    kernel;;
694
      m)    modprobe;;
695
      n)    mn_deps;;
696
      e)    mn_dev;;
697
      p)    pox;;
698
      r)    remove_ovs;;
699
      t)    vm_other;;
700
      v)    ovs;;
701
      w)    wireshark;;
702
      x)    case $OF_VERSION in
703
            1.0) nox;;
704
            1.3) nox13;;
705
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
706
            esac;;
707
      0)    OF_VERSION=1.0;;
708
      3)    OF_VERSION=1.3;;
709
      i)    mkdir -p $OPTARG; # ensure the directory is created
710
            BUILD_DIR="$( cd -P "$OPTARG" && pwd )"; # get the full path of the directory
711
            echo "Dependency installation directory: $BUILD_DIR";;
712
      ?)    usage;;
713
      esac
714
    done
715
    shift $(($OPTIND - 1))
716
fi