Beispiel #1
0
 def payload_is_accepted(self, packet):
     seq_lo, seq_hi = packet.get_seq_interval()
     first_byte, last_byte = seq_lo, seq_hi - 1
     first_ok = SequenceNumber.a_leq_b_leq_c(self.rcv_nxt, first_byte,
                                             self.rcv_nxt + self.rcv_wnd)
     last_ok = SequenceNumber.a_leq_b_leq_c(self.rcv_nxt, last_byte,
                                            self.rcv_nxt + self.rcv_wnd)
     return last_byte >= first_byte and (first_ok or last_ok)
Beispiel #2
0
 def payload_is_accepted(self, packet):
     seq_lo, seq_hi = packet.get_seq_interval()
     first_byte, last_byte = seq_lo, seq_hi-1
     first_ok = SequenceNumber.a_leq_b_leq_c(self.rcv_nxt,
                                             first_byte,
                                             self.rcv_nxt+self.rcv_wnd)
     last_ok = SequenceNumber.a_leq_b_leq_c(self.rcv_nxt, last_byte,
                                            self.rcv_nxt+self.rcv_wnd)
     return last_byte >= first_byte and (first_ok or last_ok)
Beispiel #3
0
 def __init__(self):
     self.source_port = 0
     self.destination_port = 0
     self.seq_number = SequenceNumber(0)
     self.ack_number = SequenceNumber(0)
     self.window_size = 0
     self.flags = set()
     self.payload = str()
     self.parent = None
Beispiel #4
0
 def __init__(self):
     self.source_port = 0
     self.destination_port = 0
     self.seq_number = SequenceNumber(0)
     self.ack_number = SequenceNumber(0)
     self.window_size = 0
     self.flags = set()
     self.payload = str()
     self.parent = None
Beispiel #5
0
 def usable_window_size(self):
     upper_limit = self.snd_una + self.snd_wnd
     # If the upper window limit is below SND_NXT, we must return 0.
     if SequenceNumber.a_leq_b_leq_c(self.snd_una, self.snd_nxt,
                                     upper_limit):
         return upper_limit - self.snd_nxt
     else:
         # TODO: add test!
         return 0
Beispiel #6
0
 def usable_window_size(self):
     upper_limit = self.snd_una + self.snd_wnd
     # Si el límite superior de la ventana está por debajo de SND_NXT,
     # tenemos que devolver 0.
     if SequenceNumber.a_leq_b_leq_c(self.snd_una, self.snd_nxt,
                                     upper_limit):
         return upper_limit - self.snd_nxt
     else:
         # TODO: agregar test!
         return 0
Beispiel #7
0
 def ack_is_accepted(self, ack_number):
     # Aceptar sólo si SND_UNA < ACK <= SND_NXT
     return SequenceNumber.a_lt_b_leq_c(self.snd_una, ack_number,
                                        self.snd_nxt)
Beispiel #8
0
 def ack_covers_tracked_packet(self, ack_number):
     iss = self.protocol.iss
     seq_number = self.tracked_packet.get_seq_number() 
     return SequenceNumber.a_leq_b_leq_c(iss, seq_number, ack_number)
Beispiel #9
0
 def ack_is_accepted(self, ack_number):
     # Aceptar sólo si SND_UNA < ACK <= SND_NXT
     return SequenceNumber.a_lt_b_leq_c(self.snd_una, ack_number,
                                        self.snd_nxt)
Beispiel #10
0
 def compute_iss(self):
     value = random.randint(0, MAX_SEQ)
     return SequenceNumber(value)
Beispiel #11
0
 def set_seq_number(self, seq_number):
     self.seq_number = SequenceNumber(seq_number)
Beispiel #12
0
class PTCTransportPacket(object):
    
    def __init__(self):
        self.source_port = 0
        self.destination_port = 0
        self.seq_number = SequenceNumber(0)
        self.ack_number = SequenceNumber(0)
        self.window_size = 0
        self.flags = set()
        self.payload = str()
        self.parent = None
        
    def __contains__(self, element):
        flag_contained = element in PTCFlag.__subclasses__() and\
                         element in self.get_flags()

        return flag_contained   
        
    def get_source_port(self):
        return self.source_port
    
    def get_destination_port(self):
        return self.destination_port
        
    def get_seq_number(self):
        return self.seq_number
    
    def get_seq_interval(self):
        seq_lo = self.seq_number.clone()
        seq_hi = seq_lo + len(self.payload)
        return seq_lo, seq_hi

    def get_ack_number(self):
        return self.ack_number
    
    def get_window_size(self):
        return self.window_size
    
    def get_payload(self):
        return self.payload
    
    def get_parent(self):
        return self.parent
    
    def get_flags(self):
        return self.flags
    
    def add_flag(self, flag):
        self.flags.add(flag)
        
    def add_flags(self, flags):
        self.flags.update(flags)
    
    def set_source_port(self, port):
        self.source_port = port
        
    def set_destination_port(self, port):
        self.destination_port = port          
    
    def set_seq_number(self, seq_number):
        self.seq_number = SequenceNumber(seq_number)
        
    def set_ack_number(self, ack_number):
        self.ack_number = SequenceNumber(ack_number)
        
    def set_window_size(self, window_size):
        self.window_size = window_size % (MAX_WND+1)
        
    def set_payload(self, data):
        self.payload = data
        if self.parent is not None:
            length_difference = len(data) - len(self.payload)
            self.parent.add_length(length_difference)
        
    def set_parent(self, parent):
        self.parent = parent
        
    def has_payload(self):
        return len(self.payload) > 0
        
    def get_bytes(self):
        flags_bytes = reduce(lambda value, flag: value ^ flag.get_bits(),
                             self.flags, 0)
        header_bytes = struct.pack('!HHLLHH', self.source_port,
                                              self.destination_port, 
                                              self.seq_number,
                                              self.ack_number,
                                              flags_bytes,
                                              self.window_size)
        
        
        return header_bytes + self.payload
