auto-pelab.tm 26.1 KB
Newer Older
Mike Hibler's avatar
Mike Hibler committed
1 2 3 4 5 6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# All rights reserved.
#

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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
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
113
#set PLABNODES {plab518 plab541 plab628 plab736 plab360}
114

115 116 117 118 119 120 121 122 123 124
# 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
}

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 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
#
# 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
205 206
{Server program to run automatically on all elab nodes.\
 Set to the NULL string to disable. }
207
$ns define-template-parameter CLIENTPROG $cstr \
Mike Hibler's avatar
Mike Hibler committed
208
{Client to run automatically on elab nodes.\
209 210
 NOTE: not supported currently. }

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

214 215 216 217 218 219 220
#
# 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. }

221 222 223 224 225 226 227 228
#
# 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). }

229 230 231 232 233 234 235 236 237 238 239
#
# 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. }

240
#
241 242 243 244
# 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.
245
#
246 247 248 249 250 251 252 253 254 255 256
$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. }
257

258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
#
# 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
275 276 277
# XXX for internal use only
set NO_STUB 0

278 279 280 281 282 283
#
# Enforce NO_PLAB requirements
#
if {$NO_PLAB} {
    set FAKE_PLAB 0
    set REAL_PLAB 0
284 285 286
# XXX don't force use of dbmonitor; may want to just use init_elabnodes.
#    set USE_DBMONITOR 1
    set NO_STUB 1
287 288
}

Mike Hibler's avatar
Mike Hibler committed
289 290 291 292 293 294 295 296
#
# Enforce USE_DBMONITOR requirements
#
if {$USE_DBMONITOR} {
    set USE_MAGENT 0
    set NO_STUB 1
}

297 298 299
# End of user-settable options
##########

300 301 302
set pid ${GLOBALS::pid}
set eid ${GLOBALS::eid}

303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
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"
}
340 341 342

# we don't run dbmonitor on the nodes anymore
if {0 && $USE_DBMONITOR} {
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
    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
366
set anlist {}
367 368 369 370 371

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

375
    if {$REAL_PLAB && ![info exists skip($i)]} {
376 377 378 379 380 381 382 383 384
        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
385

386 387 388
        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
389 390 391
	set allnodes($anix) [$planet($i) program-agent -command $ALLNODESPROG]
	lappend anlist $allnodes($anix)
	incr anix
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415

        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
416 417 418
	set allnodes($anix) [$plab($i) program-agent -command $ALLNODESPROG]
	lappend anlist $allnodes($anix)
	incr anix
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
    }

    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
440 441 442
    set allnodes($anix) [$elab($i) program-agent -command $ALLNODESPROG]
    lappend anlist $allnodes($anix)
    incr anix
443 444 445 446 447 448

    #
    # 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
    #
449
    if {[llength $PLABNODES] > 0 && ![info exists skip($i)]} {
450 451 452 453
        set opt(pelab-elab-$i-mapping) [lindex $PLABNODES [expr $i - 1]]
    }
}

454 455
#
# Run the DB monitor on ops
456
# Intervals are passed via the environment.
457 458 459 460
#
if {$USE_DBMONITOR} {
    set dbmonitor [new Program $ns]
    $dbmonitor set node "ops"
461
    $dbmonitor set command "/usr/testbed/sbin/dbmonitor.pl $pid $eid"
462
    $dbmonitor set expected-exit-code $ecode
463 464 465
    set monitorlist $dbmonitor
}

466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
#
# 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
484
set anhosts [$ns event-group $anlist]
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 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

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
}

