Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ b0fb3988

History | View | Annotate | Download (16.3 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
# Location of CONFIG_NET_NS-enabled kernel(s)
13
KERNEL_LOC=http://www.openflow.org/downloads/mininet
14

    
15
# Attempt to identify Linux release
16

    
17
DIST=Unknown
18
RELEASE=Unknown
19
CODENAME=Unknown
20
ARCH=`uname -m`
21
if [ "$ARCH" = "x86_64" ]; then ARCH="amd64"; fi
22
if [ "$ARCH" = "i686" ]; then ARCH="i386"; fi
23

    
24
test -e /etc/debian_version && DIST="Debian"
25
grep Ubuntu /etc/lsb-release &> /dev/null && DIST="Ubuntu"
26
if [ "$DIST" = "Ubuntu" ] || [ "$DIST" = "Debian" ]; then
27
    install='sudo apt-get -y install'
28
    remove='sudo apt-get -y remove'
29
    pkginst='sudo dpkg -i'
30
    # Prereqs for this script
31
    if ! which lsb_release &> /dev/null; then
32
        $install lsb-release
33
    fi
34
    if ! which bc &> /dev/null; then
35
        $install bc
36
    fi 
37
fi
38
if which lsb_release &> /dev/null; then
39
    DIST=`lsb_release -is`
40
    RELEASE=`lsb_release -rs`
41
    CODENAME=`lsb_release -cs`
42
fi
43
echo "Detected Linux distribution: $DIST $RELEASE $CODENAME $ARCH"
44

    
45
# Kernel params
46

    
47
if [ "$DIST" = "Ubuntu" ]; then
48
    if [ "$RELEASE" = "10.04" ]; then
49
        KERNEL_NAME='3.0.0-15-generic'
50
    else
51
        KERNEL_NAME=`uname -r`
52
    fi
53
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}
54
elif [ "$DIST" = "Debian" ] && [ "$ARCH" = "i386" ] && [ "$CODENAME" = "lenny" ]; then
55
    KERNEL_NAME=2.6.33.1-mininet
56
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
57
    KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
58
else
59
    echo "Install.sh currently only supports Ubuntu and Debian Lenny i386."
60
    exit 1
61
fi
62

    
63
# More distribution info
64
DIST_LC=`echo $DIST | tr [A-Z] [a-z]` # as lower case
65

    
66
# Kernel Deb pkg to be removed:
67
KERNEL_IMAGE_OLD=linux-image-2.6.26-33-generic
68

    
69
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
70

    
71
OVS_RELEASE=1.4.0
72
OVS_PACKAGE_LOC=https://github.com/downloads/mininet/mininet
73
OVS_BUILDSUFFIX=-ignore # was -2
74
OVS_PACKAGE_NAME=ovs-$OVS_RELEASE-core-$DIST_LC-$RELEASE-$ARCH$OVS_BUILDSUFFIX.tar
75
OVS_SRC=~/openvswitch
76
OVS_TAG=v$OVS_RELEASE
77
OVS_BUILD=$OVS_SRC/build-$KERNEL_NAME
78
OVS_KMODS=($OVS_BUILD/datapath/linux/{openvswitch_mod.ko,brcompat_mod.ko})
79

    
80
function kernel {
81
    echo "Install Mininet-compatible kernel if necessary"
82
    sudo apt-get update
83
    if [ "$DIST" = "Ubuntu" ] &&  [ "$RELEASE" = "10.04" ]; then
84
        $install linux-image-$KERNEL_NAME
85
    elif [ "$DIST" = "Debian" ]; then
86
        # The easy approach: download pre-built linux-image and linux-headers packages:
87
        wget -c $KERNEL_LOC/$KERNEL_HEADERS
88
        wget -c $KERNEL_LOC/$KERNEL_IMAGE
89

    
90
        # Install custom linux headers and image:
91
        $pkginst $KERNEL_IMAGE $KERNEL_HEADERS
92

    
93
        # The next two steps are to work around a bug in newer versions of
94
        # kernel-package, which fails to add initrd images with the latest kernels.
95
        # See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525032
96
        # Generate initrd image if the .deb didn't install it:
97
        if ! test -e /boot/initrd.img-${KERNEL_NAME}; then
98
            sudo update-initramfs -c -k ${KERNEL_NAME}
99
        fi
100
        
101
        # Ensure /boot/grub/menu.lst boots with initrd image:
102
        sudo update-grub
103

    
104
        # The default should be the new kernel. Otherwise, you may need to modify 
105
        # /boot/grub/menu.lst to set the default to the entry corresponding to the
106
        # kernel you just installed.
107
    fi
108
}
109

    
110
function kernel_clean {
111
    echo "Cleaning kernel..."
112

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

    
118
    # Also remove downloaded packages:
119
    rm -f ~/linux-headers-* ~/linux-image-*
120
}
121

    
122
# Install Mininet deps
123
function mn_deps {
124
    echo "Installing Mininet dependencies"
125
    $install gcc make screen psmisc xterm ssh iperf iproute \
126
        python-setuptools python-networkx cgroup-bin ethtool
127

    
128
    if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" = "10.04" ]; then
129
        echo "Upgrading networkx to avoid deprecation warning"
130
        sudo easy_install --upgrade networkx
131
    fi
132

    
133
    # Add sysctl parameters as noted in the INSTALL file to increase kernel 
134
    # limits to support larger setups:
135
    sudo su -c "cat $HOME/mininet/util/sysctl_addon >> /etc/sysctl.conf"
136

    
137
    # Load new sysctl settings:
138
    sudo sysctl -p
139
    
140
    echo "Installing Mininet core"
141
    pushd ~/mininet
142
    sudo make install
143
    popd
144
}
145

    
146
# The following will cause a full OF install, covering:
147
# -user switch
148
# The instructions below are an abbreviated version from
149
# http://www.openflowswitch.org/wk/index.php/Debian_Install
150
# ... modified to use Debian Lenny rather than unstable.
151
function of {
152
    echo "Installing OpenFlow reference implementation..."
153
    cd ~/
154
    $install git-core autoconf automake autotools-dev pkg-config \
155
		make gcc libtool libc6-dev 
156
    git clone git://openflowswitch.org/openflow.git
157
    cd ~/openflow
158

    
159
    # Patch controller to handle more than 16 switches
160
    patch -p1 < ~/mininet/util/openflow-patches/controller.patch
161

    
162
    # Resume the install:
163
    ./boot.sh
164
    ./configure
165
    make
166
    sudo make install
167

    
168
    # Remove avahi-daemon, which may cause unwanted discovery packets to be 
169
    # sent during tests, near link status changes:
170
    $remove avahi-daemon
171

    
172
    # Disable IPv6.  Add to /etc/modprobe.d/blacklist:
173
    if [ "$DIST" = "Ubuntu" ]; then
174
        BLACKLIST=/etc/modprobe.d/blacklist.conf
175
    else
176
        BLACKLIST=/etc/modprobe.d/blacklist
177
    fi
178
    sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
179
    cd ~
180
}
181

    
182
function wireshark {
183
    echo "Installing Wireshark dissector..."
184

    
185
    sudo apt-get install -y wireshark libgtk2.0-dev
186

    
187
    if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" != "10.04" ]; then
188
        # Install newer version
189
        sudo apt-get install -y scons mercurial libglib2.0-dev
190
        sudo apt-get install -y libwiretap-dev libwireshark-dev
191
        cd ~
192
        hg clone https://bitbucket.org/barnstorm/of-dissector
193
        cd of-dissector/src
194
        export WIRESHARK=/usr/include/wireshark
195
        scons
196
        # libwireshark0/ on 11.04; libwireshark1/ on later
197
        WSDIR=`ls -d /usr/lib/wireshark/libwireshark* | head -1`
198
        WSPLUGDIR=$WSDIR/plugins/
199
        sudo cp openflow.so $WSPLUGDIR
200
        echo "Copied openflow plugin to $WSPLUGDIR"
201
    else
202
        # Install older version from reference source
203
        cd ~/openflow/utilities/wireshark_dissectors/openflow
204
        make
205
        sudo make install
206
    fi
207

    
208
    # Copy coloring rules: OF is white-on-blue:
209
    mkdir -p ~/.wireshark
210
    cp ~/mininet/util/colorfilters ~/.wireshark
211
}
212

    
213

    
214
# Install Open vSwitch
215
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
216
function ovs {
217
    echo "Installing Open vSwitch..."
218

    
219
    # Required for module build/dkms install
220
    $install $KERNEL_HEADERS
221

    
222
    # First see if we have packages
223
    # XXX wget -c seems to fail from github/amazon s3
224
    cd /tmp
225
    if wget $OVS_PACKAGE_LOC/$OVS_PACKAGE_NAME; then
226
	$install patch dkms fakeroot python-argparse
227
        tar xf $OVS_PACKAGE_NAME
228
        orig=`tar tf $OVS_PACKAGE_NAME`
229
        # Now install packages in reasonable dependency order
230
        order='dkms common pki openvswitch-switch brcompat controller'
231
        pkgs=""
232
        for p in $order; do
233
            pkg=`echo "$orig" | grep $p`
234
	    # Annoyingly, things seem to be missing without this flag
235
            $pkginst --force-confmiss $pkg
236
        done
237
        # Switch can run on its own, but 
238
        # Mininet should control the controller
239
	if [ -e /etc/init.d/openvswitch-controller ]; then
240
            if sudo service openvswitch-controller stop; then
241
                echo "Stopped running controller"
242
            fi
243
            sudo update-rc.d openvswitch-controller disable
244
        fi
245
        echo "Done (hopefully) installing packages"
246
        cd ~
247
        return
248
    fi
249

    
250
    # Otherwise try distribution's OVS packages
251
    if [ "$DIST" = "Ubuntu" ] && [ `echo "$RELEASE >= 11.10" | bc` = 1 ]; then
252
        if ! dpkg --get-selections | grep openvswitch-datapath; then
253
            # If you've already installed a datapath, assume you
254
            # know what you're doing and don't need dkms datapath.
255
            # Otherwise, install it.
256
            $install openvswitch-datapath-dkms
257
        fi
258
	if $install openvswitch-switch openvswitch-controller; then
259
            return
260
        fi
261
    fi
262

    
263
    $install pkg-config gcc make python-dev libssl-dev libtool
264

    
265
    if [ "$DIST" = "Debian" ]; then
266
        if [ "$CODENAME" = "lenny" ]; then
267
            $install git-core
268
            # Install Autoconf 2.63+ backport from Debian Backports repo:
269
            # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
270
            sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
271
            sudo apt-get update
272
            sudo apt-get -y --force-yes install debian-backports-keyring
273
            sudo apt-get -y --force-yes -t lenny-backports install autoconf
274
        fi
275
    else
276
        $install git
277
    fi    
278

    
279
    # Install OVS from release
280
    cd ~/
281
    git clone git://openvswitch.org/openvswitch $OVS_SRC
282
    cd $OVS_SRC
283
    git checkout $OVS_TAG
284
    ./boot.sh
285
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
286
    if [ ! -e $BUILDDIR ]; then
287
        echo "Creating build sdirectory $BUILDDIR"
288
        sudo mkdir -p $BUILDDIR
289
    fi
290
    opts="--with-linux=$BUILDDIR"
291
    mkdir -p $OVS_BUILD
292
    cd $OVS_BUILD
293
    ../configure $opts
294
    make
295
    sudo make install
296

    
297
    modprobe
298
}
299

    
300
function remove_ovs {
301
    pkgs=`dpkg --get-selections | grep openvswitch | awk '{ print $1;}'`
302
    echo "Removing existing Open vSwitch packages:"
303
    echo $pkgs
304
    if ! $remove $pkgs; then
305
        echo "Not all packages removed correctly"
306
    fi
307
    # For some reason this doesn't happen
308
    if scripts=`ls /etc/init.d/*openvswitch* 2>/dev/null`; then
309
        echo $scripts
310
        for s in $scripts; do
311
            s=$(basename $s)
312
            echo SCRIPT $s
313
            sudo service $s stop
314
            sudo rm -f /etc/init.d/$s
315
            sudo update-rc.d -f $s remove
316
        done
317
    fi
318
    echo "Done removing OVS"
319
}
320

    
321
# Install NOX with tutorial files
322
function nox {
323
    echo "Installing NOX w/tutorial files..."
324

    
325
    # Install NOX deps:
326
    $install autoconf automake g++ libtool python python-twisted \
327
		swig libssl-dev make
328
    if [ "$DIST" = "Debian" ]; then
329
        $install libboost1.35-dev
330
    elif [ "$DIST" = "Ubuntu" ]; then
331
        $install python-dev libboost-dev 
332
        $install libboost-filesystem-dev
333
        $install libboost-test-dev
334
    fi
335
    # Install NOX optional deps:
336
    $install libsqlite3-dev python-simplejson
337

    
338
    # Fetch NOX destiny
339
    cd ~/
340
    git clone git://noxrepo.org/nox noxcore
341
    cd noxcore
342
    git checkout -b destiny remotes/origin/destiny
343

    
344
    # Apply patches
345
    git checkout -b tutorial-destiny
346
    git am ~/mininet/util/nox-patches/*tutorial-port-nox-destiny*.patch
347
    if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 12.04` -eq 1 ]; then
348
        git am ~/mininet/util/nox-patches/*nox-ubuntu12-hacks.patch
349
    fi
350

    
351
    # Build
352
    ./boot.sh
353
    mkdir build
354
    cd build
355
    ../configure
356
    make -j3
357
    #make check
358

    
359
    # Add NOX_CORE_DIR env var:
360
    sed -i -e 's|# for examples$|&\nexport NOX_CORE_DIR=~/noxcore/build/src|' ~/.bashrc
361

    
362
    # To verify this install:
363
    #cd ~/noxcore/build/src
364
    #./nox_core -v -i ptcp:
365
}
366

    
367
# Install OFtest
368
function oftest {
369
    echo "Installing oftest..."
370

    
371
    # Install deps:
372
    $install tcpdump python-scapy
373

    
374
    # Install oftest:
375
    cd ~/
376
    git clone git://openflow.org/oftest
377
    cd oftest
378
    cd tools/munger
379
    sudo make install
380
}
381

    
382
# Install cbench
383
function cbench {
384
    echo "Installing cbench..."
385
    
386
    $install libsnmp-dev libpcap-dev
387
    cd ~/
388
    git clone git://openflow.org/oflops.git
389
    cd oflops
390
    sh boot.sh || true # possible error in autoreconf, so run twice
391
    sh boot.sh
392
    ./configure --with-openflow-src-dir=$HOME/openflow
393
    make
394
    sudo make install || true # make install fails; force past this
395
}
396

    
397
function other {
398
    echo "Doing other setup tasks..."
399

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

    
403
    # Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
404
    # a graphical git history viewer.
405
    $install tcpdump tshark gitk
406

    
407
    # Install common text editors
408
    $install vim nano emacs
409

    
410
    # Install NTP
411
    $install ntp
412

    
413
    # Set git to colorize everything.
414
    git config --global color.diff auto
415
    git config --global color.status auto
416
    git config --global color.branch auto
417

    
418
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
419
    if [ "$DIST" = "Debian" ]; then
420
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
421
    fi
422

    
423
    # Clean unneeded debs:
424
    rm -f ~/linux-headers-* ~/linux-image-*
425
}
426

    
427
# Script to copy built OVS kernel module to where modprobe will
428
# find them automatically.  Removes the need to keep an environment variable
429
# for insmod usage, and works nicely with multiple kernel versions.
430
#
431
# The downside is that after each recompilation of OVS you'll need to
432
# re-run this script.  If you're using only one kernel version, then it may be
433
# a good idea to use a symbolic link in place of the copy below.
434
function modprobe {
435
    echo "Setting up modprobe for OVS kmod..."
436

    
437
    sudo cp $OVS_KMODS $DRIVERS_DIR
438
    sudo depmod -a ${KERNEL_NAME}
439
}
440

    
441
function all {
442
    echo "Running all commands..."
443
    kernel
444
    mn_deps
445
    of
446
    wireshark
447
    ovs
448
    nox
449
    oftest
450
    cbench
451
    other
452
    echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
453
    echo "Enjoy Mininet!"
454
}
455

    
456
# Restore disk space and remove sensitive files before shipping a VM.
457
function vm_clean {
458
    echo "Cleaning VM..."
459
    sudo apt-get clean
460
    sudo rm -rf /tmp/*
461
    sudo rm -rf openvswitch*.tar.gz
462

    
463
    # Remove sensistive files
464
    history -c  # note this won't work if you have multiple bash sessions
465
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
466
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
467
    sudo rm -f ~/.ssh/authorized_keys*
468

    
469
    # Remove Mininet files
470
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
471
    #sudo rm -f /usr/bin/mnexec
472

    
473
    # Clear optional dev script for SSH keychain load on boot
474
    rm -f ~/.bash_profile
475

    
476
    # Clear git changes
477
    git config --global user.name "None"
478
    git config --global user.email "None"
479

    
480
    # Remove mininet install script
481
    rm -f install-mininet.sh
482
}
483

    
484
function usage {
485
    printf 'Usage: %s [-acdfhkmntvxy]\n\n' $(basename $0) >&2
486
    
487
    printf 'This install script attempts to install useful packages\n' >&2
488
    printf 'for Mininet. It should (hopefully) work on Ubuntu 10.04, 11.10\n' >&2
489
    printf 'and Debian 5.0 (Lenny). If you run into trouble, try\n' >&2
490
    printf 'installing one thing at a time, and looking at the \n' >&2
491
    printf 'specific installation function in this script.\n\n' >&2
492

    
493
    printf 'options:\n' >&2
494
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
495
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
496
    printf -- ' -c: (C)lean up after kernel install\n' >&2
497
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2    
498
    printf -- ' -f: install open(F)low\n' >&2
499
    printf -- ' -h: print this (H)elp message\n' >&2
500
    printf -- ' -k: install new (K)ernel\n' >&2
501
    printf -- ' -m: install Open vSwitch kernel (M)odule from source dir\n' >&2
502
    printf -- ' -n: install mini(N)et dependencies + core files\n' >&2
503
    printf -- ' -r: remove existing Open vSwitch packages\n' >&2
504
    printf -- ' -t: install o(T)her stuff\n' >&2
505
    printf -- ' -v: install open (V)switch\n' >&2
506
    printf -- ' -w: install OpenFlow (w)ireshark dissector\n' >&2
507
    printf -- ' -x: install NO(X) OpenFlow controller\n' >&2
508
    printf -- ' -y: install (A)ll packages\n' >&2    
509
    
510
    exit 2
511
}
512

    
513
if [ $# -eq 0 ]
514
then
515
    all
516
else
517
    while getopts 'abcdfhkmnrtvwx' OPTION
518
    do
519
      case $OPTION in
520
      a)    all;;
521
      b)    cbench;;
522
      c)    kernel_clean;;
523
      d)    vm_clean;;
524
      f)    of;;
525
      h)    usage;;
526
      k)    kernel;;
527
      m)    modprobe;;
528
      n)    mn_deps;;
529
      r)    remove_ovs;;
530
      t)    other;;
531
      v)    ovs;;
532
      w)    wireshark;;
533
      x)    nox;;
534
      ?)    usage;;
535
      esac
536
    done
537
    shift $(($OPTIND - 1))
538
fi