Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 7596de59

History | View | Annotate | Download (11.2 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

    
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=v1.1.1
39
OVS_DIR=~/openvswitch
40
OVS_KMOD=openvswitch_mod.ko
41

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

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

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

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

    
69
}
70

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

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

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

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

    
87
    if [ "$DIST" = "Ubuntu" ] && grep '10.04' /etc/*release*; then
88
        echo "Upgrading networkx to avoid deprecation warning"
89
        sudo easy_install --upgrade networkx
90
    fi
91

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

    
95
	#Load new sysctl settings:
96
	sudo sysctl -p
97
    
98
    echo "Installing Mininet core"
99
    pushd ~/mininet
100
    sudo make install
101
    popd
102
}
103

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

    
113
	cd ~/
114
	sudo apt-get install -y git-core automake m4 pkg-config libtool make libc6-dev autoconf autotools-dev gcc
115
	git clone git://openflowswitch.org/openflow.git
116
	cd ~/openflow
117

    
118
	# Resume the install:
119
	./boot.sh
120
	./configure
121
	make
122
	sudo make install
123

    
124
	# Install dissector:
125
	sudo apt-get install -y wireshark libgtk2.0-dev
126
	cd ~/openflow/utilities/wireshark_dissectors/openflow
127
	make
128
	sudo make install
129

    
130
	# Copy coloring rules: OF is white-on-blue:
131
	mkdir -p ~/.wireshark
132
	cp ~/mininet/util/colorfilters ~/.wireshark
133

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

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

    
146
# Install OpenVSwitch
147
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
148
function ovs {
149
	echo "Installing OpenVSwitch..."
150

    
151
    if [ "$DIST" = "Debian" ]; then
152
        sudo aptitude -y install pkg-config gcc make git-core python-dev libssl-dev
153
        #Install Autoconf 2.63+ backport from Debian Backports repo:
154
        #Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
155
        sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
156
        sudo apt-get update
157
        sudo apt-get -y --force-yes install debian-backports-keyring
158
        sudo apt-get -y --force-yes -t lenny-backports install autoconf
159
    fi
160

    
161
    if [ "$DIST" = "Ubuntu" ]; then
162
        sudo apt-get -y install $KERNEL_HEADERS
163
    fi
164

    
165
	#Install OVS from release
166
	cd ~/
167
	git clone git://openvswitch.org/openvswitch
168
	cd $OVS_DIR
169
    git checkout $OVS_RELEASE
170
	./boot.sh
171
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
172
    if [ ! -e $BUILDDIR ]; then
173
        echo "Creating build sdirectory $BUILDDIR"
174
        sudo mkdir -p $BUILDDIR
175
    fi
176
    opts="--with-l26=$BUILDDIR"
177
	./configure $opts
178
	make
179
	sudo make install
180
}
181

    
182
# Install NOX with tutorial files
183
function nox {
184
	echo "Installing NOX w/tutorial files..."
185

    
186
	#Install NOX deps:
187
	sudo apt-get -y install autoconf automake g++ libtool python python-twisted swig  libxerces-c2-dev libssl-dev make
188
    if [ "$DIST" = "Debian" ]; then
189
        sudo apt-get -y install libboost1.35-dev
190
    elif [ "$DIST" = "Ubuntu" ]; then
191
        sudo apt-get -y install python-dev libboost-dev 
192
        sudo apt-get -y install libboost-filesystem-dev
193
        sudo apt-get -y install libboost-test-dev
194
    fi
195
	#Install NOX optional deps:
196
	sudo apt-get install -y libsqlite3-dev python-simplejson
197

    
198
	#Install NOX:
199
	cd ~/
200
	git clone git://openflowswitch.org/nox-tutorial noxcore
201
	cd noxcore
202

    
203
	# With later autoconf versions this doesn't quite work:
204
	./boot.sh --apps-core || true
205
    if [ "$DIST" = "Debian" ]; then
206
        # So use this instead:
207
        autoreconf --install --force
208
    fi
209
	mkdir build
210
	cd build
211
	../configure --with-python=yes
212
    make
213
	#make check
214

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

    
218
	# To verify this install:
219
	#cd ~/noxcore/build/src
220
    #./nox_core -v -i ptcp:
221
}
222

    
223
# Install OFtest
224
function oftest {
225
    echo "Installing oftest..."
226

    
227
    #Install deps:
228
    sudo apt-get install -y tcpdump python-scapy
229

    
230
    #Install oftest:
231
    cd ~/
232
    git clone git://openflow.org/oftest
233
    cd oftest
234
    cd tools/munger
235
    sudo make install
236
}
237

    
238
# Install cbench
239
function cbench {
240
    echo "Installing cbench..."
241
    
242
    sudo apt-get install -y libsnmp-dev libpcap-dev
243
    cd ~/
244
    git clone git://openflow.org/oflops.git
245
    cd oflops
246
    sh boot.sh || true # possible error in autoreconf, so run twice
247
    sh boot.sh
248
    ./configure --with-openflow-src-dir=$HOME/openflow
249
    make
250
    sudo make install || true # make install fails; force past this
251
}
252

    
253
function other {
254
	echo "Doing other setup tasks..."
255

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

    
259
	#Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
260
	#a graphical git history viewer.
261
	sudo apt-get install -y tcpdump tshark gitk
262

    
263
    #Install common text editors
264
    sudo apt-get install -y vim nano emacs
265

    
266
    #Install NTP
267
    sudo apt-get install -y ntp
268

    
269
	#Set git to colorize everything.
270
	git config --global color.diff auto
271
	git config --global color.status auto
272
	git config --global color.branch auto
273

    
274
	#Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
275
    if [ "$DIST" = "Debian" ]; then
276
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
277
    fi
278

    
279
    # Clean unneeded debs:
280
    rm -f ~/linux-headers-* ~/linux-image-*
281
}
282

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

    
293
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
294
	sudo depmod -a ${KERNEL_NAME}
295
}
296

    
297
function all {
298
	echo "Running all commands..."
299
    if [ "$DIST" != "Ubuntu" ]; then
300
        # Ubuntu ships with Mininet-compatible kernel
301
        kernel
302
    fi
303
	mn_deps
304
	of
305
	ovs
306
    modprobe
307
	nox
308
	oftest
309
	cbench
310
	other
311
	echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
312
	echo "Enjoy Mininet!"
313
}
314

    
315
# Restore disk space and remove sensitive files before shipping a VM.
316
function vm_clean {
317
	echo "Cleaning VM..."
318
	sudo apt-get clean
319
	sudo rm -rf /tmp/*
320
	sudo rm -rf openvswitch*.tar.gz
321

    
322
	# Remove sensistive files
323
	history -c  # note this won't work if you have multiple bash sessions
324
	rm -f ~/.bash_history  # need to clear in memory and remove on disk
325
	rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
326
	sudo rm -f ~/.ssh/authorized_keys2
327

    
328
	# Remove Mininet files
329
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
330
	#sudo rm -f /usr/bin/mnexec
331

    
332
	# Clear optional dev script for SSH keychain load on boot
333
	rm -f ~/.bash_profile
334

    
335
	# Clear git changes
336
	git config --global user.name "None"
337
	git config --global user.email "None"
338

    
339
	# Remove mininet install script
340
	rm -f install-mininet.sh
341
}
342

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

    
370
if [ $# -eq 0 ]
371
then
372
	all
373
else
374
	while getopts 'abcdfhkmntvx' OPTION
375
	do
376
	  case $OPTION in
377
	  a)    all;;
378
	  b)    cbench;;
379
	  c)    kernel_clean;;
380
	  d)    vm_clean;;
381
	  f)    of;;
382
	  h)	usage;;
383
	  k)    kernel;;
384
	  m)    modprobe;;
385
	  n)    mn_deps;;
386
	  t)    other;;
387
	  v)    ovs;;
388
	  x)    nox;;
389
	  ?)    usage;;
390
	  esac
391
	done
392
	shift $(($OPTIND - 1))
393
fi