Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 4e13f615

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

    
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
	#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
        sudo aptitude -y install pkg-config gcc make git-core python-dev libssl-dev
148
        #Install Autoconf 2.63+ backport from Debian Backports repo:
149
        #Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
150
        sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
151
        sudo apt-get update
152
        sudo apt-get -y --force-yes install debian-backports-keyring
153
        sudo apt-get -y --force-yes -t lenny-backports install autoconf
154
    fi
155

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

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

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

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

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

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

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

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

    
218
# Install OFtest
219
function oftest {
220
    echo "Installing oftest..."
221

    
222
    #Install deps:
223
    sudo apt-get install -y tcpdump python-scapy
224

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

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

    
247
function other {
248
	echo "Doing other setup tasks..."
249

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

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

    
257
    #Install common text editors
258
    sudo apt-get install -y vim nano emacs
259

    
260
    #Install NTP
261
    sudo apt-get install -y ntp
262

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

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

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

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

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

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

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

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

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

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

    
329
	# Clear git changes
330
	git config --global user.name "None"
331
	git config --global user.email "None"
332

    
333
	# Remove mininet install script
334
	rm -f install-mininet.sh
335
}
336

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

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