Esempio n. 1
0
    def create_link(
        self, edge: CanvasEdge, canvas_src_node: CanvasNode, canvas_dst_node: CanvasNode
    ):
        """
        Create core link for a pair of canvas nodes, with token referencing
        the canvas edge.
        """
        src_node = canvas_src_node.core_node
        dst_node = canvas_dst_node.core_node

        # determine subnet
        self.interfaces_manager.determine_subnets(canvas_src_node, canvas_dst_node)

        src_interface = None
        if NodeUtils.is_container_node(src_node.type):
            src_interface = self.create_interface(canvas_src_node)
            edge.src_interface = src_interface
            self.interface_to_edge[(src_node.id, src_interface.id)] = edge.token

        dst_interface = None
        if NodeUtils.is_container_node(dst_node.type):
            dst_interface = self.create_interface(canvas_dst_node)
            edge.dst_interface = dst_interface
            self.interface_to_edge[(dst_node.id, dst_interface.id)] = edge.token

        link = core_pb2.Link(
            type=core_pb2.LinkType.WIRED,
            node_one_id=src_node.id,
            node_two_id=dst_node.id,
            interface_one=src_interface,
            interface_two=dst_interface,
        )
        edge.set_link(link)
        self.links[edge.token] = edge
        logging.info("Add link between %s and %s", src_node.name, dst_node.name)
Esempio n. 2
0
    def draw_session(self, session: core_pb2.Session):
        """
        Draw existing session.
        """
        # draw existing nodes
        for core_node in session.nodes:
            logging.debug("drawing node %s", core_node)
            # peer to peer node is not drawn on the GUI
            if NodeUtils.is_ignore_node(core_node.type):
                continue
            image = NodeUtils.node_image(core_node, self.app.guiconfig,
                                         self.app.app_scale)
            # if the gui can't find node's image, default to the "edit-node" image
            if not image:
                image = Images.get(ImageEnum.EDITNODE,
                                   int(ICON_SIZE * self.app.app_scale))
            x = core_node.position.x
            y = core_node.position.y
            node = CanvasNode(self.app, x, y, core_node, image)
            self.nodes[node.id] = node
            self.core.canvas_nodes[core_node.id] = node

        # draw existing links
        for link in session.links:
            logging.debug("drawing link: %s", link)
            canvas_node_one = self.core.canvas_nodes[link.node_one_id]
            node_one = canvas_node_one.core_node
            canvas_node_two = self.core.canvas_nodes[link.node_two_id]
            node_two = canvas_node_two.core_node
            token = create_edge_token(canvas_node_one.id, canvas_node_two.id)

            if link.type == core_pb2.LinkType.WIRELESS:
                self.add_wireless_edge(canvas_node_one, canvas_node_two, link)
            else:
                if token not in self.edges:
                    src_pos = (node_one.position.x, node_one.position.y)
                    dst_pos = (node_two.position.x, node_two.position.y)
                    edge = CanvasEdge(self, canvas_node_one.id, src_pos,
                                      dst_pos)
                    edge.token = token
                    edge.dst = canvas_node_two.id
                    edge.set_link(link)
                    edge.check_wireless()
                    canvas_node_one.edges.add(edge)
                    canvas_node_two.edges.add(edge)
                    self.edges[edge.token] = edge
                    self.core.links[edge.token] = edge
                    if link.HasField("interface_one"):
                        canvas_node_one.interfaces.append(link.interface_one)
                        edge.src_interface = link.interface_one
                    if link.HasField("interface_two"):
                        canvas_node_two.interfaces.append(link.interface_two)
                        edge.dst_interface = link.interface_two
                elif link.options.unidirectional:
                    edge = self.edges[token]
                    edge.asymmetric_link = link
                else:
                    logging.error("duplicate link received: %s", link)

        # raise the nodes so they on top of the links
        self.tag_raise(tags.NODE)