示例#1
0
 def link_event_to_topology(self, s1, s2):
     """
     Add switches to networkx topology graph and check for loops
     if our topology contains loops we calculate the spanning tree
     to be used for the first packets when destination will be unknown
     Args:
         s1: first switch in the link ex. "00-00-00-00-00-01"
         s2: second switch in the link ex. "00-00-00-00-00-02"
     Returns: nada
     """
     self.topology.add_edge(s1, s2, weight=100)  # the port of the second switch
     try:
         self.loop = nx.cycle_basis(self.topology)[0]
         self.spanning_tree = spanning_tree._calc_spanning_tree()
     except:
         self.loop = []
示例#2
0
def _handle_links (event):
  """
  Handle discovery link events to update the spanning tree
  """
  global tree
  tree = spanning_tree._calc_spanning_tree()