▼IK2215 Programming Assignment
1.Introduction
Programming assignment overview2023-09-07 2Design and implement a reliable protocol for sending/receiving datagramsGuaranteed UDP (GUDP)Enabling reliable transport over UDPAutomatic repeat request (ARQ) uses acknowledgements and timeoutsfor reliable transmissionSliding window flow control multiple packets in flightAsynchronous communication Unlike TCP, GUDP is not connection-oriented(no connection establishment)GUDPApplicationUDPIP NetworkTransportApplicationSliding window flow control2023-09-07 3Sender ReceiverACK4P0Window (size 3)
5 6 7ACK2ACK3Go-Back-N Sliding Window Protocol2023-09-07 4Understand the details of a basic, sliding window protocolAn ACK is an ACK (and not a NACK)The receiver sends an ACK only if it receives the next packet in sequenceYou cannot use an ACK to tell the sender that a packet has been lostNo duplicate ACK detectionThe sender increases the window in accordance with the ACKRetransmissions are triggered by timeouts (and nothing else)Receiving an ACK with unexpected sequence number does not trigger aretransmission There is an exception case, which we will discuss in the next slide2023-09-07 5The receiver sends an ACK only if itreceives the next packet in sequenceA deadlock occurs when all ACKs(= number of window size) were lostTo resolve this problem:Receiver must send ACK with the expectedsequence number when it receives apacket with a lower sequence number thanthe expected sequence numberSender upon receiving an ACK canassume all packets with (ACK sequencenumber - 1) were received successfullyException caseSender ReceiverTimeout!Send deadlock!Window (size 3)GUDP implementation in java2023-09-07 6GUDP runs in user space, in the same process as the applicationWe provide:GUDPPacket.java: A class for GUDP protocol declarations withassociated methods to access the GUDP packet header and payloadGUDPSocketAPI.java: Well-defined API (Application ProgrammingInterface) that you must use for your implementationGUDPEndPoint.java (optional): A class for keeping track of an end pointYour main task is to implement GUDP as a java class: GUDPSocket.javaUDP Application UDP GUDP ApplicationSliding window flow controlARQYou are not allowed to modified these files!GUDP header2023-09-07 7Version: version of the RUDP protocolWe use version 1!Type: packet typeBSN, DATA, ACK, and FINHow to use sequence numbers:BSN packets: randomDATA packets: increases by one for each packet sentACK packets: sequence number of next expected DATA packetFIN packets: sequence number of last DATA packet plus one
GUDPSocketAPI.java API you must use2023-09-07 8Your code must conform to this APIClass/method declarations defined for the assignmentYou will write the GUDPSocket class that implements this APIYou may add variables, methods, and inner classes in GUDPSocket.javaimport java.net.DatagramPacket;import java.io.IOException;public interface GUDPSocketAPI { public void send(DatagramPacket packet) throws IOException; public void receive(DatagramPacket packet) throws IOException; public void finish() throws IOException; public void close() throws IOException;}GUDPSocket.java skeleton code for you2023-09-07 9import java.net.DatagramPacket;import java.net.DatagramSocket;import java.io.IOException;public class GUDPSocket implements GUDPSocketAPI { DatagramSocket datagramSocket; public GUDPSocket(DatagramSocket socket) { datagramSocket = socket; } public void send(DatagramPacket packet) throws IOException { } public void receive(DatagramPacket packet) throws IOException { } public void finish() throws IOException { } public void close() throws IOException { }}send()2023-09-07 10Send a packetThe application put packet in the DatagramPacket formatThe destination address/port included in the packetNon-blocking returns immediatelyGDUP queue packet for future deliverypublic void send(DatagramPacket packet) throws IOException;receive()2023-09-07 11Receive a packetThe application fetch a packet from GUDP if there is one, otherwise waituntil a packet arrivesThe application handles packets from different senders (which can bedifferentiated based on the information in the packet)public void receive(DatagramPacket packet) throws IOException;finish()2023-09-07 12Finish sendingThe application calls this method to inform GUDP that it done sendingGUDP completes the actual sending and return when it is done, otherwisereport error/timeout by throwing the IOExceptionRetransmission may occur due to packet lost or arriving out-of-orderYou may clean up data structure that you use to track destination end pointspublic void finish() throws IOException;close()2023-09-07 13Close the GUDP socketThe application calls this method to terminate the GUDP socketGUDP cleans up, closes the socket, and return.public void close() throws IOException;GUDP sender side2023-09-07 14Data transfer may happen after the application passed all packets to GUDPGUDP can send multiple packets (<= window size) before it receives any ACKsend(packet)Application GUDP NetworkGUDP ACKGUDP BSNGUDP DATAGUDP DATAGUDP ACKsend(packet)finish()finish() returnGUDP ACKGUDP receiver side2023-09-07 15Receive returns only after GUDP has DATAReceiver may keep socket open to receive more DATAreceive(packet)Application GUDP NetworkGUDP DATAGUDP ACKGUDP ACKreceive(packet)GUDP BSNGUDP DATAGUDP ACKreceive(packet) returnreceive(packet) return2023-09-07 16An application can open multipleGUDP socketsEach GUDP socket can be used forcommunication with multiple peersTwo levels
2. Multiple GUDP sockets
Multiple peers per socketNeed toMaintain state for per-socket、
Have a way to look up peer stateMaintain queues with outboundpacketsProtocol control blockProgramApplicationRUDPSocket SocketPeersGrading overview2023-09-07 17The application should be able to:Send one or more files to one or more destinationsReceive multiple files from one or more sourcesHandle unexpected situations gracefullyWork with other implementationsTo pass, you must meet two criteria below:1. Application must be able to send and receive one file on one destinationGUDP must be used in data transmission (show on the wire correctly)Sliding window flow control is working correctly (multiple packets in-flight)ARQ mechanism is working correctly (handle packet loss correctly)2. And score at least
1 Oct at 17:00Plagiarism2023-09-07 18Plagiarism in practical work and computing code鈥淚t is important that students 鈥榙o their own workwhen they write computercode, when document an experiment, create a design or answer amathematical problem. If they do not do these activities themselves, yetclaim the results as their own, this is plagiarism.Students who, with unauthorized aids or otherwise attempt to mislead theexam or when a student's performance is otherwise to be assessed, maylead to disciplinary action. More information on KTH webpage about Cheating and plagiarismGrading test cases2023-09-07 191. Multiple packets in-flight (0.5p)2. Send and receive files with your code without loss (0.5p)3. Send one file to other receiver without loss (0.5p)4. Send one file to other receiver with loss (0.5p)5. Receive one file from other sender without loss (0.5p)6. Receive one file from other sender with loss (0.5p)7. Send one file to multiple receivers without loss (0.5p)8. Send one file to multiple receivers with loss (0.5p)9. Send multiple files to other receiver without loss (0.5p)10. Send multiple files to other receiver with loss (0.5p)11. Receive multiple files from other sender without loss (0.5p)12. Receive multiple files from other sender with loss 3 pointsTesting2023-09-07 20We provide sample applications that you can use to test your GUDP codeVSFtp.java: A class for a simple file transfer protocolVSSend.java: An application for sending files over VSFtpVSRecv.java: An application for receiving files over VSFtpYou are responsible for identifying relevant test cases and performing testsThink through the protocol carefully and know how it should work exactlyThink through the dynamic behaviour of the GUDP libraryWhat happens, and when?Define the protocol states and transitions<current state, event, action, new state>If you have question:Discussion forum: Q&A for lab activitiesQ&A sessions for verbal discussion or additional supportTest service http://ik2215.ssvl.kth.se2023-09-07 21You must provide:Your KTH account i.e., KTH email without theTH@SEpartYour GUDPSocket.java fileThe test runs at 00:00 everydaySlow: >
5 minutes per submissionResults send to provided KTH account2023-09-07 22### TEST6: receive one file from other sender with loss (0.5p)OK: Your code can receive one file when first BSN is lostOK: Your code can receive one file when first DATA is lostOK: Your code can receive one file when first FIN is lostOK: Your code can receive one file when first ACK is lostOK: Your code can receive one file with random lossTEST6: OK 0.5p### TEST7: send one file to multiple receivers without loss (0.5p)OK: Your code can send one file to multiple receiversTEST7: OK 0.5p### TEST8: send one file to multiple receivers with loss (0.5p)OK: Your code can send one file to multiple receiversTEST8: OK 0.5p### TEST9: send multiple files to other receiver without loss (0.5p)OK: Your code can send multiple files to other receiverTEST9: OK 0.5p### TEST10: send multiple files to other receiver with loss (0.5p)OK: Your code can send multiple files to other receiverTEST10: OK 0.5p### TEST11: receive multiple files from other sender without loss (0.5p)OK: Your code can receive one file from other senderTEST11: OK 0.5p### TEST12: receive multiple files from other sender with loss (0.5p)OK: Your code can receive one file from other senderTEST12: OK 0.5p##########IMPORTANT: You pass only if scores of TEST1-6 >=2.0 points.You get the scores only when you pass. Otherwise, you get
0 pointsRESULTS: PASSSCORE: 6.0##########OK: Code compiles without error.### TEST1: Check sender packet content (0.5p)OK: GUDP version must be 1OK: First packet is GUDP BSN (type 2)OK: Sequence number is random and not zero or oneOK: BSN packet contains only GUDP headerOK: GUDP version must be 1OK: Second packet is GUDP DATA (type 1)OK: Sequence number should be random and not zeroOK: Second packet has an increment sequence numberOK: data packet seems to contain GUDP header + payloadTEST1: OK 0.5p### TEST2: send and receive files with your code without loss (0.5p)OK: Your code can send and receive one fileOK: Your code can send and receive multiple filesTEST2: OK 0.5p### TEST3: send one file to other receiver without loss (0.5p)OK: Your code can send one file to other receiverTEST3: OK 0.5p### TEST4: send one file to other receiver with loss (0.5p)OK: Your code can send one file when first BSN is lostOK: Your code can send one file when first DATA is lostOK: Your code can send one file when first FIN is lostOK: Your code can send one file when first ACK is lostOK: Your code can send one file with random lossTEST4: OK 0.5p### TEST5: receive one file from other sender without loss (0.5p)OK: Your code can receive one file from other senderTEST5: OK 0.5pExample test outputSendQueueExample of send and receive implementation2023-09-07 23SENDApplication- Handle send end point- Wrap app data in GUDP- Put it in send queue- Take GUDP from send queue- Wrap it in UDP and send- Handle timeout/retransmissionsend() SendthreadNetworkNetworkreceivethread- Process GUDP packetBSN: Create receive end pointDATA: Update receive end point andput GUDP DATA in receive queueACK: Update send queue- FIN: Mark end pointforremovalReceiveQueuereceive()Pick up GUDP from input queueUnwrap GUDP to get app dataApplicationRECEIVEUseful resources2023-09-07 24Course book: 8th and 7th editionRead Chapter 3.4 through Chapter 3.4.3 Go-Back-N (GBN)TCP Operational Overview and the TCP Finite State Machine (FSM)Producer-consumer in Java:Baeldung, geeksforgeeksJava queue implementations: Oracle, Baeldung,geeksforgeeks,Java documentation for differentclasses:DatagramSocket, DatagramPacket,LinkedList, ArrayDequeJavawait() and notify() methods
WX:codehelp
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。