Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ cc16d2ce

History | View | Annotate | Download (10.9 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
# These kernels have been tried:
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=openvswitch-1.0.1
39
OVS_RELEASE=openvswitch # release 1.0.1 doesn't work with veth pairs.
40
OVS_DIR=~/$OVS_RELEASE
41
OVS_KMOD=openvswitch_mod.ko
42

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

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

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

    
67
	# 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.
68
    fi
69

    
70
}
71

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

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

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

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

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

    
90
	#Load new sysctl settings:
91
	sudo sysctl -p
92
    
93
    echo "Installing Mininet core"
94
    pushd ~/mininet
95
    sudo make install
96
    popd
97
}
98

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

    
108
	cd ~/
109
	sudo apt-get install -y git-core automake m4 pkg-config libtool make libc6-dev autoconf autotools-dev gcc
110
	git clone git://openflowswitch.org/openflow.git
111
	cd ~/openflow
112

    
113
	# Resume the install:
114
	./boot.sh
115
	./configure
116
	make
117
	sudo make install
118

    
119
	# Install dissector:
120
	sudo apt-get install -y wireshark libgtk2.0-dev
121
	cd ~/openflow/utilities/wireshark_dissectors/openflow
122
	make
123
	sudo make install
124

    
125
	# Copy coloring rules: OF is white-on-blue:
126
	mkdir -p ~/.wireshark
127
	cp ~/mininet/util/colorfilters ~/.wireshark
128

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

    
132
	# Disable IPv6.  Add to /etc/modprobe.d/blacklist:
133
    if [ "$DIST" = "Ubuntu" ]; then
134
        BLACKLIST=/etc/modprobe.d/blacklist.conf
135
    else
136
        BLACKLIST=/etc/modprobe.d/blacklist
137
    fi
138
	sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
139
}
140

    
141
# Install OpenVSwitch
142
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
143
function ovs {
144
	echo "Installing OpenVSwitch..."
145

    
146
    if [ "$DIST" = "Debian" ]; then
147
        #Install Autoconf 2.63+ backport from Debian Backports repo:
148
        #Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
149
        sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
150
        sudo apt-get update
151
        sudo apt-get -y --force-yes install debian-backports-keyring
152
        sudo apt-get -y --force-yes -t lenny-backports install autoconf
153
    fi
154

    
155
    if [ "$DIST" = "Ubuntu" ]; then
156
        sudo apt-get -y install $KERNEL_HEADERS
157
    fi
158

    
159
	#Install OVS from release
160
	cd ~/
161
	#wget http://openvswitch.org/releases/${OVS_RELEASE}.tar.gz
162
	#tar xzf ${OVS_RELEASE}.tar.gz
163
	#cd $OVS_RELEASE
164
	git clone git://openvswitch.org/openvswitch
165
	cd $OVS_RELEASE
166
	./boot.sh
167
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
168
    mkdir -p $BUILDDIR
169
    opts="--with-l26=$BUILDDIR"
170
	./configure $opts
171
	make
172
	sudo make install
173
}
174

    
175
# Install NOX with tutorial files
176
function nox {
177
	echo "Installing NOX w/tutorial files..."
178

    
179
	#Install NOX deps:
180
	sudo apt-get -y install autoconf automake g++ libtool python python-twisted swig  libxerces-c2-dev libssl-dev make
181
    if [ "$DIST" = "Debian" ]; then
182
        sudo apt-get -y install libboost1.35-dev
183
    elif [ "$DIST" = "Ubuntu" ]; then
184
        sudo apt-get -y install python-dev libboost-dev 
185
        sudo apt-get -y install libboost-filesystem-dev
186
        sudo apt-get -y install libboost-test-dev
187
    fi
188
	#Install NOX optional deps:
189
	sudo apt-get install -y libsqlite3-dev python-simplejson
190

    
191
	#Install NOX:
192
	cd ~/
193
	git clone git://openflowswitch.org/nox-tutorial noxcore
194
	cd noxcore
195

    
196
	# With later autoconf versions this doesn't quite work:
197
	./boot.sh --apps-core || true
198
    if [ "$DIST" = "Debian" ]; then
199
        # So use this instead:
200
        autoreconf --install --force
201
    fi
202
	mkdir build
203
	cd build
204
	../configure --with-python=yes
205
    make
206
	#make check
207

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

    
211
	# To verify this install:
212
	#cd ~/noxcore/build/src
213
    #./nox_core -v -i ptcp:
214
}
215

    
216
# Install OFtest
217
function oftest {
218
    echo "Installing oftest..."
219

    
220
    #Install deps:
221
    sudo apt-get install -y tcpdump python-scapy
222

    
223
    #Install oftest:
224
    cd ~/
225
    git clone git://openflow.org/oftest
226
    cd oftest
227
    cd tools/munger
228
    sudo make install
229
}
230

    
231
# Install cbench
232
function cbench {
233
    echo "Installing cbench..."
234
    
235
    sudo apt-get install -y libsnmp-dev libpcap-dev
236
    cd ~/
237
    git clone git://www.openflow.org/oflops.git
238
    cd oflops
239
    sh boot.sh
240
    ./configure --with-openflow-src-dir=$HOME/openflow
241
    make
242
    sudo make install || true # make install fails; force past this
243
}
244

    
245
function other {
246
	echo "Doing other setup tasks..."
247

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

    
251
	#Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
252
	#a graphical git history viewer.
253
	sudo apt-get install -y tcpdump tshark gitk
254

    
255
    #Install common text editors
256
    sudo apt-get install -y vim nano emacs
257

    
258
    #Install NTP
259
    sudo apt-get install -y ntp
260

    
261
	#Set git to colorize everything.
262
	git config --global color.diff auto
263
	git config --global color.status auto
264
	git config --global color.branch auto
265

    
266
	#Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
267
    if [ "$DIST" = "Debian" ]; then
268
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
269
    fi
270

    
271
    # Clean unneeded debs:
272
    rm -f ~/linux-headers-* ~/linux-image-*
273
}
274

    
275
# Script to copy built OVS kernel module to where modprobe will
276
# find them automatically.  Removes the need to keep an environment variable
277
# for insmod usage, and works nicely with multiple kernel versions.
278
#
279
# The downside is that after each recompilation of OVS you'll need to
280
# re-run this script.  If you're using only one kernel version, then it may be
281
# a good idea to use a symbolic link in place of the copy below.
282
function modprobe {
283
	echo "Setting up modprobe for OVS kmod..."
284

    
285
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
286
	sudo depmod -a ${KERNEL_NAME}
287
}
288

    
289
function all {
290
	echo "Running all commands..."
291
    if [ "$DIST" != "Ubuntu" ]; then
292
        # Ubuntu ships with Mininet-compatible kernel
293
        kernel
294
    fi
295
	mn_deps
296
	of
297
	ovs
298
    modprobe
299
	nox
300
	oftest
301
	cbench
302
	other
303
	echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
304
	echo "Enjoy Mininet!"
305
}
306

    
307
# Restore disk space and remove sensitive files before shipping a VM.
308
function vm_clean {
309
	echo "Cleaning VM..."
310
	sudo apt-get clean
311
	sudo rm -rf /tmp/*
312
	sudo rm -rf openvswitch*.tar.gz
313

    
314
	# Remove sensistive files
315
	history -c  # note this won't work if you have multiple bash sessions
316
	rm -f ~/.bash_history  # need to clear in memory and remove on disk
317
	rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
318
	sudo rm -f ~/.ssh/authorized_keys2
319

    
320
	# Remove Mininet files
321
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
322
	#sudo rm -f /usr/bin/mnexec
323

    
324
	# Clear optional dev script for SSH keychain load on boot
325
	rm -f ~/.bash_profile
326

    
327
	# Clear git changes
328
	git config --global user.name "None"
329
	git config --global user.email "None"
330

    
331
	# Remove mininet install script
332
	rm -f install-mininet.sh
333
}
334

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

    
361
if [ $# -eq 0 ]
362
then
363
	all
364
else
365
	while getopts 'acdfhkmntvx' OPTION
366
	do
367
	  case $OPTION in
368
      a)    all;;
369
	  c)    kernel_clean;;
370
	  d)    vm_clean;;
371
	  f)    of;;
372
	  h)	usage;;
373
	  k)    kernel;;
374
	  m)    modprobe;;
375
	  n)    mn_deps;;
376
	  t)    other;;
377
	  v)    ovs;;
378
	  x)    nox;;
379
	  ?)    usage;;
380
	  esac
381
	done
382
	shift $(($OPTIND - 1))
383
fi