Beispiel #13
0
 def should_update_window(self, ack_number):
     # TODO: add tests for this.
     # RFC 1122, p.94 (correction to RFC 793).
     return SequenceNumber.a_leq_b_leq_c(self.snd_una, ack_number,
                                         self.snd_nxt)
Beispiel #14
0
 def should_update_window(self, ack_number):
     # TODO: agregar tests para esto.
     # RFC 1122, p.94 (corrección al RFC 793).
     return SequenceNumber.a_leq_b_leq_c(self.snd_una, ack_number,
                                         self.snd_nxt)
Beispiel #15
0
 def set_ack_number(self, ack_number):
     self.ack_number = SequenceNumber(ack_number)
Beispiel #16
0
class PTCTransportPacket(object):
    
    def __init__(self):
        self.source_port = 0
        self.destination_port = 0
        self.seq_number = SequenceNumber(0)
        self.ack_number = SequenceNumber(0)
        self.window_size = 0
        self.flags = set()
        self.payload = str()
        self.parent = None
        
    def __contains__(self, element):
        flag_contained = element in PTCFlag.__subclasses__() and\
                         element in self.get_flags()

        return flag_contained   
        
    def get_source_port(self):
        return self.source_port
    
    def get_destination_port(self):
        return self.destination_port
        
    def get_seq_number(self):
        return self.seq_number
    
    def get_seq_interval(self):
        seq_lo = self.seq_number.clone()
        seq_hi = seq_lo + len(self.payload)
        return seq_lo, seq_hi

    def get_ack_number(self):
        return self.ack_number
    
    def get_window_size(self):
        return self.window_size
    
    def get_payload(self):
        return self.payload
    
    def get_parent(self):
        return self.parent
    
    def get_flags(self):
        return self.flags
    
    def add_flag(self, flag):
        self.flags.add(flag)
        
    def add_flags(self, flags):
        self.flags.update(flags)
    
    def set_source_port(self, port):
        self.source_port = port
        
    def set_destination_port(self, port):
        self.destination_port = port          
    
    def set_seq_number(self, seq_number):
        self.seq_number = SequenceNumber(seq_number)
        
    def set_ack_number(self, ack_number):
        self.ack_number = SequenceNumber(ack_number)
        
    def set_window_size(self, window_size):
        self.window_size = window_size % (MAX_WND+1)
        
    def set_payload(self, data):
        self.payload = data
        if self.parent is not None:
            length_difference = len(data) - len(self.payload)
            self.parent.add_length(length_difference)
        
    def set_parent(self, parent):
        self.parent = parent
        
    def has_payload(self):
        return len(self.payload) > 0        
        
    def get_bytes(self):
        flags_bytes = reduce(lambda value, flag: value ^ flag.get_bits(),
                             self.flags, 0)
        header_bytes = struct.pack('!HHLLHH', self.source_port,
                                              self.destination_port, 
                                              self.seq_number,
                                              self.ack_number,
                                              flags_bytes,
                                              self.window_size)
        
        
        return header_bytes + self.payload
Beispiel #17
0
 def should_update_window(self, ack_number):
     # TODO: agregar tests para esto.
     # RFC 1122, p.94 (corrección al RFC 793).
     return SequenceNumber.a_leq_b_leq_c(self.snd_una, ack_number,
                                         self.snd_nxt)
Beispiel #18
0
 def set_seq_number(self, seq_number):
     self.seq_number = SequenceNumber(seq_number)
Beispiel #19
0
 def ack_covers_tracked_packet(self, ack_number):
     iss = self.protocol.iss
     seq_number = self.tracked_packet.get_seq_number() 
     return SequenceNumber.a_leq_b_leq_c(iss, seq_number, ack_number)