Пример #1
0
    def __init__(self, port, baud_rate, terminal=None, reset=False):
        Connection.__init__(self, terminal)

        self._port = port
        self._baud_rate = baud_rate

        try:
            # These timeouts should be large enough so that any continuous transmission is fully received
            self._serial = serial.Serial(None,
                                         self._baud_rate,
                                         timeout=0.2,
                                         write_timeout=0.2)
            self._serial.dtr = False
            self._serial.rts = False
            self._serial.port = port
            self._serial.open()
            if reset:
                self._serial.rts = True
                time.sleep(0.1)
                self._serial.rts = False
                x = ""
                while not x.endswith(">>>"):
                    x += self._serial.read().decode('utf-8', errors="ignore")
            self.send_kill()
        except (OSError, serial.SerialException) as e:
            self._serial = None
            return
        except Exception as e:
            return

        self._reader_thread = Thread(target=self._reader_thread_routine)
        self._reader_thread.start()
Пример #2
0
    def __init__(self,
                 transport,
                 source_address,
                 source_port,
                 destination_address,
                 destination_port,
                 app=None,
                 window=1000):
        Connection.__init__(self, transport, source_address, source_port,
                            destination_address, destination_port, app)

        ### Sender functionality

        # send window; represents the total number of bytes that may
        # be outstanding at one time
        self.window = window
        # send buffer
        self.send_buffer = SendBuffer()
        # maximum segment size, in bytes
        self.mss = 1000
        # largest sequence number that has been ACKed so far; represents
        # the next sequence number the client expects to receive
        self.sequence = 0
        # retransmission timer
        self.timer = None
        # timeout duration in seconds
        self.timeout = 1

        ### Receiver functionality

        # receive buffer
        self.receive_buffer = ReceiveBuffer()
        # ack number to send; represents the largest in-order sequence
        # number not yet received
        self.ack = 0
Пример #3
0
    def __init__(self,transport,source_address,source_port,
                 destination_address,destination_port,app=None,window=1000):
        Connection.__init__(self,transport,source_address,source_port,
                            destination_address,destination_port,app)

        ### Sender functionality

        # send window; represents the total number of bytes that may
        # be outstanding at one time
        self.window = window
        # send buffer
        self.send_buffer = SendBuffer()
        # maximum segment size, in bytes
        self.mss = 1000
        # largest sequence number that has been ACKed so far; represents
        # the next sequence number the client expects to receive
        self.sequence = 0
        # retransmission timer
        self.timer = None
        # timeout duration in seconds
        self.timeout = 1

        ### Receiver functionality

        # receive buffer
        self.receive_buffer = ReceiveBuffer()
        # ack number to send; represents the largest in-order sequence
        # number not yet received
        self.ack = 0
Пример #4
0
    def __init__(
        self,
        transport,
        source_address,
        source_port,
        destination_address,
        destination_port,
        app=None,
        window=1000,
        dynamic_rto=True,
        type="Tahoe",
    ):
        Connection.__init__(self, transport, source_address, source_port, destination_address, destination_port, app)

        ### Sender functionality

        # send window; represents the total number of bytes that may
        # be outstanding at one time
        self.window = default_mss
        # send buffer
        self.send_buffer = SendBuffer()
        # maximum segment size, in bytes
        self.mss = default_mss
        # largest sequence number that has been ACKed so far; represents
        # the next sequence number the client expects to receive
        self.sequence = 0
        # retransmission timer
        self.timer = None
        # timeout duration in seconds
        self.timeout = 1

        self.threshold = 100000

        self.ack_received_count = {}
        self.wait_for_timeout = False

        self.reno_fast_recovery = type == "Reno"

        # constants
        self.k = 4
        self.g = 0.1
        self.alpha = 1 / 8
        self.beta = 1 / 4

        self.dynamic_rto = dynamic_rto
        self.rto = 3
        self.srtt = None
        self.rttvar = None

        ### Receiver functionality

        # receive buffer
        self.receive_buffer = ReceiveBuffer()
        # ack number to send; represents the largest in-order sequence
        # number not yet received
        self.ack = 0
