Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 76d3252c

History | View | Annotate | Download (25 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
    # Truly non-interactive apt-get installation
40
    install='sudo DEBIAN_FRONTEND=noninteractive apt-get -y -q install'
41
    remove='sudo DEBIAN_FRONTEND=noninteractive apt-get -y -q remove'
42
    pkginst='sudo dpkg -i'
43
    # Prereqs for this script
44
    if ! which lsb_release &> /dev/null; then
45
        $install lsb-release
46
    fi
47
fi
48
test -e /etc/fedora-release && DIST="Fedora"
49
test -e /etc/redhat-release && DIST="RedHatEnterpriseServer"
50
if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
51
    install='sudo yum -y install'
52
    remove='sudo yum -y erase'
53
    pkginst='sudo rpm -ivh'
54
    # Prereqs for this script
55
    if ! which lsb_release &> /dev/null; then
56
        $install redhat-lsb-core
57
    fi
58
fi
59
if which lsb_release &> /dev/null; then
60
    DIST=`lsb_release -is`
61
    RELEASE=`lsb_release -rs`
62
    CODENAME=`lsb_release -cs`
63
fi
64
echo "Detected Linux distribution: $DIST $RELEASE $CODENAME $ARCH"
65

    
66
# Kernel params
67

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

    
71
if ! echo $DIST | egrep 'Ubuntu|Debian|Fedora|RedHatEnterpriseServer'; then
72
    echo "Install.sh currently only supports Ubuntu, Debian, RedHat and Fedora."
73
    exit 1
74
fi
75

    
76
# More distribution info
77
DIST_LC=`echo $DIST | tr [A-Z] [a-z]` # as lower case
78

    
79

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

    
89

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

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

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

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

    
103

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

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

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

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

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

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

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

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

    
171
    # Patch controller to handle more than 16 switches
172
    patch -p1 < $MININET_DIR/mininet/util/openflow-patches/controller.patch
173

    
174
    # Resume the install:
175
    ./boot.sh
176
    ./configure
177
    make
178
    sudo make install
179
    cd $BUILD_DIR
180
}
181

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

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

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

    
207
    NBEEURL=${NBEEURL:-http://www.nbee.org/download/}
208
    wget -nc ${NBEEURL}${NBEESRC}.zip
209
    unzip ${NBEESRC}.zip
210
    cd ${NBEEDIR}/src
211
    cmake .
212
    make
213
    cd $BUILD_DIR/
214
    sudo cp ${NBEEDIR}/bin/libn*.so /usr/local/lib
215
    sudo ldconfig
216
    sudo cp -R ${NBEEDIR}/include/ /usr/
217

    
218
    # Resume the install:
219
    cd $BUILD_DIR/ofsoftswitch13
220
    ./boot.sh
221
    ./configure
222
    make
223
    sudo make install
224
    cd $BUILD_DIR
225
}
226

    
227

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

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

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

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

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

    
264
    cd $BUILD_DIR
