Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ c2e14519

History | View | Annotate | Download (11 KB)

1 0b1832dd Brandon Heller
#!/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 5d4d6305 Bob Lantz
 
8 0b1832dd Brandon Heller
# Fail on unset var usage
9
set -o nounset
10
11
# Location of CONFIG_NET_NS-enabled kernel(s)
12 4d1c17e1 Brandon Heller
KERNEL_LOC=http://www.openflow.org/downloads/mininet
13 0b1832dd Brandon Heller
14 cc16d2ce Bob Lantz
test -e /etc/debian_version && DIST="Debian"
15
grep Ubuntu /etc/lsb-release &> /dev/null && DIST="Ubuntu"
16 0b1832dd Brandon Heller
17
# Kernel params
18 1ee6fad7 Bob Lantz
19 cf9c9687 Bob Lantz
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 0b1832dd Brandon Heller
31 cc16d2ce Bob Lantz
echo "Detected Linux distribution: $DIST"
32 0b1832dd Brandon Heller
33
# Kernel Deb pkg to be removed:
34
KERNEL_IMAGE_OLD=linux-image-2.6.26-2-686
35
36 85b69adb Bob Lantz
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
37 0b1832dd Brandon Heller
38 37e1eafd Bob Lantz
OVS_RELEASE=v1.1.1
39
OVS_DIR=~/openvswitch
40 0b1832dd Brandon Heller
OVS_KMOD=openvswitch_mod.ko
41
42
function kernel {
43 cf9c9687 Bob Lantz
	echo "Install Mininet-compatible kernel"
44 d82b6183 Brandon Heller
	sudo apt-get update
45 cf9c9687 Bob Lantz
    
46
    if [ "$DIST" = "Debian" ]; then
47 85b69adb Bob Lantz
    
48 0b1832dd Brandon Heller
	# The easy approach: download pre-built linux-image and linux-headers packages:
49 5d4d6305 Bob Lantz
	wget -c $KERNEL_LOC/$KERNEL_HEADERS
50
	wget -c $KERNEL_LOC/$KERNEL_IMAGE
51 0b1832dd Brandon Heller
52
	#Install custom linux headers and image:
53
	sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS
54
55 c9ae0ab0 Brandon Heller
	# 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 0b1832dd Brandon Heller
	# 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 cf9c9687 Bob Lantz
    fi
68
69 0b1832dd Brandon Heller
}
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 a0ca68b6 Bob Lantz
	echo "Installing Mininet dependencies"
84 276bdaf0 Bob Lantz
	sudo aptitude install -y gcc make screen psmisc xterm ssh iperf iproute \
85
        python-setuptools python-networkx
86 0b1832dd Brandon Heller
87
	#Add sysctl parameters as noted in the INSTALL file to increase kernel limits to support larger setups:
88 0533e1cc Bob Lantz
	sudo su -c "cat $HOME/mininet/util/sysctl_addon >> /etc/sysctl.conf"
89 0b1832dd Brandon Heller
90
	#Load new sysctl settings:
91
	sudo sysctl -p
92 a0ca68b6 Bob Lantz
    
93
    echo "Installing Mininet core"
94
    pushd ~/mininet
95
    sudo make install
96
    popd
97 0b1832dd Brandon Heller
}
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 c5326892 Brandon Heller
	cd ~/
109 0b1832dd Brandon Heller
	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 011b02f8 Brandon Heller
	./configure
116 0b1832dd Brandon Heller
	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 83e7ea2a Bob Lantz
	# Disable IPv6.  Add to /etc/modprobe.d/blacklist:
133 59d32629 Bob Lantz
    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 0b1832dd Brandon Heller
}
140
141
# Install OpenVSwitch
142
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
143
function ovs {
144
	echo "Installing OpenVSwitch..."
145
146 85b69adb Bob Lantz
    if [ "$DIST" = "Debian" ]; then
147 276bdaf0 Bob Lantz
        sudo aptitude -y install pkg-config gcc make git-core python-dev libssl-dev
148 85b69adb Bob Lantz
        #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 5d4d6305 Bob Lantz
    fi
155 0b1832dd Brandon Heller
156 59d32629 Bob Lantz
    if [ "$DIST" = "Ubuntu" ]; then
157 cf9c9687 Bob Lantz
        sudo apt-get -y install $KERNEL_HEADERS
158
    fi
159
160 0b1832dd Brandon Heller
	#Install OVS from release
161
	cd ~/
162 b97415ee Brandon Heller
	git clone git://openvswitch.org/openvswitch
163 37e1eafd Bob Lantz
	cd $OVS_DIR
164
    git checkout $OVS_RELEASE
165 71ba12c5 Brandon Heller
	./boot.sh
166 5d4d6305 Bob Lantz
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
167 276bdaf0 Bob Lantz
    if [ ! -e $BUILDDIR ]; then
168 85cc906f Bob Lantz
        echo "Creating build sdirectory $BUILDDIR"
169 276bdaf0 Bob Lantz
        sudo mkdir -p $BUILDDIR
170
    fi
171 5d4d6305 Bob Lantz
    opts="--with-l26=$BUILDDIR"
172
	./configure $opts
173 0b1832dd Brandon Heller
	make
174
	sudo make install
175
}
176
177 011b02f8 Brandon Heller
# Install NOX with tutorial files
178 0b1832dd Brandon Heller
function nox {
179 011b02f8 Brandon Heller
	echo "Installing NOX w/tutorial files..."
180 0b1832dd Brandon Heller
181
	#Install NOX deps:
182 5d4d6305 Bob Lantz
	sudo apt-get -y install autoconf automake g++ libtool python python-twisted swig  libxerces-c2-dev libssl-dev make
183 59d32629 Bob Lantz
    if [ "$DIST" = "Debian" ]; then
184 5d4d6305 Bob Lantz
        sudo apt-get -y install libboost1.35-dev
185 59d32629 Bob Lantz
    elif [ "$DIST" = "Ubuntu" ]; then
186 85b69adb Bob Lantz
        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 5d4d6305 Bob Lantz
    fi
190 0b1832dd Brandon Heller
	#Install NOX optional deps:
191
	sudo apt-get install -y libsqlite3-dev python-simplejson
192
193
	#Install NOX:
194 c5326892 Brandon Heller
	cd ~/
195 3b48e829 Brandon Heller
	git clone git://openflowswitch.org/nox-tutorial noxcore
196 0b1832dd Brandon Heller
	cd noxcore
197
198 9a7717ed Brandon Heller
	# With later autoconf versions this doesn't quite work:
199 011b02f8 Brandon Heller
	./boot.sh --apps-core || true
200 59d32629 Bob Lantz
    if [ "$DIST" = "Debian" ]; then
201 85b69adb Bob Lantz
        # So use this instead:
202
        autoreconf --install --force
203
    fi
204 0b1832dd Brandon Heller
	mkdir build
205
	cd build
206
	../configure --with-python=yes
207 85b69adb Bob Lantz
    make
208 0b1832dd Brandon Heller
	#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 011b02f8 Brandon Heller
# 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 9f8c2551 Brandon Heller
    sudo apt-get install -y libsnmp-dev libpcap-dev
238 011b02f8 Brandon Heller
    cd ~/
239 4e13f615 Bob Lantz
    git clone git://openflow.org/oflops.git
240 011b02f8 Brandon Heller
    cd oflops
241
    sh boot.sh
242 0533e1cc Bob Lantz
    ./configure --with-openflow-src-dir=$HOME/openflow
243 011b02f8 Brandon Heller
    make
244
    sudo make install || true # make install fails; force past this
245
}
246
247 0b1832dd Brandon Heller
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 3b48e829 Brandon Heller
    #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 0b1832dd Brandon Heller
	#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 01eea350 Bob Lantz
    if [ "$DIST" = "Debian" ]; then
270
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
271
    fi
272 0b1832dd Brandon Heller
273 32b122bf Brandon Heller
    # Clean unneeded debs:
274
    rm -f ~/linux-headers-* ~/linux-image-*
