auto-pelab.tm 26.8 KB
Newer Older
Mike Hibler's avatar
Mike Hibler committed
1 2
#
# Copyright (c) 2006 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Mike Hibler's avatar
Mike Hibler committed
22 23
#

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 81 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 126 127 128 129
source tb_compat.tcl

set ns [new Simulator]
$ns rtproto Static

##########
# Beginning of user-settable parameters

#
# If set to 1, doesn't allocate any real Plab nodes (or fake ones either).
# Attributes for the elab-* machines are taken from DB data for nodes in
# the plabnodes list.
#
# This option requires that you have nodes listed in plabnodes and forces
# use of the dbmonitor.
#
$ns define-template-parameter NO_PLAB 0 \
{If non-zero, do not allocate any real PlanetLab nodes\
 rather initialize elab characteristics from nodes in the $plabnodes list. }

#
# This control how many _pairs_ of PCs there are. ie. 2 gets you 2 monitors,
# plus matching stubs
#
$ns define-template-parameter NUM_PCS 3 \
{The number of *pairs* of nodes in the experiment.\
 Example: '2' would allocate 2 Emulab nodes in the 'elabc' cloud,\
 along with either or both of 2 Plab nodes and 2 Emulab nodes\
 in the 'plabc' cloud. }

#
# If set to 1, we create a fake PlanetLab inside Emulab
#
$ns define-template-parameter FAKE_PLAB 0 \
{If non-zero, allocate a cloud of Emulab machines to emulate Plab nodes. }

#
# If set to 1, we grab real PlanetLab nodes. Both this and FAKE_PLAB can be
# set at the same time
#
$ns define-template-parameter REAL_PLAB 1 \
{If non-zero, use real PlanetLab nodes.\
 NOTE: can be combined with FAKE_PLAB. }

#
# Run FreeBSD 6.1 on elab_ nodes.  Forces use of dbmonitor.
#
$ns define-template-parameter DO_BSD 0 \
{If non-zero, run FreeBSD 6.1 instead of Fedora Core 2 on elab nodes.\
 NOTE: Forces use of dbmonitor. }

#
# If set to 1, we trace all links (real/fake plab, elab) at the delay nodes.
#
$ns define-template-parameter TRACE 1 \
{If non-zero, run Emulab link tracing on all links\
 (real and fake plab, elab). }

