Exemplo n.º 1
0
 def send_ack(self, reply_id, inst_id, ret_val, special_reg_ack=None):
     msg = ReplyPayload()
     msg.return_value = ret_val
     if special_reg_ack:
         msg.output = special_reg_ack
     else:
         msg.output = acknowledgment
     buff_msg = buffered_msg(reply_type, None, reply_id, [msg], inst_id)
     add_to_thread_buffer(self.buffer_mngr.outgoing_ncAckBfr[inst_id], buff_msg, 'GN_msgs_buffer_mngr')
 def handle_request(self):
     if self.shutdown == 0:
         msg = ''
         try:
             # recreates msg by concatenatning list's elements
             for single_msg in self.input_buffer:
                 msg = msg + single_msg                                              
             msg = buffered_msg(None, None, None, msg, self)
             # Sends msg to the buffer_mngr's buffer
             add_to_thread_buffer(self.buffer_mngr.incoming_moduleMsgBfr,\
             msg, "GN_msgs_buffer_mngr")                                             
             logger.debug("Msg sent to buffer_mngr."+"\n\n")
         except Exception as inst:
             logger.critical("Exception in handle_request: " + str(inst))
     else:
         logger.critical("Socket Closed."+"\n\n")
Exemplo n.º 3
0
 def send_reg_msg_to_cloud(self, inst_id):
     try:
         reg_payload = RegistrationPayload()
         config = ConfigObj(config_file_name)
         l=lambda:defaultdict(l)
         reg_dict = l()
         if config["Registered"] == 'NO':
             reg_dict["Systems Info"] = config["Systems Info"]
         for node in config["GN Info"]:
             if config["GN Info"][node]["Registered"] == 'NO':
                 # append this GN's info to the registration dict
                 reg_dict["GN Info"][node]["Systems Info"] = config["GN Info"][node]["Systems Info"]
                 reg_dict["GN Info"][node]["Sensors Info"] = config["GN Info"][node]["Sensors Info"]
         reg_payload.sys_info = reg_dict
         reg_payload.instance_id = get_instance_id()
         buff_msg = buffered_msg(registration_type, None, no_reply, [reg_payload], inst_id)
         # Sends registration msg by sending to buffer_mngr
         add_to_thread_buffer(self.buffer_mngr.outgoing_ncMsgBfr[inst_id], buff_msg, 'buffer_mngr')
         logger.debug("Registration msg sent to bufr mngr to send to cloud.")
     except Exception as inst:
         logger.critical("Exception in send_reg_msg_to_cloud:" + str(inst))
Exemplo n.º 4
0
 def process_incoming_moduleMsg(self):
     try:
         if not self.incoming_moduleMsgBfr.empty():
             item = self.incoming_moduleMsgBfr.get()
             logger.debug("Msg from GN:"  +  str(item.msg) )
             try:
                 decoded_msg = Message.decode(item.msg)
             except Exception as inst:
                 logger.critical("Exception while decoding msg: " + str(inst) )
                 logger.critical("So discarding msg............." + str(inst) )
                 self.incoming_moduleMsgBfr.task_done()
                 return 
             inst_id = decoded_msg.header.instance_id
             # check for the authenticity of the sender
             if (not self.new_node(decoded_msg.header.instance_id)) | \
             (decoded_msg.header.message_type == registration_type):
                 self.map_socket(inst_id, item.sock_or_gn_id)
                 # check whether the msg is new or duplicate
                 if self.new_msg(decoded_msg):
                     # data/registration msg obtained so send it to msg_processor
                     if decoded_msg.header.message_type == data_type or decoded_msg.header.message_type == registration_type:
                         session_id = self.convert_to_int(decoded_msg.header.sequence_id[:self.seq_no_partition_size])
                         subseq_no = self.convert_to_int(decoded_msg.header.sequence_id[self.seq_no_partition_size:])
                         # prepare the msg in proper format to insert into msg_processor's incoming_moduleMsgBfr
                         item = buffered_msg(decoded_msg.header.message_type, decoded_msg.header.sequence_id, \
                         decoded_msg.header.reply_to_id, decoded_msg.payloads, decoded_msg.header.instance_id)
                         # save the highest_gn_subseq_no temporarily until the msg is processed 
                         # and the ACK (received from the msg_processor thread) is saved in outgoing_moduleAckBfr 
                         self.unprocessed_gnSeqNos[inst_id].append((session_id, subseq_no))
                         # send to msg_processor's incoming_moduleMsgBfr
                         add_to_thread_buffer(self.msg_processor.incoming_moduleMsgBfr, item, 'Msg_Processor')
                         #print "sent to msg processor"+str('%0.4f' % time.time())
                 else:
                     logger.critical("OLD MSG DISCARDED.............\n\n")
             else:
                 logger.critical("UNKNOWN GN SO MSG DISCARDED.............")
             self.incoming_moduleMsgBfr.task_done()
         
     except Exception as inst:
         logger.critical("Exception in process_incoming_moduleMsg: " + str(inst))
Exemplo n.º 5
0
 def send_data_msg(self, inst_id, data_payloads):
     buff_msg = buffered_msg(data_type, None, no_reply, data_payloads, inst_id)
     add_to_thread_buffer(self.buffer_mngr.outgoing_ncMsgBfr[inst_id], buff_msg, 'buffer_mngr')
     logger.debug("Data msg sent to bufr mngr to send to cloud/GN.")