def _add_se_info(self, parent_node=None): # If no parent node passed, SE info is attached to root topology node if parent_node is None: parent_node = self.topology # 1. Nodes nodes = [d for d in db_sync_manager.get_se_nodes_by_domain(self.domain_urn)] for node in nodes: if MonitoringUtils.check_existing_tag_in_topology(parent_node, "node", "se", node.get("component_id")): break logger.debug("se-node=%s" % (node,)) n = self._add_generic_node(parent_node, node, "se") # Output interfaces per node logger.debug("se-node-interfaces=%s" % node.get("interfaces")) for iface in node.get("interfaces"): interface = etree.SubElement(n, "interface") # Parse the component_id to get URN of SE and the port per interface component_id = iface.get("component_id") try: interface.set("id", component_id) # interface.attrib["id"] = component_id.split("_")[0] port = etree.SubElement(interface, "port") port.set("num", component_id.split("_")[1]) except Exception as e: logger.warning("Physical topology - Cannot add SE\ interface %s. Details: %s" % (component_id, e)) # 2. Links links = [l for l in db_sync_manager.get_se_links_by_domain(self.domain_urn)] logger.debug("se-links=%s" % (links)) for link in links: dpid1 = link.get("interface_ref")[0].get("component_id") dpid2 = link.get("interface_ref")[1].get("component_id") if MonitoringUtils.check_existing_tag_in_topology(parent_node, "link", "lan", [dpid1, dpid2]): break logger.debug("se-links=%s" % (link)) self._add_se_link(link)
def _add_sdn_link(self, link, parent_node=None): if parent_node is None: parent_node = self.topology auth1 = link.get("dpids")[0].get("component_manager_id").replace("authority+cm", "datapath") dpid1 = auth1 + "+" + link.get("dpids")[0].get("dpid") + "_" + link.get("ports")[0].get("port_num") auth2 = link.get("dpids")[1].get("component_manager_id").replace("authority+cm", "datapath") dpid2 = auth2 + "+" + link.get("dpids")[1].get("dpid") + "_" + link.get("ports")[1].get("port_num") if MonitoringUtils.check_existing_tag_in_topology( parent_node, "link", "lan", [dpid1, dpid2]): return l = etree.SubElement(parent_node, "link") # NOTE that this cannot be empty l.set("type", MonitoringUtilsLinks._translate_link_type(link)) link_id = "" ports = link.get("ports") dpids = link.get("dpids") try: for dpid_port in zip(dpids, ports): iface = etree.SubElement(l, "interface_ref") dpid = dpid_port[0]["component_id"] port = dpid_port[1]["port_num"] iface.set("client_id", "%s_%s" % (dpid, port)) except Exception as e: logger.warning("Physical topology - Cannot add SDN interface %s. \ Details: %s" % (link.get("component_id", "(unknown)"), e)) try: # - Prepare link ID for SDNRM-SDNRM link link_id = MonitoringUtilsLinks.get_id_for_link_sdnrm_sdnrm(zip(dpids, ports)) l.set("id", link_id) except Exception as e: logger.warning("Physical topology - Cannot add SDN link ID %s. \ Details: %s" % (link.get("component_id", "(unknown)"), e))
def _add_com_link(self, link, parent_node=None): if parent_node is None: parent_node = self.topology logger.debug("com-links=%s" % (link,)) # l = etree.SubElement(parent_node, "link") l = etree.Element("link") # NOTE that this cannot be empty l.set("type", MonitoringUtilsLinks._translate_link_type(link)) link_id = "" links = link.get("links") link_exists = False for link_i in links: if MonitoringUtils.check_existing_tag_in_topology(parent_node, "link", "lan", [link_i.get("source_id"), link_i.get("dest_id")]): link_exists = True break # Modify link on-the-fly to add the DPID port as needed link_i = MonitoringUtilsLinks._set_dpid_port_from_link(link.get("component_id"), link_i) # Source iface_source = etree.SubElement(l, "interface_ref") iface_source.set("client_id", link_i.get("source_id")) # Destination iface_dest = etree.SubElement(l, "interface_ref") iface_dest.set("client_id", link_i.get("dest_id")) # - Prepare link ID for CRM-SDNRM link link_id = MonitoringUtilsLinks.get_id_for_link_crm_sdnrm(link_i) # Finally, add it as subelement if not link_exists: l.set("id", link_id) parent_node.append(l)
def _add_com_info(self, parent_node=None): # If no parent node passed, COM info is attached to root topology node if parent_node is None: parent_node = self.topology # 1. Nodes nodes = [n for n in db_sync_manager.get_com_nodes_by_domain(self.domain_urn)] for node in nodes: if MonitoringUtils.check_existing_tag_in_topology(parent_node, "node", "server", node.get("component_id")): break logger.debug("com-node=%s" % (node)) # If no parent node passed, COM info is attached to root topology node if parent_node is None: parent_node = self.topology n = self._add_generic_node(parent_node, node, "server") # Output interfaces (avoid "*") per server node_ifaces = filter(lambda x: x != "*", node.get("interfaces")) logger.debug("com-node-interfaces=%s" % node_ifaces) for iface in node_ifaces: interface = etree.SubElement(n, "interface") # NOTE this is extending the "interface" URN interface.set("id", "%s+interface+%s" % (n.get("id"), iface)) # 2. Links links = [l for l in db_sync_manager.get_com_links_by_domain(self.domain_urn)] logger.debug("com-links=%s" % (links,)) for link in links: self._add_com_link(link, parent_node)
def _add_se_link(self, link): # Special case: links to be filtered in POST {(M)RO -> (M)MS} SE_FILTERED_LINKS = ["*"] interfaces_cid = [i.get("component_id") for i in link.get("interface_ref")] interface_cid_in_filter = [f for f in SE_FILTERED_LINKS if f in interfaces_cid] # Avoid reinserting existing link tags in the topology if MonitoringUtils.check_existing_tag_in_topology( self.topology, "link", "lan", link.get("component_id")): return if not interface_cid_in_filter: l = etree.SubElement(self.topology, "link") # NOTE that this cannot be empty l.set("type", MonitoringUtilsLinks._translate_link_type(link)) link_id = "" links = link.get("interface_ref") for link in links: # SE link iface = etree.SubElement(l, "interface_ref") iface.set("client_id", link.get("component_id")) # - Prepare link ID for SERM-SDNRM link link_id = MonitoringUtilsLinks.\ get_id_for_link_serm_sdnrm_tnrm(links) l.set("id", link_id)
def _add_se_link(self, link): # Special case: links to be filtered in POST {(M)RO -> (M)MS} SE_FILTERED_LINKS = ["*"] interfaces_cid = [ i.get("component_id") for i in link.get("interface_ref") ] interface_cid_in_filter = [ f for f in SE_FILTERED_LINKS if f in interfaces_cid ] # Avoid reinserting existing link tags in the topology if MonitoringUtils.check_existing_tag_in_topology( self.topology, "link", "lan", link.get("component_id")): return if not interface_cid_in_filter: l = etree.SubElement(self.topology, "link") # NOTE that this cannot be empty l.set("type", MonitoringUtilsLinks._translate_link_type(link)) link_id = "" links = link.get("interface_ref") for link in links: # SE link iface = etree.SubElement(l, "interface_ref") iface.set("client_id", link.get("component_id")) # - Prepare link ID for SERM-SDNRM link link_id = MonitoringUtilsLinks.get_id_for_link_serm_sdnrm_tnrm( links) l.set("id", link_id)
def _add_sdn_info(self, parent_node=None): # If no parent node passed, SDN info is attached to root topology node if parent_node is None: parent_node = self.topology # 1. Nodes datapaths = [d for d in db_sync_manager. get_sdn_datapaths_by_domain(self.domain_urn)] for dp in datapaths: if MonitoringUtils.check_existing_tag_in_topology( parent_node, "node", "switch", dp.get("component_id")): break logger.debug("sdn-datapath=%s" % (dp,)) switch = self._add_generic_node(parent_node, dp, "switch") for p in dp.get("ports"): iface = etree.SubElement(switch, "interface") iface.set("id", "%s_%s" % (switch.get("id"), p.get("num"))) port = etree.SubElement(iface, "port") port.set("num", p.get("num")) # 2. Links (sdn_links, fed_links) = [l for l in db_sync_manager. get_sdn_links_by_domain(self.domain_urn)] for sdn_link in sdn_links: logger.debug("sdn-link=%s" % (sdn_link,)) self._add_sdn_link(sdn_link, parent_node) for sdn_fed_link in fed_links: logger.debug("fed-sdn-link=%s" % (sdn_fed_link,))
def _add_tn_info(self, parent_node=None): # If no parent node passed, TN info is attached to root topology node if parent_node is None: parent_node = self.topology # 1. Nodes # XXX: (M)MS assumes one TNRM per island # This retrieves TN information from AIST instance # (providing MRO has TNRM as peer, or its information in its DB) felix_tn_urn = "urn:publicid:IDN+fms:aist:tnrm" nodes = [d for d in db_sync_manager. get_tn_nodes_by_domain(felix_tn_urn)] # nodes = [d for d in db_sync_manager.\ # get_tn_nodes_by_domain(self.domain_urn)] # nodes = [d for d in db_sync_manager.get_tn_nodes()] for node in nodes: if MonitoringUtils.check_existing_tag_in_topology( parent_node, "node", "tn", node.get("component_id"), self.domain_urn): break logger.debug("tn-node=%s" % (node,)) n = self._add_generic_node(parent_node, node, "tn") # Output interfaces per node logger.debug("tn-node-interfaces=%s" % node.get("interfaces")) for iface in node.get("interfaces"): interface = etree.SubElement(n, "interface") interface.set("id", iface.get("component_id"))
def _add_com_info(self, parent_node=None): # If no parent node passed, COM info is attached to root topology node if parent_node is None: parent_node = self.topology # 1. Nodes nodes = [ n for n in db_sync_manager.get_com_nodes_by_domain(self.domain_urn) ] for node in nodes: if MonitoringUtils.check_existing_tag_in_topology( parent_node, "node", "server", node.get("component_id")): break logger.debug("com-node=%s" % (node, )) # If no parent node passed, COM info is attached to root topology node if parent_node is None: parent_node = self.topology n = self._add_generic_node(parent_node, node, "server") # Output interfaces (avoid "*") per server node_ifaces = filter(lambda x: x != "*", node.get("interfaces")) logger.debug("com-node-interfaces=%s" % node_ifaces) for iface in node_ifaces: interface = etree.SubElement(n, "interface") # NOTE this is extending the "interface" URN interface.set("id", "%s+interface+%s" % (n.get("id"), iface)) # 2. Links links = [ l for l in db_sync_manager.get_com_links_by_domain(self.domain_urn) ] logger.debug("com-links=%s" % (links, )) for link in links: self._add_com_link(link, parent_node)
def _add_com_link(self, link, parent_node=None): if parent_node is None: parent_node = self.topology logger.debug("com-links=%s" % (link, )) #l = etree.SubElement(parent_node, "link") l = etree.Element("link") # NOTE that this cannot be empty l.set("type", MonitoringUtilsLinks._translate_link_type(link)) link_id = "" links = link.get("links") link_exists = False for link_i in links: if MonitoringUtils.check_existing_tag_in_topology( parent_node, "link", "lan", [link_i.get("source_id"), link_i.get("dest_id")]): link_exists = True break # Modify link on-the-fly to add the DPID port as needed link_i = MonitoringUtilsLinks._set_dpid_port_from_link( link.get("component_id"), link_i) # Source iface_source = etree.SubElement(l, "interface_ref") iface_source.set("client_id", link_i.get("source_id")) # Destination iface_dest = etree.SubElement(l, "interface_ref") iface_dest.set("client_id", link_i.get("dest_id")) # - Prepare link ID for CRM-SDNRM link link_id = MonitoringUtilsLinks.get_id_for_link_crm_sdnrm(link_i) # Finally, add it as subelement if not link_exists: l.set("id", link_id) parent_node.append(l)
def _add_sdn_info(self, parent_node=None): # If no parent node passed, SDN info is attached to root topology node if parent_node is None: parent_node = self.topology # 1. Nodes datapaths = [ d for d in db_sync_manager.get_sdn_datapaths_by_domain( self.domain_urn) ] for dp in datapaths: if MonitoringUtils.check_existing_tag_in_topology( parent_node, "node", "switch", dp.get("component_id")): break logger.debug("sdn-datapath=%s" % (dp, )) switch = self._add_generic_node(parent_node, dp, "switch") for p in dp.get("ports"): iface = etree.SubElement(switch, "interface") iface.set("id", "%s_%s" % (switch.get("id"), p.get("num"))) port = etree.SubElement(iface, "port") port.set("num", p.get("num")) # 2. Links (sdn_links, fed_links) = [ l for l in db_sync_manager.get_sdn_links_by_domain(self.domain_urn) ] for sdn_link in sdn_links: logger.debug("sdn-link=%s" % (sdn_link, )) self._add_sdn_link(sdn_link, parent_node) for sdn_fed_link in fed_links: logger.debug("fed-sdn-link=%s" % (sdn_fed_link, ))
def _add_tn_info(self, parent_node=None): # If no parent node passed, TN info is attached to root topology node if parent_node is None: parent_node = self.topology # 1. Nodes # XXX: (M)MS assumes one TNRM per island # This retrieves TN information from AIST instance # (providing MRO has TNRM as peer, or its information in its DB) felix_tn_urn = "urn:publicid:IDN+fms:aist:tnrm" nodes = [ d for d in db_sync_manager.get_tn_nodes_by_domain(felix_tn_urn) ] # nodes = [ d for d in db_sync_manager.get_tn_nodes_by_domain(self.domain_urn) ] # nodes = [ d for d in db_sync_manager.get_tn_nodes() ] for node in nodes: if MonitoringUtils.check_existing_tag_in_topology( parent_node, "node", "tn", node.get("component_id"), self.domain_urn): break logger.debug("tn-node=%s" % (node, )) n = self._add_generic_node(parent_node, node, "tn") # Output interfaces per node logger.debug("tn-node-interfaces=%s" % node.get("interfaces")) for iface in node.get("interfaces"): interface = etree.SubElement(n, "interface") interface.set("id", iface.get("component_id"))
def __add_island2island_tnlink(self, info, tag): tn_src = info.get("source") tn_dst = info.get("destination") if MonitoringUtils.check_existing_tag_in_topology(tag, "link", self.TN2TN_LINK_TYPE, [tn_src, tn_dst]): return tn_ = etree.SubElement(tag, "link", type=self.TN2TN_LINK_TYPE, id=info.get("id")) etree.SubElement(tn_, "interface_ref", client_id=tn_src) etree.SubElement( tn_, "interface_ref", client_id=tn_dst)
def __add_island2island_selink(self, ident, src, dst, tag): if MonitoringUtils.check_existing_tag_in_topology(tag, "link", self.MS_LINK_TYPE, [src, dst]): return logger.info("Se link (%s) between %s and %s" % (ident, src, dst,)) if (ident is not None) and (src is not None) and (dst is not None): se_ = etree.SubElement(tag, "link", type=self.MS_LINK_TYPE, id=ident) etree.SubElement(se_, "interface_ref", client_id=src) etree.SubElement(se_, "interface_ref", client_id=dst) else: logger.error("Un-terminated or Unknown se link!")
def __add_island2island_lanlink(self, src, dst, tag): if MonitoringUtils.check_existing_tag_in_topology(tag, "link", self.MS_LINK_TYPE, [src, dst]): return logger.info("Lan link between %s and %s" % (src, dst,)) if (src is not None) and (dst is not None): lan_ = etree.SubElement(tag, "link", type=self.MS_LINK_TYPE) etree.SubElement(lan_, "interface_ref", client_id=src) etree.SubElement(lan_, "interface_ref", client_id=dst) else: logger.error("Un-terminated lan link!")
def _add_se_info(self, parent_node=None): # If no parent node passed, SE info is attached to root topology node if parent_node is None: parent_node = self.topology # 1. Nodes nodes = [ d for d in db_sync_manager.get_se_nodes_by_domain(self.domain_urn) ] for node in nodes: if MonitoringUtils.check_existing_tag_in_topology( parent_node, "node", "se", node.get("component_id")): break logger.debug("se-node=%s" % (node, )) n = self._add_generic_node(parent_node, node, "se") # Output interfaces per node logger.debug("se-node-interfaces=%s" % node.get("interfaces")) for iface in node.get("interfaces"): interface = etree.SubElement(n, "interface") # Parse the component_id to get URN of SE and the port per interface component_id = iface.get("component_id") try: interface.set("id", component_id) # interface.attrib["id"] = component_id.split("_")[0] port = etree.SubElement(interface, "port") port.set("num", component_id.split("_")[1]) except Exception as e: logger.warning( "Physical topology - Cannot add SE interface %s. Details: %s" % (component_id, e)) # 2. Links links = [ l for l in db_sync_manager.get_se_links_by_domain(self.domain_urn) ] logger.debug("se-links=%s" % (links, )) for link in links: dpid1 = link.get("interface_ref")[0].get("component_id") dpid2 = link.get("interface_ref")[1].get("component_id") if MonitoringUtils.check_existing_tag_in_topology( parent_node, "link", "lan", [dpid1, dpid2]): break logger.debug("se-links=%s" % (link, )) self._add_se_link(link)
def __add_island2island_tnlink(self, info, tag): tn_src = info.get("source") tn_dst = info.get("destination") if MonitoringUtils.check_existing_tag_in_topology( tag, "link", self.TN2TN_LINK_TYPE, [tn_src, tn_dst]): return tn_ = etree.SubElement(tag, "link", type=self.TN2TN_LINK_TYPE, id=info.get("id")) etree.SubElement(tn_, "interface_ref", client_id=tn_src) etree.SubElement(tn_, "interface_ref", client_id=tn_dst)
def __add_vlink_info(self, topology_tag, ep_src, ep_dst, link_type=None): # Virtual link differs w.r.t. a normal link # in that those have: # 1) ID (slice name and ID for virtual link) # 2) End-to-end SDN-SDN or SDN-TN link interfaces # 3) (TODO - Ideally) C-SDN link logger.debug("add_vlink_info: epsrc=%s, epdst=%s, type=%s" % (ep_src, ep_dst, link_type)) self.__add_link_info(topology_tag, ep_src, ep_dst, link_type) slice_name = MonitoringUtils.find_slice_name(self.__topologies) vlink_ids = MonitoringUtils.find_virtual_links(self.__topologies) ids_used = [] max_vl_id = 0 try: link_prefix = ":end_link_" for vlink_id in vlink_ids: idx = vlink_id.find(link_prefix) + len(link_prefix) ids_used.append(int(vlink_id[idx])) max_vl_id = max(ids_used)+1 except: pass vlink_id = "%s%s%s" % (slice_name, link_prefix, max_vl_id) topology_tag.attrib["id"] = vlink_id
def __add_island2island_lanlink(self, src, dst, tag): if MonitoringUtils.check_existing_tag_in_topology( tag, "link", self.MS_LINK_TYPE, [src, dst]): return logger.info("Lan link between %s and %s" % ( src, dst, )) if (src is not None) and (dst is not None): lan_ = etree.SubElement(tag, "link", type=self.MS_LINK_TYPE) etree.SubElement(lan_, "interface_ref", client_id=src) etree.SubElement(lan_, "interface_ref", client_id=dst) else: logger.error("Un-terminated lan link!")
def __add_link_info(self, topology_tag, ep_src, ep_dst, link_type=None): # No link_type provided => interfaces appended directly under given tag root = topology_tag if link_type is not None: link_type = self.__translate_link_type(link_type) link_ = etree.Element("link") link_.set("type", link_type) root = link_ if MonitoringUtils.check_existing_tag_in_topology(root, "link", link_type, [ep_src, ep_dst]): return if link_type is not None: topology_tag.append(root) etree.SubElement(root, "interface_ref", client_id=ep_src) etree.SubElement(root, "interface_ref", client_id=ep_dst)
def __add_link_info(self, topology_tag, ep_src, ep_dst, link_type=None): # No link_type provided => interfaces appended directly under given tag root = topology_tag if link_type is not None: link_type = self.__translate_link_type(link_type) link_ = etree.Element("link") link_.set("type", link_type) root = link_ if MonitoringUtils.check_existing_tag_in_topology( root, "link", link_type, [ep_src, ep_dst]): return if link_type is not None: topology_tag.append(root) etree.SubElement(root, "interface_ref", client_id=ep_src) etree.SubElement(root, "interface_ref", client_id=ep_dst)
def __add_island2island_selink(self, ident, src, dst, tag): if MonitoringUtils.check_existing_tag_in_topology( tag, "link", self.MS_LINK_TYPE, [src, dst]): return logger.info("Se link (%s) between %s and %s" % ( ident, src, dst, )) if (ident is not None) and (src is not None) and (dst is not None): se_ = etree.SubElement(tag, "link", type=self.MS_LINK_TYPE, id=ident) etree.SubElement(se_, "interface_ref", client_id=src) etree.SubElement(se_, "interface_ref", client_id=dst) else: logger.error("Un-terminated or Unknown se link!")
def _add_sdn_link(self, link, parent_node=None): if parent_node is None: parent_node = self.topology auth1 = link.get("dpids")[0].get("component_manager_id").replace( "authority+cm", "datapath") dpid1 = auth1 + "+" + link.get("dpids")[0].get( "dpid") + "_" + link.get("ports")[0].get("port_num") auth2 = link.get("dpids")[1].get("component_manager_id").replace( "authority+cm", "datapath") dpid2 = auth2 + "+" + link.get("dpids")[1].get( "dpid") + "_" + link.get("ports")[1].get("port_num") if MonitoringUtils.check_existing_tag_in_topology( parent_node, "link", "lan", [dpid1, dpid2]): return l = etree.SubElement(parent_node, "link") # NOTE that this cannot be empty l.set("type", MonitoringUtilsLinks._translate_link_type(link)) link_id = "" ports = link.get("ports") dpids = link.get("dpids") try: for dpid_port in zip(dpids, ports): iface = etree.SubElement(l, "interface_ref") dpid = dpid_port[0]["component_id"] port = dpid_port[1]["port_num"] iface.set("client_id", "%s_%s" % (dpid, port)) except Exception as e: logger.warning( "Physical topology - Cannot add SDN interface %s. Details: %s" % (link.get("component_id", "(unknown)"), e)) try: # - Prepare link ID for SDNRM-SDNRM link link_id = MonitoringUtilsLinks.get_id_for_link_sdnrm_sdnrm( zip(dpids, ports)) l.set("id", link_id) except Exception as e: logger.warning( "Physical topology - Cannot add SDN link ID %s. Details: %s" % (link.get("component_id", "(unknown)"), e))
def __add_vlink_name(self, vlink_tag, index): # the vlink name should be composed of the slicename and a suffix slice_name = MonitoringUtils.find_slice_name(self.__topologies) vlink_id = "%s%s%s" % (slice_name, ":end_link_", index) logger.debug("vlink name: %s" % (vlink_id)) vlink_tag.attrib["id"] = vlink_id
def add_c_resources(self, slice_urn, nodes): """ Inserts one or more nodes with CRM resources information. @param slice_urn URN identifier of a given slice @param nodes Structure containing a list of CRM nodes and its attributes """ if slice_urn not in self.__stored: logger.error("Unable to find Topology info from %s!" % slice_urn) return topology = self.__stored.get(slice_urn) logger.debug("add_c_resources Nodes=%d" % (len(nodes),)) for n in nodes: logger.debug("Node=%s" % (n,)) node_ = etree.SubElement( topology, "node", id=n.get("component_id"), type="server") inner_node_ = etree.SubElement( node_, "node", id=n.get("sliver_id"), type=n.get("sliver_type_name").lower()) # Add the interface identifier of the server node here! # In the future, it will be the vlan-tagged interface of the # virtual machine (much more sense) nodekey = n.get("component_id").replace("+node+", ":") logger.debug("Node key=%s" % (nodekey,)) interfaces = db_sync_manager.get_com_interface_by_nodekey(nodekey) logger.info("Stored COM interfaces=%s" % (interfaces,)) for i in interfaces: if_index = i.rfind("interface") if_name = n.get("sliver_id") + "+" + i[if_index:len(i)] etree.SubElement(inner_node_, "interface", id=if_name) self.__mapping_c_interface[i] = if_name if len(n.get("services")) > 0: self.__add_snmp_management( inner_node_, n.get("services")[0].get("login").get("hostname")) # Links per node vm_cid = n.get("sliver_id") server_cid = vm_cid server_cid_split = server_cid.split(":") # Note: generate component_id of server from VM server_cid = ":".join(server_cid_split[:-2]) + \ "+node+" + server_cid_split[-2] node_links = db_sync_manager.\ get_com_link_by_src_dst_links(server_cid) for node_link in node_links: for node_link_l in node_link.get("links"): eps = {"source_id": node_link_l.get("source_id"), "dest_id": node_link_l.get("dest_id")} if MonitoringUtils.check_existing_tag_in_topology( topology, "link", self.MS_LINK_TYPE, [eps.get("source_id"), eps.get("dest_id")]): break eps_src_id, eps_dst_id = self.__get_eps_ids( eps.get("source_id"), eps.get("dest_id")) self.__add_link_info(topology, eps_src_id, eps_dst_id, "lan")
def add_sdn_resources(self, slice_urn, nodes): """ Inserts one or more nodes with SDNRM resources information. @param slice_urn URN identifier of a given slice @param nodes Structure containing a list of SDNRM nodes and its attributes """ # Cannot use information extracted from the manifest here! # Look into the db-table containing the requested dpids and matches. if slice_urn not in self.__stored: logger.error("Slice monitoring: unable to find topology " + "info from %s!" % slice_urn) return topology = self.__stored.get(slice_urn) groups, matches = db_sync_manager.get_slice_sdn(slice_urn) link_ids = [] # Nodes info logger.debug("add_sdn_resources Groups(%d)=%s" % (len(groups), groups)) logger.debug("add_sdn_resources Matches=%d" % (len(matches),)) for m in matches: logger.debug("Match=%s" % (m,)) self.__update_match_with_groups(m, groups) ## TODO Check db.topology.slice (maybe some information stored?) for dpid in m.get("dpids"): if MonitoringUtils.check_existing_tag_in_topology(topology, "node", "switch", dpid.get("component_id")): break logger.debug("Dpid=%s" % (dpid,)) node_ = etree.SubElement( topology, "node", id=dpid.get("component_id"), type="switch") for p in dpid.get("ports"): ifid = dpid.get("component_id") + "_" + str(p.get("num")) if_ = etree.SubElement(node_, "interface", id=ifid) etree.SubElement(if_, "port", num=str(p.get("num"))) link_ids.append( self.__create_link_id(dpid.get("dpid"), p.get("num"))) self.__add_packet_info(node_, m.get("packet")) logger.info("add_sdn_resources Link identifiers(%d)=%s" % (len(link_ids), link_ids,)) # C-SDN link info for l in link_ids: com_link = db_sync_manager.get_com_link_by_sdnkey(l) if com_link: logger.debug("COM link=%s" % (com_link,)) for eps in com_link.get("links"): if MonitoringUtils.check_existing_tag_in_topology(topology, "link",\ self.MS_LINK_TYPE, [eps.get("source_id"), eps.get("dest_id")]): break # Modify link on-the-fly to add the DPID port as needed eps = MonitoringUtilsLinks._set_dpid_port_from_link( com_link.get("component_id"), eps) eps_src_id, eps_dst_id = self.__get_eps_ids( eps.get("source_id"), eps.get("dest_id")) logger.info("eps_src_id=%s, eps_dst_id=%s" % (eps_src_id, eps_dst_id,)) self.__add_link_info(topology, eps_src_id, eps_dst_id, com_link.get("link_type")) # SDN-SDN link info ext_link_ids = self.__extend_link_ids(link_ids) logger.info("add_sdn_resources Extended link identifiers(%d)=%s" % (len(ext_link_ids), ext_link_ids,)) for l in ext_link_ids: sdn_link = db_sync_manager.get_sdn_link_by_sdnkey(l) if sdn_link: logger.debug("SDN link=%s" % (sdn_link,)) if len(sdn_link.get("dpids")) == 2 and\ len(sdn_link.get("ports")) == 2: ep1 = self.__create_link_id( sdn_link.get("dpids")[0].get("component_id"), sdn_link.get("ports")[0].get("port_num")) ep2 = self.__create_link_id( sdn_link.get("dpids")[1].get("component_id"). sdn_link.get("ports")[1].get("port_num")) # Local SDN-SDN links are not inserted under the nested link # if self.__check_ids_same_domain(ep1, ep2): self.__add_link_info(topology, ep1, ep2, self.SDN2SDN_LINK_TYPE) # else: # self.__sdn_links.append( # {'id': sdn_link.get("component_id"), # 'source': ep1, # 'destination': ep2}) else: logger.info("Slice monitoring: cannot find link that " + "ends with %s" % l)
def add_sdn_resources(self, slice_urn, nodes): """ Inserts one or more nodes with SDNRM resources information. @param slice_urn URN identifier of a given slice @param nodes Structure containing a list of SDNRM nodes and its attributes """ # Cannot use information extracted from the manifest here! # Look into the db-table containing the requested dpids and matches. if slice_urn not in self.__stored: logger.error("Slice monitoring: unable to find topology " + "info from %s!" % slice_urn) return topology = self.__stored.get(slice_urn) groups, matches = db_sync_manager.get_slice_sdn(slice_urn) link_ids = [] # Nodes info logger.debug("add_sdn_resources Groups(%d)=%s" % (len(groups), groups)) logger.debug("add_sdn_resources Matches=%d" % (len(matches),)) for m in matches: logger.debug("Match=%s" % (m,)) self.__update_match_with_groups(m, groups) # TODO Check db.topology.slice (maybe some information stored?) for dpid in m.get("dpids"): if MonitoringUtils.check_existing_tag_in_topology( topology, "node", "switch", dpid.get("component_id")): break logger.debug("Dpid=%s" % (dpid,)) node_ = etree.SubElement( topology, "node", id=dpid.get("component_id"), type="switch") # NOTE: do not append ports to dpid, different # format is used between XEN-CRM and KVM-CRM link_ids.append( self.__create_link_id(dpid.get("dpid"), "")) self.__add_packet_info(node_, m.get("packet")) logger.info("add_sdn_resources Link identifiers(%d)=%s" % (len(link_ids), link_ids,)) # SDN-SDN link info ext_link_ids = self.__extend_link_ids(link_ids) logger.info("add_sdn_resources Extended link identifiers(%d)=%s" % (len(ext_link_ids), ext_link_ids,)) for l in ext_link_ids: sdn_link = db_sync_manager.get_sdn_link_by_sdnkey(l) if sdn_link: logger.debug("SDN link=%s" % (sdn_link,)) if len(sdn_link.get("dpids")) == 2 and\ len(sdn_link.get("ports")) == 2: ep1 = self.__create_link_id( sdn_link.get("dpids")[0].get("component_id"), sdn_link.get("ports")[0].get("port_num")) ep2 = self.__create_link_id( sdn_link.get("dpids")[1].get("component_id"). sdn_link.get("ports")[1].get("port_num")) # Local SDN-SDN links not inserted under nested link # if self.__check_ids_same_domain(ep1, ep2): self.__add_link_info(topology, ep1, ep2, self.SDN2SDN_LINK_TYPE) # else: # self.__sdn_links.append( # {'id': sdn_link.get("component_id"), # 'source': ep1, # 'destination': ep2}) else: logger.info("Slice monitoring: cannot find link that " + "ends with %s" % l)
def add_sdn_resources(self, slice_urn, nodes): """ Inserts one or more nodes with SDNRM resources information. @param slice_urn URN identifier of a given slice @param nodes Structure containing a list of SDNRM nodes and its attributes """ # Cannot use information extracted from the manifest here! # Look into the db-table containing the requested dpids and matches. if slice_urn not in self.__stored: logger.error("Slice monitoring: unable to find topology " + "info from %s!" % slice_urn) return topology = self.__stored.get(slice_urn) groups, matches = db_sync_manager.get_slice_sdn(slice_urn) link_ids = [] # Nodes info logger.debug("add_sdn_resources Groups(%d)=%s" % (len(groups), groups)) logger.debug("add_sdn_resources Matches=%d" % (len(matches), )) for m in matches: logger.debug("Match=%s" % (m, )) self.__update_match_with_groups(m, groups) ## TODO Check db.topology.slice (maybe some information stored?) for dpid in m.get("dpids"): if MonitoringUtils.check_existing_tag_in_topology( topology, "node", "switch", dpid.get("component_id")): break logger.debug("Dpid=%s" % (dpid, )) node_ = etree.SubElement(topology, "node", id=dpid.get("component_id"), type="switch") for p in dpid.get("ports"): ifid = dpid.get("component_id") + "_" + str(p.get("num")) if_ = etree.SubElement(node_, "interface", id=ifid) etree.SubElement(if_, "port", num=str(p.get("num"))) link_ids.append( self.__create_link_id(dpid.get("dpid"), p.get("num"))) self.__add_packet_info(node_, m.get("packet")) logger.info("add_sdn_resources Link identifiers(%d)=%s" % ( len(link_ids), link_ids, )) # C-SDN link info for l in link_ids: com_link = db_sync_manager.get_com_link_by_sdnkey(l) if com_link: logger.debug("COM link=%s" % (com_link, )) for eps in com_link.get("links"): if MonitoringUtils.check_existing_tag_in_topology(topology, "link",\ self.MS_LINK_TYPE, [eps.get("source_id"), eps.get("dest_id")]): break # Modify link on-the-fly to add the DPID port as needed eps = MonitoringUtilsLinks._set_dpid_port_from_link( com_link.get("component_id"), eps) eps_src_id, eps_dst_id = self.__get_eps_ids( eps.get("source_id"), eps.get("dest_id")) logger.info("eps_src_id=%s, eps_dst_id=%s" % ( eps_src_id, eps_dst_id, )) self.__add_link_info(topology, eps_src_id, eps_dst_id, com_link.get("link_type")) # SDN-SDN link info ext_link_ids = self.__extend_link_ids(link_ids) logger.info("add_sdn_resources Extended link identifiers(%d)=%s" % ( len(ext_link_ids), ext_link_ids, )) for l in ext_link_ids: sdn_link = db_sync_manager.get_sdn_link_by_sdnkey(l) if sdn_link: logger.debug("SDN link=%s" % (sdn_link, )) if len(sdn_link.get("dpids")) == 2 and\ len(sdn_link.get("ports")) == 2: ep1 = self.__create_link_id( sdn_link.get("dpids")[0].get("component_id"), sdn_link.get("ports")[0].get("port_num")) ep2 = self.__create_link_id( sdn_link.get("dpids")[1].get("component_id").sdn_link. get("ports")[1].get("port_num")) # Local SDN-SDN links are not inserted under the nested link # if self.__check_ids_same_domain(ep1, ep2): self.__add_link_info(topology, ep1, ep2, self.SDN2SDN_LINK_TYPE) # else: # self.__sdn_links.append( # {'id': sdn_link.get("component_id"), # 'source': ep1, # 'destination': ep2}) else: logger.info("Slice monitoring: cannot find link that " + "ends with %s" % l)