Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 1e4f3375

History | View | Annotate | Download (8.91 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.stanford.edu/~brandonh
13

    
14
# Kernel params
15
# These kernels have been tried:
16
KERNEL_NAME=2.6.29.6-custom
17
#KERNEL_NAME=2.6.33-custom
18
#KERNEL_NAME=2.6.33.1-custom
19
#KERNEL_NAME=`uname -r`
20
KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
21
KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
22

    
23
# Kernel Deb pkg to be removed:
24
KERNEL_IMAGE_OLD=linux-image-2.6.26-2-686
25

    
26
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers
27

    
28
OVS_RELEASE=openvswitch-0.99.2
29
#OVS_RELEASE=openvswitch
30
OVS_DIR=~/$OVS_RELEASE
31
OVS_KMOD=openvswitch_mod.ko
32
OF_DIR=~/openflow
33
OF_KMOD=ofdatapath.ko
34

    
35
function kernel {
36
	echo "Install new kernel..."
37
	sudo apt-get update
38

    
39
	# The easy approach: download pre-built linux-image and linux-headers packages:
40
	wget $KERNEL_LOC/$KERNEL_HEADERS
41
	wget $KERNEL_LOC/$KERNEL_IMAGE
42

    
43
	#Install custom linux headers and image:
44
	sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS
45

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

    
57
	# 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.
58
}
59

    
60
function kernel_clean {
61
	echo "Cleaning kernel..."
62

    
63
	# To save disk space, remove previous kernel
64
	sudo apt-get -y remove $KERNEL_IMAGE_OLD
65

    
66
	#Also remove downloaded packages:
67
	rm -f ~/linux-headers-* ~/linux-image-*
68
}
69

    
70
# Install Mininet deps
71
function mn_deps {
72
	#Install dependencies:
73
	sudo apt-get install -y screen psmisc xterm ssh iperf iproute python-setuptools
74

    
75
	#Add sysctl parameters as noted in the INSTALL file to increase kernel limits to support larger setups:
76
	sudo su -c "cat /home/mininet/mininet/util/sysctl_addon >> /etc/sysctl.conf"
77

    
78
	#Load new sysctl settings:
79
	sudo sysctl -p
80
}
81

    
82
# The following will cause a full OF install, covering:
83
# -user switch
84
# -kernel switch
85
# -dissector
86
# The instructions below are an abbreviated version from
87
# http://www.openflowswitch.org/wk/index.php/Debian_Install
88
# ... modified to use Debian Lenny rather than unstable.
89
function of {
90
	echo "Installing OpenFlow and its tools..."
91

    
92
	cd ~/
93
	sudo apt-get install -y git-core automake m4 pkg-config libtool make libc6-dev autoconf autotools-dev gcc
94
	git clone git://openflowswitch.org/openflow.git
95
	cd ~/openflow
96
	git fetch
97

    
98
	# Get debianfix branch, which doesn't break on test deps install
99
	# This is an optional step.
100
	git checkout -b debianfix origin/debianfix
101
	sudo regress/scripts/install_deps.pl
102

    
103
	# Resume the install:
104
	git checkout -b release/0.8.9 origin/release/0.8.9
105
	./boot.sh
106
	./configure --with-l26=/lib/modules/${KERNEL_NAME}
107
	make
108
	sudo make install
109

    
110
	# Install dissector:
111
	sudo apt-get install -y wireshark libgtk2.0-dev
112
	cd ~/openflow/utilities/wireshark_dissectors/openflow
113
	make
114
	sudo make install
115

    
116
	# Copy coloring rules: OF is white-on-blue:
117
	mkdir -p ~/.wireshark
118
	cp ~/mininet/util/colorfilters ~/.wireshark
119

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

    
123
	# Disable IPv6.  Add to /etc/modprobe.d/blacklist.conf:
124
	sudo sh -c "echo -e 'blacklist net-pf-10\nblacklist ipv6' >> /etc/modprobe.d/blacklist.conf"
125
}
126

    
127
# Install OpenVSwitch
128
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
129
function ovs {
130
	echo "Installing OpenVSwitch..."
131

    
132
	#Install Autoconf 2.63+ backport from Debian Backports repo:
133
	#Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
134
	sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
135
	sudo apt-get update
136
	sudo apt-get -y --force-yes install debian-backports-keyring
137
	sudo apt-get -y --force-yes -t lenny-backports install autoconf
138

    
139
	#Install OVS from git
140
	#git clone git://openvswitch.org/openvswitch
141
	#cd openvswitch
142
	#./boot.sh
143

    
144
	#Install OVS from release
145
	cd ~/
146
	wget http://openvswitch.org/releases/${OVS_RELEASE}.tar.gz
147
	tar xzf ${OVS_RELEASE}.tar.gz
148
	cd $OVS_RELEASE
149

    
150
	./configure --with-l26=/lib/modules/${KERNEL_NAME}/build
151
	make
152
	sudo make install
153
}
154

    
155
# Install NOX
156
function nox {
157
	echo "Install NOX..."
158

    
159
	#Install NOX deps:
160
	sudo apt-get -y install autoconf automake g++ libtool python python-twisted swig libboost1.35-dev libxerces-c2-dev libssl-dev make
161

    
162
	#Install NOX optional deps:
163
	sudo apt-get install -y libsqlite3-dev python-simplejson
164

    
165
	#Install NOX:
166
	cd ~/
167
	git clone git://noxrepo.org/noxcore
168
	cd noxcore
169

    
170
	# With later autoconf versions this doesn't quite work:
171
	./boot.sh || true
172
	# So use this instead:
173
	autoreconf --install --force
174
	mkdir build
175
	cd build
176
	../configure --with-python=yes
177
	make
178
	#make check
179

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

    
183
	# To verify this install:
184
	#cd ~/noxcore/build/src
185
    #./nox_core -v -i ptcp:
186
}
187

    
188
function other {
189
	echo "Doing other setup tasks..."
190

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

    
194
	#Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
195
	#a graphical git history viewer.
196
	sudo apt-get install -y tcpdump tshark gitk
197

    
198
	#Set git to colorize everything.
199
	git config --global color.diff auto
200
	git config --global color.status auto
201
	git config --global color.branch auto
202

    
203
	#Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
204
	sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
205
}
206

    
207
# The OpenFlow ref kmod is broken with 2.6.33 and CONFIG_NET_NS=y.  This is a
208
# reported bug: http://www.openflowswitch.org/bugs/openflow/ticket/82
209
function of_33 {
210
	echo "Installing OpenFlow..."
211
	cd ~/
212
	cd openflow
213
	git checkout -b fix-2.6.33 origin/devel-0.8.9/fix-2.6.33
214
	./boot.sh
215
	./configure --with-l26=/lib/modules/${KERNEL_NAME}
216
	make
217
	sudo make install
218
}
219

    
220
# OVS v0.99.2 does not build on 2.6.33, and the master branch of OVS includes
221
# patches for OF1.0 support.  It doesn't look like there's a supported branch
222
# for v0.99, so the script below applies a patch for this.
223
# Since the patch is in a makefile, we'll have to steal the makefile builder,
224
# boot.sh, from the OVS git repo.
225
function ovs_33 {
226
	echo "Installing OpenVSwitch..."
227
	cd ~/
228
	git clone git://openvswitch.org/openvswitch
229
	cp openvswitch/boot.sh $OVS_RELEASE
230
	rm -rf openvswitch
231
	cd ~/$OVS_RELEASE
232
	git apply ~/mininet/util/ovs-fix-2.6.33.patch
233
	./boot.sh
234
	./configure --with-l26=/lib/modules/${KERNEL_NAME}/build
235
	make
236
	sudo make install
237
}
238

    
239
function linux_33 {
240
    kernel
241
	of_33
242
	ovs_33
243
	modprobe
244

    
245
	# Clean unneeded debs:
246
	rm -f ~/linux-headers-* ~/linux-image-*
247
}
248

    
249
# Script to copy built OVS and OF kernel modules to where modprobe will
250
# find them automatically.  Removes the need to keep an environment variable
251
# for each, and works nicely with multiple kernel versions.
252
#
253
# The downside is that after each recompilation of OVS or OF you'll need to
254
# re-run this script.  If you're using only one kernel version, then it may be
255
# a good idea to use a symbolic link in place of the copy below.
256
function modprobe {
257
	echo "Setting up modprobe for OVS kmod..."
258
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
259

    
260
	echo "Setting up modprobe for OF kmod..."
261
	sudo cp $OF_DIR/datapath/linux-2.6/$OF_KMOD $DRIVERS_DIR
262

    
263
	sudo depmod -a ${KERNEL_NAME}
264
}
265

    
266
function all {
267
	echo "Running all commands..."
268
	kernel
269
	mn_deps
270
	of
271
	ovs
272
	modprobe
273
	nox
274
	other
275
	echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
276
	echo "Enjoy Mininet!"
277
}
278

    
279
# Restore disk space and remove sensitive files before shipping a VM.
280
function vm_clean {
281
	echo "Cleaning VM..."
282
	sudo apt-get clean
283
	sudo rm -rf /tmp/*
284
	sudo rm -rf openvswitch*.tar.gz
285

    
286
	# Remove sensistive files
287
	history -c
288
	rm ~/.ssh/id_rsa*
289
	sudo rm ~/.ssh/authorized_keys2
290

    
291
	# Remove Mininet files
292
	sudo rm -rf ~/mininet
293
	sudo rm /lib/modules/python2.5/site-packages/mininet*
294
	sudo rm /usr/bin/mnexec
295

    
296
	# Clear git changes
297
	git config --global user.name "None"
298
	git config --global user.email "None"
299

    
300
}
301

    
302
function usage {
303
    printf "Usage: %s: [-acdfhkmntvxy] args\n" $(basename $0) >&2
304
    exit 2
305
}
306

    
307
if [ $# -eq 0 ]
308
then
309
	all
310
else
311
	while getopts 'acdfhkmntvxy' OPTION
312
	do
313
	  case $OPTION in
314
	  a)    all;;
315
	  c)    kernel_clean;;
316
	  d)    vm_clean;;
317
	  f)    of;;
318
	  h)	usage;;
319
	  k)    kernel;;
320
	  m)    modprobe;;
321
	  n)    mn_deps;;
322
	  t)    other;;
323
	  v)    ovs;;
324
	  x)    nox;;
325
	  y)    linux_33;;
326
	  ?)    usage;;
327
	  esac
328
	done
329
	shift $(($OPTIND - 1))
330
fi