Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 5b08af2e

History | View | Annotate | Download (23.4 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 autoconf automake libtool make gcc
190
    if [ "$DIST" = "Fedora" ]; then
191
        $install git pkgconfig glibc-devel
192
    else
193
        $install git-core autotools-dev pkg-config libc6-dev
194
    fi
195
    git clone git://openflowswitch.org/openflow.git
196
    cd $BUILD_DIR/openflow
197

    
198
    # Patch controller to handle more than 16 switches
199
    patch -p1 < $MININET_DIR/mininet/util/openflow-patches/controller.patch
200

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

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

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

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

    
238
    # Resume the install:
239
    cd $BUILD_DIR/ofsoftswitch13
240
    ./boot.sh
241
    ./configure
242
    make
243
    sudo make install
244
    cd $BUILD_DIR
245
}
246

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

    
261
function wireshark {
262
    echo "Installing Wireshark dissector..."
263

    
264
    sudo apt-get install -y wireshark tshark libgtk2.0-dev
265

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

    
295
    # Copy coloring rules: OF is white-on-blue:
296
    mkdir -p $HOME/.wireshark
297
    cp $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
298
}
299

    
300

    
301
# Install Open vSwitch
302
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
303

    
304
function ovs {
305
    echo "Installing Open vSwitch..."
306

    
307
    OVS_SRC=$BUILD_DIR/openvswitch
308
    OVS_BUILD=$OVS_SRC/build-$KERNEL_NAME
309
    OVS_KMODS=($OVS_BUILD/datapath/linux/{openvswitch_mod.ko,brcompat_mod.ko})
310

    
311
    # Required for module build/dkms install
312
    $install $KERNEL_HEADERS
313

    
314
    ovspresent=0
315

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

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

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

    
357
    if [ $ovspresent = 1 ]; then
358
        echo "Done (hopefully) installing packages"
359
        cd $BUILD_DIR
360
        return
361
    fi
362

    
363
    # Otherwise attempt to install from source
364

    
365
    $install pkg-config gcc make python-dev libssl-dev libtool
366

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

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

    
399
    modprobe
400
}
401

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

    
423
function ivs {
424
    echo "Installing Indigo Virtual Switch..."
425

    
426
    IVS_SRC=$BUILD_DIR/ivs
427

    
428
    # Install dependencies
429
    $install git pkg-config gcc make libnl-3-dev libnl-route-3-dev libnl-genl-3-dev
430

    
431
    # Install IVS from source
432
    cd $BUILD_DIR
433
    git clone git://github.com/floodlight/ivs $IVS_SRC -b $IVS_TAG --recursive
434
    cd $IVS_SRC
435
    make
436
    sudo make install
437
}
438

    
439
# Install NOX with tutorial files
440
function nox {
441
    echo "Installing NOX w/tutorial files..."
442

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

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

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

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

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

    
482
    # To verify this install:
483
    #cd ~/noxcore/build/src
484
    #./nox_core -v -i ptcp:
485
}
486

    
487
# Install NOX Classic/Zaku for OpenFlow 1.3
488
function nox13 {
489
    echo "Installing NOX w/tutorial files..."
490

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

    
502
    # Fetch NOX destiny
503
    cd $BUILD_DIR/
504
    git clone https://github.com/CPqD/nox13oflib.git
505
    cd nox13oflib
506

    
507
    # Build
508
    ./boot.sh
509
    mkdir build
510
    cd build
511
    ../configure
512
    make -j3
513
    #make check
514

    
515
    # To verify this install:
516
    #cd ~/nox13oflib/build/src
517
    #./nox_core -v -i ptcp:
518
}
519

    
520

    
521
# "Install" POX
522
function pox {
523
    echo "Installing POX into $BUILD_DIR/pox..."
524
    cd $BUILD_DIR
525
    git clone https://github.com/noxrepo/pox.git
526
}
527

    
528
# Install OFtest
529
function oftest {
530
    echo "Installing oftest..."
531

    
532
    # Install deps:
533
    $install tcpdump python-scapy
534

    
535
    # Install oftest:
536
    cd $BUILD_DIR/
537
    git clone git://github.com/floodlight/oftest
538
}
539

    
540
# Install cbench
541
function cbench {
542
    echo "Installing cbench..."
543

    
544
    if [ "$DIST" = "Fedora" ]; then
545
        $install net-snmp-devel libpcap-devel libconfig-devel
546
    else
547
        $install libsnmp-dev libpcap-dev libconfig-dev
548
    fi
549
    cd $BUILD_DIR/
550
    git clone git://openflow.org/oflops.git
551
    cd oflops
552
    sh boot.sh || true # possible error in autoreconf, so run twice
553
    sh boot.sh
554
    ./configure --with-openflow-src-dir=$BUILD_DIR/openflow
555
    make
556
    sudo make install || true # make install fails; force past this
557
}
558

    
559
function vm_other {
560
    echo "Doing other Mininet VM setup tasks..."
561

    
562
    # Remove avahi-daemon, which may cause unwanted discovery packets to be
563
    # sent during tests, near link status changes:
564
    echo "Removing avahi-daemon"
565
    $remove avahi-daemon
566

    
567
    # was: Disable IPv6.  Add to /etc/modprobe.d/blacklist:
568
    #echo "Attempting to disable IPv6"
569
    #if [ "$DIST" = "Ubuntu" ]; then
570
    #    BLACKLIST=/etc/modprobe.d/blacklist.conf
571
    #else
572
    #    BLACKLIST=/etc/modprobe.d/blacklist
573
    #fi
574
    #sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
575

    
576
    # Disable IPv6
577
    if ! grep 'disable IPv6' /etc/sysctl.conf; then
578
        echo 'Disabling IPv6'
579
        echo '
580
# Mininet: disable IPv6
581
net.ipv6.conf.all.disable_ipv6 = 1
582
net.ipv6.conf.default.disable_ipv6 = 1
583
net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
584
    fi
585
    # Disabling IPv6 breaks X11 forwarding via ssh
586
    line='AddressFamily inet'
587
    file='/etc/ssh/sshd_config'
588
    echo "Adding $line to $file"
589
    if ! grep "$line" $file > /dev/null; then
590
        echo "$line" | sudo tee -a $file > /dev/null
591
    fi
592

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

    
596
    # Install tcpdump, cmd-line packet dump tool.  Also install gitk,
597
    # a graphical git history viewer.
598
    $install tcpdump gitk
599

    
600
    # Install common text editors
601
    $install vim nano emacs
602

    
603
    # Install NTP
604
    $install ntp
605

    
606
    # Set git to colorize everything.
607
    git config --global color.diff auto
608
    git config --global color.status auto
609
    git config --global color.branch auto
610

    
611
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
612
    if [ "$DIST" = "Debian" ]; then
613
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
614
    fi
615

    
616
    # Clean unneeded debs:
617
    rm -f ~/linux-headers-* ~/linux-image-*
618
}
619

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

    
639
function all {
640
    if [ "$DIST" = "Fedora" ]; then
641
        printf "\nFedora 19 support status:\n"
642
        printf "the install script options -b, -f, -n, and -p should work.\n\n"
643
        printf "Just try:\n"
644
        printf "    install.sh -fnp\n"
645
        printf "with Fedora's kernel (3.10) and openvswitch (1.10.0) packages.\n"
646
        exit 3
647
    fi
648
    echo "Running all commands..."
649
    kernel
650
    mn_deps
651
    mn_dev
652
    of
653
    wireshark
654
    ovs
655
    # NOX-classic is deprecated, but you can install it manually if desired.
656
    # nox
657
    pox
658
    oftest
659
    cbench
660
    echo "Enjoy Mininet!"
661
}
662

    
663
# Restore disk space and remove sensitive files before shipping a VM.
664
function vm_clean {
665
    echo "Cleaning VM..."
666
    sudo apt-get clean
667
    sudo apt-get autoremove
668
    sudo rm -rf /tmp/*
669
    sudo rm -rf openvswitch*.tar.gz
670

    
671
    # Remove sensistive files
672
    history -c  # note this won't work if you have multiple bash sessions
673
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
674
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
675
    sudo rm -f ~/.ssh/authorized_keys*
676

    
677
    # Remove Mininet files
678
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
679
    #sudo rm -f /usr/bin/mnexec
680

    
681
    # Clear optional dev script for SSH keychain load on boot
682
    rm -f ~/.bash_profile
683

    
684
    # Clear git changes
685
    git config --global user.name "None"
686
    git config --global user.email "None"
687

    
688
    # Note: you can shrink the .vmdk in vmware using
689
    # vmware-vdiskmanager -k *.vmdk
690
    echo "Zeroing out disk blocks for efficient compaction..."
691
    time sudo dd if=/dev/zero of=/tmp/zero bs=1M
692
    sync ; sleep 1 ; sync ; sudo rm -f /tmp/zero
693

    
694
}
695

    
696
function usage {
697
    printf '\nUsage: %s [-abcdfhikmnprtvwx03]\n\n' $(basename $0) >&2
698

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

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

    
729
OF_VERSION=1.0
730

    
731
if [ $# -eq 0 ]
732
then
733
    all
734
else
735
    while getopts 'abcdefhikmnprs:tvwx03' OPTION
736
    do
737
      case $OPTION in
738
      a)    all;;
739
      b)    cbench;;
740
      c)    kernel_clean;;
741
      d)    vm_clean;;
742
      e)    mn_dev;;
743
      f)    case $OF_VERSION in
744
            1.0) of;;
745
            1.3) of13;;
746
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
747
            esac;;
748
      h)    usage;;
749
      i)    ivs;;
750
      k)    kernel;;
751
      m)    modprobe;;
752
      n)    mn_deps;;
753
      p)    pox;;
754
      r)    remove_ovs;;
755
      s)    mkdir -p $OPTARG; # ensure the directory is created
756
            BUILD_DIR="$( cd -P "$OPTARG" && pwd )"; # get the full path
757
            echo "Dependency installation directory: $BUILD_DIR";;
758
      t)    vm_other;;
759
      v)    ovs;;
760
      w)    wireshark;;
761
      x)    case $OF_VERSION in
762
            1.0) nox;;
763
            1.3) nox13;;
764
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
765
            esac;;
766
      0)    OF_VERSION=1.0;;
767
      3)    OF_VERSION=1.3;;
768
      ?)    usage;;
769
      esac
770
    done
771
    shift $(($OPTIND - 1))
772
fi