Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 0bfd19fe

History | View | Annotate | Download (11.4 KB)

1
#!/usr/bin/env bash
2
# Mininet install script for Debian
3
# Brandon Heller (brandonh@stanford.edu)
4

    
5
# Fail on error
6
set -e
7
 
8
# Fail on unset var usage
9
set -o nounset
10

    
11
# Location of CONFIG_NET_NS-enabled kernel(s)
12
KERNEL_LOC=http://www.openflow.org/downloads/mininet
13

    
14
test -e /etc/debian_version && DIST="Debian"
15
grep Ubuntu /etc/lsb-release &> /dev/null && DIST="Ubuntu"
16

    
17
# Kernel params
18

    
19
if [ "$DIST" = "Debian" ]; then
20
    KERNEL_NAME=2.6.33.1-mininet
21
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
22
    KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
23
elif [ "$DIST" = "Ubuntu" ]; then
24
    KERNEL_NAME=`uname -r`
25
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}
26
else
27
    echo "Install.sh currently only supports Ubuntu and Debian."
28
    exit 1
29
fi
30

    
31
echo "Detected Linux distribution: $DIST"
32

    
33
# Kernel Deb pkg to be removed:
34
KERNEL_IMAGE_OLD=linux-image-2.6.26-2-686
35

    
36
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
37

    
38
OVS_RELEASE=v1.1.1
39
OVS_DIR=~/openvswitch
40
OVS_KMOD=openvswitch_mod.ko
41

    
42
function kernel {
43
	echo "Install Mininet-compatible kernel"
44
	sudo apt-get update
45
    
46
    if [ "$DIST" = "Debian" ]; then
47
    
48
	# The easy approach: download pre-built linux-image and linux-headers packages:
49
	wget -c $KERNEL_LOC/$KERNEL_HEADERS
50
	wget -c $KERNEL_LOC/$KERNEL_IMAGE
51

    
52
	#Install custom linux headers and image:
53
	sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS
54

    
55
	# The next two steps are to work around a bug in newer versions of
56
	# kernel-package, which fails to add initrd images with the latest kernels.
57
	# See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525032
58
	# Generate initrd image if the .deb didn't install it:
59
	if ! test -e /boot/initrd.img-${KERNEL_NAME}; then
60
		sudo update-initramfs -c -k ${KERNEL_NAME}
61
	fi
62
	
63
	# Ensure /boot/grub/menu.lst boots with initrd image:
64
	sudo update-grub
65

    
66
	# The default should be the new kernel. Otherwise, you may need to modify /boot/grub/menu.lst to set the default to the entry corresponding to the kernel you just installed.
67
    fi
68

    
69
}
70

    
71
function kernel_clean {
72
	echo "Cleaning kernel..."
73

    
74
	# To save disk space, remove previous kernel
75
	sudo apt-get -y remove $KERNEL_IMAGE_OLD
76

    
77
	#Also remove downloaded packages:
78
	rm -f ~/linux-headers-* ~/linux-image-*
79
}
80

    
81
# Install Mininet deps
82
function mn_deps {
83
	echo "Installing Mininet dependencies"
84
	sudo aptitude install -y gcc make screen psmisc xterm ssh iperf iproute \
85
        python-setuptools python-networkx
86

    
87
    if [ "$DIST" = "Ubuntu" ] && [ "`lsb_release -sr`" = "10.04" ]; then
88
        echo "Upgrading networkx to avoid deprecation warning"
89
        sudo easy_install --upgrade networkx
90
    fi
91

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

    
95
	#Load new sysctl settings:
96
	sudo sysctl -p
97
    
98
    echo "Installing Mininet core"
99
    pushd ~/mininet
100
    sudo make install
101
    popd
102
}
103

    
104
# The following will cause a full OF install, covering:
105
# -user switch
106
# -dissector
107
# The instructions below are an abbreviated version from
108
# http://www.openflowswitch.org/wk/index.php/Debian_Install
109
# ... modified to use Debian Lenny rather than unstable.
110
function of {
111
	echo "Installing OpenFlow and its tools..."
112

    
113
	cd ~/
114
	sudo apt-get install -y git-core automake m4 pkg-config libtool make libc6-dev autoconf autotools-dev gcc
115
	git clone git://openflowswitch.org/openflow.git
116
	cd ~/openflow
117

    
118
    # Patch controller to handle more than 16 switches
119
    patch -p1 < ~/mininet/util/openflow-patches/controller.patch
120

    
121
	# Resume the install:
122
	./boot.sh
123
	./configure
124
	make
125
	sudo make install
126

    
127
	# Install dissector:
128
	sudo apt-get install -y wireshark libgtk2.0-dev
129
	cd ~/openflow/utilities/wireshark_dissectors/openflow
130
	make
131
	sudo make install
132

    
133
	# Copy coloring rules: OF is white-on-blue:
134
	mkdir -p ~/.wireshark
135
	cp ~/mininet/util/colorfilters ~/.wireshark
136

    
137
	# Remove avahi-daemon, which may cause unwanted discovery packets to be sent during tests, near link status changes:
138
	sudo apt-get remove -y avahi-daemon
139

    
140
	# Disable IPv6.  Add to /etc/modprobe.d/blacklist:
141
    if [ "$DIST" = "Ubuntu" ]; then
142
        BLACKLIST=/etc/modprobe.d/blacklist.conf
143
    else
144
        BLACKLIST=/etc/modprobe.d/blacklist
145
    fi
146
	sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
147
}
148

    
149
# Install OpenVSwitch
150
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
151
function ovs {
152
	echo "Installing OpenVSwitch..."
153

    
154
    if [ "$DIST" = "Debian" ]; then
155
        sudo aptitude -y install pkg-config gcc make git-core python-dev libssl-dev
156
        #Install Autoconf 2.63+ backport from Debian Backports repo:
157
        #Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
158
        sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
159
        sudo apt-get update
160
        sudo apt-get -y --force-yes install debian-backports-keyring
161
        sudo apt-get -y --force-yes -t lenny-backports install autoconf
162
    fi
163

    
164
    if [ "$DIST" = "Ubuntu" ]; then
165
        sudo apt-get -y install $KERNEL_HEADERS
166
    fi
167

    
168
	#Install OVS from release
169
	cd ~/
170
	git clone git://openvswitch.org/openvswitch
171
	cd $OVS_DIR
172
    git checkout $OVS_RELEASE
173
	./boot.sh
174
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
175
    if [ ! -e $BUILDDIR ]; then
176
        echo "Creating build sdirectory $BUILDDIR"
177
        sudo mkdir -p $BUILDDIR
178
    fi
179
    opts="--with-l26=$BUILDDIR"
180
	./configure $opts
181
	make
182
	sudo make install
183
}
184

    
185
# Install NOX with tutorial files
186
function nox {
187
	echo "Installing NOX w/tutorial files..."
188

    
189
	#Install NOX deps:
190
	sudo apt-get -y install autoconf automake g++ libtool python python-twisted swig  libxerces-c2-dev libssl-dev make
191
    if [ "$DIST" = "Debian" ]; then
192
        sudo apt-get -y install libboost1.35-dev
193
    elif [ "$DIST" = "Ubuntu" ]; then
194
        sudo apt-get -y install python-dev libboost-dev 
195
        sudo apt-get -y install libboost-filesystem-dev
196
        sudo apt-get -y install libboost-test-dev
197
    fi
198
	#Install NOX optional deps:
199
	sudo apt-get install -y libsqlite3-dev python-simplejson
200

    
201
	#Install NOX:
202
	cd ~/
203
	git clone git://openflowswitch.org/nox-tutorial noxcore
204
	cd noxcore
205

    
206
	# With later autoconf versions this doesn't quite work:
207
	./boot.sh --apps-core || true
208
    if [ "$DIST" = "Debian" ]; then
209
        # So use this instead:
210
        autoreconf --install --force
211
    fi
212
	mkdir build
213
	cd build
214
	../configure --with-python=yes
215
    make
216
	#make check
217

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

    
221
	# To verify this install:
222
	#cd ~/noxcore/build/src
223
    #./nox_core -v -i ptcp:
224
}
225

    
226
# Install OFtest
227
function oftest {
228
    echo "Installing oftest..."
229

    
230
    #Install deps:
231
    sudo apt-get install -y tcpdump python-scapy
232

    
233
    #Install oftest:
234
    cd ~/
235
    git clone git://openflow.org/oftest
236
    cd oftest
237
    cd tools/munger
238
    sudo make install
239
}
240

    
241
# Install cbench
242
function cbench {
243
    echo "Installing cbench..."
244
    
245
    sudo apt-get install -y libsnmp-dev libpcap-dev
246
    cd ~/
247
    git clone git://openflow.org/oflops.git
248
    cd oflops
249
    sh boot.sh || true # possible error in autoreconf, so run twice
250
    sh boot.sh
251
    ./configure --with-openflow-src-dir=$HOME/openflow
252
    make
253
    sudo make install || true # make install fails; force past this
254
}
255

    
256
function other {
257
	echo "Doing other setup tasks..."
258

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

    
262
	#Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
263
	#a graphical git history viewer.
264
	sudo apt-get install -y tcpdump tshark gitk
265

    
266
    #Install common text editors
267
    sudo apt-get install -y vim nano emacs
268

    
269
    #Install NTP
270
    sudo apt-get install -y ntp
271

    
272
	#Set git to colorize everything.
273
	git config --global color.diff auto
274
	git config --global color.status auto
275
	git config --global color.branch auto
276

    
277
	#Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
278
    if [ "$DIST" = "Debian" ]; then
279
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
280
    fi
281

    
282
    # Clean unneeded debs:
283
    rm -f ~/linux-headers-* ~/linux-image-*
284
}
285

    
286
# Script to copy built OVS kernel module to where modprobe will
287
# find them automatically.  Removes the need to keep an environment variable
288
# for insmod usage, and works nicely with multiple kernel versions.
289
#
290
# The downside is that after each recompilation of OVS you'll need to
291
# re-run this script.  If you're using only one kernel version, then it may be
292
# a good idea to use a symbolic link in place of the copy below.
293
function modprobe {
294
	echo "Setting up modprobe for OVS kmod..."
295

    
296
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
297
	sudo depmod -a ${KERNEL_NAME}
298
}
299

    
300
function all {
301
	echo "Running all commands..."
302
    if [ "$DIST" != "Ubuntu" ]; then
303
        # Ubuntu ships with Mininet-compatible kernel
304
        kernel
305
    fi
306
	mn_deps
307
	of
308
	ovs
309
    modprobe
310
	nox
311
	oftest
312
	cbench
313
	other
314
	echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
315
	echo "Enjoy Mininet!"
316
}
317

    
318
# Restore disk space and remove sensitive files before shipping a VM.
319
function vm_clean {
320
	echo "Cleaning VM..."
321
	sudo apt-get clean
322
	sudo rm -rf /tmp/*
323
	sudo rm -rf openvswitch*.tar.gz
324

    
325
	# Remove sensistive files
326
	history -c  # note this won't work if you have multiple bash sessions
327
	rm -f ~/.bash_history  # need to clear in memory and remove on disk
328
	rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
329
	sudo rm -f ~/.ssh/authorized_keys2
330

    
331
	# Remove Mininet files
332
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
333
	#sudo rm -f /usr/bin/mnexec
334

    
335
	# Clear optional dev script for SSH keychain load on boot
336
	rm -f ~/.bash_profile
337

    
338
	# Clear git changes
339
	git config --global user.name "None"
340
	git config --global user.email "None"
341

    
342
	# Remove mininet install script
343
	rm -f install-mininet.sh
344
}
345

    
346
function usage {
347
    printf 'Usage: %s [-acdfhkmntvxy]\n\n' $(basename $0) >&2
348
    
349
    printf 'This install script attempts to install useful packages\n' >&2
350
    printf 'for Mininet. It should (hopefully) work on Ubuntu 10.04 and\n' >&2
351
    printf 'Debian 5.0 (Lenny). If you run into trouble, try\n' >&2
352
    printf 'installing one thing at a time, and looking at the \n' >&2
353
    printf 'specific installation function in this script.\n\n' >&2
354
        
355
    printf 'options:\n' >&2
356
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
357
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
358
    printf -- ' -c: (C)lean up after kernel install\n' >&2
359
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2    
360
    printf -- ' -f: install open(F)low\n' >&2
361
    printf -- ' -h: print this (H)elp message\n' >&2
362
    printf -- ' -k: install new (K)ernel\n' >&2
363
    printf -- ' -m: install Open vSwitch kernel (M)odule\n' >&2
364
    printf -- ' -n: install mini(N)et dependencies + core files\n' >&2
365
    printf -- ' -t: install o(T)her stuff\n' >&2
366
    printf -- ' -v: install open (V)switch\n' >&2
367
    printf -- ' -x: install NO(X) OpenFlow controller\n' >&2
368
    printf -- ' -y: install (A)ll packages\n' >&2    
369
    
370
    exit 2
371
}
372

    
373
if [ $# -eq 0 ]
374
then
375
	all
376
else
377
	while getopts 'abcdfhkmntvx' OPTION
378
	do
379
	  case $OPTION in
380
	  a)    all;;
381
	  b)    cbench;;
382
	  c)    kernel_clean;;
383
	  d)    vm_clean;;
384
	  f)    of;;
385
	  h)	usage;;
386
	  k)    kernel;;
387
	  m)    modprobe;;
388
	  n)    mn_deps;;
389
	  t)    other;;
390
	  v)    ovs;;
391
	  x)    nox;;
392
	  ?)    usage;;
393
	  esac
394
	done
395
	shift $(($OPTIND - 1))
396
fi