コード例 #1
0
    def get_iface_config(self, emane_net: EmaneNet,
                         iface: CoreInterface) -> Dict[str, str]:
        """
        Retrieve configuration for a given interface, first checking for interface
        specific config, node specific config, network specific config, and finally
        falling back to the default configuration settings.

        :param emane_net: emane network the interface is connected to
        :param iface: interface running emane
        :return: net, node, or interface model configuration
        """
        model_name = emane_net.model.name
        config = None
        # try to retrieve interface specific configuration
        if iface.node_id is not None:
            key = utils.iface_config_id(iface.node.id, iface.node_id)
            config = self.get_config(key, model_name, default=False)
        # attempt to retrieve node specific config, when iface config is not present
        if not config:
            config = self.get_config(iface.node.id, model_name, default=False)
        # attempt to get emane net specific config, when node config is not present
        if not config:
            # with EMANE 0.9.2+, we need an extra NEM XML from
            # model.buildnemxmlfiles(), so defaults are returned here
            config = self.get_config(emane_net.id, model_name, default=False)
        # return default config values, when a config is not present
        if not config:
            config = emane_net.model.default_values()
        return config
コード例 #2
0
    def read_emane_configs(self) -> None:
        emane_configurations = self.scenario.find("emane_configurations")
        if emane_configurations is None:
            return

        for emane_configuration in emane_configurations.iterchildren():
            node_id = get_int(emane_configuration, "node")
            iface_id = get_int(emane_configuration, "iface")
            model_name = emane_configuration.get("model")
            configs = {}

            # validate node and model
            node = self.session.nodes.get(node_id)
            if not node:
                raise CoreXmlError(
                    f"node for emane config doesn't exist: {node_id}")
            model = self.session.emane.models.get(model_name)
            if not model:
                raise CoreXmlError(f"invalid emane model: {model_name}")
            if iface_id is not None and iface_id not in node.ifaces:
                raise CoreXmlError(
                    f"invalid interface id({iface_id}) for node({node.name})")

            # read and set emane model configuration
            mac_configuration = emane_configuration.find("mac")
            for config in mac_configuration.iterchildren():
                name = config.get("name")
                value = config.get("value")
                configs[name] = value

            phy_configuration = emane_configuration.find("phy")
            for config in phy_configuration.iterchildren():
                name = config.get("name")
                value = config.get("value")
                configs[name] = value

            external_configuration = emane_configuration.find("external")
            for config in external_configuration.iterchildren():
                name = config.get("name")
                value = config.get("value")
                configs[name] = value

            logging.info("reading emane configuration node(%s) model(%s)",
                         node_id, model_name)
            node_id = utils.iface_config_id(node_id, iface_id)
            self.session.emane.set_model_config(node_id, model_name, configs)
コード例 #3
0
def configure_node(session: Session, node: core_pb2.Node, core_node: NodeBase,
                   context: ServicerContext) -> None:
    for emane_config in node.emane_configs:
        _id = utils.iface_config_id(node.id, emane_config.iface_id)
        config = {k: v.value for k, v in emane_config.config.items()}
        session.emane.set_config(_id, emane_config.model, config)
    if node.wlan_config:
        config = {k: v.value for k, v in node.wlan_config.items()}
        session.mobility.set_model_config(node.id, BasicRangeModel.name,
                                          config)
    if node.mobility_config:
        config = {k: v.value for k, v in node.mobility_config.items()}
        session.mobility.set_model_config(node.id, Ns2ScriptedMobility.name,
                                          config)
    for service_name, service_config in node.service_configs.items():
        data = service_config.data
        config = ServiceConfig(
            node_id=node.id,
            service=service_name,
            startup=data.startup,
            validate=data.validate,
            shutdown=data.shutdown,
            files=data.configs,
            directories=data.dirs,
        )
        service_configuration(session, config)
        for file_name, file_data in service_config.files.items():
            session.services.set_service_file(node.id, service_name, file_name,
                                              file_data)
    if node.config_service_configs:
        if not isinstance(core_node, CoreNode):
            context.abort(
                grpc.StatusCode.INVALID_ARGUMENT,
                "invalid node type with config service configs",
            )
        for service_name, service_config in node.config_service_configs.items(
        ):
            service = core_node.config_services[service_name]
            if service_config.config:
                service.set_config(service_config.config)
            for name, template in service_config.templates.items():
                service.set_template(name, template)
コード例 #4
0
ファイル: test_emane.py プロジェクト: xiaoxiaopingzi/core
    def test_xml_emane_interface_config(self, session: Session,
                                        tmpdir: TemporaryFile,
                                        ip_prefixes: IpPrefixes):
        # create nodes
        options = NodeOptions(model="mdr", x=50, y=50)
        node1 = session.add_node(CoreNode, options=options)
        iface1_data = ip_prefixes.create_iface(node1)
        node2 = session.add_node(CoreNode, options=options)
        iface2_data = ip_prefixes.create_iface(node2)

        # create emane node
        options = NodeOptions(model=None, emane=EmaneRfPipeModel.name)
        emane_node = session.add_node(EmaneNet, options=options)

        # create links
        session.add_link(node1.id, emane_node.id, iface1_data)
        session.add_link(node2.id, emane_node.id, iface2_data)

        # set node specific conifg
        datarate = "101"
        config_id = utils.iface_config_id(node1.id, iface1_data.id)
        session.emane.set_config(config_id, EmaneRfPipeModel.name,
                                 {"datarate": datarate})

        # instantiate session
        session.instantiate()

        # save xml
        xml_file = tmpdir.join("session.xml")
        file_path = xml_file.strpath
        session.save_xml(Path(file_path))

        # verify xml file was created and can be parsed
        assert xml_file.isfile()
        assert ElementTree.parse(file_path)

        # stop current session, clearing data
        session.shutdown()

        # verify nodes have been removed from session
        with pytest.raises(CoreError):
            assert not session.get_node(node1.id, CoreNode)
        with pytest.raises(CoreError):
            assert not session.get_node(node2.id, CoreNode)
        with pytest.raises(CoreError):
            assert not session.get_node(emane_node.id, EmaneNet)

        # load saved xml
        session.open_xml(Path(file_path), start=True)

        # verify nodes have been recreated
        assert session.get_node(node1.id, CoreNode)
        assert session.get_node(node2.id, CoreNode)
        assert session.get_node(emane_node.id, EmaneNet)
        links = []
        for node_id in session.nodes:
            node = session.nodes[node_id]
            links += node.links()
        assert len(links) == 2
        config = session.emane.get_config(config_id, EmaneRfPipeModel.name)
        assert config["datarate"] == datarate