Ejemplo n.º 1
0
    def test_move_nodes_geo(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node(CoreNode)
        lon, lat, alt = 10.0, 15.0, 5.0
        queue = Queue()

        def node_handler(node_data: NodeData):
            assert node_data.longitude == lon
            assert node_data.latitude == lat
            assert node_data.altitude == alt
            queue.put(node_data)

        session.node_handlers.append(node_handler)

        def move_iter():
            yield core_pb2.MoveNodesRequest(
                session_id=session.id,
                node_id=node.id,
                geo=core_pb2.Geo(lon=lon, lat=lat, alt=alt),
            )

        # then
        with client.context_connect():
            client.move_nodes(move_iter())

        # assert
        assert node.position.lon == lon
        assert node.position.lat == lat
        assert node.position.alt == alt
        assert queue.get(timeout=5)
Ejemplo n.º 2
0
    def test_set_session_location(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()

        # then
        scale = 2
        xyz = (1, 1, 1)
        lat_lon_alt = (1, 1, 1)
        with client.context_connect():
            response = client.set_session_location(
                session.id,
                x=xyz[0],
                y=xyz[1],
                z=xyz[2],
                lat=lat_lon_alt[0],
                lon=lat_lon_alt[1],
                alt=lat_lon_alt[2],
                scale=scale,
            )

        # then
        assert response.result is True
        assert session.location.refxyz == xyz
        assert session.location.refscale == scale
        assert session.location.refgeo == lat_lon_alt
Ejemplo n.º 3
0
    def test_node_events(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node(CoreNode)
        node.position.lat = 10.0
        node.position.lon = 20.0
        node.position.alt = 5.0
        queue = Queue()

        def handle_event(event_data):
            assert event_data.session_id == session.id
            assert event_data.HasField("node_event")
            event_node = event_data.node_event.node
            assert event_node.geo.lat == node.position.lat
            assert event_node.geo.lon == node.position.lon
            assert event_node.geo.alt == node.position.alt
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            session.broadcast_node(node)

            # then
            queue.get(timeout=5)
Ejemplo n.º 4
0
    def test_link_events(self, grpc_server: CoreGrpcServer,
                         ip_prefixes: IpPrefixes):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        wlan = session.add_node(WlanNode)
        node = session.add_node(CoreNode)
        interface = ip_prefixes.create_interface(node)
        session.add_link(node.id, wlan.id, interface)
        link_data = wlan.all_link_data()[0]
        queue = Queue()

        def handle_event(event_data):
            assert event_data.session_id == session.id
            assert event_data.HasField("link_event")
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            session.broadcast_link(link_data)

            # then
            queue.get(timeout=5)
Ejemplo n.º 5
0
    def test_set_emane_model_config(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        emane_network = session.create_emane_network(
            model=EmaneIeee80211abgModel, geo_reference=(47.57917, -122.13232, 2.00000)
        )
        config_key = "bandwidth"
        config_value = "900000"

        # then
        with client.context_connect():
            response = client.set_emane_model_config(
                session.id,
                emane_network.id,
                EmaneIeee80211abgModel.name,
                {config_key: config_value},
            )

        # then
        assert response.result is True
        config = session.emane.get_model_config(
            emane_network.id, EmaneIeee80211abgModel.name
        )
        assert config[config_key] == config_value
Ejemplo n.º 6
0
    def test_get_emane_model_configs(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        session.set_location(47.57917, -122.13232, 2.00000, 1.0)
        options = NodeOptions()
        options.emane = EmaneIeee80211abgModel.name
        emane_network = session.add_node(_type=NodeTypes.EMANE,
                                         options=options)
        session.emane.set_model(emane_network, EmaneIeee80211abgModel)
        config_key = "platform_id_start"
        config_value = "2"
        session.emane.set_model_config(emane_network.id,
                                       EmaneIeee80211abgModel.name,
                                       {config_key: config_value})

        # then
        with client.context_connect():
            response = client.get_emane_model_configs(session.id)

        # then
        assert len(response.configs) == 1
        model_config = response.configs[0]
        assert emane_network.id == model_config.node_id
        assert model_config.model == EmaneIeee80211abgModel.name
        assert len(model_config.config) > 0
        assert model_config.interface == -1
Ejemplo n.º 7
0
    def test_set_emane_model_config(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        session.set_location(47.57917, -122.13232, 2.00000, 1.0)
        options = NodeOptions()
        options.emane = EmaneIeee80211abgModel.name
        emane_network = session.add_node(_type=NodeTypes.EMANE,
                                         options=options)
        session.emane.set_model(emane_network, EmaneIeee80211abgModel)
        config_key = "bandwidth"
        config_value = "900000"

        # then
        with client.context_connect():
            response = client.set_emane_model_config(
                session.id,
                emane_network.id,
                EmaneIeee80211abgModel.name,
                {config_key: config_value},
            )

        # then
        assert response.result is True
        config = session.emane.get_model_config(emane_network.id,
                                                EmaneIeee80211abgModel.name)
        assert config[config_key] == config_value
Ejemplo n.º 8
0
    def test_delete_link(self, grpc_server: CoreGrpcServer, ip_prefixes: IpPrefixes):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node1 = session.add_node(CoreNode)
        iface1 = ip_prefixes.create_iface(node1)
        node2 = session.add_node(CoreNode)
        iface2 = ip_prefixes.create_iface(node2)
        session.add_link(node1.id, node2.id, iface1, iface2)
        link_node = None
        for node_id in session.nodes:
            node = session.nodes[node_id]
            if node.id not in {node1.id, node2.id}:
                link_node = node
                break
        assert len(link_node.links()) == 1

        # then
        with client.context_connect():
            response = client.delete_link(
                session.id, node1.id, node2.id, iface1.id, iface2.id
            )

        # then
        assert response.result is True
        assert len(link_node.links()) == 0
Ejemplo n.º 9
0
    def test_move_nodes_geo(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node(CoreNode)
        lon, lat, alt = 10.0, 15.0, 5.0
        streamer = MoveNodesStreamer(session.id)
        streamer.send_geo(node.id, lon, lat, alt)
        streamer.stop()
        queue = Queue()

        def node_handler(node_data: NodeData):
            n = node_data.node
            assert n.position.lon == lon
            assert n.position.lat == lat
            assert n.position.alt == alt
            queue.put(node_data)

        session.node_handlers.append(node_handler)

        # then
        with client.context_connect():
            client.move_nodes(streamer)

        # assert
        assert queue.get(timeout=5)
        assert node.position.lon == lon
        assert node.position.lat == lat
        assert node.position.alt == alt
Ejemplo n.º 10
0
    def test_delete_link(self, grpc_server, ip_prefixes):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node_one = session.add_node()
        interface_one = ip_prefixes.create_interface(node_one)
        node_two = session.add_node()
        interface_two = ip_prefixes.create_interface(node_two)
        session.add_link(node_one.id, node_two.id, interface_one,
                         interface_two)
        link_node = None
        for node_id in session.nodes:
            node = session.nodes[node_id]
            if node.id not in {node_one.id, node_two.id}:
                link_node = node
                break
        assert len(link_node.all_link_data(0)) == 1

        # then
        with client.context_connect():
            response = client.delete_link(session.id, node_one.id, node_two.id,
                                          interface_one.id, interface_two.id)

        # then
        assert response.result is True
        assert len(link_node.all_link_data(0)) == 0
Ejemplo n.º 11
0
    def test_set_wlan_config(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        session.set_state(EventTypes.CONFIGURATION_STATE)
        wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
        wlan.setmodel(BasicRangeModel, BasicRangeModel.default_values())
        session.instantiate()
        range_key = "range"
        range_value = "50"

        # then
        with client.context_connect():
            response = client.set_wlan_config(
                session.id, wlan.id, {
                    range_key: range_value,
                    "delay": "0",
                    "loss": "0",
                    "bandwidth": "50000",
                    "error": "0",
                    "jitter": "0"
                })

        # then
        assert response.result is True
        config = session.mobility.get_model_config(wlan.id,
                                                   BasicRangeModel.name)
        assert config[range_key] == range_value
        assert wlan.model.range == int(range_value)
Ejemplo n.º 12
0
    def test_set_emane_model_config(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        session.set_location(47.57917, -122.13232, 2.00000, 1.0)
        options = NodeOptions(emane=EmaneIeee80211abgModel.name)
        emane_network = session.add_node(EmaneNet, options=options)
        session.emane.node_models[
            emane_network.id] = EmaneIeee80211abgModel.name
        config_key = "bandwidth"
        config_value = "900000"
        option = ConfigOption(
            label=config_key,
            name=config_key,
            value=config_value,
            type=ConfigOptionType.INT32,
            group="Default",
        )
        config = EmaneModelConfig(emane_network.id,
                                  EmaneIeee80211abgModel.name,
                                  config={config_key: option})

        # then
        with client.context_connect():
            result = client.set_emane_model_config(session.id, config)

        # then
        assert result is True
        config = session.emane.get_config(emane_network.id,
                                          EmaneIeee80211abgModel.name)
        assert config[config_key] == config_value
Ejemplo n.º 13
0
    def test_edit_link(self, grpc_server: CoreGrpcServer,
                       ip_prefixes: IpPrefixes):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        switch = session.add_node(SwitchNode)
        node = session.add_node(CoreNode)
        iface = ip_prefixes.create_iface(node)
        session.add_link(node.id, switch.id, iface)
        options = LinkOptions(bandwidth=30000)
        link = switch.links()[0]
        assert options.bandwidth != link.options.bandwidth
        link = Link(node.id,
                    switch.id,
                    iface1=Interface(id=iface.id),
                    options=options)

        # then
        with client.context_connect():
            result = client.edit_link(session.id, link)

        # then
        assert result is True
        link = switch.links()[0]
        assert options.bandwidth == link.options.bandwidth
Ejemplo n.º 14
0
    def test_exception_events(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        queue = Queue()
        exception_level = ExceptionLevels.FATAL
        source = "test"
        node_id = None
        text = "exception message"

        def handle_event(event_data):
            assert event_data.session_id == session.id
            assert event_data.HasField("exception_event")
            exception_event = event_data.exception_event
            assert exception_event.level == exception_level.value
            assert exception_event.node_id == 0
            assert exception_event.source == source
            assert exception_event.text == text
            queue.put(event_data)

        # then
        with client.context_connect():
            client.events(session.id, handle_event)
            time.sleep(0.1)
            session.exception(exception_level, source, node_id, text)

            # then
            queue.get(timeout=5)
Ejemplo n.º 15
0
    def test_edit_link(self, grpc_server: CoreGrpcServer,
                       ip_prefixes: IpPrefixes):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        switch = session.add_node(SwitchNode)
        node = session.add_node(CoreNode)
        interface = ip_prefixes.create_interface(node)
        session.add_link(node.id, switch.id, interface)
        options = core_pb2.LinkOptions(bandwidth=30000)
        link = switch.all_link_data()[0]
        assert options.bandwidth != link.bandwidth

        # then
        with client.context_connect():
            response = client.edit_link(session.id,
                                        node.id,
                                        switch.id,
                                        options,
                                        interface_one_id=interface.id)

        # then
        assert response.result is True
        link = switch.all_link_data()[0]
        assert options.bandwidth == link.bandwidth
Ejemplo n.º 16
0
    def test_move_node_exception(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node(CoreNode)

        # then and when
        with pytest.raises(CoreError), client.context_connect():
            client.move_node(session.id, node.id)
Ejemplo n.º 17
0
    def test_get_services(self, grpc_server):
        # given
        client = CoreGrpcClient()

        # then
        with client.context_connect():
            response = client.get_services()

        # then
        assert len(response.services) > 0
Ejemplo n.º 18
0
    def test_get_session_options(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()

        # then
        with client.context_connect():
            response = client.get_session_options(session.id)

        # then
        assert len(response.groups) > 0
Ejemplo n.º 19
0
    def test_get_service_defaults(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()

        # then
        with client.context_connect():
            defaults = client.get_service_defaults(session.id)

        # then
        assert len(defaults) > 0
Ejemplo n.º 20
0
    def test_add_link_exception(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node(CoreNode)

        # then
        link = Link(node.id, 3)
        with pytest.raises(grpc.RpcError):
            with client.context_connect():
                client.add_link(session.id, link)
Ejemplo n.º 21
0
    def test_add_link_exception(self, grpc_server, interface_helper):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node()

        # then
        interface = interface_helper.create_interface(node.id, 0)
        with pytest.raises(grpc.RpcError):
            with client.context_connect():
                client.add_link(session.id, 1, 3, interface)
Ejemplo n.º 22
0
    def test_get_emane_models(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()

        # then
        with client.context_connect():
            response = client.get_emane_models(session.id)

        # then
        assert len(response.models) > 0
Ejemplo n.º 23
0
    def test_get_wlan_config(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)

        # then
        with client.context_connect():
            response = client.get_wlan_config(session.id, wlan.id)

        # then
        assert len(response.groups) > 0
Ejemplo n.º 24
0
    def test_set_session_state(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()

        # then
        with client.context_connect():
            response = client.set_session_state(session.id, core_pb2.SessionState.DEFINITION)

        # then
        assert response.result is True
        assert session.state == core_pb2.SessionState.DEFINITION
Ejemplo n.º 25
0
    def test_save_xml(self, grpc_server, tmpdir):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        tmp = tmpdir.join("text.xml")

        # then
        with client.context_connect():
            client.save_xml(session.id, str(tmp))

        # then
        assert tmp.exists()
Ejemplo n.º 26
0
    def test_get_node(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node()

        # then
        with client.context_connect():
            response = client.get_node(session.id, node.id)

        # then
        assert response.node.id == node.id
Ejemplo n.º 27
0
    def test_get_node_service_file(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node()

        # then
        with client.context_connect():
            response = client.get_node_service_file(session.id, node.id, "DefaultRoute", "defaultroute.sh")

        # then
        assert response.data is not None
Ejemplo n.º 28
0
    def test_get_node_service(self, grpc_server):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        node = session.add_node()

        # then
        with client.context_connect():
            response = client.get_node_service(session.id, node.id, "DefaultRoute")

        # then
        assert len(response.service.configs) > 0
Ejemplo n.º 29
0
    def test_move_nodes_exception(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        grpc_server.coreemu.create_session()

        def move_iter():
            yield core_pb2.MoveNodesRequest()

        # then
        with pytest.raises(grpc.RpcError):
            with client.context_connect():
                client.move_nodes(move_iter())
Ejemplo n.º 30
0
    def test_get_wlan_config(self, grpc_server: CoreGrpcServer):
        # given
        client = CoreGrpcClient()
        session = grpc_server.coreemu.create_session()
        wlan = session.add_node(WlanNode)

        # then
        with client.context_connect():
            response = client.get_wlan_config(session.id, wlan.id)

        # then
        assert len(response.config) > 0