From 630954e4bb28511419355dbf1e2c1765b9c567b9 Mon Sep 17 00:00:00 2001 From: Andy Bavier Date: Fri, 21 Aug 2009 20:08:02 +0000 Subject: [PATCH] Verify request against capacity --- sfa/rspecs/aggregates/rspec_manager_vini.py | 28 +---------------- sfa/rspecs/aggregates/vini/utils.py | 34 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/sfa/rspecs/aggregates/rspec_manager_vini.py b/sfa/rspecs/aggregates/rspec_manager_vini.py index e5199708..70131d75 100644 --- a/sfa/rspecs/aggregates/rspec_manager_vini.py +++ b/sfa/rspecs/aggregates/rspec_manager_vini.py @@ -148,32 +148,6 @@ def get_rspec(api, hrn): return topo.toxml(hrn) -""" -Check the requested topology against the available topology and capacity -""" -def check_request(hrn, rspec, nodes, sites, sitelinks, maxbw): - linkspecs = rspec['Rspec']['Request'][0]['NetSpec'][0]['LinkSpec'] - if linkspecs: - for l in linkspecs: - n1 = Node.lookup(l['endpoint'][0]) - n2 = Node.lookup(l['endpoint'][1]) - bw = l['bw'][0] - reqbps = get_tc_rate(bw) - maxbps = get_tc_rate(maxbw) - - if reqbps <= 0: - raise GeniInvalidArgument(bw, "BW") - if reqbps > maxbps: - raise PermissionError(" %s requested %s but max BW is %s" % - (hrn, bw, maxbw)) - - if adjacent_nodes(n1, n2, sites, sitelinks): - availbps = get_avail_bps(n1, n2, sites, sitelinks) - if availbps < reqbps: - raise PermissionError("%s: capacity exceeded" % hrn) - else: - raise PermissionError("%s: nodes %s and %s not adjacent" - % (hrn, n1.tag, n2.tag)) """ Hook called via 'sfi.py create' @@ -198,7 +172,7 @@ def create_slice(api, hrn, xml): topo.nodeTopoFromRspec(rspec) # Check request against current allocations - #check_request(hrn, rspec, nodes, sites, sitelinks, maxbw) + topo.verifyNodeTopo(hrn, topo, maxbw) nodes = topo.nodesInTopo() hostnames = [] diff --git a/sfa/rspecs/aggregates/vini/utils.py b/sfa/rspecs/aggregates/vini/utils.py index 94e64bf7..98455003 100644 --- a/sfa/rspecs/aggregates/vini/utils.py +++ b/sfa/rspecs/aggregates/vini/utils.py @@ -1,5 +1,6 @@ import re import socket +from sfa.util.faults import * from sfa.rspecs.aggregates.vini.topology import * default_topo_xml = """ @@ -469,6 +470,16 @@ class Topology: tags.append(self.tags[t]) return tags + 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") @@ -523,6 +534,29 @@ class Topology: 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 = """ -- 2.43.0