Resolve problems with same IP address assigned to multiple interfaces
authorAndy Bavier <acb@cs.princeton.edu>
Tue, 21 Apr 2009 18:17:38 +0000 (18:17 +0000)
committerAndy Bavier <acb@cs.princeton.edu>
Tue, 21 Apr 2009 18:17:38 +0000 (18:17 +0000)
create-topo-attributes.py

index c446b94..ab4680e 100755 (executable)
@@ -13,7 +13,6 @@ from topology import links
 
 def get_adjacency_matrix(links):
     topo = {}
-    idx = 1
     for (a, b) in links:
         aNodes = get_sitenodes(a)
         bNodes = get_sitenodes(b)
@@ -23,9 +22,8 @@ def get_adjacency_matrix(links):
                     topo[nodeA] = {}
                 if nodeB not in topo:
                     topo[nodeB] = {}
-                topo[nodeA][nodeB] = idx
-                topo[nodeB][nodeA] = idx
-        idx += 1
+                topo[nodeA][nodeB] = 1
+                topo[nodeB][nodeA] = 1
     return topo
                     
             
@@ -50,13 +48,35 @@ def get_sitenodes(siteid):
 
 """
 Find the IP address assigned to a virtual interface in the topology
-(for creating /etc/hosts)
+(for creating /etc/hosts).
+Each virtual link is on a /30 subnet.
 """
-def get_virt_ip(myid, linkid):
-    return "192.168.%d.%d" % (linkid, myid)
+def get_linkid(myid, remoteid):
+    if myid < remoteid:
+        linkid = (myid<<7) + remoteid
+    else:
+        linkid = (remoteid<<7) + myid
+    return linkid
 
-def get_virt_net(linkid):
-    return "192.168.%d.0/24" % linkid
+def get_nodeid(myid, remoteid):
+    if myid < remoteid:
+        nodeid = 1
+    else:
+        nodeid = 2
+    return nodeid
+
+def get_virt_ip(myid, remoteid):
+    linkid = get_linkid(myid, remoteid)
+    nodeid = get_nodeid(myid, remoteid)
+    first = linkid >> 6
+    second = ((linkid & 0x3f)<<2) + nodeid
+    return "192.168.%d.%d" % (first, second)
+
+def get_virt_net(myid, remoteid):
+    linkid = get_linkid(myid, remoteid)
+    first = linkid >> 6
+    second = (linkid & 0x3f)<<2
+    return "192.168.%d.%d/30" % (first, second)
 
 """
 Create a dictionary of site records keyed by site ID
@@ -116,10 +136,9 @@ for slice in GetSlices():
                 if b in slicenodes:
                     if a not in topo:
                         topo[a] = []
-                    link_id = adj_matrix[a][b]
-                    my_ip = get_virt_ip(a, link_id)
-                    remote_ip = get_virt_ip(b, link_id)
-                    net = get_virt_net(link_id)
+                    my_ip = get_virt_ip(a, b)
+                    remote_ip = get_virt_ip(b, a)
+                    net = get_virt_net(a, b)
                     link = b, get_ipaddr(b), "1Mbit", my_ip, remote_ip, net
                     topo[a].append(link)
                     shortname = nodes[a]['hostname'].replace('.vini-veritas.net', '')