Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 71ba12c5

History | View | Annotate | Download (8.21 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.33.1-mininet
17
#KERNEL_NAME=`uname -r`
18
KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
19
KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
20

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

    
24
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers
25

    
26
#OVS_RELEASE=openvswitch-1.0.1
27
OVS_RELEASE=openvswitch # release 1.0.1 doesn't work with veth pairs.
28
OVS_DIR=~/$OVS_RELEASE
29
OVS_KMOD=openvswitch_mod.ko
30

    
31
function kernel {
32
	echo "Install new kernel..."
33
	sudo apt-get update
34

    
35
	# The easy approach: download pre-built linux-image and linux-headers packages:
36
	wget $KERNEL_LOC/$KERNEL_HEADERS
37
	wget $KERNEL_LOC/$KERNEL_IMAGE
38

    
39
	#Install custom linux headers and image:
40
	sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS
41

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

    
53
	# 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.
54
}
55

    
56
function kernel_clean {
57
	echo "Cleaning kernel..."
58

    
59
	# To save disk space, remove previous kernel
60
	sudo apt-get -y remove $KERNEL_IMAGE_OLD
61

    
62
	#Also remove downloaded packages:
63
	rm -f ~/linux-headers-* ~/linux-image-*
64
}
65

    
66
# Install Mininet deps
67
function mn_deps {
68
	#Install dependencies:
69
	sudo apt-get install -y screen psmisc xterm ssh iperf iproute python-setuptools
70

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

    
74
	#Load new sysctl settings:
75
	sudo sysctl -p
76
}
77

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

    
87
	cd ~/
88
	sudo apt-get install -y git-core automake m4 pkg-config libtool make libc6-dev autoconf autotools-dev gcc
89
	git clone git://openflowswitch.org/openflow.git
90
	cd ~/openflow
91

    
92
	# Resume the install:
93
	./boot.sh
94
	./configure
95
	make
96
	sudo make install
97

    
98
	# Install dissector:
99
	sudo apt-get install -y wireshark libgtk2.0-dev
100
	cd ~/openflow/utilities/wireshark_dissectors/openflow
101
	make
102
	sudo make install
103

    
104
	# Copy coloring rules: OF is white-on-blue:
105
	mkdir -p ~/.wireshark
106
	cp ~/mininet/util/colorfilters ~/.wireshark
107

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

    
111
	# Disable IPv6.  Add to /etc/modprobe.d/blacklist:
112
	sudo sh -c "echo -e 'blacklist net-pf-10\nblacklist ipv6' >> /etc/modprobe.d/blacklist"
113
}
114

    
115
# Install OpenVSwitch
116
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
117
function ovs {
118
	echo "Installing OpenVSwitch..."
119

    
120
	#Install Autoconf 2.63+ backport from Debian Backports repo:
121
	#Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
122
	sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
123
	sudo apt-get update
124
	sudo apt-get -y --force-yes install debian-backports-keyring
125
	sudo apt-get -y --force-yes -t lenny-backports install autoconf
126

    
127
	#Install OVS from release
128
	cd ~/
129
	#wget http://openvswitch.org/releases/${OVS_RELEASE}.tar.gz
130
	#tar xzf ${OVS_RELEASE}.tar.gz
131
	#cd $OVS_RELEASE
132
	git clone git://openvswitch.org/openvswitch
133
	cd $OVS_RELEASE
134
	./boot.sh
135
	./configure --with-l26=/lib/modules/${KERNEL_NAME}/build
136
	make
137
	sudo make install
138
}
139

    
140
# Install NOX with tutorial files
141
function nox {
142
	echo "Installing NOX w/tutorial files..."
143

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

    
147
	#Install NOX optional deps:
148
	sudo apt-get install -y libsqlite3-dev python-simplejson
149

    
150
	#Install NOX:
151
	cd ~/
152
	git clone git://openflowswitch.org/nox-tutorial noxcore
153
	cd noxcore
154

    
155
	# With later autoconf versions this doesn't quite work:
156
	./boot.sh --apps-core || true
157
	# So use this instead:
158
	autoreconf --install --force
159
	mkdir build
160
	cd build
161
	../configure --with-python=yes
162
	make
163
	#make check
164

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

    
168
	# To verify this install:
169
	#cd ~/noxcore/build/src
170
    #./nox_core -v -i ptcp:
171
}
172

    
173
# Install OFtest
174
function oftest {
175
    echo "Installing oftest..."
176

    
177
    #Install deps:
178
    sudo apt-get install -y tcpdump python-scapy
179

    
180
    #Install oftest:
181
    cd ~/
182
    git clone git://openflow.org/oftest
183
    cd oftest
184
    cd tools/munger
185
    sudo make install
186
}
187

    
188
# Install cbench
189
function cbench {
190
    echo "Installing cbench..."
191
    
192
    sudo apt-get install -y libsnmp-dev libpcap-dev
193
    cd ~/
194
    git clone git://www.openflow.org/oflops.git
195
    cd oflops
196
    sh boot.sh
197
    ./configure --with-openflow-src-dir=/home/mininet/openflow
198
    make
199
    sudo make install || true # make install fails; force past this
200
}
201

    
202
function other {
203
	echo "Doing other setup tasks..."
204

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

    
208
	#Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
209
	#a graphical git history viewer.
210
	sudo apt-get install -y tcpdump tshark gitk
211

    
212
    #Install common text editors
213
    sudo apt-get install -y vim nano emacs
214

    
215
    #Install NTP
216
    sudo apt-get install -y ntp
217

    
218
	#Set git to colorize everything.
219
	git config --global color.diff auto
220
	git config --global color.status auto
221
	git config --global color.branch auto
222

    
223
	#Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
224
	sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
225

    
226
    # Clean unneeded debs:
227
    rm -f ~/linux-headers-* ~/linux-image-*
228
}
229

    
230
# Script to copy built OVS kernel module to where modprobe will
231
# find them automatically.  Removes the need to keep an environment variable
232
# for insmod usage, and works nicely with multiple kernel versions.
233
#
234
# The downside is that after each recompilation of OVS you'll need to
235
# re-run this script.  If you're using only one kernel version, then it may be
236
# a good idea to use a symbolic link in place of the copy below.
237
function modprobe {
238
	echo "Setting up modprobe for OVS kmod..."
239

    
240
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
241
	sudo depmod -a ${KERNEL_NAME}
242
}
243

    
244
function all {
245
	echo "Running all commands..."
246
	kernel
247
	mn_deps
248
	of
249
	ovs
250
	modprobe
251
	nox
252
	oftest
253
	cbench
254
	other
255
	echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
256
	echo "Enjoy Mininet!"
257
}
258

    
259
# Restore disk space and remove sensitive files before shipping a VM.
260
function vm_clean {
261
	echo "Cleaning VM..."
262
	sudo apt-get clean
263
	sudo rm -rf /tmp/*
264
	sudo rm -rf openvswitch*.tar.gz
265

    
266
	# Remove sensistive files
267
	history -c
268
	rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
269
	sudo rm ~/.ssh/authorized_keys2
270

    
271
	# Remove Mininet files
272
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
273
	#sudo rm -f /usr/bin/mnexec
274

    
275
	# Clear git changes
276
	git config --global user.name "None"
277
	git config --global user.email "None"
278

    
279
	#sudo rm -rf ~/mininet
280
}
281

    
282
function usage {
283
    printf "Usage: %s: [-acdfhkmntvxy] args\n" $(basename $0) >&2
284
    exit 2
285
}
286

    
287
if [ $# -eq 0 ]
288
then
289
	all
290
else
291
	while getopts 'acdfhkmntvx' OPTION
292
	do
293
	  case $OPTION in
294
	  a)    all;;
295
	  c)    kernel_clean;;
296
	  d)    vm_clean;;
297
	  f)    of;;
298
	  h)	usage;;
299
	  k)    kernel;;
300
	  m)    modprobe;;
301
	  n)    mn_deps;;
302
	  t)    other;;
303
	  v)    ovs;;
304
	  x)    nox;;
305
	  ?)    usage;;
306
	  esac
307
	done
308
	shift $(($OPTIND - 1))
309
fi