Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ b80f4aeb

History | View | Annotate | Download (12.9 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

    
21
test -e /etc/debian_version && DIST="Debian"
22
grep Ubuntu /etc/lsb-release &> /dev/null && DIST="Ubuntu"
23
if [ "$DIST" = "Ubuntu" ] || [ "$DIST" = "Debian" ]; then
24
    sudo apt-get install -y lsb-release
25
fi
26
if which lsb_release &> /dev/null; then
27
    DIST=`lsb_release -is`
28
    RELEASE=`lsb_release -rs`
29
    CODENAME=`lsb_release -cs`
30
fi
31
echo "Detected Linux distribution: $DIST $RELEASE $CODENAME"
32

    
33
# Kernel params
34

    
35
if [ "$DIST" = "Debian" ]; then
36
    KERNEL_NAME=2.6.33.1-mininet
37
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
38
    KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
39
elif [ "$DIST" = "Ubuntu" ]; then
40
    if [ "$RELEASE" = "10.04" ]; then
41
        KERNEL_NAME='3.0.0-15-generic'
42
    else
43
        KERNEL_NAME=`uname -r`
44
    fi
45
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}
46
else
47
    echo "Install.sh currently only supports Ubuntu and Debian."
48
    exit 1
49
fi
50

    
51
# Kernel Deb pkg to be removed:
52
KERNEL_IMAGE_OLD=linux-image-2.6.26-2-686
53

    
54
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
55

    
56
OVS_RELEASE=v1.2.2
57
OVS_SRC=~/openvswitch
58
OVS_BUILD=$OVS_SRC/build-$KERNEL_NAME
59
OVS_KMODS=($OVS_BUILD/datapath/linux/{openvswitch_mod.ko,brcompat_mod.ko})
60

    
61
function kernel {
62
    echo "Install Mininet-compatible kernel if necessary"
63
    sudo apt-get update
64
    if [ "$DIST" = "Debian" ]; then
65
        # The easy approach: download pre-built linux-image and linux-headers packages:
66
        wget -c $KERNEL_LOC/$KERNEL_HEADERS
67
        wget -c $KERNEL_LOC/$KERNEL_IMAGE
68

    
69
        # Install custom linux headers and image:
70
        sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS
71

    
72
        # The next two steps are to work around a bug in newer versions of
73
        # kernel-package, which fails to add initrd images with the latest kernels.
74
        # See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525032
75
        # Generate initrd image if the .deb didn't install it:
76
        if ! test -e /boot/initrd.img-${KERNEL_NAME}; then
77
            sudo update-initramfs -c -k ${KERNEL_NAME}
78
        fi
79
        
80
        # Ensure /boot/grub/menu.lst boots with initrd image:
81
        sudo update-grub
82

    
83
        # The default should be the new kernel. Otherwise, you may need to modify 
84
        # /boot/grub/menu.lst to set the default to the entry corresponding to the
85
        # kernel you just installed.
86
    fi
87
    if [ "$DIST" = "Ubuntu" ] &&  [ "$RELEASE" = "10.04" ]; then
88
        sudo apt-get -y install linux-image-$KERNEL_NAME
89
    fi
90
}
91

    
92
function kernel_clean {
93
    echo "Cleaning kernel..."
94

    
95
    # To save disk space, remove previous kernel
96
    sudo apt-get -y remove $KERNEL_IMAGE_OLD
97

    
98
    # Also remove downloaded packages:
99
    rm -f ~/linux-headers-* ~/linux-image-*
100
}
101

    
102
# Install Mininet deps
103
function mn_deps {
104
    echo "Installing Mininet dependencies"
105
    sudo aptitude install -y gcc make screen psmisc xterm ssh iperf iproute \
106
        python-setuptools python-networkx
107

    
108
    if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" = "10.04" ]; then
109
        echo "Upgrading networkx to avoid deprecation warning"
110
        sudo easy_install --upgrade networkx
111
    fi
112

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

    
117
    # Load new sysctl settings:
118
    sudo sysctl -p
119
    
120
    echo "Installing Mininet core"
121
    pushd ~/mininet
122
    sudo make install
123
    popd
124
}
125

    
126
# The following will cause a full OF install, covering:
127
# -user switch
128
# -dissector
129
# The instructions below are an abbreviated version from
130
# http://www.openflowswitch.org/wk/index.php/Debian_Install
131
# ... modified to use Debian Lenny rather than unstable.
132
function of {
133
    echo "Installing OpenFlow and its tools..."
134

    
135
    cd ~/
136
    sudo apt-get install -y git-core automake m4 pkg-config libtool \
137
		make libc6-dev autoconf autotools-dev gcc
138
    git clone git://openflowswitch.org/openflow.git
139
    cd ~/openflow
140

    
141
    # Patch controller to handle more than 16 switches
142
    patch -p1 < ~/mininet/util/openflow-patches/controller.patch
143

    
144
    # Resume the install:
145
    ./boot.sh
146
    ./configure
147
    make
148
    sudo make install
149

    
150
    # Install dissector:
151
    sudo apt-get install -y wireshark libgtk2.0-dev
152
    cd ~/openflow/utilities/wireshark_dissectors/openflow
153
    make
154
    sudo make install
155

    
156
    # The OpenFlow wireshark plugin does not install to the correct dir.
157
    # The correct way would be to fix the install script.
158
    # For now, just copy it to the global WS plugin dir.
159
    # Tested on Ubuntu 11.04.
160
    if [ -e /var/packet-openflow.so ]; then
161
        cp /var/packet-openflow.so /usr/lib/wireshark/libwireshark0/plugins
162
    fi
163

    
164
    # Copy coloring rules: OF is white-on-blue:
165
    mkdir -p ~/.wireshark
166
    cp ~/mininet/util/colorfilters ~/.wireshark
167

    
168
    # Remove avahi-daemon, which may cause unwanted discovery packets to be 
169
    # sent during tests, near link status changes:
170
    sudo apt-get remove -y 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
}
180

    
181
# Install Open vSwitch
182
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
183
function ovs {
184
    echo "Installing Open vSwitch..."
185

    
186
    if [ "$DIST" = "Debian" ] && [ "$CODENAME" == "lenny" ]; then
187
        sudo aptitude -y install pkg-config gcc make git-core python-dev libssl-dev
188
        # Install Autoconf 2.63+ backport from Debian Backports repo:
189
        # Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
190
        sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
191
        sudo apt-get update
192
        sudo apt-get -y --force-yes install debian-backports-keyring
193
        sudo apt-get -y --force-yes -t lenny-backports install autoconf
194
    fi
195

    
196
    if [ "$DIST" = "Ubuntu" ]; then
197
        sudo apt-get -y install $KERNEL_HEADERS
198
    fi
199

    
200
    # Install OVS from release
201
    cd ~/
202
    git clone git://openvswitch.org/openvswitch
203
    cd $OVS_SRC
204
    git checkout $OVS_RELEASE
205
    ./boot.sh
206
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
207
    if [ ! -e $BUILDDIR ]; then
208
        echo "Creating build sdirectory $BUILDDIR"
209
        sudo mkdir -p $BUILDDIR
210
    fi
211
	opts="--with-linux=$BUILDDIR"
212
	mkdir -p $OVS_BUILD
213
	cd $OVS_BUILD
214
    ../configure $opts
215
    make
216
    sudo make install
217
	# openflowd is deprecated, but for now copy it in
218
	sudo cp tests/test-openflowd /usr/local/bin/ovs-openflowd
219
}
220

    
221
# Install NOX with tutorial files
222
function nox {
223
    echo "Installing NOX w/tutorial files..."
224

    
225
    # Install NOX deps:
226
    sudo apt-get -y install autoconf automake g++ libtool python python-twisted \
227
		swig libssl-dev make
228
    if [ "$DIST" = "Debian" ]; then
229
        sudo apt-get -y install libboost1.35-dev
230
    elif [ "$DIST" = "Ubuntu" ]; then
231
        sudo apt-get -y install python-dev libboost-dev 
232
        sudo apt-get -y install libboost-filesystem-dev
233
        sudo apt-get -y install libboost-test-dev
234
    fi
235
    # Install NOX optional deps:
236
    sudo apt-get install -y libsqlite3-dev python-simplejson
237

    
238
    # Fetch NOX destiny
239
    cd ~/
240
    git clone git://noxrepo.org/nox noxcore
241
    cd noxcore
242
    git checkout -b destiny remotes/origin/destiny
243

    
244
    # Apply patches
245
    git checkout -b tutorial-destiny
246
    git am ~/mininet/util/nox-patches/*.patch
247

    
248
    # Build
249
    ./boot.sh
250
    mkdir build
251
    cd build
252
    ../configure
253
    make -j3
254
    #make check
255

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

    
259
    # To verify this install:
260
    #cd ~/noxcore/build/src
261
    #./nox_core -v -i ptcp:
262
}
263

    
264
# Install OFtest
265
function oftest {
266
    echo "Installing oftest..."
267

    
268
    # Install deps:
269
    sudo apt-get install -y tcpdump python-scapy
270

    
271
    # Install oftest:
272
    cd ~/
273
    git clone git://openflow.org/oftest
274
    cd oftest
275
    cd tools/munger
276
    sudo make install
277
}
278

    
279
# Install cbench
280
function cbench {
281
    echo "Installing cbench..."
282
    
283
    sudo apt-get install -y libsnmp-dev libpcap-dev
284
    cd ~/
285
    git clone git://openflow.org/oflops.git
286
    cd oflops
287
    sh boot.sh || true # possible error in autoreconf, so run twice
288
    sh boot.sh
289
    ./configure --with-openflow-src-dir=$HOME/openflow
290
    make
291
    sudo make install || true # make install fails; force past this
292
}
293

    
294
function other {
295
    echo "Doing other setup tasks..."
296

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

    
300
    # Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
301
    # a graphical git history viewer.
302
    sudo apt-get install -y tcpdump tshark gitk
303

    
304
    # Install common text editors
305
    sudo apt-get install -y vim nano emacs
306

    
307
    # Install NTP
308
    sudo apt-get install -y ntp
309

    
310
    # Set git to colorize everything.
311
    git config --global color.diff auto
312
    git config --global color.status auto
313
    git config --global color.branch auto
314

    
315
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
316
    if [ "$DIST" = "Debian" ]; then
317
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
318
    fi
319

    
320
    # Clean unneeded debs:
321
    rm -f ~/linux-headers-* ~/linux-image-*
322
}
323

    
324
# Script to copy built OVS kernel module to where modprobe will
325
# find them automatically.  Removes the need to keep an environment variable
326
# for insmod usage, and works nicely with multiple kernel versions.
327
#
328
# The downside is that after each recompilation of OVS you'll need to
329
# re-run this script.  If you're using only one kernel version, then it may be
330
# a good idea to use a symbolic link in place of the copy below.
331
function modprobe {
332
    echo "Setting up modprobe for OVS kmod..."
333

    
334
    sudo cp $OVS_KMODS $DRIVERS_DIR
335
    sudo depmod -a ${KERNEL_NAME}
336
}
337

    
338
function all {
339
    echo "Running all commands..."
340
    kernel
341
    mn_deps
342
    of
343
    ovs
344
    modprobe
345
    nox
346
    oftest
347
    cbench
348
    other
349
    echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
350
    echo "Enjoy Mininet!"
351
}
352

    
353
# Restore disk space and remove sensitive files before shipping a VM.
354
function vm_clean {
355
    echo "Cleaning VM..."
356
    sudo apt-get clean
357
    sudo rm -rf /tmp/*
358
    sudo rm -rf openvswitch*.tar.gz
359

    
360
    # Remove sensistive files
361
    history -c  # note this won't work if you have multiple bash sessions
362
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
363
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
364
    sudo rm -f ~/.ssh/authorized_keys*
365

    
366
    # Remove Mininet files
367
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
368
    #sudo rm -f /usr/bin/mnexec
369

    
370
    # Clear optional dev script for SSH keychain load on boot
371
    rm -f ~/.bash_profile
372

    
373
    # Clear git changes
374
    git config --global user.name "None"
375
    git config --global user.email "None"
376

    
377
    # Remove mininet install script
378
    rm -f install-mininet.sh
379
}
380

    
381
function usage {
382
    printf 'Usage: %s [-acdfhkmntvxy]\n\n' $(basename $0) >&2
383
    
384
    printf 'This install script attempts to install useful packages\n' >&2
385
    printf 'for Mininet. It should (hopefully) work on Ubuntu 10.04, 11.10\n' >&2
386
    printf 'and Debian 5.0 (Lenny). If you run into trouble, try\n' >&2
387
    printf 'installing one thing at a time, and looking at the \n' >&2
388
    printf 'specific installation function in this script.\n\n' >&2
389

    
390
    printf 'options:\n' >&2
391
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
392
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
393
    printf -- ' -c: (C)lean up after kernel install\n' >&2
394
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2    
395
    printf -- ' -f: install open(F)low\n' >&2
396
    printf -- ' -h: print this (H)elp message\n' >&2
397
    printf -- ' -k: install new (K)ernel\n' >&2
398
    printf -- ' -m: install Open vSwitch kernel (M)odule\n' >&2
399
    printf -- ' -n: install mini(N)et dependencies + core files\n' >&2
400
    printf -- ' -t: install o(T)her stuff\n' >&2
401
    printf -- ' -v: install open (V)switch\n' >&2
402
    printf -- ' -x: install NO(X) OpenFlow controller\n' >&2
403
    printf -- ' -y: install (A)ll packages\n' >&2    
404
    
405
    exit 2
406
}
407

    
408
if [ $# -eq 0 ]
409
then
410
    all
411
else
412
    while getopts 'abcdfhkmntvx' OPTION
413
    do
414
      case $OPTION in
415
      a)    all;;
416
      b)    cbench;;
417
      c)    kernel_clean;;
418
      d)    vm_clean;;
419
      f)    of;;
420
      h)    usage;;
421
      k)    kernel;;
422
      m)    modprobe;;
423
      n)    mn_deps;;
424
      t)    other;;
425
      v)    ovs;;
426
      x)    nox;;
427
      ?)    usage;;
428
      esac
429
    done
430
    shift $(($OPTIND - 1))
431
fi