Пример #5
0
    def __init__(self,
                 transport,
                 source_address,
                 source_port,
                 destination_address,
                 destination_port,
                 app=None,
                 drop=[],
                 fast_retransmit=False,
                 measure=False):
        Connection.__init__(self, transport, source_address, source_port,
                            destination_address, destination_port, app)

        # -- Sender functionality

        # send buffer
        self.send_buffer = SendBuffer()
        # maximum segment size, in bytes
        self.mss = 1000
        # initial cwnd is equal to 1mss
        self.cwnd = float(self.mss)
        # boolean flag that indicates if in slow start or additive increase
        self.slow_start = True
        # When cwnd >= ss_thresh, slow start ends
        self.ss_thresh = 100000
        if self.node.hostname == 'n1':
            self.trace("Entering Slow Start: SS Thresh = %s" %
                       (self.ss_thresh))
        # Tracks additive increase - determines when to add another MSS to cwnd
        self.cwnd_inc = 0

        # largest sequence number that has been ACKed so far; represents
        # the next sequence number the client expects to receive
        self.sequence = 0
        # plot sequence numbers
        self.plot_sequence_header()
        self.plot_cwnd_header()
        self.plot_cwnd()
        # packets to drop
        self.drop = drop
        self.dropped = []
        # retransmission timer
        self.timer = None
        # timeout duration in seconds
        self.timeout = 1

        # -- Receiver functionality

        # receive buffer
        self.receive_buffer = ReceiveBuffer()
        # ack number to send; represents the largest in-order sequence
        # number not yet received
        self.ack = 0
        self.fast_retransmit = fast_retransmit
        self.last_ack = 0
        self.last_ack_count = 0
Пример #6
0
    def __init__(self,
                 transport,
                 source_address,
                 source_port,
                 destination_address,
                 destination_port,
                 app=None,
                 window=1000,
                 drop=[]):
        Connection.__init__(self, transport, source_address, source_port,
                            destination_address, destination_port, app)

        # -- Sender functionality

        # send window; represents the total number of bytes that may
        # be outstanding at one time
        self.window = window
        # send buffer
        self.send_buffer = SendBuffer()
        # maximum segment size, in bytes
        self.mss = 1000
        # largest sequence number that has been ACKed so far; represents
        # the next sequence number the client expects to receive
        self.sequence = 0
        # plot sequence numbers
        self.plot_sequence_header()
        # packets to drop
        self.drop = drop
        self.dropped = []
        # retransmission timer
        self.timer = None
        # timeout duration in seconds
        self.timeout = 1
        # RTO calculation variables
        self.rto = 1
        self.srtt = 0
        self.rttvar = 0
        # Variables for handling fast retransmit
        self.fast_enable = False
        self.last_ack = 0
        self.same_ack_count = 0
        self.fast_retransmitted = False

        # -- Receiver functionality

        # receive buffer
        self.receive_buffer = ReceiveBuffer()
        # ack number to send; represents the largest in-order sequence
        # number not yet received
        self.ack = 0
Пример #7
0
    def __init__(self, host, port, terminal, password_prompt):
        Connection.__init__(self, terminal)
        self._host = host
        self._port = port
        self.s = None
        self.ws = None

        if not self._start_connection():
            return

        if not self.handle_password(password_prompt):
            self._clear()
            raise PasswordException()

        self._reader_thread = Thread(target=self._reader_thread_routine)
        self._reader_thread.start()
Пример #8
0
    def __init__(self,
                 transport,
                 source_address,
                 source_port,
                 destination_address,
                 destination_port,
                 app=None,
                 window=1000):
        Connection.__init__(self, transport, source_address, source_port,
                            destination_address, destination_port, app)

        ### Sender functionality

        # send window; represents the total number of bytes that may
        # be outstanding at one time
        # Step 2
        self.window = window
        # send buffer
        self.send_buffer = SendBuffer()
        # maximum segment size, in bytes
        # self.mss = 1000
        self.mss = min(1000, window)
        # largest sequence number that has been ACKed so far; represents
        # the next sequence number the client expects to receive
        self.sequence = 0
        # retransmission timer
        self.timer = None
        # timeout duration in seconds
        self.timeout = 3.0
        # estimated rtt
        self.est_rtt = None
        # alpha
        self.alpha = 0.125
        # variation rtt
        self.var_rtt = None  ## TODO: revisit this later
        # beta
        self.beta = 0.25
        # timer start
        self.start_time = 0.0
        ### Receiver functionality

        # receive buffer
        self.receive_buffer = ReceiveBuffer()
        # ack number to send; represents the largest in-order sequence
        # number not yet received
        self.ack = 0
