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_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_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_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_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_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") 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)