Example #1
0
def _prepare_system_control_message(receiver, *, performative):
    msg = Message(to=receiver)
    msg.body = performative
    msg.thread = None
    msg.body = "heartbeat"
    msg.set_metadata("performative", performative)
    return msg
Example #2
0
    def build_cfp(receiver, agent_sender):
        msg = Message(to=receiver)
        msg.thread = str(agent_sender.jid)
        msg.set_metadata(CrossroadsMessages.PERFORMATIVE,
                         CrossroadsMessages.CFP)
        # msg.body dont like dicts (but strings), so... every data needed set to metadata, cause it;s a dict...
        msg.body = None
        msg.body = json.dumps(agent_sender.cfp)

        return msg
Example #3
0
def _prepare_message(receiver, information, *, performative="inform"):
    try:
        msg = Message(to=receiver)
        msg.thread = information['thread']
        msg.body = information['body']
        msg.set_metadata("performative", performative)
        msg.set_metadata("message_id", str(information['id']))
        return msg
    except Exception as e:
        print(e)
Example #4
0
def test_match_false_thread():
    template = Template()
    template.thread = "thread-id"

    message = Message()

    assert not template.match(message)

    message.thread = "thread-id-false"

    assert not template.match(message)
Example #5
0
def test_behaviour_match_without_template():
    class TestBehaviour(OneShotBehaviour):
        async def run(self):
            pass

    behaviour = TestBehaviour()

    msg = Message()
    msg.sender = "sender1@host"
    msg.to = "recv1@host"
    msg.body = "Hello World"
    msg.thread = "thread-id"
    msg.set_metadata("performative", "query")

    assert behaviour.match(msg)
Example #6
0
def test_behaviour_match_without_template():
    class TestBehaviour(OneShotBehaviour):
        async def run(self):
            pass

    behaviour = TestBehaviour()

    msg = Message()
    msg.sender = "sender1@host"
    msg.to = "recv1@host"
    msg.body = "Hello World"
    msg.thread = "thread-id"
    msg.set_metadata("performative", "query")

    assert behaviour.match(msg)
Example #7
0
def test_match():
    template = Template()
    template.sender = "sender1@host"
    template.to = "recv1@host"
    template.body = "Hello World"
    template.thread = "thread-id"
    template.metadata = {"performative": "query"}

    message = Message()
    message.sender = "sender1@host"
    message.to = "recv1@host"
    message.body = "Hello World"
    message.thread = "thread-id"
    message.set_metadata("performative", "query")

    assert template.match(message)
Example #8
0
async def request_path(agent, origin, destination, route_host):
    """
    Sends a message to the RouteAgent to request a path

    Args:
        agent: the agent who is requesting the path
        origin (list): a list with the origin coordinates [longitude, latitude]
        destination (list): a list with the target coordinates [longitude, latitude]
        route_host (str): name of the route host server

    Returns:
        list, float, float: a list of points (longitude and latitude) representing the path,
                            the distance of the path in meters, a estimation of the duration of the path

    Examples:
        >>> path, distance, duration = request_path(agent, origin=[0,0], destination=[1,1])
        >>> print(path)
        [[0,0], [0,1], [1,1]]
        >>> print(distance)
        2.0
        >>> print(duration)
        3.24
    """
    if origin[0] == destination[0] and origin[1] == destination[1]:
        return [[origin[1], origin[0]]], 0, 0

    msg = Message()
    msg.thread = str(uuid.uuid4()).replace("-", "")
    template = Template()
    template.thread = msg.thread
    behav = RequestRouteBehaviour(msg, origin, destination, route_host)
    agent.add_behaviour(behav, template)

    while not behav.is_killed():
        await asyncio.sleep(0.01)

    if (behav.exit_code is {} or "type" in behav.exit_code
            and behav.exit_code["type"] == "error"):
        return None, None, None
    else:
        return (
            behav.exit_code["path"],
            behav.exit_code["distance"],
            behav.exit_code["duration"],
        )
Example #9
0
def test_thread_set_none():
    msg = Message()
    msg.thread = None
Example #10
0
def test_thread_set_not_string():
    msg = Message()
    with pytest.raises(TypeError):
        msg.thread = 1000
Example #11
0
def test_thread_set_string():
    msg = Message()
    msg.thread = "thread_id_001"
Example #12
0
def test_thread_set_none():
    msg = Message()
    msg.thread = None
Example #13
0
def test_thread_set_not_string():
    msg = Message()
    with pytest.raises(TypeError):
        msg.thread = 1000
Example #14
0
def test_thread_set_string():
    msg = Message()
    msg.thread = "thread_id_001"
Example #15
0
template = Template()
# template.sender = "sender1@host"
template.sender = "madks@Temp3rr0r-pc"
# template.to = "recv1@host"
template.to = "admin@Temp3rr0r-pc"
template.body = "Hello World"
template.thread = "thread-id"
template.metadata = {"performative": "query"}

message = Message()
# message.sender = "sender1@host"
message.sender = "madks@Temp3rr0r-pc"
# message.to = "recv1@host"
message.to = "admin@Temp3rr0r-pc"
message.body = "Hello World"
message.thread = "thread-id"
message.set_metadata("performative", "query")

assert template.match(message)

t1 = Template()
# t1.sender = "sender1@host"
t1.sender = "madks@Temp3rr0r-pc"
t2 = Template()
# t2.to = "recv1@host"
t2.to = "admin@Temp3rr0r-pc"
t2.metadata = {"performative": "query"}

m = Message()
# m.sender = "sender1@host"
m.sender = "madks@Temp3rr0r-pc"
Example #16
0
def _prepare_respawn_notification(receiver, *, performative="inform"):
    msg = Message(to=receiver)
    msg.body = "respawn_notification"
    msg.thread = None
    msg.set_metadata("performative", performative)
    return msg