Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 1ee6fad7

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

    
19
KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
20

    
21
if [ "$DIST" = "Debian" ]; then
22
    KERNEL_NAME=2.6.33.1-mininet
23
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
24
    KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
25
elif [ "$DIST" = "Ubuntu" ]; then
26
    KERNEL_NAME=`uname -r`
27
    KERNEL_HEADERS=linux-headers-${KERNEL_NAME}
28
else
29
    echo "Install.sh currently only supports Ubuntu and Debian."
30
    exit 1
31
fi
32

    
33
echo "Detected Linux distribution: $DIST"
34

    
35
# Kernel Deb pkg to be removed:
36
KERNEL_IMAGE_OLD=linux-image-2.6.26-2-686
37

    
38
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
39

    
40
#OVS_RELEASE=openvswitch-1.0.1
41
OVS_RELEASE=openvswitch # release 1.0.1 doesn't work with veth pairs.
42
OVS_DIR=~/$OVS_RELEASE
43
OVS_KMOD=openvswitch_mod.ko
44

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

    
55
	#Install custom linux headers and image:
56
	sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS
57

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

    
69
	# 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.
70
    fi
71

    
72
}
73

    
74
function kernel_clean {
75
	echo "Cleaning kernel..."
76

    
77
	# To save disk space, remove previous kernel
78
	sudo apt-get -y remove $KERNEL_IMAGE_OLD
79

    
80
	#Also remove downloaded packages:
81
	rm -f ~/linux-headers-* ~/linux-image-*
82
}
83

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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