Ejemplo n.º 1
0
 def check_dest(self):
     """Check that the destination is present in the DAG and the graph"""
     dest_in_graph = self.dest in self.g
     log.debug('Checking for %s in the graph: %s', self.dest, dest_in_graph)
     if not dest_in_graph:
         log.info('Adding %s in the graph', self.dest)
         self.g.add_node(self.dest, data=Node())
         new_paths = {}
         new_paths_cost = {n: sys.maxint for n in self.g.nodes_iter()}
     dest_in_dag = self.dest in self.dag
     log.debug('Checking for the presence of %s the the DAG: %s',
               self.dest, dest_in_dag)
     if not dest_in_dag or not dest_in_graph:
         if not dest_in_dag:
             sinks = ssu.find_sink(self.dag)
         else:
             sinks = self.dag.predecessors(self.dest)
         for s in sinks:
             if not dest_in_dag:
                 log.info('Adding %s to %s in the dag', self.dest, s)
                 self.dag.add_edge(s, self.dest)
             if not dest_in_graph:
                 log.info('Adding edge (%s, %s) in the graph',
                          s, self.dest)
                 self.g.add_edge(s, self.dest, weight=self.new_edge_weight)
                 log.debug('Updating spt/cost accordingly')
                 for n in self.g.nodes_iter():
                     if n == self.dest:
                         new_paths[n] = [[n]]
                         new_paths_cost[n] = 0
                         continue
                     if not self.has_path(n, s):
                         continue
                     ns_cost = self.cost(n, s) + self.new_edge_weight
                     if ns_cost < new_paths_cost[n]:  # Created a new SP
                         ns_path = self.path(n, s)
                         new_paths_cost[n] = ns_cost
                         new_paths[n] = list(ssu.extend_paths_list(ns_path,
                                                                   self.dest
                                                                   ))
                     elif ns_cost == new_paths_cost:  # Created ECMP
                         ns_path = self.path(n, s)
                         new_paths[n].extend(ssu.extend_paths_list(ns_path,
                                                                   self.dest
                                                                   ))
     for n, p in new_paths.iteritems():  # Incrementally update the SPT
         self.register_path(n, self.dest, p, new_paths_cost[n])
Ejemplo n.º 2
0
 def add_dest_to_graphs(self, dest, dag):
     if dest not in dag:
         for node in ssu.find_sink(dag):
             logger.info('Connected %s to %s in the DAG', node, dest)
             dag.add_edge(node, dest)