tb_compat.tcl.in 43.9 KB
Newer Older
1
# -*- tcl -*-
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2006 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5
6
7
# All rights reserved.
#

8
9
10
# This is the tb_compact.tcl that deals with all the TB specific commands.
# It should be loaded at the beginning of any ns script using the TB commands.

Leigh B. Stoller's avatar
Leigh B. Stoller committed
11
12
13
14
15
16
17
18
19
20
21
22
23
# We set up some helper stuff in a separate namespace to avoid any conflicts.
namespace eval TBCOMPAT {
    var_import ::GLOBALS::DB
    var_import ::GLOBALS::pid
    var_import ::GLOBALS::eid

    # This is regular expression that matches slightly more than valid
    # IP addresses.  The only thing it doesn't check is that IP 
    # addresses are in range (i.e. 0-255).
    variable IP {^([0-9]{1,3}\.){3,3}[0-9]{1,3}$}

    # This is an RE to match a floating point number.
    variable FLOAT {(^[0-9]+(\.[0-9]+)?$)|(^\.[0-9]+$)}
24
25
26
27
28
29
30

    # This is the default weight for a soft vtype.
    variable default_soft_vtype_weight 0.5

    # This is the default weight for a hard vtype.
    variable default_hard_vtype_weight 1.0

Timothy Stack's avatar
   
Timothy Stack committed
31
32
    variable prefix "@prefix@"

Timothy Stack's avatar
   
Timothy Stack committed
33
34
35
36
37
38
39
40
41
42
43
44
    # Substitutions for "/proj",
    variable FSDIR_PROJ "@FSDIR_PROJ@"

    # ... "/groups",
    variable FSDIR_GROUPS "@FSDIR_GROUPS@"

    # ... "/users", and
    variable FSDIR_USERS "@FSDIR_USERS@"

    # ... "/share".
    variable FSDIR_SHARE "@FSDIR_SHARE@"

Leigh B. Stoller's avatar
Leigh B. Stoller committed
45
46
47
48
49
50
51
52
53
    # This is a general procedure that takes a node, an object (lan or link)
    # it is connected to, and an IP address, and sets the IP address
    # for the node on that object.  It checks both the validity of the
    # IP addresses and the fact that the node is actually a member of the
    # lan/link.
    proc set-ip {node obj ip} {
	variable IP
	set caller [lindex [info level -1] 0]
	if {[regexp $IP $ip] == 0} {
54
	    perror "$caller - $ip is not a valid IP address."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
55
56
57
58
	    return
	}
	set port [$node find_port $obj]
	if {$port == -1} {
59
	    perror "$caller - $node is not connected to $obj."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
60
61
62
63
64
65
66
	    return
	}
	$node ip $port $ip
    }

    # Let's set up a hwtypes table that contains all valid hardware types.
    variable hwtypes
67
    variable isremote
68
    variable isvirt
Leigh B. Stoller's avatar
Leigh B. Stoller committed
69
    variable issubnode
Leigh B. Stoller's avatar
Leigh B. Stoller committed
70

Shashi Guruprasad's avatar
Shashi Guruprasad committed
71
72
73
    # NSE hack: sim type is not in DB. Just adding it now
    set hwtypes(sim) 1
    set isremote(sim) 0
74
    set isvirt(sim) 0
Leigh B. Stoller's avatar
Leigh B. Stoller committed
75
    set issubnode(sim) 0
Shashi Guruprasad's avatar
Shashi Guruprasad committed
76

77
78
79
80
81
    # The permissions table. Entries in this table indicate who is allowed
    # to use nodes of a particular type. No entries means anyone can use it.
    #
    # We omit this check in anonymous mode.
    #
82
    variable nodetypeXpid_permissions
83
    
84
85
86
87
    # And a os table with valid OS Descriptor names. While we still call
    # them "osids", we are using the user level name not the internal,
    # globally unique name. We leave it to a later phase to deal with it.
    #
Leigh B. Stoller's avatar
Leigh B. Stoller committed
88
    # We omit this check in anonymous mode.
89
90
91
92
93
94
95
96
97
    #
    variable osids

    # The default OSID for the node type. 
    variable default_osids

    # A mapping of event objects and types.
    variable objtypes
    variable eventtypes
98
99
100
101
102
103

    # Existing (reserved nodes).
    variable reserved_list
    variable reserved_type
    variable reserved_node
    set reserved_list {}
104

105
106
107
108
    # Input parameters for Templates
    variable parameter_list_defaults
    array set parameter_list_defaults {}

109
110
    # Physical node names
    variable physnodes
111
112
113
114
115
116

    ## Feedback related stuff below:

    # Experiment directory name.
    variable expdir

117
118
    # ElabInElab stuff. Do not initialize.
    variable elabinelab_maxpcs
119
120
    variable elabinelab_hardware
    variable elabinelab_fixnodes
121
    variable elabinelab_nodeos
122
    variable elabinelab_source_tarfile ""
123
    variable elabinelab_tarfiles
124

125
126
127
128
129
130
131
132
    # Mapping of "resource classes" and "reservation types" to bootstrap
    # values, where a resource class is a symbolic string provided by the user
    # (e.g. Client, Server), and a reservation type is a resource name provided
    # by the system (e.g. cpupercent, kbps).  This array will be filled by the
    # tb-feedback methods and then written out to a "bootstrap_data.tcl" file
    # to be read in during future evaluations of the NS file.
    variable BootstrapReservations

133
134
135
136
137
138
139
    # Table of vnodes/vlinks that were locate on an overloaded pnode.
    variable Alerts

    # Table of "estimated" reservations.  Basically, its our memory of previous
    # guesses for vnodes that have 0% CPU usage on an overloaded pnode.
    variable EstimatedReservations

140
141
    # The experiment directory, this is where the feedback related files will
    # be read from and dumped to.  XXX Hacky
Timothy Stack's avatar
   
Timothy Stack committed
142
    set expdir "${FSDIR_PROJ}/${::GLOBALS::pid}/exp/${::GLOBALS::eid}/"
143
144

    # XXX Just for now...
Timothy Stack's avatar
   
Timothy Stack committed
145
    variable tbxlogfile
146
    if {[file exists "$expdir"]} {
147
148
	set logname "$expdir/logs/feedback.log"
	set tbxlogfile [open $logname w 0664];
149
	catch "exec chmod 0664 $logname"
Timothy Stack's avatar
   
Timothy Stack committed
150
	puts $tbxlogfile "BEGIN feedback log"
151
152
153
154
155
156
157
158
159
160
    }

    # Get any Emulab generated feedback data from the experiment directory.
    if {[file exists "${expdir}/tbdata/feedback_data.tcl"]} {
	source "${expdir}/tbdata/feedback_data.tcl"
    }
    # Get any bootstrap feedback data from a previous run.
    if {[file exists "${expdir}/tbdata/bootstrap_data.tcl"]} {
	source "${expdir}/tbdata/bootstrap_data.tcl"
    }
161
162
163
164
    # Get any estimated feedback data from a previous run.
    if {[file exists "${expdir}/tbdata/feedback_estimate.tcl"]} {
	source "${expdir}/tbdata/feedback_estimate.tcl"
    }
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

    #
    # Configure the default reservations for an object based on an optional
    # "resource class".  First, the function will check for a reservation
    # specifically made for the object, then it will try to initialize the
    # reservation from the resource class, otherwise it does nothing and
    # returns zero.
    #
    # @param object The object name for which to configure the feedback
    #   defaults.
    # @param rclass The "resource class" of the object or the empty string if
    #   it is not part of any class.  This is just a symbolic string, such as
    #   "Client" or "Server".
    # @return One, if there is an initialized slot in the "Reservations" array
    #   for the given object, or zero if it could not be initialized.
    #
    proc feedback-defaults {object rclass} {
	var_import ::TBCOMPAT::Reservations;  # The reservations to make

	if {[array get Reservations $object,*] == ""} {
	    # No node-specific values exist, try to initialize from the rclass.
	    if {[array get Reservations $rclass,*] != ""} {
		# Use bootstrap feedback from a previous topology,
		set rcdefaults [array get Reservations $rclass,*]
		# ... substitute the node name for the rclass, and
		regsub -all -- $rclass $rcdefaults $object rcdefaults
		# ... add all the reservations to the table.
		array set Reservations $rcdefaults
		set retval 1
	    } else {
		# No feedback exists yet, let the caller fill it in.
		set retval 0
	    }
	} else {
	    # Node-specific values exist, use those.
	    set retval 1
	}
	return $retval
    }

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
    #
    # Produce an estimate of a vnode's resource usage.  If a guess was already
    # made in the previous iteration, double that value.  Otherwise, we just
    # assume 10%.
    #
    # @param object The object for which to produce the estimate.
    # @param rtype The resource type: cpupercent, rampercent
    # @return The estimated resource usage.
    # 
    proc feedback-estimate {object rtype} {
	var_import ::TBCOMPAT::EstimatedReservations

	if {[array get EstimatedReservations $object,$rtype] != ""} {
	    set retval [expr [set EstimatedReservations($object,$rtype)] * 2]
	} else {
	    set retval 10.0; # XXX get from DB
	}
	set EstimatedReservations($object,$rtype) $retval
	return $retval
    }

226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
    #
    # Record bootstrap feedback data for a resource class.  This function
    # should be called for every member of a resource class so that the one
    # with the highest reservation will be used to bootstrap.
    #
    # @param rclass The "resource class" for which to update the bootstrap
    #   feedback data.  This is just a symbolic string, such as "Client" or
    #   "Server".
    # @param rtype The type of reservation (e.g. cpupercent,kbps).
    # @param res The amount to reserve.
    #
    proc feedback-bootstrap {rclass rtype res} {
	# The bootstrap reservations
	var_import ::TBCOMPAT::BootstrapReservations

	if {$rclass == ""} {
	    # No class to operate on...
	} elseif {([array get BootstrapReservations($rclass,$rtype)] == "") ||
	    ($res > $BootstrapReservations($rclass,$rtype))} {
		# This is either the first time this function was called for
		# this rclass/rtype or the new value is greater than the old.
		set BootstrapReservations($rclass,$rtype) $res
	}
    }
Timothy Stack's avatar
   
Timothy Stack committed
250
251
252
253
254
255
256

