Changeset 2c51061


Ignore:
Timestamp:
Jun 1, 2010 11:41:09 AM (15 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
9e38ded
Parents:
1502580
Message:

Make it easier to follow compositions by using the non-numeric stems of user specified node names as the basis for names in the composed experiment.

Also added an option to output textbed commands in the ns2 output.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/compose.py

    r1502580 r2c51061  
    164164                action='store_true',
    165165                help='add testbed attributes to each component')
     166        self.add_option('--output_testbeds', dest='output_testbeds',
     167                default=False, action='store_true',
     168                help='Output tb-set-node-testbed commands to ns2')
    166169        self.add_option('--lax', dest='lax', default=False,
    167170                action='store_true',
     
    218221    return n
    219222
     223def base_name(n):
     224    """
     225    Extract a base name of the node to use for constructing a non-colliding
     226    name.  This makes the composed topologies a little more readable.  It's a
     227    single regexp, but the function name is more meaningful.
     228    """
     229    return re.sub('\d+$', '',n)
     230
     231
     232
    220233def localize_names(top, names, marks):
    221234    """
     
    232245        s.set_attribute('localized_name', s.name)
    233246        if s.name in names:
    234             sub_map[s.name] = n = make_new_name(names, "substrate")
     247            sub_map[s.name] = n = make_new_name(names, base_name(s.name))
    235248            s.name = n
    236249        else:
     
    240253        e.set_attribute('localized_name', e.name)
    241254        if e.name in names:
    242             nn= make_new_name(names, "node")
     255            nn= make_new_name(names, base_name(e.name))
    243256            for c in marks.get(e.name, []):
    244257                c.name = nn
     
    469482
    470483
    471 def output_composition(top, constraints, outfile=None, format=None):
     484def output_composition(top, constraints, outfile=None, format=None,
     485        output_testbeds=False):
    472486    """
    473487    Output the composition to the file named by outfile (if any) in the format
    474488    given by format if any.  If both are None, output to stdout in topdl
    475489    """
    476     def xml_out(f, top, constraints):
     490    def xml_out(f, top, constraints, output_testbeds):
    477491        """
    478492        Output into topdl.  Just call the topdl output, as the constraint
     
    488502        print >>f, "</component>"
    489503
    490     def ns2_out(f, top, constraints):
     504    def ns2_out(f, top, constraints, output_testbeds):
    491505        """
    492506        Reformat the constraint data structures into ns2 constraint comments
     
    505519            if x: return "required"
    506520            else: return "optional"
     521
     522        def testbed_filter(e):
     523            if isinstance(e, topdl.Computer) and e.get_attribute('testbed'):
     524                return 'tb-set-node-testbed ${%s} "%s"' % \
     525                        (topdl.to_tcl_name(e.name), e.get_attribute('testbed'))
     526            else:
     527                return ""
     528
     529        if output_testbeds: filters = [ testbed_filter ]
     530        else: filters = [ ]
    507531       
    508532        # ns2_out main line
     
    512536                    required_format(c.required), ",".join(c.provides),
    513537                    ",".join(c.accepts))
    514         print >>f, topdl.topology_to_ns2(top)
     538        print >>f, topdl.topology_to_ns2(top, filters=filters)
    515539
    516540    # Info to map from format to output routine. 
     
    540564    if outfile: f = open(outfile, "w")
    541565    else: f = sys.stdout
    542     exporter(f, top, constraints)
     566    exporter(f, top, constraints, output_testbeds)
    543567    if outfile: f.close()
    544568
     
    667691# Put out the composition with only the unmatched constraints
    668692output_composition(comp, [c for c in constraints if not c.match],
    669         opts.outfile, opts.format)
     693        opts.outfile, opts.format, opts.output_testbeds)
    670694
    671695sys.exit(0)
Note: See TracChangeset for help on using the changeset viewer.