def get_adjacency_matrix(links):
topo = {}
- idx = 1
for (a, b) in links:
aNodes = get_sitenodes(a)
bNodes = get_sitenodes(b)
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
"""
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
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', '')