#
# If set to 1, we trace on all end nodes instead of (or in addition to)
# all delay nodes above.
#
# XXX this option won't do anything right now.  If there are delay nodes
# involved for local LAN/clouds it is ignored, and as long as tracing is
# enabled, plab nodes will get end_node tracing anyway.
#
$ns define-template-parameter TRACE_END_NODES 0 \
{If non-zero, perform link tracing on the end nodes instead of\
 (or in addition to) on the delay nodes.\
  NOTE: This option doesn't do anything right now. }

#
# If you want to get specific real planetlab nodes, ask for them here by site
# or by emulab node ID. 
# NOTES:
#   An empty list for either selection method turns it off
#   Do not use both site and node selection at the same time!
#   The list must be at least as long as NUM_PCS above, It can be longer, but
#     extra elements will be ignored
#   I recommend using the sites option, rather than the nodes option, since that
#     may get you less-loaded nodes and is more robust to crashed nodes
#   You can get a list of node IDs and sites at:
#     https://www.emulab.net/nodecontrol_list.php3?showtype=widearea
#   Site names are case-sensitive!
#

# Empty list
$ns define-template-parameter PLABSITES {} \
{List of specific PlanetLab sites to use for node selection.\
 Leave empty to let the system choose.\
 NOTE: do not use both plabnodes and PLABSITES at the same time.\
 NOTE: You can get a list of node IDs and sites at:\
     https://www.emulab.net/nodecontrol_list.php3?showtype=widearea\
 NOTE: site names are case-sensitive. }
# Example site list
#set PLABSITES {UCB Stanford Cornell Jerusalem Taiwan}

# Empty list
$ns define-template-parameter PLABNODES {} \
{List of specific PlanetLab nodes to use.\
 Leave empty to let the system choose.\
 NOTE: must specify at least NUM_PCS nodes in the list if NO_PLAB is non-zero.\
 NOTE: do not use both plabnodes and PLABSITES at the same time.\
 NOTE: You can get a list of node IDs and sites at:\
     https://www.emulab.net/nodecontrol_list.php3?showtype=widearea }
# Example node list
130
#set PLABNODES {plab518 plab541 plab628 plab736 plab360}
131

132 133 134 135 136 137 138 139 140 141
# Empty List
$ns define-template-parameter SKIPLIST {} \
{Node numbers to ignore.  For example "2 7"}
# Example list
#set SKIPLIST {2 7}

for {set i 0} {$i < [llength $SKIPLIST]} {incr i} {
    set skip([lindex $SKIPLIST $i]) 1
}

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 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
#
# Where to grab your tarball of pelab software from. To make this tarball:
#   Go to your testbed source tree
#   Run 'cvs up'!!!
#   Run 'gmake' in pelab/stub and pelab/libnetmon (on a DEVBOX node)
#   From the root of your source tree, run:
#       tar czvf /proj/tbres/my-pelab.tar.gz pelab
#   Of course, don't name it 'my-plab.tar.gz'! You can put this file in
#       a subdirectory if you want, but it must be somewhere in
#       /proj/tbres/
#   Put the path to your tarball in this variable
#
$ns define-template-parameter PELAB_TAR "/proj/tbres/tarfiles/pelab.tar.gz" \
{Tarball of pelab software.\
 NOTE: To make this tarball:\
   (1) Go to your testbed source tree,\
   (2) Run 'cvs up',\
   (3) Run 'gmake' in pelab/magent, pelab/stub and pelab/libnetmon\
       (on a DEVBOX node)\
 From the root of your source tree, run:\
   tar czvf /proj/tbres/my-pelab.tar.gz pelab\
 Of course, don't name it 'my-plab.tar.gz'. You can put this file in\
    a subdirectory if you want, but it must be somewhere in /proj/tbres/\
 Put the path to your tarball in this variable. }
#set PELAB_TAR "/proj/tbres/mike/pelab-bin.tar.gz"


#
# When using a fake plab, these are the parameters for the fake Internet
# 'cloud' connecting the plab nodes. For now, all nodes have the same
# parameters - hopefully this will change in a later version
#
$ns define-template-parameter CLOUD_DELAY "30ms" \
{Initial one-way delay for the fake plab ('plabc') cloud.\
 NOTE: only used if fake_plab is non-zero. }
$ns define-template-parameter CLOUD_BW "1.5Mbps" \
{Initial bandwidth for the fake plab ('plabc') cloud.\
 NOTE: only used if fake_plab is non-zero. }

#
# When using a fake plab, these are the parameters for the 'control'
# delay (ie. the latency for the elab nodes to reach the plab nodes
#
$ns define-template-parameter CONTROL_DELAY "0ms" \
{Delay for control network between fake Plab and elab nodes.\
 NOTE: only used if fake_plab is non-zero. }
$ns define-template-parameter CONTROL_BW "100Mbps" \
{Bandwidth for control network between fake Plab and elab nodes.\
 NOTE: only used if fake_plab is non-zero. }

#
# These are the initial conditions for the 'elabc' cloud, the Emulab side of
# a pelab experiment
#
$ns define-template-parameter ECLOUD_DELAY "0ms" \
{Initial one-way delay for the 'elabc' cloud. }
$ns define-template-parameter ECLOUD_BW "100Mbps" \
{Initial bandwidth for the 'elabc' cloud. }

#
# Hardare type to use for PCs inside of emulab
#
$ns define-template-parameter HWTYPE "pc" \
{Emulab node type to use for nodes allocated in both\
 'elabc' and 'plabc' clouds. }

#
# Server and client to use for automated testing. If set, will automatically
# be started by the 'start-experiment' script
#
if {$DO_BSD} {
    set sstr "/usr/local/etc/emulab/emulab-iperf -s "
    # NOTE: No client support for now, you'll have to run the client yourself
    set cstr "/usr/local/etc/emulab/emulab-iperf -t 60 -c "
} else {
    set sstr "/usr/bin/iperf -s "
    # NOTE: No client support for now, you'll have to run the client yourself
    set cstr "/usr/bin/iperf -t 60 -c "
}
$ns define-template-parameter SERVERPROG $sstr \
Mike Hibler's avatar
Mike Hibler committed
222 223
{Server program to run automatically on all elab nodes.\
 Set to the NULL string to disable. }
224
$ns define-template-parameter CLIENTPROG $cstr \
Mike Hibler's avatar
Mike Hibler committed
225
{Client to run automatically on elab nodes.\
226 227
 NOTE: not supported currently. }

Mike Hibler's avatar
Mike Hibler committed
228 229 230
$ns define-template-parameter ALLNODESPROG "/bin/true" \
{Application to run automatically on all nodes.}

231 232 233 234 235 236 237
#
# If non-zero, uses the new stub (magent) instead of the old one
#
$ns define-template-parameter USE_MAGENT 1 \
{If non-zero, uses the new stub (magent)\
 instead of the old one on plab nodes. }

238 239 240 241 242 243 244 245
#
# If non-zero, start an iperfd process to receive traffic that would
# otherwise go to the stub.
#
$ns define-template-parameter MAGENT_NORECV 0 \
{If non-zero, turn off receiving traffic in the stub\
 (an iperfd process is started to do it instead). }

246 247 248 249 250 251 252 253 254 255 256
#
# If non-zero, uses the DB-based "monitor" to control the cloud shaping
#
set val 0
if {$DO_BSD} {
    set val 1
}
$ns define-template-parameter USE_DBMONITOR $val \
{If non-zero, uses the DB-based "monitor"\
 (rather than the application monitor) to control the cloud shaping. }

257
#
258 259 260 261
# If dbmonitor is set, these are the intervals at which the latency and BW
# data are sampled by bgmon on the plab nodes.  The smaller (shorter interval)
# of the two, is used as the interval at which dbmonitor polls the DB to get
# data recorded by bgmon.
262
#
263 264 265 266 267 268 269 270 271 272 273
$ns define-template-parameter DBMONITOR_LATINTERVAL 10 \
{If USE_DBMONITOR is non-zero, the interval in seconds at which DB latency\
 data is updated by bgmon for use by the DB monitor.  The DB monitor queries\
 the database using the smaller of this and the DBMONITOR_BWINTERVAL values.\
 Uses the default value if set to zero here. }

$ns define-template-parameter DBMONITOR_BWINTERVAL 0 \
{If USE_DBMONITOR is non-zero, the interval in seconds at which DB bandwidth\
 data is updated by bgmon for use by the DB monitor.  The DB monitor queries\
 the database using the smaller of this and the DBMONITOR_LATINTERVAL values.\
 Uses the default value if set to zero here. }
274

275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
#
# If non-zero, limits the number of slots in the queues for the fake PlanetLab
#
$ns define-template-parameter LIMIT_FAKE_QUEUE_SLOTS 0 \
{If non-zero, limits the size of the dummynet queues used\
 for the fake Plab cloud to the given value.\
 NOTE: default queue size is 50 packets. }

#
# Use this to set a unique port so that you don't collide with others on the
# same node. Only supported when USE_MAGENT is 1
#
$ns define-template-parameter STUB_PORT 3149 \
{TCP port number to use for the new stub (magent).\
 Change to avoid collisions with others on the same node.\
 NOTE: only used when USE_MAGENT is non-zero. }

Mike Hibler's avatar
Mike Hibler committed
292 293 294
# XXX for internal use only
set NO_STUB 0

295 296 297 298 299 300
#
# Enforce NO_PLAB requirements
#
if {$NO_PLAB} {
    set FAKE_PLAB 0
    set REAL_PLAB 0
301 302 303
# XXX don't force use of dbmonitor; may want to just use init_elabnodes.
#    set USE_DBMONITOR 1
    set NO_STUB 1
304 305
}

Mike Hibler's avatar
Mike Hibler committed
306 307 308 309 310 311 312 313
#
# Enforce USE_DBMONITOR requirements
#
if {$USE_DBMONITOR} {
    set USE_MAGENT 0
    set NO_STUB 1
}

314 315 316
# End of user-settable options
##########

317 318 319
set pid ${GLOBALS::pid}
set eid ${GLOBALS::eid}

320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
set delay_os FBSD54-DNODE

if {$DO_BSD} {
    set node_os FBSD61-STD
} else {
    # XXX -UPDATE for now.  Contains bug fixes (progagent command lines).
    set node_os PLAB-DEVBOX-UPDATE
    #set node_os PLAB-DEVBOX
}

tb-set-delay-os $delay_os

set stub_peer_port $STUB_PORT
set stub_command_port [expr $STUB_PORT + 1]

#
# Tarballs and RPMs we install on all nodes
#
set tarfiles "/local $PELAB_TAR"
set plab_rpms "/proj/tbres/auto-pelab/libpcap-0.8.3-3.i386.rpm /proj/tbres/auto-pelab/iperf-2.0.2-1.1.fc2.rf.i386.rpm"
if {$DO_BSD} {
    set elab_rpms ""
} else {
    set elab_rpms "/proj/tbres/auto-pelab/libpcap-0.8.3-3.i386.rpm /proj/tbres/auto-pelab/iperf-2.0.2-1.1.fc2.rf.i386.rpm"
}

if {$DO_BSD} {
    set elabshell "/bin/sh -T"
} else {
    set elabshell "/bin/sh"
}

if {$USE_MAGENT} {
    set stubcommand "/bin/sh /local/pelab/magent/auto-magent.sh --peerserverport=$stub_peer_port --monitorserverport=$stub_command_port"
} else {
    set stubcommand "/bin/sh /local/pelab/stub/auto-stub.sh"
}
357 358 359

# we don't run dbmonitor on the nodes anymore
if {0 && $USE_DBMONITOR} {
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
    set moncommand "$elabshell /local/pelab/dbmonitor/auto-dbmonitor.sh"
} else {
    set moncommand "$elabshell /local/pelab/monitor/auto-monitor.sh --stub-port=$stub_command_port"
}

#
# So far, nothing I tried can get the auto-* scripts to return 0
# when interrupted
#
set ecode 15

set elan_string ""
set plan_string ""
set inet_string ""

set stublist {}
set planetstublist {}
set plabstublist {}
set monitorlist {}
set planetservers {}
set serverlist {}
set clientlist {}
set tflist {}
Mike Hibler's avatar
Mike Hibler committed
383
set anlist {}
384 385 386 387 388

#
# Create all of the nodes
#
set tfix 1
Mike Hibler's avatar
Mike Hibler committed
389
set anix 1
390 391
for {set i 1} {$i <= $NUM_PCS} {incr i} {

392
    if {$REAL_PLAB && ![info exists skip($i)]} {
393 394 395 396 397 398 399 400 401
        set planet($i) [$ns node]
        tb-set-hardware $planet($i) pcplab
        append inet_string "$planet(${i}) "
        set planetstub($i) [$planet($i) program-agent -expected-exit-code $ecode -command $stubcommand]
        lappend stublist $planetstub($i)
        lappend planetstublist $planetstub($i)

        tb-set-node-tarfiles $planet($i) $tarfiles
        tb-set-node-rpms $planet($i) $plab_rpms
Mike Hibler's avatar
Mike Hibler committed
402

403 404 405
        set tfupdate($tfix) [$planet($i) program-agent -command "sudo /usr/local/etc/emulab/update -it"]
	lappend tflist $tfupdate($tfix)
	incr tfix
Mike Hibler's avatar
Mike Hibler committed
406 407 408
	set allnodes($anix) [$planet($i) program-agent -command $ALLNODESPROG]
	lappend anlist $allnodes($anix)
	incr anix
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432

        if {[llength $PLABSITES] > 0} {
            set why_doesnt_tcl_have_concat "*&"
            append why_doesnt_tcl_have_concat [lindex $PLABSITES [expr $i - 1]]
            $planet($i) add-desire $why_doesnt_tcl_have_concat 1.0
        } elseif {[llength $PLABNODES] > 0} {
            tb-fix-node $planet($i) [lindex $PLABNODES [expr $i - 1]]
        }
    }

    if {$FAKE_PLAB} {
        set plab($i) [$ns node]
        tb-set-node-os $plab($i) $node_os
        tb-set-hardware $plab($i) $HWTYPE
        append plan_string "$plab(${i}) "
        set plabstub($i) [$plab($i) program-agent -expected-exit-code $ecode -command $stubcommand]
        lappend stublist $plabstub($i)
        lappend plabstublist $plabstub($i)

        tb-set-node-tarfiles $plab($i) $tarfiles
        tb-set-node-rpms $plab($i) $plab_rpms
        set tfupdate($tfix) [$plab($i) program-agent -command "sudo /usr/local/etc/emulab/update -it"]
	lappend tflist $tfupdate($tfix)
	incr tfix
Mike Hibler's avatar
Mike Hibler committed
433 434 435
	set allnodes($anix) [$plab($i) program-agent -command $ALLNODESPROG]
	lappend anlist $allnodes($anix)
	incr anix
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
    }

    set elab($i) [$ns node]
    tb-set-node-os $elab($i) $node_os
    tb-set-hardware $elab($i) $HWTYPE
    append elan_string "$elab(${i}) "
    set monitor($i) [$elab($i) program-agent -expected-exit-code $ecode -command $moncommand]
    lappend monitorlist $monitor($i)

    set server($i) [$elab($i) program-agent -expected-exit-code $ecode -command $SERVERPROG]
    set client($i) [$elab($i) program-agent -expected-exit-code $ecode -command $CLIENTPROG]
    lappend serverlist $server($i)
    lappend clientlist $client($i)

    tb-set-node-tarfiles $elab($i) $tarfiles
    if {$elab_rpms != ""} {
        tb-set-node-rpms $elab($i) $elab_rpms
    }
    set tfupdate($tfix) [$elab($i) program-agent -command "sudo /usr/local/etc/emulab/update -it"]
    lappend tflist $tfupdate($tfix)
    incr tfix
Mike Hibler's avatar
Mike Hibler committed
457 458 459
    set allnodes($anix) [$elab($i) program-agent -command $ALLNODESPROG]
    lappend anlist $allnodes($anix)
    incr anix
460 461 462 463 464 465

    #
    # If the user has given a PLABNODES list, we set up $opt variables so that
    # even if they are not actually using PlanetLab nodes, the simple model can
    # still see the mapping between elab and plab nodes
    #
466
    if {[llength $PLABNODES] > 0 && ![info exists skip($i)]} {
467 468 469 470
        set opt(pelab-elab-$i-mapping) [lindex $PLABNODES [expr $i - 1]]
    }
}

471 472
#
# Run the DB monitor on ops
473
# Intervals are passed via the environment.
474 475 476 477
#
if {$USE_DBMONITOR} {
    set dbmonitor [new Program $ns]
    $dbmonitor set node "ops"
478
    $dbmonitor set command "/usr/testbed/sbin/dbmonitor.pl $pid $eid"
479
    $dbmonitor set expected-exit-code $ecode
480 481 482
    set monitorlist $dbmonitor
}

483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
#
# Set up groups to make it easy for us to start/stop program agents
#
if {$stublist != {}} {
    set stubgroup [$ns event-group $stublist]
    if {$REAL_PLAB} {
        set planetstubs [$ns event-group $planetstublist]
    }
    if {$FAKE_PLAB} {
        set plabstubs [$ns event-group $plabstublist]
    }
}
set monitorgroup [$ns event-group $monitorlist]

set allservers [$ns event-group $serverlist]
set allclients [$ns event-group $clientlist]

set tfhosts [$ns event-group $tflist]
Mike Hibler's avatar
Mike Hibler committed
501
set anhosts [$ns event-group $anlist]
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585

set tracelist {}

#
# Real Internet cloud for real plab nodes
#
if {$REAL_PLAB} {
    set realinternet [$ns make-lan "$inet_string" 100Mbps 0ms]
    tb-set-lan-protocol $realinternet ipv4
    if {$TRACE} {
	$realinternet trace header "tcp and port $stub_peer_port"
	if {$TRACE_END_NODES} {
	    $realinternet trace_endnode 1
	}
	lappend tracelist $realinternet
    }
}

#
# Fake 'Internet' cloud for fake plab nodes
#
if {$FAKE_PLAB} {
    set plabc [$ns make-cloud "$plan_string" $CLOUD_BW $CLOUD_DELAY]
    tb-set-ip-lan $plab(1) $plabc 10.1.0.1
    if {$TRACE} {
	$plabc trace
	if {$TRACE_END_NODES} {
	    $plabc trace_endnode 1
	}
	lappend tracelist $plabc
    }
    if {$LIMIT_FAKE_QUEUE_SLOTS} {
        for {set i 1} {$i <= $NUM_PCS} {incr i} {
            set fakequeues($i) [[$ns lanlink $plabc $plab($i)] queue]
            $fakequeues($i) set limit_ $LIMIT_FAKE_QUEUE_SLOTS
        }
    }
}

#
# Lan which will be controlled by the monitor
#
set elabc [$ns make-cloud "$elan_string" $ECLOUD_BW $ECLOUD_DELAY]
tb-set-ip-lan $elab(1) $elabc 10.0.0.1
if {$TRACE} {
    $elabc trace
    if {$TRACE_END_NODES} {
	$elabc trace_endnode 1
    }
    lappend tracelist $elabc
}

#
# We don't want the sync server to end up out there on some plab node
#
tb-set-sync-server $elab(1)

#
# Set up a fake Internet link between the PlanetLab and Emulab sides
# when using fake plab nodes
#
if {$FAKE_PLAB} {
    set erouter [$ns node]
    set prouter [$ns node]

    set elabcontrol [$ns make-lan "$elan_string $erouter" 100Mbps 0ms]
    set plabcontrol [$ns make-lan "$plan_string $prouter" 100Mbps 0ms]

    set internet [$ns duplex-link $erouter $prouter $CONTROL_BW $CONTROL_DELAY DropTail]
    if {$TRACE} {
	$internet trace
	if {$TRACE_END_NODES} {
	    $internet trace_endnode 1
	}
	lappend tracelist $internet
    }

    tb-set-ip-lan $elab(1) $elabcontrol 192.168.0.1
    tb-set-ip-lan $plab(1) $plabcontrol 192.168.1.1

    tb-set-ip-link $erouter $internet 192.168.254.1
    tb-set-ip-link $prouter $internet 192.168.254.2
}

586
# for one-off ops commands
587 588 589 590 591 592 593 594 595 596 597 598 599
set opsagent [new Program $ns]
$opsagent set node "ops"
$opsagent set command "/bin/true"

#
# The set of traced links
# XXX still cannot use an event-group of link tracing events in a sequence
#
#set tracegroup [$ns event-group $tracelist]

#
# Build up the event sequences to start and stop an actual run.
#
600
if {$NO_PLAB || $REAL_PLAB} {
601 602
  set start_real [$ns event-sequence]
    $start_real append "$ns log \"Starting REAL plab experiment\""
603 604

    # stop stubs and monitors
605
    $start_real append "$ns log \"##### Stopping stubs and monitors...\""
Mike Hibler's avatar
Mike Hibler committed
606
    if {!$NO_STUB && $REAL_PLAB} {
607
	$start_real append "$planetstubs stop"
608
    }
609
    $start_real append "$monitorgroup stop"
610 611

    # stop servers
Mike Hibler's avatar
Mike Hibler committed
612
    if {$SERVERPROG != ""} {
613 614
	$start_real append "$ns log \"##### Stopping servers...\""
	$start_real append "$allservers stop"
Mike Hibler's avatar
Mike Hibler committed
615
    }
616 617

    # stop link logging
618
    $start_real append "$ns log \"##### Roll link trace logs...\""
619
    foreach link $tracelist {
620 621
        $start_real append "$link trace snapshot"
        $start_real append "$link trace stop"
622 623 624 625
    }

    # clean out log files
    # XXX original script passed --root, cleanlogs does not--may be a problem.
626 627
    $start_real append "$ns log \"##### Cleaning logs...\""
    $start_real append "$ns cleanlogs"
628 629

    # reset shaping characteristics for all nodes
630 631 632
    $start_real append "$ns log \"##### Resetting links...\""
    $start_real append "$elabc clear"
    $start_real append "$elabc reset"
633

634 635 636
    if {$REAL_PLAB} {
	# distinguish between real/fake runs
	# XXX I'm thinkin...we can do better than this!
637
	$start_real append "$opsagent run -command \"cp /dev/null /proj/$pid/exp/$eid/tmp/real_plab\""
638 639

	# save off node list
640 641
	$start_real append "$ns log \"##### Creating node list...\""
	$start_real append "$opsagent run -command \"/usr/testbed/bin/node_list -m -e $pid,$eid > /proj/$pid/exp/$eid/tmp/node_list\""
642 643

	# initialize path characteristics
644 645 646
	$start_real append "$ns log \"##### Initialize emulation node path characteristics...\""
	$start_real append "$elabc create"
	$start_real append "$opsagent run -command \"/usr/testbed/bin/init-elabnodes.pl  -o /proj/$pid/exp/$eid/tmp/initial-conditions.txt $pid $eid\""
647
    } else {
648
	$start_real append "$elabc create"
649
    }
650 651 652 653

    # restart link tracing
    # XXX cleanlogs has unlinked the current trace log, so we have to
    # snapshot to bring it back into existence
654
    $start_real append "$ns log \"##### Starting link tracing...\""
655
    foreach link $tracelist {
656 657
        $start_real append "$link trace snapshot"
        $start_real append "$link trace start"
658 659 660
    }

    # restart servers
Mike Hibler's avatar
Mike Hibler committed
661
    if {$SERVERPROG != ""} {
662 663
	$start_real append "$ns log \"##### Starting server...\""
	$start_real append "$allservers start"
Mike Hibler's avatar
Mike Hibler committed
664
    }
665 666

    # restart stubs and monitors
667
    $start_real append "$ns log \"##### Starting stubs and monitors...\""
Mike Hibler's avatar
Mike Hibler committed
668
    if {!$NO_STUB && $REAL_PLAB} {
669
	$start_real append "$planetstubs start"
670
    }
671
    $start_real append "$monitorgroup start"
672 673

    # gather up the data and inform the user
674
    $start_real append "$ns log \"##### Experiment run started!\""
675 676 677
    # XXX cannot do a report here as that will cause the logs to be
    #     deleted before the next loghole sync

678
  set stop_real [$ns event-sequence]
679
    $stop_real append "$ns log \"Stopping REAL plab experiment\""
680 681

    # stop stubs and monitors
682
    $stop_real append "$ns log \"##### Stopping stubs and monitors...\""
Mike Hibler's avatar
Mike Hibler committed
683
    if {!$NO_STUB && $REAL_PLAB} {
684
	$stop_real append "$planetstubs stop"
685
    }
686
    $stop_real append "$monitorgroup stop"
687 688

    # stop servers
Mike Hibler's avatar
Mike Hibler committed
689
    if {$SERVERPROG != ""} {
690 691
	$stop_real append "$ns log \"##### Stopping servers...\""
	$stop_real append "$allservers stop"
Mike Hibler's avatar
Mike Hibler committed
692
    }
693 694

    # stop link logging and save logs
695
    $stop_real append "$ns log \"##### Stop link tracing...\""
696
    foreach link $tracelist {
697 698
        $stop_real append "$link trace snapshot"
        $stop_real append "$link trace stop"
699 700 701
    }

    # reset shaping characteristics for all nodes
702 703 704
    $stop_real append "$ns log \"##### Resetting links...\""
    $stop_real append "$elabc clear"
    $stop_real append "$elabc reset"
705 706

    # gather up the data and inform the user
707 708
    $stop_real append "$ns log \"##### Experiment run stopped!\""
    $stop_real append "$ns report"
709 710 711 712 713 714 715 716 717 718 719 720 721
}

#
# Build up the event sequences to start and stop an actual run on FAKE
# plab nodes.  The only difference here (besides the names) is that these
# sequences use plabstubs rather than planetstubs.
#
if {$FAKE_PLAB} {
  set start_fake [$ns event-sequence]
    $start_fake append "$ns log \"Starting FAKE plab experiment\""

    # stop stubs and monitors
    $start_fake append "$ns log \"##### Stopping stubs and monitors...\""
Mike Hibler's avatar
Mike Hibler committed
722
    if {!$NO_STUB} {
723
	$start_fake append "$plabstubs stop"
Mike Hibler's avatar
Mike Hibler committed
724
    }
725 726 727
    $start_fake append "$monitorgroup stop"

    # stop servers
Mike Hibler's avatar
Mike Hibler committed
728 729 730 731
    if {$SERVERPROG != ""} {
	$start_fake append "$ns log \"##### Stopping servers...\""
	$start_fake append "$allservers stop"
    }
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751

    # stop link logging
    $start_fake append "$ns log \"##### Roll link trace logs...\""
    foreach link $tracelist {
        $start_fake append "$link trace snapshot"
        $start_fake append "$link trace stop"
    }

    # clean out log files
    # XXX original script passed --root, cleanlogs does not--may be a problem.
    $start_fake append "$ns log \"##### Cleaning logs...\""
    $start_fake append "$ns cleanlogs"

    # reset shaping characteristics for all nodes
    $start_fake append "$ns log \"##### Resetting links...\""
    $start_fake append "$elabc clear"
    $start_fake append "$elabc reset"

    # distinguish between real/fake runs
    # XXX I'm thinkin...we can do better than this!
752
    $start_fake append "$opsagent run -command \"rm -f /proj/$pid/exp/$eid/tmp/real_plab\""
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767

    # save off node list
    $start_fake append "$ns log \"##### Creating node list...\""
    $start_fake append "$opsagent run -command \"/usr/testbed/bin/node_list -m -e $pid,$eid > /proj/$pid/exp/$eid/tmp/node_list\""

    # restart link tracing
    # XXX cleanlogs has unlinked the current trace log, so we have to
    # snapshot to bring it back into existence
    $start_fake append "$ns log \"##### Starting link tracing...\""
    foreach link $tracelist {
        $start_fake append "$link trace snapshot"
        $start_fake append "$link trace start"
    }

    # restart servers
Mike Hibler's avatar
Mike Hibler committed
768 769 770 771
    if {$SERVERPROG != ""} {
	$start_fake append "$ns log \"##### Starting server...\""
	$start_fake append "$allservers start"
    }
772 773 774

    # restart stubs and monitors
    $start_fake append "$ns log \"##### Starting stubs and monitors...\""
Mike Hibler's avatar
Mike Hibler committed
775 776 777
    if {!$NO_STUB} {
	$start_fake append "$plabstubs start"
    }
778 779 780 781 782 783 784 785 786 787 788 789
    $start_fake append "$monitorgroup start"

    # gather up the data and inform the user
    $start_fake append "$ns log \"##### Experiment run started!\""
    # XXX cannot do a report here as that will cause the logs to be
    #     deleted before the next loghole sync

  set stop_fake [$ns event-sequence]
    $stop_fake append "$ns log \"Stopping FAKE plab experiment\""

    # stop stubs and monitors
    $stop_fake append "$ns log \"##### Stopping stubs and monitors...\""
Mike Hibler's avatar
Mike Hibler committed
790 791 792
    if {!$NO_STUB} {
	$stop_fake append "$plabstubs stop"
    }
793 794 795
    $stop_fake append "$monitorgroup stop"

    # stop servers
Mike Hibler's avatar
Mike Hibler committed
796 797 798 799
    if {$SERVERPROG != ""} {
	$stop_fake append "$ns log \"##### Stopping servers...\""
	$stop_fake append "$allservers stop"
    }
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830

    # stop link logging and save logs
    $stop_fake append "$ns log \"##### Stop link tracing...\""
    foreach link $tracelist {
        $stop_fake append "$link trace snapshot"
        $stop_fake append "$link trace stop"
    }

    # reset shaping characteristics for all nodes
    $stop_fake append "$ns log \"##### Resetting links...\""
    $stop_fake append "$elabc clear"
    $stop_fake append "$elabc reset"

    # gather up the data and inform the user
    $stop_fake append "$ns log \"##### Experiment run stopped!\""
    $stop_fake append "$ns report"
}

#
# Schedule sequences for start/stop run.
#
# For starting a run, the event system is restarted so we just need
# to have an "at 0" event to trigger it.
#
# For stopping a run, we don't need anything special.  The default action
# of stopping all program agents, snapshotting link tracing, and collecting
# logfiles is sufficient.  The only other action we used to do was to reset
# link shaping on the elabc cloud with the "clear" and "reset" events.
# However, we do that on a start run, so it is not strictly necessary to
# do it on stop.
#
831
if {$NO_PLAB || $REAL_PLAB} {
832
    $ns at 0 "start_real run"
833 834 835 836 837
} elseif {$FAKE_PLAB} {
    $ns at 0 "start_fake run"
}

$ns run