569
# for one-off ops commands
570 571 572 573 574 575 576 577 578 579 580 581 582
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.
#
583
if {$NO_PLAB || $REAL_PLAB} {
584 585
  set start_real [$ns event-sequence]
    $start_real append "$ns log \"Starting REAL plab experiment\""
586 587

    # stop stubs and monitors
588
    $start_real append "$ns log \"##### Stopping stubs and monitors...\""
Mike Hibler's avatar
Mike Hibler committed
589
    if {!$NO_STUB && $REAL_PLAB} {
590
	$start_real append "$planetstubs stop"
591
    }
592
    $start_real append "$monitorgroup stop"
593 594

    # stop servers
Mike Hibler's avatar
Mike Hibler committed
595
    if {$SERVERPROG != ""} {
596 597
	$start_real append "$ns log \"##### Stopping servers...\""
	$start_real append "$allservers stop"
Mike Hibler's avatar
Mike Hibler committed
598
    }
599 600

    # stop link logging
601
    $start_real append "$ns log \"##### Roll link trace logs...\""
602
    foreach link $tracelist {
603 604
        $start_real append "$link trace snapshot"
        $start_real append "$link trace stop"
605 606 607 608
    }

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

    # reset shaping characteristics for all nodes
613 614 615
    $start_real append "$ns log \"##### Resetting links...\""
    $start_real append "$elabc clear"
    $start_real append "$elabc reset"
616

617 618 619
    if {$REAL_PLAB} {
	# distinguish between real/fake runs
	# XXX I'm thinkin...we can do better than this!
620
	$start_real append "$opsagent run -command \"cp /dev/null /proj/$pid/exp/$eid/tmp/real_plab\""
621 622

	# save off node list
623 624
	$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\""
625 626

	# initialize path characteristics
627 628 629
	$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\""
630
    } else {
631
	$start_real append "$elabc create"
632
    }
633 634 635 636

    # restart link tracing
    # XXX cleanlogs has unlinked the current trace log, so we have to
    # snapshot to bring it back into existence
637
    $start_real append "$ns log \"##### Starting link tracing...\""
638
    foreach link $tracelist {
639 640
        $start_real append "$link trace snapshot"
        $start_real append "$link trace start"
641 642 643
    }

    # restart servers
Mike Hibler's avatar
Mike Hibler committed
644
    if {$SERVERPROG != ""} {
645 646
	$start_real append "$ns log \"##### Starting server...\""
	$start_real append "$allservers start"
Mike Hibler's avatar
Mike Hibler committed
647
    }
648 649

    # restart stubs and monitors
650
    $start_real append "$ns log \"##### Starting stubs and monitors...\""
Mike Hibler's avatar
Mike Hibler committed
651
    if {!$NO_STUB && $REAL_PLAB} {
652
	$start_real append "$planetstubs start"
653
    }
654
    $start_real append "$monitorgroup start"
655 656

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

661
  set stop_real [$ns event-sequence]
662
    $stop_real append "$ns log \"Stopping REAL plab experiment\""
663 664

    # stop stubs and monitors
665
    $stop_real append "$ns log \"##### Stopping stubs and monitors...\""
Mike Hibler's avatar
Mike Hibler committed
666
    if {!$NO_STUB && $REAL_PLAB} {
667
	$stop_real append "$planetstubs stop"
668
    }
669
    $stop_real append "$monitorgroup stop"
670 671

    # stop servers
Mike Hibler's avatar
Mike Hibler committed
672
    if {$SERVERPROG != ""} {
673 674
	$stop_real append "$ns log \"##### Stopping servers...\""
	$stop_real append "$allservers stop"
Mike Hibler's avatar
Mike Hibler committed
675
    }
676 677

    # stop link logging and save logs
678
    $stop_real append "$ns log \"##### Stop link tracing...\""
679
    foreach link $tracelist {
680 681
        $stop_real append "$link trace snapshot"
        $stop_real append "$link trace stop"
682 683 684
    }

    # reset shaping characteristics for all nodes
685 686 687
    $stop_real append "$ns log \"##### Resetting links...\""
    $stop_real append "$elabc clear"
    $stop_real append "$elabc reset"
688 689

    # gather up the data and inform the user
690 691
    $stop_real append "$ns log \"##### Experiment run stopped!\""
    $stop_real append "$ns report"
692 693 694 695 696 697 698 699 700 701 702 703 704
}

#
# 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
705
    if {!$NO_STUB} {
706
	$start_fake append "$plabstubs stop"
Mike Hibler's avatar
Mike Hibler committed
707
    }
708 709 710
    $start_fake append "$monitorgroup stop"

    # stop servers
Mike Hibler's avatar
Mike Hibler committed
711 712 713 714
    if {$SERVERPROG != ""} {
	$start_fake append "$ns log \"##### Stopping servers...\""
	$start_fake append "$allservers stop"
    }
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734

    # 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!
735
    $start_fake append "$opsagent run -command \"rm -f /proj/$pid/exp/$eid/tmp/real_plab\""
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750

    # 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
751 752 753 754
    if {$SERVERPROG != ""} {
	$start_fake append "$ns log \"##### Starting server...\""
	$start_fake append "$allservers start"
    }
755 756 757

    # restart stubs and monitors
    $start_fake append "$ns log \"##### Starting stubs and monitors...\""
Mike Hibler's avatar
Mike Hibler committed
758 759 760
    if {!$NO_STUB} {
	$start_fake append "$plabstubs start"
    }
761 762 763 764 765 766 767 768 769 770 771 772
    $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
773 774 775
    if {!$NO_STUB} {
	$stop_fake append "$plabstubs stop"
    }
776 777 778
    $stop_fake append "$monitorgroup stop"

    # stop servers
Mike Hibler's avatar
Mike Hibler committed
779 780 781 782
    if {$SERVERPROG != ""} {
	$stop_fake append "$ns log \"##### Stopping servers...\""
	$stop_fake append "$allservers stop"
    }
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813

    # 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.
#
814
if {$NO_PLAB || $REAL_PLAB} {
815
    $ns at 0 "start_real run"
816 817 818 819 820
} elseif {$FAKE_PLAB} {
    $ns at 0 "start_fake run"
}

$ns run