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