示例#1
0
def add_link_data(
    link_proto: core_pb2.Link
) -> Tuple[InterfaceData, InterfaceData, LinkOptions]:
    """
    Convert link proto to link interfaces and options data.

    :param link_proto: link  proto
    :return: link interfaces and options
    """
    interface_one = link_interface(link_proto.interface_one)
    interface_two = link_interface(link_proto.interface_two)

    link_type = None
    link_type_value = link_proto.type
    if link_type_value is not None:
        link_type = LinkTypes(link_type_value)

    options = LinkOptions(_type=link_type)
    options_data = link_proto.options
    if options_data:
        options.delay = options_data.delay
        options.bandwidth = options_data.bandwidth
        options.per = options_data.per
        options.dup = options_data.dup
        options.jitter = options_data.jitter
        options.mer = options_data.mer
        options.burst = options_data.burst
        options.mburst = options_data.mburst
        options.unidirectional = options_data.unidirectional
        options.key = options_data.key
        options.opaque = options_data.opaque

    return interface_one, interface_two, options
示例#2
0
    def read_links(self):
        link_elements = self.scenario.find("links")
        if link_elements is None:
            return

        node_sets = set()
        for link_element in link_elements.iterchildren():
            node_one = get_int(link_element, "node_one")
            node_two = get_int(link_element, "node_two")
            node_set = frozenset((node_one, node_two))

            interface_one_element = link_element.find("interface_one")
            interface_one = None
            if interface_one_element is not None:
                interface_one = create_interface_data(interface_one_element)

            interface_two_element = link_element.find("interface_two")
            interface_two = None
            if interface_two_element is not None:
                interface_two = create_interface_data(interface_two_element)

            options_element = link_element.find("options")
            link_options = LinkOptions()
            if options_element is not None:
                link_options.bandwidth = get_int(options_element, "bandwidth")
                link_options.burst = get_int(options_element, "burst")
                link_options.delay = get_int(options_element, "delay")
                link_options.dup = get_int(options_element, "dup")
                link_options.mer = get_int(options_element, "mer")
                link_options.mburst = get_int(options_element, "mburst")
                link_options.jitter = get_int(options_element, "jitter")
                link_options.key = get_int(options_element, "key")
                link_options.per = get_int(options_element, "per")
                link_options.unidirectional = get_int(options_element,
                                                      "unidirectional")
                link_options.session = options_element.get("session")
                link_options.emulation_id = get_int(options_element,
                                                    "emulation_id")
                link_options.network_id = get_int(options_element,
                                                  "network_id")
                link_options.opaque = options_element.get("opaque")
                link_options.gui_attributes = options_element.get(
                    "gui_attributes")

            if link_options.unidirectional == 1 and node_set in node_sets:
                logging.info("updating link node_one(%s) node_two(%s): %s",
                             node_one, node_two, link_options)
                self.session.update_link(node_one, node_two, interface_one.id,
                                         interface_two.id, link_options)
            else:
                logging.info("adding link node_one(%s) node_two(%s): %s",
                             node_one, node_two, link_options)
                self.session.add_link(node_one, node_two, interface_one,
                                      interface_two, link_options)

            node_sets.add(node_set)
示例#3
0
文件: corexml.py 项目: gsomlo/core
    def read_links(self):
        link_elements = self.scenario.find("links")
        if link_elements is None:
            return

        for link_element in link_elements.iterchildren():
            node_one = get_int(link_element, "node_one")
            node_two = get_int(link_element, "node_two")

            interface_one_element = link_element.find("interface_one")
            interface_one = None
            if interface_one_element is not None:
                interface_one = create_interface_data(interface_one_element)

            interface_two_element = link_element.find("interface_two")
            interface_two = None
            if interface_two_element is not None:
                interface_two = create_interface_data(interface_two_element)

            options_element = link_element.find("options")
            link_options = LinkOptions()
            if options_element is not None:
                link_options.bandwidth = get_float(options_element, "bandwidth")
                link_options.burst = get_float(options_element, "burst")
                link_options.delay = get_float(options_element, "delay")
                link_options.dup = get_float(options_element, "dup")
                link_options.mer = get_float(options_element, "mer")
                link_options.mburst = get_float(options_element, "mburst")
                link_options.jitter = get_float(options_element, "jitter")
                link_options.key = get_float(options_element, "key")
                link_options.per = get_float(options_element, "per")
                link_options.unidirectional = get_int(options_element, "unidirectional")
                link_options.session = options_element.get("session")
                link_options.emulation_id = get_int(options_element, "emulation_id")
                link_options.network_id = get_int(options_element, "network_id")
                link_options.opaque = options_element.get("opaque")
                link_options.gui_attributes = options_element.get("gui_attributes")

            logger.info("reading link node_one(%s) node_two(%s)", node_one, node_two)
            self.session.add_link(node_one, node_two, interface_one, interface_two, link_options)
