讲解:COMP3331/9331、Computer Networks、Java,C++,Python Statistics

COMP3331/9331 Computer Networks and ApplicationsAssignment for Term 1, 2019Individual AssignmentVersion 1.1Due: 26th April 2019Updates to the assignment, including any corrections and clarifications, will be postedon the course website (https://moodle.telt.unsw.edu.au/course/view.php?id=37585).Please make sure that you check the course website regularly for updates. You canpost questions in the assignment forum.1. Change Log1. Version 1.0 released on Feb 18, 2018.2. Goal and learning objectivesFor this assignment, you will be asked to implement a part of the peer-to-peer (P2P)protocol Circular DHT which is described in Section 2.6 of the text ComputerNetworking (6th ed) and would be discussed in the lecture. A primary requirement fora P2P application is that the peers form a connected network at all time. A complicationthat a P2P network must be able to deal with is that peers can join and leave thenetwork at any time. For example, if a peer leaves the network suddenly (because ithas crashed), then the remaining peers must try to keep a connected network withoutthis peer. It is therefore necessary to design P2P networks so that they can deal withthese complications. One such method has been described in Section 2.6 of the text,under the heading of Peer Churn for circular DHT. You will also learn how to implementreliable data transmission over UDP.2.1. Learning ObjectivesOn completing this assignment, you will gain sufficient expertise in the followingskills:1. Understanding of routing mechanism and connectivity maintenance in peerto-peersystems, and Circular DHT in particular.2. Socket programming for both UDP and TCP transport protocols.3. Protocol and message design for applications.4. Basic understanding of creating a reliable connection.3. BackgroundThe following is extracted from the Peer Churn section of the text:“In P2P systems, a peer can come or go without warning. Thus, when designing aDHT, we also must be concerned about maintaining the DHT overlay in the presenceof such peer churn. To get a big-picture understanding of how this could beaccomplished, let’s once again consider the DHT in Figure 2.27(a) [Reproduced hereas Figure 1]. To handle peer churn, we will now require each peer to track (that is,know the IP address of) its first and second successor; for example, peer 4 now tracksboth peer 5 and peer 8. We also require each peer to periodically verify that its twosuccessors are alive (for example, by periodically sending ping messages to them andasking for responses). Let’s now consider how DHT is maintained when a peerabruptly leaves. For example, suppose peer 5 in Figure 2.27(a)[Figure 1 in thisassignment spec] abruptly leaves. In this case, the two peers preceding the departedpeer (4 and 3) learn that 5 has departed, since it no longer responds to ping messages.Peers 4 and 3 thus need to update their successor state information. Let’s considerhow peer 4 updates its state:1. Peer 4 replaces its first successor (peer 5) with its second successor (peer 8).2. Peer 4 then asks its new first successor (peer 8) for the identifier and IPaddresses of its immediate successor (peer 10). Peer 4 then makes peer 10 itssecond successor.Having briefly addressed what has to be done when a peer leaves, let’s now considerwhat happens when a peer wants to join the DHT. Let’s say a peer with identifier 13wants to join the DHT, and at the time of joining, it only knows about peer 1’s existencein the DHT. Peer 13 would first send peer 1 a message, saying ”what will be peer 13’spredecessor and successor?” This message gets forwarded through the DHT until itreaches peer 12, who realises it will be peer 13’s predecessor and its currentsuccessor, peer 15, will become its successor. Next, peer 12 sends this predecessorand successor information to peer 13. Peer 13 can now join the DHT by making peer15 its successor and by notifying peer 12 that it should be its immediate successor topeer 13.Figure 1. DHT configuration.4. Assignment descriptionFor this assignment, you are asked to write a Java, C, or Python program which canhandle query/response and peer churn (leaving only) for circular DHT as described inSection 3. However, there are a few important points that you need to note:1. You will be running each peer in an xterm on one machine. Therefore, trackinga peer no longer means knowing the IP address but in your case, it meansknowing the port numbers (we will further elaborate on this point later).2. You will not be able to use built in ping in OS to determine whether the twosuccessors of a peer are still alive. You will need to implement your own pingmechanism.Please make sure that your P2P program is working in the CSE laboratory as wewill test (and mark) your assignment using CSE machines.If your program does not work on CSE machine, you will get ‘0’ mark forassignment as we cannot accept running the code on your own machine.In the following description, we will continue to use the example in Figure 1, but a veryimportant point that you need to note is that: you should not make any assumptionregarding the number of peers and their identities in your program. The number ofpeers and their identities to be used for the evaluation can change from student tostudent. You should therefore make sure that you test that your program can deal withthe general situation. You can assume that there would be no more than 10 peers andthe peer identities is within the range of 0-255.There are a number of mandatory requirements:1. You must name your program cdht.c, cdht.java, or cdht.py.2. This program uses 5 input arguments. The first three input arguments are allintegers in the range of [0,255]. The fourth input is an integer value. And thefinal input is a value in the range of [0,1]. They are used to initialise the networkas discussed in section 4.1 (initialization step).3. For python programs, please indicate the version of python you used clearly inthe first lines of your report.4. For c programs, please include makefile with your submission and explain theprocess for making the file in your report. You must also show this on yourdemo.4.1. Assignment specificationIn this section, we will discuss the steps that you must take to implement thisassignment. Make sure your program covers all these steps to get full mark. Themarking guideline is discussed in section 7.Step 1: InitializationThe main aim of this step is to initialize the DHT. For the example in Figure 1, whichhas 8 peers, 8 xterms will be open to initialise 8 peers. This step will be performed byusing a set-up script, of which the following is an example:This script opens up 8 xterms and starts a peer in each xterm. The -e option asks thexterm to execute the command specified after the switch (For meaning of the otherxterm options, please use man xterm).In order to understand what the input arguments represent, let us look at the first linemore closely. The executable part of this line is “java cdht 1 3 4 400 0.1”.The first input argument, i.e., 1” is the identity of the peer to be initialised. The secondand third arguments, i.e., 3 and 4, are the identities of the two successive peers. Theforth argument is Maximum Segment Size (MSS) used to determine the size of thedata that must be transferred in each segment (discussed more in Step 3). MSS inthis example is set to 400. The last argument is the drop probability which must bebetween 0-1 (discussed more in Step 3). You will find that the above file initialises theconfiguration of the circular DHT given in Figure 1. The above configuration file isavailable from the assignment website. There are also C and Python versions.Given the above set-up script, each peer will know its identity and the identities of itstwo successors. There are a few assumptions that you can safely assume:1. We will ask you to work with at most 10 peers.2. The minimum number of peers is 4.3. The identity of a peer is always in the range of [0,255].4. The set-up script that we give you will always correctly describe a circularDHT.You can always create more set-up scripts for testing. Although for the demo (seeSection 5) you will run your code with the above configuration, but we will also testyour code with another configuration that we have to ensure that you did not hardcodeanything in the program. You would not know that configuration, but the configurationwill follow the above rules. Thus, make sure you test your code with differentconfigurations.Step 2: Ping successorsAfter initialisation, each peer will start pinging its two successors to see whether theyare alive. The ping mechanism should define two types of messages: 1) ping request,and 2) ping response. The ping messages should use UDP protocol. You can assumethat a peer whose identity is i will listen to the UDP port 50000 + i for ping messages.For example, peers 4 and 12 will listen on UDP ports 50004 and 50012 respectivelyfor ping request messages. Each peer should output a line to the terminal when a pingrequest message is received from any of its two predecessors. For example, peer 10is expected to receive ping request messages from peers 5 and 8; when peer 10receives a ping request message from peer 5, it should output the following line to theterminal:A ping request message was received from Peer 5.Similarly, if peer 10 receives a ping request message from peer 8, it should output thefollowing line to the terminal:A ping request message was received from Peer 8.The numbers ”5” and ”8” are correct for this example, your program is of courseexpected to print the correct identities for the situation.NOTE: Printing ping messages to the terminal is highly important as the evaluator willmark you according to the outputs. So, if no output is printed, the evaluator will assumethat the ping was unsuccessful. Even if you implement the ping correctly but there isno output, you will get 10% of the mark for that part (see Section 7).Since the title of each xterm displays the identity of each peer, you should be able tokeep track of each peer. When a peer receives a ping request message from anotherpeer, it should send a ping response message to the sending peer so that the sendingpeer knows that the receiving peer is alive. When a peer receives a ping responsefrom another peer, it should display on the terminal. For example, if peer 10 is stillalive, peer 5 is expected to receive a ping response message from peer 10, and peer5 should display:A ping response message was received from Peer 10.It is important to note that the messages displayed in the terminal should differentiatebetween ping request and ping response messages.You will need to decide on how often you send the ping messages. You should notsend them very often, otherwise you may overwhelm the computer. Please don’t makethe evaluator waiting for more than 3 minutes before it shows the output. Otherwise itwill be assumed that the program does not work.Step 3: Requesting a fileAn application of DHT is distributed file storage. In this step, you will be using the P2Pnetwork that you have created to request for files. To request a file with filename Xfrom peer Y, the requester will type “request X” to the xterm of peer Y. Thus, yourprogram must be able to receive string inputs. Before describing what will beevaluated, we first specify the rules for filenames, hashing, file location and messages: Filename: You can assume all the filenames in this P2P system are four digitnumbers. Some examples of valid filename are 0000, 0159, 1890, etc.Filenames such as a912 and 32134 are invalid because the former contains anon-numeral character and the latter does not consist of exactly 4 numerals. Hash function: All the peers in the network use the same hash function. Notethat you need to implement a simple hash function, so you do not need to useconventional hash functions. The hash function will be applied to the filename.Given the filename format defined earlier, each filename is an integer in therange [0, 9999]. To compute the hash of a file, you must compute the remainderof the filename integer when it is divided by 256. This gives you a hash valueas an integer in [0,255]. For example, for the file with filename 2012, its integer equivalent is 2012 and the remainder when 2012 is divided by 256 is 220; thus,the hash of the file 2012 is 220.? File location: The location where a file is stored in a P2P network depends onthe hash of the file as well as the peers that are currently in the network. Therule is, for a file whose hash is n (where n is an integer in [0, 255]), the file willbe stored in the peer that is the closest successor of n. We will use the P2Pnetwork in figure 1 to illustrate this rule. If the hash values of three different filesare 6, 10 and 210, then they will be stored, respectively, in peers 8, 10 and 1. Request and response messages: If a peer wants to request for a file, the peer(which we will call the requesting peer) will send a file request message to itssuccessor. The file request message will be passed round the P2P networkuntil it reaches the peer that has the file (which we will call the responding peer).The responding peer will send a response message directly to the requestingpeer. We require both these messages, i.e., file request and response, to besent over TCP. You can assume that a peer whose identity is i will listen to theTCP port 50000 + i for these messages. Transfer the file: The responding peer has to transfer a file to the requestingpeer over UDP connection. Unlike ping packets, the file has to be sent directlyto the requesting peer. Recall that UDP is not reliable. You need to make theconnection reliable by implementing a simple protocol with stop-and-waitbehaviour. Recall that in stop-and-wait, the sender sends a data packet to thereceiver, and waits until it receives an acknowledgement, or a timeout happens.In case an ACK is received, the sender sends the next part of data, and if atimeout occurs, the sender re-transmits the data. Note that, this will be a verysimple reliable connection which only deals with packet lost. The respondingpeer forms packet with MSS bytes of data. Then, it has to add the sequencenumber, acknowledge number, and MSS, and encapsulate all as a packet. Thispacket will then be transmitted to the requesting peer. The responding peer willstart a timer for the packet which essentially is needed for timeout operation.Once the requesting peer received the data packet, it will generate acorresponding acknowledgement and send back to the responding peer. Onreceipt of the acknowledgement packet, the responding peer will transfer thenext MSS bytes of data. If the data packet gets lost, the requesting peer will nottransfer the acknowledgement (as no data is received) and thus the timeout willhappen in the responding peer. Recall that the responding peer maintains atimer for each data packet it sends. The timeout-interval is set to 1 seconds inthis assignment. If the responding peer does not receive an acknowledgementfor the sent packet within timeout-interval, it considers the packet to be lost, andthus have to re-transmit the packet.The responding and requesting peers must maintains a log file namedresponding_log.txt and requesting_log.txt where they record the informationabout each segment they send and receive. The format of the log file shall beas follow: WCOMP3331/9331作业代写、Computer Networks作业代做、Java,C++,Python程序语言作here =snd/rcv/drop/RTX. Snd = send, rcv= receive, drop= packetdropped, and RTX= retransmission. is the time since the start of the program.Note that we will test your program in a single machine, thus packet drop inUDP will be rare (if any). To test your program, the peers shall accept a drop_rate value as input which is the probability in which packets aredropped. Before delivering a packet to the socket to be sent to the requestingpeer (i.e., after setting the timeout and forming the packet), the respondingpeer creates a random number (between 0-1) and checks if the randomnumber is smaller than the drop probability. If yes, the responding peer willnot send the packet. The timer set by the responding peer will eventuallyreach the timeout-interval which in turns triggers packet re-transmission. Inlog file, you shall print the log corresponding to the drop packet when thepacket is dropped. Thus, the time difference between the dropped packet andthe retransmitted packet must be at least timeout-interval.Know let us describe the process you need to take for your demo. The illustration isbased on the network in figure 1. Use peer 8 as the requesting peer and the filename2012 as the filename. Place the PDF named 2012 in the same folder as the executionfiles are located. Type the string “request 2012” in the xterm for peer 8 to informpeer 8 to begin the file request process. Peer 8 should format a file request messageand forward it to its successor. Peer 8 should display in its xterm the following:File request message for 2012 has been sent to my successor.The successor to peer 8, which is peer 10, should decide whether it has the file. Thedecision should be negative in this case and peer 10 should then forward the filerequest message to its successor. Peer 10 should display:File 2012 is not stored here.File request message has been forwarded to my successor.The file request message will then be passed onto peer 10, 12 and then peer 15. Allthese peers should decide that they do not have the file and forward the file requestmessage to their respective successor. Peers 10, 12, and 15 are expected to display:File 2012 is not stored here.File request message has been forwarded to my successor.After peer 1 has received the file request message, it should decide that it has thefile 2012. Peer 1 will then format a response message and send it directly torequesting peer, which is peer 8. Peer 1 also must print that it starts sending the fileand when finished it must print that the transmission is finished. Peer 1 shoulddisplay:File 2012 is here.A response message, destined for peer 8, has been sent.We now start sending the file ………The file is sent.After peer 8 has received the response message from peer 1, it should display:Received a response message from peer 1, which has the file2012.We now start receiving the file ………The file is received. At the end of the data transition there should be a duplicate of the file in the directoryin which the codes are located. You must open the duplicate copy as well. You canname the copy of the file as “received_file.pdf”. You also need to show the log files.NOTE:1) Printing messages to the terminal and the log files are highly important as theevaluator will mark you according to the outputs. So, if no output is printed, theevaluator will assume that the file request was unsuccessful. Even if you implementthe request process correctly but there is no output, you will get 10% of the mark forthis part.2) Please check marking criteria in section 7 for more detailed discussion on how wewill require you to do the demo.Important note: In the above illustration, we have assumed that the requesting peer does nothave the file that it is requesting. For this assignment, you can safely assume that this is thecase. You can always assume that we will give you a requesting peer and filename combinationsuch that the requesting peer and the responding peer are different.Step 4: Peer departureIn this step, one of the peers depart from the network in a graceful manner, which in thisassignment means the peer informs its predecessors before it departs from the networks. Inorder to realise graceful departure, we ask each peer should monitor the standard input for theinput string “quit” (The other string that each peer should monitor is request followed by avalid filename, as in Step 3).For demo, consider that peer 10 departs from the network gracefully. Type the string quit(followed by carriage return) in the xterm for peer 10 to inform peer 10 to begin the departureoperation. Peer 10 should send a departure message to peers 5 and 8 to inform them that itwants to depart from the network (Note that peer 10 learns that its predecessors are peers 5 and8 from the ping request messages). Peer 10 will also inform peers 5 and 8 in the departuremessage that its successors are peers 12 and 15. We require that the departure messages are tobe sent over TCP. You can assume that a peer whose identity is i will listen to the TCP port50000 + i for these messages. After peer 10 has sent the departure message to peers 5 and 8, itshould make sure that peers 5 and 8 have received the message before terminating the cdhtprogram.After peer 8 has received the departure message from peer 10, it should output the line to theterminal:Peer 10 will depart from the network.Since peer 10 is to depart, peer 8 will then make peer 12 its first successor and peer 15 itssecond successor. Note that peer 8 deduce the identities of its new successors from thedeparture message from peer 10. Peer 8 will output the lines:My first successor is now peer 12.My second successor is now peer 15.The above describes what peer 8 should do. In a similar way, peer 5 should output these linesto the terminal:Peer 10 will depart from the network.My first successor is now peer 8.My second successor is now peer 12.Note that for correct implementation, after peers 5 and 8 have updated their successors, theyshould start pinging their new successors. Ping messages will be used to confirm this.NOTE: Printing messages to the terminal is highly important as the evaluator will markyou according to the outputs. So, if no output is printed, the evaluator will assume thatthe file request was unsuccessful. Even if you implement the departure processcorrectly but there is no output, you will get 10% of the final mark for this part.Step 5: Kill a peerIn this step, you need to select one of the xterms and kill it (by pressing Ctrl + C in the xterm).This is to mimic the event of a peer leaving the network ungracefully. Kill the terminal in whichpeer 5 is running. After some time (depending on how often ping messages are sent), peers 3and 4 should find out that peer 5 is no longer there. Peer 4 should output the line to the terminal:Peer 5 is no longer alive.We will come back to explain how you can determine whether a peer is alive shortly. Sincepeer 5 is no longer alive, peer 4 will then make peer 8 its first successor. It will output the line:My first successor is now peer 8.Peer 4 will then send a message to peer 8 to find out the identity of the first successor of peer8. We require this message to be sent over TCP. You can assume that a peer whose identity isi will listen to the TCP port 50000+i for these messages. Peer 8 should reply to peer 4’s queryand let peer 4 knows that its successor is peer 12 (Note that peer 10 has departed from thenetwork gracefully earlier). After peer 4 receives this message, it should output the line:My second successor is now peer 12.The above describes what peer 3 should do. In a similar way, peer 3 should output these linesto the terminal:Peer 5 is no longer alive.My first successor is now peer 4.My second successor is now peer 8.Note that for correct implementation, after peers 3 and 4 have updated their successors, theyshould start pinging their new successors. The ping messages would be evaluated for this aim.Let us now return to explain how a peer can know whether its successors are alive. You candetermine this by using ping messages and it is important that you include a sequence numberfield in the ping messages. Let us assume that you have decided to have the peers ping eachother every t seconds. Let us consider what happens when peer 4 pings peer 5. Peer 4 will sendpeer 5 a ping request message every t seconds. The first ping request message will havesequence number 0, the next one has sequence number 1, the one after will have a sequence number 2 and so on. When peer 5 receives a ping request message from peer 4 with sequencenumber n, it will formulate a ping response message and includes the same sequence numbern in the ping response message. In this way, peer 4 knows that peer 5 has received the pingrequest message with sequence number n. Of course, a peer can only respond to a ping requestmessage if it is still alive. Let us assume that peer 4 sends 16 messages to peer 5 with sequencenumbers 0 to 15. Peer 5 sends ping responses for the first 12 ping request messages (withsequence numbers 0-11) but after that peer 5 fails to respond because it has been killed. Frompeer 4’s perspective, it knows that peer 5 has not given any replies to the last four consecutivemessages (with sequence numbers 12-15), it may use this property that peer 5 has notresponded to the last 4 messages to claim that peer 5 is no longer alive. Note that this examplehas assumed that a peer will declare that a successor is not alive if 4 consecutive ping messagesare not replied, you will need to experiment to find out what a good number is. You should beaware that UDP does not provide guaranteed delivery, therefore there is a chance that UDPmessages may be lost. Therefore, it is not a good idea to declare a peer is not alive if one pingrequest message is not responded because the message could have been lost in transit. Notethat there are three parameters that you will need to decide. The first parameter is the numberof consecutive ping request messages that a peer fails to respond to before that node is declaredto be no longer alive. The second parameter is the frequency of the ping messages. The thirdparameter, which is generally called timeout in computer networking literature, is the time thata peer needs to wait before declaring that a particular ping response has not been received.Please don’t make the evaluator wait for more than 3 minutes for your program to detect a nodehas been killed.5. Mandatory Screencast DemoThe screencast demo must go through steps 2-5 outlined in section 4.1 (inclusive). You maydescribe your program during demo or just run the steps mentioned above. Demo is limited to5 minutes and longer demos are subjected to 50% penalty of the final mark (see Section 7).You must show your code during the screencast and you must log in to your CSE account whiledoing demo. We will test your program using CSE machines, thus, please make sure you runand demo your code on CSE machines. Failure to do this may result in failure of running yourcode on CSE machines and thus loosing significant part of mark. The evaluator will comparethe results shown in your demo with the results he/she gets from running your code on CSEmachines.Please upload your screencast on YouTube as unlisted video before the submitting andinclude the YouTube link in your report.Check the marking guide in section 7. Make sure that you show and do all the steps as outlinedin this marking guide. We will mark you according to the marking guide and if you fail to doany of the criteria, then you will lose mark for that (e.g., failure in showing that you used TCPor UDP for messages).You can use the following command in CSE machines to record the screen:avconv -f x11grab -r 10 -s 1920x1080 -i :0.0 -vcodec libx264 -threads 4 /tmp/screencap.aviImportant noteThe screencast is mandatory and is considered as demo for assignment 1. Without demo, youwill get maximum 10% of the final mark of the assignment with no exception.6. Additional Notes This is not a group assignment. You are expected to work on this individually. How to Start: Sample client and server programs you have done for Labs 2 and 3 canprepare you for this assignment. Also, you can use sample client-server programs inMoodle. Language and Platform: You are free to use either C, Python, or JAVA to implementthis assignment. Please choose a language that you are comfortable with. The programs will be tested on CSE Linux machines. So please make sure that yourentire application runs correctly on these machines (i.e., your lab computers). This isespecially important if you plan to develop and test the programs on your personalcomputers (which may possibly use a different OS or version). You are free to design your own format and data structure for the messages. Just makesure your program handles these messages appropriately. You are encouraged to use assignment forum to ask questions and to discuss differentapproaches to solve the problem. However, you should not post your solution nor anycode fragment on the forum. You must submit a maximum 3 pages report (named report.pdf) with your codes. Inreport, describe the steps you take to implement the program, design choices includingthe interval between pings and the number of lost packets before assuming a peer iskilled, and the message formats you used. If you have borrowed code, please indicatethat here with the source reference. If you are using python, include the version ofpython you are using in your report. Make sure you include the link to your demo.7. Marking PolicyYou should test your program rigorously before submitting your code. Note that you mustsubmit a demo of your work otherwise you will lose 90% of the final mark. Your code will bemarked using the following criteria:7.1. Ping successors (2 marks)7.1.1. Correct compilation of all the files: Compile your files during the Demo. Forlanguages that don’t need compiling files, simply run your code (part 1.3 below)and you will get the mark for this part (0.25 mark).7.1.2. Using UDP for ping messages: You must show the part of your code that provesthat you used UDP for ping (0.25 mark).7.1.3. Correct receiving of ping requests: Run all peers. Ping receive message mustbe shown in all peers with the correct ids (0.75 mark).7.1.4. Correct receiving of ping response: Ping response message must be shown inall peers with the correct ids (0.75 mark).7.2. Requesting a file (7.5 marks)7.2.1. Initializing and sending the file request to the successor: The requesting peermust initialize a packet and send it to its successor once “request x” is typed toits terminal (where x is the filename) (1.5 marks).7.2.2. Forwarding the request to the correct node that has the requested file: Theintermediate peers must show the proper message that they received andforwarded the request as per discussion in section 4.1. (1.5 marks).7.2.3. Sending the response directly to the requester using TCP: The requester mustprint that it sends the response to the requesting peer. No other node shouldreceive this message (and print anything). Show in your code that you usedirect messaging using TCP for this part (0.75 marks).7.2.4. File at the requesting peer is identical with the file sent by the responder peer(0.75)7.2.5. Stop-and-wait behavior (alternate send and receive), correct MSS (1.5 mark)7.2.6. Drop probability is correct (according to the drop_rate supplied as input) (0.75)7.2.7. Segments are transmitted after timeout (0.75)<转自:http://www.7daixie.com/2019042422487544.html

你可能感兴趣的:(讲解:COMP3331/9331、Computer Networks、Java,C++,Python Statistics)