import re
import socket
+from sfa.util.faults import *
from sfa.rspecs.aggregates.vini.topology import *
+default_topo_xml = """
+ <LinkSpec>
+ <endpoint>i2atla1</endpoint>
+ <endpoint>i2chic1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2atla1</endpoint>
+ <endpoint>i2hous1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2atla1</endpoint>
+ <endpoint>i2wash1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2chic1</endpoint>
+ <endpoint>i2kans1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2chic1</endpoint>
+ <endpoint>i2wash1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2hous1</endpoint>
+ <endpoint>i2kans1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2hous1</endpoint>
+ <endpoint>i2losa1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2kans1</endpoint>
+ <endpoint>i2salt1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2losa1</endpoint>
+ <endpoint>i2salt1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2losa1</endpoint>
+ <endpoint>i2seat1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2newy1</endpoint>
+ <endpoint>i2wash1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>
+ <LinkSpec>
+ <endpoint>i2salt1</endpoint>
+ <endpoint>i2seat1</endpoint>
+ <kbps>1000</kbps>
+ </LinkSpec>"""
+
# Taken from bwlimit.py
#
# See tc_util.c and http://physics.nist.gov/cuu/Units/binary.html. Be
def __init__(self, site):
self.id = site['site_id']
self.node_ids = site['node_ids']
- self.name = site['abbreviated_name']
+ self.name = site['abbreviated_name'].replace(" ", "_")
self.tag = site['login_base']
self.public = site['is_public']
+ self.enabled = site['enabled']
self.links = set()
def get_sitenodes(self, nodes):
tags.append(self.tags[t])
return tags
- def nodeTopoFromRspec(self, rspec):
+ def lookupSiteLink(self, node1, node2):
+ site1 = self.sites[node1.site_id]
+ site2 = self.sites[node2.site_id]
+ for link in self.sitelinks:
+ if site1 == link.end1 and site2 == link.end2:
+ return link
+ if site2 == link.end1 and site1 == link.end2:
+ return link
+ return None
+
+ def nodeTopoFromRSpec(self, rspec):
if self.nodelinks:
raise Error("virtual topology already present")
for node in self.getNodes():
nodedict[node.tag] = node
- linkspecs = rspecdict['Rspec']['Request'][0]['NetSpec'][0]['LinkSpec']
+ linkspecs = rspecdict['RSpec']['Request'][0]['NetSpec'][0]['LinkSpec']
for l in linkspecs:
n1 = nodedict[l['endpoint'][0]]
n2 = nodedict[l['endpoint'][1]]
- bps = get_tc_rate(l['bw'][0])
+ bps = int(l['kbps'][0]) * 1000
self.nodelinks.append(Link(n1, n2, bps))
def nodeTopoFromSliceTags(self, slice):
if tag.tagname == 'topo_rspec' and not tag.updated:
tag.delete()
tag.write(self.api)
+
+ """
+ Check the requested topology against the available topology and capacity
+ """
+ def verifyNodeTopo(self, hrn, topo, maxbw):
+ maxbps = get_tc_rate(maxbw)
+ for link in self.nodelinks:
+ if link.bps <= 0:
+ raise GeniInvalidArgument(bw, "BW")
+ if link.bps > maxbps:
+ raise PermissionError(" %s requested %s but max BW is %s" %
+ (hrn, format_tc_rate(link.bps), maxbw))
+
+ n1 = link.end1
+ n2 = link.end2
+ sitelink = self.lookupSiteLink(n1, n2)
+ if not sitelink:
+ raise PermissionError("%s: nodes %s and %s not adjacent" % (hrn, n1.tag, n2.tag))
+ if sitelink.bps < link.bps:
+ raise PermissionError("%s: insufficient capacity between %s and %s" % (hrn, n1.tag, n2.tag))
+
+ """
+ Produce XML directly from the topology specification.
+ """
+ def toxml(self, hrn = None):
+ xml = """<?xml version="1.0"?>
+<RSpec name="vini">
+ <Capacity>
+ <NetSpec name="physical_topology">"""
+
+ for site in self.getSites():
+ if not (site.public and site.enabled and site.node_ids):
+ continue
+
+ xml += """
+ <SiteSpec name="%s"> """ % site.name
+
+ for node in site.get_sitenodes(self.nodes):
+ if not node.tag:
+ continue
+
+ xml += """
+ <NodeSpec name="%s">
+ <hostname>%s</hostname>
+ <kbps>%s</kbps>
+ </NodeSpec>""" % (node.tag, node.hostname, int(node.bps/1000))
+ xml += """
+ </SiteSpec>"""
+
+ for link in self.sitelinks:
+ xml += """
+ <SiteLinkSpec>
+ <endpoint>%s</endpoint>
+ <endpoint>%s</endpoint>
+ <kbps>%s</kbps>
+ </SiteLinkSpec>""" % (link.end1.name, link.end2.name, int(link.bps/1000))
+
+
+ if hrn:
+ name = hrn
+ else:
+ name = 'default_topology'
+ xml += """
+ </NetSpec>
+ </Capacity>
+ <Request>
+ <NetSpec name="%s">""" % name
+
+ if hrn:
+ for link in self.nodelinks:
+ xml += """
+ <LinkSpec>
+ <endpoint>%s</endpoint>
+ <endpoint>%s</endpoint>
+ <kbps>%s</kbps>
+ </LinkSpec>""" % (link.end1.tag, link.end2.tag, int(link.bps/1000))
+ else:
+ xml += default_topo_xml
+
+ xml += """
+ </NetSpec>
+ </Request>
+</RSpec>"""
+
+ # Remove all leading whitespace and newlines
+ lines = xml.split("\n")
+ noblanks = ""
+ for line in lines:
+ noblanks += line.strip()
+ return noblanks
"""