Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 26c61734

History | View | Annotate | Download (15.4 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
# -dissector
149
# The instructions below are an abbreviated version from
150
# http://www.openflowswitch.org/wk/index.php/Debian_Install
151
# ... modified to use Debian Lenny rather than unstable.
152
function of {
153
    echo "Installing OpenFlow and OpenFlow WireShark dissector..."
154
    cd ~/
155
    $install git-core autoconf automake autotools-dev pkg-config \
156
		make gcc libtool libc6-dev 
157
    git clone git://openflowswitch.org/openflow.git
158
    cd ~/openflow
159

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

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

    
169
    # Install dissector:
170
    $install wireshark libgtk2.0-dev
171
    cd ~/openflow/utilities/wireshark_dissectors/openflow
172
    make
173
    sudo make install
174

    
175
    # The OpenFlow wireshark plugin does not install to the correct dir.
176
    # The correct way would be to fix the install script.
177
    # For now, just copy it to the global WS plugin dir.
178
    # Tested on Ubuntu 11.04.
179
    if [ -e /var/packet-openflow.so ]; then
180
        WS_DIR=`ls -d /usr/lib/wireshark/libwireshark* | head -1`
181
        sudo cp /var/packet-openflow.so $WS_DIR/plugins/
182
    fi
183

    
184
    # Copy coloring rules: OF is white-on-blue:
185
    mkdir -p ~/.wireshark
186
    cp ~/mininet/util/colorfilters ~/.wireshark
187

    
188
    # Remove avahi-daemon, which may cause unwanted discovery packets to be 
189
    # sent during tests, near link status changes:
190
    $remove avahi-daemon
191

    
192
    # Disable IPv6.  Add to /etc/modprobe.d/blacklist:
193
    if [ "$DIST" = "Ubuntu" ]; then
194
        BLACKLIST=/etc/modprobe.d/blacklist.conf
195
    else
196
        BLACKLIST=/etc/modprobe.d/blacklist
197
    fi
198
    sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
199
    cd ~
200
}
201

    
202
# Install Open vSwitch
203
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
204
function ovs {
205
    echo "Installing Open vSwitch..."
206

    
207
    # Required for module build/dkms install
208
    $install $KERNEL_HEADERS
209

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

    
238
    # Otherwise try distribution's OVS packages
239
    if [ "$DIST" = "Ubuntu" ] && [ `echo "$RELEASE >= 11.10" | bc` = 1 ]; then
240
	if $install openvswitch-switch openvswitch-controller; then
241
            return
242
        fi
243
    fi
244

    
245
    $install pkg-config gcc make python-dev libssl-dev libtool
246

    
247
    if [ "$DIST" = "Debian" ]; then
248
        if [ "$CODENAME" = "lenny" ]; then
249
            $install git-core
250
            # Install Autoconf 2.63+ backport from Debian Backports repo:
251
            # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
252
            sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
253
            sudo apt-get update
254
            sudo apt-get -y --force-yes install debian-backports-keyring
255
            sudo apt-get -y --force-yes -t lenny-backports install autoconf
256
        fi
257
    else
258
        $install git
259
    fi    
260

    
261
    # Install OVS from release
262
    cd ~/
263
    git clone git://openvswitch.org/openvswitch $OVS_SRC
264
    cd $OVS_SRC
265
    git checkout $OVS_TAG
266
    ./boot.sh
267
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
268
    if [ ! -e $BUILDDIR ]; then
269
        echo "Creating build sdirectory $BUILDDIR"
270
        sudo mkdir -p $BUILDDIR
271
    fi
272
    opts="--with-linux=$BUILDDIR"
273
    mkdir -p $OVS_BUILD
274
    cd $OVS_BUILD
275
    ../configure $opts
276
    make
277
    sudo make install
278

    
279
    modprobe
280
}
281

    
282
function remove_ovs {
283
    pkgs=`dpkg --get-selections | grep openvswitch | awk '{ print $1;}'`
284
    echo "Removing existing Open vSwitch packages:"
285
    echo $pkgs
286
    if ! $remove $pkgs; then
287
        echo "Not all packages removed correctly"
288
    fi
289
    # For some reason this doesn't happen
290
    if scripts=`ls /etc/init.d/*openvswitch* 2>/dev/null`; then
291
        echo $scripts
292
        for s in $scripts; do
293
            s=$(basename $s)
294
            echo SCRIPT $s
295
            sudo service $s stop
296
            sudo rm -f /etc/init.d/$s
297
            sudo update-rc.d -f $s remove
298
        done
299
    fi
300
    echo "Done removing OVS"
301
}
302

    
303
# Install NOX with tutorial files
304
function nox {
305
    echo "Installing NOX w/tutorial files..."
306

    
307
    # Install NOX deps:
308
    $install autoconf automake g++ libtool python python-twisted \
309
		swig libssl-dev make
310
    if [ "$DIST" = "Debian" ]; then
311
        $install libboost1.35-dev
312
    elif [ "$DIST" = "Ubuntu" ]; then
313
        $install python-dev libboost-dev 
314
        $install libboost-filesystem-dev
315
        $install libboost-test-dev
316
    fi
317
    # Install NOX optional deps:
318
    $install libsqlite3-dev python-simplejson
319

    
320
    # Fetch NOX destiny
321
    cd ~/
322
    git clone git://noxrepo.org/nox noxcore
323
    cd noxcore
324
    git checkout -b destiny remotes/origin/destiny
325

    
326
    # Apply patches
327
    git checkout -b tutorial-destiny
328
    git am ~/mininet/util/nox-patches/*.patch
329

    
330
    # Build
331
    ./boot.sh
332
    mkdir build
333
    cd build
334
    ../configure
335
    make -j3
336
    #make check
337

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

    
341
    # To verify this install:
342
    #cd ~/noxcore/build/src
343
    #./nox_core -v -i ptcp:
344
}
345

    
346
# Install OFtest
347
function oftest {
348
    echo "Installing oftest..."
349

    
350
    # Install deps:
351
    $install tcpdump python-scapy
352

    
353
    # Install oftest:
354
    cd ~/
355
    git clone git://openflow.org/oftest
356
    cd oftest
357
    cd tools/munger
358
    sudo make install
359
}
360

    
361
# Install cbench
362
function cbench {
363
    echo "Installing cbench..."
364
    
365
    $install libsnmp-dev libpcap-dev
366
    cd ~/
367
    git clone git://openflow.org/oflops.git
368
    cd oflops
369
    sh boot.sh || true # possible error in autoreconf, so run twice
370
    sh boot.sh
371
    ./configure --with-openflow-src-dir=$HOME/openflow
372
    make
373
    sudo make install || true # make install fails; force past this
374
}
375

    
376
function other {
377
    echo "Doing other setup tasks..."
378

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

    
382
    # Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
383
    # a graphical git history viewer.
384
    $install tcpdump tshark gitk
385

    
386
    # Install common text editors
387
    $install vim nano emacs
388

    
389
    # Install NTP
390
    $install ntp
391

    
392
    # Set git to colorize everything.
393
    git config --global color.diff auto
394
    git config --global color.status auto
395
    git config --global color.branch auto
396

    
397
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
398
    if [ "$DIST" = "Debian" ]; then
399
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
400
    fi
401

    
402
    # Clean unneeded debs:
403
    rm -f ~/linux-headers-* ~/linux-image-*
404
}
405

    
406
# Script to copy built OVS kernel module to where modprobe will
407
# find them automatically.  Removes the need to keep an environment variable
408
# for insmod usage, and works nicely with multiple kernel versions.
409
#
410
# The downside is that after each recompilation of OVS you'll need to
411
# re-run this script.  If you're using only one kernel version, then it may be
412
# a good idea to use a symbolic link in place of the copy below.
413
function modprobe {
414
    echo "Setting up modprobe for OVS kmod..."
415

    
416
    sudo cp $OVS_KMODS $DRIVERS_DIR
417
    sudo depmod -a ${KERNEL_NAME}
418
}
419

    
420
function all {
421
    echo "Running all commands..."
422
    kernel
423
    mn_deps
424
    of
425
    ovs
426
    nox
427
    oftest
428
    cbench
429
    other
430
    echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
431
    echo "Enjoy Mininet!"
432
}
433

    
434
# Restore disk space and remove sensitive files before shipping a VM.
435
function vm_clean {
436
    echo "Cleaning VM..."
437
    sudo apt-get clean
438
    sudo rm -rf /tmp/*
439
    sudo rm -rf openvswitch*.tar.gz
440

    
441
    # Remove sensistive files
442
    history -c  # note this won't work if you have multiple bash sessions
443
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
444
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
445
    sudo rm -f ~/.ssh/authorized_keys*
446

    
447
    # Remove Mininet files
448
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
449
    #sudo rm -f /usr/bin/mnexec
450

    
451
    # Clear optional dev script for SSH keychain load on boot
452
    rm -f ~/.bash_profile
453

    
454
    # Clear git changes
455
    git config --global user.name "None"
456
    git config --global user.email "None"
457

    
458
    # Remove mininet install script
459
    rm -f install-mininet.sh
460
}
461

    
462
function usage {
463
    printf 'Usage: %s [-acdfhkmntvxy]\n\n' $(basename $0) >&2
464
    
465
    printf 'This install script attempts to install useful packages\n' >&2
466
    printf 'for Mininet. It should (hopefully) work on Ubuntu 10.04, 11.10\n' >&2
467
    printf 'and Debian 5.0 (Lenny). If you run into trouble, try\n' >&2
468
    printf 'installing one thing at a time, and looking at the \n' >&2
469
    printf 'specific installation function in this script.\n\n' >&2
470

    
471
    printf 'options:\n' >&2
472
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
473
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
474
    printf -- ' -c: (C)lean up after kernel install\n' >&2
475
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2    
476
    printf -- ' -f: install open(F)low\n' >&2
477
    printf -- ' -h: print this (H)elp message\n' >&2
478
    printf -- ' -k: install new (K)ernel\n' >&2
479
    printf -- ' -m: install Open vSwitch kernel (M)odule from source dir\n' >&2
480
    printf -- ' -n: install mini(N)et dependencies + core files\n' >&2
481
    printf -- ' -r: remove existing Open vSwitch packages\n' >&2
482
    printf -- ' -t: install o(T)her stuff\n' >&2
483
    printf -- ' -v: install open (V)switch\n' >&2
484
    printf -- ' -x: install NO(X) OpenFlow controller\n' >&2
485
    printf -- ' -y: install (A)ll packages\n' >&2    
486
    
487
    exit 2
488
}
489

    
490
if [ $# -eq 0 ]
491
then
492
    all
493
else
494
    while getopts 'abcdfhkmnrtvx' OPTION
495
    do
496
      case $OPTION in
497
      a)    all;;
498
      b)    cbench;;
499
      c)    kernel_clean;;
500
      d)    vm_clean;;
501
      f)    of;;
502
      h)    usage;;
503
      k)    kernel;;
504
      m)    modprobe;;
505
      n)    mn_deps;;
506
      r)    remove_ovs;;
507
      t)    other;;
508
      v)    ovs;;
509
      x)    nox;;
510
      ?)    usage;;
511
      esac
512
    done
513
    shift $(($OPTIND - 1))
514
fi