Пример #1
0
 def get_wlan_configs_proto(self) -> List[core_pb2.WlanConfig]:
     configs = []
     for node_id, config in self.wlan_configs.items():
         config = {x: config[x].value for x in config}
         wlan_config = core_pb2.WlanConfig(node_id=node_id, config=config)
         configs.append(wlan_config)
     return configs
Пример #2
0
    def set_wlan_config(
            self, session_id: int, node_id: int,
            config: Dict[str, str]) -> core_pb2.SetWlanConfigResponse:
        """
        Set wlan configuration for a node.

        :param session_id: session id
        :param node_id: node id
        :param config: wlan configuration
        :return: response with result of success or failure
        :raises grpc.RpcError: when session doesn't exist
        """
        wlan_config = core_pb2.WlanConfig(node_id=node_id, config=config)
        request = core_pb2.SetWlanConfigRequest(session_id=session_id,
                                                wlan_config=wlan_config)
        return self.stub.SetWlanConfig(request)
Пример #3
0
    def test_start_session(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        position = core_pb2.Position(x=50, y=100)
        node_one = core_pb2.Node(id=1, position=position, model="PC")
        position = core_pb2.Position(x=100, y=100)
        node_two = core_pb2.Node(id=2, position=position, model="PC")
        position = core_pb2.Position(x=200, y=200)
        wlan_node = core_pb2.Node(id=3,
                                  type=NodeTypes.WIRELESS_LAN.value,
                                  position=position)
        nodes = [node_one, node_two, wlan_node]
        interface_helper = InterfaceHelper(ip4_prefix="10.83.0.0/16")
        interface_one = interface_helper.create_interface(node_one.id, 0)
        interface_two = interface_helper.create_interface(node_two.id, 0)
        link = core_pb2.Link(
            type=core_pb2.LinkType.WIRED,
            node_one_id=node_one.id,
            node_two_id=node_two.id,
            interface_one=interface_one,
            interface_two=interface_two,
        )
        links = [link]
        hook = core_pb2.Hook(state=core_pb2.SessionState.RUNTIME,
                             file="echo.sh",
                             data="echo hello")
        hooks = [hook]
        location_x = 5
        location_y = 10
        location_z = 15
        location_lat = 20
        location_lon = 30
        location_alt = 40
        location_scale = 5
        location = core_pb2.SessionLocation(
            x=location_x,
            y=location_y,
            z=location_z,
            lat=location_lat,
            lon=location_lon,
            alt=location_alt,
            scale=location_scale,
        )
        emane_config_key = "platform_id_start"
        emane_config_value = "2"
        emane_config = {emane_config_key: emane_config_value}
        model_node_id = 20
        model_config_key = "bandwidth"
        model_config_value = "500000"
        model_config = core_pb2.EmaneModelConfig(
            node_id=model_node_id,
            interface_id=-1,
            model=EmaneIeee80211abgModel.name,
            config={model_config_key: model_config_value},
        )
        model_configs = [model_config]
        wlan_config_key = "range"
        wlan_config_value = "333"
        wlan_config = core_pb2.WlanConfig(
            node_id=wlan_node.id, config={wlan_config_key: wlan_config_value})
        wlan_configs = [wlan_config]
        mobility_config_key = "refresh_ms"
        mobility_config_value = "60"
        mobility_config = core_pb2.MobilityConfig(
            node_id=wlan_node.id,
            config={mobility_config_key: mobility_config_value})
        mobility_configs = [mobility_config]
        service_config = core_pb2.ServiceConfig(node_id=node_one.id,
                                                service="DefaultRoute",
                                                validate=["echo hello"])
        service_configs = [service_config]
        service_file_config = core_pb2.ServiceFileConfig(
            node_id=node_one.id,
            service="DefaultRoute",
            file="defaultroute.sh",
            data="echo hello",
        )
        service_file_configs = [service_file_config]

        # when
        with patch.object(CoreXmlWriter, "write"):
            with client.context_connect():
                client.start_session(
                    session.id,
                    nodes,
                    links,
                    location,
                    hooks,
                    emane_config,
                    model_configs,
                    wlan_configs,
                    mobility_configs,
                    service_configs,
                    service_file_configs,
                )

        # then
        assert node_one.id in session.nodes
        assert node_two.id in session.nodes
        assert wlan_node.id in session.nodes
        assert session.nodes[node_one.id].netif(0) is not None
        assert session.nodes[node_two.id].netif(0) is not None
        hook_file, hook_data = session._hooks[core_pb2.SessionState.RUNTIME][0]
        assert hook_file == hook.file
        assert hook_data == hook.data
        assert session.location.refxyz == (location_x, location_y, location_z)
        assert session.location.refgeo == (location_lat, location_lon,
                                           location_alt)
        assert session.location.refscale == location_scale
        assert session.emane.get_config(emane_config_key) == emane_config_value
        set_wlan_config = session.mobility.get_model_config(
            wlan_node.id, BasicRangeModel.name)
        assert set_wlan_config[wlan_config_key] == wlan_config_value
        set_mobility_config = session.mobility.get_model_config(
            wlan_node.id, Ns2ScriptedMobility.name)
        assert set_mobility_config[
            mobility_config_key] == mobility_config_value
        set_model_config = session.emane.get_model_config(
            model_node_id, EmaneIeee80211abgModel.name)
        assert set_model_config[model_config_key] == model_config_value
        service = session.services.get_service(node_one.id,
                                               service_config.service,
                                               default_service=True)
        assert service.validate == tuple(service_config.validate)
        service_file = session.services.get_service_file(
            node_one, service_file_config.service, service_file_config.file)
        assert service_file.data == service_file_config.data