Example #1
0
def build_platform_xml(
    emane_manager: "EmaneManager",
    control_net: CtrlNet,
    emane_net: EmaneNet,
    iface: CoreInterface,
    nem_id: int,
) -> None:
    """
    Create platform xml for a specific node.

    :param emane_manager: emane manager with emane
        configurations
    :param control_net: control net node for this emane
        network
    :param emane_net: emane network associated with interface
    :param iface: interface running emane
    :param nem_id: nem id to use for this interface
    :return: the next nem id that can be used for creating platform xml files
    """
    # build nem xml
    nem_definition = nem_file_name(iface)
    nem_element = etree.Element(
        "nem", id=str(nem_id), name=iface.localname, definition=nem_definition
    )

    # check if this is an external transport, get default config if an interface
    # specific one does not exist
    config = emane_manager.get_iface_config(emane_net, iface)
    if is_external(config):
        nem_element.set("transport", "external")
        platform_endpoint = "platformendpoint"
        add_param(nem_element, platform_endpoint, config[platform_endpoint])
        transport_endpoint = "transportendpoint"
        add_param(nem_element, transport_endpoint, config[transport_endpoint])
    else:
        transport_name = transport_file_name(iface)
        transport_element = etree.SubElement(
            nem_element, "transport", definition=transport_name
        )
        add_param(transport_element, "device", iface.name)

    transport_configs = {"otamanagerdevice", "eventservicedevice"}
    platform_element = etree.Element("platform")
    for configuration in emane_manager.emane_config.emulator_config:
        name = configuration.id
        if iface.is_raw() and name in transport_configs:
            value = control_net.brname
        else:
            value = emane_manager.get_config(name)
        add_param(platform_element, name, value)
    platform_element.append(nem_element)
    mac = _MAC_PREFIX + ":00:00:"
    mac += f"{(nem_id >> 8) & 0xFF:02X}:{nem_id & 0xFF:02X}"
    iface.set_mac(mac)

    doc_name = "platform"
    file_name = f"{iface.name}-platform.xml"
    create_iface_file(iface, platform_element, doc_name, file_name)
Example #2
0
def nem_file_name(iface: CoreInterface) -> str:
    """
    Return the string name for the NEM XML file, e.g. "eth0-nem.xml"

    :param iface: interface running emane
    :return: nem xm file name
    """
    append = "-raw" if iface.is_raw() else ""
    return f"{iface.name}-nem{append}.xml"
Example #3
0
def create_iface_file(
    iface: CoreInterface, xml_element: etree.Element, doc_name: str, file_name: str
) -> None:
    """
    Create emane xml for an interface.

    :param iface: interface running emane
    :param xml_element: root element to write to file
    :param doc_name: name to use in the emane doctype
    :param file_name: name of xml file
    :return:
    """
    node = iface.node
    if iface.is_raw():
        file_path = os.path.join(node.session.session_dir, file_name)
    else:
        file_path = os.path.join(node.nodedir, file_name)
    create_file(xml_element, doc_name, file_path, node.server)