Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ c26b4525

History | View | Annotate | Download (21 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
function kernel {
93
    echo "Install Mininet-compatible kernel if necessary"
94
    sudo apt-get update
95
    if [ "$DIST" = "Ubuntu" ] &&  [ "$RELEASE" = "10.04" ]; then
96
        $install linux-image-$KERNEL_NAME
97
    elif [ "$DIST" = "Debian" ]; then
98
        # The easy approach: download pre-built linux-image and linux-headers packages:
99
        wget -c $KERNEL_LOC/$KERNEL_HEADERS
100
        wget -c $KERNEL_LOC/$KERNEL_IMAGE
101

    
102
        # Install custom linux headers and image:
103
        $pkginst $KERNEL_IMAGE $KERNEL_HEADERS
104

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

    
113
        # Ensure /boot/grub/menu.lst boots with initrd image:
114
        sudo update-grub
115

    
116
        # The default should be the new kernel. Otherwise, you may need to modify
117
        # /boot/grub/menu.lst to set the default to the entry corresponding to the
118
        # kernel you just installed.
119
    fi
120
}
121

    
122
function kernel_clean {
123
    echo "Cleaning kernel..."
124

    
125
    # To save disk space, remove previous kernel
126
    if ! $remove $KERNEL_IMAGE_OLD; then
127
        echo $KERNEL_IMAGE_OLD not installed.
128
    fi
129

    
130
    # Also remove downloaded packages:
131
    rm -f $HOME/linux-headers-* $HOME/linux-image-*
132
}
133

    
134
# Install Mininet deps
135
function mn_deps {
136
    echo "Installing Mininet dependencies"
137
    $install gcc make socat psmisc xterm ssh iperf iproute telnet \
138
        python-setuptools cgroup-bin ethtool help2man \
139
        pyflakes pylint pep8
140

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

    
150
    echo "Installing Mininet core"
151
    pushd $MININET_DIR/mininet
152
    sudo make install
153
    popd
154
}
155

    
156
# Install Mininet developer dependencies
157
function mn_dev {
158
    echo "Installing Mininet developer dependencies"
159
    $install doxygen doxypy texlive-fonts-recommended
160
}
161

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

    
175
    # Patch controller to handle more than 16 switches
176
    patch -p1 < $MININET_DIR/mininet/util/openflow-patches/controller.patch
177

    
178
    # Resume the install:
179
    ./boot.sh
180
    ./configure
181
    make
182
    sudo make install
183
    cd $BUILD_DIR
184
}
185

    
186
function of13 {
187
    echo "Installing OpenFlow 1.3 soft switch implementation..."
188
    cd $BUILD_DIR/
189
    $install  git-core autoconf automake autotools-dev pkg-config \
190
        make gcc g++ libtool libc6-dev cmake libpcap-dev libxerces-c2-dev  \
191
        unzip libpcre3-dev flex bison libboost-dev
192

    
193
    if [ ! -d "ofsoftswitch13" ]; then
194
        git clone https://github.com/CPqD/ofsoftswitch13.git
195
        if [[ -n "$OF13_SWITCH_REV" ]]; then
196
            cd ofsoftswitch13
197
            git checkout ${OF13_SWITCH_REV}
198
            cd ..
199
        fi
200
    fi
201

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

    
215
    # Resume the install:
216
    cd $BUILD_DIR/ofsoftswitch13
217
    ./boot.sh
218
    ./configure
219
    make
220
    sudo make install
221
    cd $BUILD_DIR
222
}
223

    
224
function wireshark {
225
    echo "Installing Wireshark dissector..."
226

    
227
    sudo apt-get install -y wireshark tshark libgtk2.0-dev
228

    
229
    if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" != "10.04" ]; then
230
        # Install newer version
231
        sudo apt-get install -y scons mercurial libglib2.0-dev
232
        sudo apt-get install -y libwiretap-dev libwireshark-dev
233
        cd $BUILD_DIR
234
        hg clone https://bitbucket.org/barnstorm/of-dissector
235
        cd of-dissector
236
        if [[ -n "$WS_DISSECTOR_REV" ]]; then
237
            hg checkout ${WS_DISSECTOR_REV}
238
        fi
239
        cd src
240
        export WIRESHARK=/usr/include/wireshark
241
        scons
242
        # libwireshark0/ on 11.04; libwireshark1/ on later
243
        WSDIR=`ls -d /usr/lib/wireshark/libwireshark* | head -1`
244
        WSPLUGDIR=$WSDIR/plugins/
245
        sudo cp openflow.so $WSPLUGDIR
246
        echo "Copied openflow plugin to $WSPLUGDIR"
247
    else
248
        # Install older version from reference source
249
        cd $BUILD_DIR/openflow/utilities/wireshark_dissectors/openflow
250
        make
251
        sudo make install
252
    fi
253

    
254
    # Copy coloring rules: OF is white-on-blue:
255
    mkdir -p $HOME/.wireshark
256
    cp $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
257
}
258

    
259

    
260
# Install Open vSwitch
261
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
262

    
263
function ovs {
264
    echo "Installing Open vSwitch..."
265

    
266
    # Required for module build/dkms install
267
    $install $KERNEL_HEADERS
268

    
269
    ovspresent=0
270

    
271
    # First see if we have packages
272
    # XXX wget -c seems to fail from github/amazon s3
273
    cd /tmp
274
    if wget $OVS_PACKAGE_LOC/$OVS_PACKAGE_NAME 2> /dev/null; then
275
	$install patch dkms fakeroot python-argparse
276
        tar xf $OVS_PACKAGE_NAME
277
        orig=`tar tf $OVS_PACKAGE_NAME`
278
        # Now install packages in reasonable dependency order
279
        order='dkms common pki openvswitch-switch brcompat controller'
280
        pkgs=""
281
        for p in $order; do
282
            pkg=`echo "$orig" | grep $p`
283
	    # Annoyingly, things seem to be missing without this flag
284
            $pkginst --force-confmiss $pkg
285
        done
286
        ovspresent=1
287
    fi
288

    
289
    # Otherwise try distribution's OVS packages
290
    if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 11.10` = 1 ]; then
291
        if ! dpkg --get-selections | grep openvswitch-datapath; then
292
            # If you've already installed a datapath, assume you
293
            # know what you're doing and don't need dkms datapath.
294
            # Otherwise, install it.
295
            $install openvswitch-datapath-dkms
296
        fi
297
	if $install openvswitch-switch openvswitch-controller; then
298
            echo "Ignoring error installing openvswitch-controller"
299
        fi
300
        ovspresent=1
301
    fi
302

    
303
    # Switch can run on its own, but
304
    # Mininet should control the controller
305
    if [ -e /etc/init.d/openvswitch-controller ]; then
306
        if sudo service openvswitch-controller stop; then
307
            echo "Stopped running controller"
308
        fi
309
        sudo update-rc.d openvswitch-controller disable
310
    fi
311

    
312
    if [ $ovspresent = 1 ]; then
313
        echo "Done (hopefully) installing packages"
314
        cd $BUILD_DIR
315
        return
316
    fi
317

    
318
    # Otherwise attempt to install from source
319

    
320
    $install pkg-config gcc make python-dev libssl-dev libtool
321

    
322
    if [ "$DIST" = "Debian" ]; then
323
        if [ "$CODENAME" = "lenny" ]; then
324
            $install git-core
325
            # Install Autoconf 2.63+ backport from Debian Backports repo:
326
            # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
327
            sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
328
            sudo apt-get update
329
            sudo apt-get -y --force-yes install debian-backports-keyring
330
            sudo apt-get -y --force-yes -t lenny-backports install autoconf
331
        fi
332
    else
333
        $install git
334
    fi
335

    
336
    # Install OVS from release
337
    cd $BUILD_DIR/
338
    git clone git://openvswitch.org/openvswitch $OVS_SRC
339
    cd $OVS_SRC
340
    git checkout $OVS_TAG
341
    ./boot.sh
342
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
343
    if [ ! -e $BUILDDIR ]; then
344
        echo "Creating build sdirectory $BUILDDIR"
345
        sudo mkdir -p $BUILDDIR
346
    fi
347
    opts="--with-linux=$BUILDDIR"
348
    mkdir -p $OVS_BUILD
349
    cd $OVS_BUILD
350
    ../configure $opts
351
    make
352
    sudo make install
353

    
354
    modprobe
355
}
356

    
357
function remove_ovs {
358
    pkgs=`dpkg --get-selections | grep openvswitch | awk '{ print $1;}'`
359
    echo "Removing existing Open vSwitch packages:"
360
    echo $pkgs
361
    if ! $remove $pkgs; then
362
        echo "Not all packages removed correctly"
363
    fi
364
    # For some reason this doesn't happen
365
    if scripts=`ls /etc/init.d/*openvswitch* 2>/dev/null`; then
366
        echo $scripts
367
        for s in $scripts; do
368
            s=$(basename $s)
369
            echo SCRIPT $s
370
            sudo service $s stop
371
            sudo rm -f /etc/init.d/$s
372
            sudo update-rc.d -f $s remove
373
        done
374
    fi
375
    echo "Done removing OVS"
376
}
377

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

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

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

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

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

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

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

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

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

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

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

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

    
459

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

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

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

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

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

    
483
    $install libsnmp-dev libpcap-dev libconfig-dev
484
    cd $BUILD_DIR/
485
    git clone git://openflow.org/oflops.git
486
    cd oflops
487
    sh boot.sh || true # possible error in autoreconf, so run twice
488
    sh boot.sh
489
    ./configure --with-openflow-src-dir=$BUILD_DIR/openflow
490
    make
491
    sudo make install || true # make install fails; force past this
492
}
493

    
494
function vm_other {
495
    echo "Doing other Mininet VM setup tasks..."
496

    
497
    # Remove avahi-daemon, which may cause unwanted discovery packets to be
498
    # sent during tests, near link status changes:
499
    echo "Removing avahi-daemon"
500
    $remove avahi-daemon
501

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

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

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

    
531
    # Install tcpdump, cmd-line packet dump tool.  Also install gitk,
532
    # a graphical git history viewer.
533
    $install tcpdump gitk
534

    
535
    # Install common text editors
536
    $install vim nano emacs
537

    
538
    # Install NTP
539
    $install ntp
540

    
541
    # Set git to colorize everything.
542
    git config --global color.diff auto
543
    git config --global color.status auto
544
    git config --global color.branch auto
545

    
546
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
547
    if [ "$DIST" = "Debian" ]; then
548
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
549
    fi
550

    
551
    # Clean unneeded debs:
552
    rm -f ~/linux-headers-* ~/linux-image-*
553
}
554

    
555
# Script to copy built OVS kernel module to where modprobe will
556
# find them automatically.  Removes the need to keep an environment variable
557
# for insmod usage, and works nicely with multiple kernel versions.
558
#
559
# The downside is that after each recompilation of OVS you'll need to
560
# re-run this script.  If you're using only one kernel version, then it may be
561
# a good idea to use a symbolic link in place of the copy below.
562
function modprobe {
563
    echo "Setting up modprobe for OVS kmod..."
564

    
565
    sudo cp $OVS_KMODS $DRIVERS_DIR
566
    sudo depmod -a ${KERNEL_NAME}
567
}
568

    
569
function all {
570
    echo "Running all commands..."
571
    kernel
572
    mn_deps
573
    mn_dev
574
    of
575
    wireshark
576
    ovs
577
    # NOX-classic is deprecated, but you can install it manually if desired.
578
    # nox
579
    pox
580
    oftest
581
    cbench
582
    echo "Enjoy Mininet!"
583
}
584

    
585
# Restore disk space and remove sensitive files before shipping a VM.
586
function vm_clean {
587
    echo "Cleaning VM..."
588
    sudo apt-get clean
589
    sudo apt-get autoremove
590
    sudo rm -rf /tmp/*
591
    sudo rm -rf openvswitch*.tar.gz
592

    
593
    # Remove sensistive files
594
    history -c  # note this won't work if you have multiple bash sessions
595
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
596
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
597
    sudo rm -f ~/.ssh/authorized_keys*
598

    
599
    # Remove Mininet files
600
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
601
    #sudo rm -f /usr/bin/mnexec
602

    
603
    # Clear optional dev script for SSH keychain load on boot
604
    rm -f ~/.bash_profile
605

    
606
    # Clear git changes
607
    git config --global user.name "None"
608
    git config --global user.email "None"
609

    
610
    # Note: you can shrink the .vmdk in vmware using
611
    # vmware-vdiskmanager -k *.vmdk
612
    echo "Zeroing out disk blocks for efficient compaction..."
613
    time sudo dd if=/dev/zero of=/tmp/zero bs=1M
614
    sync ; sleep 1 ; sync ; sudo rm -f /tmp/zero
615

    
616
}
617

    
618
function usage {
619
    printf '\nUsage: %s [-abcdfhkmnprtvwx03]\n\n' $(basename $0) >&2
620

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

    
627
    printf 'options:\n' >&2
628
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
629
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
630
    printf -- ' -c: (C)lean up after kernel install\n' >&2
631
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2
632
    printf -- ' -f: install open(F)low\n' >&2
633
    printf -- ' -h: print this (H)elp message\n' >&2
634
    printf -- ' -k: install new (K)ernel\n' >&2
635
    printf -- ' -m: install Open vSwitch kernel (M)odule from source dir\n' >&2
636
    printf -- ' -n: install mini(N)et dependencies + core files\n' >&2
637
    printf -- ' -e: install mininet d(E)veloper dependencies\n' >&2
638
    printf -- ' -p: install (P)OX OpenFlow Controller\n' >&2
639
    printf -- ' -r: remove existing Open vSwitch packages\n' >&2
640
    printf -- ' -t: complete o(T)her Mininet VM setup tasks\n' >&2
641
    printf -- ' -v: install open (V)switch\n' >&2
642
    printf -- ' -w: install OpenFlow (w)ireshark dissector\n' >&2
643
    printf -- ' -x: install NO(X) Classic OpenFlow controller\n' >&2
644
    printf -- ' -0: (default) -0[fx] installs OpenFlow 1.0 versions\n' >&2
645
    printf -- ' -3: -3[fx] installs OpenFlow 1.3 versions\n' >&2
646
    printf -- ' -i < directory >: sets the (I)nstallation directory for Mininet dependencies\n' >&2
647
    exit 2
648
}
649

    
650
OF_VERSION=1.0
651

    
652
if [ $# -eq 0 ]
653
then
654
    all
655
else
656
    while getopts 'abcdefhkmnprtvwx03i:' OPTION
657
    do
658
      case $OPTION in
659
      a)    all;;
660
      b)    cbench;;
661
      c)    kernel_clean;;
662
      d)    vm_clean;;
663
      f)    case $OF_VERSION in
664
            1.0) of;;
665
            1.3) of13;;
666
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
667
            esac;;
668
      h)    usage;;
669
      k)    kernel;;
670
      m)    modprobe;;
671
      n)    mn_deps;;
672
      e)    mn_dev;;
673
      p)    pox;;
674
      r)    remove_ovs;;
675
      t)    vm_other;;
676
      v)    ovs;;
677
      w)    wireshark;;
678
      x)    case $OF_VERSION in
679
            1.0) nox;;
680
            1.3) nox13;;
681
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
682
            esac;;
683
      0)    OF_VERSION=1.0;;
684
      3)    OF_VERSION=1.3;;
685
      i)    mkdir -p $OPTARG; # ensure the directory is created
686
            BUILD_DIR="$( cd -P "$OPTARG" && pwd )"; # get the full path of the directory
687
            echo "Dependency installation directory: $BUILD_DIR";;
688
      ?)    usage;;
689
      esac
690
    done
691
    shift $(($OPTIND - 1))
692
fi