if options.local: ttl=0 if len(args): readFromCmdline(args) lcm = lcm.LCM("udpm://239.255.76.67:7667?ttl=%d"%(ttl)) msg = route2_tree_t() msg.timestamp = int(time.time() * 1000000) print rtree msg.n = len(rtree) rtables=list() for (node, rtable) in rtree: rt = route2_table_t() rt.node = node rt.n = len(rtable) entries=list() for (dest,nh,w) in rtable: re = route2_entry_t() re.dest = dest re.node = nh re.weight = w entries.append(re) rt.entries = entries rtables.append(rt) msg.rtable = rtables #print msg print "publishing msg to ",options.channel
def route_to_route2(rtree): global no_sink rtree2 = route2_tree_t() rtree2.timestamp = rtree.timestamp rtables2={} """ copy the table """ for rtable in rtree.rtable: rtable2 = route2_table_t() rtable2.node = rtable.node for rentry in rtable.entries: rentry2 = route2_entry_t() rentry2.dest = 'SINK' rentry2.node = rentry.node rentry2.weight = rentry.weight if rentry.node == 'SINK' and no_sink: print "WARNING: omiting SINK by request" continue rtable2.entries.append(rentry2) rtable2.n = len(rtable2.entries) rtables2[rtable.node] = rtable2 newtables={} paths=find_paths(rtree) print "Paths",paths for p in paths: dest = p[-1] for j in range(0, len(p)-1): n = p[j] tab = {} if n in newtables: tab=newtables[n] if dest not in tab: nh = p[j+1] tab[dest]=nh newtables[n] = tab print newtables for (node, rtable) in newtables.items(): rt = route2_table_t() rt.node = node if node in rtables2: rt = rtables2[node] print node, entries=list() for (dest,nh) in rtable.items(): re = route2_entry_t() re.dest = dest re.node = nh re.weight = 1 print dest,nh, entries.append(re) print "" rt.entries += entries rt.n = len(rt.entries) rtables2[node]=rt rtables=[rtable for (node,rtable) in rtables2.items()] rtree2.rtable = rtables rtree2.n = len(rtables) return rtree2