Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 40ad3a1b

History | View | Annotate | Download (24 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
    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
    if [ "$DIST" = "Fedora" ]; then
265
        # Just install Fedora's wireshark RPMS
266
        # Fedora's wirehark >= 1.10.2-2 includes an OF dissector
267
        # (it has been backported from the future Wireshark 1.12 code base)
268
        $install wireshark wireshark-gnome
269
        return
270
    fi
271

    
272
    $install wireshark tshark libgtk2.0-dev
273

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

    
303
    # Copy coloring rules: OF is white-on-blue:
304
    mkdir -p $HOME/.wireshark
305
    cp $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
306
}
307

    
308

    
309
# Install Open vSwitch
310
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
311

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

    
315
    if [ "$DIST" = "Fedora" ]; then
316
        # Just install Fedora's openvswitch RPMS
317
        $install openvswitch openvswitch-controller
318
        return
319
    fi
320

    
321
    OVS_SRC=$BUILD_DIR/openvswitch
322
    OVS_BUILD=$OVS_SRC/build-$KERNEL_NAME
323
    OVS_KMODS=($OVS_BUILD/datapath/linux/{openvswitch_mod.ko,brcompat_mod.ko})
324

    
325
    # Required for module build/dkms install
326
    $install $KERNEL_HEADERS
327

    
328
    ovspresent=0
329

    
330
    # First see if we have packages
331
    # XXX wget -c seems to fail from github/amazon s3
332
    cd /tmp
333
    if wget $OVS_PACKAGE_LOC/$OVS_PACKAGE_NAME 2> /dev/null; then
334
	$install patch dkms fakeroot python-argparse
335
        tar xf $OVS_PACKAGE_NAME
336
        orig=`tar tf $OVS_PACKAGE_NAME`
337
        # Now install packages in reasonable dependency order
338
        order='dkms common pki openvswitch-switch brcompat controller'
339
        pkgs=""
340
        for p in $order; do
341
            pkg=`echo "$orig" | grep $p`
342
	    # Annoyingly, things seem to be missing without this flag
343
            $pkginst --force-confmiss $pkg
344
        done
345
        ovspresent=1
346
    fi
347

    
348
    # Otherwise try distribution's OVS packages
