Statistics
| Branch: | Tag: | Revision:

mininet / util / install.sh @ 47be38e6

History | View | Annotate | Download (21.3 KB)

1 0b1832dd Brandon Heller
#!/usr/bin/env bash
2 60b5864e Bob Lantz
3 7e79d135 Bob Lantz
# Mininet install script for Ubuntu (and Debian Lenny)
4 0b1832dd Brandon Heller
# Brandon Heller (brandonh@stanford.edu)
5
6
# Fail on error
7
set -e
8 82c8bdaf Bob Lantz
9 0b1832dd Brandon Heller
# Fail on unset var usage
10
set -o nounset
11
12 adf391fd Brian O'Connor
# Get directory containing mininet folder
13 389c7aa5 Brian O'Connor
MININET_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd -P )"
14 adf391fd Brian O'Connor
15
# Set up build directory, which by default is the working directory
16
#  unless the working directory is a subdirectory of mininet, 
17
#  in which case we use the directory containing mininet
18 389c7aa5 Brian O'Connor
BUILD_DIR="$(pwd -P)"
19
case $BUILD_DIR in
20 adf391fd Brian O'Connor
  $MININET_DIR/*) BUILD_DIR=$MININET_DIR;; # currect directory is a subdirectory
21 389c7aa5 Brian O'Connor
  *) BUILD_DIR=$BUILD_DIR;;
22 adf391fd Brian O'Connor
esac
23
24 0b1832dd Brandon Heller
# Location of CONFIG_NET_NS-enabled kernel(s)
25 4d1c17e1 Brandon Heller
KERNEL_LOC=http://www.openflow.org/downloads/mininet
26 0b1832dd Brandon Heller
27 8d1444a9 Bob Lantz
# Attempt to identify Linux release
28
29
DIST=Unknown
30
RELEASE=Unknown
31
CODENAME=Unknown
32 3cd2e1a6 Bob Lantz
ARCH=`uname -m`
33 2a4cbe2f Bob Lantz
if [ "$ARCH" = "x86_64" ]; then ARCH="amd64"; fi
34 46cffb3b Bob Lantz
if [ "$ARCH" = "i686" ]; then ARCH="i386"; fi
35 60b5864e Bob Lantz
36 cc16d2ce Bob Lantz
test -e /etc/debian_version && DIST="Debian"
37
grep Ubuntu /etc/lsb-release &> /dev/null && DIST="Ubuntu"
38 8d1444a9 Bob Lantz
if [ "$DIST" = "Ubuntu" ] || [ "$DIST" = "Debian" ]; then
39 3cd2e1a6 Bob Lantz
    install='sudo apt-get -y install'
40
    remove='sudo apt-get -y remove'
41 2a4cbe2f Bob Lantz
    pkginst='sudo dpkg -i'
42 738ae1f3 Bob Lantz
    # Prereqs for this script
43 2a4cbe2f Bob Lantz
    if ! which lsb_release &> /dev/null; then
44 738ae1f3 Bob Lantz
        $install lsb-release
45 2a4cbe2f Bob Lantz
    fi
46 8d1444a9 Bob Lantz
fi
47 15f2d240 Jose Pedro Oliveira
test -e /etc/fedora-release && DIST="Fedora"
48
if [ "$DIST" = "Fedora" ]; then
49
    install='sudo yum -y install'
50
    remove='sudo yum -y erase'
51
    pkginst='sudo rpm -ivh'
52
    # Prereqs for this script
53
    if ! which lsb_release &> /dev/null; then
54
        $install redhat-lsb-core
55
    fi
56
fi
57 8d1444a9 Bob Lantz
if which lsb_release &> /dev/null; then
58
    DIST=`lsb_release -is`
59
    RELEASE=`lsb_release -rs`
60
    CODENAME=`lsb_release -cs`
61
fi
62 3cd2e1a6 Bob Lantz
echo "Detected Linux distribution: $DIST $RELEASE $CODENAME $ARCH"
63 0b1832dd Brandon Heller
64
# Kernel params
65 1ee6fad7 Bob Lantz
66 2dee3413 Bob Lantz
KERNEL_NAME=`uname -r`
67
KERNEL_HEADERS=kernel-headers-${KERNEL_NAME}
68
69
if ! echo $DIST | egrep 'Ubuntu|Debian|Fedora'; then
70
    echo "Install.sh currently only supports Ubuntu, Debian and Fedora."
71 cf9c9687 Bob Lantz
    exit 1
72
fi
73 0b1832dd Brandon Heller
74 2a4cbe2f Bob Lantz
# More distribution info
75
DIST_LC=`echo $DIST | tr [A-Z] [a-z]` # as lower case
76 0b1832dd Brandon Heller
77 47be38e6 Bob Lantz
78
# Determine whether version $1 >= version $2
79
# usage: if version_ge 1.20 1.2.3; then echo "true!"; fi
80
function version_ge {
81
    # sort -V sorts by *version number*
82
    latest=`printf "$1\n$2" | sort -V | tail -1`
83
    # If $1 is latest version, then $1 >= $2
84
    [ "$1" == "$latest" ]
85
}
86
87
88 0b1832dd Brandon Heller
# Kernel Deb pkg to be removed:
89 65d46518 Bob Lantz
KERNEL_IMAGE_OLD=linux-image-2.6.26-33-generic
90 0b1832dd Brandon Heller
91 85b69adb Bob Lantz
DRIVERS_DIR=/lib/modules/${KERNEL_NAME}/kernel/drivers/net
92 0b1832dd Brandon Heller
93 2a4cbe2f Bob Lantz
OVS_RELEASE=1.4.0
94
OVS_PACKAGE_LOC=https://github.com/downloads/mininet/mininet
95 f85c1cef Bob Lantz
OVS_BUILDSUFFIX=-ignore # was -2
96 2a4cbe2f Bob Lantz
OVS_PACKAGE_NAME=ovs-$OVS_RELEASE-core-$DIST_LC-$RELEASE-$ARCH$OVS_BUILDSUFFIX.tar
97
OVS_TAG=v$OVS_RELEASE
98 0b1832dd Brandon Heller
99 1f07530a Brandon Heller
OF13_SWITCH_REV=${OF13_SWITCH_REV:-""}
100
101 8ee4aa6d Rich Lane
102 0b1832dd Brandon Heller
function kernel {
103 8d1444a9 Bob Lantz
    echo "Install Mininet-compatible kernel if necessary"
104 c120e378 Bob Lantz
    sudo apt-get update
105 2dee3413 Bob Lantz
    $install linux-image-$KERNEL_NAME
106 0b1832dd Brandon Heller
}
107
108
function kernel_clean {
109 c120e378 Bob Lantz
    echo "Cleaning kernel..."
110 0b1832dd Brandon Heller
111 c120e378 Bob Lantz
    # To save disk space, remove previous kernel
112 65d46518 Bob Lantz
    if ! $remove $KERNEL_IMAGE_OLD; then
113
        echo $KERNEL_IMAGE_OLD not installed.
114 de5d3118 Bob Lantz
    fi
115 0b1832dd Brandon Heller
116 c120e378 Bob Lantz
    # Also remove downloaded packages:
117 adf391fd Brian O'Connor
    rm -f $HOME/linux-headers-* $HOME/linux-image-*
118 0b1832dd Brandon Heller
}
119
120
# Install Mininet deps
121
function mn_deps {
122 c120e378 Bob Lantz
    echo "Installing Mininet dependencies"
123 15f2d240 Jose Pedro Oliveira
    if [ "$DIST" = "Fedora" ]; then
124
        $install gcc make socat psmisc xterm openssh-clients iperf \
125
            iproute telnet python-setuptools libcgroup-tools \
126
            ethtool help2man pyflakes pylint python-pep8
127
    else
128
        $install gcc make socat psmisc xterm ssh iperf iproute telnet \
129
            python-setuptools cgroup-bin ethtool help2man \
130
            pyflakes pylint pep8
131
    fi
132 0b1832dd Brandon Heller
133 a0ca68b6 Bob Lantz
    echo "Installing Mininet core"
134 adf391fd Brian O'Connor
    pushd $MININET_DIR/mininet
135 a0ca68b6 Bob Lantz
    sudo make install
136
    popd
137 0b1832dd Brandon Heller
}
138
139 c26b4525 Brian O'Connor
# Install Mininet developer dependencies
140
function mn_dev {
141
    echo "Installing Mininet developer dependencies"
142
    $install doxygen doxypy texlive-fonts-recommended
143
}
144
145 0b1832dd Brandon Heller
# The following will cause a full OF install, covering:
146
# -user switch
147
# The instructions below are an abbreviated version from
148
# http://www.openflowswitch.org/wk/index.php/Debian_Install
149
function of {
150 5507550c Bob Lantz
    echo "Installing OpenFlow reference implementation..."
151 2dee3413 Bob Lantz
    cd $BUILD_DIR
152 6cb05c37 Jose Pedro Oliveira
    $install autoconf automake libtool make gcc
153
    if [ "$DIST" = "Fedora" ]; then
154
        $install git pkgconfig glibc-devel
155
    else
156
        $install git-core autotools-dev pkg-config libc6-dev
157
    fi
158 c120e378 Bob Lantz
    git clone git://openflowswitch.org/openflow.git
159 adf391fd Brian O'Connor
    cd $BUILD_DIR/openflow
160 0b1832dd Brandon Heller
161 0bfd19fe Bob Lantz
    # Patch controller to handle more than 16 switches
162 adf391fd Brian O'Connor
    patch -p1 < $MININET_DIR/mininet/util/openflow-patches/controller.patch
163 0bfd19fe Bob Lantz
164 c120e378 Bob Lantz
    # Resume the install:
165
    ./boot.sh
166
    ./configure
167
    make
168
    sudo make install
169 adf391fd Brian O'Connor
    cd $BUILD_DIR
170 0b1832dd Brandon Heller
}
171
172 5b14cc29 ederlf
function of13 {
173
    echo "Installing OpenFlow 1.3 soft switch implementation..."
174 adf391fd Brian O'Connor
    cd $BUILD_DIR/
175 5b14cc29 ederlf
    $install  git-core autoconf automake autotools-dev pkg-config \
176
        make gcc g++ libtool libc6-dev cmake libpcap-dev libxerces-c2-dev  \
177
        unzip libpcre3-dev flex bison libboost-dev
178
179
    if [ ! -d "ofsoftswitch13" ]; then
180 3e70b01e David Erickson
        git clone https://github.com/CPqD/ofsoftswitch13.git
181
        if [[ -n "$OF13_SWITCH_REV" ]]; then
182
            cd ofsoftswitch13
183
            git checkout ${OF13_SWITCH_REV}
184
            cd ..
185
        fi
186 5b14cc29 ederlf
    fi
187
188
    # Install netbee
189 3582facd Brandon Heller
    NBEESRC="nbeesrc-jan-10-2013"
190 40b13c28 Brandon Heller
    NBEEURL=${NBEEURL:-http://www.nbee.org/download/}
191
    wget -nc ${NBEEURL}${NBEESRC}.zip
192 3582facd Brandon Heller
    unzip ${NBEESRC}.zip
193
    cd ${NBEESRC}/src
194 5b14cc29 ederlf
    cmake .
195
    make
196 adf391fd Brian O'Connor
    cd $BUILD_DIR/
197 3582facd Brandon Heller
    sudo cp ${NBEESRC}/bin/libn*.so /usr/local/lib
198 4b8b4b73 Bob Lantz
    sudo ldconfig
199 3582facd Brandon Heller
    sudo cp -R ${NBEESRC}/include/ /usr/
200 5b14cc29 ederlf
201
    # Resume the install:
202 adf391fd Brian O'Connor
    cd $BUILD_DIR/ofsoftswitch13
203 5b14cc29 ederlf
    ./boot.sh
204
    ./configure
205
    make
206
    sudo make install
207 adf391fd Brian O'Connor
    cd $BUILD_DIR
208 5b14cc29 ederlf
}
209
210 47be38e6 Bob Lantz
211 5507550c Bob Lantz
function wireshark {
212 9ca775cb Bob Lantz
    echo "Installing Wireshark"
213 de268015 Jose Pedro Oliveira
    if [ "$DIST" = "Fedora" ]; then
214
        $install wireshark wireshark-gnome
215 5507550c Bob Lantz
    else
216 9ca775cb Bob Lantz
        $install wireshark tshark
217 5507550c Bob Lantz
    fi
218
219 47be38e6 Bob Lantz
    echo "Checking Wireshark version"
220
    WSVER=`wireshark -v | egrep -o '[0-9\.]+' | head -1`
221
    if version_ge $WSVER 1.12; then
222
        echo "Wireshark version $WSVER >= 1.12 - returning"
223
        return
224
    fi
225
226 9ca775cb Bob Lantz
    echo "Cloning LoxiGen and building openflow.lua dissector"
227
    cd $BUILD_DIR
228
    git clone https://github.com/floodlight/loxigen.git
229
    cd loxigen
230
    make wireshark
231
232
    # Copy into plugin directory
233
    # libwireshark0/ on 11.04; libwireshark1/ on later
234
    WSDIR=`find /usr/lib -type d -name 'libwireshark*' | head -1`
235
    WSPLUGDIR=$WSDIR/plugins/
236
    PLUGIN=loxi_output/wireshark/openflow.lua
237
    sudo cp $PLUGIN $WSPLUGDIR
238
    echo "Copied openflow plugin $PLUGIN to $WSPLUGDIR"
239
240 5507550c Bob Lantz
    # Copy coloring rules: OF is white-on-blue:
241 adf391fd Brian O'Connor
    mkdir -p $HOME/.wireshark
242
    cp $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
243 9ca775cb Bob Lantz
244
    cd $BUILD_DIR
245 0b1832dd Brandon Heller
}
246
247 1902dd2e Bob Lantz
248 4b7b23cf Gregory Gee
# Install Open vSwitch specific version Ubuntu package
249
function ubuntuOvs {
250
    echo "Creating and Installing Open vSwitch packages..."
251
252
    OVS_SRC=$BUILD_DIR/openvswitch
253
    OVS_TARBALL_LOC=http://openvswitch.org/releases
254
255 47be38e6 Bob Lantz
    if [ "$DIST" = "Ubuntu" ] && version_ge $RELEASE 12.04; then
256 4b7b23cf Gregory Gee
        rm -rf $OVS_SRC
257
        mkdir -p $OVS_SRC
258
        cd $OVS_SRC
259
260
        if wget $OVS_TARBALL_LOC/openvswitch-$OVS_RELEASE.tar.gz 2> /dev/null; then
261
            tar xzf openvswitch-$OVS_RELEASE.tar.gz
262
        else
263
            echo "Failed to find OVS at $OVS_TARBALL_LOC/openvswitch-$OVS_RELEASE.tar.gz"
264
            cd $BUILD_DIR
265
            return
266
        fi
267
268
        # Remove any old packages
269
        $remove openvswitch-common openvswitch-datapath-dkms openvswitch-controller \
270
                openvswitch-pki openvswitch-switch
271
272
        # Get build deps
273
        $install build-essential fakeroot debhelper autoconf automake libssl-dev \
274
                 pkg-config bzip2 openssl python-all procps python-qt4 \
275
                 python-zopeinterface python-twisted-conch dkms
276
277
        # Build OVS
278
        cd $BUILD_DIR/openvswitch/openvswitch-$OVS_RELEASE
279
                DEB_BUILD_OPTIONS='parallel=2 nocheck' fakeroot debian/rules binary
280
        cd ..
281
        $pkginst openvswitch-common_$OVS_RELEASE*.deb openvswitch-datapath-dkms_$OVS_RELEASE*.deb \
282
                 openvswitch-pki_$OVS_RELEASE*.deb openvswitch-switch_$OVS_RELEASE*.deb
283
        if $pkginst openvswitch-controller_$OVS_RELEASE*.deb; then
284
            echo "Ignoring error installing openvswitch-controller"
285
        fi
286
287
        modinfo openvswitch
288
        sudo ovs-vsctl show
289
        # Switch can run on its own, but
290
        # Mininet should control the controller
291
        # This appears to only be an issue on Ubuntu/Debian
292
        if sudo service openvswitch-controller stop; then
293
            echo "Stopped running controller"
294
        fi
295
        if [ -e /etc/init.d/openvswitch-controller ]; then
296
            sudo update-rc.d openvswitch-controller disable
297
        fi
298
    else
299
        echo "Failed to install Open vSwitch.  OS must be Ubuntu >= 12.04"
300
            cd $BUILD_DIR
301
            return
302
    fi
303
}
304
305
306 7e79d135 Bob Lantz
# Install Open vSwitch
307 2f8dfe58 Bob Lantz
308 0b1832dd Brandon Heller
function ovs {
309 7e79d135 Bob Lantz
    echo "Installing Open vSwitch..."
310 0b1832dd Brandon Heller
311 2dee3413 Bob Lantz
    if [ "$DIST" == "Fedora" ]; then
312 541ba67d Jose Pedro Oliveira
        $install openvswitch openvswitch-controller
313
        return
314
    fi
315
316 2dee3413 Bob Lantz
    # Manually installing openvswitch-datapath may be necessary
317
    # for manually built kernel .debs using Debian's defective kernel
318
    # packaging, which doesn't yield usable headers.
319
    if ! dpkg --get-selections | grep openvswitch-datapath; then
320
        # If you've already installed a datapath, assume you
321
        # know what you're doing and don't need dkms datapath.
322
        # Otherwise, install it.
323
        $install openvswitch-datapath-dkms
324 5d4d6305 Bob Lantz
    fi
325 0b1832dd Brandon Heller
326 2dee3413 Bob Lantz
    $install openvswitch-switch openvswitch-controller
327 cf9c9687 Bob Lantz
328 82c8bdaf Bob Lantz
    # Switch can run on its own, but
329 2f8dfe58 Bob Lantz
    # Mininet should control the controller
330 2dee3413 Bob Lantz
    # This appears to only be an issue on Ubuntu/Debian
331
    if sudo service openvswitch-controller stop; then
332
        echo "Stopped running controller"
333
    fi
334 2f8dfe58 Bob Lantz
    if [ -e /etc/init.d/openvswitch-controller ]; then
335
        sudo update-rc.d openvswitch-controller disable
336
    fi
337 0b1832dd Brandon Heller
}
338
339 2a4cbe2f Bob Lantz
function remove_ovs {
340 2b261610 Bob Lantz
    pkgs=`dpkg --get-selections | grep openvswitch | awk '{ print $1;}'`
341 2a4cbe2f Bob Lantz
    echo "Removing existing Open vSwitch packages:"
342
    echo $pkgs
343
    if ! $remove $pkgs; then
344
        echo "Not all packages removed correctly"
345
    fi
346
    # For some reason this doesn't happen
347
    if scripts=`ls /etc/init.d/*openvswitch* 2>/dev/null`; then
348
        echo $scripts
349
        for s in $scripts; do
350
            s=$(basename $s)
351
            echo SCRIPT $s
352
            sudo service $s stop
353
            sudo rm -f /etc/init.d/$s
354
            sudo update-rc.d -f $s remove
355
        done
356
    fi
357
    echo "Done removing OVS"
358 0b1832dd Brandon Heller
}
359
360 8ee4aa6d Rich Lane
function ivs {
361 786117dd Bob Lantz
    echo "Installing Indigo Virtual Switch..."
362
363
    IVS_SRC=$BUILD_DIR/ivs
364
365 8ee4aa6d Rich Lane
    # Install dependencies
366
    $install git pkg-config gcc make libnl-3-dev libnl-route-3-dev libnl-genl-3-dev
367
368
    # Install IVS from source
369 786117dd Bob Lantz
    cd $BUILD_DIR
370 7c29c2eb Bob Lantz
    git clone git://github.com/floodlight/ivs $IVS_SRC --recursive
371 8ee4aa6d Rich Lane
    cd $IVS_SRC
372
    make
373
    sudo make install
374
}
375
376 011b02f8 Brandon Heller
# Install NOX with tutorial files
377 0b1832dd Brandon Heller
function nox {
378 c120e378 Bob Lantz
    echo "Installing NOX w/tutorial files..."
379 0b1832dd Brandon Heller
380 c120e378 Bob Lantz
    # Install NOX deps:
381 3cd2e1a6 Bob Lantz
    $install autoconf automake g++ libtool python python-twisted \
382 7e79d135 Bob Lantz
		swig libssl-dev make
383 59d32629 Bob Lantz
    if [ "$DIST" = "Debian" ]; then
384 3cd2e1a6 Bob Lantz
        $install libboost1.35-dev
385 59d32629 Bob Lantz
    elif [ "$DIST" = "Ubuntu" ]; then
386 82c8bdaf Bob Lantz
        $install python-dev libboost-dev
387 3cd2e1a6 Bob Lantz
        $install libboost-filesystem-dev
388
        $install libboost-test-dev
389 5d4d6305 Bob Lantz
    fi
390 c120e378 Bob Lantz
    # Install NOX optional deps:
391 3cd2e1a6 Bob Lantz
    $install libsqlite3-dev python-simplejson
392 0b1832dd Brandon Heller
393 7e79d135 Bob Lantz
    # Fetch NOX destiny
394 adf391fd Brian O'Connor
    cd $BUILD_DIR/
395 ad85e44d Bob
    git clone https://github.com/noxrepo/nox-classic.git noxcore
396 c120e378 Bob Lantz
    cd noxcore
397 ad85e44d Bob
    if ! git checkout -b destiny remotes/origin/destiny ; then
398
        echo "Did not check out a new destiny branch - assuming current branch is destiny"
399
    fi
400 0b1832dd Brandon Heller
401 7e79d135 Bob Lantz
    # Apply patches
402
    git checkout -b tutorial-destiny
403 adf391fd Brian O'Connor
    git am $MININET_DIR/mininet/util/nox-patches/*tutorial-port-nox-destiny*.patch
404 47be38e6 Bob Lantz
    if [ "$DIST" = "Ubuntu" ] && version_ge $RELEASE 12.04; then
405 adf391fd Brian O'Connor
        git am $MININET_DIR/mininet/util/nox-patches/*nox-ubuntu12-hacks.patch
406 b0fb3988 Bob Lantz
    fi
407 7e79d135 Bob Lantz
408
    # Build
409
    ./boot.sh
410 c120e378 Bob Lantz
    mkdir build
411
    cd build
412 7e79d135 Bob Lantz
    ../configure
413
    make -j3
414 c120e378 Bob Lantz
    #make check
415 0b1832dd Brandon Heller
416 c120e378 Bob Lantz
    # Add NOX_CORE_DIR env var:
417 adf391fd Brian O'Connor
    sed -i -e 's|# for examples$|&\nexport NOX_CORE_DIR=$BUILD_DIR/noxcore/build/src|' ~/.bashrc
418 0b1832dd Brandon Heller
419 c120e378 Bob Lantz
    # To verify this install:
420
    #cd ~/noxcore/build/src
421 0b1832dd Brandon Heller
    #./nox_core -v -i ptcp:
422
}
423
424 4b8b4b73 Bob Lantz
# Install NOX Classic/Zaku for OpenFlow 1.3
425 5b14cc29 ederlf
function nox13 {
426
    echo "Installing NOX w/tutorial files..."
427
428
    # Install NOX deps:
429
    $install autoconf automake g++ libtool python python-twisted \
430
        swig libssl-dev make
431
    if [ "$DIST" = "Debian" ]; then
432
        $install libboost1.35-dev
433
    elif [ "$DIST" = "Ubuntu" ]; then
434
        $install python-dev libboost-dev
435
        $install libboost-filesystem-dev
436
        $install libboost-test-dev
437
    fi
438
439
    # Fetch NOX destiny
440 adf391fd Brian O'Connor
    cd $BUILD_DIR/
441 5b14cc29 ederlf
    git clone https://github.com/CPqD/nox13oflib.git
442
    cd nox13oflib
443
444
    # Build
445
    ./boot.sh
446
    mkdir build
447
    cd build
448
    ../configure
449
    make -j3
450
    #make check
451
452
    # To verify this install:
453
    #cd ~/nox13oflib/build/src
454
    #./nox_core -v -i ptcp:
455
}
456
457
458 d4ece25b Bob Lantz
# "Install" POX
459
function pox {
460 adf391fd Brian O'Connor
    echo "Installing POX into $BUILD_DIR/pox..."
461
    cd $BUILD_DIR
462 d4ece25b Bob Lantz
    git clone https://github.com/noxrepo/pox.git
463
}
464
465 011b02f8 Brandon Heller
# Install OFtest
466
function oftest {
467
    echo "Installing oftest..."
468
469 c120e378 Bob Lantz
    # Install deps:
470 3cd2e1a6 Bob Lantz
    $install tcpdump python-scapy
471 011b02f8 Brandon Heller
472 c120e378 Bob Lantz
    # Install oftest:
473 adf391fd Brian O'Connor
    cd $BUILD_DIR/
474 496cd25d Brandon Heller
    git clone git://github.com/floodlight/oftest
475 011b02f8 Brandon Heller
}
476
477
# Install cbench
478
function cbench {
479
    echo "Installing cbench..."
480 82c8bdaf Bob Lantz
481 6cb05c37 Jose Pedro Oliveira
    if [ "$DIST" = "Fedora" ]; then
482
        $install net-snmp-devel libpcap-devel libconfig-devel
483
    else
484
        $install libsnmp-dev libpcap-dev libconfig-dev
485
    fi
486 adf391fd Brian O'Connor
    cd $BUILD_DIR/
487 a6e55e35 Fernando Cappi
    git clone git://gitosis.stanford.edu/oflops.git
488 011b02f8 Brandon Heller
    cd oflops
489 5675f2a1 Bob Lantz
    sh boot.sh || true # possible error in autoreconf, so run twice
490 011b02f8 Brandon Heller
    sh boot.sh
491 adf391fd Brian O'Connor
    ./configure --with-openflow-src-dir=$BUILD_DIR/openflow
492 011b02f8 Brandon Heller
    make
493
    sudo make install || true # make install fails; force past this
494
}
495
496 949e0b3a Bob Lantz
function vm_other {
497 c3f975ae Bob Lantz
    echo "Doing other Mininet VM setup tasks..."
498
499
    # Remove avahi-daemon, which may cause unwanted discovery packets to be
500
    # sent during tests, near link status changes:
501
    echo "Removing avahi-daemon"
502
    $remove avahi-daemon
503
504
    # was: Disable IPv6.  Add to /etc/modprobe.d/blacklist:
505
    #echo "Attempting to disable IPv6"
506
    #if [ "$DIST" = "Ubuntu" ]; then
507
    #    BLACKLIST=/etc/modprobe.d/blacklist.conf
508
    #else
509
    #    BLACKLIST=/etc/modprobe.d/blacklist
510
    #fi
511
    #sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
512
513
    # Disable IPv6
514
    if ! grep 'disable IPv6' /etc/sysctl.conf; then
515
        echo 'Disabling IPv6'
516
        echo '
517
# Mininet: disable IPv6
518
net.ipv6.conf.all.disable_ipv6 = 1
519
net.ipv6.conf.default.disable_ipv6 = 1
520 7bc10ebc Bob Lantz
net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
521
    fi
522
    # Disabling IPv6 breaks X11 forwarding via ssh
523
    line='AddressFamily inet'
524
    file='/etc/ssh/sshd_config'
525
    echo "Adding $line to $file"
526
    if ! grep "$line" $file > /dev/null; then
527
        echo "$line" | sudo tee -a $file > /dev/null
528 c3f975ae Bob Lantz
    fi
529 0b1832dd Brandon Heller
530 c120e378 Bob Lantz
    # Enable command auto completion using sudo; modify ~/.bashrc:
531
    sed -i -e 's|# for examples$|&\ncomplete -cf sudo|' ~/.bashrc
532 0b1832dd Brandon Heller
533 c3f975ae Bob Lantz
    # Install tcpdump, cmd-line packet dump tool.  Also install gitk,
534 c120e378 Bob Lantz
    # a graphical git history viewer.
535 c3f975ae Bob Lantz
    $install tcpdump gitk
536 0b1832dd Brandon Heller
537 c120e378 Bob Lantz
    # Install common text editors
538 3cd2e1a6 Bob Lantz
    $install vim nano emacs
539 3b48e829 Brandon Heller
540 c120e378 Bob Lantz
    # Install NTP
541 3cd2e1a6 Bob Lantz
    $install ntp
542 3b48e829 Brandon Heller
543 c120e378 Bob Lantz
    # Set git to colorize everything.
544
    git config --global color.diff auto
545
    git config --global color.status auto
546
    git config --global color.branch auto
547 0b1832dd Brandon Heller
548 c120e378 Bob Lantz
    # Reduce boot screen opt-out delay. Modify timeout in /boot/grub/menu.lst to 1:
549 01eea350 Bob Lantz
    if [ "$DIST" = "Debian" ]; then
550
        sudo sed -i -e 's/^timeout.*$/timeout         1/' /boot/grub/menu.lst
551
    fi
552 0b1832dd Brandon Heller
553 32b122bf Brandon Heller
    # Clean unneeded debs:
554
    rm -f ~/linux-headers-* ~/linux-image-*
555 fc48e6ee Brandon Heller
}
556
557 011b02f8 Brandon Heller
# Script to copy built OVS kernel module to where modprobe will
558 0b1832dd Brandon Heller
# find them automatically.  Removes the need to keep an environment variable
559 011b02f8 Brandon Heller
# for insmod usage, and works nicely with multiple kernel versions.
560 0b1832dd Brandon Heller
#
561 011b02f8 Brandon Heller
# The downside is that after each recompilation of OVS you'll need to
562 0b1832dd Brandon Heller
# re-run this script.  If you're using only one kernel version, then it may be
563
# a good idea to use a symbolic link in place of the copy below.
564
function modprobe {
565 c120e378 Bob Lantz
    echo "Setting up modprobe for OVS kmod..."
566 7e87dbaa Brian O'Connor
    set +o nounset
567
    if [ -z "$OVS_KMODS" ]; then
568
      echo "OVS_KMODS not set. Aborting."
569
    else
570
      sudo cp $OVS_KMODS $DRIVERS_DIR
571
      sudo depmod -a ${KERNEL_NAME}
572
    fi
573
    set -o nounset
574 0b1832dd Brandon Heller
}
575
576
function all {
577 5b08af2e Jose Pedro Oliveira
    if [ "$DIST" = "Fedora" ]; then
578 04578241 Jose Pedro Oliveira
        printf "\nFedora 18+ support (still work in progress):\n"
579
        printf " * Fedora 18+ has kernel 3.10 RPMS in the updates repositories\n"
580
        printf " * Fedora 18+ has openvswitch 1.10 RPMS in the updates repositories\n"
581
        printf " * the install.sh script options [-bfnpvw] should work.\n"
582
        printf " * for a basic setup just try:\n"
583
        printf "       install.sh -fnpv\n\n"
584 5b08af2e Jose Pedro Oliveira
        exit 3
585
    fi
586 40a9c153 Bob Lantz
    echo "Installing all packages except for -eix (doxypy, ivs, nox-classic)..."
587 8d1444a9 Bob Lantz
    kernel
588 c120e378 Bob Lantz
    mn_deps
589 40a9c153 Bob Lantz
    # Skip mn_dev (doxypy/texlive/fonts/etc.) because it's huge
590
    # mn_dev
591 c120e378 Bob Lantz
    of
592 1902dd2e Bob Lantz
    wireshark
593 c120e378 Bob Lantz
    ovs
594 40a9c153 Bob Lantz
    # We may add ivs once it's more mature
595
    # ivs
596 d4ece25b Bob Lantz
    # NOX-classic is deprecated, but you can install it manually if desired.
597
    # nox
598
    pox
599 c120e378 Bob Lantz
    oftest
600
    cbench
601
    echo "Enjoy Mininet!"
602 0b1832dd Brandon Heller
}
603
604
# Restore disk space and remove sensitive files before shipping a VM.
605
function vm_clean {
606 c120e378 Bob Lantz
    echo "Cleaning VM..."
607
    sudo apt-get clean
608 8f113b48 Bob Lantz
    sudo apt-get autoremove
609 c120e378 Bob Lantz
    sudo rm -rf /tmp/*
610
    sudo rm -rf openvswitch*.tar.gz
611
612
    # Remove sensistive files
613
    history -c  # note this won't work if you have multiple bash sessions
614
    rm -f ~/.bash_history  # need to clear in memory and remove on disk
615
    rm -f ~/.ssh/id_rsa* ~/.ssh/known_hosts
616
    sudo rm -f ~/.ssh/authorized_keys*
617
618
    # Remove Mininet files
619
    #sudo rm -f /lib/modules/python2.5/site-packages/mininet*
620
    #sudo rm -f /usr/bin/mnexec
621
622
    # Clear optional dev script for SSH keychain load on boot
623
    rm -f ~/.bash_profile
624
625
    # Clear git changes
626
    git config --global user.name "None"
627
    git config --global user.email "None"
628
629 5c5a1eae Bob Lantz
    # Note: you can shrink the .vmdk in vmware using
630
    # vmware-vdiskmanager -k *.vmdk
631 2de621cd Bob Lantz
    echo "Zeroing out disk blocks for efficient compaction..."
632 5c5a1eae Bob Lantz
    time sudo dd if=/dev/zero of=/tmp/zero bs=1M
633
    sync ; sleep 1 ; sync ; sudo rm -f /tmp/zero
634 8f113b48 Bob Lantz
635 0b1832dd Brandon Heller
}
636
637
function usage {
638 4b7b23cf Gregory Gee
    printf '\nUsage: %s [-abcdfhikmnprtvVwx03]\n\n' $(basename $0) >&2
639 82c8bdaf Bob Lantz
640 01eea350 Bob Lantz
    printf 'This install script attempts to install useful packages\n' >&2
641 eca5a151 Bob Lantz
    printf 'for Mininet. It should (hopefully) work on Ubuntu 11.10+\n' >&2
642
    printf 'If you run into trouble, try\n' >&2
643 01eea350 Bob Lantz
    printf 'installing one thing at a time, and looking at the \n' >&2
644
    printf 'specific installation function in this script.\n\n' >&2
645 7e79d135 Bob Lantz
646 01eea350 Bob Lantz
    printf 'options:\n' >&2
647
    printf -- ' -a: (default) install (A)ll packages - good luck!\n' >&2
648 c2e14519 Bob Lantz
    printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
649 01eea350 Bob Lantz
    printf -- ' -c: (C)lean up after kernel install\n' >&2
650 82c8bdaf Bob Lantz
    printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2
651 786117dd Bob Lantz
    printf -- ' -e: install Mininet d(E)veloper dependencies\n' >&2
652
    printf -- ' -f: install Open(F)low\n' >&2
653 01eea350 Bob Lantz
    printf -- ' -h: print this (H)elp message\n' >&2
654 786117dd Bob Lantz
    printf -- ' -i: install (I)ndigo Virtual Switch\n' >&2
655 01eea350 Bob Lantz
    printf -- ' -k: install new (K)ernel\n' >&2
656 e5b54a31 Bob Lantz
    printf -- ' -m: install Open vSwitch kernel (M)odule from source dir\n' >&2
657 786117dd Bob Lantz
    printf -- ' -n: install Mini(N)et dependencies + core files\n' >&2
658 eca5a151 Bob Lantz
    printf -- ' -p: install (P)OX OpenFlow Controller\n' >&2
659 2a4cbe2f Bob Lantz
    printf -- ' -r: remove existing Open vSwitch packages\n' >&2
660 786117dd Bob Lantz
    printf -- ' -s <dir>: place dependency (S)ource/build trees in <dir>\n' >&2
661 949e0b3a Bob Lantz
    printf -- ' -t: complete o(T)her Mininet VM setup tasks\n' >&2
662 786117dd Bob Lantz
    printf -- ' -v: install Open (V)switch\n' >&2
663 4b7b23cf Gregory Gee
    printf -- ' -V <version>: install a particular version of Open (V)switch on Ubuntu\n' >&2
664 786117dd Bob Lantz
    printf -- ' -w: install OpenFlow (W)ireshark dissector\n' >&2
665 4b8b4b73 Bob Lantz
    printf -- ' -x: install NO(X) Classic OpenFlow controller\n' >&2
666
    printf -- ' -0: (default) -0[fx] installs OpenFlow 1.0 versions\n' >&2
667
    printf -- ' -3: -3[fx] installs OpenFlow 1.3 versions\n' >&2
668 0b1832dd Brandon Heller
    exit 2
669
}
670
671 4b8b4b73 Bob Lantz
OF_VERSION=1.0
672
673 0b1832dd Brandon Heller
if [ $# -eq 0 ]
674
then
675 c120e378 Bob Lantz
    all
676 0b1832dd Brandon Heller
else
677 4b7b23cf Gregory Gee
    while getopts 'abcdefhikmnprs:tvV:wx03' OPTION
678 c120e378 Bob Lantz
    do
679
      case $OPTION in
680
      a)    all;;
681
      b)    cbench;;
682
      c)    kernel_clean;;
683
      d)    vm_clean;;
684 786117dd Bob Lantz
      e)    mn_dev;;
685 4b8b4b73 Bob Lantz
      f)    case $OF_VERSION in
686 5b14cc29 ederlf
            1.0) of;;
687
            1.3) of13;;
688 4b8b4b73 Bob Lantz
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
689 5b14cc29 ederlf
            esac;;
690 c120e378 Bob Lantz
      h)    usage;;
691 8ee4aa6d Rich Lane
      i)    ivs;;
692 c120e378 Bob Lantz
      k)    kernel;;
693
      m)    modprobe;;
694
      n)    mn_deps;;
695 d4ece25b Bob Lantz
      p)    pox;;
696 2a4cbe2f Bob Lantz
      r)    remove_ovs;;
697 786117dd Bob Lantz
      s)    mkdir -p $OPTARG; # ensure the directory is created
698
            BUILD_DIR="$( cd -P "$OPTARG" && pwd )"; # get the full path
699
            echo "Dependency installation directory: $BUILD_DIR";;
700 949e0b3a Bob Lantz
      t)    vm_other;;
701 c120e378 Bob Lantz
      v)    ovs;;
702 4b7b23cf Gregory Gee
      V)    OVS_RELEASE=$OPTARG;
703
            ubuntuOvs;;
704 1902dd2e Bob Lantz
      w)    wireshark;;
705 4b8b4b73 Bob Lantz
      x)    case $OF_VERSION in
706
            1.0) nox;;
707
            1.3) nox13;;
708
            *)  echo "Invalid OpenFlow version $OF_VERSION";;
709
            esac;;
710
      0)    OF_VERSION=1.0;;
711
      3)    OF_VERSION=1.3;;
712 c120e378 Bob Lantz
      ?)    usage;;
713
      esac
714
    done
715
    shift $(($OPTIND - 1))
716 0b1832dd Brandon Heller
fi