Example #1
0
 def dispatch_event(self, step='NORMAL'):
     e = Event_Queue.Get_Earliest()
     while e:
         e.dispatch()
         if step == 'SINGLE_STEP':
             self.logging.info(str(e))
             self.wait()
         e = Event_Queue.Get_Earliest()
Example #2
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)
Example #3
0
 def post_send_link(self, node, neighbor, latency):
     Event_Queue.Post(
         Event(
             Get_Time(),
             EVENT_TYPE.SEND_LINK,
             self,
             node,
             neighbor,
             latency
         )
     )
Example #4
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
         )
     )
Example #5
0
 def __str__(self):
     ans = "==== Print Topology ====\n"
     ans += super().__str__()
     ans += "==== Print Event ====\n"
     ans += Event_Queue.Str()
     return ans