def test_correct_usage():
    # Test the constructor
    sa1 = SocketAddress("a", 2, 3)
    sa2 = SocketAddress("a", 2, 3)
    sa3 = SocketAddress("b", 2, 3)
    sa4 = SocketAddress("a", 4, 3)
    sa5 = SocketAddress("a", 2, 5)

    # Test the properties
    assert sa1.listen_port == 3
    assert sa1.notify_host_name == "a"
    assert sa1.notify_port_no == 2

    # Test the equality and other basic ops
    assert sa1 == sa1
    assert sa1 == sa2
    assert sa1 != ("a", 2, 3)
    assert sa1 != sa3
    assert sa1 != sa4
    assert sa1 != sa5
    assert repr(sa1) == "SocketAddress('a', 2, 3)"
    assert str(sa1) == "SocketAddress('a', 2, 3)"

    # Test that we can use them as dictionary keys like a tuple
    d = dict()
    d[sa1] = 123
    d[sa2] = 234
    d[sa3] = 345
    d[sa4] = 456
    d[sa5] = 567
    assert len(d) == 4
    assert d[sa1] == 234
def test_wrong_usage():
    sa = SocketAddress(None, 1, 1)
    # Stringified the None...
    assert sa.notify_host_name == "None"

    with pytest.raises(TypeError):
        SocketAddress("a", None, 1)
    with pytest.raises(ValueError):
        SocketAddress("a", 1, "a")
예제 #3
0
    def add_database_socket_address(database_notify_host,
                                    database_notify_port_num,
                                    database_ack_port_num):
        """
        :param database_notify_host:
            Host to talk to tell that the database (and application) is ready.
        :type database_notify_host: str or None
        :param database_notify_port_num:
            Port to talk to tell that the database (and application) is ready.
        :type database_notify_port_num: int or None
        :param database_ack_port_num:
            Port on which to listen for an acknowledgement that the
            simulation should start.
        :type database_ack_port_num: int or None
        """
        if database_notify_port_num is None:
            database_notify_port_num = get_config_int("Database",
                                                      "notify_port")
        if database_notify_host is None:
            database_notify_host = get_config_str("Database",
                                                  "notify_hostname")
        elif database_notify_host == "0.0.0.0":
            database_notify_host = "localhost"
        if database_ack_port_num is None:
            database_ack_port_num = get_config_int("Database", "listen_port")

        # build the database socket address used by the notification interface
        database_socket = SocketAddress(
            listen_port=database_ack_port_num,
            notify_host_name=database_notify_host,
            notify_port_no=database_notify_port_num)

        # update socket interface with new demands.
        SpynnakerExternalDevicePluginManager.add_socket_address(
            database_socket)
예제 #4
0
    def add_database_socket_address(
            database_notify_host, database_notify_port_num,
            database_ack_port_num):
        config = get_simulator().config
        if database_notify_port_num is None:
            database_notify_port_num = helpful_functions.read_config_int(
                config, "Database", "notify_port")
        if database_notify_host is None:
            database_notify_host = helpful_functions.read_config(
                config, "Database", "notify_hostname")
        elif database_notify_host == "0.0.0.0":
            database_notify_host = "localhost"
        if database_ack_port_num is None:
            database_ack_port_num = helpful_functions.read_config_int(
                config, "Database", "listen_port")

        # build the database socket address used by the notification interface
        database_socket = SocketAddress(
            listen_port=database_ack_port_num,
            notify_host_name=database_notify_host,
            notify_port_no=database_notify_port_num)

        # update socket interface with new demands.
        SpynnakerExternalDevicePluginManager.add_socket_address(
            database_socket)
예제 #5
0
파일: gfe.py 프로젝트: jofas/master_thesis
def __add_db_sock():
    database_socket = SocketAddress(
        listen_port=globals.ack_port,
        notify_host_name=globals.host,
        notify_port_no=globals.notify_port
    )

    get_simulator().add_socket_address(database_socket)
예제 #6
0
def register_database_notification_request(hostname, notify_port, ack_port):
    """ Adds a socket system which is registered with the notification protocol

    :param hostname: hostname to connect to
    :param notify_port: port num for the notify command
    :param ack_port: port num for the acknowledge command
    :rtype: None
    """
    spynnaker_external_devices.add_socket_address(
        SocketAddress(hostname, notify_port, ack_port))
