Esempio n. 1
0
File: tcp.py Progetto: Steve525/bene
    def handle_packet(self,packet):
        # handle ACK (Sender)
        # if the ACK number is greater than our send base...
        #    update the acknowledged segment counter, restart timer and send if possible
        if packet.ack_number > self.send_base:
            Sim.trace("ACK RCVD: %d <=== %d : %d" % (packet.destination_address,packet.source_address,packet.ack_number))
            bytes_acked = packet.ack_number - self.send_base
            self.not_yet_acknowledged_segments -= bytes_acked
            
            if self.cwnd >= self.ssthreshold:
                self.cwnd += (self.mss * bytes_acked) / self.cwnd
            else:                
                self.cwnd += bytes_acked

            self.cancel_timer()
            self.timer = Sim.scheduler.add(delay=self.timeout, event='new_ack_data', handler=self.retransmit)
            self.send_if_possible()
            self.send_base = packet.ack_number
            # print congestion window
            
            if self.source_port > 3:
                Sim.trace_custom("%f" % (self.cwnd/self.mss), 'cwnd', self.source_port)
            
        # handle data (Receiver)
        if packet.length > 0:
            Sim.trace("SEGMENT RCVD: %d <=== %d : %d" % (packet.destination_address,packet.source_address,packet.sequence))
            self.receive_temp_buffer.add(packet.sequence)
            self.receive_packet_buffer.append(packet)
            self.send_cumulative_ack()
Esempio n. 2
0
File: tcp.py Progetto: Steve525/bene
 def send_cumulative_ack(self):
     sequences = sorted(self.receive_temp_buffer)
     for i in range(self.ack/self.mss, len(sequences)):
         if sequences[i] == self.ack:
             pkt = self.find_packet(self.ack)
             self.increment_ack(pkt.sequence + pkt.length)
             self.app.handle_packet(pkt)
             Sim.trace_custom("%d %d" % (pkt.sequence, pkt.length), 'rate', self.source_port)
     
     self.send_ack()
Esempio n. 3
0
File: tcp.py Progetto: Steve525/bene
 def loss_detected(self):
     Sim.trace_custom("%f" % (self.cwnd/self.mss), 'cwnd', self.source_port)
     self.ssthreshold = max(self.cwnd/2, self.mss)
     self.cwnd = 1 * self.mss
     Sim.trace_custom("%f" % (self.cwnd/self.mss), 'cwnd', self.source_port)