# Path: sts/replay_event.py
# class WaitTime(InputEvent):
#   ''' Causes the simulation to sleep for the specified number of seconds.
#   Controller processes continue running during this time.'''
#   def __init__(self, wait_time, label=None, round=-1, time=None):
#     '''
#     Parameters:
#      - wait_time: float representing how long to sleep in seconds.
#      - label: a unique label for this event. Internal event labels begin with 'i'
#        and input event labels begin with 'e'.
#      - time: the timestamp of when this event occured. Stored as a tuple:
#        [seconds since unix epoch, microseconds].
#      - round: optional integer. Indicates what simulation round this event occured
#        in.
#     '''
#     super(WaitTime, self).__init__(label=label, round=round, time=time)
#     self.wait_time = wait_time
# 
#   def proceed(self, simulation):
#     log.info("WaitTime: pausing simulation for %f seconds" % (self.wait_time))
#     time.sleep(self.wait_time)
#     return True
# 
#   @staticmethod
#   def from_json(json_hash):
#     (label, time, round) = extract_label_time(json_hash)
#     assert_fields_exist(json_hash, 'wait_time')
#     wait_time = json_hash['wait_time']
#     return WaitTime(wait_time, round=round, label=label, time=time)
# 
# Path: sts/util/convenience.py
# def timestamp_string():
#   return time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime())


import os
import time
import logging
import sts.dataplane_traces.trace_generator as tg
from sts.replay_event import WaitTime
from sts.syncproto.base import SyncTime
from sts.util.convenience import timestamp_string
      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"):

# Path: sts/replay_event.py
# class WaitTime(InputEvent):
#   ''' Causes the simulation to sleep for the specified number of seconds.
#   Controller processes continue running during this time.'''
#   def __init__(self, wait_time, label=None, round=-1, time=None):
#     '''
#     Parameters:
#      - wait_time: float representing how long to sleep in seconds.
#      - label: a unique label for this event. Internal event labels begin with 'i'
#        and input event labels begin with 'e'.
#      - time: the timestamp of when this event occured. Stored as a tuple:
#        [seconds since unix epoch, microseconds].
#      - round: optional integer. Indicates what simulation round this event occured
#        in.
#     '''
#     super(WaitTime, self).__init__(label=label, round=round, time=time)
#     self.wait_time = wait_time
# 
#   def proceed(self, simulation):
#     log.info("WaitTime: pausing simulation for %f seconds" % (self.wait_time))
#     time.sleep(self.wait_time)
#     return True
# 
#   @staticmethod
#   def from_json(json_hash):
#     (label, time, round) = extract_label_time(json_hash)
#     assert_fields_exist(json_hash, 'wait_time')
#     wait_time = json_hash['wait_time']
#     return WaitTime(wait_time, round=round, label=label, time=time)
# 
# Path: sts/util/convenience.py
# def timestamp_string():
#   return time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime())


# Path: sts/input_traces/input_logger.py
import os
import time
import logging
import sts.dataplane_traces.trace_generator as tg
from sts.replay_event import WaitTime
from sts.syncproto.base import SyncTime
from sts.util.convenience import timestamp_string

      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