Пример #9
0
 def __init__(self,transport,source_address,source_port,
              destination_address,destination_port,window_size,app=None):
     Connection.__init__(self,transport,source_address,source_port,
                         destination_address,destination_port,app)
     self.send_buffer = ''
     self.next_sequence_num = 0
     self.received_ack_number = 0
     self.unacked_packet_count = 0
     self.mss = 1000
     self.sequence = 0
     self.received_sequences = set([])
     self.receive_buffer = []
     self.ack = 0
     self.timer = None
     self.timeout = 1
     self.max_sequence = math.pow(2,64)
     self.window_size = window_size
Пример #10
0
	def __init__(self,transport,source_address,source_port,
				 destination_address,destination_port,app=None):
		Connection.__init__(self,transport,source_address,source_port,
							destination_address,destination_port,app)
		self.send_buffer = ''
		self.receive_buffer = []
		self.packets_outstanding = 0
		self.mss = 1000
		self.sequence = 0
		self.ack = 0
		self.timer = None
		self.timeout = 1
		self.max_sequence = math.pow(2,64)
		self.window_size = 1
		self.window_start = 0
		self.timer_set = False
		self.queueing_delay = 0
		self.pkt_q_delay_threshold = 0.0000000001
		self.pkts_rcvd = 0
Пример #11
0
    def __init__(self,transport,source_address,source_port,
                 destination_address,destination_port,app=None):
        Connection.__init__(self,transport,source_address,source_port,
                            destination_address,destination_port,app)
        self.send_buffer = ''
        self.received_ack_number = 0
        self.unacked_packet_count = 0
        self.mss = 1000
        self.sequence = 0
        self.received_sequences = set([])
        self.receive_buffer = []
        self.ack = 0
        self.cwnd = 0
        self.threshold = 100000
        self.timer = None
        self.timeout = 0.1
        self.max_sequence = math.pow(2,64)

        self.rate_file = open ('output/rate%d.txt' % source_port, 'w+')
        self.sequence_file = open('output/sequence%d.txt' % source_port, 'w+')
        self.window_file = open('output/window%d.txt' % source_port, 'w+')
        self.ack_file = open('output/acks%d.txt' % source_port, 'w+')
Пример #12
0
 def __init__(self,transport,source_address,source_port,
              destination_address,destination_port,window,app=None):
     
     Connection.__init__(self,transport,source_address,source_port,
                         destination_address,destination_port,app)
     #sender
     self.send_buffer = ''
     self.next_sequence_num = 0
     self.send_base = self.next_sequence_num
     self.not_yet_acknowledged_segments = 0
     #receiver
     self.receive_temp_buffer = set([])
     self.receive_packet_buffer = []
     self.ack = 0
     self.timer_counter = 0
     self.triple_dup_ack_counter = 0
     
     self.mss = 1000
     self.window = window
     
     self.timer = None
     self.timeout = 1    # 1 second
     self.max_sequence = math.pow(2,64)
Пример #13
0
    def __init__(self, host, port, terminal, ask_for_password):
        Connection.__init__(self, terminal)

        self.s = socket.socket()
        self.s.settimeout(3)
        errno = self.s.connect_ex((host, port))
        if errno != 0:
            self._clear()
            return
        self.s.settimeout(None)

        websocket_helper.client_handshake(self.s)

        self.ws = WebSocket(self.s)
        self.login(ask_for_password())
        try:
            self.read_all()
        except:
            self._clear()
            return

        self._reader_thread = Thread(target=self._reader_thread_routine)
        self._reader_thread.start()
