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