Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 25f64a39

History | View | Annotate | Download (10.3 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
# Kernel params
15
# These kernels have been tried:
16
KERNEL_NAME=2.6.33.1-mininet
17
#KERNEL_NAME=`uname -r`
18
KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
19
KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
20
DIST=`lsb_release -is`
21

    
22
# Kernel Deb pkg to be removed:
23
KERNEL_IMAGE_OLD=linux-image-2.6.26-2-686
24

    
25
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
26

    
27
#OVS_RELEASE=openvswitch-1.0.1
28
OVS_RELEASE=openvswitch # release 1.0.1 doesn't work with veth pairs.
29
OVS_DIR=~/$OVS_RELEASE
30
OVS_KMOD=openvswitch_mod.ko
31

    
32
function kernel {
33
	echo "Install new kernel..."
34
	sudo apt-get update
35

    
36
    # Until we build ext4 into our kernel image
37
    ext2=`mount | head -1 | egrep 'ext2|ext3'`
38
    if [ "$ext2" == "" ]; then
39
        echo "Kernel package requires ext2 or ext3 root filesystem"
40
        exit 1
41
    fi
42
    
43
	# The easy approach: download pre-built linux-image and linux-headers packages:
44
	wget -c $KERNEL_LOC/$KERNEL_HEADERS
45
	wget -c $KERNEL_LOC/$KERNEL_IMAGE
46

    
47
	#Install custom linux headers and image:
48
	sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS
49

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

    
61
	# 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.
62
}
63

    
64
function kernel_clean {
65
	echo "Cleaning kernel..."
66

    
67
	# To save disk space, remove previous kernel
68
	sudo apt-get -y remove $KERNEL_IMAGE_OLD
69

    
70
	#Also remove downloaded packages:
71
	rm -f ~/linux-headers-* ~/linux-image-*
72
}
73

    
74
# Install Mininet deps
75
function mn_deps {
76
	#Install dependencies:
77
	sudo apt-get install -y screen psmisc xterm ssh iperf iproute python-setuptools
78

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

    
82
	#Load new sysctl settings:
83
	sudo sysctl -p
84
}
85

    
86
# The following will cause a full OF install, covering:
87
# -user switch
88
# -dissector
89
# The instructions below are an abbreviated version from
90
# http://www.openflowswitch.org/wk/index.php/Debian_Install
91
# ... modified to use Debian Lenny rather than unstable.
92
function of {
93
	echo "Installing OpenFlow and its tools..."
94

    
95
	cd ~/
96
	sudo apt-get install -y git-core automake m4 pkg-config libtool make libc6-dev autoconf autotools-dev gcc
97
	git clone git://openflowswitch.org/openflow.git
98
	cd ~/openflow
99

    
100
	# Resume the install:
101
	./boot.sh
102
	./configure
103
	make
104
	sudo make install
105

    
106
	# Install dissector:
107
	sudo apt-get install -y wireshark libgtk2.0-dev
108
	cd ~/openflow/utilities/wireshark_dissectors/openflow
109
	make
110
	sudo make install
111

    
112
	# Copy coloring rules: OF is white-on-blue:
113
	mkdir -p ~/.wireshark
114
	cp ~/mininet/util/colorfilters ~/.wireshark
115

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

    
119
	# Disable IPv6.  Add to /etc/modprobe.d/blacklist:
120
	sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> /etc/modprobe.d/blacklist"
121
}
122

    
123
# Install OpenVSwitch
124
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
125
function ovs {
126
	echo "Installing OpenVSwitch..."
127

    
128
    if [ "$DIST" = "Debian" ]; then
129
        #Install Autoconf 2.63+ backport from Debian Backports repo:
130
        #Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
131
        sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
132
        sudo apt-get update
133
        sudo apt-get -y --force-yes install debian-backports-keyring
134
        sudo apt-get -y --force-yes -t lenny-backports install autoconf
135
    fi
136

    
137
	#Install OVS from release
138
	cd ~/
139
	#wget http://openvswitch.org/releases/${OVS_RELEASE}.tar.gz
140
	#tar xzf ${OVS_RELEASE}.tar.gz
141
	#cd $OVS_RELEASE
142
	git clone git://openvswitch.org/openvswitch
143
	cd $OVS_RELEASE
144
	./boot.sh
145
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
146
    mkdir -p $BUILDDIR
147
    opts="--with-l26=$BUILDDIR"
148
	./configure $opts
149
	make
150
	sudo make install
151
}
152

    
153
# Install NOX with tutorial files
154
function nox {
155
	echo "Installing NOX w/tutorial files..."
156

    
157
	#Install NOX deps:
158
	sudo apt-get -y install autoconf automake g++ libtool python python-twisted swig  libxerces-c2-dev libssl-dev make
159
    if [ "$DIST" == "Debian" ]; then
160
        sudo apt-get -y install libboost1.35-dev
161
    elif [ "$DIST" == "Ubuntu" ]; then
162
        sudo apt-get -y install python-dev libboost-dev 
163
        sudo apt-get -y install libboost-filesystem-dev
164
        sudo apt-get -y install libboost-test-dev
165
    fi
166
	#Install NOX optional deps:
167
	sudo apt-get install -y libsqlite3-dev python-simplejson
168

    
169
	#Install NOX:
170
	cd ~/
171
	git clone git://openflowswitch.org/nox-tutorial noxcore
172
	cd noxcore
173

    
174
	# With later autoconf versions this doesn't quite work:
175
	./boot.sh --apps-core || true
176
    if [ "$DIST" == "Debian" ]; then
177
        # So use this instead:
178
        autoreconf --install --force
179
    fi
180
	mkdir build
181
	cd build
182
	../configure --with-python=yes
183
    make
184
	#make check
185

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

    
189
	# To verify this install:
190
	#cd ~/noxcore/build/src
191
    #./nox_core -v -i ptcp:
192
}
193

    
194
# Install OFtest
195
function oftest {
196
    echo "Installing oftest..."
197

    
198
    #Install deps:
199
    sudo apt-get install -y tcpdump python-scapy
200

    
201
    #Install oftest:
202
    cd ~/
203
    git clone git://openflow.org/oftest
204
    cd oftest
205
    cd tools/munger
206
    sudo make install
207
}
208

    
209
# Install cbench
210
function cbench {
211
    echo "Installing cbench..."
212
    
213
    sudo apt-get install -y libsnmp-dev libpcap-dev
214
    cd ~/
215
    git clone git://www.openflow.org/oflops.git
216
    cd oflops
217
    sh boot.sh
218
    ./configure --with-openflow-src-dir=$HOME/openflow
219
    make
220
    sudo make install || true # make install fails; force past this
221
}
222

    
223
function other {
224
	echo "Doing other setup tasks..."
225

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

    
229
	#Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
230
	#a graphical git history viewer.
231
	sudo apt-get install -y tcpdump tshark gitk
232

    
233
    #Install common text editors
234
    sudo apt-get install -y vim nano emacs
235

    
236
    #Install NTP
237
    sudo apt-get install -y ntp
238

    
239
	#Set git to colorize everything.
240
	git config --global color.diff auto
241
	git config --global color.status auto
242
	git config --global color.branch auto
243

    
244
	#Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
245
    if [ "$DIST" = "Debian" ]; then
246
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
247
    fi
248

    
249
    # Clean unneeded debs:
250
    rm -f ~/linux-headers-* ~/linux-image-*
251
}
252

    
253
# Script to copy built OVS kernel module to where modprobe will
254
# find them automatically.  Removes the need to keep an environment variable
255
# for insmod usage, and works nicely with multiple kernel versions.
256
#
257
# The downside is that after each recompilation of OVS you'll need to
258
# re-run this script.  If you're using only one kernel version, then it may be
259
# a good idea to use a symbolic link in place of the copy below.
260
function modprobe {
261
	echo "Setting up modprobe for OVS kmod..."
262

    
263
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
264
	sudo depmod -a ${KERNEL_NAME}
265
}
266

    
267
function all {
268
	echo "Running all commands..."
269
    if [ "$DIST" != "Ubuntu" ]; then
270
        # Ubuntu ships with Mininet-compatible kernel
271
        kernel
272
    fi
273
	mn_deps
274
	of
275
	ovs
276
	modprobe
277
	nox
278
	oftest
279
	cbench
280
	other
281
	echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
282
	echo "Enjoy Mininet!"
283
}
284

    
285
# Restore disk space and remove sensitive files before shipping a VM.
286
function vm_clean {
287
	echo "Cleaning VM..."
288
	sudo apt-get clean
289
	sudo rm -rf /tmp/*
290
	sudo rm -rf openvswitch*.tar.gz
291

    
292
	# Remove sensistive files
293
	history -c  # note this won't work if you have multiple bash sessions
294
	rm ~/.bash_history  # need to clear in memory and remove on disk
295
	rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
296
	sudo rm ~/.ssh/authorized_keys2
297

    
298
	# Remove Mininet files
299
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
300
	#sudo rm -f /usr/bin/mnexec
301

    
302
	# Clear optional dev script for SSH keychain load on boot
303
	rm ~/.bash_profile
304

    
305
	# Clear git changes
306
	git config --global user.name "None"
307
	git config --global user.email "None"
308

    
309
	#sudo rm -rf ~/mininet
310
}
311

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

    
338
if [ $# -eq 0 ]
339
then
340
	all
341
else
342
	while getopts 'acdfhkmntvx' OPTION
343
	do
344
	  case $OPTION in
345
      a)    all;;
346
	  c)    kernel_clean;;
347
	  d)    vm_clean;;
348
	  f)    of;;
349
	  h)	usage;;
350
	  k)    kernel;;
351
	  m)    modprobe;;
352
	  n)    mn_deps;;
353
	  t)    other;;
354
	  v)    ovs;;
355
	  x)    nox;;
356
	  ?)    usage;;
357
	  esac
358
	done
359
	shift $(($OPTIND - 1))
360
fi