def test_reqid(self): reqid = REQID.generate() packed_reqid = REQID.pack(reqid) unpacked_reqid = REQID.unpack(packed_reqid) self.assertEqual(reqid, unpacked_reqid) self.assertFalse(reqid.is_zero()) zero_reqid = REQID.generate_zero() packed_zero = REQID.pack(zero_reqid) # the length of REQID is 32 bytes self.assertEqual(packed_zero, bytearray(0 for i in range(32))) self.assertTrue(zero_reqid.is_zero())
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
def get_mock_requst_packets(is_message): """Returns a list of valid IncomingPackets with non-zero REQID and the corresponding raw data""" pkt_list = [] raw_list = [] message_list = [mock_protobuf.get_mock_register_response(), mock_protobuf.get_mock_config(), mock_protobuf.get_mock_bolt(), mock_protobuf.get_mock_topology()] # normal packet (PhysicalPlan as request) for message in message_list: if is_message: reqid = REQID.generate_zero() else: reqid = REQID.generate() normal_pkt = convert_to_incoming_packet(reqid, message) pkt_list.append(normal_pkt) raw_list.append((reqid, message)) return pkt_list, raw_list
def get_a_mock_message_list_and_builder(): """Get a list of IncomingPackets, the corresponding mock messages, builder and typename""" pkt_list = [] raw_list = mock_protobuf.get_many_mock_pplans() for msg in raw_list: reqid = REQID.generate_zero() pkt = convert_to_incoming_packet(reqid, msg) pkt_list.append(pkt) builder, typename = mock_protobuf.get_pplan_builder_and_typename() return pkt_list, raw_list, builder, typename
def get_mock_requst_packets(is_message): """Returns a list of valid IncomingPackets with non-zero REQID and the corresponding raw data""" pkt_list = [] raw_list = [] message_list = [ mock_protobuf.get_mock_register_response(), mock_protobuf.get_mock_config(), mock_protobuf.get_mock_bolt(), mock_protobuf.get_mock_topology() ] # normal packet (PhysicalPlan as request) for message in message_list: if is_message: reqid = REQID.generate_zero() else: reqid = REQID.generate() normal_pkt = convert_to_incoming_packet(reqid, message) pkt_list.append(normal_pkt) raw_list.append((reqid, message)) return pkt_list, raw_list
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)
def get_a_mock_request_packet_and_raw(): """Returns a tuple of mock (IncomingPacket, REQID, RegisterResponse message)""" reqid = REQID.generate() message = mock_protobuf.get_mock_register_response() pkt = convert_to_incoming_packet(reqid, message) return pkt, reqid, message
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)