+# Returns a mapping from interfaces to the nodes they lie on and their peer interfaces
+# i -> node,i_peer
+
+def get_interface_map():
+ r = RSpec()
+ r.parseFile(SFA_MAX_DEFAULT_RSPEC)
+ rspec = r.toDict()
+ capacity = rspec['rspec']['capacity']
+ netspec = capacity[0]['netspec'][0]
+ linkdefs = {}
+ for n in netspec['nodespec']:
+ ifspecs = n['ifspec']
+ nodename = n['node']
+ for i in ifspecs:
+ ifname = i['name']
+ linkid = i['linkid']
+
+ if (linkdefs.has_key(linkid)):
+ linkdefs[linkid].extend([(nodename,ifname)])
+ else:
+ linkdefs[linkid]=[(nodename,ifname)]
+
+ # topology maps interface x interface -> link,node1,node2
+ topology={}
+
+ for k in linkdefs.keys():
+ (n1,i1) = linkdefs[k][0]
+ (n2,i2) = linkdefs[k][1]
+
+ topology[i1] = (n1, i2)
+ topology[i2] = (n2, i1)
+