Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 011b02f8

History | View | Annotate | Download (8.06 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_DIR=~/$OVS_RELEASE
28
OVS_KMOD=openvswitch_mod.ko
29

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
126
	#Install OVS from release
127
	cd ~/
128
	wget http://openvswitch.org/releases/${OVS_RELEASE}.tar.gz
129
	tar xzf ${OVS_RELEASE}.tar.gz
130
	cd $OVS_RELEASE
131

    
132
	./configure --with-l26=/lib/modules/${KERNEL_NAME}/build
133
	make
134
	sudo make install
135
}
136

    
137
# Install NOX with tutorial files
138
function nox {
139
	echo "Installing NOX w/tutorial files..."
140

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

    
144
	#Install NOX optional deps:
145
	sudo apt-get install -y libsqlite3-dev python-simplejson
146

    
147
	#Install NOX:
148
	cd ~/
149
	git clone git://openflowswitch.org/nox-tutorial noxcore
150
	cd noxcore
151

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

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

    
165
	# To verify this install:
166
	#cd ~/noxcore/build/src
167
    #./nox_core -v -i ptcp:
168
}
169

    
170
# Install OFtest
171
function oftest {
172
    echo "Installing oftest..."
173

    
174
    #Install deps:
175
    sudo apt-get install -y tcpdump python-scapy
176

    
177
    #Install oftest:
178
    cd ~/
179
    git clone git://openflow.org/oftest
180
    cd oftest
181
    cd tools/munger
182
    sudo make install
183
}
184

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

    
199
function other {
200
	echo "Doing other setup tasks..."
201

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

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

    
209
    #Install common text editors
210
    sudo apt-get install -y vim nano emacs
211

    
212
    #Install NTP
213
    sudo apt-get install -y ntp
214

    
215
	#Set git to colorize everything.
216
	git config --global color.diff auto
217
	git config --global color.status auto
218
	git config --global color.branch auto
219

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

    
223
    # Clean unneeded debs:
224
    rm -f ~/linux-headers-* ~/linux-image-*
225
}
226

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

    
237
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
238
	sudo depmod -a ${KERNEL_NAME}
239
}
240

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

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

    
263
	# Remove sensistive files
264
	history -c
265
	rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
266
	sudo rm ~/.ssh/authorized_keys2
267

    
268
	# Remove Mininet files
269
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
270
	#sudo rm -f /usr/bin/mnexec
271

    
272
	# Clear git changes
273
	git config --global user.name "None"
274
	git config --global user.email "None"
275

    
276
	#sudo rm -rf ~/mininet
277
}
278

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

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