Пример #14
0
    def __init__(self,
                 transport,
                 source_address,
                 source_port,
                 destination_address,
                 destination_port,
                 app=None,
                 window=1000,
                 threshold=100000,
                 fast_recovery=False,
                 aiad=False,
                 aimdc=0.5):
        Connection.__init__(self, transport, source_address, source_port,
                            destination_address, destination_port, app)

        ### Sender functionality

        # send window; represents the total number of bytes that may
        # be outstanding at one time (cwnd)
        self.window = window
        # send buffer
        self.send_buffer = SendBuffer()
        # maximum segment size, in bytes
        self.mss = 1000
        # largest sequence number that has been ACKed so far; represents
        # the next sequence number the client expects to receive
        self.sequence = 0
        # retransmission timer
        self.timer = None
        # timeout duration in seconds
        self.timeout = 1
        # Round trip time in seconds
        self.estimated_rtt = None
        # Deviation of sample rtt from estimated rtt
        self.deviation_rtt = None
        # State determines slow start vs. additive increase
        # 0 = slow start
        # 1 = additive increase
        self.state = 0
        # Threshold for slow start
        self.threshold = threshold
        self.trace("Threshold starting at %d" % self.threshold)
        # Same ack count (used for calculating three duplicate acks)
        self.same_ack_count = 0
        # Most recent ack (used for calculating three duplicate acks)
        self.last_ack = None
        # Make sure settings start with slow start
        self.window = self.mss

        # Used when dropping certain packets
        self.dropped_count = 0

        # Fast Recovery (Reno)
        self.fast_recovery = fast_recovery

        # AIAD
        self.aiad = aiad

        # AIMD Constant
        self.aimdc = aimdc

        ### Used to make TCP Sequence Graphs

        self.x = []
        self.y = []
        self.dropX = []
        self.dropY = []
        self.ackX = []
        self.ackY = []

        ### Used to make window size graphs

        self.window_x = []
        self.window_y = []

        ### Receiver functionality

        # receive buffer
        self.receive_buffer = ReceiveBuffer()
        # ack number to send; represents the largest in-order sequence
        # number not yet received
        self.ack = 0
        # a list of all the queuing delays from the sender to receiver
        self.queueing_delay_list = []
        # keep track of when packets were received
        self.packets_received = {}
Пример #15
0
    def __init__(self,transport,source_address,source_port,
                 destination_address,destination_port,app=None,window=1000,
                 threshold=100000,fast_recovery=False):
        Connection.__init__(self,transport,source_address,source_port,
                            destination_address,destination_port,app)

        ### Sender functionality

        # send window; represents the total number of bytes that may
        # be outstanding at one time (cwnd)
        self.window = window
        # send buffer
        self.send_buffer = SendBuffer()
        # maximum segment size, in bytes
        self.mss = 1000
        # largest sequence number that has been ACKed so far; represents
        # the next sequence number the client expects to receive
        self.sequence = 0
        # retransmission timer
        self.timer = None
        # timeout duration in seconds
        self.timeout = 1
        # Round trip time in seconds
        self.estimated_rtt = None
        # Deviation of sample rtt from estimated rtt
        self.deviation_rtt = None
        # State determines slow start vs. additive increase
        # 0 = slow start
        # 1 = additive increase
        self.state = 0
        # Threshold for slow start
        self.threshold = threshold
        self.trace("Threshold starting at %d" % self.threshold)
        # Same ack count (used for calculating three duplicate acks)
        self.same_ack_count = 0
        # Most recent ack (used for calculating three duplicate acks)
        self.last_ack = None
        # Make sure settings start with slow start
        self.window = self.mss

        # Used when dropping certain packets
        self.dropped_count = 0
        
        # Fast Recovery (Reno)
        self.fast_recovery=fast_recovery
        
        ### Used to make TCP Sequence Graphs

        self.x = []
        self.y = []
        self.dropX = []
        self.dropY = []
        self.ackX = []
        self.ackY = []

        ### Receiver functionality

        # receive buffer
        self.receive_buffer = ReceiveBuffer()
        # ack number to send; represents the largest in-order sequence
        # number not yet received
        self.ack = 0
        # a list of all the queuing delays from the sender to receiver
        self.queueing_delay_list = []