예제 #7
0
 def test_send_start_resume_notification(self):
     """ Test the sending of the start/resume message of the notification\
         protocol
     """
     listener = EIEIOConnection()
     socket_addresses = [
         SocketAddress("127.0.0.1", listener.local_port, None)
     ]
     protocol = NotificationProtocol(socket_addresses, False)
     protocol.send_start_resume_notification()
     message = listener.receive_eieio_message(timeout=10)
     self.assertIsInstance(message, EIEIOCommandMessage)
     self.assertEqual(message.eieio_header.command,
                      EIEIO_COMMAND_IDS.START_RESUME_NOTIFICATION.value)
예제 #8
0
def add_socket_address(database_ack_port_num, database_notify_host,
                       database_notify_port_num):
    """ Adds a socket address for the notification protocol.

    :param database_ack_port_num: port number to send acknowledgement to
    :param database_notify_host: host IP to send notification to
    :param database_notify_port_num: port that the external device will be\
        notified on.
    """
    database_socket = SocketAddress(listen_port=database_ack_port_num,
                                    notify_host_name=database_notify_host,
                                    notify_port_no=database_notify_port_num)

    _sim().add_socket_address(database_socket)
예제 #9
0
def add_socket_address(database_ack_port_num, database_notify_host,
                       database_notify_port_num):
    """
    adds a socket address for the notification protocol

    :param database_ack_port_num: port num to send acknowledgement to
    :param database_notify_host: host ip to send notification to
    :param database_notify_port_num: port that the external device will be\
        notified on.
    """
    database_socket = SocketAddress(listen_port=database_ack_port_num,
                                    notify_host_name=database_notify_host,
                                    notify_port_no=database_notify_port_num)

    globals_variables.get_simulator().add_socket_address(database_socket)