示例#4
0
文件: server.py 项目: yanhc519/core
 def EditLink(self, request, context):
     logging.debug("edit link: %s", request)
     session = self.get_session(request.session_id, context)
     node_one_id = request.node_one_id
     node_two_id = request.node_two_id
     interface_one_id = request.interface_one_id
     interface_two_id = request.interface_two_id
     options_data = request.options
     link_options = LinkOptions()
     link_options.delay = options_data.delay
     link_options.bandwidth = options_data.bandwidth
     link_options.per = options_data.per
     link_options.dup = options_data.dup
     link_options.jitter = options_data.jitter
     link_options.mer = options_data.mer
     link_options.burst = options_data.burst
     link_options.mburst = options_data.mburst
     link_options.unidirectional = options_data.unidirectional
     link_options.key = options_data.key
     link_options.opaque = options_data.opaque
     session.update_link(node_one_id, node_two_id, interface_one_id,
                         interface_two_id, link_options)
     return core_pb2.EditLinkResponse(result=True)
示例#5
0
文件: server.py 项目: yanhc519/core
    def AddLink(self, request, context):
        logging.debug("add link: %s", request)
        session = self.get_session(request.session_id, context)

        # validate node exist
        self.get_node(session, request.link.node_one_id, context)
        self.get_node(session, request.link.node_two_id, context)
        node_one_id = request.link.node_one_id
        node_two_id = request.link.node_two_id

        interface_one = None
        interface_one_data = request.link.interface_one
        if interface_one_data:
            name = interface_one_data.name
            if name == "":
                name = None
            mac = interface_one_data.mac
            if mac == "":
                mac = None
            else:
                mac = MacAddress.from_string(mac)
            interface_one = InterfaceData(
                _id=interface_one_data.id,
                name=name,
                mac=mac,
                ip4=interface_one_data.ip4,
                ip4_mask=interface_one_data.ip4mask,
                ip6=interface_one_data.ip6,
                ip6_mask=interface_one_data.ip6mask,
            )

        interface_two = None
        interface_two_data = request.link.interface_two
        if interface_two_data:
            name = interface_two_data.name
            if name == "":
                name = None
            mac = interface_two_data.mac
            if mac == "":
                mac = None
            else:
                mac = MacAddress.from_string(mac)
            interface_two = InterfaceData(
                _id=interface_two_data.id,
                name=name,
                mac=mac,
                ip4=interface_two_data.ip4,
                ip4_mask=interface_two_data.ip4mask,
                ip6=interface_two_data.ip6,
                ip6_mask=interface_two_data.ip6mask,
            )

        link_type = None
        link_type_value = request.link.type
        if link_type_value is not None:
            link_type = LinkTypes(link_type_value)

        options_data = request.link.options
        link_options = LinkOptions(_type=link_type)
        if options_data:
            link_options.delay = options_data.delay
            link_options.bandwidth = options_data.bandwidth
            link_options.per = options_data.per
            link_options.dup = options_data.dup
            link_options.jitter = options_data.jitter
            link_options.mer = options_data.mer
            link_options.burst = options_data.burst
            link_options.mburst = options_data.mburst
            link_options.unidirectional = options_data.unidirectional
            link_options.key = options_data.key
            link_options.opaque = options_data.opaque

        session.add_link(node_one_id,
                         node_two_id,
                         interface_one,
                         interface_two,
                         link_options=link_options)
        return core_pb2.AddLinkResponse(result=True)