265
}
266

    
267

    
268
# Install Open vSwitch specific version Ubuntu package
269
function ubuntuOvs {
270
    echo "Creating and Installing Open vSwitch packages..."
271

    
272
    OVS_SRC=$BUILD_DIR/openvswitch
273
    OVS_TARBALL_LOC=http://openvswitch.org/releases
274

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

    
291
    rm -rf $OVS_SRC
292
    mkdir -p $OVS_SRC
293
    cd $OVS_SRC
294

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

    
303
    # Remove any old packages
304
    $remove openvswitch-common openvswitch-datapath-dkms openvswitch-controller \
305
            openvswitch-pki openvswitch-switch
306

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

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

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

    
335

    
336
# Install Open vSwitch
337

    
338
function ovs {
339
    echo "Installing Open vSwitch..."
340

    
341
    if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
342
        $install openvswitch openvswitch-controller
343
        return
344
    fi
345

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

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

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

    
405
function ivs {
406
    echo "Installing Indigo Virtual Switch..."
407

    
408
    IVS_SRC=$BUILD_DIR/ivs
409

    
410
    # Install dependencies
411
    $install git pkg-config gcc make libnl-3-dev libnl-route-3-dev libnl-genl-3-dev
412

    
413
    # Install IVS from source
414
    cd $BUILD_DIR
415
    git clone git://github.com/floodlight/ivs $IVS_SRC --recursive
416
    cd $IVS_SRC
417
    make
418
    sudo make install
419
}
420

    
421
# Install RYU
422
function ryu {
423
    echo "Installing RYU..."
424

    
425
    # install Ryu dependencies"
426
    $install autoconf automake g++ libtool python make
427
    if [ "$DIST" = "Ubuntu" -o "$DIST" = "Debian" ]; then
428
        $install libxml2 libxslt-dev python-pip python-dev
429
        sudo pip install --upgrade gevent pbr webob routes paramiko \\
430
            oslo.config
431
    fi
432

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

    
444
    # install ryu
445
    sudo python ./setup.py install
446

    
447
    # Add symbolic link to /usr/bin
448
    sudo ln -s ./bin/ryu-manager /usr/local/bin/ryu-manager
449
}
450

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

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

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

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

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

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

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

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

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

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

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

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

    
532

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

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

    
544
    # Install deps:
545
    $install tcpdump python-scapy
546

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

    
552
# Install cbench
553
function cbench {
554
    echo "Installing cbench..."
555

    
556
    if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
557
        $install net-snmp-devel libpcap-devel libconfig-devel
558
    else
559
        $install libsnmp-dev libpcap-dev libconfig-dev
560
    fi
561
    cd $BUILD_DIR/
562
    # was:  git clone git://gitosis.stanford.edu/oflops.git
563
    # Use our own fork on github for now:
564
    git clone git://github.com/mininet/oflops
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
    echo "Disabling IPv6"
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
    # Since the above doesn't disable neighbor discovery, also do this:
600
    if ! grep 'ipv6.disable' /etc/default/grub; then
601
        sudo sed -i -e \
602
        's/GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 /' \
603
        /etc/default/grub
604
        sudo update-grub
605
    fi
606
    # Disabling IPv6 breaks X11 forwarding via ssh
607
    line='AddressFamily inet'
608
    file='/etc/ssh/sshd_config'
609
    echo "Adding $line to $file"
610
    if ! grep "$line" $file > /dev/null; then
611
        echo "$line" | sudo tee -a $file > /dev/null
612
    fi
613

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

    
617
    # Install tcpdump, cmd-line packet dump tool.  Also install gitk,
618
    # a graphical git history viewer.
619
    $install tcpdump gitk
620

    
621
    # Install common text editors
622
    $install vim nano emacs
623

    
624
    # Install NTP
625
    $install ntp
626

    
627
    # Install vconfig for VLAN example
628
    if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
629
        $install vconfig
630
    else
631
        $install vlan
632
    fi
633

    
634
    # Set git to colorize everything.
635
    git config --global color.diff auto
636
    git config --global color.status auto
637
    git config --global color.branch auto
638

    
639
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
640
    if [ "$DIST" = "Debian" ]; then
641
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
642
    fi
643

    
644
    # Clean unneeded debs:
645
    rm -f ~/linux-headers-* ~/linux-image-*
646
}
647

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

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

    
695
# Restore disk space and remove sensitive files before shipping a VM.
696
function vm_clean {
697
    echo "Cleaning VM..."
698
    sudo apt-get clean
699
    sudo apt-get autoremove
700
    sudo rm -rf /tmp/*
701
    sudo rm -rf openvswitch*.tar.gz
702

    
703
    # Remove sensistive files
704
    history -c  # note this won't work if you have multiple bash sessions
705
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
706
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
707
    sudo rm -f ~/.ssh/authorized_keys*
708

    
709
    # Remove SSH keys and regenerate on boot
710
    echo 'Removing SSH keys from /etc/ssh/'
711
    sudo rm -f /etc/ssh/*key*
712
    if ! grep mininet /etc/rc.local >& /dev/null; then
713
        sudo sed -i -e "s/exit 0//" /etc/rc.local
714
        echo '
715
# mininet: regenerate ssh keys if we deleted them
716
if ! stat -t /etc/ssh/*key* >/dev/null 2>&1; then
717
    /usr/sbin/dpkg-reconfigure openssh-server
718
fi
719
exit 0
720
' | sudo tee -a /etc/rc.local > /dev/null
721
    fi
722

    
723
    # Remove Mininet files
724
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
725
    #sudo rm -f /usr/bin/mnexec
726

    
727
    # Clear optional dev script for SSH keychain load on boot
728
    rm -f ~/.bash_profile
729

    
730
    # Clear git changes
731
    git config --global user.name "None"
732
    git config --global user.email "None"
733

    
734
    # Note: you can shrink the .vmdk in vmware using
735
    # vmware-vdiskmanager -k *.vmdk
736
    echo "Zeroing out disk blocks for efficient compaction..."
737
    time sudo dd if=/dev/zero of=/tmp/zero bs=1M || true
738
    sync ; sleep 1 ; sync ; sudo rm -f /tmp/zero
739

    
740
}
741

    
742
function usage {
743
    printf '\nUsage: %s [-abcdfhikmnprtvVwxy03]\n\n' $(basename $0) >&2
744

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

    
751
    printf 'options:\n' >&2
752
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
753
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
754
    printf -- ' -c: (C)lean up after kernel install\n' >&2
755
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2
756
    printf -- ' -e: install Mininet d(E)veloper dependencies\n' >&2
757
    printf -- ' -f: install Open(F)low\n' >&2
758
    printf -- ' -h: print this (H)elp message\n' >&2
759
    printf -- ' -i: install (I)ndigo Virtual Switch\n' >&2
760
    printf -- ' -k: install new (K)ernel\n' >&2
761
    printf -- ' -m: install Open vSwitch kernel (M)odule from source dir\n' >&2
762
    printf -- ' -n: install Mini(N)et dependencies + core files\n' >&2
763
    printf -- ' -p: install (P)OX OpenFlow Controller\n' >&2
764
    printf -- ' -r: remove existing Open vSwitch packages\n' >&2
765
    printf -- ' -s <dir>: place dependency (S)ource/build trees in <dir>\n' >&2
766
    printf -- ' -t: complete o(T)her Mininet VM setup tasks\n' >&2
767
    printf -- ' -v: install Open (V)switch\n' >&2
768
    printf -- ' -V <version>: install a particular version of Open (V)switch on Ubuntu\n' >&2
769
    printf -- ' -w: install OpenFlow (W)ireshark dissector\n' >&2
770
    printf -- ' -y: install R(y)u Controller\n' >&2
771
    printf -- ' -x: install NO(X) Classic OpenFlow controller\n' >&2
772
    printf -- ' -0: (default) -0[fx] installs OpenFlow 1.0 versions\n' >&2
773
    printf -- ' -3: -3[fx] installs OpenFlow 1.3 versions\n' >&2
774
    exit 2
775
}
776

    
777
OF_VERSION=1.0
778

    
779
if [ $# -eq 0 ]
780
then
781
    all
782
else
783
    while getopts 'abcdefhikmnprs:tvV:wxy03' OPTION
784
    do
785
      case $OPTION in
786
      a)    all;;
787
      b)    cbench;;
788
      c)    kernel_clean;;
789
      d)    vm_clean;;
790
      e)    mn_dev;;
791
      f)    case $OF_VERSION in
792
            1.0) of;;
793
            1.3) of13;;
794
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
795
            esac;;
796
      h)    usage;;
797
      i)    ivs;;
798
      k)    kernel;;
799
      m)    modprobe;;
800
      n)    mn_deps;;
801
      p)    pox;;
802
      r)    remove_ovs;;
803
      s)    mkdir -p $OPTARG; # ensure the directory is created
804
            BUILD_DIR="$( cd -P "$OPTARG" && pwd )"; # get the full path
805
            echo "Dependency installation directory: $BUILD_DIR";;
806
      t)    vm_other;;
807
      v)    ovs;;
808
      V)    OVS_RELEASE=$OPTARG;
809
            ubuntuOvs;;
810
      w)    install_wireshark;;
811
      x)    case $OF_VERSION in
812
            1.0) nox;;
813
            1.3) nox13;;
814
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
815
            esac;;
816
      y)    ryu;;
817
      0)    OF_VERSION=1.0;;
818
      3)    OF_VERSION=1.3;;
819
      ?)    usage;;
820
      esac
821
    done
822
    shift $(($OPTIND - 1))
823
fi