Changeset c7a6a20 for fedd/deter


Ignore:
Timestamp:
Oct 2, 2012 2:31:32 PM (12 years ago)
Author:
Ted Faber <faber@…>
Branches:
master
Children:
995ad61
Parents:
ab662b6
Message:

Simplify link instantiation and replicate source tcl effects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/deter/topdl.py

    rab662b6 rc7a6a20  
    10781078        name = to_tcl_name(s.name or "sub%d" % idx)
    10791079
    1080         if len(s.interfaces) > 2:
    1081             # Lan
    1082             members = [ to_tcl_name("${%s}") % i.element.name \
    1083                     for i in s.interfaces]
    1084             out += 'set %s [$ns make-lan "%s" %fkb %fms ]\n' % \
    1085                     (name, " ".join([to_tcl_name(m) for m in members]),
    1086                             rate, delay)
    1087             if loss:
    1088                 "tb-set-lan-loss ${%s} %f\n" % (name, float(loss))
    1089 
    1090             for i in s.interfaces:
    1091                 e = i.element
    1092                 ip = i.get_attribute("ip4_address")
    1093                 if ip:
    1094                     out += "tb-set-ip-lan ${%s} ${%s} %s\n" % \
    1095                             (to_tcl_name(e.name), name, ip)
    1096                 if i.capacity and i.capacity.rate != rate:
    1097                     out += "tb-set-node-lan-bandwidth ${%s} ${%s} %fkb\n" % \
    1098                             (to_tcl_name(e.name), name, i.capacity.rate)
    1099                 if i.latency and i.latency.time != delay:
    1100                     out += "tb-set-node-lan-delay ${%s} ${%s} %fms\n" % \
    1101                             (to_tcl_name(e.name), name, i.latency.time)
    1102                 iloss = i.get_attribute('loss')
    1103                 if loss and iloss != loss :
    1104                     out += "tb-set-node-lan-loss ${%s} ${%s} %f\n" % \
    1105                             (to_tcl_name(e.name), name, float(loss))
    1106             out+= "\n"
    1107         elif len(s.interfaces) == 2:
    1108             f = s.interfaces[0]
    1109             t = s.interfaces[1]
    1110 
    1111             out += "set %s [$ns duplex-link ${%s} ${%s} %fkb %fms DropTail]\n" %\
    1112                     (name, to_tcl_name(f.element.name),
    1113                             to_tcl_name(t.element.name), rate, delay)
    1114             if loss:
    1115                 out += "tb-set-link-loss ${%s} %f\n" % (name, float(loss))
    1116 
    1117             for i in s.interfaces:
    1118                 lloss = i.get_attribute("loss")
    1119                 cap_override = i.capacity and \
    1120                         i.capacity.rate != rate
    1121                 delay_override = i.latency and \
    1122                         i.latency.time != delay
    1123                 loss_override = lloss and lloss != loss
    1124                 if cap_override or delay_override or loss_override:
    1125                     if i.capacity: cap = i.capacity.rate
    1126                     else: cap = rate
    1127 
    1128                     if i.latency: delay = i.latency.time
    1129 
    1130                     if lloss: loss = lloss
    1131                     else: loss = loss or 0.0
    1132 
    1133                     out += "tb-set-link-simplex-params ${%s} ${%s} %fms %fkb %f\n"\
    1134                             % (name, to_tcl_name(i.element.name),
    1135                                     delay, cap, loss)
    1136                 ip = i.get_attribute('ip4_address')
    1137                 if ip:
    1138                     out += "tb-set-ip-link ${%s} ${%s} %s\n" % \
    1139                             (to_tcl_name(i.element.name), name, ip)
    1140             out+= "\n"
     1080        # Lan
     1081        members = [ to_tcl_name("${%s}") % i.element.name \
     1082                for i in s.interfaces]
     1083        out += 'set %s [$ns make-lan "%s" %fkb %fms ]\n' % \
     1084                (name, " ".join([to_tcl_name(m) for m in members]),
     1085                        rate, 2 * delay)
     1086        if loss:
     1087            "tb-set-lan-loss ${%s} %f\n" % (name, float(loss))
     1088
     1089        for i in s.interfaces:
     1090            e = i.element
     1091            ip = i.get_attribute("ip4_address")
     1092            if ip:
     1093                out += "tb-set-ip-lan ${%s} ${%s} %s\n" % \
     1094                        (to_tcl_name(e.name), name, ip)
     1095            if i.capacity :
     1096                out += "tb-set-node-lan-bandwidth ${%s} ${%s} %fkb\n" % \
     1097                        (to_tcl_name(e.name), name, i.capacity.rate)
     1098            if i.latency :
     1099                out += "tb-set-node-lan-delay ${%s} ${%s} %fms\n" % \
     1100                        (to_tcl_name(e.name), name, i.latency.time)
     1101            iloss = i.get_attribute('loss')
     1102            if loss and iloss != loss :
     1103                out += "tb-set-node-lan-loss ${%s} ${%s} %f\n" % \
     1104                        (to_tcl_name(e.name), name, float(loss))
     1105        out+= "\n"
    11411106        for f in filters:
    11421107            out+= f(s)
Note: See TracChangeset for help on using the changeset viewer.