- def __add_vlink(self, vlink, slicenodes, parent = None):
- n1 = n2 = None
- endpoints = vlink.get("endpoints")
- if endpoints:
- (end1, end2) = endpoints.split()
- n1 = self.lookupNode(end1)
- n2 = self.lookupNode(end2)
- elif parent:
- """ Try to infer the endpoints for the virtual link """
- site_endpoints = parent.get("endpoints")
- (n1, n2) = self.__infer_endpoints(site_endpoints, slicenodes)
- else:
- raise Error("no endpoints given")
-
- #print "Added virtual link: %s -- %s" % (n1.tag, n2.tag)
- bps = int(vlink.findtext("kbps")) * 1000
- sitelink = self.lookupSiteLink(n1, n2)
- if not sitelink:
- raise PermissionError("nodes %s and %s not adjacent" %
- (n1.idtag, n2.idtag))
- self.nodelinks.append(Link(n1, n2, bps, sitelink))
- return
-
- """
- Infer the endpoints of the virtual link. If the slice exists on
- only a single node at each end of the physical link, we'll assume that
- the user wants the virtual link to terminate at these nodes.
- """
- def __infer_endpoints(self, endpoints, slicenodes):
- n = []
- ends = endpoints.split()
- for end in ends:
- found = 0
- site = self.lookupSite(end)
- for id in site.node_ids:
- if id in slicenodes:
- n.append(slicenodes[id])
- found += 1
- if found != 1:
- raise Error("could not infer endpoint for site %s" % site.id)
- #print "Inferred endpoints: %s %s" % (n[0].idtag, n[1].idtag)
- return n
-
- def annotateFromRSpec(self, xml):
- if self.nodelinks:
- raise Error("virtual topology already present")
-
- nodedict = {}
- for node in self.getNodes():
- nodedict[node.idtag] = node
-
- slicenodes = {}
-
- tree = etree.parse(StringIO(xml))
-
- if self.schema: