Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 15f2d240

History | View | Annotate | Download (22.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
test -e /etc/fedora-release && DIST="Fedora"
51
if [ "$DIST" = "Fedora" ]; then
52
    install='sudo yum -y install'
53
    remove='sudo yum -y erase'
54
    pkginst='sudo rpm -ivh'
55
    # Prereqs for this script
56
    if ! which lsb_release &> /dev/null; then
57
        $install redhat-lsb-core
58
    fi
59
    if ! which bc &> /dev/null; then
60
        $install bc
61
    fi
62
fi
63
if which lsb_release &> /dev/null; then
64
    DIST=`lsb_release -is`
65
    RELEASE=`lsb_release -rs`
66
    CODENAME=`lsb_release -cs`
67
fi
68
echo "Detected Linux distribution: $DIST $RELEASE $CODENAME $ARCH"
69

    
70
# Kernel params
71

    
72
if [ "$DIST" = "Ubuntu" ]; then
73
    if [ "$RELEASE" = "10.04" ]; then
74
        KERNEL_NAME='3.0.0-15-generic'
75
    else
76
        KERNEL_NAME=`uname -r`
77
    fi
78
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}
79
elif [ "$DIST" = "Debian" ] && [ "$ARCH" = "i386" ] && [ "$CODENAME" = "lenny" ]; then
80
    KERNEL_NAME=2.6.33.1-mininet
81
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
82
    KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
83
elif [ "$DIST" = "Fedora" ]; then
84
    KERNEL_NAME=`uname -r`
85
    KERNEL_HEADERS=kernel-headers-${KERNEL_NAME}
86
else
87
    echo "Install.sh currently only supports Ubuntu, Debian Lenny i386 and Fedora."
88
    exit 1
