# 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
      forwarder.allow_message_send(message)
    return message

  # TODO(cs): make this a factory method that returns DeferredOFConnection objects
  # with bound openflow_buffer.insert() method. (much cleaner API + separation of concerns)
  def insert_pending_receipt(self, dpid, controller_id, ofp_message, conn):
    ''' Called by DeferredOFConnection to insert messages into our buffer '''
    fingerprint = OFFingerprint.from_pkt(ofp_message)
    if self.pass_through_whitelisted_packets and self.in_whitelist(fingerprint):
      conn.allow_message_receipt(ofp_message)
      return
    conn_message = (conn, ofp_message)
    message_id = PendingReceive(dpid, controller_id, fingerprint)
    self.pending_receives.insert(message_id, conn_message)
    b64_packet = base64_encode(ofp_message)
    self.raiseEventNoErrors(PendingMessage(message_id, b64_packet))
    return message_id

  # TODO(cs): make this a factory method that returns DeferredOFConnection objects
  # with bound openflow_buffer.insert() method. (much cleaner API + separation of concerns)
  def insert_pending_send(self, dpid, controller_id, ofp_message, conn):
    ''' Called by DeferredOFConnection to insert messages into our buffer '''
    fingerprint = OFFingerprint.from_pkt(ofp_message)
    if (self.pass_through_sends or
        (self.pass_through_whitelisted_packets and self.in_whitelist(fingerprint))):
      conn.allow_message_send(ofp_message)
      return
    conn_message = (conn, ofp_message)
    message_id = PendingSend(dpid, controller_id, fingerprint)
    self.pending_sends.insert(message_id, conn_message)

# 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

      forwarder.allow_message_send(message)
    return message

  # TODO(cs): make this a factory method that returns DeferredOFConnection objects
  # with bound openflow_buffer.insert() method. (much cleaner API + separation of concerns)
  def insert_pending_receipt(self, dpid, controller_id, ofp_message, conn):
    ''' Called by DeferredOFConnection to insert messages into our buffer '''
    fingerprint = OFFingerprint.from_pkt(ofp_message)
    if self.pass_through_whitelisted_packets and self.in_whitelist(fingerprint):
      conn.allow_message_receipt(ofp_message)
      return
    conn_message = (conn, ofp_message)
    message_id = PendingReceive(dpid, controller_id, fingerprint)
    self.pending_receives.insert(message_id, conn_message)
    b64_packet = base64_encode(ofp_message)
    self.raiseEventNoErrors(PendingMessage(message_id, b64_packet))
    return message_id

  # TODO(cs): make this a factory method that returns DeferredOFConnection objects
  # with bound openflow_buffer.insert() method. (much cleaner API + separation of concerns)
  def insert_pending_send(self, dpid, controller_id, ofp_message, conn):
    ''' Called by DeferredOFConnection to insert messages into our buffer '''
    fingerprint = OFFingerprint.from_pkt(ofp_message)
    if (self.pass_through_sends or
        (self.pass_through_whitelisted_packets and self.in_whitelist(fingerprint))):
      conn.allow_message_send(ofp_message)
      return
    conn_message = (conn, ofp_message)
    message_id = PendingSend(dpid, controller_id, fingerprint)
    self.pending_sends.insert(message_id, conn_message)

    b64_packet = base64_encode(ofp_message)