Esempio n. 1
0
    def load_command_file(self, file):
        try:
            f = open(file)
            for line in f.readlines():
                line = line.strip()
                if line == "" or line[0] == '#':
                    continue

                items = line.split(' ')
                time_stamp = int(items[0])
                event_type = items[1]

                num_args = len(items) - 2
                if event_type == EVENT_TYPE.PRINT:
                    Event_Queue.Post(
                        Event(time_stamp, event_type, self,
                              "".join(items[2:])))
                elif num_args < 0 or num_args > 3:
                    sys.stderr.write(line)
                    raise BufferError
                elif num_args == 0:
                    Event_Queue.Post(Event(time_stamp, event_type, self))
                elif num_args == 1:
                    Event_Queue.Post(
                        Event(time_stamp, event_type, self, int(items[2])))
                elif num_args == 2:
                    Event_Queue.Post(
                        Event(time_stamp, event_type, self, int(items[2]),
                              int(items[3])))
                elif num_args == 3:
                    Event_Queue.Post(
                        Event(time_stamp, event_type, self, int(items[2]),
                              int(items[3]), int(items[4])))
            f.close()

        except IOError as e:
            print("Can not open file " + file)
            print(e)
            sys.exit(-1)

        except BufferError:
            print("File with wrong format " + file)
            sys.exit(-1)

        except Exception as e:
            print("File with wrong format " + file)
            print(e)
            traceback.print_exc()
            sys.exit(-1)
Esempio n. 2
0
 def post_send_link(self, node, neighbor, latency):
     Event_Queue.Post(
         Event(
             Get_Time(),
             EVENT_TYPE.SEND_LINK,
             self,
             node,
             neighbor,
             latency
         )
     )
Esempio n. 3
0
 def send_to_neighbor(self, node, neighbor, m):
     if (node, neighbor) not in self.__g.edges:
         return
     Event_Queue.Post(
         Event(
             Get_Time() + int(self.__g[node][neighbor]['latency']),
             EVENT_TYPE.ROUTING_MESSAGE_ARRIVAL,
             self,
             neighbor,
             m
         )
     )