예제 #1
0
파일: stopandwait.py 프로젝트: jvisker/bene
 def receive_packet(self, packet):
     # handle ACK
     if self.packet_is_outstanding and packet.ack_number == self.sequence:
         # this acks new data, so advance the send buffer, reset
         # the outstanding flag, cancel the timer, and send if possible
         Sim.trace(
             "%d received StopAndWait ACK from %d for %d"
             % (packet.destination_address, packet.source_address, packet.ack_number)
         )
         self.send_buffer = self.send_buffer[self.sequence - self.last_sent :]
         self.packet_is_outstanding = False
         self.cancel_timer()
         self.send_if_possible()
     # handle data
     if packet.length > 0:
         Sim.trace(
             "%d received StopAndWait segment from %d for %d"
             % (packet.destination_address, packet.source_address, packet.sequence)
         )
         # if the packet is the one we're expecting increment our
         # ack number and add the data to the receive buffer
         if packet.sequence == self.ack:
             self.increment_ack(packet.sequence + packet.length)
             self.receive_buffer += packet.body
             # deliver data that is in order
             self.app.receive_packet(packet)
         # always send an ACK
         self.send_ack()
예제 #2
0
파일: node.py 프로젝트: Steve525/bene
 def forward_packet(self,packet):
     if packet.destination_address not in self.forwarding_table:
         Sim.trace("%d no routing entry for %d" % (self.links[0].address,packet.destination_address))
         return
     link = self.forwarding_table[packet.destination_address]
     Sim.trace("%d forwarding packet to %d" % (link.address,packet.destination_address))
     link.handle_packet(packet)
예제 #3
0
파일: tcp.py 프로젝트: kbpontius/lab4-CS460
    def trace(self,message):
        ''' Print debugging messages. '''
        if self.destination_port != self.plot_port_number:
            return

        if not self.plot_sequence_on and not self.plot_rate_on and not self.plot_queue_on and not self.plot_window_on:
            Sim.trace("TCP",message)
예제 #4
0
 def retransmit(self,event):
     if not self.send_buffer:
         return
     if not self.packet_is_outstanding:
         return
     Sim.trace("%d retransmission timer fired" % (self.source_address))
     packet = self.send_one_packet(self.last_sent)
예제 #5
0
 def forward_unicast_packet(self,packet):
     if packet.destination_address not in self.forwarding_table:
         Sim.trace("%s no routing entry for %d" % (self.hostname,packet.destination_address))
         return
     link = self.forwarding_table[packet.destination_address]
     Sim.trace("%s forwarding packet to %d" % (self.hostname,packet.destination_address))
     link.send_packet(packet)
예제 #6
0
파일: tcp.py 프로젝트: kbpontius/lab4-CS460
    def plot_sequence(self, sequence_number, isACK = False, dropped=False):
        if self.destination_port != self.plot_port_number:
            return

        message = "%i %i %d" % (sequence_number, dropped, isACK)

        if self.plot_sequence_on:
            Sim.trace("TCP", message)
예제 #7
0
파일: tcp.py 프로젝트: kbpontius/lab4-CS460
    def plot_window(self, size):
        if self.destination_port != self.plot_port_number:
            return

        message = "%i" % size

        if self.plot_window_on:
            Sim.trace("TCP", message)
예제 #8
0
 def send_ack(self):
     packet = TCPPacket(source_address=self.source_address,
                        source_port=self.source_port,
                        destination_address=self.destination_address,
                        destination_port=self.destination_port,
                        sequence=self.sequence,ack_number=self.ack)
     # send the packet
     Sim.trace("%d sending StopAndWait ACK to %d for %d" % (self.source_address,self.destination_address,packet.ack_number))
     self.transport.send_packet(packet)
예제 #9
0
파일: node.py 프로젝트: Steve525/bene
    def handle_packet(self,packet):
        # if this is the first time we have seen this packet, set its
        # creation timestamp
        if packet.created == None:
            packet.created = Sim.scheduler.current_time()
        # check if the packet is for me
        for link in self.links:
            if link.address == packet.destination_address:
                Sim.trace("%d received packet" % (packet.destination_address))
                self.receive_packet(packet)
                return

        # forward the packet
        self.forward_packet(packet)
예제 #10
0
    def send_one_packet(self,sequence):
        # get one packet worth of data
        body = self.send_buffer[0:self.mss]
        packet = TCPPacket(source_address=self.source_address,
                           source_port=self.source_port,
                           destination_address=self.destination_address,
                           destination_port=self.destination_port,
                           body=body,
                           sequence=sequence,ack_number=self.ack)

        # send the packet
        Sim.trace("%d sending StopAndWait segment to %d for %d" % (self.source_address,self.destination_address,packet.sequence))
        self.transport.send_packet(packet)

        # set a timer
        self.timer = Sim.scheduler.add(delay=self.timeout, event='retransmit', handler=self.retransmit)
        return packet
