Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ cf9c9687

History | View | Annotate | Download (10.5 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
	#Install 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

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

    
100
	cd ~/
101
	sudo apt-get install -y git-core automake m4 pkg-config libtool make libc6-dev autoconf autotools-dev gcc
102
	git clone git://openflowswitch.org/openflow.git
103
	cd ~/openflow
104

    
105
	# Resume the install:
106
	./boot.sh
107
	./configure
108
	make
109
	sudo make install
110

    
111
	# Install dissector:
112
	sudo apt-get install -y wireshark libgtk2.0-dev
113
	cd ~/openflow/utilities/wireshark_dissectors/openflow
114
	make
115
	sudo make install
116

    
117
	# Copy coloring rules: OF is white-on-blue:
118
	mkdir -p ~/.wireshark
119
	cp ~/mininet/util/colorfilters ~/.wireshark
120

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

    
124
	# Disable IPv6.  Add to /etc/modprobe.d/blacklist:
125
	sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> /etc/modprobe.d/blacklist"
126
}
127

    
128
# Install OpenVSwitch
129
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
130
function ovs {
131
	echo "Installing OpenVSwitch..."
132

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

    
142
    if [ "$DIST" == "Ubuntu" ]; then
143
        sudo apt-get -y install $KERNEL_HEADERS
144
    fi
145

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

    
162
# Install NOX with tutorial files
163
function nox {
164
	echo "Installing NOX w/tutorial files..."
165

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

    
178
	#Install NOX:
179
	cd ~/
180
	git clone git://openflowswitch.org/nox-tutorial noxcore
181
	cd noxcore
182

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

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

    
198
	# To verify this install:
199
	#cd ~/noxcore/build/src
200
    #./nox_core -v -i ptcp:
201
}
202

    
203
# Install OFtest
204
function oftest {
205
    echo "Installing oftest..."
206

    
207
    #Install deps:
208
    sudo apt-get install -y tcpdump python-scapy
209

    
210
    #Install oftest:
211
    cd ~/
212
    git clone git://openflow.org/oftest
213
    cd oftest
214
    cd tools/munger
215
    sudo make install
216
}
217

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

    
232
function other {
233
	echo "Doing other setup tasks..."
234

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

    
238
	#Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
239
	#a graphical git history viewer.
240
	sudo apt-get install -y tcpdump tshark gitk
241

    
242
    #Install common text editors
243
    sudo apt-get install -y vim nano emacs
244

    
245
    #Install NTP
246
    sudo apt-get install -y ntp
247

    
248
	#Set git to colorize everything.
249
	git config --global color.diff auto
250
	git config --global color.status auto
251
	git config --global color.branch auto
252

    
253
	#Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
254
    if [ "$DIST" = "Debian" ]; then
255
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
256
    fi
257

    
258
    # Clean unneeded debs:
259
    rm -f ~/linux-headers-* ~/linux-image-*
260
}
261

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

    
272
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
273
	sudo depmod -a ${KERNEL_NAME}
274
}
275

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

    
294
# Restore disk space and remove sensitive files before shipping a VM.
295
function vm_clean {
296
	echo "Cleaning VM..."
297
	sudo apt-get clean
298
	sudo rm -rf /tmp/*
299
	sudo rm -rf openvswitch*.tar.gz
300

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

    
307
	# Remove Mininet files
308
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
309
	#sudo rm -f /usr/bin/mnexec
310

    
311
	# Clear optional dev script for SSH keychain load on boot
312
	rm ~/.bash_profile
313

    
314
	# Clear git changes
315
	git config --global user.name "None"
316
	git config --global user.email "None"
317

    
318
	#sudo rm -rf ~/mininet
319
}
320

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

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