def parse_sel_switches(self, sel_switches): for each_id, switch in sel_switches.iteritems(): # prepare the switch id switch_id = "s" + str(each_id) sw = self.get_node_object(switch_id) # Check to see if a switch with this id already exists in the graph, # if so grab it, otherwise create it if not sw: sw = Switch(switch_id, self) self.graph.add_node(switch_id, node_type="switch", sw=sw) self.switch_ids.append(switch_id) # Parse out the information about all the ports in the switch switch_ports = {} for port in switch["ports"]: switch_ports[port["portId"]] = Port(sw, port_json=port) sw.ports = switch_ports # Parse group table if one is available if "groups" in sel_switches[each_id]: sw.group_table = GroupTable(sw, sel_switches[each_id]["groups"]) # Parse all the flow tables and sort them by table_id in the list switch_flow_tables = [] for table_id in sel_switches[each_id]["flow_tables"]: switch_flow_tables.append( FlowTable(sw, table_id, sel_switches[each_id]["flow_tables"][table_id])) sw.flow_tables = sorted(switch_flow_tables, key=lambda flow_table: flow_table.table_id)
def parse_ryu_switches(self): ryu_switches = None with open(self.network_configuration.conf_path + "ryu_switches.json", "r") as in_file: ryu_switches = json.loads(in_file.read()) # Go through each node and grab the ryu_switches and the corresponding hosts associated with the switch for dpid in ryu_switches: # prepare a switch id switch_id = "s" + str(dpid) # Check to see if a switch with this id already exists in the graph, # if so grab it, otherwise create it sw = self.get_node_object(switch_id) if not sw: sw = Switch(switch_id, self) self.graph.add_node(switch_id, node_type="switch", sw=sw) self.switch_ids.append(switch_id) # Parse out the information about all the ports in the switch switch_ports = {} for port in ryu_switches[dpid]["ports"]: if port["port_no"] == 4294967294: continue if port["port_no"] == "LOCAL": continue switch_ports[int(port["port_no"])] = Port(sw, port_json=port) if (not ryu_switches[dpid]["ports"]): #import pdb; pdb.set_trace() ovs_sw = self.network_configuration.mininet_obj.get(switch_id) for intf in ovs_sw.intfList(): if intf.name != 'lo': new_port_obj = Port(sw, None, intf) switch_ports[new_port_obj.port_number] = new_port_obj sw.ports = switch_ports # Parse group table if one is available if "groups" in ryu_switches[dpid]: sw.group_table = GroupTable(sw, ryu_switches[dpid]["groups"]) # Parse all the flow tables and sort them by table_id in the list switch_flow_tables = [] for table_id in ryu_switches[dpid]["flow_tables"]: switch_flow_tables.append( FlowTable(sw, table_id, ryu_switches[dpid]["flow_tables"][table_id])) sw.flow_tables = sorted( switch_flow_tables, key=lambda flow_table: flow_table.table_id)
def parse_onos_switches(self): onos_switches = None with open(self.network_configuration.conf_path + "onos_switches.json", "r") as in_file: onos_switches = json.loads(in_file.read()) for onos_switch in onos_switches["devices"]: # prepare a switch id switch_id = self.onos_sw_device_id_to_node_id_mapping( onos_switch["id"]) # Check to see if a switch with this id already exists in the graph, # if so grab it, otherwise create it sw = self.get_node_object(switch_id) if not sw: sw = Switch(switch_id, self) self.graph.add_node(switch_id, node_type="switch", sw=sw) self.switch_ids.append(switch_id) # Parse out the information about all the ports in the switch switch_ports = {} for port_num in onos_switch["ports"]: switch_ports[int(port_num)] = Port( sw, port_json=onos_switch["ports"][port_num]) sw.ports = switch_ports # Parse group table if one is available if "groups" in onos_switch: sw.group_table = GroupTable(sw, onos_switch["groups"]) # Parse all the flow tables and sort them by table_id in the list switch_flow_tables = [] for table_id in onos_switch["flow_tables"]: switch_flow_tables.append( FlowTable(sw, table_id, onos_switch["flow_tables"][table_id])) sw.flow_tables = sorted( switch_flow_tables, key=lambda flow_table: flow_table.table_id)
def parse_onos_switches(self, onos_switches): for onos_switch in onos_switches["devices"]: if not onos_switch["available"]: continue # prepare a switch id switch_id = self.onos_sw_device_id_to_node_id_mapping( onos_switch["id"]) # Check to see if a switch with this id already exists in the graph, # if so grab it, otherwise create it sw = self.get_node_object(switch_id) if not sw: sw = Switch(switch_id, self) self.graph.add_node(switch_id, node_type="switch", sw=sw) self.switch_ids.append(switch_id) # Parse out the information about all the ports in the switch switch_ports = {} for port_json in onos_switch["ports"]: if port_json["port"] == "local": continue switch_ports[int(port_json["port"])] = Port(sw, port_raw=port_json) sw.ports = switch_ports # Parse group table if one is available if "groups" in onos_switch: sw.group_table = GroupTable(sw, onos_switch["groups"]) # Parse all the flow tables and sort them by table_id in the list switch_flow_tables = [] for table_id in onos_switch["flow_tables"]: switch_flow_tables.append( FlowTable(sw, table_id, onos_switch["flow_tables"][table_id])) sw.flow_tables = sorted( switch_flow_tables, key=lambda flow_table: flow_table.table_id)
def parse_ryu_switches(self, ryu_switches): # Go through each node and grab the ryu_switches and the corresponding hosts associated with the switch for dpid in ryu_switches: # prepare a switch id switch_id = "s" + str(dpid) # Check to see if a switch with this id already exists in the graph, # if so grab it, otherwise create it sw = self.get_node_object(switch_id) if not sw: sw = Switch(switch_id, self) self.graph.add_node(switch_id, node_type="switch", sw=sw) self.switch_ids.append(switch_id) # Parse out the information about all the ports in the switch switch_ports = {} for port in ryu_switches[dpid]["ports"]: if port["port_no"] == 4294967294: continue if port["port_no"] == "LOCAL": continue switch_ports[int(port["port_no"])] = Port(sw, port_raw=port) sw.ports = switch_ports # Parse group table if one is available if "groups" in ryu_switches[dpid]: sw.group_table = GroupTable(sw, ryu_switches[dpid]["groups"]) # Parse all the flow tables and sort them by table_id in the list switch_flow_tables = [] for table_id in ryu_switches[dpid]["flow_tables"]: switch_flow_tables.append( FlowTable(sw, table_id, ryu_switches[dpid]["flow_tables"][table_id])) sw.flow_tables = sorted( switch_flow_tables, key=lambda flow_table: flow_table.table_id)
def parse_grpc_switches(self, grpc_switches): # Go through each node and grab the ryu_switches and the corresponding hosts associated with the switch for switch in grpc_switches: # Check to see if a switch with this id already exists in the graph, # if so grab it, otherwise create it sw = self.get_node_object(switch.switch_id) if not sw: sw = Switch(switch.switch_id, self) self.graph.add_node(switch.switch_id, node_type="switch", sw=sw) self.switch_ids.append(switch.switch_id) # Parse out the information about all the ports in the switch switch_ports = {} for port in switch.ports: if port.port_num == 4294967294: continue if port.port_num == "LOCAL": continue switch_ports[int(port.port_num)] = Port(sw, port_raw=port) sw.ports = switch_ports # Parse group table if one is available if len(switch.group_table) > 0: sw.group_table = GroupTable(sw, switch.group_table) # Parse all the flow tables and sort them by table_id in the list switch_flow_tables = [] for flow_table in switch.flow_tables: switch_flow_tables.append( FlowTable(sw, flow_table.table_num, flow_table)) sw.flow_tables = sorted( switch_flow_tables, key=lambda flow_table: flow_table.table_id)