Skip to content

Commit

Permalink
✨ Give name to DATA packet from discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Benito Palacios Sanchez committed Dec 11, 2016
1 parent b9eebfa commit 5aa1c41
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
17 changes: 10 additions & 7 deletions logparser/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
from logparser.devices.logger import (log_cfg, log_error, log_process,
log_recv, log_send, log_warning)
from logparser.utils import (add_statistics_bandwidth, add_statistics_packet,
get_locator, get_oid, get_participant,
get_port_name, get_port_number, hex2ip,
is_builtin_entity, parse_guid, parse_sn)
get_data_packet_name, get_locator, get_oid,
get_participant, get_port_name, get_port_number,
hex2ip, is_builtin_entity, parse_guid, parse_sn)


# --------------------------------------------------------------------------- #
Expand Down Expand Up @@ -169,12 +169,13 @@ def on_send_data(match, state):
def on_resend_data(match, state):
"""It happens when the writer resend a DATA message."""
writer_oid = get_oid(match[0])
packet_name = get_data_packet_name(match[0])
remote_part = parse_guid(state, match[1], match[2], match[3])
remote_oid = get_oid(match[4])
seqnum = parse_sn(match[5])
verb = 1 if is_builtin_entity(match[0]) else 0
log_send(remote_part, writer_oid,
"Resend DATA (%d) to reader %s" % (seqnum, remote_oid),
"Resend %s [%d] to reader %s" % (packet_name, seqnum, remote_oid),
state, verb)


Expand Down Expand Up @@ -329,6 +330,7 @@ def on_receive_data(match, state):
remote = match[5].split('.')
writer_addr = parse_guid(state, remote[0], remote[1], remote[2])
writer_oid = get_oid(remote[3])
packet = get_data_packet_name(remote[3]) if packet == "DATA" else packet

# Sequece number check
full_id = writer_addr + "." + writer_oid + ' to ' + reader_oid
Expand All @@ -345,7 +347,7 @@ def on_receive_data(match, state):

# Show the message after any possible warning.
verb = 1 if is_builtin_entity(remote[3]) else 0
log_recv(writer_addr, reader_oid, "Received %s (%d) from writer %s (%s)" %
log_recv(writer_addr, reader_oid, "Received %s [%d] from writer %s (%s)" %
(packet, seqnum, writer_oid, comm),
state, verb)

Expand All @@ -358,9 +360,10 @@ def on_receive_out_order_data(match, state):
remote = match[3].split('.')
writer_addr = parse_guid(state, remote[0], remote[1], remote[2])
writer_oid = get_oid(remote[3])
packet_name = get_data_packet_name(remote[3])
verb = 1 if is_builtin_entity(remote[3]) else 0
log_recv(writer_addr, reader_oid, "Received %s DATA (%d) from writer %s" %
(kind, seqnum, writer_oid),
log_recv(writer_addr, reader_oid, "Received %s %s [%d] from writer %s" %
(kind, packet_name, seqnum, writer_oid),
state, verb)


Expand Down
15 changes: 13 additions & 2 deletions logparser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
+ add_statistics_packets: Add the given packet to the packet statistics.
+ add_statistics_bandwidth: Add the given packet to the bandwidth statistics.
+ obfuscate: Obfuscate the given text.
+ get_oid: Parse the entity object ID and conver to text.
+ is_builtin_entity: Get if the OID hex number is for a built-in entity.
+ get_oid: Get a name for the entity ID in hexadecimal text format.
+ is_builtin_entity: Return if the OID hex number is for a built-in entity.
+ get_data_packet_name: Return the DATA packet name.
+ get_topic_name: Get the topic name, obfuscating if needed.
+ get_type_name: Get the type name, obfuscating if needed.
+ get_port_number: Get the port number, obfuscating if needed.
Expand Down Expand Up @@ -213,6 +214,16 @@ def is_builtin_entity(oid):
return oid_num & 0xC0 == 0xC0


def get_data_packet_name(oid):
"""Return the DATA packet name."""
# More information in get_oid
entity_name = get_oid(oid)
PACKET_NAMES = {
"SED_PUB_WRITER": "DATA(w)", "SED_SUB_WRITER": "DATA(r)",
"SPD_PART_WRITER": "DATA(p)", "MESSAGE_WRITER": "DATA(m)"}
return PACKET_NAMES[entity_name] if entity_name in PACKET_NAMES else "DATA"


def get_topic_name(topic, state):
"""Get the topic name, obfuscating if needed."""
return obfuscate(topic, state) if state['obfuscate'] else topic
Expand Down

0 comments on commit 5aa1c41

Please sign in to comment.