” COMP3331编程 写作、Python编程 辅导COMP3331/9331 Computer Networks and ApplicationsAssignment for Term 2, 2021Version 1.0Due: 11:59am (noon) Friday, 6 August 2021 (Week 10)1. Change LogVersion 1.0 released on 21st June 2021.2. Goal and learning objectivesFor this assignment, you will be asked to implement a reliable transport protocol over the UDPprotocol. We will refer to the Reliable transport protocol that you will be programming in thisassignment as Padawan Transport Protocol (PTP). PTP will include most (but not all) of thefeatures that are described in Sections 3.5.4 and 3.5.6 of the text Computer Networking (7th ed.).Examples of these features include timeout, ACK, sequence numbers, etc. Note that these featuresare commonly found in many transport protocols. Therefore, this assignment will give you anopportunity to implement some of these basic features of a transport protocol. In addition, you mayhave wondered why the designer of the TCP/IP protocol stack includes such feature-less transportprotocol as UDP. You will find in this assignment that you can design your own transport protocoland run it over UDP. This is the case for some existing multimedia delivery services on the Internet,where they have implemented their own proprietary transport protocol over UDP.Note that it is mandatory that you implement PTP over UDP. Do not use TCP sockets. Youwill not receive any mark for this assignment if you use TCP sockets.2.1 Learning ObjectivesOn completing this assignment, you will gain sufficient expertise in the following skills:1. Detailed understanding of how reliable transport protocols such as TCP function.2. Socket programming for UDP transport protocol.3. Protocol and message design.Non-CSE Student: The rationale for this option is that students enrolled in a program that does notinclude a computer science component have had very limited exposure to programming and inparticular working on complex programming assignments. A Non-CSE student is a student who isnot enrolled in a CSE program (single or double degree). Examples would include students enrolledexclusively in a single degree program such as Mechatronics or Aerospace or Actuarial Studies orLaw. Students enrolled in dual degree programs that include a CSE program as one of the degreesdo not qualify. Any student who meets this criterion and wishes to avail of this option MUST emailcs3331@cse.unsw.edu.au to seek approval before 5pm, 2nd July (Friday, Week 5). We willassume by default that all students are attempting the CSE version of the assignment unless theyhave sought explicit permission. No exceptions.Updates to the assignment, including any corrections and clarifications, will be posted on thesubject website. Please make sure that you check the subject website regularly for updates.23. Assignment SpecificationAs part of this assignment, you will have to implement Padawan Transport Protocol (PTP), a pieceof software that consists of a sender and receiver component that allows reliable unidirectionaldata transfer. PTP includes some of the features of the TCP protocol that are described in sections3.5.4 and 3.5.6 of the textbook (7th edition). You will use your PTP protocol to transfer simple text(ASCII) files (examples Provided on the assignment webpage) from the sender to the receiver. Youshould implement PTP as two separate programs: Sender and Receiver. You only have toimplement unidirectional transfer of data from the Sender to the Receiver. As illustrated in Figure1, data segments will flow from Sender to Receiver while ACK segments will flow from Receiverto Sender. Let us reiterate this, PTP must be implemented on top of UDP. Do not use TCPsockets. If you use TCP, you will not receive any marks for your assignment.You will find it useful to review sections 3.5.4 and 3.5.6 of the text. It may also be useful to reviewthe basic concepts of reliable data transfer from section 3.4.NOTE: Section 3.5 of the textbook which covers the bulk of the discussion on TCP is available todownload on the assignment page.3.1 File NamesThe main code for the sender and receiver should be contained in the following files: sender.c,or Sender.java or sender.py, and receiver.c or Receiver.java or receiver.py.You are free to create additional files such as header files or other class files and name them as youwish.3.2 List of features provided by the Sender and ReceiverYou are required to implement the following features in the Sender and Receiver:1. A three-way handshake (SYN, SYN+ACK, ACK) for the connection establishment. The ACKsent by the sender to conclude the three-way handshake should not contain any payload (i.e., data).See Section 3.5.6 of the text for further details.2. The four-segment connection termination (FIN, ACK, FIN, ACK). The Sender will initiate theconnection close once the entire file has been successfully transmitted. It is possible for theReceiver to combine the ACK and FIN in one message. See Section 3.5.6 of the text for furtherdetails. The Sender should terminate after connection closure.Figure 1: The basic setup of your assignment. A file is to be transferred from the Sender to the Receiver.Sender will run on the sender side while Receiver will run on the receiver side. Note that data segments willflow from the sender to receiver, while ACK segments will flow from the receiver to sender.DataAck Sender ReceiverUDP Socket1Let OS pick the port numberUDP Socket 2receiver_port specified as argument33. Sender must maintain a single timer for timeout operation (Section 3.5.4 of the text). You mustuse a constant timeout in your program. The value of the timeout will be supplied to Sender as aninput argument.4. Sender should implement all the features mentioned in Section 3.5.4 of the text, with theexception of doubling the timeout. The PTP protocol must include the simplified TCP sender(Figure 3.33 of the text) and fast retransmit (pages 247-248). You will need to use a number ofconcepts that we have discussed in class, e.g., sequence numbers, cumulative acknowledgements,timers, buffers, etc. for implementing your protocol.5.Receiver should implement the features mentioned in Section 3.5.4 of the text. However, you donot need to follow Table 3.2 (of text) for ACK generation. All segments should be immediatelyacknowledged, i.e., you do not have to implement delayed ACKs.6. PTP is a byte-stream oriented protocol. You will need to include sequence number andacknowledgement number fields in the PTP header for each segment. The meaning of sequencenumber and acknowledgment number are the same as TCP.7. One of the command line Arguments, MSS (Maximum segment size) is the maximum number ofbytes of data that your PTP segment can contain. In other words, MSS counts data ONLY and doesNOT include header. Sender must be able to deal with different values of MSS. The value of MSSwill be supplied to Sender as an input argument. You may safely assume that the MSS will besmaller than the maximum possible size of a UDP segment (64Kbytes).8. Another input argument for Sender is Maximum Window Size (MWS). MWS is the maximumnumber of un-acknowledged bytes that the Sender can have at any time. MWS counts ONLY data.Header length should NOT be counted as part of MWS.Remarks: Note that TCP does not explicitly define a maximum window size. In TCP, the maximumnumber of un-acknowledged bytes is limited by the smaller of receive window and the congestioncontrol window. Since you will not be implementing flow or congestion control, you will be limitingthe number of un-acknowledged bytes by using the MWS parameter. In other words, you will needto ensure that during the lifetime of the connection, the following condition is satisfied:LastByteSent LastByteAcked MWS10. Even though you will use UDP since the sender and receiver will mostly be running on the samephysical machine, there will be no real possibility of PTP segments being dropped. In order to testthe reliability of your protocol, it is imperative to introduce artificially induced packet loss. For thispurpose, you must also implement a Packet Loss (PL) Module as part of the Sender program. Thedetails for this module are explained later in the specification.4.3 Features excludedThere are a number of transport layer features adopted by TCP that are excluded from thisassignment:1. You do not need to use a random initial sequence number.2. You do not need to implement timeout estimation. The timer value is provided as a commandline argument.3. You do not need to double timeout interval.4. You do not need to implement any flow nor congestion control.5. PTP does not have to deal With corrupted packets. Packets will rarely be corrupted when thesender and receiver are executing on the same machine. In short, it is safe for you to assume4that packets are only lost.6. You do not need to handle abnormal behaviour, i.e., Sender or Receiver program crashing. Inother words, you do not need to implement functionality like RST in TCP.4.4 Packet header and MSSIn designing the segment header, you only need to include the fields that you think are necessary forPTP. You can draw inspiration from TCP but the exact format of the PTP packet header is for youto decide. The header portion can include as many fields as you think are necessary. Two importantfields that will be needed are the sequence number and acknowledgement number. You will alsoneed a number of flags for connection establishment and teardown.The data portion must not contain more than MSS bytes of data. You must use the same PTPsegment format for data transfer as well as for the acknowledgements flowing back from thereceiver to the sender. The only difference will be that the acknowledgement segments will notcontain any data. All information that is necessary for the proper functioning of your protocol mustbe provided in the PTP headers. You may use the port number and IP address included within theUDP datagram that encapsulates the PTP segments.4.5 SenderThis section provides details on the Sender.The Sender should accept the following eight (8) arguments (note that the last two arguments areused exclusively by the PL module):1. receiver_host_ip: the IP address of the host machine on which the Receiver is running.2. receiver_port: the port number on which Receiver is expecting to receive packets fromthe sender. This should match the command line argument of the same name for the Receiver.3. FileToSend.txt: the name of the text file that has to be transferred from sender toreceiver using your reliable transport protocol. You may assume that the file included in theargument will be available in the current working directory of the Sender with the correctaccess permissions set (read).4. MWS: the maximum window size used by your PTP protocol in bytes.5. MSS: Maximum Segment Size which is the maximum amount of data (in bytes) carried ineach PTP segment. NOTE: In our tests we will ensure that MWS is exactly divisible by MSS.6. timeout: the value of timeout in milliseconds.The following two arguments are used exclusively by the PL module:7. pdrop: the probability that a PTP data segment which is ready to be transmitted will bedropped. This value must be between 0 and 1. For example if pdrop = 0.5, it means that50% of the transmitted packets are dropped by the PL.8. seed: The seed for your Random number generator. The use of seed will be explained inSection 4.5.2 of the specification.The Sender should be initiated as follows:If you use Java:java Sender receiver_host_ip receiver_port FileToSend.txt MWS MSS timeout pdropseed5If you use C:./sender receiver_host_ip receiver_port FileToSend.txt MWS MSS timeout pdropseedIf you use Python:python sender.py receiver_host_ip receiver_port FileToSend.txt MWS MSS timeoutpdrop seedNote that, you should first execute the Receiver before initiating the Sender.It is very likely that you will be executing the Sender and Receiver on the same machine. In thiscase use 127.0.0.1 (localhost) for the receiver_host_ip.4.5.1 The PL ModuleThe PL module should be implemented as part of your Sender program. The function of the PL is toemulate packet loss on the Internet. Even though theoretically UDP datagrams will get lost, in ourtest environment these events will occur very rarely. Further to test the reliability of your PTPprotocol we would like to be able to control the percentage of packets being lost. You can assumethat packets will not be delayed or corrupted in the network.The following describes the sequence of steps that the PL should perform on receiving a PTPsegment:1. If the PTP segment is for connection establishment or teardown, then pass the segment toUDP, do not drop it.Remark: In order to reduce the complexity of connection setup, the connection establishmentand teardown segments from the Sender can bypass the PL module and will not be dropped.2. If the PTP segment is not for connection establishment or teardown, the PL module must doone of the following:(a) with probability pdrop drop the datagram.(b) With probability (1-pdrop), forward the datagram.To implement this simply generate a random number between 0 and 1. If the chosen numberis greater than pdrop transmit the packet, else the packet is dropped.Remark: The file PingServer.java in Lab Exercise 2 contains an example of randomlydropping packets.Once the PL is ready to transmit a PTP segment, the Sender should encapsulate the PTP segment ina UDP datagram (i.e., create a UDP datagram with the PTP segment as the payload). It should thentransmit this datagram to the Receiver through the UDP socket created earlier. (Use thereceiver_host_ip and receiver_port as the destination IP address and port numberrespectively). Once the Entire text file has been transmitted reliably (i.e., the sender window isempty and the final ACK is received) the Sender can close the UDP socket and terminate.Note that the ACK segments from the receiver must completely bypass the PL modules. In otherwords, ACK segments are never lost.4.5.2 Seed for random number generatorsIn order for us to check your results, we will be asking you to initialise your random numbergenerator with a specific seed in Section 8 of the spec so that we can repeat your experiments.If you have not learnt about the principles behind random number generators, you need to know that6random numbers are in fact generated by a deterministic formula by a computer program.Therefore, strictly speaking, random number generators are called pseudo-random numbergenerators because the numbers are not truly random. The deterministic formula for randomnumber generation in Python, Java and C uses an input parameter called a seed. If the same seed isused, then the same sequence of random numbers will be produced.The following code fragment in Python, Java and C will generate random numbers between 0 and 1using a supplied seed.1. In Python, you initialise a random number generator (assuming the seed is 50) by usingrandom.seed(50);. After that you can generate a random floating point number between(0,1) by using random.random();2. In Java, you initalise a random number generator (assuming the seed is 50) by using Randomrandom = new Random(50);. After that, you can generate a random floating pointnumber between (0,1) by using float x = random.nextFloat();3. In C, you initalise a random number generator (assuming the seed is 50) by usingsrand(50);. After that, you can generate a random floating point number between (0,1) byusing float x = rand()/((float)(RAND_MAX)+1); Note that, RAND_MAX is themaximum value returned by the rand() function.You will find that if you specify different seeds, a different sequence of pseudo-random numberswill be produced.4.5.3 Additional requirements for SenderYour Sender will receive acknowledgements from the Receiver through the same socket, which thesender uses to transmit data. The Sender must first extract the PTP acknowledgement from the UDPdatagram that it receives and then process it as per the operation of your PTP protocol. The formatof the acknowledgement segments should be exactly the same as the data segments except that theyshould not contain any data. Note that these acknowledgements should bypass the PL module.The sender should maintain a log file titled Sender_log.txt where it records the informationabout each segment that it sends and receives. You may assume that the sender program will havepermission to create files in its Current working directory. Information about dropped segmentspackets should also be included. Start each entry on a new line. The format should be as follows:snd/rcv/drop time type of packet seq-number number-ofbytesack-numberwhere type of packet could be S (SYN), A (ACK), F (FIN) and D (Data) and the fields should betab separated.For example, the following shows the log file for a Sender that transmits 112 bytes of data. TheMSS used here is 56 bytes and the timeout interval is 100msec. Notice that the second data packetis dropped and is hence retransmitted after a timeout interval of 100msec.snd 34.335 S 121 0 0rcv 34.40 SA 154 0 122snd 34.54 A 122 0 155snd 34.57 D 122 56 155drop 34.67 D 178 56 155rcv 36.56 A 155 0 1787snd 134.67 D 178 56 155rcv 137.65 A 155 0 234snd 138.76 F 234 0 155rcv 140.23 FA 155 0 235snd 141.11 A 235 0 156Once the entire file has been transmitted reliably the Sender should initiate the connection closureprocess by sending a FIN segment (refer to Section 3.5.6 of the text). The Sender should also printthe following statistics at the end of the log file (i.e., Sender_log.txt): Amount of (original) Data Transferred (in bytes) Number of Data Segments Sent (excluding retransmissions) Number of (all) Packets Dropped (by the PL module) Number of Retransmitted Segments Number of Duplicate Acknowledgements receivedNOTE: Generation of this log file is very important. It will help your tutors in understanding theflow of your implementation and marking. So, if your code does not generate any log files, you willonly be graded out of 25% of the marks.The Sender should not print any output to the terminal. If you are printing output to the terminal fordebugging purposes, make sure you disable it prior to submission.4.6 ReceiverThe Receiver should accept the following two arguments:1. receiver_port: the port number on which the Receiver will open a UDP socket forreceiving datagrams from the Sender.2. FileReceived.txt: the Name of the text file into which the text sent by the sendershould be stored (this is the file that is being transferred from sender to receiver).The Receiver should be initiated as follows:If you use Java:java Receiver receiver_port FileReceived.txtIf you use C:./receiver receiver_port FileReceived.txtIf you use Python:python receiver.py receiver_port FileReceived.txtNote that, you should first start the Receiver before initiating the Sender.The Receiver should generate an ACK immediately after receiving a data segment. This is the onlyACK generation rule you need. You do not need to follow Table 3.2 of the text. In other words, youmust not implement delayed ACKs. The format of the acknowledgement segment must be exactlysimilar to the PTP data segment. It should however not contain any payload.The receiver is expected to buffer out-of-order arrival segments.The receiver should first open a UDP listening socket on receiver_port and then wait forsegments to arrive from the Sender. The first segment to be sent by the Sender is a SYN segmentand the receiver is expected to reply a SYNACK segment.After the completion of the three-way handshake, the receiver should create a new text file calledFileReceived.txt. You may assume that the receiver program will have permission to create8files in its current working directory. All incoming data should be stored in this file. The Receivershould first extract the PTP segment from the arriving UDP datagrams and then extract the data(i.e., payload) from the PTP segment. Note that, the Receiver should examine the header of theUDP datagram that encapsulates the PTP segment to determine the UDP port and IP address thatthe Sender is using. This information is needed to send the ACK segment to the Sender. The ACKshould be encapsulated in an UDP datagram and sent to the Sender.The data should be written into FileReceived.txt. At the end of the transfer, the Receivershould have a duplicate of the text file sent by the Sender. You can verify this by using the diffcommand on a Linux machine (diff FileReceived.txt FileToSend.txt). Whentesting your program, if you have the Sender and Receiver executing in the same working directorythen make sure that the file name provided as the argument to the Receiver is different from the filename used by the sender.The Receiver should also maintain a log file titled Receiver_log.txt where it records theinformation about each segment that it sends and receives. The format should be exactly similar tothe sender log file as outlined in the Sender specification tab separated fields.The Receiver should terminate after the connection closure procedure initiated by the senderconcludes. The Receiver should also print the following statistics at the end of the log file (i.e.,Receiver_log.txt): Amount of (original) Data Received (in bytes) do not include retransmitted data Number of (original) Data Segments Received Number of duplicate segments received (if any)NOTE: Generation of this log file is very important. It will help your tutors in understanding theflow of your implementation and marking. So, if your code does not generate any log files, you willonly be graded out of 25% of the marks.The Receiver should not print any output to the terminal. If you are printing output to the terminalfor debugging purposes, make sure you disable it prior to submission.4.7 Overall structureThe overall structure of your protocol is depicted in Figure 2. The PL module is only at the Sender.Figure 2: The overall structure of your assignmentTransmit ACK packetFileToSend.txtread file and createPTP segment(s)PTP segment Start/Stop/Check timerTimeoutUDP socket UDP socket create and transmit UDP datagramreceive UDP datagramFileReceived.txtWrite text into filePTP segmentSender ReceiverACK packet PL module PTP protocol PTP protocol 9Receiver DesignThe Receiver program logic is straightforward. Upon receive of a UDP segment through the socket,the Receiver should extract the PTP segment which is encapsulated within the UDP segment. Itshould then execute the PTP protocol logic (outlined in Section 4.6 of the spec). This includes theconnection setup, data transmission and finally connection teardown. During the data transmissionphase an ACK segment should be generated for each received PTP segment. Each PTP segmentsent by the Receiver must be encapsulated in a UDP datagram and sent to the Sender. The Receivermay have to buffer the PTP segment (if out of order) or else write the data contained in the PTPsegment to the file.To summarise, the key steps are:1. Connection setup2. Data Transmission (repeat until end of file)a. Receive PTP segmentb. Send ACK segmentc. Buffer data or write data into file3. Connection teardownSender DesignThe Sender program logic is a little more complicated. The Sender must first execute connectionsetup, followed by data transmission and finally correction teardown. During data transmission, theSender should transmit a number of PTP segments (based on the MWS and MSS), all of whichneed to be buffered (in case of retransmissions) and wait for the corresponding ACKs. A timershould be started for the oldest unacknowledged segment. Each data segment should also be passedthrough the PL module which determines if the segment should be dropped or forwarded. Each PTPsegment to be transmitted must be encapsulated in a UDP datagram and sent to the Receiver. TheSender should also process incoming ACK segments from the Receiver. In the case of a timeout,the Sender should transmit the Oldest unacknowledged segment. Given the complexity and the needto deal with multiple events, there are two options you may consider for the design of the Sender:(i) using multiple threads to manage the various events (ii) non-blocking or asynchronous I/O byusing polling, i.e., select().To summarise, the key steps are:1. Connection setup2. Data Transmission (repeat until end of file)a. Read fileb. Create PTP segmentc. Start Timer if required (retransmit oldest unacknowledged segment on expiry)d. Send PTP segment to PL modulee. If PTP segment is not dropped, transmit to Receiverf. Process ACK if received3. Connection teardown6. Additional Notes This is NOT group assignment. You are expected to work on this individually. Tips on getting started: The best way to tackle a complex implementation task is to do it instages. A good starting point is to implement the file transfer using the simpler stop-and-waitprotocol (version rdt3.0 from the textbook and lectures). First, make sure that your programworks without implementing the PL module. Next, implement the packet drop functionality ofthe PL and test your protocol. Once you can verify that this works, extend your code to handletransmission of a window of packets (i.e., MWS). Send a window of packets and wait for all10acknowledgements to come back before sending another window worth of data. As before, testthe no loss case first. Then, extend your program to handle packet losses. Once you have thecomplete PTP protocol implemented run comprehensive tests to ensure that your programworks correctly. It is imperative that you rigorously test your code to ensure that all possible(and logical) interactions can be correctly executed. Test, test and test. You are free to design your own format and data structure for the messages. Just make sure yourprogram handles these messages appropriately. Backup and Versioning: We strongly recommend you to back-up your programs frequently.CSE backups all user accounts nightly. If you are developing code on your personal machine, itis strongly recommended that you undertake daily backups. We also recommend using a goodversioning system so that you can roll back and recover from any inadvertent changes. Thereare many services available for this, which are easy to use. We will NOT entertain any requestsfor special consideration due to issues related to computer failure, lost files, etc. Language and Platform: You are free to use C, JAVA or Python to implement thisassignment. Please choose a language that you are comfortable with. The programs will betested on CSE Linux machines. So please make sure that your entire application runs correctlyon these machines (i.e., your lab computers) or using VLAB. This is especially important if youplan to develop and test the programs on your personal computers (which may possibly use adifferent OS or version or IDE). Note that CSE machines support the following: gcc version8.2, Java 11, Python 2.7 and 3.7. If you are using Python, please clearly mention in yourreport which version of Python we should use to test your code. You may only use the basicsocket programming APIs providing in your programming language of choice. You may not useany special ready-to-use libraries or APIs that implement certain functions of the spec for you. You are encouraged to use the course discussion forum to ask questions and to discuss differentapproaches to solve the problem. However, you should not post your solution or any codefragments on the forum. We will arrange for additional consultations in Weeks 7-10 to assist you with assignmentrelated questions. Information about the consults will be announced via the website.7. Assignment SubmissionPlease ensure that you use the mandated file name. You may of course have additional header filesand/or helper files. If you are using C, then you MUST submi”
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。