예제 #10
0
def run_broken():
    machine_time_step = 1000
    time_scale_factor = 1
    # machine_port = 11111
    machine_receive_port = 22222
    machine_host = "0.0.0.0"
    live_gatherer_label = "LiveHeatGatherer"
    notify_port = 19999
    database_listen_port = 19998

    # set up the front end and ask for the detected machines dimensions
    front_end.setup(
        graph_label="heat_demo_graph",
        model_binary_module=sys.modules[__name__],
        database_socket_addresses={SocketAddress(
            "127.0.0.1", notify_port, database_listen_port)})
    machine = front_end.machine()

    # create a live gatherer vertex for each board
    default_gatherer = None
    live_gatherers = dict()
    used_cores = set()
    for chip in machine.ethernet_connected_chips:

        # Try to use core 17 if one is available as it is outside the grid
        processor = chip.get_processor_with_id(17)
        if processor is None or processor.is_monitor:
            processor = chip.get_first_none_monitor_processor()
        if processor is not None:
            live_gatherer = front_end.add_machine_vertex(
                LivePacketGatherMachineVertex,
                {
                    'label': live_gatherer_label,
                    'ip_address': machine_host,
                    'port': machine_receive_port,
                    'payload_as_time_stamps': False,
                    'use_payload_prefix': False,
                    'strip_sdp': True,
                    'message_type': EIEIOType.KEY_PAYLOAD_32_BIT
                }
            )
            live_gatherers[chip.x, chip.y] = live_gatherer
            used_cores.add((chip.x, chip.y, processor.processor_id))
            if default_gatherer is None:
                default_gatherer = live_gatherer

    # Create a list of lists of vertices (x * 4) by (y * 4)
    # (for 16 cores on a chip - missing cores will have missing vertices)
    max_x_element_id = (machine.max_chip_x + 1) * 4
    max_y_element_id = (machine.max_chip_y + 1) * 4
    vertices = [
        [None for _ in range(max_y_element_id)]
        for _ in range(max_x_element_id)
    ]

    receive_labels = list()
    for x in range(0, max_x_element_id):
        for y in range(0, max_y_element_id):

            chip_x = x / 4
            chip_y = y / 4
            core_x = x % 4
            core_y = y % 4
            core_p = ((core_x * 4) + core_y) + 1

            # Add an element if the chip and core exists
            chip = machine.get_chip_at(chip_x, chip_y)
            if chip is not None:
                core = chip.get_processor_with_id(core_p)
                if (core is not None and not core.is_monitor and
                        (chip_x, chip_y, core_p) not in used_cores):
                    element = front_end.add_machine_vertex(
                        HeatDemoVertex,
                        {
                            'machine_time_step': machine_time_step,
                            'time_scale_factor': time_scale_factor
                        },
                        label="Heat Element {}, {}".format(
                            x, y))
                    vertices[x][y] = element
                    vertices[x][y].add_constraint(
                        ChipAndCoreConstraint(chip_x, chip_y, core_p))

                    # add a link from the heat element to the live packet
                    # gatherer
                    live_gatherer = live_gatherers.get(
                        (chip.nearest_ethernet_x, chip.nearest_ethernet_y),
                        default_gatherer)
                    front_end.add_machine_edge(
                        MachineEdge,
                        {
                            'pre_vertex': vertices[x][y],
                            'post_vertex': live_gatherer
                        },
                        label="Live output from {}, {}".format(x, y),
                        semantic_label="TRANSMISSION")
                    receive_labels.append(vertices[x][y].label)

    # build edges
    for x in range(0, max_x_element_id):
        for y in range(0, max_y_element_id):

            if vertices[x][y] is not None:

                # Add a north link if not at the top
                if y+1 < max_y_element_id and vertices[x][y+1] is not None:
                    front_end.add_machine_edge(
                        HeatDemoEdge,
                        {
                            'pre_vertex': vertices[x][y],
                            'post_vertex': vertices[x][y + 1],
                            'direction': HeatDemoEdge.DIRECTIONS.SOUTH
                        },
                        label="North Edge from {}, {} to {}, {}".format(
                            x, y, x + 1, y),
                        semantic_label="TRANSMISSION")

                # Add an east link if not at the right
                if x+1 < max_y_element_id and vertices[x+1][y] is not None:
                    front_end.add_machine_edge(
                        HeatDemoEdge,
                        {
                            'pre_vertex': vertices[x][y],
                            'post_vertex': vertices[x + 1][y],
                            'direction': HeatDemoEdge.DIRECTIONS.WEST
                        },
                        label="East Edge from {}, {} to {}, {}".format(
                            x, y, x + 1, y),
                        semantic_label="TRANSMISSION")

                # Add a south link if not at the bottom
                if (y - 1) >= 0 and vertices[x][y - 1] is not None:
                    front_end.add_machine_edge(
                        HeatDemoEdge,
                        {
                            'pre_vertex': vertices[x][y],
                            'post_vertex': vertices[x][y - 1],
                            'direction': HeatDemoEdge.DIRECTIONS.NORTH
                        },
                        label="South Edge from {}, {} to {}, {}".format(
                            x, y, x, y - 1),
                        semantic_label="TRANSMISSION")

                # check for the likely hood for a W link
                if (x - 1) >= 0 and vertices[x - 1][y] is not None:
                    front_end.add_machine_edge(
                        HeatDemoEdge,
                        {
                            'pre_vertex': vertices[x][y],
                            'post_vertex': vertices[x - 1][y],
                            'direction': HeatDemoEdge.DIRECTIONS.EAST
                        },
                        label="West Edge from {}, {} to {}, {}".format(
                            x, y, x - 1, y),
                        semantic_label="TRANSMISSION")

    # Set up the live connection for receiving heat elements
    live_heat_connection = LiveEventConnection(
        live_gatherer_label, receive_labels=receive_labels,
        local_port=notify_port, machine_vertices=True)
    heat_values = defaultdict(list)
    condition = Condition()

    def receive_heat(label, atom, value):
        with condition:
            print "{}: {}".format(label, value / 65536.0)

    # Set up callbacks to occur when spikes are received
    for label in receive_labels:
        live_heat_connection.add_receive_callback(label, receive_heat)

    front_end.run(1000)
    front_end.stop()

    for label in receive_labels:
        print "{}: {}".format(
            label, ["{:05.2f}".format(value) for value in heat_values[label]])