# Path: sts/input_traces/input_logger.py
# class InputLogger(object):
#   '''Log input events injected by a control_flow.Fuzzer'''
# 
#   def __init__(self):
#     self.last_time = SyncTime.now()
#     self._disallow_timeouts = False
#     self._events_after_close = []
#     self.output = None
#     self.output_path = ""
# 
#   def open(self, results_dir=None, output_filename="events.trace"):
#     if results_dir is not None:
#       self.output_path = results_dir + "/" + output_filename
#       self.replay_cfg_path = results_dir + "/replay_config.py"
#       self.mcs_cfg_path = results_dir + "/mcs_config.py"
#       self.interactive_replay_cfg_path = results_dir + "/interactive_replay_config.py"
#       self.openflow_replay_cfg_path = results_dir + "/openflow_replay_config.py"
#     else:
#       raise ValueError("Default results_dir currently not supported")
#     self.output = open(self.output_path, 'w')
# 
#   def disallow_timeouts(self):
#     self._disallow_timeouts = True
# 
#   def allow_timeouts(self):
#     self._disallow_timeouts = False
# 
#   def _serialize_event(self, event, output):
#     if self._disallow_timeouts and hasattr(event, "disallow_timeouts"):
#       event.timeout_disallowed = True
#     self.last_time = event.time
#     json_hash = event.to_json()
#     log.debug("logging event %r" % event)
#     output.write(json_hash + '\n')
# 
#   def log_input_event(self, event):
#     '''
#     Log the event as a json hash.
#     '''
#     if not self.output:
#       raise Exception("Not opened -- call InputLogger.open")
#     if not self.output.closed:
#       self._serialize_event(event, self.output)
#     else:
#       self._events_after_close.append(event)
# 
#   def dump_buffered_events(self, events):
#     ''' If there were un-acknowledge message receives or state changes at the
#     end of the run, dump them to a separate input trace ".unacked" '''
#     with open(self.output_path + ".unacked", 'w') as output:
#       for event in events + self._events_after_close:
#         self._serialize_event(event, output)
# 
#   def close(self, control_flow, simulation_cfg, skip_mcs_cfg=False):
#     # First, insert a WaitTime, in case there was a controller crash
#     self.log_input_event(WaitTime(1.0, time=self.last_time))
#     # Flush the json input log
#     self.output.close()
# 
#     # Write the config files
#     path_templates = [(self.replay_cfg_path, replay_config_template),
#                       (self.interactive_replay_cfg_path, interactive_replay_config_template),
#                       (self.openflow_replay_cfg_path, openflow_replay_config_template)]
#     if not skip_mcs_cfg:
#       path_templates.append((self.mcs_cfg_path, mcs_config_template))
# 
#     wait_on_deterministic_values = False
#     if hasattr(control_flow.sync_callback, "record_deterministic_values"):
#       wait_on_deterministic_values = control_flow.sync_callback.record_deterministic_values
# 
#     delay_flow_mods = False
#     if hasattr(control_flow, "delay_flow_mods"):
#       delay_flow_mods = control_flow.delay_flow_mods
# 
#     bug_signature = ""
#     if hasattr(control_flow, "bug_signature"):
#       bug_signature = control_flow.bug_signature
# 
#     for path, template in path_templates:
#       with open(path, 'w') as cfg_out:
#         config_string = template % (str(simulation_cfg),
#                                     self.output_path,
#                                     str(wait_on_deterministic_values),
#                                     str(delay_flow_mods),
#                                     "'%s'" % str(control_flow.invariant_check_name),
#                                     '"%s"' % str(bug_signature))
#         cfg_out.write(config_string)


import argparse
import os
import sys
import sts.replay_event as replay_events
from sts.dataplane_traces.trace import Trace
from sts.input_traces.input_logger import InputLogger
from sts.input_traces.log_parser import parse
#!/usr/bin/env python


sys.path.append(os.path.join(os.path.dirname(__file__), ".."))

def main(args):
  if args.dp_trace_path is None:
    args.dp_trace_path = os.path.dirname(args.input) + "/dataplane.trace"

  dp_trace = Trace(args.dp_trace_path).dataplane_trace

  event_logger = InputLogger()
  event_logger.open(results_dir="/tmp/events.trace")

  with open(args.input) as input_file:
    trace = parse(input_file)
    for event in trace:

