|
@@ -13,14 +13,16 @@ class MessageMapping:
|
|
|
|
|
|
ATTR_PACKET_TIME = "packet_time"
|
|
|
|
|
|
- def __init__(self, messages):
|
|
|
+ def __init__(self, messages, pcap_start_timestamp_str):
|
|
|
self.messages = messages
|
|
|
self.id_to_packet = {}
|
|
|
+ ts_date_format = "%Y-%m-%d %H:%M:%S.%f"
|
|
|
+ self.pcap_start_dt = datetime.datetime.strptime(pcap_start_timestamp_str, ts_date_format)
|
|
|
|
|
|
def map_message(self, message, packet):
|
|
|
self.id_to_packet[message.msg_id] = packet
|
|
|
|
|
|
- def to_xml(self):
|
|
|
+ def to_xml(self, ):
|
|
|
doc = Document()
|
|
|
|
|
|
mappings = doc.createElement(self.TAG_MAPPING_GROUP)
|
|
@@ -34,11 +36,13 @@ class MessageMapping:
|
|
|
mapping.setAttribute("Src", str(message.src["ID"]))
|
|
|
mapping.setAttribute("Dst", str(message.dst["ID"]))
|
|
|
mapping.setAttribute("Type", str(message.type.value))
|
|
|
+ mapping.setAttribute("CSV_XML_Time", str(message.csv_time))
|
|
|
|
|
|
dt = datetime.datetime.fromtimestamp(message.time)
|
|
|
- mapping.setAttribute("Time", str(message.time))
|
|
|
- mapping.setAttribute("Time-Datetime", dt.strftime("%Y-%m-%d %H:%M:%S.") + str(dt.microsecond))
|
|
|
- mapping.setAttribute("Time-Timeonly", dt.strftime("%H:%M:%S.") + str(dt.microsecond))
|
|
|
+ dt_relative = dt - self.pcap_start_dt
|
|
|
+ mapping.setAttribute("PCAP_Time-Timestamp", str(message.time))
|
|
|
+ mapping.setAttribute("PCAP_Time-Datetime", dt.strftime("%Y-%m-%d %H:%M:%S.") + str(dt.microsecond))
|
|
|
+ mapping.setAttribute("PCAP_Time-Relative", "%d.%s" % (dt_relative.total_seconds(), str(dt_relative.microseconds).rjust(6, "0")))
|
|
|
|
|
|
packet = self.id_to_packet.get(message.msg_id)
|
|
|
mapping.setAttribute(self.ATTR_HAS_PACKET, "true" if packet is not None else "false")
|