def test_create_route_error_header_from_message_str(self): route_error_header_obj = header.create_header_obj_from_raw_message('LR,0131,10,|0131|5|4|0132|') self.assertEqual(route_error_header_obj.source, '0131') self.assertEqual(route_error_header_obj.ttl, 4) self.assertEqual(route_error_header_obj.broken_node, '0132') self.assertEqual(route_error_header_obj.flag, header.RouteErrorHeader.HEADER_TYPE)
def test_create_route_request_header_obj_good(self): header_obj = header.create_header_obj_from_raw_message('LR,0136,10,|0137|3|8|4|0138|') self.assertEqual(header_obj.source, '0137') self.assertEqual(header_obj.flag, 3) self.assertEqual(header_obj.ttl, 8) self.assertEqual(header_obj.end_node, '0138') self.assertEqual(header_obj.hops, 4)
def process_incoming_message(self): while self.PROCESS_INCOMING_MESSAGES: if not consumer_producer.response_q.empty( ) and not self.PAUSE_PROCESSING_INCOMING_MESSAGES: raw_message = consumer_producer.response_q.get() try: header_obj = header.create_header_obj_from_raw_message( raw_message) if header_obj.ttl > 1: self.routing_table.add_neighbor_to_routing_table( header_obj) if header_obj.flag == header.RouteRequestHeader.HEADER_TYPE: self.process_route_request(header_obj) elif header_obj.flag == header.MessageHeader.HEADER_TYPE: self.process_message_header(header_obj) elif header_obj.flag == header.RouteReplyHeader.HEADER_TYPE: self.process_route_reply_header(header_obj) elif header_obj.flag == header.RouteErrorHeader.HEADER_TYPE: self.process_route_error_header(header_obj) elif header_obj.flag == header.MessageAcknowledgeHeader.HEADER_TYPE: self.process_ack_header(header_obj) except ValueError as e: logging.warning(str(e)) try: logging.debug( 'try to add received signal to unsupported devices list...' ) addr = header.get_received_from_value(raw_message) self.routing_table.add_neighbor_with_unsupported_protocol( addr) except ValueError as e: logging.warning(str(e))
def test_create_message_header_obj_edge_comma_in_message(self): header_obj = header.create_header_obj_from_raw_message('LR,0136,10,|0135|1|3|0138|0137|hello, good morning|') self.assertEqual(header_obj.source, '0135') self.assertEqual(header_obj.destination, '0138') self.assertEqual(header_obj.flag, 1) self.assertEqual(header_obj.ttl, 3) self.assertEqual(header_obj.next_node, '0137') self.assertEqual(header_obj.payload, 'hello, good morning') self.assertEqual(header_obj.received_from, '0136')
def test_create_route_reply_header_obj_good(self): header_obj = header.create_header_obj_from_raw_message('LR,0136,10,|0137|4|8|3|0139|0140|') self.assertEqual(header_obj.source, '0137') self.assertEqual(header_obj.received_from, '0136') self.assertEqual(header_obj.end_node, '0139') self.assertEqual(header_obj.next_node, '0140') self.assertEqual(header_obj.flag, 4) self.assertEqual(header_obj.ttl, 8) self.assertEqual(header_obj.hops, 3)
def test_create_message_ack_header_good(self): header_obj = header.create_header_obj_from_raw_message('LR,0137,16,|0137|2|5|0138|8774d3|') self.assertEqual(header_obj.flag, 2)
def test_get_best_route_for_destination_good(self): with patch.object(protocol_lite.ProtocolLite, 'send_header'): raw_message = 'LR,0133,16,|0131|2|5|0133|99fc8d|' header_obj = header.create_header_obj_from_raw_message(raw_message) self.protocol.process_ack_header(header_obj) self.assertEqual('|0131|2|4|0133|99fc8d|', header_obj.get_header_str())