Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ e5b54a31

History | View | Annotate | Download (15.2 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
        sudo 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
	if [ -e /etc/init.d/openvswitch-controller ]; then
223
            if sudo service openvswitch-controller stop; then
224
                echo "Stopped running controller"
225
            fi
226
            sudo update-rc.d openvswitch-controller disable
227
        fi
228
        echo "Done (hopefully) installing packages"
229
        return
230
    fi
231

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

    
239
    $install $KERNEL_HEADERS
240
    $install pkg-config gcc make python-dev libssl-dev libtool
241

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

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

    
274
    modprobe
275
}
276

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

    
298
# Install NOX with tutorial files
299
function nox {
300
    echo "Installing NOX w/tutorial files..."
301

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

    
315
    # Fetch NOX destiny
316
    cd ~/
317
    git clone git://noxrepo.org/nox noxcore
318
    cd noxcore
319
    git checkout -b destiny remotes/origin/destiny
320

    
321
    # Apply patches
322
    git checkout -b tutorial-destiny
323
    git am ~/mininet/util/nox-patches/*.patch
324

    
325
    # Build
326
    ./boot.sh
327
    mkdir build
328
    cd build
329
    ../configure
330
    make -j3
331
    #make check
332

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

    
336
    # To verify this install:
337
    #cd ~/noxcore/build/src
338
    #./nox_core -v -i ptcp:
339
}
340

    
341
# Install OFtest
342
function oftest {
343
    echo "Installing oftest..."
344

    
345
    # Install deps:
346
    $install tcpdump python-scapy
347

    
348
    # Install oftest:
349
    cd ~/
350
    git clone git://openflow.org/oftest
351
    cd oftest
352
    cd tools/munger
353
    sudo make install
354
}
355

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

    
371
function other {
372
    echo "Doing other setup tasks..."
373

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

    
377
    # Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
378
    # a graphical git history viewer.
379
    $install tcpdump tshark gitk
380

    
381
    # Install common text editors
382
    $install vim nano emacs
383

    
384
    # Install NTP
385
    $install ntp
386

    
387
    # Set git to colorize everything.
388
    git config --global color.diff auto
389
    git config --global color.status auto
390
    git config --global color.branch auto
391

    
392
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
393
    if [ "$DIST" = "Debian" ]; then
394
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
395
    fi
396

    
397
    # Clean unneeded debs:
398
    rm -f ~/linux-headers-* ~/linux-image-*
399
}
400

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

    
411
    sudo cp $OVS_KMODS $DRIVERS_DIR
412
    sudo depmod -a ${KERNEL_NAME}
413
}
414

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

    
429
# Restore disk space and remove sensitive files before shipping a VM.
430
function vm_clean {
431
    echo "Cleaning VM..."
432
    sudo apt-get clean
433
    sudo rm -rf /tmp/*
434
    sudo rm -rf openvswitch*.tar.gz
435

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

    
442
    # Remove Mininet files
443
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
444
    #sudo rm -f /usr/bin/mnexec
445

    
446
    # Clear optional dev script for SSH keychain load on boot
447
    rm -f ~/.bash_profile
448

    
449
    # Clear git changes
450
    git config --global user.name "None"
451
    git config --global user.email "None"
452

    
453
    # Remove mininet install script
454
    rm -f install-mininet.sh
455
}
456

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

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

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