예제 #11
0
파일: link.py 프로젝트: Steve525/bene
 def handle_packet(self,packet):
     # drop packet due to queue overflow
     if self.queue_size and len(self.queue) == self.queue_size:
         Sim.trace("! %d dropped packet due to queue overflow" % (self.address))
         Sim.trace_custom('x', 'queue', self.filename)
         return
     # drop packet due to random loss
     if self.loss > 0 and random.random() < self.loss:
         Sim.trace("! %d dropped packet due to random loss" % (self.address))
         return
     packet.enter_queue = Sim.scheduler.current_time()
     #Sim.trace("packet %d entered queue" % packet.sequence)
     if len(self.queue) == 0 and not self.busy:
         # packet can be sent immediately
         self.busy = True
         self.transmit(packet)
     else:
         # add packet to queue
         Sim.trace_custom('%d' % (len(self.queue)), 'queue', self.filename)
         self.queue.append(packet)
예제 #12
0
 def send_packet(self,packet):
     # check if link is running
     if not self.running:
         return
     # drop packet due to queue overflow
     if self.queue_size and len(self.queue) == self.queue_size:
         Sim.trace("%d dropped packet due to queue overflow" % (self.address))
         return
     # drop packet due to random loss
     if self.loss > 0 and random.random() < self.loss:
         Sim.trace("%d dropped packet due to random loss" % (self.address))
         return
     packet.enter_queue = Sim.scheduler.current_time()
     if len(self.queue) == 0 and not self.busy:
         # packet can be sent immediately
         self.busy = True
         self.transmit(packet)
     else:
         # add packet to queue
         self.queue.append(packet)
예제 #13
0
파일: link.py 프로젝트: mkeagar/cs460
 def handle_packet(self,packet):
     # drop packet due to queue overflow
     if self.queue_size and len(self.queue) == self.queue_size:
         Sim.trace("%d dropped packet due to queue overflow" % (self.address))
         if self.printOut:
             self.myfile.write(str(Sim.scheduler.current_time()) + " x\n")
             Sim.print_packet_loss(packet)
         return
     # drop packet due to random loss
     if self.loss > 0 and random.random() < self.loss:
         Sim.trace("%d dropped packet due to random loss" % (self.address))
         if self.printOut:
             self.myfile.write(str(Sim.scheduler.current_time()) + " x\n")
         return
     packet.enter_queue = Sim.scheduler.current_time()
     if len(self.queue) == 0 and not self.busy:
         # packet can be sent immediately
         self.busy = True
         self.transmit(packet)
     else:
         # add packet to queue
         self.queue.append(packet)
예제 #14
0
    def receive_packet(self,packet):
        # handle broadcast packets
        if packet.destination_address == 0:
            Sim.trace("%s received packet" % (self.hostname))
            self.deliver_packet(packet)
        else:
            # check if unicast packet is for me
            for link in self.links:
                if link.address == packet.destination_address:
                    Sim.trace("%s received packet" % (self.hostname))
                    self.deliver_packet(packet)
                    return

        # decrement the TTL and drop if it has reached the last hop
        packet.ttl = packet.ttl - 1
        if packet.ttl <= 0:
            Sim.trace("%s dropping packet due to TTL expired" % (self.hostname))
            return

        # forward the packet
        self.forward_packet(packet)
예제 #15
0
 def trace_queue(self, message):
     Sim.trace("Queue", message)
예제 #16
0
 def receive_data(self, data):
     Sim.trace('AppHandler', "application got %d bytes" % (len(data)))
     self.f.write(data)
     self.f.flush()
예제 #17
0
 def trace(self, message):
     Sim.trace("DVR", message)
예제 #18
0
 def trace(self,message):
     Sim.trace("Node",message)
예제 #19
0
파일: link.py 프로젝트: nathand8/bene
 def trace(self,message):
     Sim.trace("Link",message)
예제 #20
0
 def trace(self, message):
     Sim.trace("Link", message)
예제 #21
0
 def forward_broadcast_packet(self,packet):
     for link in self.links:
         Sim.trace("%s forwarding broadcast packet to %s" % (self.hostname,link.endpoint.hostname))
         packet_copy = copy.deepcopy(packet)
         link.send_packet(packet_copy)
예제 #22
0
 def trace(self,message):
     ''' Print debugging messages. '''
     Sim.trace("TCP",message)
예제 #23
0
 def receive_data(self,data):
     Sim.trace('AppHandler',"application got %d bytes" % (len(data)))
     self.f.write(data)
     self.f.flush()