Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 5d4d6305

History | View | Annotate | Download (8.71 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=UBUNTU  # Assume Ubuntu, not debian Lenny
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
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
	# The easy approach: download pre-built linux-image and linux-headers packages:
37
	wget -c $KERNEL_LOC/$KERNEL_HEADERS
38
	wget -c $KERNEL_LOC/$KERNEL_IMAGE
39

    
40
	#Install custom linux headers and image:
41
	sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS
42

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

    
54
	# 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.
55
}
56

    
57
function kernel_clean {
58
	echo "Cleaning kernel..."
59

    
60
	# To save disk space, remove previous kernel
61
	sudo apt-get -y remove $KERNEL_IMAGE_OLD
62

    
63
	#Also remove downloaded packages:
64
	rm -f ~/linux-headers-* ~/linux-image-*
65
}
66

    
67
# Install Mininet deps
68
function mn_deps {
69
	#Install dependencies:
70
	sudo apt-get install -y screen psmisc xterm ssh iperf iproute python-setuptools
71

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

    
75
	#Load new sysctl settings:
76
	sudo sysctl -p
77
}
78

    
79
# The following will cause a full OF install, covering:
80
# -user switch
81
# -dissector
82
# The instructions below are an abbreviated version from
83
# http://www.openflowswitch.org/wk/index.php/Debian_Install
84
# ... modified to use Debian Lenny rather than unstable.
85
function of {
86
	echo "Installing OpenFlow and its tools..."
87

    
88
	cd ~/
89
	sudo apt-get install -y git-core automake m4 pkg-config libtool make libc6-dev autoconf autotools-dev gcc
90
	git clone git://openflowswitch.org/openflow.git
91
	cd ~/openflow
92

    
93
	# Resume the install:
94
	./boot.sh
95
	./configure
96
	make
97
	sudo make install
98

    
99
	# Install dissector:
100
	sudo apt-get install -y wireshark libgtk2.0-dev
101
	cd ~/openflow/utilities/wireshark_dissectors/openflow
102
	make
103
	sudo make install
104

    
105
	# Copy coloring rules: OF is white-on-blue:
106
	mkdir -p ~/.wireshark
107
	cp ~/mininet/util/colorfilters ~/.wireshark
108

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

    
112
	# Disable IPv6.  Add to /etc/modprobe.d/blacklist:
113
	sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> /etc/modprobe.d/blacklist"
114
}
115

    
116
# Install OpenVSwitch
117
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
118
function ovs {
119
	echo "Installing OpenVSwitch..."
120

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

    
130
	#Install OVS from release
131
	cd ~/
132
	#wget http://openvswitch.org/releases/${OVS_RELEASE}.tar.gz
133
	#tar xzf ${OVS_RELEASE}.tar.gz
134
	#cd $OVS_RELEASE
135
	git clone git://openvswitch.org/openvswitch
136
	cd $OVS_RELEASE
137
	./boot.sh
138
    BUILDDIR=/lib/modules/${KERNEL_NAME}/build
139
    mkdir -p $BUILDDIR
140
    opts="--with-l26=$BUILDDIR"
141
	./configure $opts
142
	make
143
	sudo make install
144
}
145

    
146
# Install NOX with tutorial files
147
function nox {
148
	echo "Installing NOX w/tutorial files..."
149

    
150
	#Install NOX deps:
151
	sudo apt-get -y install autoconf automake g++ libtool python python-twisted swig  libxerces-c2-dev libssl-dev make
152
    if [ "$DIST" == "LENNY" ]; then
153
        sudo apt-get -y install libboost1.35-dev
154
    else
155
        sudo apt-get -y install libboost1.40-dev
156
    fi
157
	#Install NOX optional deps:
158
	sudo apt-get install -y libsqlite3-dev python-simplejson
159

    
160
	#Install NOX:
161
	cd ~/
162
	git clone git://openflowswitch.org/nox-tutorial noxcore
163
	cd noxcore
164

    
165
	# With later autoconf versions this doesn't quite work:
166
	./boot.sh --apps-core || true
167
	# So use this instead:
168
	autoreconf --install --force
169
	mkdir build
170
	cd build
171
	../configure --with-python=yes
172
	make
173
	#make check
174

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

    
178
	# To verify this install:
179
	#cd ~/noxcore/build/src
180
    #./nox_core -v -i ptcp:
181
}
182

    
183
# Install OFtest
184
function oftest {
185
    echo "Installing oftest..."
186

    
187
    #Install deps:
188
    sudo apt-get install -y tcpdump python-scapy
189

    
190
    #Install oftest:
191
    cd ~/
192
    git clone git://openflow.org/oftest
193
    cd oftest
194
    cd tools/munger
195
    sudo make install
196
}
197

    
198
# Install cbench
199
function cbench {
200
    echo "Installing cbench..."
201
    
202
    sudo apt-get install -y libsnmp-dev libpcap-dev
203
    cd ~/
204
    git clone git://www.openflow.org/oflops.git
205
    cd oflops
206
    sh boot.sh
207
    ./configure --with-openflow-src-dir=$HOME/openflow
208
    make
209
    sudo make install || true # make install fails; force past this
210
}
211

    
212
function other {
213
	echo "Doing other setup tasks..."
214

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

    
218
	#Install tcpdump and tshark, cmd-line packet dump tools.  Also install gitk,
219
	#a graphical git history viewer.
220
	sudo apt-get install -y tcpdump tshark gitk
221

    
222
    #Install common text editors
223
    sudo apt-get install -y vim nano emacs
224

    
225
    #Install NTP
226
    sudo apt-get install -y ntp
227

    
228
	#Set git to colorize everything.
229
	git config --global color.diff auto
230
	git config --global color.status auto
231
	git config --global color.branch auto
232

    
233
	#Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
234
	sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
235

    
236
    # Clean unneeded debs:
237
    rm -f ~/linux-headers-* ~/linux-image-*
238
}
239

    
240
# Script to copy built OVS kernel module to where modprobe will
241
# find them automatically.  Removes the need to keep an environment variable
242
# for insmod usage, and works nicely with multiple kernel versions.
243
#
244
# The downside is that after each recompilation of OVS you'll need to
245
# re-run this script.  If you're using only one kernel version, then it may be
246
# a good idea to use a symbolic link in place of the copy below.
247
function modprobe {
248
	echo "Setting up modprobe for OVS kmod..."
249

    
250
	sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
251
	sudo depmod -a ${KERNEL_NAME}
252
}
253

    
254
function all {
255
	echo "Running all commands..."
256
	kernel
257
	mn_deps
258
	of
259
	ovs
260
	modprobe
261
	nox
262
	oftest
263
	cbench
264
	other
265
	echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
266
	echo "Enjoy Mininet!"
267
}
268

    
269
# Restore disk space and remove sensitive files before shipping a VM.
270
function vm_clean {
271
	echo "Cleaning VM..."
272
	sudo apt-get clean
273
	sudo rm -rf /tmp/*
274
	sudo rm -rf openvswitch*.tar.gz
275

    
276
	# Remove sensistive files
277
	history -c
278
	rm ~/.bash_history # history -c doesn't seem to work for some reason
279
	rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
280
	sudo rm ~/.ssh/authorized_keys2
281

    
282
	# Remove Mininet files
283
	#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
284
	#sudo rm -f /usr/bin/mnexec
285

    
286
	# Clear optional dev script for SSH keychain load on boot
287
	rm ~/.bash_profile
288

    
289
	# Clear git changes
290
	git config --global user.name "None"
291
	git config --global user.email "None"
292

    
293
	#sudo rm -rf ~/mininet
294
}
295

    
296
function usage {
297
    printf "Usage: %s: [-acdfhkmntvxy] args\n" $(basename $0) >&2
298
    exit 2
299
}
300

    
301
function lenny {
302
    echo "Installing for Lenny"
303
    DIST=LENNY
304
}
305

    
306
if [ $# -eq 0 ]
307
then
308
	all
309
else
310
	while getopts 'lacdfhkmntvx' OPTION
311
	do
312
	  case $OPTION in
313
      l)    lenny;;
314
      a)    all;;
315
	  c)    kernel_clean;;
316
	  d)    vm_clean;;
317
	  f)    of;;
318
	  h)	usage;;
319
	  k)    kernel;;
320
	  m)    modprobe;;
321
	  n)    mn_deps;;
322
	  t)    other;;
323
	  v)    ovs;;
324
	  x)    nox;;
325
	  ?)    usage;;
326
	  esac
327
	done
328
	shift $(($OPTIND - 1))
329
fi