3. Messsage Transport

3.2. hamas.transport.contents module

Class for the payload in the messages.

This class represent the application layer of the agent communication protocol. Whereas the message class can be seen as the envelope, this class can be seen as the letter inside the envelope. The payload is not important for the delivery of the message, but is used by the receiving Agent itself.

class hamas.transport.contents.Content

Bases: hamas.transport.serializable.Serializable

class hamas.transport.contents.DictionaryContent(dictionary)

Bases: hamas.transport.contents.Content

class hamas.transport.contents.RemoteProcess(function)

Bases: hamas.transport.contents.Content

function
class hamas.transport.contents.RemoteProcessCall(function, args, kwargs)

Bases: hamas.transport.contents.RemoteProcess

args
kwargs
class hamas.transport.contents.RemoteProcessReply(function, returns)

Bases: hamas.transport.contents.RemoteProcess

returns
class hamas.transport.contents.StringContent(string)

Bases: hamas.transport.contents.Content

3.3. hamas.transport.fractions module

Fractions are the units on the transport layer.

class hamas.transport.fractions.Fraction(port, flag, seq_id=None, sdu=None)

Bases: object

static assemble_msg(fractions)

Assemble a serialized message out of fractions.

The sequence ID can start at any number and can be overlapped, thus it needs to be passed as argument.

Parameters:fractions (list) –
Returns:The assembled, serialized message.
Return type:msg (bytes)
classmethod deserialize(serialized)

Disassemble a single fraction.

Parameters:serialized (bytes) –
classmethod disassemble(port, msg, mtu)

Prepare a message for sending.

A agent to agent message is probably too long, so it needs to be separated in fractions.

Parameters:
  • port (int) – The used port on both sides
  • msg (bytes) – The message which will be separated in fractions.
  • mtu (int) – The maximum transmission unit
Returns:

the ready to send PDUs

Return type:

pdus (list)

flag
flag_decodings = {b'\x04': 'RST', b'\x03': 'FIN', b'\x02': 'DATA', b'\x05': 'URL', b'\x00': 'SYN', b'\x06': 'JOIN', b'\x01': 'SYN-ACK'}
flag_encodings = {'RST': b'\x04', 'SYN-ACK': b'\x01', 'SYN': b'\x00', 'JOIN': b'\x06', 'FIN': b'\x03', 'URL': b'\x05', 'DATA': b'\x02'}
flag_fmt = 'c'
static get_port(serialized)
header_fmt = '>BHc'
classmethod header_len()
classmethod max_ports()
classmethod max_sdu_len(mtu)
classmethod max_size(mtu)
classmethod num_fractions(msg, mtu)
port
port_fmt = 'B'
sdu
seq_id
seq_id_fmt = 'H'
serialize()

3.4. hamas.transport.message_transport module

class hamas.transport.message_transport.MessageTransportSystem(platform, has_platform, has_zigbee, has_mqtt, has_uds, regex, broker, update_interval=60)

Bases: object

Provides the communication between agents.

Parameters:
  • platform (AgentPlatform) – The agent platform on which the message transport system resides.
  • has_platform (bool) – Define if a PlatformConnector should be initialised.
  • has_zigbee (bool) – Define if a ZigBeeConnector should be initialised.
  • has_mqtt (bool) – Define if a MqttConnector should be initialised.
  • has_uds (bool) – Define if a UnixConnector should be initialised.
  • regex (str) – A regular expression to find the ZigBee device, if needed.
  • broker (str) – The address of the MQTT broker.
  • update_interval (int,float) – Define in what interval the connectors should update their network.
_init_mqtt_conn(broker)

Initiate the MQTT Connector.

_init_platform_conn()

Initiate the platform connector.

_init_unix_conn()

Initiate the unix domain socket connector.

_init_zigbee_conn(regex)

Initiate the ZigBee Connector.

coroutine _unicast(message, recipient)

Send a message to one specific agent.

loop
other_platforms
classmethod parse_aid(aid)
platform_name
coroutine receive(message)
coroutine send(message)

This method checks the routing option.

This is a coroutine because it has to wait for the xbee module in another thread.

coroutine start()
stop()
coroutine wait_for_zigbee()

3.5. hamas.transport.messages module

The classes that agents can send to each other

A message is mapped to the transport and session layer of the agent communication protocol. The sender, recipient and routing options are used to deliver the message. The content field is used by the receiving agent. The message class is the envelope and the content is the letter. The request class is necessary to open a session, which is called conversation. A conversation are all messages with the same conversation ID. The normal use case is that an agent sends a Request and the receiving agent will answer with an instance of Reply. The platform will then match these two messages and establish in that way a conversation.

class hamas.transport.messages.Message(sender, content=None, recipient=None, routing='unicast', conversation_id=None, performative=None)

Bases: hamas.transport.serializable.Serializable

The object that agents sends to other agents.

The sending agent doesn’t expect any reply.

recipient

str, None – The recipient

_sender

str – The sender

content

Content – The content data

_routing

str – The routing scheme of the message

__conversation_id

bytes – Control of conversation. This number shall be unique for one conversation. Also this field can only be read.

conversation_id
classmethod deserialize(serialized, *args)
performative
recipient
routing

Returns the routing scheme of the message.

Unicast: To one defined recipient. Broadcast: To all agents.

sender

Returns the AID of the sender

3.6. hamas.transport.serializable module

Serializable objects like messages and Payloads

Classes which inherits from this class have to overwrite _get_init_args to be serializable.

class hamas.transport.serializable.Serializable

Bases: abc.ABC

Objects which can be transformed to a bytes object

_get_init_args()

Helper function for the serialization

Returns:the positional constructor arguments as tuple
Return type:args (tuple)
classmethod deserialize(serialized)

Deserialize a bytes object to a Content object

Parameters:serialized (bytes) – The serialized object.
Returns:Returns an instance of the class Content
Return type:payload(Content)
pickle()
serialize()

Serialize this instance to a bytes object

Returns:The serialized object.
Return type:serialized (bytes)
serializers = {b'\x04': 'hamas.transport.contents.DictionaryContent', b'\x03': 'hamas.transport.contents.StringContent', b'\x02': 'hamas.transport.contents.RemoteProcessReply', b'\x05': 'hamas.transport.messages.Message', b'\x01': 'hamas.transport.contents.RemoteProcessCall'}
static unpickle(serialized)