Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 276bdaf0

History | View | Annotate | Download (11.1 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 aptitude install -y gcc make screen psmisc xterm ssh iperf iproute \
86
        python-setuptools python-networkx
87

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
221
# Install OFtest
222
function oftest {
223
    echo "Installing oftest..."
224

    
225
    #Install deps:
226
    sudo apt-get install -y tcpdump python-scapy
227

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

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

    
250
function other {
251
	echo "Doing other setup tasks..."
252

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

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

    
260
    #Install common text editors
261
    sudo apt-get install -y vim nano emacs
262

    
263
    #Install NTP
264
    sudo apt-get install -y ntp
265

    
266
	#Set git to colorize everything.
267
	git config --global color.diff auto
268
	git config --global color.status auto
269
	git config --global color.branch auto
270

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

    
276
    # Clean unneeded debs:
277
    rm -f ~/linux-headers-* ~/linux-image-*
278
}
279

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

    
290
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
291
	sudo depmod -a ${KERNEL_NAME}
292
}
293

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

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

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

    
325
	# Remove Mininet files
326
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
327
	#sudo rm -f /usr/bin/mnexec
328

    
329
	# Clear optional dev script for SSH keychain load on boot
330
	rm -f ~/.bash_profile
331

    
332
	# Clear git changes
333
	git config --global user.name "None"
334
	git config --global user.email "None"
335

    
336
	# Remove mininet install script
337
	rm -f install-mininet.sh
338
}
339

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

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