349
    if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 11.10` = 1 ]; then
350
        if ! dpkg --get-selections | grep openvswitch-datapath; then
351
            # If you've already installed a datapath, assume you
352
            # know what you're doing and don't need dkms datapath.
353
            # Otherwise, install it.
354
            $install openvswitch-datapath-dkms
355
        fi
356
	if $install openvswitch-switch openvswitch-controller; then
357
            echo "Ignoring error installing openvswitch-controller"
358
        fi
359
        ovspresent=1
360
    fi
361

    
362
    # Switch can run on its own, but
363
    # Mininet should control the controller
364
    if [ -e /etc/init.d/openvswitch-controller ]; then
365
        if sudo service openvswitch-controller stop; then
366
            echo "Stopped running controller"
367
        fi
368
        sudo update-rc.d openvswitch-controller disable
369
    fi
370

    
371
    if [ $ovspresent = 1 ]; then
372
        echo "Done (hopefully) installing packages"
373
        cd $BUILD_DIR
374
        return
375
    fi
376

    
377
    # Otherwise attempt to install from source
378

    
379
    $install pkg-config gcc make python-dev libssl-dev libtool
380

    
381
    if [ "$DIST" = "Debian" ]; then
382
        if [ "$CODENAME" = "lenny" ]; then
383
            $install git-core
384
            # Install Autoconf 2.63+ backport from Debian Backports repo:
385
            # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
386
            sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
387
            sudo apt-get update
388
            sudo apt-get -y --force-yes install debian-backports-keyring
389
            sudo apt-get -y --force-yes -t lenny-backports install autoconf
390
        fi
391
    else
392
        $install git
393
    fi
394

    
395
    # Install OVS from release
396
    cd $BUILD_DIR/
397
    git clone git://openvswitch.org/openvswitch $OVS_SRC
398
    cd $OVS_SRC
399
    git checkout $OVS_TAG
400
    ./boot.sh
401
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
402
    if [ ! -e $BUILDDIR ]; then
403
        echo "Creating build sdirectory $BUILDDIR"
404
        sudo mkdir -p $BUILDDIR
405
    fi
406
    opts="--with-linux=$BUILDDIR"
407
    mkdir -p $OVS_BUILD
408
    cd $OVS_BUILD
409
    ../configure $opts
410
    make
411
    sudo make install
412

    
413
    modprobe
414
}
415

    
416
function remove_ovs {
417
    pkgs=`dpkg --get-selections | grep openvswitch | awk '{ print $1;}'`
418
    echo "Removing existing Open vSwitch packages:"
419
    echo $pkgs
420
    if ! $remove $pkgs; then
421
        echo "Not all packages removed correctly"
422
    fi
423
    # For some reason this doesn't happen
424
    if scripts=`ls /etc/init.d/*openvswitch* 2>/dev/null`; then
425
        echo $scripts
426
        for s in $scripts; do
427
            s=$(basename $s)
428
            echo SCRIPT $s
429
            sudo service $s stop
430
            sudo rm -f /etc/init.d/$s
431
            sudo update-rc.d -f $s remove
432
        done
433
    fi
434
    echo "Done removing OVS"
435
}
436

    
437
function ivs {
438
    echo "Installing Indigo Virtual Switch..."
439

    
440
    IVS_SRC=$BUILD_DIR/ivs
441

    
442
    # Install dependencies
443
    $install git pkg-config gcc make libnl-3-dev libnl-route-3-dev libnl-genl-3-dev
444

    
445
    # Install IVS from source
446
    cd $BUILD_DIR
447
    git clone git://github.com/floodlight/ivs $IVS_SRC -b $IVS_TAG --recursive
448
    cd $IVS_SRC
449
    make
450
    sudo make install
451
}
452

    
453
# Install NOX with tutorial files
454
function nox {
455
    echo "Installing NOX w/tutorial files..."
456

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

    
470
    # Fetch NOX destiny
471
    cd $BUILD_DIR/
472
    git clone https://github.com/noxrepo/nox-classic.git noxcore
473
    cd noxcore
474
    if ! git checkout -b destiny remotes/origin/destiny ; then
475
        echo "Did not check out a new destiny branch - assuming current branch is destiny"
476
    fi
477

    
478
    # Apply patches
479
    git checkout -b tutorial-destiny
480
    git am $MININET_DIR/mininet/util/nox-patches/*tutorial-port-nox-destiny*.patch
481
    if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 12.04` = 1 ]; then
482
        git am $MININET_DIR/mininet/util/nox-patches/*nox-ubuntu12-hacks.patch
483
    fi
484

    
485
    # Build
486
    ./boot.sh
487
    mkdir build
488
    cd build
489
    ../configure
490
    make -j3
491
    #make check
492

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

    
496
    # To verify this install:
497
    #cd ~/noxcore/build/src
498
    #./nox_core -v -i ptcp:
499
}
500

    
501
# Install NOX Classic/Zaku for OpenFlow 1.3
502
function nox13 {
503
    echo "Installing NOX w/tutorial files..."
504

    
505
    # Install NOX deps:
506
    $install autoconf automake g++ libtool python python-twisted \
507
        swig libssl-dev make
508
    if [ "$DIST" = "Debian" ]; then
509
        $install libboost1.35-dev
510
    elif [ "$DIST" = "Ubuntu" ]; then
511
        $install python-dev libboost-dev
512
        $install libboost-filesystem-dev
513
        $install libboost-test-dev
514
    fi
515

    
516
    # Fetch NOX destiny
517
    cd $BUILD_DIR/
518
    git clone https://github.com/CPqD/nox13oflib.git
519
    cd nox13oflib
520

    
521
    # Build
522
    ./boot.sh
523
    mkdir build
524
    cd build
525
    ../configure
526
    make -j3
527
    #make check
528

    
529
    # To verify this install:
530
    #cd ~/nox13oflib/build/src
531
    #./nox_core -v -i ptcp:
532
}
533

    
534

    
535
# "Install" POX
536
function pox {
537
    echo "Installing POX into $BUILD_DIR/pox..."
538
    cd $BUILD_DIR
539
    git clone https://github.com/noxrepo/pox.git
540
}
541

    
542
# Install OFtest
543
function oftest {
544
    echo "Installing oftest..."
545

    
546
    # Install deps:
547
    $install tcpdump python-scapy
548

    
549
    # Install oftest:
550
    cd $BUILD_DIR/
551
    git clone git://github.com/floodlight/oftest
552
}
553

    
554
# Install cbench
555
function cbench {
556
    echo "Installing cbench..."
557

    
558
    if [ "$DIST" = "Fedora" ]; then
559
        $install net-snmp-devel libpcap-devel libconfig-devel
560
    else
561
        $install libsnmp-dev libpcap-dev libconfig-dev
562
    fi
563
    cd $BUILD_DIR/
564
    git clone git://openflow.org/oflops.git
565
    cd oflops
566
    sh boot.sh || true # possible error in autoreconf, so run twice
567
    sh boot.sh
568
    ./configure --with-openflow-src-dir=$BUILD_DIR/openflow
569
    make
570
    sudo make install || true # make install fails; force past this
571
}
572

    
573
function vm_other {
574
    echo "Doing other Mininet VM setup tasks..."
575

    
576
    # Remove avahi-daemon, which may cause unwanted discovery packets to be
577
    # sent during tests, near link status changes:
578
    echo "Removing avahi-daemon"
579
    $remove avahi-daemon
580

    
581
    # was: Disable IPv6.  Add to /etc/modprobe.d/blacklist:
582
    #echo "Attempting to disable IPv6"
583
    #if [ "$DIST" = "Ubuntu" ]; then
584
    #    BLACKLIST=/etc/modprobe.d/blacklist.conf
585
    #else
586
    #    BLACKLIST=/etc/modprobe.d/blacklist
587
    #fi
588
    #sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
589

    
590
    # Disable IPv6
591
    if ! grep 'disable IPv6' /etc/sysctl.conf; then
592
        echo 'Disabling IPv6'
593
        echo '
594
# Mininet: disable IPv6
595
net.ipv6.conf.all.disable_ipv6 = 1
596
net.ipv6.conf.default.disable_ipv6 = 1
597
net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
598
    fi
599
    # Disabling IPv6 breaks X11 forwarding via ssh
600
    line='AddressFamily inet'
601
    file='/etc/ssh/sshd_config'
602
    echo "Adding $line to $file"
603
    if ! grep "$line" $file > /dev/null; then
604
        echo "$line" | sudo tee -a $file > /dev/null
605
    fi
606

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

    
610
    # Install tcpdump, cmd-line packet dump tool.  Also install gitk,
611
    # a graphical git history viewer.
612
    $install tcpdump gitk
613

    
614
    # Install common text editors
615
    $install vim nano emacs
616

    
617
    # Install NTP
618
    $install ntp
619

    
620
    # Set git to colorize everything.
621
    git config --global color.diff auto
622
    git config --global color.status auto
623
    git config --global color.branch auto
624

    
625
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
626
    if [ "$DIST" = "Debian" ]; then
627
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
628
    fi
629

    
630
    # Clean unneeded debs:
631
    rm -f ~/linux-headers-* ~/linux-image-*
632
}
633

    
634
# Script to copy built OVS kernel module to where modprobe will
635
# find them automatically.  Removes the need to keep an environment variable
636
# for insmod usage, and works nicely with multiple kernel versions.
637
#
638
# The downside is that after each recompilation of OVS you'll need to
639
# re-run this script.  If you're using only one kernel version, then it may be
640
# a good idea to use a symbolic link in place of the copy below.
641
function modprobe {
642
    echo "Setting up modprobe for OVS kmod..."
643
    set +o nounset
644
    if [ -z "$OVS_KMODS" ]; then
645
      echo "OVS_KMODS not set. Aborting."
646
    else
647
      sudo cp $OVS_KMODS $DRIVERS_DIR
648
      sudo depmod -a ${KERNEL_NAME}
649
    fi
650
    set -o nounset
651
}
652

    
653
function all {
654
    if [ "$DIST" = "Fedora" ]; then
655
        printf "\nFedora 19 support status:\n"
656
        printf "the install script options -b, -f, -n, and -p should work.\n\n"
657
        printf "Just try:\n"
658
        printf "    install.sh -fnp\n"
659
        printf "with Fedora's kernel (3.10) and openvswitch (1.10.0) packages.\n"
660
        exit 3
661
    fi
662
    echo "Installing all packages except for -eix (doxypy, ivs, nox-classic)..."
663
    kernel
664
    mn_deps
665
    # Skip mn_dev (doxypy/texlive/fonts/etc.) because it's huge
666
    # mn_dev
667
    of
668
    wireshark
669
    ovs
670
    # We may add ivs once it's more mature
671
    # ivs
672
    # NOX-classic is deprecated, but you can install it manually if desired.
673
    # nox
674
    pox
675
    oftest
676
    cbench
677
    echo "Enjoy Mininet!"
678
}
679

    
680
# Restore disk space and remove sensitive files before shipping a VM.
681
function vm_clean {
682
    echo "Cleaning VM..."
683
    sudo apt-get clean
684
    sudo apt-get autoremove
685
    sudo rm -rf /tmp/*
686
    sudo rm -rf openvswitch*.tar.gz
687

    
688
    # Remove sensistive files
689
    history -c  # note this won't work if you have multiple bash sessions
690
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
691
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
692
    sudo rm -f ~/.ssh/authorized_keys*
693

    
694
    # Remove Mininet files
695
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
696
    #sudo rm -f /usr/bin/mnexec
697

    
698
    # Clear optional dev script for SSH keychain load on boot
699
    rm -f ~/.bash_profile
700

    
701
    # Clear git changes
702
    git config --global user.name "None"
703
    git config --global user.email "None"
704

    
705
    # Note: you can shrink the .vmdk in vmware using
706
    # vmware-vdiskmanager -k *.vmdk
707
    echo "Zeroing out disk blocks for efficient compaction..."
708
    time sudo dd if=/dev/zero of=/tmp/zero bs=1M
709
    sync ; sleep 1 ; sync ; sudo rm -f /tmp/zero
710

    
711
}
712

    
713
function usage {
714
    printf '\nUsage: %s [-abcdfhikmnprtvwx03]\n\n' $(basename $0) >&2
715

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

    
722
    printf 'options:\n' >&2
723
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
724
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
725
    printf -- ' -c: (C)lean up after kernel install\n' >&2
726
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2
727
    printf -- ' -e: install Mininet d(E)veloper dependencies\n' >&2
728
    printf -- ' -f: install Open(F)low\n' >&2
729
    printf -- ' -h: print this (H)elp message\n' >&2
730
    printf -- ' -i: install (I)ndigo Virtual Switch\n' >&2
731
    printf -- ' -k: install new (K)ernel\n' >&2
732
    printf -- ' -m: install Open vSwitch kernel (M)odule from source dir\n' >&2
733
    printf -- ' -n: install Mini(N)et dependencies + core files\n' >&2
734
    printf -- ' -p: install (P)OX OpenFlow Controller\n' >&2
735
    printf -- ' -r: remove existing Open vSwitch packages\n' >&2
736
    printf -- ' -s <dir>: place dependency (S)ource/build trees in <dir>\n' >&2
737
    printf -- ' -t: complete o(T)her Mininet VM setup tasks\n' >&2
738
    printf -- ' -v: install Open (V)switch\n' >&2
739
    printf -- ' -w: install OpenFlow (W)ireshark dissector\n' >&2
740
    printf -- ' -x: install NO(X) Classic OpenFlow controller\n' >&2
741
    printf -- ' -0: (default) -0[fx] installs OpenFlow 1.0 versions\n' >&2
742
    printf -- ' -3: -3[fx] installs OpenFlow 1.3 versions\n' >&2
743
    exit 2
744
}
745

    
746
OF_VERSION=1.0
747

    
748
if [ $# -eq 0 ]
749
then
750
    all
751
else
752
    while getopts 'abcdefhikmnprs:tvwx03' OPTION
753
    do
754
      case $OPTION in
755
      a)    all;;
756
      b)    cbench;;
757
      c)    kernel_clean;;
758
      d)    vm_clean;;
759
      e)    mn_dev;;
760
      f)    case $OF_VERSION in
761
            1.0) of;;
762
            1.3) of13;;
763
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
764
            esac;;
765
      h)    usage;;
766
      i)    ivs;;
767
      k)    kernel;;
768
      m)    modprobe;;
769
      n)    mn_deps;;
770
      p)    pox;;
771
      r)    remove_ovs;;
772
      s)    mkdir -p $OPTARG; # ensure the directory is created
773
            BUILD_DIR="$( cd -P "$OPTARG" && pwd )"; # get the full path
774
            echo "Dependency installation directory: $BUILD_DIR";;
775
      t)    vm_other;;
776
      v)    ovs;;
777
      w)    wireshark;;
778
      x)    case $OF_VERSION in
779
            1.0) nox;;
780
            1.3) nox13;;
781
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
782
            esac;;
783
      0)    OF_VERSION=1.0;;
784
      3)    OF_VERSION=1.3;;
785
      ?)    usage;;
786
      esac
787
    done
788
    shift $(($OPTIND - 1))
789
fi