Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
For part 1 of the project, your team will implement a simple go-back-N protocol similar to TCP. This protocol is called the 352 Reliable Data Protocol (RDP) version 1 (352 RDP v1). You will realize it as a Python (version 2) module that uses UDP as the underlying transport protocol. Later versions will add security, port spaces, and concurrency.
As part of the project part 1, you will be given 3 files. You can find them in the Sakai site under “Resources” -> “Project resources” -> “Part 1” .
1. sock352.py : This is a skeleton definition of the class and methods you need to write. You should modify this file with your implementation. That is, fill in the methods with your own code.
2. client1.py : A Python client program that uses CS 352 sockets. You may not alter the source code for this file.
3. server1.py: A Python server program that uses CS 352 sockets. You may not alter the source code for this file.
Your library must implement the following methods as defined in the sock352.py file:
init(udp_port1, udp_port2) socket()
bind(address) connect(address) listen(backlog)
accept() close() send(buffer) recv(numBytes)
These function map to the existing Python methods for sockets. See this link: https://docs.python.org/2/howto/sockets.html for the definitions of these functions. The one exception init() call. This call takes a single parameter, which is the UDP port that the rest of the CS 352 RDP library will use for communication between hosts. Setting the udp_port to zero should use the default port of 27182.
For part 1 of the project, you will only need to make a single connection work over a single port for a single thread. The goal is to correctly implement a go-back-N protocol for one connection, for example, when sending a single file between a client and server. Later versions of the project will build on part to add port-spaces and handle multiple simultaneous connections.
UDP Sockets
Figure 1: Layering in CS 352 Sockets
Figure 1 shows the architecture of the 352 socket layer. All communications go through a single UDP socket. A set of ports which are managed by 352 sockets exists on top of the UDP socket.
To allow 2 instances of 352 sockets to communicate on the same machine, 2 UDP sockets must be used, one for each instance. As these can not have the same UDP port number, they must have different port numbers. In this case, each instance must use 2 UDP ports, one for sending and one for receiving.
Recall as in TCP, 352 RDP v1 maps the abstraction of a logical byte stream onto a model of an unreliable packet network. 352 RDP v1 thus closely follows TCP for the underlying packet protocol. A connection has 3 phases: Set-up, data transfer, and termination. 352 RDP v1 uses a much simpler timeout strategy than TCP for handling lost packets.
Packet structure:
The CS 352 RDP v1 packet as defined as a C structure, which must be translated into a Python struct:
/* a CS 352 RDP protocol packet header */ struct __attribute__ ((__packed__)) sock352_pkt_hdr { uint8_t version; uint8_t flags; uint8_t opt_ptr; uint8_t protocol; uint16_t header_len; uint16_t checksum; uint32_t source_port; uint32_t dest_port; uint64_t sequence_no; uint64_t ack_no; uint32_t window; uint32_t payload_len; /* version number */ /* for connection set up, tear-down, control */ /* option type between the header and payload */ /* higher-level protocol */ /* length of the header */ /* checksum of the packet */ /* source port */ /* destination port */ /* sequence number */ /* acknowledgement number */ /* receiver advertised window in bytes*/ /* length of the payload */ }; typedef struct sock352_pkt_hdr sock352_pkt_hdr_t; /* typedef shortcut */Fields in Red (version,flags,header_len,sequence_no,ack_no,payload_len) must be filled in correctly in part 1, while the Blue fields can be ignored for this part of the project.
Note that uintX_t is an X-bit unsigned integer., as defined in <sys/types.h>. At the packet level, all these fields are defined to be in network byte-order (big-endian, most significant byte first).