Generate site adjacency map from list of physical links between sites
authorAndy Bavier <acb@cs.princeton.edu>
Thu, 26 Feb 2009 19:32:11 +0000 (19:32 +0000)
committerAndy Bavier <acb@cs.princeton.edu>
Thu, 26 Feb 2009 19:32:11 +0000 (19:32 +0000)
create-topo-attributes.py

index 8f26ff8..324d09f 100755 (executable)
@@ -10,21 +10,56 @@ import string
 import socket
 
 """
-Map sites to adjacent sites in topology.  Generated manually :-(
-A site is adjacent to itself.
+Links in the physical topology, gleaned from looking at the Internet2
+and NLR topology maps.  Link (a, b) connects sites with IDs a and b.
 """
-adjacencies = {
-    1: [1], 2: [2,12], 3: [3], 4: [4,5,6,7,9,10], 5: [4,5,6,8], 
-    6: [4,5,6,10], 7: [4,7,8], 8: [5,7,8], 9: [4,9,10], 10: [4,6,9,10], 
-    11: [11,13,15,16,17], 12: [2,12,13], 13: [11,12,13,15], 14: [14], 
-    15: [11,13,15,19], 16: [11,16], 17: [11,17,19,22], 18: [18], 
-    19: [15,17,19,20], 20: [19,20,21,22], 21: [20,21,22], 22: [17,20,21,22]
-    }
+links = [(2, 12),  # I2 Princeton - New York 
+         (4, 5),   # NLR Chicago - Houston
+         (4, 6),   # NLR Chicago - Atlanta
+         (4, 7),   # NLR Chicago - Seattle
+         (4, 9),   # NLR Chicago - New York
+         (4, 10),  # NLR Chicago - Wash DC
+         (5, 6),   # NLR Houston - Atlanta
+         (5, 8),   # NLR Houston - Los Angeles
+         (6, 10),  # NLR Atlanta - Wash DC
+         (7, 8),   # NLR Seattle - Los Angeles
+         (9, 10),  # NLR New York - Wash DC
+         (11, 13), # I2 Chicago - Wash DC
+         (11, 15), # I2 Chicago - Atlanta
+         (11, 16), # I2 Chicago - CESNET
+         (11, 17), # I2 Chicago - Kansas City
+         (12, 13), # I2 New York - Wash DC
+         (13, 15), # I2 Wash DC - Atlanta
+         (15, 19), # I2 Atlanta - Houston
+         (17, 19), # I2 Kansas City - Houston
+         (17, 22), # I2 Kansas City - Salt Lake City
+         (19, 20), # I2 Houston - Los Angeles
+         (20, 21), # I2 Los Angeles - Seattle
+         (20, 22), # I2 Los Angeles - Salt Lake City
+         (21, 22)] # I2 Seattle - Salt Lake City
+
+
+"""
+Generate site adjacency map from list of links
+"""
+def gen_adjacencies(links):
+    adj = {}
+    for (a, b) in links:
+        if a in adj:
+            adj[a].append(b)
+        else:
+            adj[a] = [a, b]
+        if b in adj:
+            adj[b].append(a)
+        else:
+            adj[b] = [b, a]
+    return adj
+
 
 """
 Test whether two sites are adjacent to each other in the adjacency graph.
 """
-def is_adjacent(s1, s2):
+def is_adjacent(adjacencies, s1, s2):
     set1 = set(adjacencies[s1])
     set2 = set(adjacencies[s2])
 
@@ -39,11 +74,11 @@ def is_adjacent(s1, s2):
 """
 Check the adjacency graph for discrepancies.
 """
-def check_adjacencies():
+def check_adjacencies(adjacencies):
     for site in adjacencies:
         for adj in adjacencies[site]:
             try:
-                test = is_adjacent(site, adj)
+                test = is_adjacent(adjacencies, site, adj)
             except Exception, e:
                 print "Error: ", e, " Fix adjacencies!"
     return
@@ -100,8 +135,8 @@ def get_nodes():
         tmp.append(t)
     return dict(tmp)
 
-    
-check_adjacencies()
+adjacencies = gen_adjacencies(links)    
+check_adjacencies(adjacencies)
 
 """ Need global topology information """
 sites = get_sites()