Exemplo n.º 1
0
 def _test_blocking_timeout(self, timeout, delta):
     client = PFTPClient([])
     t1 = time()
     sent = client.rdt_send(b'00000' * 2900, btimeout=timeout)
     t2 = time()
     client.logger.info("")
     client.logger.info("Took : {}".format(t2 - t1))
     self.assertAlmostEqual(t2 - t1, timeout, delta=delta)
Exemplo n.º 2
0
    def test_rdt_send_saw_2(self):
        # SAW Test : Level 2
        # send one segment from server. check for delivery.
        # do not send back ACK. wait for retry packet. use blocking timeout to return from loop
        mss = 400
        client = PFTPClient([self.SERVER_ADDR], mss=mss)
        msg = lambda size: b'1' * size

        msg_size = 336
        seq_gen = SequenceNumberGenerator()
        # start a blocking send
        t1 = Thread(target=client.rdt_send, args=[msg(msg_size), 3])
        t1.start()
        # receive first segment
        actual, addr = self._receive_segment(mss)
        _seq = Header.size() + mss
        _, seq = seq_gen.get_next(_seq)
        expected = SegmentBuilder().with_data(
            msg(msg_size)).with_seq(seq).with_type(Segment.TYPE_DATA).build()
        self.assertEqual(actual.header.seq, expected.header.seq)
        self.assertEqual(actual.header.stype, expected.header.stype)
        self.assertEqual(actual.header.checksum, expected.header.checksum)
        # check retried segment
        actual, addr = self._receive_segment(mss)
        _, seq = seq_gen.get_current()  # Notice sequence Number here
        expected = SegmentBuilder().with_data(
            msg(msg_size)).with_seq(seq).with_type(Segment.TYPE_DATA).build()
        self.assertEqual(actual.header.seq, expected.header.seq)
        self.assertEqual(actual.header.stype, expected.header.stype)
        self.assertEqual(actual.header.checksum, expected.header.checksum)
        t1.join()
Exemplo n.º 3
0
 def test_enqueue_bytes(self):
     c = PFTPClient([])
     msg = b'0' * 19
     c._enqueue_bytes(msg)
     self.assertEqual(len(c.queue_msg), 1)
     c._enqueue_bytes(msg)
     c._enqueue_bytes(msg)
     c._enqueue_bytes(msg)
     self.assertEqual(len(c.queue_msg), 4)
Exemplo n.º 4
0
    def test_rdt_send_saw_3(self):
        # SAW Test : Level 3
        # simulate failures. check for retry.
        mss = 4000
        client = PFTPClient([self.SERVER_ADDR], mss=mss, atimeout=0.5)
        msg = lambda size: b'1' * size

        msg_size = 8000
        # start a blocking send
        t1 = Thread(target=client.rdt_send, args=[msg(msg_size)])
        rcvd_msg = b''
        t1.start()
        while len(rcvd_msg) < msg_size:
            try:
                segment, addr = self._receive_segment(mss + Header.size())
            except (socketTimeout, MalformedSegmentError):
                continue
            if bool(random.getrandbits(1)):
                self._send_ack_to(seq=segment.header.seq, addr=addr)
                rcvd_msg += segment.data
        t1.join()
        # finally make sure all 8000 bytes are received
        self.assertEqual(len(rcvd_msg), msg_size)
Exemplo n.º 5
0
    def test_rdt_send_saw_non_blocking(self):
        # non blocking mode test
        mss = 400
        client = PFTPClient([self.SERVER_ADDR], mss=mss)
        msg = lambda size: b'1' * size

        msg_size = 673
        seq_gen = SequenceNumberGenerator()
        client.setblocking(False)
        client.rdt_send(msg(msg_size))
        # start a blocking send
        # check all segments
        for chunk in _chunk_bytes(msg(msg_size), mss):
            actual, addr = self._receive_segment(mss + Header.size())
            _seq = Header.size() + mss
            _, seq = seq_gen.get_next(_seq)
            expected = SegmentBuilder().with_data(chunk).with_seq(
                seq).with_type(Segment.TYPE_DATA).build()
            self._send_ack_to(seq=actual.header.seq, addr=addr)
            self.assertEqual(actual, expected)
