Newer
Older
#!/usr/bin/env bash
# Mininet install script for Debian
# Brandon Heller (brandonh@stanford.edu)
# Fail on error
set -e
# Fail on unset var usage
set -o nounset
# Location of CONFIG_NET_NS-enabled kernel(s)
KERNEL_LOC=http://www.stanford.edu/~brandonh
# Kernel params
# These kernels have been tried:
#KERNEL_NAME=2.6.33-custom
#KERNEL_NAME=`uname -r`
KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
# Kernel Deb pkg to be removed:
KERNEL_IMAGE_OLD=linux-image-2.6.26-2-686
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers
OVS_RELEASE=openvswitch-0.99.2
#OVS_RELEASE=openvswitch
OVS_DIR=~/$OVS_RELEASE
OVS_KMOD=openvswitch_mod.ko
OF_DIR=~/openflow
OF_KMOD=ofdatapath.ko
function kernel {
echo "Install new kernel..."
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# The easy approach: download pre-built linux-image and linux-headers packages:
wget $KERNEL_LOC/$KERNEL_HEADERS
wget $KERNEL_LOC/$KERNEL_IMAGE
#Install custom linux headers and image:
sudo dpkg -i $KERNEL_IMAGE $KERNEL_HEADERS
# 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.
}
function kernel_clean {
echo "Cleaning kernel..."
# To save disk space, remove previous kernel
sudo apt-get -y remove $KERNEL_IMAGE_OLD
#Also remove downloaded packages:
rm -f ~/linux-headers-* ~/linux-image-*
}
# Install Mininet deps
function mn_deps {
#Install dependencies:
sudo apt-get install -y screen psmisc xterm ssh iperf iproute python-setuptools
#Add sysctl parameters as noted in the INSTALL file to increase kernel limits to support larger setups:
sudo su -c "cat /home/mininet/mininet/util/sysctl_addon >> /etc/sysctl.conf"
#Load new sysctl settings:
sudo sysctl -p
}
# The following will cause a full OF install, covering:
# -user switch
# -kernel switch
# -dissector
# The instructions below are an abbreviated version from
# http://www.openflowswitch.org/wk/index.php/Debian_Install
# ... modified to use Debian Lenny rather than unstable.
function of {
echo "Installing OpenFlow and its tools..."
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
sudo apt-get install -y git-core automake m4 pkg-config libtool make libc6-dev autoconf autotools-dev gcc
git clone git://openflowswitch.org/openflow.git
cd ~/openflow
git fetch
# Get debianfix branch, which doesn't break on test deps install
# This is an optional step.
git checkout -b debianfix origin/debianfix
sudo regress/scripts/install_deps.pl
# Resume the install:
git checkout -b release/0.8.9 origin/release/0.8.9
./boot.sh
./configure --with-l26=/lib/modules/${KERNEL_NAME}
make
sudo make install
# Install dissector:
sudo apt-get install -y wireshark libgtk2.0-dev
cd ~/openflow/utilities/wireshark_dissectors/openflow
make
sudo make install
# Copy coloring rules: OF is white-on-blue:
mkdir -p ~/.wireshark
cp ~/mininet/util/colorfilters ~/.wireshark
# Remove avahi-daemon, which may cause unwanted discovery packets to be sent during tests, near link status changes:
sudo apt-get remove -y avahi-daemon
# Disable IPv6. Add to /etc/modprobe.d/blacklist.conf:
sudo sh -c "echo -e 'blacklist net-pf-10\nblacklist ipv6' >> /etc/modprobe.d/blacklist.conf"
}
# Install OpenVSwitch
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
function ovs {
echo "Installing OpenVSwitch..."
#Install Autoconf 2.63+ backport from Debian Backports repo:
#Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
sudo apt-get update
sudo apt-get -y --force-yes install debian-backports-keyring
sudo apt-get -y --force-yes -t lenny-backports install autoconf
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#Install OVS from git
#git clone git://openvswitch.org/openvswitch
#cd openvswitch
#./boot.sh
#Install OVS from release
cd ~/
wget http://openvswitch.org/releases/${OVS_RELEASE}.tar.gz
tar xzf ${OVS_RELEASE}.tar.gz
cd $OVS_RELEASE
./configure --with-l26=/lib/modules/${KERNEL_NAME}/build
make
sudo make install
}
# Install NOX
function nox {
echo "Install NOX..."
#Install NOX deps:
sudo apt-get -y install autoconf automake g++ libtool python python-twisted swig libboost1.35-dev libxerces-c2-dev libssl-dev make
#Install NOX optional deps:
sudo apt-get install -y libsqlite3-dev python-simplejson
#Install NOX:
git clone git://noxrepo.org/noxcore
cd noxcore
# With later autoconf versions this doesn't quite work:
./boot.sh || true
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# So use this instead:
autoreconf --install --force
mkdir build
cd build
../configure --with-python=yes
make
#make check
# Add NOX_CORE_DIR env var:
sed -i -e 's|# for examples$|&\nexport NOX_CORE_DIR=~/noxcore/build/src|' ~/.bashrc
# To verify this install:
#cd ~/noxcore/build/src
#./nox_core -v -i ptcp:
}
function other {
echo "Doing other setup tasks..."
#Enable command auto completion using sudo; modify ~/.bashrc:
sed -i -e 's|# for examples$|&\ncomplete -cf sudo|' ~/.bashrc
#Install tcpdump and tshark, cmd-line packet dump tools. Also install gitk,
#a graphical git history viewer.
sudo apt-get install -y tcpdump tshark gitk
#Set git to colorize everything.
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
#Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
sudo sed -i -e 's/^timeout.*$/timeout 1/' /boot/grub/menu.lst
}
# Script to copy built OVS and OF kernel modules to where modprobe will
# find them automatically. Removes the need to keep an environment variable
# for each, and works nicely with multiple kernel versions.
#
# The downside is that after each recompilation of OVS or OF you'll need to
# re-run this script. If you're using only one kernel version, then it may be
# a good idea to use a symbolic link in place of the copy below.
function modprobe {
echo "Setting up modprobe for OVS kmod..."
sudo cp $OVS_DIR/datapath/linux-2.6/$OVS_KMOD $DRIVERS_DIR
echo "Setting up modprobe for OF kmod..."
sudo cp $OF_DIR/datapath/linux-2.6/$OF_KMOD $DRIVERS_DIR
sudo depmod -a
}
function all {
echo "Running all commands..."
kernel
mn_deps
of
ovs
modprobe
nox
other
echo "Please reboot, then run ./mininet/util/install.sh -c to remove unneeded packages."
echo "Enjoy Mininet!"
}
# Restore disk space and remove sensitive files before shipping a VM.
function vm_clean {
echo "Cleaning VM..."
sudo apt-get clean
sudo rm -rf /tmp/*
sudo rm -rf openvswitch*.tar.gz
# Remove sensistive files
history -c
rm ~/.ssh/id_rsa*
sudo rm ~/.ssh/authorized_keys2
# Remove Mininet files
sudo rm -rf ~/mininet
sudo rm /lib/modules/python2.5/site-packets/mininet*
sudo rm /usr/bin/mnexec
# Clear git changes
git config --global user.name "None"
git config --global user.email "None"
}
function usage {
printf "Usage: %s: [-acdfhkmntvx] args\n" $(basename $0) >&2
exit 2
}
if [ $# -eq 0 ]
then
all
else
while getopts 'acdfhkmntvx' OPTION
do
case $OPTION in
a) all;;
c) kernel_clean;;
d) vm_clean;;
f) of;;
h) usage;;
k) kernel;;
m) modprobe;;
n) mn_deps;;
t) other;;
v) ovs;;
x) nox;;
?) usage;;
esac
done
shift $(($OPTIND - 1))
fi