Пример #1
0
def get_fail_packet():
    """Returns an incomplete IncomingPacket object"""
    raw = OutgoingPacket.create_packet(REQID.generate(),
                                       mock_protobuf.get_mock_pplan()).raw
    packet = IncomingPacket.create_packet(raw[:4], raw[4:])
    packet.is_complete = False
    return packet
Пример #2
0
def convert_to_incoming_packet(reqid, message):
  """Convert (reqid, message) pair to IncomingPacket object"""
  raw = OutgoingPacket.create_packet(reqid, message).raw
  dispatcher = MockDispatcher()
  dispatcher.prepare_with_raw(raw)
  packet = IncomingPacket()
  packet.read(dispatcher)

  packet.data = packet.data
  return packet
Пример #3
0
def convert_to_incoming_packet(reqid, message):
    """Convert (reqid, message) pair to IncomingPacket object"""
    raw = OutgoingPacket.create_packet(reqid, message).raw
    dispatcher = MockDispatcher()
    dispatcher.prepare_with_raw(raw)
    packet = IncomingPacket()
    packet.read(dispatcher)

    packet.data = packet.data
    return packet
Пример #4
0
  def send_request(self, request, context, response_type, timeout_sec):
    """Sends a request message (REQID is non-zero)"""
    # generates a unique request id
    reqid = REQID.generate()
    Log.debug("%s: In send_request() with REQID: %s" % (self._get_classname(), str(reqid)))
    # register response message type
    self.response_message_map[reqid] = response_type
    self.context_map[reqid] = context

    # Add timeout for this request if necessary
    if timeout_sec > 0:
      def timeout_task():
        self.handle_timeout(reqid)
      self.looper.register_timer_task_in_sec(timeout_task, timeout_sec)

    outgoing_pkt = OutgoingPacket.create_packet(reqid, request)
    self._send_packet(outgoing_pkt)
Пример #5
0
  def send_request(self, request, context, response_type, timeout_sec):
    """Sends a request message (REQID is non-zero)"""
    # generates a unique request id
    reqid = REQID.generate()
    Log.debug("%s: In send_request() with REQID: %s" % (self._get_classname(), str(reqid)))
    # register response message type
    self.response_message_map[reqid] = response_type
    self.context_map[reqid] = context

    # Add timeout for this request if necessary
    if timeout_sec > 0:
      def timeout_task():
        self.handle_timeout(reqid)
      self.looper.register_timer_task_in_sec(timeout_task, timeout_sec)

    outgoing_pkt = OutgoingPacket.create_packet(reqid, request)
    self._send_packet(outgoing_pkt)
Пример #6
0
 def send_message(self, message):
   """Sends a message (REQID is zero)"""
   Log.debug("In send_message() of %s" % self._get_classname())
   outgoing_pkt = OutgoingPacket.create_packet(REQID.generate_zero(), message)
   self._send_packet(outgoing_pkt)
Пример #7
0
def get_fail_packet():
  """Returns an incomplete IncomingPacket object"""
  raw = OutgoingPacket.create_packet(REQID.generate(), mock_protobuf.get_mock_pplan()).raw
  packet = IncomingPacket.create_packet(raw[:4], raw[4:])
  packet.is_complete = False
  return packet
Пример #8
0
 def send_message(self, message):
     """Sends a message (REQID is zero)"""
     Log.debug("In send_message() of %s" % self._get_classname())
     outgoing_pkt = OutgoingPacket.create_packet(REQID.generate_zero(),
                                                 message)
     self._send_packet(outgoing_pkt)