    #
    # Verify that the argument is an http, https, or ftp URL.
    #
    # @param url The URL to check.
    # @return True if "url" looks like a URL.
    #
257
258
    # What is xxx:// you might ask? Its part of experimental template code.
    #
Timothy Stack's avatar
   
Timothy Stack committed
259
260
261
    proc verify-url {url} {
	if {[string match "http://*" $url] ||
	    [string match "https://*" $url] ||
262
263
	    [string match "ftp://*" $url] ||
	    [string match "xxx://*" $url]} {
Timothy Stack's avatar
   
Timothy Stack committed
264
265
266
267
268
269
	    set retval 1
	} else {
	    set retval 0
	}
	return $retval
    }
270
271
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
272
273
# IP addresses routines.  These all do some checks and convert into set-ip
# calls.
274
proc tb-set-ip {node ip} {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
275
276
    $node instvar portlist
    if {[llength $portlist] != 1} {
277
	perror "\[tb-set-ip] $node does not have a single connection."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
278
279
280
	return
    }
    ::TBCOMPAT::set-ip $node [lindex $portlist 0] $ip
281
282
}
proc tb-set-ip-interface {src dst ip} {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
283
284
285
286
    set sim [$src set sim]
    set reallink [$sim find_link $src $dst]
    if {$reallink == {}} {
	perror \
287
	    "\[tb-set-ip-interface] No connection between $src and $dst."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
288
	return
289
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
290
    ::TBCOMPAT::set-ip $src $reallink $ip
291
292
}
proc tb-set-ip-lan {src lan ip} {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
293
    if {[$lan info class] != "Lan"} {
294
	perror "\[tb-set-ip-lan] $lan is not a LAN."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
295
296
297
	return
    }
    ::TBCOMPAT::set-ip $src $lan $ip
298
299
}
proc tb-set-ip-link {src link ip} {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
300
    if {[$link info class] != "Link"} {
301
	perror "\[tb-set-ip-link] $link is not a link."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
302
303
304
	return
    }
    ::TBCOMPAT::set-ip $src $link $ip
305
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
306

307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#
# Set the netmask. To make it easier to compute subnets later, do
# allow the user to alter the netmask beyond the bottom 3 octets.
# This restricts the user to a lan of 4095 nodes, but that seems okay
# for now. 
# 
proc tb-set-netmask {lanlink netmask} {
    var_import ::TBCOMPAT::IP
    
    if {[$lanlink info class] != "Link" && [$lanlink info class] != "Lan"} {
	perror "\[tb-set-netmask] $lanlink is not a link or a lan."
	return
    }
    if {[regexp $IP $netmask] == 0} {
	perror "\[tb-set-netmask] - $netmask is not a valid IP mask"
	return
    }
    set netmaskint [inet_atohl $netmask]
325
    if {[expr ($netmaskint & 0xFFFF0000)] != 0xFFFF0000} {
326
327
328
329
330
331
	perror "\[tb-set-netmask] - $netmask is too big"
	return
    }
    $lanlink set netmask $netmask
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
332
# Node state routines.
333
proc tb-set-hardware {node type args} {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
334
    var_import ::TBCOMPAT::hwtypes
335
    var_import ::TBCOMPAT::isremote
336
    var_import ::TBCOMPAT::isvirt
Leigh B. Stoller's avatar
Leigh B. Stoller committed
337
    var_import ::TBCOMPAT::issubnode
338
339
340
    var_import ::GLOBALS::vtypes
    if {(! [info exists hwtypes($type)]) &&
	(! [info exists vtypes($type)])} {
341
	perror "\[tb-set-hardware] Invalid hardware type $type."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
342
343
	return
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
344
    if {! ${GLOBALS::anonymous} && ! ${GLOBALS::passmode}} {
345
346
	var_import ::TBCOMPAT::nodetypeXpid_permissions
	var_import ::GLOBALS::pid
Leigh B. Stoller's avatar
Leigh B. Stoller committed
347
	set allowed 1
348
349
	
	if {[info exists nodetypeXpid_permissions($type)]} {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
350
	    set allowed 0
351
352
353
354
355
356
357
358
359
360
361
	    foreach allowedpid $nodetypeXpid_permissions($type) {
		if {$allowedpid == $pid} {
		    set allowed 1
		}
	    }
	}
	if {! $allowed} {
	    perror "\[tb-set-hardware] No permission to use type $type."
	    return
	}
    }
362
363
364
365
    set remote 0
    if {[info exists isremote($type)]} {
	set remote $isremote($type)
    }
366
367
368
369
    set isv 0
    if {[info exists isvirt($type)]} {
	set isv $isvirt($type)
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
370
371
372
373
374
    set issub 0
    if {[info exists isvirt($type)]} {
	set issub $issubnode($type)
    }
    $node set_hwtype $type $remote $isv $issub
375
}
376

377
proc tb-set-node-os {node os} {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
378
    if {! ${GLOBALS::anonymous} && ! ${GLOBALS::passmode}} {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
379
380
	var_import ::TBCOMPAT::osids
	if {! [info exists osids($os)]} {
381
	    perror "\[tb-set-node-os] Invalid osid $os."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
382
383
384
385
386
387
388
389
390
391
	    return
	}
    }
    $node set osid $os
}
proc tb-set-node-cmdline {node cmdline} {
    $node set cmdline $cmdline
}
proc tb-set-node-rpms {node args} {
    if {$args == {}} {
392
	perror "\[tb-set-node-rpms] No rpms given."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
393
394
	return
    }
395
396
397
398
    # Lets assume that a single argument is a string and break it up.
    if {[llength $args] == 1} {
	set args [split [lindex $args 0] " "]
    }
399
    $node set rpms [join $args ";"]
400
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
401
402
403
404
405
proc tb-set-node-startup {node cmd} {
    $node set startup $cmd
}
proc tb-set-node-tarfiles {node args} {
    if {$args == {}} {
406
	perror "\[tb-set-node-tarfiles] tb-set-node-tarfiles <node> (<dir> <tar>)+"
Leigh B. Stoller's avatar
Leigh B. Stoller committed
407
408
	return
    }
409
410
411
412
    # Lets assume that a single argument is a string and break it up.
    if {[llength $args] == 1} {
	set args [split [lindex $args 0] " "]
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
413
    if {[expr [llength $args] % 2] != 0} {
414
	perror "\[tb-set-node-tarfiles] Arguments should be node and series of pairs."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
415
416
	return
    }
417
418
    set tarfiles {}
    while {$args != {}} {
Timothy Stack's avatar
   
Timothy Stack committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
	set dir [lindex $args 0]
	set tarfile [lindex $args 1]
	
	# Check the install directory to make sure it is not an NFS mount.
	# This check can also act as an alert to the user that the arguments
	# are wrong.  For example, the following line will pass the above
	# checks, but fail this one:
	#
	#   tb-set-node-tarfiles $node /proj/foo/bar.tgz /proj/foo/baz.tgz
	#
	# XXX /proj is hardcoded since the subst is /q/proj.
	if {[string match "/proj/*" $dir] ||
	    [string match "${::TBCOMPAT::FSDIR_GROUPS}/*" $dir] ||
	    [string match "${::TBCOMPAT::FSDIR_USERS}/*" $dir] ||
	    [string match "${::TBCOMPAT::FSDIR_SHARE}/*" $dir]} {
	    perror "\[tb-set-node-tarfiles] '$dir' refers to an NFS directory instead of the node's local disk."
	    return
Timothy Stack's avatar
   
Timothy Stack committed
436
437
438
	} elseif {![string match "/*" $dir]} {
	    perror "\[tb-set-node-tarfiles] '$dir' is not an absolute path."
	    return
Timothy Stack's avatar
   
Timothy Stack committed
439
440
	}

441
442
443
444
445
	# Skip the rest in passmode.
	if {${GLOBALS::anonymous} || ${GLOBALS::passmode}} {
	    return
	}

Timothy Stack's avatar
   
Timothy Stack committed
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
	# Check the tar file to make sure it exists, is readable, etc...
	if {[string match "*://*" $tarfile]} {
	    # It is a URL, check for a valid protocol.
	    if {![::TBCOMPAT::verify-url $tarfile]} {
		perror "\[tb-set-node-tarfiles] '$tarfile' is not an http, https, or ftp URL."
		return
	    }
	} elseif {![string match "/proj/*" $tarfile] &&
	          ![string match "/groups/*" $tarfile]} {
	    perror "\[tb-set-node-tarfiles] '$tarfile' is not in '/proj' or '/groups'"
	    return
	} elseif {![file exists $tarfile]} {
	    perror "\[tb-set-node-tarfiles] '$tarfile' does not exist."
	    return
	} elseif {![file isfile $tarfile]} {
	    perror "\[tb-set-node-tarfiles] '$tarfile' is not a file."
	    return
	} elseif {![file readable $tarfile]} {
	    perror "\[tb-set-node-tarfiles] '$tarfile' is not readable."
	    return
	}

	# Make sure the tarfile has a valid extension.
	if {![string match "*.tar" $tarfile] &&
	    ![string match "*.tar.Z" $tarfile] &&
	    ![string match "*.tar.gz" $tarfile] &&
	    ![string match "*.tgz" $tarfile] &&
	    ![string match "*.tar.bz2" $tarfile]} {
	    perror "\[tb-set-node-tarfiles] '$tarfile' does not have a valid extension (e.g. *.tar, *.tar.Z, *.tar.gz, *.tgz)."
	    return
	}
	lappend tarfiles "$dir $tarfile"
478
479
	set args [lrange $args 2 end]
    }
480
    $node set tarfiles [join $tarfiles ";"]
Leigh B. Stoller's avatar
Leigh B. Stoller committed
481
}
482
483
484
proc tb-set-ip-routing {type} {
    var_import ::GLOBALS::default_ip_routing_type

485
    if {$type == {}} {
486
	perror "\[tb-set-ip-routing] No type given."
487
488
489
	return
    }
    if {($type != "none") &&
490
491
	($type != "ospf")} {
	perror "\[tb-set-ip-routing] Type is not one of none|ospf"
492
493
	return
    }
494
    set default_ip_routing_type $type
495
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
496
497
498
499
500
501

# Lan/Link state routines.

# This takes two possible formats:
# tb-set-link-loss <link> <loss>
# tb-set-link-loss <src> <dst> <loss>
502
proc tb-set-link-loss {srclink args} {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
503
    var_import ::TBCOMPAT::FLOAT
504
505
    if {[llength $args] == 2} {
	set dst [lindex $args 0]
Leigh B. Stoller's avatar
Leigh B. Stoller committed
506
507
508
509
	set lossrate [lindex $args 1]
	set sim [$srclink set sim]
	set reallink [$sim find_link $srclink $dst]
	if {$reallink == {}} {
510
	    perror "\[tb-set-link-loss] No link between $srclink and $dst."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
511
	    return
512
513
	}
    } else {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
514
	set reallink $srclink
515
	set lossrate [lindex $args 0]
Leigh B. Stoller's avatar
Leigh B. Stoller committed
516
517
518
    }
    if {([regexp $FLOAT $lossrate] == 0) ||
	($lossrate > 1.0)} {
519
	perror "\[tb-set-link-loss] $lossrate is not a valid loss rate."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
520
    }
521
522
    $reallink instvar loss
    $reallink instvar rloss
Leigh B. Stoller's avatar
Leigh B. Stoller committed
523
524
525
    set adjloss [expr 1-sqrt(1-$lossrate)]
    foreach pair [array names loss] {
	set loss($pair) $adjloss
526
	set rloss($pair) $adjloss
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
# This takes two possible formats:
# tb-set-link-est-bandwidth <link> <loss>
# tb-set-link-est-bandwidth <src> <dst> <loss>
proc tb-set-link-est-bandwidth {srclink args} {
    if {[llength $args] == 2} {
	set dst [lindex $args 0]
	set bw [lindex $args 1]
	set sim [$srclink set sim]
	set reallink [$sim find_link $srclink $dst]
	if {$reallink == {}} {
	    perror "\[tb-set-link-est-bandwidth] No link between $srclink and $dst."
	    return
	}
    } else {
	set reallink $srclink
	set bw [lindex $args 0]
    }
    $reallink instvar bandwidth
    $reallink instvar ebandwidth 
    $reallink instvar rebandwidth
    foreach pair [array names bandwidth] {
	set ebandwidth($pair) [parse_bw $bw]
	set rebandwidth($pair) [parse_bw $bw]
    }
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
556
557
558
proc tb-set-lan-loss {lan lossrate} {
    var_import ::TBCOMPAT::FLOAT
    if {[$lan info class] != "Lan"} {
559
	perror "\[tb-set-lan-loss] $lan is not a lan."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
560
561
562
563
	return
    }
    if {([regexp $FLOAT $lossrate] == 0) ||
	($lossrate > 1.0)} {
564
	perror "\[tb-set-lan-loss] $lossrate is not a valid loss rate."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
565
566
    }
    $lan instvar loss
567
    $lan instvar rloss
Leigh B. Stoller's avatar
Leigh B. Stoller committed
568
569
570
    set adjloss [expr 1-sqrt(1-$lossrate)]
    foreach pair [array names loss] {
	set loss($pair) $adjloss
571
	set rloss($pair) $adjloss
Leigh B. Stoller's avatar
Leigh B. Stoller committed
572
    }
Christopher Alfeld's avatar
Added:    
Christopher Alfeld committed
573
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
574

575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
proc tb-set-lan-est-bandwidth {lan bw} {
    if {[$lan info class] != "Lan"} {
	perror "\[tb-set-lan-est-bandwidth] $lan is not a lan."
	return
    }

    $lan instvar bandwidth
    $lan instvar ebandwidth 
    $lan instvar rebandwidth
    foreach pair [array names bandwidth] {
	set ebandwidth($pair) [parse_bw $bw]
	set rebandwidth($pair) [parse_bw $bw]
    }
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
590
591
proc tb-set-node-lan-delay {node lan delay} {
    if {[$node info class] != "Node"} {
592
	perror "\[tb-set-node-lan-delay] $node is not a node."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
593
594
595
	return
    }
    if {[$lan info class] != "Lan"} {
596
	perror "\[tb-set-node-lan-delay] $lan is not a lan."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
597
598
599
600
	return
    }
    set port [$lan get_port $node]
    if {$port == {}} {
601
	perror "\[tb-set-node-lan-delay] $node is not in $lan."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
602
603
	return
    }
Mike Hibler's avatar
Mike Hibler committed
604
605
606
607

    set rdelay [parse_delay $delay]
    $lan set delay([list $node $port]) $rdelay
    $lan set rdelay([list $node $port]) $rdelay
Christopher Alfeld's avatar
Added:    
Christopher Alfeld committed
608
}
609
610


Leigh B. Stoller's avatar
Leigh B. Stoller committed
611
612
proc tb-set-node-lan-bandwidth {node lan bw} {
    if {[$node info class] != "Node"} {
613
	perror "\[tb-set-node-lan-bandwidth] $node is not a node."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
614
615
616
	return
    }
    if {[$lan info class] != "Lan"} {
617
	perror "\[tb-set-node-lan-bandwidth] $lan is not a lan."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
618
619
620
621
	return
    }
    set port [$lan get_port $node]
    if {$port == {}} {
622
	perror "\[tb-set-node-lan-bandwidth] $node is not in $lan."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
623
624
625
	return
    }
    $lan set bandwidth([list $node $port]) [parse_bw $bw]
626
    $lan set rbandwidth([list $node $port]) [parse_bw $bw]
627
}
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
proc tb-set-node-lan-est-bandwidth {node lan bw} {
    if {[$node info class] != "Node"} {
	perror "\[tb-set-node-lan-est-bandwidth] $node is not a node."
	return
    }
    if {[$lan info class] != "Lan"} {
	perror "\[tb-set-node-lan-est-bandwidth] $lan is not a lan."
	return
    }
    set port [$lan get_port $node]
    if {$port == {}} {
	perror "\[tb-set-node-lan-est-bandwidth] $node is not in $lan."
	return
    }
    $lan set ebandwidth([list $node $port]) [parse_bw $bw]
    $lan set rebandwidth([list $node $port]) [parse_bw $bw]
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
645
646
647
proc tb-set-node-lan-loss {node lan loss} {
    var_import ::TBCOMPAT::FLOAT
    if {[$node info class] != "Node"} {
Mike Hibler's avatar
Mike Hibler committed
648
	perror "\[tb-set-node-lan-loss] $node is not a node."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
649
650
651
	return
    }
    if {[$lan info class] != "Lan"} {
Mike Hibler's avatar
Mike Hibler committed
652
	perror "\[tb-set-node-lan-loss] $lan is not a lan."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
653
654
655
656
	return
    }
    set port [$lan get_port $node]
    if {$port == {}} {
Mike Hibler's avatar
Mike Hibler committed
657
	perror "\[tb-set-node-lan-loss] $node is not in $lan."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
658
659
660
661
	return
    }
    if {([regexp $FLOAT $loss] == 0) ||
	($loss > 1.0)} {
662
	perror "\[tb-set-link-loss] $loss is not a valid loss rate."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
663
664
    }
    $lan set loss([list $node $port]) $loss
665
    $lan set rloss([list $node $port]) $loss
Christopher Alfeld's avatar
Added:    
Christopher Alfeld committed
666
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
667
668
669
670
proc tb-set-node-lan-params {node lan delay bw loss} {
    tb-set-node-lan-delay $node $lan $delay
    tb-set-node-lan-bandwidth $node $lan $bw
    tb-set-node-lan-loss $node $lan $loss
671
}
672
673
674
675
676
677
678
679
680
681
682

proc tb-set-node-failure-action {node type} {
    if {[$node info class] != "Node"} {
	perror "\[tb-set-node-failure-action] $node is not a node."
	return
    }
    if {[lsearch -exact {fatal nonfatal ignore} $type] == -1} {
	perror "\[tb-set-node-failure-action] type must be one of fatal|nonfatal|ignore."
	return
    }
    $node set failureaction $type
683
684
685
686
}

proc tb-fix-node {vnode pnode} {
    if {[$vnode info class] != "Node"} {
687
	perror "\[tb-fix-node] $vnode is not a node."
688
689
	return
    }
690
    $vnode set_fixed $pnode
691
692
}

693
694
proc tb-make-soft-vtype {name types} {
    var_import ::TBCOMPAT::hwtypes
695
    var_import ::TBCOMPAT::isremote
696
697
698
699
700
701
702
703
704
705
706
707
708
    var_import ::GLOBALS::vtypes
    var_import ::TBCOMPAT::default_soft_vtype_weight

    foreach type $types {
	if {! [info exists hwtypes($type)]} {
	    perror "\[tb-make-soft-vtype] Invalid hardware type $type."
	}
    }
    set vtypes($name) [Vtype $name $default_soft_vtype_weight $types]
}

proc tb-make-hard-vtype {name types} {
    var_import ::TBCOMPAT::hwtypes
709
    var_import ::TBCOMPAT::isremote
710
711
712
713
714
715
716
717
718
719
720
721
722
    var_import ::GLOBALS::vtypes
    var_import ::TBCOMPAT::default_hard_vtype_weight

    foreach type $types {
	if {! [info exists hwtypes($type)]} {
	    perror "\[tb-make-hard-vtype] Invalid hardware type $type."
	}
    }
    set vtypes($name) [Vtype $name $default_hard_vtype_weight $types]
}

proc tb-make-weighted-vtype {name weight types} {
    var_import ::TBCOMPAT::hwtypes
723
    var_import ::TBCOMPAT::isremote
724
725
726
727
728
    var_import ::GLOBALS::vtypes
    var_import ::TBCOMPAT::FLOAT

    foreach type $types {
	if {! [info exists hwtypes($type)]} {
729
730
731
732
	    perror "\[tb-make-weighted-vtype] Invalid hardware type $type."
	}
	if {$isremote($type)} {
	    perror "\[tb-make-weighted-vtype] Remote type $type not allowed."
733
734
735
736
737
738
739
	}
    }
    if {([regexp $FLOAT $weight] == 0) ||
	($weight <= 0) || ($weight >= 1.0)} {
	perror "\[tb-make-weighted-vtype] $weight is not a valid weight. (0 < weight < 1)."
    }
    set vtypes($name) [Vtype $name $weight $types]
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
}

proc tb-set-link-simplex-params {link src delay bw loss} {
    var_import ::TBCOMPAT::FLOAT
    if {[$link info class] != "Link"} {
	perror "\[tb-set-link-simplex-params] $link is not a link."
	return
    }
    if {[$src info class] != "Node"} {
	perror "\[tb-set-link-simplex-params] $src is not a link."
	return
    }
    set port [$link get_port $src]
    if {$port == {}} {
	perror "\[tb-set-link-simplex-params] $src is not in $link."
	return
    }
    if {([regexp $FLOAT $loss] == 0) || ($loss > 1.0)} {
	perror "\[tb-set-link-simplex-params] $loss is not a valid loss rate."
	return
    }
    set adjloss [expr 1-sqrt(1-$loss)]
    set np [list $src $port]
    foreach nodeport [$link set nodelist] {
	if {$nodeport != $np} {
	    set onp $nodeport
	}
    }

    set realdelay [parse_delay $delay]
    set realbw [parse_bw $bw]
    $link set delay($np) [expr $realdelay / 2.0]
    $link set rdelay($onp) [expr $realdelay / 2.0]
    $link set bandwidth($np) $realbw
    $link set rbandwidth($onp) $realbw
    $link set loss($np) [expr $adjloss]
    $link set rloss($onp) [expr $adjloss]
}

proc tb-set-lan-simplex-params {lan node todelay tobw toloss fromdelay frombw fromloss} {
    var_import ::TBCOMPAT::FLOAT
    if {[$node info class] != "Node"} {
Mike Hibler's avatar
Mike Hibler committed
782
	perror "\[tb-set-lan-simplex-params] $node is not a node."
783
784
785
	return
    }
    if {[$lan info class] != "Lan"} {
Mike Hibler's avatar
Mike Hibler committed
786
	perror "\[tb-set-lan-simplex-params] $lan is not a lan."
787
788
789
790
	return
    }
    set port [$lan get_port $node]
    if {$port == {}} {
Mike Hibler's avatar
Mike Hibler committed
791
	perror "\[tb-set-lan-simplex-params] $node is not in $lan."
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
	return
    }
    if {([regexp $FLOAT $toloss] == 0) || ($toloss > 1.0)} {
	perror "\[tb-set-link-loss] $toloss is not a valid loss rate."
    }
    if {([regexp $FLOAT $fromloss] == 0) || ($fromloss > 1.0)} {
	perror "\[tb-set-link-loss] $fromloss is not a valid loss rate."
    }

    set realtodelay [parse_delay $todelay]
    set realfromdelay [parse_delay $fromdelay]
    set realtobw [parse_bw $tobw]
    set realfrombw [parse_bw $frombw]

    $lan set delay([list $node $port]) $realtodelay
    $lan set rdelay([list $node $port]) $realfromdelay
    $lan set loss([list $node $port]) $toloss
    $lan set rloss([list $node $port]) $fromloss
    $lan set bandwidth([list $node $port]) $realtobw
    $lan set rbandwidth([list $node $port]) $realfrombw
812
813
814
}

proc tb-set-uselatestwadata {onoff} {
815
    var_import ::GLOBALS::uselatestwadata
816
817
818
819
820
821
822
823

    if {$onoff != 0 && $onoff != 1} {
	perror "\[tb-set-uselatestwadata] $onoff must be 0/1"
	return
    }

    set uselatestwadata $onoff
}
824

825
826
827
828
829
830
831
832
833
834
835
proc tb-set-usewatunnels {onoff} {
    var_import ::GLOBALS::usewatunnels

    if {$onoff != 0 && $onoff != 1} {
	perror "\[tb-set-usewatunnels] $onoff must be 0/1"
	return
    }

    set usewatunnels $onoff
}

836
proc tb-use-endnodeshaping {onoff} {
837
838
839
    var_import ::GLOBALS::uselinkdelays

    if {$onoff != 0 && $onoff != 1} {
840
	perror "\[tb-use-endnodeshaping] $onoff must be 0/1"
841
842
843
844
845
846
	return
    }

    set uselinkdelays $onoff
}

847
proc tb-force-endnodeshaping {onoff} {
848
849
850
    var_import ::GLOBALS::forcelinkdelays

    if {$onoff != 0 && $onoff != 1} {
851
	perror "\[tb-force-endnodeshaping] $onoff must be 0/1"
852
853
854
855
856
857
	return
    }

    set forcelinkdelays $onoff
}

858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
proc tb-set-wasolver-weights {delay bw plr} {
    var_import ::GLOBALS::wa_delay_solverweight
    var_import ::GLOBALS::wa_bw_solverweight
    var_import ::GLOBALS::wa_plr_solverweight

    if {($delay < 0) || ($bw < 0) || ($plr < 0)} {
	perror "\[tb-set-wasolver-weights] Weights must be postive integers."
	return
    }
    if {($delay == {}) || ($bw == {}) || ($plr == {})} {
	perror "\[tb-set-wasolver-weights] Must provide delay, bw, and plr."
	return
    }

    set wa_delay_solverweight $delay
    set wa_bw_solverweight $bw
    set wa_plr_solverweight $plr
}
876
877

#
878
# Control emulated for a link
879
# 
880
881
882
proc tb-set-multiplexed {lanlink onoff} {
    if {[$lanlink info class] != "Link" && [$lanlink info class] != "Lan" } {
	perror "\[tb-set-multiplexed] $link is not a link or a lan."
883
884
	return
    }
885
    $lanlink set emulated $onoff
886
887
888
}

#
889
# For emulated links, allow bw shaping to be turned off
890
# 
891
892
893
proc tb-set-noshaping {lanlink onoff} {
    if {[$lanlink info class] != "Link" && [$lanlink info class] != "Lan" } {
	perror "\[tb-set-noshaping] $link is not a link or a lan."
894
895
	return
    }
896
    $lanlink set nobwshaping $onoff
897
}
898

899
900
901
#
# For emulated links, allow veth device to be used. Not a user option.
# 
902
903
904
proc tb-set-useveth {lanlink onoff} {
    if {[$lanlink info class] != "Link" && [$lanlink info class] != "Lan"} {
	perror "\[tb-set-useveth] $link is not a link or a lan."
905
906
	return
    }
907
    $lanlink set useveth $onoff
908
909
}

910
911
912
913
914
915
#
# Control linkdelays for lans and links
# 
proc tb-set-endnodeshaping {lanlink onoff} {
    if {[$lanlink info class] != "Link" && [$lanlink info class] != "Lan"} {
	perror "\[tb-set-endnodeshaping] $lanlink is not a link or a lan."
916
917
	return
    }
918
    $lanlink set uselinkdelay $onoff
919
}
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947

#
# Crude control of colocation of virt nodes. Will be flushed when we have
# a real story. Sets it for the entire link or lan. Maybe set it on a
# per node basis?
#
proc tb-set-allowcolocate {lanlink onoff} {
    if {[$lanlink info class] != "Link" && [$lanlink info class] != "Lan"} {
	perror "\[tb-set-allowcolocate] $lanlink is not a link or a lan."
	return
    }
    $lanlink set trivial_ok $onoff
}

#
# Another crude control. Allow override of multiplex factor that is listed
# in the node_types table. 
#
proc tb-set-colocate-factor {factor} {
    var_import ::GLOBALS::multiplex_factor

    if {$factor < 1 || $factor > 100} {
	perror "\[tb-set-colocate-factor] factor must be 1 <= factor <= 100"
	return
    }

    set multiplex_factor $factor
}
948
949
950
951
952
953
954
955
956
957
958
959
960
961

#
# Set the sync server for the experiment. Must a vnode name that has been
# allocated.
#
proc tb-set-sync-server {node} {
    var_import ::GLOBALS::sync_server

    if {[$node info class] != "Node"} {
	perror "\[tb-set-sync-server] $node is not a node."
	return
    }
    set sync_server $node
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
962

963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
#
# Turn on or of the ipassign program for IP address assignment and route
# calculation
#
proc tb-use-ipassign {onoff} {
    var_import ::GLOBALS::use_ipassign

    set use_ipassign $onoff
}

#
# Give arguments for ipassign
#
proc tb-set-ipassign-args {stuff} {
    var_import ::GLOBALS::ipassign_args

    set ipassign_args $stuff
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
982
983
984
985
986
#
# Set the startup command for a node. Replaces the tb-set-node-startup
# command above, but we have to keep that one around for a while. This
# new version dispatched to the node object, which uses a program object.
# 
987
proc tb-set-node-startcmd {node command} {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
988
    if {[$node info class] != "Node"} {
989
	perror "\[tb-set-node-startcmd] $node is not a node."
Leigh B. Stoller's avatar
Leigh B. Stoller committed
990
991
	return
    }
992
    set command "($command ; /usr/local/etc/emulab/startcmddone \$?)"
993
994
995
    set newprog [$node start-command $command]

    return $newprog
Leigh B. Stoller's avatar
Leigh B. Stoller committed
996
}
997
998
999
1000

#
# More crude controls.
#
For faster browsing, not all history is shown. View entire blame