# Path: sts/util/convenience.py
# def base64_encode(packet):
#   if hasattr(packet, "pack"):
#     packet = packet.pack()
#   # base 64 occasionally adds extraneous newlines: bit.ly/aRTmNu
#   return base64.b64encode(packet).replace("\n", "")


from collections import defaultdict, namedtuple
from sts.fingerprints.messages import *
from pox.lib.revent import Event, EventMixin
from sts.syncproto.base import SyncTime
from sts.util.convenience import base64_encode
from sts.util.ordered_default_dict import OrderedDefaultDict
import logging
    import sts.replay_event

  def _pass_through_handler(self, message_event):
    ''' handler for pass-through mode '''

    # NOTE(aw): FIRST record event, then schedule execution to maintain causality
    # TODO(cs): figure out a better way to resolve circular dependency
    message_id = message_event.pending_message
    # Record
    if message_event.send_event:
      replay_event_class = sts.replay_event.ControlMessageSend
    else:
      replay_event_class = sts.replay_event.ControlMessageReceive

    replay_event = replay_event_class(dpid=message_id.dpid,
                                      controller_id=message_id.controller_id,
                                      fingerprint=message_id.fingerprint,
                                      b64_packet=message_event.b64_packet,
                                      time=message_event.time)
    if self._delegate_input_logger is not None:
      # TODO(cs): set event.round somehow?
      self._delegate_input_logger.log_input_event(replay_event)
    else: # TODO(cs): why is this an else:?
      self.passed_through_events.append(replay_event)
    # Pass through
    self.schedule(message_id)

  def set_pass_through(self, input_logger=None):
    ''' Cause all message receipts to pass through immediately without being
    buffered'''
    self.passed_through_events = []

# Path: sts/util/convenience.py
# def base64_encode(packet):
#   if hasattr(packet, "pack"):
#     packet = packet.pack()
#   # base 64 occasionally adds extraneous newlines: bit.ly/aRTmNu
#   return base64.b64encode(packet).replace("\n", "")


# Path: sts/openflow_buffer.py
from collections import defaultdict, namedtuple
from sts.fingerprints.messages import *
from pox.lib.revent import Event, EventMixin
from sts.syncproto.base import SyncTime
from sts.util.convenience import base64_encode
from sts.util.ordered_default_dict import OrderedDefaultDict
import logging
    import sts.replay_event


  def _pass_through_handler(self, message_event):
    ''' handler for pass-through mode '''

    # NOTE(aw): FIRST record event, then schedule execution to maintain causality
    # TODO(cs): figure out a better way to resolve circular dependency
    message_id = message_event.pending_message
    # Record
    if message_event.send_event:
      replay_event_class = sts.replay_event.ControlMessageSend
    else:
      replay_event_class = sts.replay_event.ControlMessageReceive

    replay_event = replay_event_class(dpid=message_id.dpid,
                                      controller_id=message_id.controller_id,
                                      fingerprint=message_id.fingerprint,
                                      b64_packet=message_event.b64_packet,
                                      time=message_event.time)
    if self._delegate_input_logger is not None:
      # TODO(cs): set event.round somehow?
      self._delegate_input_logger.log_input_event(replay_event)
    else: # TODO(cs): why is this an else:?
      self.passed_through_events.append(replay_event)
    # Pass through
    self.schedule(message_id)

  def set_pass_through(self, input_logger=None):
    ''' Cause all message receipts to pass through immediately without being
    buffered'''
    self.passed_through_events = []

    self._delegate_input_logger = input_logger