Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 0c2fbaf1

History | View | Annotate | Download (24.2 KB)

1
#!/usr/bin/env bash
2

    
3
# Mininet install script for Ubuntu (and Debian Wheezy+)
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
fi
47
test -e /etc/fedora-release && DIST="Fedora"
48
test -e /etc/redhat-release && DIST="RedHatEnterpriseServer"
49
if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
50
    install='sudo yum -y install'
51
    remove='sudo yum -y erase'
52
    pkginst='sudo rpm -ivh'
53
    # Prereqs for this script
54
    if ! which lsb_release &> /dev/null; then
55
        $install redhat-lsb-core
56
    fi
57
fi
58
if which lsb_release &> /dev/null; then
59
    DIST=`lsb_release -is`
60
    RELEASE=`lsb_release -rs`
61
    CODENAME=`lsb_release -cs`
62
fi
63
echo "Detected Linux distribution: $DIST $RELEASE $CODENAME $ARCH"
64

    
65
# Kernel params
66

    
67
KERNEL_NAME=`uname -r`
68
KERNEL_HEADERS=kernel-headers-${KERNEL_NAME}
69

    
70
if ! echo $DIST | egrep 'Ubuntu|Debian|Fedora|RedHatEnterpriseServer'; then
71
    echo "Install.sh currently only supports Ubuntu, Debian, RedHat and Fedora."
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

    
79
# Determine whether version $1 >= version $2
80
# usage: if version_ge 1.20 1.2.3; then echo "true!"; fi
81
function version_ge {
82
    # sort -V sorts by *version number*
83
    latest=`printf "$1\n$2" | sort -V | tail -1`
84
    # If $1 is latest version, then $1 >= $2
85
    [ "$1" == "$latest" ]
86
}
87

    
88

    
89
# Kernel Deb pkg to be removed:
90
KERNEL_IMAGE_OLD=linux-image-2.6.26-33-generic
91

    
92
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
93

    
94
OVS_RELEASE=1.4.0
95
OVS_PACKAGE_LOC=https://github.com/downloads/mininet/mininet
96
OVS_BUILDSUFFIX=-ignore # was -2
97
OVS_PACKAGE_NAME=ovs-$OVS_RELEASE-core-$DIST_LC-$RELEASE-$ARCH$OVS_BUILDSUFFIX.tar
98
OVS_TAG=v$OVS_RELEASE
99

    
100
OF13_SWITCH_REV=${OF13_SWITCH_REV:-""}
101

    
102

    
103
function kernel {
104
    echo "Install Mininet-compatible kernel if necessary"
105
    sudo apt-get update
106
    if ! $install linux-image-$KERNEL_NAME; then
107
        echo "Could not install linux-image-$KERNEL_NAME"
108
        echo "Skipping - assuming installed kernel is OK."
109
    fi
110
}
111

    
112
function kernel_clean {
113
    echo "Cleaning kernel..."
114

    
115
    # To save disk space, remove previous kernel
116
    if ! $remove $KERNEL_IMAGE_OLD; then
117
        echo $KERNEL_IMAGE_OLD not installed.
118
    fi
119

    
120
    # Also remove downloaded packages:
121
    rm -f $HOME/linux-headers-* $HOME/linux-image-*
122
}
123

    
124
# Install Mininet deps
125
function mn_deps {
126
    echo "Installing Mininet dependencies"
127
    if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
128
        $install gcc make socat psmisc xterm openssh-clients iperf \
129
            iproute telnet python-setuptools libcgroup-tools \
130
            ethtool help2man pyflakes pylint python-pep8
131
    else
132
        $install gcc make socat psmisc xterm ssh iperf iproute telnet \
133
            python-setuptools cgroup-bin ethtool help2man \
134
            pyflakes pylint pep8
135
    fi
136

    
137
    echo "Installing Mininet core"
138
    pushd $MININET_DIR/mininet
139
    sudo make install
140
    popd
141
}
142

    
143
# Install Mininet developer dependencies
144
function mn_dev {
145
    echo "Installing Mininet developer dependencies"
146
    $install doxygen doxypy texlive-fonts-recommended
147
    if ! $install doxygen-latex; then
148
        echo "doxygen-latex not needed"
149
    fi
150
}
151

    
152
# The following will cause a full OF install, covering:
153
# -user switch
154
# The instructions below are an abbreviated version from
155
# http://www.openflowswitch.org/wk/index.php/Debian_Install
156
function of {
157
    echo "Installing OpenFlow reference implementation..."
158
    cd $BUILD_DIR
159
    $install autoconf automake libtool make gcc
160
    if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
161
        $install git pkgconfig glibc-devel
162
    else
163
        $install git-core autotools-dev pkg-config libc6-dev
164
    fi
165
    git clone git://openflowswitch.org/openflow.git
166
    cd $BUILD_DIR/openflow
167

    
168
    # Patch controller to handle more than 16 switches
169
    patch -p1 < $MININET_DIR/mininet/util/openflow-patches/controller.patch
170

    
171
    # Resume the install:
172
    ./boot.sh
173
    ./configure
174
    make
175
    sudo make install
176
    cd $BUILD_DIR
177
}
178

    
179
function of13 {
180
    echo "Installing OpenFlow 1.3 soft switch implementation..."
181
    cd $BUILD_DIR/
182
    $install  git-core autoconf automake autotools-dev pkg-config \
183
        make gcc g++ libtool libc6-dev cmake libpcap-dev libxerces-c2-dev  \
184
        unzip libpcre3-dev flex bison libboost-dev
185

    
186
    if [ ! -d "ofsoftswitch13" ]; then
187
        git clone https://github.com/CPqD/ofsoftswitch13.git
188
        if [[ -n "$OF13_SWITCH_REV" ]]; then
189
            cd ofsoftswitch13
190
            git checkout ${OF13_SWITCH_REV}
191
            cd ..
192
        fi
193
    fi
194

    
195
    # Install netbee
196
    if [ "$DIST" = "Ubuntu" ] && version_ge $RELEASE 14.04; then
197
        NBEESRC="nbeesrc-feb-24-2015"
198
        NBEEDIR="netbee"
199
    else
200
        NBEESRC="nbeesrc-jan-10-2013"
201
        NBEEDIR="nbeesrc-jan-10-2013"
202
    fi
203

    
204
    NBEEURL=${NBEEURL:-http://www.nbee.org/download/}
205
    wget -nc ${NBEEURL}${NBEESRC}.zip
206
    unzip ${NBEESRC}.zip
207
    cd ${NBEEDIR}/src
208
    cmake .
209
    make
210
    cd $BUILD_DIR/
211
    sudo cp ${NBEEDIR}/bin/libn*.so /usr/local/lib
212
    sudo ldconfig
213
    sudo cp -R ${NBEEDIR}/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

    
225
function install_wireshark {
226
    if ! which wireshark; then
227
        echo "Installing Wireshark"
228
        if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
229
            $install wireshark wireshark-gnome
230
        else
231
            $install wireshark tshark
232
        fi
233
    fi
234

    
235
    # Copy coloring rules: OF is white-on-blue:
236
    echo "Optionally installing wireshark color filters"
237
    mkdir -p $HOME/.wireshark
238
    cp -n $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
239

    
240
    echo "Checking Wireshark version"
241
    WSVER=`wireshark -v | egrep -o '[0-9\.]+' | head -1`
242
    if version_ge $WSVER 1.12; then
243
        echo "Wireshark version $WSVER >= 1.12 - returning"
244
        return
245
    fi
246

    
247
    echo "Cloning LoxiGen and building openflow.lua dissector"
248
    cd $BUILD_DIR
249
    git clone https://github.com/floodlight/loxigen.git
250
    cd loxigen
251
    make wireshark
252

    
253
    # Copy into plugin directory
254
    # libwireshark0/ on 11.04; libwireshark1/ on later
255
    WSDIR=`find /usr/lib -type d -name 'libwireshark*' | head -1`
256
    WSPLUGDIR=$WSDIR/plugins/
257
    PLUGIN=loxi_output/wireshark/openflow.lua
258
    sudo cp $PLUGIN $WSPLUGDIR
259
    echo "Copied openflow plugin $PLUGIN to $WSPLUGDIR"
260

    
261
    cd $BUILD_DIR
262
}
263

    
264

    
265
# Install Open vSwitch specific version Ubuntu package
266
function ubuntuOvs {
267
    echo "Creating and Installing Open vSwitch packages..."
268

    
269
    OVS_SRC=$BUILD_DIR/openvswitch
270
    OVS_TARBALL_LOC=http://openvswitch.org/releases
271

    
272
    if ! echo "$DIST" | egrep "Ubuntu|Debian" > /dev/null; then
273
        echo "OS must be Ubuntu or Debian"
274
        $cd BUILD_DIR
275
        return
276
    fi
277
    if [ "$DIST" = "Ubuntu" ] && ! version_ge $RELEASE 12.04; then
278
        echo "Ubuntu version must be >= 12.04"
279
        cd $BUILD_DIR
280
        return
281
    fi
282
    if [ "$DIST" = "Debian" ] && ! version_ge $RELEASE 7.0; then
283
        echo "Debian version must be >= 7.0"
284
        cd $BUILD_DIR
285
        return
286
    fi
287

    
288
    rm -rf $OVS_SRC
289
    mkdir -p $OVS_SRC
290
    cd $OVS_SRC
291

    
292
    if wget $OVS_TARBALL_LOC/openvswitch-$OVS_RELEASE.tar.gz 2> /dev/null; then
293
        tar xzf openvswitch-$OVS_RELEASE.tar.gz
294
    else
295
        echo "Failed to find OVS at $OVS_TARBALL_LOC/openvswitch-$OVS_RELEASE.tar.gz"
296
        cd $BUILD_DIR
297
        return
298
    fi
299

    
300
    # Remove any old packages
301
    $remove openvswitch-common openvswitch-datapath-dkms openvswitch-controller \
302
            openvswitch-pki openvswitch-switch
303

    
304
    # Get build deps
305
    $install build-essential fakeroot debhelper autoconf automake libssl-dev \
306
             pkg-config bzip2 openssl python-all procps python-qt4 \
307
             python-zopeinterface python-twisted-conch dkms
308

    
309
    # Build OVS
310
    cd $BUILD_DIR/openvswitch/openvswitch-$OVS_RELEASE
311
            DEB_BUILD_OPTIONS='parallel=2 nocheck' fakeroot debian/rules binary
312
    cd ..
313
    $pkginst openvswitch-common_$OVS_RELEASE*.deb openvswitch-datapath-dkms_$OVS_RELEASE*.deb \
314
             openvswitch-pki_$OVS_RELEASE*.deb openvswitch-switch_$OVS_RELEASE*.deb
315
    if $pkginst openvswitch-controller_$OVS_RELEASE*.deb; then
316
        echo "Ignoring error installing openvswitch-controller"
317
    fi
318

    
319
    modinfo openvswitch
320
    sudo ovs-vsctl show
321
    # Switch can run on its own, but
322
    # Mininet should control the controller
323
    # This appears to only be an issue on Ubuntu/Debian
324
    if sudo service openvswitch-controller stop; then
325
        echo "Stopped running controller"
326
    fi
327
    if [ -e /etc/init.d/openvswitch-controller ]; then
328
        sudo update-rc.d openvswitch-controller disable
329
    fi
330
}
331

    
332

    
333
# Install Open vSwitch
334

    
335
function ovs {
336
    echo "Installing Open vSwitch..."
337

    
338
    if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
339
        $install openvswitch openvswitch-controller
340
        return
341
    fi
342

    
343
    if [ "$DIST" = "Ubuntu" ] && ! version_ge $RELEASE 14.04; then
344
        # Older Ubuntu versions need openvswitch-datapath/-dkms
345
        # Manually installing openvswitch-datapath may be necessary
346
        # for manually built kernel .debs using Debian's defective kernel
347
        # packaging, which doesn't yield usable headers.
348
        if ! dpkg --get-selections | grep openvswitch-datapath; then
349
            # If you've already installed a datapath, assume you
350
            # know what you're doing and don't need dkms datapath.
351
            # Otherwise, install it.
352
            $install openvswitch-datapath-dkms
353
        fi
354
    fi
355

    
356
    $install openvswitch-switch
357
    if $install openvswitch-controller; then
358
        # Switch can run on its own, but
359
        # Mininet should control the controller
360
        # This appears to only be an issue on Ubuntu/Debian
361
        if sudo service openvswitch-controller stop; then
362
            echo "Stopped running controller"
363
        fi
364
        if [ -e /etc/init.d/openvswitch-controller ]; then
365
            sudo update-rc.d openvswitch-controller disable
366
        fi
367
    else
368
        echo "Attempting to install openvswitch-testcontroller"
369
        if ! $install openvswitch-testcontroller; then
370
            echo "Failed - skipping openvswitch-testcontroller"
371
        fi
372
    fi
373

    
374
}
375

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

    
397
function ivs {
398
    echo "Installing Indigo Virtual Switch..."
399

    
400
    IVS_SRC=$BUILD_DIR/ivs
401

    
402
    # Install dependencies
403
    $install git pkg-config gcc make libnl-3-dev libnl-route-3-dev libnl-genl-3-dev
404

    
405
    # Install IVS from source
406
    cd $BUILD_DIR
407
    git clone git://github.com/floodlight/ivs $IVS_SRC --recursive
408
    cd $IVS_SRC
409
    make
410
    sudo make install
411
}
412

    
413
# Install RYU
414
function ryu {
415
    echo "Installing RYU..."
416

    
417
    # install Ryu dependencies"
418
    $install autoconf automake g++ libtool python make
419
    if [ "$DIST" = "Ubuntu" ]; then
420
        $install libxml2 libxslt-dev python-pip python-dev
421
        sudo pip install gevent
422
    elif [ "$DIST" = "Debian" ]; then
423
        $install libxml2 libxslt-dev python-pip python-dev
424
        sudo pip install gevent
425
    fi
426

    
427
    # if needed, update python-six
428
    SIX_VER=`pip show six | grep Version | awk '{print $2}'`
429
    if version_ge 1.7.0 $SIX_VER; then
430
        echo "Installing python-six version 1.7.0..."
431
        sudo pip install -I six==1.7.0
432
    fi
433
    # fetch RYU
434
    cd $BUILD_DIR/
435
    git clone git://github.com/osrg/ryu.git ryu
436
    cd ryu
437

    
438
    # install ryu
439
    sudo python ./setup.py install
440

    
441
    # Add symbolic link to /usr/bin
442
    sudo ln -s ./bin/ryu-manager /usr/local/bin/ryu-manager
443
}
444

    
445
# Install NOX with tutorial files
446
function nox {
447
    echo "Installing NOX w/tutorial files..."
448

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

    
462
    # Fetch NOX destiny
463
    cd $BUILD_DIR/
464
    git clone https://github.com/noxrepo/nox-classic.git noxcore
465
    cd noxcore
466
    if ! git checkout -b destiny remotes/origin/destiny ; then
467
        echo "Did not check out a new destiny branch - assuming current branch is destiny"
468
    fi
469

    
470
    # Apply patches
471
    git checkout -b tutorial-destiny
472
    git am $MININET_DIR/mininet/util/nox-patches/*tutorial-port-nox-destiny*.patch
473
    if [ "$DIST" = "Ubuntu" ] && version_ge $RELEASE 12.04; then
474
        git am $MININET_DIR/mininet/util/nox-patches/*nox-ubuntu12-hacks.patch
475
    fi
476

    
477
    # Build
478
    ./boot.sh
479
    mkdir build
480
    cd build
481
    ../configure
482
    make -j3
483
    #make check
484

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

    
488
    # To verify this install:
489
    #cd ~/noxcore/build/src
490
    #./nox_core -v -i ptcp:
491
}
492

    
493
# Install NOX Classic/Zaku for OpenFlow 1.3
494
function nox13 {
495
    echo "Installing NOX w/tutorial files..."
496

    
497
    # Install NOX deps:
498
    $install autoconf automake g++ libtool python python-twisted \
499
        swig libssl-dev make
500
    if [ "$DIST" = "Debian" ]; then
501
        $install libboost1.35-dev
502
    elif [ "$DIST" = "Ubuntu" ]; then
503
        $install python-dev libboost-dev
504
        $install libboost-filesystem-dev
505
        $install libboost-test-dev
506
    fi
507

    
508
    # Fetch NOX destiny
509
    cd $BUILD_DIR/
510
    git clone https://github.com/CPqD/nox13oflib.git
511
    cd nox13oflib
512

    
513
    # Build
514
    ./boot.sh
515
    mkdir build
516
    cd build
517
    ../configure
518
    make -j3
519
    #make check
520

    
521
    # To verify this install:
522
    #cd ~/nox13oflib/build/src
523
    #./nox_core -v -i ptcp:
524
}
525

    
526

    
527
# "Install" POX
528
function pox {
529
    echo "Installing POX into $BUILD_DIR/pox..."
530
    cd $BUILD_DIR
531
    git clone https://github.com/noxrepo/pox.git
532
}
533

    
534
# Install OFtest
535
function oftest {
536
    echo "Installing oftest..."
537

    
538
    # Install deps:
539
    $install tcpdump python-scapy
540

    
541
    # Install oftest:
542
    cd $BUILD_DIR/
543
    git clone git://github.com/floodlight/oftest
544
}
545

    
546
# Install cbench
547
function cbench {
548
    echo "Installing cbench..."
549

    
550
    if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
551
        $install net-snmp-devel libpcap-devel libconfig-devel
552
    else
553
        $install libsnmp-dev libpcap-dev libconfig-dev
554
    fi
555
    cd $BUILD_DIR/
556
    git clone git://gitosis.stanford.edu/oflops.git
557
    cd oflops
558
    sh boot.sh || true # possible error in autoreconf, so run twice
559
    sh boot.sh
560
    ./configure --with-openflow-src-dir=$BUILD_DIR/openflow
561
    make
562
    sudo make install || true # make install fails; force past this
563
}
564

    
565
function vm_other {
566
    echo "Doing other Mininet VM setup tasks..."
567

    
568
    # Remove avahi-daemon, which may cause unwanted discovery packets to be
569
    # sent during tests, near link status changes:
570
    echo "Removing avahi-daemon"
571
    $remove avahi-daemon
572

    
573
    # was: Disable IPv6.  Add to /etc/modprobe.d/blacklist:
574
    #echo "Attempting to disable IPv6"
575
    #if [ "$DIST" = "Ubuntu" ]; then
576
    #    BLACKLIST=/etc/modprobe.d/blacklist.conf
577
    #else
578
    #    BLACKLIST=/etc/modprobe.d/blacklist
579
    #fi
580
    #sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
581
    echo "Disabling IPv6"
582
    # Disable IPv6
583
    if ! grep 'disable_ipv6' /etc/sysctl.conf; then
584
        echo 'Disabling IPv6'
585
        echo '
586
# Mininet: disable IPv6
587
net.ipv6.conf.all.disable_ipv6 = 1
588
net.ipv6.conf.default.disable_ipv6 = 1
589
net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
590
    fi
591
    # Since the above doesn't disable neighbor discovery, also do this:
592
    if ! grep 'ipv6.disable' /etc/default/grub; then
593
        sudo sed -i -e \
594
        's/GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 /' \
595
        /etc/default/grub
596
        sudo update-grub
597
    fi
598
    # Disabling IPv6 breaks X11 forwarding via ssh
599
    line='AddressFamily inet'
600
    file='/etc/ssh/sshd_config'
601
    echo "Adding $line to $file"
602
    if ! grep "$line" $file > /dev/null; then
603
        echo "$line" | sudo tee -a $file > /dev/null
604
    fi
605

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

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

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

    
616
    # Install NTP
617
    $install ntp
618

    
619
    # Install vconfig for VLAN example
620
    if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
621
        $install vconfig
622
    else
623
        $install vlan
624
    fi
625

    
626
    # Set git to colorize everything.
627
    git config --global color.diff auto
628
    git config --global color.status auto
629
    git config --global color.branch auto
630

    
631
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
632
    if [ "$DIST" = "Debian" ]; then
633
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
634
    fi
635

    
636
    # Clean unneeded debs:
637
    rm -f ~/linux-headers-* ~/linux-image-*
638
}
639

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

    
659
function all {
660
    if [ "$DIST" = "Fedora" ]; then
661
        printf "\nFedora 18+ support (still work in progress):\n"
662
        printf " * Fedora 18+ has kernel 3.10 RPMS in the updates repositories\n"
663
        printf " * Fedora 18+ has openvswitch 1.10 RPMS in the updates repositories\n"
664
        printf " * the install.sh script options [-bfnpvw] should work.\n"
665
        printf " * for a basic setup just try:\n"
666
        printf "       install.sh -fnpv\n\n"
667
        exit 3
668
    fi
669
    echo "Installing all packages except for -eix (doxypy, ivs, nox-classic)..."
670
    kernel
671
    mn_deps
672
    # Skip mn_dev (doxypy/texlive/fonts/etc.) because it's huge
673
    # mn_dev
674
    of
675
    install_wireshark
676
    ovs
677
    # We may add ivs once it's more mature
678
    # ivs
679
    # NOX-classic is deprecated, but you can install it manually if desired.
680
    # nox
681
    pox
682
    oftest
683
    cbench
684
    echo "Enjoy Mininet!"
685
}
686

    
687
# Restore disk space and remove sensitive files before shipping a VM.
688
function vm_clean {
689
    echo "Cleaning VM..."
690
    sudo apt-get clean
691
    sudo apt-get autoremove
692
    sudo rm -rf /tmp/*
693
    sudo rm -rf openvswitch*.tar.gz
694

    
695
    # Remove sensistive files
696
    history -c  # note this won't work if you have multiple bash sessions
697
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
698
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
699
    sudo rm -f ~/.ssh/authorized_keys*
700

    
701
    # Remove Mininet files
702
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
703
    #sudo rm -f /usr/bin/mnexec
704

    
705
    # Clear optional dev script for SSH keychain load on boot
706
    rm -f ~/.bash_profile
707

    
708
    # Clear git changes
709
    git config --global user.name "None"
710
    git config --global user.email "None"
711

    
712
    # Note: you can shrink the .vmdk in vmware using
713
    # vmware-vdiskmanager -k *.vmdk
714
    echo "Zeroing out disk blocks for efficient compaction..."
715
    time sudo dd if=/dev/zero of=/tmp/zero bs=1M
716
    sync ; sleep 1 ; sync ; sudo rm -f /tmp/zero
717

    
718
}
719

    
720
function usage {
721
    printf '\nUsage: %s [-abcdfhikmnprtvVwxy03]\n\n' $(basename $0) >&2
722

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

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

    
755
OF_VERSION=1.0
756

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