def A_input(self, pkt): # process the ACK, NACK from B if pkt.checksum == pkt.get_checksum() and pkt.acknum == self.seq: self.state = "WAIT_LAYER5" self.seq = 0 if self.seq else 1 evl.remove_timer() else: to_layer_three("A", self.lastPkt)
def A_handle_timer(self): # go back n, A_handle_timer # Read all the sent packet that it is not acknowledged # using "read_all()" of the circular buffer and resend them # If you need to resend packets, set a timer after that for ptk in self.window.read_all() : if ptk.seqnum >= self.base : to_layer_three("A", ptk) evl.start_timer("A", self.estimated_rtt)
def A_output(self, m): # go back n, A_output # If the buffer is full, just drop the packet # Construct the packet based on the message. # Make sure that the sequence number is correct # Send the packet and save it to the circular buffer using "push()" of circular_buffer # Set the timer using "evl.start_timer(entity, time)", and the time should be set to estimated_rtt. # iMake sure that there is only one timer started in the event list # if not self.window.isfull() : if self.nextSeq < self.base + self.windowSize : pkt = packet(seqnum=self.nextSeq, payload=m) # print(str(pkt.payload.data)) self.window.push(pkt) to_layer_three("A", pkt) # if self.base == self.nextSeq : evl.start_timer("A", self.estimated_rtt) self.nextSeq += 1
def send_ack(AorB, ack): pkt = packet(acknum=ack) pkt.checksum = pkt.get_checksum() to_layer_three(AorB, pkt)
def A_output(self, m): # TODO: called from layer 5, pass the data to the other side pkt = packet(seqnum=self.seq, payload=m) to_layer_three("A", pkt)
def A_handle_timer(self): # resend the packet as needed to_layer_three("A", self.lastPkt) evl.start_timer("A", self.estimated_rtt)
def A_output(self, m): pkt = packet(seqnum=self.seq, payload=m) to_layer_three("A", pkt) evl.start_timer("A", self.estimated_rtt) self.state = "WAIT_ACK" self.lastPkt = pkt