275 fc48e6ee Brandon Heller
}
276
277 011b02f8 Brandon Heller
# Script to copy built OVS kernel module to where modprobe will
278 0b1832dd Brandon Heller
# find them automatically.  Removes the need to keep an environment variable
279 011b02f8 Brandon Heller
# for insmod usage, and works nicely with multiple kernel versions.
280 0b1832dd Brandon Heller
#
281 011b02f8 Brandon Heller
# The downside is that after each recompilation of OVS you'll need to
282 0b1832dd Brandon Heller
# 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 011b02f8 Brandon Heller
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
288 e4370f7e Brandon Heller
	sudo depmod -a ${KERNEL_NAME}
289 0b1832dd Brandon Heller
}
290
291
function all {
292
	echo "Running all commands..."
293 25f64a39 Bob Lantz
    if [ "$DIST" != "Ubuntu" ]; then
294
        # Ubuntu ships with Mininet-compatible kernel
295
        kernel
296
    fi
297 0b1832dd Brandon Heller
	mn_deps
298
	of
299
	ovs
300 dd2a2442 Bob Lantz
    modprobe
301 0b1832dd Brandon Heller
	nox
302 011b02f8 Brandon Heller
	oftest
303
	cbench
304 0b1832dd Brandon Heller
	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 01eea350 Bob Lantz
	history -c  # note this won't work if you have multiple bash sessions
318 4800435d Brandon Heller
	rm -f ~/.bash_history  # need to clear in memory and remove on disk
319 74cd0843 Brandon Heller
	rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
320 4800435d Brandon Heller
	sudo rm -f ~/.ssh/authorized_keys2
321 0b1832dd Brandon Heller
322
	# Remove Mininet files
323 3b48e829 Brandon Heller
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
324
	#sudo rm -f /usr/bin/mnexec
325 0b1832dd Brandon Heller
326 7abca147 Brandon Heller
	# Clear optional dev script for SSH keychain load on boot
327 4800435d Brandon Heller
	rm -f ~/.bash_profile
328 7abca147 Brandon Heller
329 0b1832dd Brandon Heller
	# Clear git changes
330
	git config --global user.name "None"
331
	git config --global user.email "None"
332
333 4800435d Brandon Heller
	# Remove mininet install script
334
	rm -f install-mininet.sh
335 0b1832dd Brandon Heller
}
336
337
function usage {
338 01eea350 Bob Lantz
    printf 'Usage: %s [-acdfhkmntvxy]\n\n' $(basename $0) >&2
339 85b69adb Bob Lantz
    
340 01eea350 Bob Lantz
    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 85b69adb Bob Lantz
        
346 01eea350 Bob Lantz
    printf 'options:\n' >&2
347
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
348 c2e14519 Bob Lantz
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
349 01eea350 Bob Lantz
    printf -- ' -c: (C)lean up after kernel install\n' >&2
350
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2    
351
    printf -- ' -f: install open(F)low\n' >&2
352
    printf -- ' -h: print this (H)elp message\n' >&2
353
    printf -- ' -k: install new (K)ernel\n' >&2
354
    printf -- ' -m: install Open vSwitch kernel (M)odule\n' >&2
355 a0ca68b6 Bob Lantz
    printf -- ' -n: install mini(N)et dependencies + core files\n' >&2
356 01eea350 Bob Lantz
    printf -- ' -t: install o(T)her stuff\n' >&2
357
    printf -- ' -v: install open (V)switch\n' >&2
358 276bdaf0 Bob Lantz
    printf -- ' -x: install NO(X) OpenFlow controller\n' >&2
359 01eea350 Bob Lantz
    printf -- ' -y: install (A)ll packages\n' >&2    
360 85b69adb Bob Lantz
    
361 0b1832dd Brandon Heller
    exit 2
362
}
363
364
if [ $# -eq 0 ]
365
then
366
	all
367
else
368 c2e14519 Bob Lantz
	while getopts 'abcdfhkmntvx' OPTION
369 0b1832dd Brandon Heller
	do
370
	  case $OPTION in
371 c2e14519 Bob Lantz
	  a)    all;;
372
	  b)    cbench;;
373 0b1832dd Brandon Heller
	  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