Changeset 6c57fe9
- Timestamp:
- Sep 2, 2009 10:36:18 AM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-2.00, version-3.01, version-3.02
- Children:
- f9ef40b
- Parents:
- cc8d8e9
- Location:
- fedd/federation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/access.py
rcc8d8e9 r6c57fe9 18 18 from remote_service import xmlrpc_handler, soap_handler, service_caller 19 19 20 import topdl 21 import httplib 22 import tempfile 23 from urlparse import urlparse 24 20 25 21 26 # Make log messages disappear if noone configures a fedd logger … … 57 62 self.fileserver = config.get("access", "fileserver") 58 63 self.eventserver = config.get("access", "eventserver") 64 self.certdir = config.get("access","certdir") 59 65 60 66 self.attrs = { } … … 649 655 for o in owners: 650 656 self.auth.set_attribute(o, allocID) 657 try: 658 f = open("%s/%s.pem" % (self.certdir, aid), "w") 659 print >>f, alloc_cert 660 f.close() 661 except IOError, e: 662 raise service_error(service_error.internal, 663 "Can't open %s/%s : %s" % (self.certdir, aid, e)) 651 664 resp = self.build_response({ 'fedid': allocID } , ap) 652 665 return resp … … 1124 1137 1125 1138 def StartSegment(self, req, fid): 1139 def get_url(url, cf, tmpdir): 1140 po = urlparse(url) 1141 fn = po.path.rpartition('/')[2] 1142 try: 1143 conn = httplib.HTTPSConnection(po.hostname, port=po.port, 1144 cert_file=cf, key_file=cf) 1145 conn.putrequest('GET', po.path) 1146 conn.endheaders() 1147 response = conn.getresponse() 1148 1149 lf = open("%s/%s" % (tmpdir, fn), "w") 1150 buf = response.read(4096) 1151 while buf: 1152 lf.write(buf) 1153 buf = response.read(4096) 1154 lf.close() 1155 except IOError, e: 1156 raise service_error(service_error.internal, 1157 "Erro writing tempfile: %s" %e) 1158 except httplib.HTTPException, e: 1159 raise service_error(service_error.internal, 1160 "Error retrieving data: %s" % e) 1161 1162 configs = set(('hosts', 'ssh_pubkey', 'ssh_secretkey')) 1163 1164 1126 1165 try: 1127 1166 req = req['StartSegmentRequestBody'] … … 1129 1168 raise service_error(server_error.req, "Badly formed request") 1130 1169 auth_attr = req['allocID']['fedid'] 1170 attrs = req.get('fedAttr', []) 1171 print auth_attr 1172 print "%s" % auth_attr 1131 1173 if self.auth.check_attribute(fid, auth_attr): 1132 1174 print "OK" 1133 1175 else: 1134 1176 print "Fail" 1177 1178 if req.has_key('segmentdescription') and \ 1179 req['segmentdescription'].has_key('topdldescription'): 1180 topo = \ 1181 topdl.Topology(**req['segmentdescription']['topdldescription']) 1182 else: 1183 raise service_error(service_error.req, 1184 "Request missing segmentdescription'") 1185 1186 certfile = "%s/%s.pem" % (self.certdir, auth_attr) 1187 try: 1188 tmpdir = tempfile.mkdtemp(prefix="access-") 1189 except IOError: 1190 raise service_error(service_error.internal, "Cannot create tmp dir") 1191 1192 sw = set() 1193 for e in [c for c in topo.elements if getattr(c, 'software', False)]: 1194 for s in e.software: 1195 sw.add(s.location) 1196 for s in sw: 1197 get_url(s, certfile, tmpdir) 1198 1199 for a in attrs: 1200 if a['attribute'] in configs: 1201 get_url(a['value'], certfile, tmpdir) 1202 1135 1203 return { 'allocID': req['allocID'] } -
fedd/federation/experiment_control.py
rcc8d8e9 r6c57fe9 18 18 import xml.parsers.expat 19 19 20 from threading import *21 from subprocess import *20 from threading import Lock, Thread, Condition 21 from subprocess import call, Popen, PIPE 22 22 23 23 from urlparse import urlparse … … 232 232 or config.get("globals", "trusted_certs") 233 233 234 # XXX: 235 self.repodir = '/usr/local/etc/fedd/repo' 234 self.repodir = config.get("experiment_control", "repodir") 236 235 237 236 self.exp_stem = "fed-stem" … … 2152 2151 self.caller = caller 2153 2152 2154 def __call__(self, uri, aid, topo ):2153 def __call__(self, uri, aid, topo, attrs=None): 2155 2154 req = { 2156 2155 'allocID': { 'fedid' : aid }, … … 2159 2158 }, 2160 2159 } 2161 2162 print "calling %s" % uri 2160 if attrs: 2161 req['fedAttr'] = attrs 2162 2163 2163 r = self.caller(uri, req, self.cert_file, self.cert_pwd, 2164 2164 self.trusted_certs) … … 2170 2170 2171 2171 def new_allocate_resources(self, allocated, master, eid, expid, expcert, 2172 tbparams, topo, tmpdir, alloc_log=None ):2172 tbparams, topo, tmpdir, alloc_log=None, attrs=None): 2173 2173 started = { } # Testbeds where a sub-experiment started 2174 2174 # successfully … … 2203 2203 trusted_certs=self.trusted_certs, 2204 2204 caller=self.call_StartSegment), 2205 args=(uri, aid, topo[tb] ), name=tb,2205 args=(uri, aid, topo[tb], attrs), name=tb, 2206 2206 pdata=thread_pool, trace_file=self.trace_file) 2207 2207 threads.append(t) … … 2294 2294 to instantiate them and start it all up. 2295 2295 """ 2296 2297 def add_kit(e, kit): 2298 """ 2299 Add a Software object created from the list of (install, location) 2300 tuples passed as kit to the software attribute of an object e. We 2301 do this enough to break out the code, but it's kind of a hack to 2302 avoid changing the old tuple rep. 2303 """ 2304 2305 s = [ topdl.Software(install=i, location=l) for i, l in kit] 2306 2307 if isinstance(e.software, list): e.software.extend(s) 2308 else: e.software = s 2309 2296 2310 2297 2311 if not self.auth.check_attribute(fid, 'create'): … … 2463 2477 reverse=True) 2464 2478 ips = ip_allocator(int(ip_addr("10.0.0.0")), 2 **24) 2465 for s in subs: 2479 ifs = { } 2480 hosts = [ ] 2481 # The config urlpath 2482 configpath = "/%s/config" % expid 2483 # The config file system location 2484 configdir ="%s%s" % ( self.repodir, configpath) 2485 2486 for idx, s in enumerate(subs): 2466 2487 a = ips.allocate(len(s.interfaces)+2) 2467 2488 if a : … … 2479 2500 topdl.Attribute('ip4_address', 2480 2501 "%s" % ip_addr(base))) 2502 hname = i.element.name[0] 2503 if ifs.has_key(hname): 2504 hosts.append("%s\t%s-%s %s-%d" % \ 2505 (ip_addr(base), hname, s.name, hname, 2506 ifs[hname])) 2507 else: 2508 ifs[hname] = 0 2509 hosts.append("%s\t%s-%s %s-%d %s" % \ 2510 (ip_addr(base), hname, s.name, hname, 2511 ifs[hname], hname)) 2512 2513 ifs[hname] += 1 2481 2514 base += 1 2482 2515 # save config files 2516 try: 2517 os.makedirs(configdir) 2518 except IOError, e: 2519 raise service_error( 2520 "Cannot create config directory: %s" % e) 2483 2521 # Find the testbeds to look up 2484 2522 testbeds = set([ a.value for e in top.elements \ 2485 2523 for a in e.attribute \ 2486 2524 if a.attribute == 'testbed'] ) 2525 2487 2526 2488 2527 # Make per testbed topologies. Copy the main topo and remove … … 2510 2549 topo[tb].make_indices() 2511 2550 2512 2551 for e in topo[tb].elements: 2552 if tb == master: 2553 cmd = 'sudo -H /usr/local/federation/bin/make_hosts /proj/%s/exp/%s/tmp/hosts >& /tmp/federate' % (tbparams[tb].get('project', 'project'), eid) 2554 else: 2555 cmd = "sudo -H /bin/sh /usr/local/federation/bin/federate.sh >& /tmp/federate" 2556 scmd = e.get_attribute('startup') 2557 if scmd: 2558 cmd = "%s \\$USER '%s'" % (cmd, scmd) 2559 2560 e.set_attribute('startup', cmd) 2561 if self.fedkit: add_kit(e, self.fedkit) 2562 2563 # Copy configuration files into the remote file store 2564 try: 2565 f = open("%s/hosts" % configdir, "w") 2566 f.write('\n'.join(hosts)) 2567 f.close() 2568 except IOError, e: 2569 raise service_error(service_error.internal, 2570 "Cannot write hosts file: %s" % e) 2571 try: 2572 self.copy_file("%s" % gw_pubkey, "%s/%s" % \ 2573 (configdir, gw_pubkey_base)) 2574 self.copy_file("%s" % gw_secretkey, "%s/%s" % \ 2575 (configdir, gw_secretkey_base)) 2576 except IOError, e: 2577 raise service_error(service_error.internal, 2578 "Cannot copy keyfiles: %s" % e) 2579 2580 # Allow the individual testbeds to access the configuration files. 2581 for tb in tbparams.keys(): 2582 asignee = tbparams[tb]['allocID']['fedid'] 2583 for f in ("hosts", gw_secretkey_base, gw_pubkey_base): 2584 self.auth.set_attribute(asignee, "%s/%s" % (configpath, f)) 2585 print "assigned %s/%s" % (configpath, f) 2513 2586 2514 2587 # Now, for each substrate in the main topology, find those that … … 2516 2589 # into the copies of those substrates on the sub topologies. 2517 2590 for s in top.substrates: 2518 tests = { } 2591 # tbs will contain an ip address on this subsrate that is in 2592 # each testbed. 2593 tbs = { } 2519 2594 for i in s.interfaces: 2520 2595 e = i.element 2521 2596 tb = e.get_attribute('testbed') 2522 if tb and not t ests.has_key(tb):2597 if tb and not tbs.has_key(tb): 2523 2598 for i in e.interface: 2524 2599 if s in i.subs: 2525 tests[tb]= \ 2526 i.get_attribute('ip4_address') 2527 if len(tests) < 2: 2600 tbs[tb]= i.get_attribute('ip4_address') 2601 if len(tbs) < 2: 2528 2602 continue 2529 2603 2530 2604 # More than one testbed is on this substrate. Insert 2531 # some portals into the subtopologies. 2532 2533 for st in tests.keys(): 2534 for dt in [ t for t in tests.keys() if t != st]: 2605 # some portals into the subtopologies. st == source testbed, 2606 # dt == destination testbed. 2607 segment_substrate = { } 2608 for st in tbs.keys(): 2609 segment_substrate[st] = { } 2610 for dt in [ t for t in tbs.keys() if t != st]: 2535 2611 myname = "%stunnel" % dt 2536 2612 desthost = "%stunnel" % st … … 2541 2617 ddomain = ".%s.%s%s" % (eid, dproject, 2542 2618 tbparams[dt].get('domain', ".example.com")) 2543 boss = tbparams[master].get('boss', "boss") 2544 fs = tbparams[master].get('fs', "fs") 2545 event_server = "%s%s" % \ 2546 (tbparams[st].get('eventserver', "event_server"), 2547 tbparams[dt].get('domain', "example.com")) 2548 remote_event_server = "%s%s" % \ 2549 (tbparams[dt].get('eventserver', "event_server"), 2550 tbparams[dt].get('domain', "example.com")) 2551 seer_control = "%s%s" % \ 2552 (tbparams[st].get('control', "control"), sdomain) 2553 local_key_dir = "/proj/%s/exp/%s/tmp" % ( sproject, eid) 2554 remote_conf_dir = "/proj/%s/exp/%s/tmp" % ( dproject, eid) 2555 conf_file = "%s%s.gw.conf" % (myname, sdomain) 2556 remote_conf_file = "%s%s.gw.conf" % (desthost, ddomain) 2557 # translate to lower case so the `hostname` hack for specifying 2558 # configuration files works. 2559 conf_file = conf_file.lower(); 2560 remote_conf_file = remote_conf_file.lower(); 2619 mdomain = "%s.%s%s" % (eid, 2620 tbparams[master].get('project', 'project'), 2621 tbparams[master].get('domain', '.example.com')) 2622 # XXX: active and type need to be unkludged 2561 2623 active = ("%s" % (st == master)) 2562 portal = topdl.Computer(**{ 2563 'name': "%stunnel" % dt, 2564 'attribute' : [{ 2565 'attribute': n, 2566 'value': v, 2567 } for n, v in (\ 2568 ('gateway', 'true'), 2569 ('boss', boss), 2570 ('fs', fs), 2571 ('event_server', event_server), 2572 ('remote_event_server', remote_event_server), 2573 ('seer_control', seer_control), 2574 ('local_key_dir', local_key_dir), 2575 ('remote_conf_dir', remote_conf_dir), 2576 ('conf_file', conf_file), 2577 ('remote_conf_file', remote_conf_file), 2578 ('remote_script_dir', "/usr/local/federation/bin"), 2579 ('local_script_dir', "/usr/local/federation/bin"), 2580 )], 2581 'interface': [{ 2582 'substrate': s.name, 2583 'attribute': [ { 2584 'attribute': 'ip4_addreess', 2585 'value': tests[dt], 2586 }, ], 2587 }, ], 2588 }) 2624 if not segment_substrate[st].has_key(dt): 2625 # Put a substrate and a segment for the connected 2626 # testbed in there. 2627 tsubstrate = \ 2628 topdl.Substrate(name='%s-%s' % (st, dt)) 2629 segment_element = topdl.Segment( 2630 id= tbparams[dt]['allocID'], 2631 type='emulab', 2632 uri = self.tbmap.get(dt, None), 2633 interface=[ 2634 topdl.Interface( 2635 substrate=tsubstrate.name), 2636 ], 2637 attribute = [ 2638 topdl.Attribute(attribute=n, value=v) 2639 for n, v in (\ 2640 ('domain', ddomain), 2641 ('experiment', "%s/%s" % \ 2642 (dproject, eid)),) 2643 ], 2644 ) 2645 segment_substrate[st][dt] = tsubstrate 2646 topo[st].substrates.append(tsubstrate) 2647 topo[st].elements.append(segment_element) 2648 portal = topdl.Computer( 2649 name="%stunnel" % dt, 2650 attribute=[ 2651 topdl.Attribute(attribute=n,value=v) 2652 for n, v in (\ 2653 ('portal', 'true'), 2654 ('masterdomain', mdomain), 2655 ('experiment', "%s/%s" % \ 2656 (sproject, eid)), 2657 ('peer', "%s.%s" % \ 2658 (desthost, ddomain)), 2659 ('scriptdir', 2660 "/usr/local/federation/bin"), 2661 ('active', "%s" % active), 2662 ('type', 'both'), 2663 ('startup', 'sudo -H /usr/local/federation/bin/fed-tun.pl -f /proj/%s/exp/%s/tmp/%s%s.gw.conf >& /tmp/bridge.log' % (sproject, eid, myname.lower(), sdomain.lower()))) 2664 ], 2665 interface=[ 2666 topdl.Interface( 2667 substrate=s.name, 2668 attribute=[ 2669 topdl.Attribute( 2670 attribute='ip4_addreess', 2671 value=tbs[dt] 2672 ) 2673 ]), 2674 topdl.Interface( 2675 substrate=\ 2676 segment_substrate[st][dt].name 2677 ), 2678 ], 2679 ) 2680 if self.fedkit: add_kit(portal, self.fedkit) 2681 if self.gatewaykit: add_kit(portal, self.gatewaykit) 2682 2589 2683 topo[st].elements.append(portal) 2684 2590 2685 # Connect the gateway nodes into the topologies and clear out 2591 2686 # substrates that are not in the topologies … … 2626 2721 try: 2627 2722 f = open("%s/%s" % (softdir, dest) , "w") 2723 self.log.debug("Writing %s/%s" % (softdir,dest) ) 2628 2724 data = u.read(4096) 2629 2725 while data: … … 2644 2740 for tb in tbparams.keys(): 2645 2741 self.auth.set_attribute(tbparams[tb]['allocID']['fedid'], 2646 " %s/%s" % ( path, dest))2742 "/%s/%s" % ( path, dest)) 2647 2743 2648 2744 # Convert the software locations in the segments into the local … … 2650 2746 for soft in [ s for tb in topo.values() \ 2651 2747 for e in tb.elements \ 2652 for s in e.software ]: 2748 if getattr(e, 'software', False) \ 2749 for s in e.software ]: 2653 2750 if softmap.has_key(soft.location): 2654 2751 soft.location = softmap[soft.location] … … 2709 2806 alloc_log.addHandler(h) 2710 2807 2808 # XXX 2809 url_base = 'https://users.isi.deterlab.net:23232' 2810 attrs = [ 2811 { 2812 'attribute': 'ssh_pubkey', 2813 'value': '%s/%s/config/%s' % \ 2814 (url_base, expid, gw_pubkey_base) 2815 }, 2816 { 2817 'attribute': 'ssh_secretkey', 2818 'value': '%s/%s/config/%s' % \ 2819 (url_base, expid, gw_secretkey_base) 2820 }, 2821 { 2822 'attribute': 'hosts', 2823 'value': '%s/%s/config/hosts' % \ 2824 (url_base, expid) 2825 }, 2826 ] 2827 2711 2828 # Start a thread to do the resource allocation 2712 2829 t = Thread(target=self.new_allocate_resources, 2713 2830 args=(allocated, master, eid, expid, expcert, tbparams, 2714 topo, tmpdir, alloc_log ),2831 topo, tmpdir, alloc_log, attrs), 2715 2832 name=eid) 2716 2833 t.start() … … 2774 2891 2775 2892 def get_handler(self, path, fid): 2776 print "in get_handler %s %s" % (path, fid) 2777 return ("/users/faber/test.html", "text/html") 2893 print "%s" % path 2894 if self.auth.check_attribute(fid, path): 2895 return ("%s/%s" % (self.repodir, path), "application/binary") 2896 else: 2897 return (None, None) 2778 2898 2779 2899 def get_vtopo(self, req, fid): -
fedd/federation/server.py
rcc8d8e9 r6c57fe9 140 140 code = 200 141 141 fid = fedid(cert=self.request.get_peer_cert()) 142 print "in do_GET: %s %s" % (fid, self.request.get_peer_cert())143 142 fname, type = self.server.get_handler(self.path, fid) 144 try: 145 f = open(fname, "rb") 146 size = os.path.getsize(fname) 147 except IOError, e: 143 if fname: 144 try: 145 f = open(fname, "rb") 146 size = os.path.getsize(fname) 147 except IOError, e: 148 code = 404 149 size = 0 150 else: 148 151 code = 404 149 152 size = 0 -
fedd/federation/topdl.py
rcc8d8e9 r6c57fe9 1 1 #!/usr/local/bin/python 2 3 import re 2 4 3 5 class base: … … 31 33 return rv 32 34 33 35 def set_attribute(self, key, value): 36 attrs = getattr(self, 'attribute', None) 37 if attrs is None: 38 return 39 for a in attrs: 40 if a.attribute == key: 41 a.value = value 42 break 43 else: 44 attrs.append(Attribute(key, value)) 34 45 35 46 class ConsistencyError(RuntimeError): pass … … 207 218 if self.attribute: 208 219 rv['attribute'] = [ a.to_dict() for a in self.attribute ] 220 return rv 221 222 class ID(base): 223 def __init__(self, fedid=None, uuid=None, uri=None, localname=None, 224 kerberosUsername=None): 225 self.fedid=fedid 226 self.uuid = uuid 227 self.uri = uri 228 self.localname = localname 229 self.kerberosUsername = kerberosUsername 230 231 def clone(self): 232 return ID(self.fedid, self.uuid, self.uri, self.localname, 233 self.kernberosUsername) 234 235 def to_dict(self): 236 rv = { } 237 if self.fedid: rv['fedid'] = self.fedid 238 if self.uuid: rv['uuid'] = self.uuid 239 if self.uri: rv['uri'] = self.uri 240 if self.localname: rv['localname'] = self.localname 241 if self.kerberosUsername: rv['kerberosUsername'] = self.kerberosUsername 209 242 return rv 210 243 … … 256 289 return { 'computer': rv } 257 290 291 292 class Testbed(base): 293 def __init__(self, uri, type, interface=[], attribute=[]): 294 self.uri = uri 295 self.type = type 296 self.interface = [ self.init_class(Interface, c) \ 297 for c in self.make_list(interface) ] 298 self.attribute = [ self.init_class(Attribute, c) \ 299 for c in self.make_list(attribute) ] 300 301 def clone(self): 302 return Testbed(self.uri, self.type, 303 interface=[i.clone() for i in self.interface], 304 attribute=[a.cone() for a in self.attribute]) 305 306 def to_dict(self): 307 rv = { } 308 if self.uri: rv['uri'] = self.uri 309 if self.type: rv['type'] = self.type 310 if self.interface: 311 rv['interface'] = [ i.to_dict() for i in self.interface] 312 if self.attribute: 313 rv['attribute'] = [ a.to_dict() for a in self.attribute] 314 return { 'testbed': rv } 315 316 class Segment(base): 317 def __init__(self, id, type, uri, interface=[], attribute=[]): 318 self.id = self.init_class(ID, id) 319 self.type = type 320 self.uri = uri 321 self.interface = [ self.init_class(Interface, c) \ 322 for c in self.make_list(interface) ] 323 self.attribute = [ self.init_class(Attribute, c) \ 324 for c in self.make_list(attribute) ] 325 326 def clone(self): 327 return Segment(self.id.clone(), self.type, self.uri, 328 interface=[i.clone() for i in self.interface], 329 attribute=[a.clone() for a in attribute]) 330 331 def to_dict(self): 332 rv = { } 333 if self.id: rv['id'] = self.id.to_dict() 334 if self.type: rv['type'] = self.type 335 if self.uri: rv['uri'] = self.uri 336 if self.interface: 337 rv['interface'] = [ i.to_dict() for i in self.interface ] 338 if self.attribute: 339 rv['attribute'] = [ a.to_dict() for a in self.attribute ] 340 return { 'segment': rv } 341 342 258 343 class Other(base): 259 344 def __init__(self, interface=[], attribute=[]): … … 268 353 269 354 def to_dict(self): 355 rv = {} 270 356 if self.interface: 271 357 rv['interface'] = [ i.to_dict() for i in self.interface ] 272 358 if self.attribute: 273 359 rv['attribute'] = [ a.to_dict() for a in self.attribute ] 360 return {'other': rv } 274 361 275 362 … … 285 372 classmap = { 286 373 'computer': Computer, 374 'testbed': Testbed, 375 'segment': Segment, 287 376 'other': Other, 288 377 } … … 489 578 return { 'node': nodes, 'lan': lans } 490 579 491 def topology_to_ns2(t): 580 def to_tcl_name(n): 581 t = re.subst('-(\d+)', '(\1)', n) 582 return t 583 584 def generate_portal_image_filter(image): 585 def rv(e): 586 s ="" 587 if isinstance(e, Computer): 588 gw = e.get_attribute('portal') 589 if gw: 590 s = "tb-set-node-os $%s %s" % (to_tcl_name(e.name[0]), image) 591 return s 592 return rv 593 594 def generate_portal_command_filter(cmd): 595 def rv(e): 596 s ="" 597 if isinstance(e, Computer): 598 gw = e.get_attribute('portal') 599 if gw: 600 s = "%s $%s" % (cmd, to_tcl_name(e.name[0])) 601 return s 602 return rv 603 604 605 def topology_to_ns2(t, filters=[]): 492 606 out = """ 493 607 set ns [new Simulator] … … 495 609 496 610 """ 611 497 612 for e in t.elements: 498 613 rpms = "" 499 614 tarfiles = "" 500 615 if isinstance(e, Computer): 501 name = e.name[0]616 name = to_tcl_name(e.name[0]) 502 617 out += "set %s [$ns node]\n" % name 503 618 if e.os and len(e.os) == 1: … … 517 632 if startcmd: 518 633 out+= 'tb-set-node-startcmd $%s "%s"\n' % (name, startcmd) 634 for f in filters: 635 out += f(e) 519 636 out+= "\n" 520 637 … … 525 642 else: 526 643 delay = 0 527 name = s.name or "sub%d" % idx644 name = to_tcl_name(s.name or "sub%d" % idx) 528 645 529 646 if len(s.interfaces) > 2: 530 647 # Lan 531 members = [ i.element.name[0] for i in s.interfaces] 532 out += 'set %s [$ns make-lan "%s" %f %fms ]\n' % \ 648 members = [ to_tcl_name("$%s") % i.element.name[0] \ 649 for i in s.interfaces] 650 out += 'set %s [$ns make-lan "%s" %fkb %fms ]\n' % \ 533 651 (name, " ".join(members), s.capacity.rate, delay) 534 652 if loss: … … 541 659 out += "tb-set-ip-lan $%s $%s %s\n" % (e.name, name, ip) 542 660 if i.capacity and i.capacity.rate != s.capacity.rate: 543 out += "tb-set-node-lan-bandwidth $%s $%s %f \n" % \544 ( e.name[0], name, i.capacity.rate)661 out += "tb-set-node-lan-bandwidth $%s $%s %fkb\n" % \ 662 (to_tcl_name(e.name[0]), name, i.capacity.rate) 545 663 if i.latency and i.latency.time != delay: 546 664 out += "tb-set-node-lan-delay $%s $%s %fms\n" % \ 547 ( e.name[0], name, i.latency.time)665 (to_tcl_name(e.name[0]), name, i.latency.time) 548 666 iloss = i.get_attribute('loss') 549 667 if loss and iloss != loss : 550 668 out += "tb-set-node-lan-loss $%s $%s %f" % \ 551 ( e.name[0], name, float(loss))669 (to_tcl_name(e.name[0]), name, float(loss)) 552 670 out+= "\n" 553 671 elif len(s.interfaces) == 2: … … 555 673 t = s.interfaces[1] 556 674 557 out += "set %s [$ns duplex-link $%s $%s %f %fms DropTail]\n" %\ 558 (name, f.element.name[0], t.element.name[0], 675 out += "set %s [$ns duplex-link $%s $%s %fkb %fms DropTail]\n" %\ 676 (name, to_tcl_name(f.element.name[0]), 677 to_tcl_name(t.element.name[0]), 559 678 s.capacity.rate, delay) 560 679 if loss: … … 577 696 else: loss = loss or 0.0 578 697 579 out += "tb-set-link-simplex-params $%s $%s %fms %f %f\n" % \ 580 (name, i.element.name[0], delay, cap, loss) 698 out += "tb-set-link-simplex-params $%s $%s %fms %fkb %f\n"\ 699 % (name, to_tcl_name(i.element.name[0]), 700 delay, cap, loss) 581 701 out+= "\n" 702 for f in filters: 703 out+= f(s) 582 704 out+=""" 583 705 $ns run
Note: See TracChangeset
for help on using the changeset viewer.