+class SfaNoPairRSpec(SfaFault):
+ def __init__(self, interface, interface2):
+ faultString = "Interface " + interface + " should be paired with " + interface2
+ SfaFault.__init__(self, 100, faultString, '')
+
+# 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)
+
+
+ return topology
+
+
+def allocations_to_rspec(allocations):
+ rspec = xml.dom.minidom.parse(SFA_MAX_DEFAULT_RSPEC)
+ req = rspec.firstChild.appendChild(rspec.createElement("request"))
+ for (iname,ip) in allocations:
+ ifspec = req.appendChild(rspec.createElement("ifspec"))
+ ifspec.setAttribute("name","tns:"+iname)
+ ifspec.setAttribute("ip",ip)
+
+ return rspec.toxml()
+
+
+def if_endpoints(ifs):