예제 #1
0
    def parse_onos_host_nodes(self):
        onos_hosts = None

        with open(self.network_configuration.conf_path + "onos_hosts.json",
                  "r") as in_file:
            onos_hosts = json.loads(in_file.read())

        for onos_host_dict in onos_hosts:
            host_switch_id = self.onos_sw_device_id_to_node_id_mapping(
                onos_host_dict["location"]["elementId"])
            host_switch_obj = self.get_node_object(host_switch_id)

            # Onos links do not give host-switch links, so need to add Port to each switch
            host_port_json = {"port": onos_host_dict["location"]["port"]}
            host_switch_port = Port(host_switch_obj, port_json=host_port_json)
            host_switch_obj.ports[int(
                host_switch_port.port_number)] = host_switch_port

            # Add the host to the graph
            host_id = "h" + host_switch_id[1:] + onos_host_dict["location"][
                "port"]
            self.host_ids.add(host_id)

            h_obj = Host(host_id, self, onos_host_dict["ipAddresses"][0],
                         onos_host_dict["mac"], host_switch_obj,
                         host_switch_port)

            # Make the connections both on switch and host side
            host_switch_obj.host_ports.append(
                int(onos_host_dict["location"]["port"]))
            host_switch_obj.attached_hosts.append(h_obj)
            host_switch_port.attached_host = h_obj

            self.graph.add_node(host_id, node_type="host", h=h_obj)

            self.add_link(host_id, int(0), host_switch_id,
                          int(host_switch_port.port_number))