# Path: sts/input_traces/input_logger.py
# class InputLogger(object):
#   '''Log input events injected by a control_flow.Fuzzer'''
# 
#   def __init__(self):
#     self.last_time = SyncTime.now()
#     self._disallow_timeouts = False
#     self._events_after_close = []
#     self.output = None
#     self.output_path = ""
# 
#   def open(self, results_dir=None, output_filename="events.trace"):
#     if results_dir is not None:
#       self.output_path = results_dir + "/" + output_filename
#       self.replay_cfg_path = results_dir + "/replay_config.py"
#       self.mcs_cfg_path = results_dir + "/mcs_config.py"
#       self.interactive_replay_cfg_path = results_dir + "/interactive_replay_config.py"
#       self.openflow_replay_cfg_path = results_dir + "/openflow_replay_config.py"
#     else:
#       raise ValueError("Default results_dir currently not supported")
#     self.output = open(self.output_path, 'w')
# 
#   def disallow_timeouts(self):
#     self._disallow_timeouts = True
# 
#   def allow_timeouts(self):
#     self._disallow_timeouts = False
# 
#   def _serialize_event(self, event, output):
#     if self._disallow_timeouts and hasattr(event, "disallow_timeouts"):
#       event.timeout_disallowed = True
#     self.last_time = event.time
#     json_hash = event.to_json()
#     log.debug("logging event %r" % event)
#     output.write(json_hash + '\n')
# 
#   def log_input_event(self, event):
#     '''
#     Log the event as a json hash.
#     '''
#     if not self.output:
#       raise Exception("Not opened -- call InputLogger.open")
#     if not self.output.closed:
#       self._serialize_event(event, self.output)
#     else:
#       self._events_after_close.append(event)
# 
#   def dump_buffered_events(self, events):
#     ''' If there were un-acknowledge message receives or state changes at the
#     end of the run, dump them to a separate input trace ".unacked" '''
#     with open(self.output_path + ".unacked", 'w') as output:
#       for event in events + self._events_after_close:
#         self._serialize_event(event, output)
# 
#   def close(self, control_flow, simulation_cfg, skip_mcs_cfg=False):
#     # First, insert a WaitTime, in case there was a controller crash
#     self.log_input_event(WaitTime(1.0, time=self.last_time))
#     # Flush the json input log
#     self.output.close()
# 
#     # Write the config files
#     path_templates = [(self.replay_cfg_path, replay_config_template),
#                       (self.interactive_replay_cfg_path, interactive_replay_config_template),
#                       (self.openflow_replay_cfg_path, openflow_replay_config_template)]
#     if not skip_mcs_cfg:
#       path_templates.append((self.mcs_cfg_path, mcs_config_template))
# 
#     wait_on_deterministic_values = False
#     if hasattr(control_flow.sync_callback, "record_deterministic_values"):
#       wait_on_deterministic_values = control_flow.sync_callback.record_deterministic_values
# 
#     delay_flow_mods = False
#     if hasattr(control_flow, "delay_flow_mods"):
#       delay_flow_mods = control_flow.delay_flow_mods
# 
#     bug_signature = ""
#     if hasattr(control_flow, "bug_signature"):
#       bug_signature = control_flow.bug_signature
# 
#     for path, template in path_templates:
#       with open(path, 'w') as cfg_out:
#         config_string = template % (str(simulation_cfg),
#                                     self.output_path,
#                                     str(wait_on_deterministic_values),
#                                     str(delay_flow_mods),
#                                     "'%s'" % str(control_flow.invariant_check_name),
#                                     '"%s"' % str(bug_signature))
#         cfg_out.write(config_string)


# Path: tools/insert_dp_events_into_traceX.py
import argparse
import os
import sys
import sts.replay_event as replay_events
from sts.dataplane_traces.trace import Trace
from sts.input_traces.input_logger import InputLogger
from sts.input_traces.log_parser import parse

#!/usr/bin/env python


sys.path.append(os.path.join(os.path.dirname(__file__), ".."))

def main(args):
  if args.dp_trace_path is None:
    args.dp_trace_path = os.path.dirname(args.input) + "/dataplane.trace"

  dp_trace = Trace(args.dp_trace_path).dataplane_trace

  event_logger = InputLogger()
  event_logger.open(results_dir="/tmp/events.trace")

  with open(args.input) as input_file:
    trace = parse(input_file)
    for event in trace:

      if type(event) == replay_events.TrafficInjection: