Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 8183cb62

History | View | Annotate | Download (15 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-2-686
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=-1
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
    $remove $KERNEL_IMAGE_OLD
115

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

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

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

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

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

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

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

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

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

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

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

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

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

    
199
# Install Open vSwitch
200
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
201
function ovs {
202
    echo "Installing Open vSwitch..."
203

    
204
    # First see if we have packages
205
    # XXX wget -c seems to fail from github/amazon s3
206
    if wget $OVS_PACKAGE_LOC/$OVS_PACKAGE_NAME; then
207
	# Install dkms dependencies
208
	$install patch dkms fakeroot
209
        tar xf $OVS_PACKAGE_NAME
210
        orig=`tar tf $OVS_PACKAGE_NAME`
211
        # Now install packages in reasonable dependency order
212
        order='common pki openvswitch-switch brcompat controller dkms'
213
        pkgs=""
214
        for p in $order; do
215
            pkg=`echo "$orig" | grep $p`
216
            pkgs="$pkgs $pkg"
217
        done
218
        echo PKGS $pkgs
219
        $pkginst $pkgs
220
        # Switch can run on its own, but 
221
        # Mininet should control the controller
222
        sudo service openvswitch-controller stop
223
        sudo update-rc.d openvswitch-controller disable
224
        echo "Done (hopefully) installing packages"
225
        return
226
    fi
227

    
228
    # Otherwise try distribution's OVS packages
229
    if [ "$DIST" = "Ubuntu" ] && [ `echo "$RELEASE >= 11.10" | bc` = 1 ]; then
230
	if $install openvswitch-switch openvswitch-controller; then
231
            return
232
        fi
233
    fi
234

    
235
    $install $KERNEL_HEADERS
236
    $install pkg-config gcc make python-dev libssl-dev libtool
237

    
238
    if [ "$DIST" = "Debian" ]; then
239
        if [ "$CODENAME" = "lenny" ]; then
240
            $install git-core
241
            # Install Autoconf 2.63+ backport from Debian Backports repo:
242
            # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
243
            sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
244
            sudo apt-get update
245
            sudo apt-get -y --force-yes install debian-backports-keyring
246
            sudo apt-get -y --force-yes -t lenny-backports install autoconf
247
        fi
248
    else
249
        $install git
250
    fi    
251

    
252
    # Install OVS from release
253
    cd ~/
254
    git clone git://openvswitch.org/openvswitch $OVS_SRC
255
    cd $OVS_SRC
256
    git checkout $OVS_TAG
257
    ./boot.sh
258
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
259
    if [ ! -e $BUILDDIR ]; then
260
        echo "Creating build sdirectory $BUILDDIR"
261
        sudo mkdir -p $BUILDDIR
262
    fi
263
    opts="--with-linux=$BUILDDIR"
264
    mkdir -p $OVS_BUILD
265
    cd $OVS_BUILD
266
    ../configure $opts
267
    make
268
    sudo make install
269
}
270

    
271
function remove_ovs {
272
    pkgs=`dpkg-query -l | grep openvswitch | awk '{ print $2;}'`
273
    echo "Removing existing Open vSwitch packages:"
274
    echo $pkgs
275
    if ! $remove $pkgs; then
276
        echo "Not all packages removed correctly"
277
    fi
278
    # For some reason this doesn't happen
279
    if scripts=`ls /etc/init.d/*openvswitch* 2>/dev/null`; then
280
        echo $scripts
281
        for s in $scripts; do
282
            s=$(basename $s)
283
            echo SCRIPT $s
284
            sudo service $s stop
285
            sudo rm -f /etc/init.d/$s
286
            sudo update-rc.d -f $s remove
287
        done
288
    fi
289
    echo "Done removing OVS"
290
}
291

    
292
# Install NOX with tutorial files
293
function nox {
294
    echo "Installing NOX w/tutorial files..."
295

    
296
    # Install NOX deps:
297
    $install autoconf automake g++ libtool python python-twisted \
298
		swig libssl-dev make
299
    if [ "$DIST" = "Debian" ]; then
300
        $install libboost1.35-dev
301
    elif [ "$DIST" = "Ubuntu" ]; then
302
        $install python-dev libboost-dev 
303
        $install libboost-filesystem-dev
304
        $install libboost-test-dev
305
    fi
306
    # Install NOX optional deps:
307
    $install libsqlite3-dev python-simplejson
308

    
309
    # Fetch NOX destiny
310
    cd ~/
311
    git clone git://noxrepo.org/nox noxcore
312
    cd noxcore
313
    git checkout -b destiny remotes/origin/destiny
314

    
315
    # Apply patches
316
    git checkout -b tutorial-destiny
317
    git am ~/mininet/util/nox-patches/*.patch
318

    
319
    # Build
320
    ./boot.sh
321
    mkdir build
322
    cd build
323
    ../configure
324
    make -j3
325
    #make check
326

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

    
330
    # To verify this install:
331
    #cd ~/noxcore/build/src
332
    #./nox_core -v -i ptcp:
333
}
334

    
335
# Install OFtest
336
function oftest {
337
    echo "Installing oftest..."
338

    
339
    # Install deps:
340
    $install tcpdump python-scapy
341

    
342
    # Install oftest:
343
    cd ~/
344
    git clone git://openflow.org/oftest
345
    cd oftest
346
    cd tools/munger
347
    sudo make install
348
}
349

    
350
# Install cbench
351
function cbench {
352
    echo "Installing cbench..."
353
    
354
    $install libsnmp-dev libpcap-dev
355
    cd ~/
356
    git clone git://openflow.org/oflops.git
357
    cd oflops
358
    sh boot.sh || true # possible error in autoreconf, so run twice
359
    sh boot.sh
360
    ./configure --with-openflow-src-dir=$HOME/openflow
361
    make
362
    sudo make install || true # make install fails; force past this
363
}
364

    
365
function other {
366
    echo "Doing other setup tasks..."
367

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

    
371
    # Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
372
    # a graphical git history viewer.
373
    $install tcpdump tshark gitk
374

    
375
    # Install common text editors
376
    $install vim nano emacs
377

    
378
    # Install NTP
379
    $install ntp
380

    
381
    # Set git to colorize everything.
382
    git config --global color.diff auto
383
    git config --global color.status auto
384
    git config --global color.branch auto
385

    
386
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
387
    if [ "$DIST" = "Debian" ]; then
388
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
389
    fi
390

    
391
    # Clean unneeded debs:
392
    rm -f ~/linux-headers-* ~/linux-image-*
393
}
394

    
395
# Script to copy built OVS kernel module to where modprobe will
396
# find them automatically.  Removes the need to keep an environment variable
397
# for insmod usage, and works nicely with multiple kernel versions.
398
#
399
# The downside is that after each recompilation of OVS you'll need to
400
# re-run this script.  If you're using only one kernel version, then it may be
401
# a good idea to use a symbolic link in place of the copy below.
402
function modprobe {
403
    echo "Setting up modprobe for OVS kmod..."
404

    
405
    sudo cp $OVS_KMODS $DRIVERS_DIR
406
    sudo depmod -a ${KERNEL_NAME}
407
}
408

    
409
function all {
410
    echo "Running all commands..."
411
    kernel
412
    mn_deps
413
    of
414
    ovs
415
    modprobe
416
    nox
417
    oftest
418
    cbench
419
    other
420
    echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
421
    echo "Enjoy Mininet!"
422
}
423

    
424
# Restore disk space and remove sensitive files before shipping a VM.
425
function vm_clean {
426
    echo "Cleaning VM..."
427
    sudo apt-get clean
428
    sudo rm -rf /tmp/*
429
    sudo rm -rf openvswitch*.tar.gz
430

    
431
    # Remove sensistive files
432
    history -c  # note this won't work if you have multiple bash sessions
433
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
434
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
435
    sudo rm -f ~/.ssh/authorized_keys*
436

    
437
    # Remove Mininet files
438
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
439
    #sudo rm -f /usr/bin/mnexec
440

    
441
    # Clear optional dev script for SSH keychain load on boot
442
    rm -f ~/.bash_profile
443

    
444
    # Clear git changes
445
    git config --global user.name "None"
446
    git config --global user.email "None"
447

    
448
    # Remove mininet install script
449
    rm -f install-mininet.sh
450
}
451

    
452
function usage {
453
    printf 'Usage: %s [-acdfhkmntvxy]\n\n' $(basename $0) >&2
454
    
455
    printf 'This install script attempts to install useful packages\n' >&2
456
    printf 'for Mininet. It should (hopefully) work on Ubuntu 10.04, 11.10\n' >&2
457
    printf 'and Debian 5.0 (Lenny). If you run into trouble, try\n' >&2
458
    printf 'installing one thing at a time, and looking at the \n' >&2
459
    printf 'specific installation function in this script.\n\n' >&2
460

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

    
480
if [ $# -eq 0 ]
481
then
482
    all
483
else
484
    while getopts 'abcdfhkmnrtvx' OPTION
485
    do
486
      case $OPTION in
487
      a)    all;;
488
      b)    cbench;;
489
      c)    kernel_clean;;
490
      d)    vm_clean;;
491
      f)    of;;
492
      h)    usage;;
493
      k)    kernel;;
494
      m)    modprobe;;
495
      n)    mn_deps;;
496
      r)    remove_ovs;;
497
      t)    other;;
498
      v)    ovs;;
499
      x)    nox;;
500
      ?)    usage;;
501
      esac
502
    done
503
    shift $(($OPTIND - 1))
504
fi