From 20c50fa34be62d0d7d86996a4688be35424e9b83 Mon Sep 17 00:00:00 2001 From: Benito Palacios Sanchez Date: Wed, 14 Dec 2016 00:14:55 +0100 Subject: [PATCH 1/6] :art: Apply code review format changes Pull Request #8 --- logparser/__init__.py | 2 +- logparser/devices/logger.py | 2 +- logparser/devices/markdownformatdevice.py | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/logparser/__init__.py b/logparser/__init__.py index 3853b50..366c7e6 100644 --- a/logparser/__init__.py +++ b/logparser/__init__.py @@ -13,7 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""Package LogParser.""" +"""LogParser package.""" __version__ = "1.2a2" __license__ = "Apache" diff --git a/logparser/devices/logger.py b/logparser/devices/logger.py index 87897a0..6365cde 100644 --- a/logparser/devices/logger.py +++ b/logparser/devices/logger.py @@ -82,7 +82,7 @@ def log(content, level, state): for kind in filter(None, content.get('kind', '').split("|")): for subkind in KIND_TO_COLOR[kind].split("|"): color += COLORS[subkind] - if len(color) > 0: + if len(color): content['description'] = color + content['description'] + \ COLORS['END'] diff --git a/logparser/devices/markdownformatdevice.py b/logparser/devices/markdownformatdevice.py index 7eb3619..9b69c18 100644 --- a/logparser/devices/markdownformatdevice.py +++ b/logparser/devices/markdownformatdevice.py @@ -202,7 +202,6 @@ def write_statistics_bandwidth(self, state): for typ in stats[addr]: # If this is a port with dictionary of statistics types if isinstance(stats[addr][typ], dict): - # Show statistics per port with verbosity >= 1 if state['verbosity'] < 1: continue port = typ From 17749c3dc9b39e068f40672b50c53bf274ae936b Mon Sep 17 00:00:00 2001 From: Benito Palacios Sanchez Date: Wed, 14 Dec 2016 18:18:36 +0100 Subject: [PATCH 2/6] :art: Apply CR feedback from #9 --- README.md | 3 +++ logparser/devices/inputdevices.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fcc2319..03f3e0f 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,13 @@ Logger.get_instance().set_verbosity_by_category( * Environment variable `NDDS_QOS_PROFILES`. It is possible to specify an inline XML QoS profile inside the variable: ```bash +# Bash export NDDS_QOS_PROFILES="str://\"ALLALLTIMESTAMPED\"" +# Tcsh setenv NDDS_QOS_PROFILES 'str://"ALLALLTIMESTAMPED"' +# Windows CMD set NDDS_QOS_PROFILES=str://"ALLALLTIMESTAMPED" ``` diff --git a/logparser/devices/inputdevices.py b/logparser/devices/inputdevices.py index 2483c27..c00e51e 100644 --- a/logparser/devices/inputdevices.py +++ b/logparser/devices/inputdevices.py @@ -128,7 +128,7 @@ def print_progress(self, threshold=0, decimals=1, barLength=100): return progress = 100.0 * iteration / total - if self.progress > 0 and progress - self.progress < threshold: + if self.progress and progress - self.progress < threshold: return self.progress = progress From 5b5cdd2a6f8462efc7691ed1d42ae1d64f9dadf5 Mon Sep 17 00:00:00 2001 From: Benito Palacios Sanchez Date: Sun, 11 Dec 2016 13:16:18 +0100 Subject: [PATCH 3/6] :bug: Fix entity GUID parsing The algorithm get the name of a entity GUID was returning in some cases INVALID or the wrong entity ID. Sometimes, two different entities were referred with the same name. --- logparser/utils.py | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/logparser/utils.py b/logparser/utils.py index ec666bb..9a4e4ba 100644 --- a/logparser/utils.py +++ b/logparser/utils.py @@ -166,35 +166,44 @@ def obfuscate(text, state): def get_oid(oid): - """Parse the entity object ID and conver to text.""" - oid_names = { + """Get a name for the entity ID in hexadecimal text format.""" + # Information from RTPS Spec: http://www.omg.org/spec/DDSI-RTPS/2.2/PDF/ + BUILTIN_NAMES = { # Built-in OID names. - 0x00000000: "UNKNOWN", 0x000001c1: "BUILTIN_PARTIC", - 0x000002c2: "TOPIC_WRITER", 0x000002c7: "TOPIC_READER", - 0x000003c2: "PUB_WRITER", 0x000003c7: "PUB_READER", - 0x000004c2: "SUB_WRITER", 0x000004c7: "SUB_READER", - 0x000100c2: "PARTIC_WRITER", 0x000100c7: "PARTIC_READER", + 0x00000000: "UNKNOWN", 0x000001c1: "PARTICIPANT", + 0x000002c2: "SED_TOPIC_WRITER", 0x000002c7: "SED_TOPIC_READER", + 0x000003c2: "SED_PUB_WRITER", 0x000003c7: "SED_PUB_READER", + 0x000004c2: "SED_SUB_WRITER", 0x000004c7: "SED_SUB_READER", + 0x000100c2: "SPD_PART_WRITER", 0x000100c7: "SPD_PART_READER", 0x000200c2: "MESSAGE_WRITER", 0x000200c7: "MESSAGE_READER"} - user_oid_kind = { - # Application defined entities. - 0x00: "UNK", 0x01: "PAR", + ENTITY_ORIGINS = {0x00: "USER", 0x40: "VEND", 0xc0: "BUILTIN"} + ENTITY_KINDS = { + 0x00: "UNK", 0x01: "PART", 0x02: "W+K", 0x03: "W-K", 0x04: "R-K", 0x07: "R+K"} + + # Convert into a number from the hexadecimal text representation oid_num = int(oid, 16) - if oid_num & 0x80000000 == 0: - name = oid_names[oid_num] if oid_num in oid_names else oid + + # Analyze the entity kind + entity_kind = oid_num & 0xFF + origin = ENTITY_ORIGINS[entity_kind & 0xC0] + kind = ENTITY_KINDS[entity_kind & 0x3F] + + if origin == "BUILTIN": + name = BUILTIN_NAMES[oid_num] + elif origin == "USER": + name = kind + "_" + hex(oid_num >> 8)[2:].zfill(6) else: - kind = oid_num & 0xFF - kind = user_oid_kind[kind] if kind in user_oid_kind else "INV" - num = (oid_num & 0x7FFFF000) >> 13 - name = str(num).zfill(2) + "_" + kind + name = origin + "_" + kind + "_" + hex(oid_num >> 8)[2:].zfill(6) return name def is_builtin_entity(oid): - """Get if the OID hex number is for a built-in entity.""" + """Return if the OID hex number is for a built-in entity.""" + # More information in get_oid oid_num = int(oid, 16) - return oid_num & 0x80000000 == 0 + return oid_num & 0xC0 == 0xC0 def get_topic_name(topic, state): From eb635c35eb62ed337b3fa6e4a89404261de68f02 Mon Sep 17 00:00:00 2001 From: Benito Palacios Sanchez Date: Sun, 11 Dec 2016 13:31:06 +0100 Subject: [PATCH 4/6] :sparkles: Add security entity GUID --- logparser/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/logparser/utils.py b/logparser/utils.py index 9a4e4ba..2b1f2b6 100644 --- a/logparser/utils.py +++ b/logparser/utils.py @@ -168,14 +168,21 @@ def obfuscate(text, state): def get_oid(oid): """Get a name for the entity ID in hexadecimal text format.""" # Information from RTPS Spec: http://www.omg.org/spec/DDSI-RTPS/2.2/PDF/ + # Security entities: http://www.omg.org/spec/DDS-SECURITY/1.0/Beta2/ BUILTIN_NAMES = { - # Built-in OID names. + # Built-in Entity GUIDs 0x00000000: "UNKNOWN", 0x000001c1: "PARTICIPANT", 0x000002c2: "SED_TOPIC_WRITER", 0x000002c7: "SED_TOPIC_READER", 0x000003c2: "SED_PUB_WRITER", 0x000003c7: "SED_PUB_READER", 0x000004c2: "SED_SUB_WRITER", 0x000004c7: "SED_SUB_READER", 0x000100c2: "SPD_PART_WRITER", 0x000100c7: "SPD_PART_READER", - 0x000200c2: "MESSAGE_WRITER", 0x000200c7: "MESSAGE_READER"} + 0x000200c2: "MESSAGE_WRITER", 0x000200c7: "MESSAGE_READER", + # Security Built-in Entity GUIDs + 0xff0003c2: "SED_PUB_SEC_WRITER", 0xff0003c7: "SED_PUB_SEC_READER", + 0xff0004c2: "SED_SUB_SEC_WRITER", 0xff0004c7: "SED_SUB_SEC_READER", + 0xff0200c2: "MSG_SEC_WRITER", 0xff0200c7: "MSG_SEC_READER", + 0x000201c2: "MSG_STA_SEC_WRITER", 0x000201c7: "MSG_STA_SEC_READER", + 0xff0202c2: "MSG_VOL_SEC_WRITER", 0xff0202c7: "MSG_VOL_SEC_READER"} ENTITY_ORIGINS = {0x00: "USER", 0x40: "VEND", 0xc0: "BUILTIN"} ENTITY_KINDS = { 0x00: "UNK", 0x01: "PART", From 7139a49f6e678504828cd80c495f2b43ca6de8d7 Mon Sep 17 00:00:00 2001 From: Benito Palacios Sanchez Date: Sun, 11 Dec 2016 13:49:20 +0100 Subject: [PATCH 5/6] :sparkles: Give name to DATA packet from discovery --- logparser/network/network.py | 17 ++++++++++------- logparser/utils.py | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/logparser/network/network.py b/logparser/network/network.py index 25af4cd..51824f0 100644 --- a/logparser/network/network.py +++ b/logparser/network/network.py @@ -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) # --------------------------------------------------------------------------- # @@ -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) @@ -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 @@ -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) @@ -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) diff --git a/logparser/utils.py b/logparser/utils.py index 2b1f2b6..e316bd6 100644 --- a/logparser/utils.py +++ b/logparser/utils.py @@ -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. @@ -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 From b1d6c469350ea5122f5334ec56d4a0794ce95a28 Mon Sep 17 00:00:00 2001 From: Benito Palacios Sanchez Date: Mon, 19 Dec 2016 17:18:52 +0100 Subject: [PATCH 6/6] :art: Improve comments with CR feedback #10 --- logparser/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logparser/utils.py b/logparser/utils.py index e316bd6..28b51f3 100644 --- a/logparser/utils.py +++ b/logparser/utils.py @@ -168,7 +168,7 @@ def obfuscate(text, state): def get_oid(oid): """Get a name for the entity ID in hexadecimal text format.""" - # Information from RTPS Spec: http://www.omg.org/spec/DDSI-RTPS/2.2/PDF/ + # Information from RTPS Spec: http://www.omg.org/spec/DDSI-RTPS/ # Security entities: http://www.omg.org/spec/DDS-SECURITY/1.0/Beta2/ BUILTIN_NAMES = { # Built-in Entity GUIDs @@ -190,7 +190,7 @@ def get_oid(oid): 0x02: "W+K", 0x03: "W-K", 0x04: "R-K", 0x07: "R+K"} - # Convert into a number from the hexadecimal text representation + # Convert the hexadecimal text representation to a number oid_num = int(oid, 16) # Analyze the entity kind