Example #1
0
    def __enforce_se_consistency(self, route):
        route_original = etree.tostring(route)
        if isinstance(route, str):
            root = etree.fromstring(route)
        else:
            root = route
        # Use GENIv3 namespace as used in base request formatter
        ns = root.nsmap[None]
        # Verify that interfaces (from node) are all defined in links
        interfaces = root.xpath("//x:node//x:interface", namespaces={"x": ns})
        links = root.xpath("//x:link", namespaces={"x": ns})

        for link in links:
            local_interfaces = link.xpath(
                "x:interface_ref", namespaces={"x": ns})
            for interface in interfaces:
                # Check for inconsistent interfaces and remove them, i.e.
                # not defined in link's client_id or on its interfaces
                if URNUtils.get_datapath_and_port_from_datapath_id(
                    interface.get("client_id"))[0] not in \
                    link.get("client_id") \
                    or interface.get("client_id") not in \
                        [x.get("client_id") for x in local_interfaces]:
                    logger.debug("SE request: removing interface not in use \
                        (%s)" % etree.tostring(interface, pretty_print=True))
                    interface.getparent().remove(interface)

        if len(links) == 0:
            try:
                interfaces[0].getparent().getparent().remove(
                    interfaces[0].getparent())
                logger.debug("SE request: removing request due to \
                    missing links")
            except:
                pass
        if len(interfaces) == 0:
            try:
                links[0].getparent().remove(links[0])
                logger.debug("SE request: removing request due to \
                    missing interfaces")
            except:
                pass

        route_new = etree.tostring(route)
        if route_original != route_new:
            logger.info(
                "Route (after consistency check)=%s" %
                (etree.tostring(route, pretty_print=True),))
Example #2
0
 def add_vlan_to_link(self, link_cid, iface_cid):
     """
     Add vlan to component ID of link's interface
     when using a newly formatted RSpec.
     This format is used: "urn+...+datapath+<dpid>_<port>+vlan=<vlan>.
     """
     if "vlan=" in link_cid:
         urn_src, vlan_src, urn_dst, vlan_dst = URNUtils.get_fields_from_domain_link_id(link_cid)
         if_vlan_pairs = {urn_src: vlan_src, urn_dst: vlan_dst}
         # if_dpid = URNUtils.get_datapath_from_datapath_id(if_cid)
         if_dpid, if_port = URNUtils.get_datapath_and_port_from_datapath_id(iface_cid)
         if_dpid_port = "%s_%s" % (if_dpid, if_port)
         for if_vlan in if_vlan_pairs.keys():
             if if_dpid_port in if_vlan:
                 iface_cid += "+vlan=%s" % if_vlan_pairs[if_vlan]
                 break
     return iface_cid