Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ a0ca68b6

History | View | Annotate | Download (10.6 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
DIST=`lsb_release -is`
15

    
16
# Kernel params
17
# These kernels have been tried:
18
if [ "$DIST" = "Debian" ]; then
19
    KERNEL_NAME=2.6.33.1-mininet
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
elif [ "$DIST" = "Ubuntu" ]; then
23
    KERNEL_NAME=`uname -r`
24
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}
25
else
26
    echo "Install.sh currently only supports Ubuntu and Debian."
27
    exit 1
28
fi
29

    
30
# Kernel Deb pkg to be removed:
31
KERNEL_IMAGE_OLD=linux-image-2.6.26-2-686
32

    
33
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
34

    
35
#OVS_RELEASE=openvswitch-1.0.1
36
OVS_RELEASE=openvswitch # release 1.0.1 doesn't work with veth pairs.
37
OVS_DIR=~/$OVS_RELEASE
38
OVS_KMOD=openvswitch_mod.ko
39

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

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

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

    
64
	# 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.
65
    fi
66

    
67
}
68

    
69
function kernel_clean {
70
	echo "Cleaning kernel..."
71

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

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

    
79
# Install Mininet deps
80
function mn_deps {
81
	echo "Installing Mininet dependencies"
82
	sudo apt-get install -y screen psmisc xterm ssh iperf iproute python-setuptools
83

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

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

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

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

    
110
	# Resume the install:
111
	./boot.sh
112
	./configure
113
	make
114
	sudo make install
115

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

    
122
	# Copy coloring rules: OF is white-on-blue:
123
	mkdir -p ~/.wireshark
124
	cp ~/mininet/util/colorfilters ~/.wireshark
125

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

    
129
	# Disable IPv6.  Add to /etc/modprobe.d/blacklist:
130
	sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> /etc/modprobe.d/blacklist"
131
}
132

    
133
# Install OpenVSwitch
134
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
135
function ovs {
136
	echo "Installing OpenVSwitch..."
137

    
138
    if [ "$DIST" = "Debian" ]; then
139
        #Install Autoconf 2.63+ backport from Debian Backports repo:
140
        #Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
141
        sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
142
        sudo apt-get update
143
        sudo apt-get -y --force-yes install debian-backports-keyring
144
        sudo apt-get -y --force-yes -t lenny-backports install autoconf
145
    fi
146

    
147
    if [ "$DIST" == "Ubuntu" ]; then
148
        sudo apt-get -y install $KERNEL_HEADERS
149
    fi
150

    
151
	#Install OVS from release
152
	cd ~/
153
	#wget http://openvswitch.org/releases/${OVS_RELEASE}.tar.gz
154
	#tar xzf ${OVS_RELEASE}.tar.gz
155
	#cd $OVS_RELEASE
156
	git clone git://openvswitch.org/openvswitch
157
	cd $OVS_RELEASE
158
	./boot.sh
159
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
160
    mkdir -p $BUILDDIR
161
    opts="--with-l26=$BUILDDIR"
162
	./configure $opts
163
	make
164
	sudo make install
165
}
166

    
167
# Install NOX with tutorial files
168
function nox {
169
	echo "Installing NOX w/tutorial files..."
170

    
171
	#Install NOX deps:
172
	sudo apt-get -y install autoconf automake g++ libtool python python-twisted swig  libxerces-c2-dev libssl-dev make
173
    if [ "$DIST" == "Debian" ]; then
174
        sudo apt-get -y install libboost1.35-dev
175
    elif [ "$DIST" == "Ubuntu" ]; then
176
        sudo apt-get -y install python-dev libboost-dev 
177
        sudo apt-get -y install libboost-filesystem-dev
178
        sudo apt-get -y install libboost-test-dev
179
    fi
180
	#Install NOX optional deps:
181
	sudo apt-get install -y libsqlite3-dev python-simplejson
182

    
183
	#Install NOX:
184
	cd ~/
185
	git clone git://openflowswitch.org/nox-tutorial noxcore
186
	cd noxcore
187

    
188
	# With later autoconf versions this doesn't quite work:
189
	./boot.sh --apps-core || true
190
    if [ "$DIST" == "Debian" ]; then
191
        # So use this instead:
192
        autoreconf --install --force
193
    fi
194
	mkdir build
195
	cd build
196
	../configure --with-python=yes
197
    make
198
	#make check
199

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

    
203
	# To verify this install:
204
	#cd ~/noxcore/build/src
205
    #./nox_core -v -i ptcp:
206
}
207

    
208
# Install OFtest
209
function oftest {
210
    echo "Installing oftest..."
211

    
212
    #Install deps:
213
    sudo apt-get install -y tcpdump python-scapy
214

    
215
    #Install oftest:
216
    cd ~/
217
    git clone git://openflow.org/oftest
218
    cd oftest
219
    cd tools/munger
220
    sudo make install
221
}
222

    
223
# Install cbench
224
function cbench {
225
    echo "Installing cbench..."
226
    
227
    sudo apt-get install -y libsnmp-dev libpcap-dev
228
    cd ~/
229
    git clone git://www.openflow.org/oflops.git
230
    cd oflops
231
    sh boot.sh
232
    ./configure --with-openflow-src-dir=$HOME/openflow
233
    make
234
    sudo make install || true # make install fails; force past this
235
}
236

    
237
function other {
238
	echo "Doing other setup tasks..."
239

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

    
243
	#Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
244
	#a graphical git history viewer.
245
	sudo apt-get install -y tcpdump tshark gitk
246

    
247
    #Install common text editors
248
    sudo apt-get install -y vim nano emacs
249

    
250
    #Install NTP
251
    sudo apt-get install -y ntp
252

    
253
	#Set git to colorize everything.
254
	git config --global color.diff auto
255
	git config --global color.status auto
256
	git config --global color.branch auto
257

    
258
	#Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
259
    if [ "$DIST" = "Debian" ]; then
260
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
261
    fi
262

    
263
    # Clean unneeded debs:
264
    rm -f ~/linux-headers-* ~/linux-image-*
265
}
266

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

    
277
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
278
	sudo depmod -a ${KERNEL_NAME}
279
}
280

    
281
function all {
282
	echo "Running all commands..."
283
    if [ "$DIST" != "Ubuntu" ]; then
284
        # Ubuntu ships with Mininet-compatible kernel
285
        kernel
286
    fi
287
	mn_deps
288
	of
289
	ovs
290
	modprobe
291
	nox
292
	oftest
293
	cbench
294
	other
295
	echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
296
	echo "Enjoy Mininet!"
297
}
298

    
299
# Restore disk space and remove sensitive files before shipping a VM.
300
function vm_clean {
301
	echo "Cleaning VM..."
302
	sudo apt-get clean
303
	sudo rm -rf /tmp/*
304
	sudo rm -rf openvswitch*.tar.gz
305

    
306
	# Remove sensistive files
307
	history -c  # note this won't work if you have multiple bash sessions
308
	rm ~/.bash_history  # need to clear in memory and remove on disk
309
	rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
310
	sudo rm ~/.ssh/authorized_keys2
311

    
312
	# Remove Mininet files
313
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
314
	#sudo rm -f /usr/bin/mnexec
315

    
316
	# Clear optional dev script for SSH keychain load on boot
317
	rm ~/.bash_profile
318

    
319
	# Clear git changes
320
	git config --global user.name "None"
321
	git config --global user.email "None"
322

    
323
	#sudo rm -rf ~/mininet
324
}
325

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

    
352
if [ $# -eq 0 ]
353
then
354
	all
355
else
356
	while getopts 'acdfhkmntvx' OPTION
357
	do
358
	  case $OPTION in
359
      a)    all;;
360
	  c)    kernel_clean;;
361
	  d)    vm_clean;;
362
	  f)    of;;
363
	  h)	usage;;
364
	  k)    kernel;;
365
	  m)    modprobe;;
366
	  n)    mn_deps;;
367
	  t)    other;;
368
	  v)    ovs;;
369
	  x)    nox;;
370
	  ?)    usage;;
371
	  esac
372
	done
373
	shift $(($OPTIND - 1))
374
fi