Exemplo n.º 6
0
 def setUp(self):
     self.server_addr = [('127.0.0.1', 9989), ('127.0.0.1', 9988)]
     self.mss = 8000
     self.logger = logger()
     self.pftpclient = PFTPClient(self.server_addr, atimeout=0.5, mss=self.mss)
     return super().setUp()
Exemplo n.º 7
0
from pftp.client.pftpclient import PFTPClient

if __name__ == "__main__":
    msg = lambda x: b'10' * (x // 2)
    msg_size = int(input('Enter Message Size: '))
    mss = int(input('Enter MSS: '))
    atimeout = float(
        input('Enter Wait Timeout: ')
    )  # 0.03 seconds is the sweet spot is servers are on same machine
    no_clients = int(input('Enter No of Receivers: '))
    timeout = int(input('Enter Stop Timeout: '))

    print('Enter Receiver <Host>,<Port> each on new line...')

    addresses = []
    for i in range(no_clients):
        x = input()
        addresses.append((str(x).split(',')[0], int(str(x).split(',')[1])))

    input('Press Enter to start transmitting file')

    PFTPClient(addresses, atimeout=atimeout,
               mss=mss).rdt_send(msg(msg_size), btimeout=timeout)
Exemplo n.º 8
0
    def test_dequeue_bytes(self):
        c = PFTPClient([])
        expected = b'0' * 19
        c._enqueue_bytes(expected)
        actual = c._dequeue_bytes(19)
        self.assertEqual(actual, expected)

        c = PFTPClient([])
        expected = b'0' * 19
        c._enqueue_bytes(expected)
        actual = c._dequeue_bytes(19)
        self.assertEqual(actual, expected)

        expected = b'0' * 40
        c._enqueue_bytes(expected)
        a1, e1 = c._dequeue_bytes(19), b'0' * 19
        a2, e2 = c._dequeue_bytes(1), b'0' * 1
        a3, e3 = c._dequeue_bytes(20), b'0' * 20
        self.assertEqual(a1, e1)
        self.assertEqual(a2, e2)
        self.assertEqual(a3, e3)

        # 10 MB Test case
        expected = b'1' * 10000000
        c._enqueue_bytes(expected)
        a1 = c._dequeue_bytes(10000000)
        self.assertEqual(a1, expected)

        # test order of dequeued bits
        expected = b'1010101001000010010101010010100100100101001001010110'
        c._enqueue_bytes(expected)
        a1, a2, a3 = c._dequeue_bytes(1), c._dequeue_bytes(
            10), c._dequeue_bytes(10)
        e0, e1, e2 = expected[0:1], expected[1:11], expected[11:21]
        self.assertEqual(a1, e0)
        self.assertEqual(a2, e1)
        self.assertEqual(a3, e2)
Exemplo n.º 9
0
import sys
from time import time

from pftp.client.pftpclient import PFTPClient

if __name__ == "__main__":
    n = int(sys.argv[1])
    MSS = int(sys.argv[2])
    atimeout = float(sys.argv[3])
    server_port = 7735

    servers = [('152.46.19.167', server_port), ('152.46.19.168', server_port),
               ('152.46.19.169', server_port), ('192.168.10.62', server_port),
               ('192.168.10.172', server_port)]

    with open('data.txt', 'rb') as file:
        data = file.read()

    input(
        'Press Enter to start P2MPClient with n: {}, MSS: {}, Wait Timeout: {}'
        .format(n, MSS, atimeout))

    start = time()
    sent = PFTPClient(servers[:n], mss=MSS, atimeout=atimeout).rdt_send(data)

    print('Took {:.2f} seconds to sent {} bytes'.format(time() - start, sent))