89
fi
90

    
91
# More distribution info
92
DIST_LC=`echo $DIST | tr [A-Z] [a-z]` # as lower case
93

    
94
# Kernel Deb pkg to be removed:
95
KERNEL_IMAGE_OLD=linux-image-2.6.26-33-generic
96

    
97
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
98

    
99
OVS_RELEASE=1.4.0
100
OVS_PACKAGE_LOC=https://github.com/downloads/mininet/mininet
101
OVS_BUILDSUFFIX=-ignore # was -2
102
OVS_PACKAGE_NAME=ovs-$OVS_RELEASE-core-$DIST_LC-$RELEASE-$ARCH$OVS_BUILDSUFFIX.tar
103
OVS_TAG=v$OVS_RELEASE
104

    
105
IVS_TAG=v0.3
106

    
107
# Command-line versions overrides that simplify custom VM creation
108
# To use, pass in the vars on the cmd line before install.sh, e.g.
109
# WS_DISSECTOR_REV=pre-ws-1.10.0 install.sh -w
110
WS_DISSECTOR_REV=${WS_DISSECTOR_REV:-""}
111
OF13_SWITCH_REV=${OF13_SWITCH_REV:-""}
112

    
113

    
114
function kernel {
115
    echo "Install Mininet-compatible kernel if necessary"
116
    sudo apt-get update
117
    if [ "$DIST" = "Ubuntu" ] &&  [ "$RELEASE" = "10.04" ]; then
118
        $install linux-image-$KERNEL_NAME
119
    elif [ "$DIST" = "Debian" ]; then
120
        # The easy approach: download pre-built linux-image and linux-headers packages:
121
        wget -c $KERNEL_LOC/$KERNEL_HEADERS
122
        wget -c $KERNEL_LOC/$KERNEL_IMAGE
123

    
124
        # Install custom linux headers and image:
125
        $pkginst $KERNEL_IMAGE $KERNEL_HEADERS
126

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

    
135
        # Ensure /boot/grub/menu.lst boots with initrd image:
136
        sudo update-grub
137

    
138
        # The default should be the new kernel. Otherwise, you may need to modify
139
        # /boot/grub/menu.lst to set the default to the entry corresponding to the
140
        # kernel you just installed.
141
    fi
142
}
143

    
144
function kernel_clean {
145
    echo "Cleaning kernel..."
146

    
147
    # To save disk space, remove previous kernel
148
    if ! $remove $KERNEL_IMAGE_OLD; then
149
        echo $KERNEL_IMAGE_OLD not installed.
150
    fi
151

    
152
    # Also remove downloaded packages:
153
    rm -f $HOME/linux-headers-* $HOME/linux-image-*
154
}
155

    
156
# Install Mininet deps
157
function mn_deps {
158
    echo "Installing Mininet dependencies"
159
    if [ "$DIST" = "Fedora" ]; then
160
        $install gcc make socat psmisc xterm openssh-clients iperf \
161
            iproute telnet python-setuptools libcgroup-tools \
162
            ethtool help2man pyflakes pylint python-pep8
163
    else
164
        $install gcc make socat psmisc xterm ssh iperf iproute telnet \
165
            python-setuptools cgroup-bin ethtool help2man \
166
            pyflakes pylint pep8
167
    fi
168

    
169
    echo "Installing Mininet core"
170
    pushd $MININET_DIR/mininet
171
    sudo make install
172
    popd
173
}
174

    
175
# Install Mininet developer dependencies
176
function mn_dev {
177
    echo "Installing Mininet developer dependencies"
178
    $install doxygen doxypy texlive-fonts-recommended
179
}
180

    
181
# The following will cause a full OF install, covering:
182
# -user switch
183
# The instructions below are an abbreviated version from
184
# http://www.openflowswitch.org/wk/index.php/Debian_Install
185
# ... modified to use Debian Lenny rather than unstable.
186
function of {
187
    echo "Installing OpenFlow reference implementation..."
188
    cd $BUILD_DIR/
189
    $install git-core autoconf automake autotools-dev pkg-config \
190
		make gcc libtool libc6-dev
191
    git clone git://openflowswitch.org/openflow.git
192
    cd $BUILD_DIR/openflow
193

    
194
    # Patch controller to handle more than 16 switches
195
    patch -p1 < $MININET_DIR/mininet/util/openflow-patches/controller.patch
196

    
197
    # Resume the install:
198
    ./boot.sh
199
    ./configure
200
    make
201
    sudo make install
202
    cd $BUILD_DIR
203
}
204

    
205
function of13 {
206
    echo "Installing OpenFlow 1.3 soft switch implementation..."
207
    cd $BUILD_DIR/
208
    $install  git-core autoconf automake autotools-dev pkg-config \
209
        make gcc g++ libtool libc6-dev cmake libpcap-dev libxerces-c2-dev  \
210
        unzip libpcre3-dev flex bison libboost-dev
211

    
212
    if [ ! -d "ofsoftswitch13" ]; then
213
        git clone https://github.com/CPqD/ofsoftswitch13.git
214
        if [[ -n "$OF13_SWITCH_REV" ]]; then
215
            cd ofsoftswitch13
216
            git checkout ${OF13_SWITCH_REV}
217
            cd ..
218
        fi
219
    fi
220

    
221
    # Install netbee
222
    NBEESRC="nbeesrc-jan-10-2013"
223
    NBEEURL=${NBEEURL:-http://www.nbee.org/download/}
224
    wget -nc ${NBEEURL}${NBEESRC}.zip
225
    unzip ${NBEESRC}.zip
226
    cd ${NBEESRC}/src
227
    cmake .
228
    make
229
    cd $BUILD_DIR/
230
    sudo cp ${NBEESRC}/bin/libn*.so /usr/local/lib
231
    sudo ldconfig
232
    sudo cp -R ${NBEESRC}/include/ /usr/
233

    
234
    # Resume the install:
235
    cd $BUILD_DIR/ofsoftswitch13
236
    ./boot.sh
237
    ./configure
238
    make
239
    sudo make install
240
    cd $BUILD_DIR
241
}
242

    
243
function wireshark_version_check {
244
    # Check Wireshark version
245
    WS=$(which wireshark)
246
    WS_VER_PATCH=(1 10) # targetting wireshark 1.10.0
247
    WS_VER=($($WS --version | sed 's/[a-z ]*\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1 \2 \3/'))
248
    if [ "${WS_VER[0]}" -lt "${WS_VER_PATCH[0]}" ] ||
249
       [[ "${WS_VER[0]}" -le "${WS_VER_PATCH[0]}" && "${WS_VER[1]}" -lt "${WS_VER_PATCH[1]}" ]]
250
    then
251
        # pre-1.10.0 wireshark
252
        echo "Setting revision: pre-ws-1.10.0"
253
        WS_DISSECTOR_REV="pre-ws-1.10.0" 
254
    fi
255
}
256

    
257
function wireshark {
258
    echo "Installing Wireshark dissector..."
259

    
260
    sudo apt-get install -y wireshark tshark libgtk2.0-dev
261

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

    
291
    # Copy coloring rules: OF is white-on-blue:
292
    mkdir -p $HOME/.wireshark
293
    cp $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
294
}
295

    
296

    
297
# Install Open vSwitch
298
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
299

    
300
function ovs {
301
    echo "Installing Open vSwitch..."
302

    
303
    OVS_SRC=$BUILD_DIR/openvswitch
304
    OVS_BUILD=$OVS_SRC/build-$KERNEL_NAME
305
    OVS_KMODS=($OVS_BUILD/datapath/linux/{openvswitch_mod.ko,brcompat_mod.ko})
306

    
307
    # Required for module build/dkms install
308
    $install $KERNEL_HEADERS
309

    
310
    ovspresent=0
311

    
312
    # First see if we have packages
313
    # XXX wget -c seems to fail from github/amazon s3
314
    cd /tmp
315
    if wget $OVS_PACKAGE_LOC/$OVS_PACKAGE_NAME 2> /dev/null; then
316
	$install patch dkms fakeroot python-argparse
317
        tar xf $OVS_PACKAGE_NAME
318
        orig=`tar tf $OVS_PACKAGE_NAME`
319
        # Now install packages in reasonable dependency order
320
        order='dkms common pki openvswitch-switch brcompat controller'
321
        pkgs=""
322
        for p in $order; do
323
            pkg=`echo "$orig" | grep $p`
324
	    # Annoyingly, things seem to be missing without this flag
325
            $pkginst --force-confmiss $pkg
326
        done
327
        ovspresent=1
328
    fi
329

    
330
    # Otherwise try distribution's OVS packages
331
    if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 11.10` = 1 ]; then
332
        if ! dpkg --get-selections | grep openvswitch-datapath; then
333
            # If you've already installed a datapath, assume you
334
            # know what you're doing and don't need dkms datapath.
335
            # Otherwise, install it.
336
            $install openvswitch-datapath-dkms
337
        fi
338
	if $install openvswitch-switch openvswitch-controller; then
339
            echo "Ignoring error installing openvswitch-controller"
340
        fi
341
        ovspresent=1
342
    fi
343

    
344
    # Switch can run on its own, but
345
    # Mininet should control the controller
346
    if [ -e /etc/init.d/openvswitch-controller ]; then
347
        if sudo service openvswitch-controller stop; then
348
            echo "Stopped running controller"
349
        fi
350
        sudo update-rc.d openvswitch-controller disable
351
    fi
352

    
353
    if [ $ovspresent = 1 ]; then
354
        echo "Done (hopefully) installing packages"
355
        cd $BUILD_DIR
356
        return
357
    fi
358

    
359
    # Otherwise attempt to install from source
360

    
361
    $install pkg-config gcc make python-dev libssl-dev libtool
362

    
363
    if [ "$DIST" = "Debian" ]; then
364
        if [ "$CODENAME" = "lenny" ]; then
365
            $install git-core
366
            # Install Autoconf 2.63+ backport from Debian Backports repo:
367
            # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
368
            sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
369
            sudo apt-get update
370
            sudo apt-get -y --force-yes install debian-backports-keyring
371
            sudo apt-get -y --force-yes -t lenny-backports install autoconf
372
        fi
373
    else
374
        $install git
375
    fi
376

    
377
    # Install OVS from release
378
    cd $BUILD_DIR/
379
    git clone git://openvswitch.org/openvswitch $OVS_SRC
380
    cd $OVS_SRC
381
    git checkout $OVS_TAG
382
    ./boot.sh
383
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
384
    if [ ! -e $BUILDDIR ]; then
385
        echo "Creating build sdirectory $BUILDDIR"
386
        sudo mkdir -p $BUILDDIR
387
    fi
388
    opts="--with-linux=$BUILDDIR"
389
    mkdir -p $OVS_BUILD
390
    cd $OVS_BUILD
391
    ../configure $opts
392
    make
393
    sudo make install
394

    
395
    modprobe
396
}
397

    
398
function remove_ovs {
399
    pkgs=`dpkg --get-selections | grep openvswitch | awk '{ print $1;}'`
400
    echo "Removing existing Open vSwitch packages:"
401
    echo $pkgs
402
    if ! $remove $pkgs; then
403
        echo "Not all packages removed correctly"
404
    fi
405
    # For some reason this doesn't happen
406
    if scripts=`ls /etc/init.d/*openvswitch* 2>/dev/null`; then
407
        echo $scripts
408
        for s in $scripts; do
409
            s=$(basename $s)
410
            echo SCRIPT $s
411
            sudo service $s stop
412
            sudo rm -f /etc/init.d/$s
413
            sudo update-rc.d -f $s remove
414
        done
415
    fi
416
    echo "Done removing OVS"
417
}
418

    
419
function ivs {
420
    echo "Installing Indigo Virtual Switch..."
421

    
422
    IVS_SRC=$BUILD_DIR/ivs
423

    
424
    # Install dependencies
425
    $install git pkg-config gcc make libnl-3-dev libnl-route-3-dev libnl-genl-3-dev
426

    
427
    # Install IVS from source
428
    cd $BUILD_DIR
429
    git clone git://github.com/floodlight/ivs $IVS_SRC -b $IVS_TAG --recursive
430
    cd $IVS_SRC
431
    make
432
    sudo make install
433
}
434

    
435
# Install NOX with tutorial files
436
function nox {
437
    echo "Installing NOX w/tutorial files..."
438

    
439
    # Install NOX deps:
440
    $install autoconf automake g++ libtool python python-twisted \
441
		swig libssl-dev make
442
    if [ "$DIST" = "Debian" ]; then
443
        $install libboost1.35-dev
444
    elif [ "$DIST" = "Ubuntu" ]; then
445
        $install python-dev libboost-dev
446
        $install libboost-filesystem-dev
447
        $install libboost-test-dev
448
    fi
449
    # Install NOX optional deps:
450
    $install libsqlite3-dev python-simplejson
451

    
452
    # Fetch NOX destiny
453
    cd $BUILD_DIR/
454
    git clone https://github.com/noxrepo/nox-classic.git noxcore
455
    cd noxcore
456
    if ! git checkout -b destiny remotes/origin/destiny ; then
457
        echo "Did not check out a new destiny branch - assuming current branch is destiny"
458
    fi
459

    
460
    # Apply patches
461
    git checkout -b tutorial-destiny
462
    git am $MININET_DIR/mininet/util/nox-patches/*tutorial-port-nox-destiny*.patch
463
    if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 12.04` = 1 ]; then
464
        git am $MININET_DIR/mininet/util/nox-patches/*nox-ubuntu12-hacks.patch
465
    fi
466

    
467
    # Build
468
    ./boot.sh
469
    mkdir build
470
    cd build
471
    ../configure
472
    make -j3
473
    #make check
474

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

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

    
483
# Install NOX Classic/Zaku for OpenFlow 1.3
484
function nox13 {
485
    echo "Installing NOX w/tutorial files..."
486

    
487
    # Install NOX deps:
488
    $install autoconf automake g++ libtool python python-twisted \
489
        swig libssl-dev make
490
    if [ "$DIST" = "Debian" ]; then
491
        $install libboost1.35-dev
492
    elif [ "$DIST" = "Ubuntu" ]; then
493
        $install python-dev libboost-dev
494
        $install libboost-filesystem-dev
495
        $install libboost-test-dev
496
    fi
497

    
498
    # Fetch NOX destiny
499
    cd $BUILD_DIR/
500
    git clone https://github.com/CPqD/nox13oflib.git
501
    cd nox13oflib
502

    
503
    # Build
504
    ./boot.sh
505
    mkdir build
506
    cd build
507
    ../configure
508
    make -j3
509
    #make check
510

    
511
    # To verify this install:
512
    #cd ~/nox13oflib/build/src
513
    #./nox_core -v -i ptcp:
514
}
515

    
516

    
517
# "Install" POX
518
function pox {
519
    echo "Installing POX into $BUILD_DIR/pox..."
520
    cd $BUILD_DIR
521
    git clone https://github.com/noxrepo/pox.git
522
}
523

    
524
# Install OFtest
525
function oftest {
526
    echo "Installing oftest..."
527

    
528
    # Install deps:
529
    $install tcpdump python-scapy
530

    
531
    # Install oftest:
532
    cd $BUILD_DIR/
533
    git clone git://github.com/floodlight/oftest
534
}
535

    
536
# Install cbench
537
function cbench {
538
    echo "Installing cbench..."
539

    
540
    $install libsnmp-dev libpcap-dev libconfig-dev
541
    cd $BUILD_DIR/
542
    git clone git://openflow.org/oflops.git
543
    cd oflops
544
    sh boot.sh || true # possible error in autoreconf, so run twice
545
    sh boot.sh
546
    ./configure --with-openflow-src-dir=$BUILD_DIR/openflow
547
    make
548
    sudo make install || true # make install fails; force past this
549
}
550

    
551
function vm_other {
552
    echo "Doing other Mininet VM setup tasks..."
553

    
554
    # Remove avahi-daemon, which may cause unwanted discovery packets to be
555
    # sent during tests, near link status changes:
556
    echo "Removing avahi-daemon"
557
    $remove avahi-daemon
558

    
559
    # was: Disable IPv6.  Add to /etc/modprobe.d/blacklist:
560
    #echo "Attempting to disable IPv6"
561
    #if [ "$DIST" = "Ubuntu" ]; then
562
    #    BLACKLIST=/etc/modprobe.d/blacklist.conf
563
    #else
564
    #    BLACKLIST=/etc/modprobe.d/blacklist
565
    #fi
566
    #sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
567

    
568
    # Disable IPv6
569
    if ! grep 'disable IPv6' /etc/sysctl.conf; then
570
        echo 'Disabling IPv6'
571
        echo '
572
# Mininet: disable IPv6
573
net.ipv6.conf.all.disable_ipv6 = 1
574
net.ipv6.conf.default.disable_ipv6 = 1
575
net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
576
    fi
577
    # Disabling IPv6 breaks X11 forwarding via ssh
578
    line='AddressFamily inet'
579
    file='/etc/ssh/sshd_config'
580
    echo "Adding $line to $file"
581
    if ! grep "$line" $file > /dev/null; then
582
        echo "$line" | sudo tee -a $file > /dev/null
583
    fi
584

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

    
588
    # Install tcpdump, cmd-line packet dump tool.  Also install gitk,
589
    # a graphical git history viewer.
590
    $install tcpdump gitk
591

    
592
    # Install common text editors
593
    $install vim nano emacs
594

    
595
    # Install NTP
596
    $install ntp
597

    
598
    # Set git to colorize everything.
599
    git config --global color.diff auto
600
    git config --global color.status auto
601
    git config --global color.branch auto
602

    
603
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
604
    if [ "$DIST" = "Debian" ]; then
605
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
606
    fi
607

    
608
    # Clean unneeded debs:
609
    rm -f ~/linux-headers-* ~/linux-image-*
610
}
611

    
612
# Script to copy built OVS kernel module to where modprobe will
613
# find them automatically.  Removes the need to keep an environment variable
614
# for insmod usage, and works nicely with multiple kernel versions.
615
#
616
# The downside is that after each recompilation of OVS you'll need to
617
# re-run this script.  If you're using only one kernel version, then it may be
618
# a good idea to use a symbolic link in place of the copy below.
619
function modprobe {
620
    echo "Setting up modprobe for OVS kmod..."
621
    set +o nounset
622
    if [ -z "$OVS_KMODS" ]; then
623
      echo "OVS_KMODS not set. Aborting."
624
    else
625
      sudo cp $OVS_KMODS $DRIVERS_DIR
626
      sudo depmod -a ${KERNEL_NAME}
627
    fi
628
    set -o nounset
629
}
630

    
631
function all {
632
    echo "Running all commands..."
633
    kernel
634
    mn_deps
635
    mn_dev
636
    of
637
    wireshark
638
    ovs
639
    # NOX-classic is deprecated, but you can install it manually if desired.
640
    # nox
641
    pox
642
    oftest
643
    cbench
644
    echo "Enjoy Mininet!"
645
}
646

    
647
# Restore disk space and remove sensitive files before shipping a VM.
648
function vm_clean {
649
    echo "Cleaning VM..."
650
    sudo apt-get clean
651
    sudo apt-get autoremove
652
    sudo rm -rf /tmp/*
653
    sudo rm -rf openvswitch*.tar.gz
654

    
655
    # Remove sensistive files
656
    history -c  # note this won't work if you have multiple bash sessions
657
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
658
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
659
    sudo rm -f ~/.ssh/authorized_keys*
660

    
661
    # Remove Mininet files
662
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
663
    #sudo rm -f /usr/bin/mnexec
664

    
665
    # Clear optional dev script for SSH keychain load on boot
666
    rm -f ~/.bash_profile
667

    
668
    # Clear git changes
669
    git config --global user.name "None"
670
    git config --global user.email "None"
671

    
672
    # Note: you can shrink the .vmdk in vmware using
673
    # vmware-vdiskmanager -k *.vmdk
674
    echo "Zeroing out disk blocks for efficient compaction..."
675
    time sudo dd if=/dev/zero of=/tmp/zero bs=1M
676
    sync ; sleep 1 ; sync ; sudo rm -f /tmp/zero
677

    
678
}
679

    
680
function usage {
681
    printf '\nUsage: %s [-abcdfhikmnprtvwx03]\n\n' $(basename $0) >&2
682

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

    
689
    printf 'options:\n' >&2
690
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
691
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
692
    printf -- ' -c: (C)lean up after kernel install\n' >&2
693
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2
694
    printf -- ' -e: install Mininet d(E)veloper dependencies\n' >&2
695
    printf -- ' -f: install Open(F)low\n' >&2
696
    printf -- ' -h: print this (H)elp message\n' >&2
697
    printf -- ' -i: install (I)ndigo Virtual Switch\n' >&2
698
    printf -- ' -k: install new (K)ernel\n' >&2
699
    printf -- ' -m: install Open vSwitch kernel (M)odule from source dir\n' >&2
700
    printf -- ' -n: install Mini(N)et dependencies + core files\n' >&2
701
    printf -- ' -p: install (P)OX OpenFlow Controller\n' >&2
702
    printf -- ' -r: remove existing Open vSwitch packages\n' >&2
703
    printf -- ' -s <dir>: place dependency (S)ource/build trees in <dir>\n' >&2
704
    printf -- ' -t: complete o(T)her Mininet VM setup tasks\n' >&2
705
    printf -- ' -v: install Open (V)switch\n' >&2
706
    printf -- ' -w: install OpenFlow (W)ireshark dissector\n' >&2
707
    printf -- ' -x: install NO(X) Classic OpenFlow controller\n' >&2
708
    printf -- ' -0: (default) -0[fx] installs OpenFlow 1.0 versions\n' >&2
709
    printf -- ' -3: -3[fx] installs OpenFlow 1.3 versions\n' >&2
710
    exit 2
711
}
712

    
713
OF_VERSION=1.0
714

    
715
if [ $# -eq 0 ]
716
then
717
    all
718
else
719
    while getopts 'abcdefhikmnprs:tvwx03' OPTION
720
    do
721
      case $OPTION in
722
      a)    all;;
723
      b)    cbench;;
724
      c)    kernel_clean;;
725
      d)    vm_clean;;
726
      e)    mn_dev;;
727
      f)    case $OF_VERSION in
728
            1.0) of;;
729
            1.3) of13;;
730
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
731
            esac;;
732
      h)    usage;;
733
      i)    ivs;;
734
      k)    kernel;;
735
      m)    modprobe;;
736
      n)    mn_deps;;
737
      p)    pox;;
738
      r)    remove_ovs;;
739
      s)    mkdir -p $OPTARG; # ensure the directory is created
740
            BUILD_DIR="$( cd -P "$OPTARG" && pwd )"; # get the full path
741
            echo "Dependency installation directory: $BUILD_DIR";;
742
      t)    vm_other;;
743
      v)    ovs;;
744
      w)    wireshark;;
745
      x)    case $OF_VERSION in
746
            1.0) nox;;
747
            1.3) nox13;;
748
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
749
            esac;;
750
      0)    OF_VERSION=1.0;;
751
      3)    OF_VERSION=1.3;;
752
      ?)    usage;;
753
      esac
754
    done
755
    shift $(($OPTIND - 1))
756
fi