-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRDT.py
More file actions
executable file
·107 lines (89 loc) · 5.1 KB
/
Copy pathRDT.py
File metadata and controls
executable file
·107 lines (89 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import socket
class RDTSocket():
def __init__(self) -> None:
"""
You shold define necessary attributes in this function to initialize the RDTSocket
"""
#############################################################################
# TODO: NECESSARY ATTRIBUTES HERE #
#############################################################################
#############################################################################
# TODO: YOUR CODE HERE #
#############################################################################
pass
def bind(self, address: (str, int)): # type: ignore
"""
When trying to establish a connection. The socket must be bound to an address
and listening for connections. address is the address bound to the socket on
the other end of the connection.
params:
address: Target IP address and its port
"""
#############################################################################
# TODO: YOUR CODE HERE #
#############################################################################
raise NotImplementedError()
def accept(self): # type: ignore
"""
When using this SOCKET to create an RDT SERVER, it should accept the connection
from a CLIENT. After that, an RDT connection should be established.
Please note that this function needs to support multithreading and be able to
establish multiple socket connections. Messages from different sockets should
be isolated from each other, requiring you to multiplex the data received at
the underlying UDP.
This function should be blocking.
"""
#############################################################################
# TODO: YOUR CODE HERE #
#############################################################################
raise NotImplementedError()
def connect(self, address: (str, int)): # type: ignore
"""
When using this SOCKET to create an RDT client, it should send the connection
request to target SERVER. After that, an RDT connection should be established.
params:
address: Target IP address and its port
"""
#############################################################################
# TODO: YOUR CODE HERE #
#############################################################################
raise NotImplementedError()
def send(self, data=None, tcpheader=None, test_case=0):
"""
RDT can use this function to send specified data to a target that has already
established a reliable connection. Please note that the corresponding CHECKSUM
for the specified data should be calculated before computation. Additionally,
this function should implement flow control during the sending phase. Moreover,
when the data to be sent is too large, this function should be able to divide
the data into multiple chunks and send them to the destination in a pipelined
manner.
params:
data: The data that will be sent.
tcpheader: Message header.Include SYN, ACK, FIN, CHECKSUM, etc. Use this
attribute when needed.
test_case: Indicate the test case will be used in this experiment
"""
#############################################################################
# TODO: YOUR CODE HERE #
#############################################################################
raise NotImplementedError()
def recv(self):
"""
You should implement the basic logic for receiving data in this function, and
verify the data. When corrupted or missing data packets are detected, a request
for retransmission should be sent to the other party.
This function should be bolcking.
"""
#############################################################################
# TODO: YOUR CODE HERE #
#############################################################################
raise NotImplementedError()
def close(self):
"""
Close current RDT connection.
You should follow the 4-way-handshake, and then the RDT connection will be terminated.
"""
#############################################################################
# TODO: YOUR CODE HERE #
#############################################################################
raise NotImplementedError()