Computer Networks-Project 3 Congestion Control Project3TA:FanJiachen07302010028@fudan.edu.cn ZhuZhu07302010096(@fudan.edu.cn Assigned: May 23, 2011 1 Overview In this assignment, you will implement a BitTorrent-like file transfer application. The application will run on top of UDP, and you will need to implement a reliability and congestion control protocol(similar to TCP) for the application The application will be able to simultaneously download different parts, called"chunks", of a file from different servers. Please remember to read the complete assignment handout more than once so that you know exactly what is being provided and what functionality you are expected to add The project consists of a mandatory component that will be used for grading, and an optional optimi=ation com- ponent. The group/groups whose application performs the fastest file transfers (by selecting good peers from whom to download, while still performing proper congestion control) will receive high score anp.T his is a group project and you MAY find AT MOST partners to work with. Of course, you can complete this project own 1.1 Help Sessions, Checkpoints and Deadlines The timeline for the project is below, including several checkpoints. To help you pace your work, remember that checkpoints represent a date by which you should easily have completed the required functionality. Given the timeline, you can see that this means you should get started now! The late policy is explained on the course website Date Description Assignment handed out. PLEASE START EARLY May 27 Checkpoint 1: WHOHAS flooding and IHAVE responses Checkpoint 2: Simple Chunk Download with stop-and-wait Checkpiont 3: Sliding window flow-control with reliability June 15 Checkpoint 4: Simple Congestion Avoidance, with cwnd= I after any loss June 19 Early bird deadline with 10 bonus points(full functionality) June 26 Late deadline with no penalty(also extra credit) by 23: 59 There are four mandatory checkpoints. Each checkpoint is worth 10 points
Computer Networks - Project 3 Congestion Control Project 3 TA: Fan Jiachen 07302010028@fudan.edu.cn Zhu Zhu 07302010096@fudan.edu.cn Assigned: May 23, 2011 1 Overview In this assignment, you will implement a BitTorrent-like file transfer application. The application will run on top of UDP, and you will need to implement a reliability and congestion control protocol (similar to TCP) for the application. The application will be able to simultaneously download different parts, called ―chunks‖, of a file from different servers. Please remember to read the complete assignment handout more than once so that you know exactly what is being provided and what functionality you are expected to add. The project consists of a mandatory component that will be used for grading, and an optional optimization component. The group/groups whose application performs the fastest file transfers (by selecting good peers from whom to download, while still performing proper congestion control) will receive high score. This is a group project and you MAY find AT MOST 2 partners to work with. Of course, you can complete this project on your own. 1.1 Help Sessions, Checkpoints and Deadlines The timeline for the project is below, including several checkpoints. To help you pace your work, remember that checkpoints represent a date by which you should easily have completed the required functionality. Given the timeline, you can see that this means you should get started now! The late policy is explained on the course website. Date Description May 23 Assignment handed out. PLEASE START EARLY! May 27 Checkpoint 1: WHOHAS flooding and IHAVE responses June 3 Checkpoint 2: Simple Chunk Download with stop-and-wait June 8 Checkpiont 3: Sliding window flow-control with reliability June 15 Checkpoint 4: Simple Congestion Avoidance, with cwnd = 1 after any loss June 19 Early bird deadline with 10 bonus points (full functionality) June 26 Late deadline with no penalty (also extra credit) by 23:59 There are four mandatory checkpoints. Each checkpoint is worth 10 points
Figure 1: Diagram of bittorrent chunking and torrents: Bittorrent takes a large file and breaks it down into separate chunks which can be downloaded from different"peers". Chunks are identified by a"hash-value" which is the result of computing a well-known hash function over the data in the chunk. When a client wants to download a file, it first grabs a"torrent"file, which contains all of the hash values for the desired data file. The torrent lets the client know what chunks to request from other peers in the network 2 Where to get help a big part of being a good programmer is learning how to be reso urceful during the development process. The first places to look for help are(1)carefully re-reading the assignment, (2) looking at the project 3 website for updates and the FAQ, (3)scanning previous bulletin board posts, and (4) googling any standard compiler or script error mes- ages. If you still have a question AFTER doing this, general questions should be posted to the class bulletin board, FDU SOFTWARE, we are happy to help. Welcome to the Multimedia and Networking Lab(Software Building Room108) to discuss the problems of this project 3 Project Outline During the course of this project, you will do the following Implement a BitTorrent-like protocol to search for peers and download/upload file parts. Implement flow control and congestion control mechanisms to ensure fair and efficient network utilization. Implement smart optimizations to get the best possible transfer time(extra credit) 4 Proiect specification 4.1 Background This project is loosely based on the BitTorrent Peer-to-Peer(P2P)file transfer protocol. In a traditional file transfer application, the client knows which server has the file, and sends a request to that specific server for the given file. In many P2P file transfer applications, the actual location of the file is unknown, and the file may be present at multiple locations. The client first sends a query to discover which of its many peers have the file it wants, and then retrieves the file from one or more of these peers While p2P services had already become commonplace, Bit Torrent introduced some new concepts that made it ally popular. Firstly BitTorrent splits the file into different"chunks". Each chunk can be downloaded independently of the others, and then the entire collection of chunks is reassembled into the file. In this assignment, you will be using a fixed-size chunk of 512 Kbytes Bit Torrent uses a central"tracker"that tracks which peers have which chunks of a file. a client begins a download by first obtaining a"torrent"file, which lists the information about each chunk of the file. a chunk is identified by the
Original File Chunks Hash( ) ".torrent" = Figure 1: Diagram of bittorrent chunking and torrents: Bittorrent takes a large file and breaks it down into separate chunks which can be downloaded from different ―peers‖. Chunks are identified by a ―hash-value‖, which is the result of computing a well-known hash function over the data in the chunk. When a client wants to download a file, it first grabs a ―torrent‖ file, which contains all of the hash values for the desired data file. The torrent lets the client know what chunks to request from other peers in the network. 2 Where to get help A big part of being a good programmer is learning how to be reso urceful during the development process. The first places to look for help are (1) carefully re-reading the assignment, (2) looking at the project 3 website for updates and the FAQ, (3) scanning previous bulletin board posts, and (4) googling any standard compiler or script error messages. If you still have a question AFTER doing this, general questions should be posted to the class bulletin board, FDU_SOFTWARE, we are happy to help.Welcome to the Multimedia and Networking Lab(Software Building Room108) to discuss the problems of this project. 3 Project Outline During the course of this project, you will do the following: • Implement a BitTorrent-like protocol to search for peers and download/upload file parts. • Implement flow control and congestion control mechanisms to ensure fair and efficient network utilization. • Implement smart optimizations to get the best possible transfer time (extra credit). 4 Project specification 4.1 Background This project is loosely based on the BitTorrent Peer-to-Peer (P2P) file transfer protocol. In a traditional file transfer application, the client knows which server has the file, and sends a request to that specific server for the given file. In many P2P file transfer applications, the actual location of the file is unknown, and the file may be present at multiple locations. The client first sends a query to discover which of its many peers have the file it wants, and then retrieves the file from one or more of these peers. While P2P services had already become commonplace, BitTorrent introduced some new concepts that made it really popular. Firstly BitTorrent splits the file into different ―chunks‖. Each chunk can be downloaded independently of the others, and then the entire collection of chunks is reassembled into the file. In this assignment, you will be using a fixed-size chunk of 512 Kbytes. BitTorrent uses a central ―tracker‖ that tracks which peers have which chunks of a file. A client begins a download by first obtaining a ―.torrent‖ file, which lists the information about each chunk of the file. A chunk is identified by the 2
cryptographic hash of its contents; after a client has downloaded a chunk, it must compute the cryptographic hash to determine whether it obtained the right chunk or not. See Figure 1 To download a particular chunk, the receiving peer obtains from the tracker a list of peers that contain the chunk, and then directly contacts one of those peers to begin the download. BitTorrent uses a "rarest-chunk-first heuristic where it tries to fetch the rarest chunk first. The peer can download/upload four different chunks in parallel YoucanreadmoreabouttheBittorrenTprotocoldetailsfromhttp://www.bittorrent.org/beps/bep\ 0003.html. Bram Cohen, its originator also wrote a paper on the design decisions behind Bit Torrent. The paper is availableathttp://www.bittorrent.org/bittorrentecon.p This project departs from real Bit Torrent in several ways Instead of implementing a tracker server, your peers will flood the network to find which peers have which chunks of a file. Each peer will know the identities of every other peer in the network; you do not have to o simplify set-up and testing, all file data is actually accessed from a single master data file". Peers are igured with a file to tell them what chunks from this file they"own"upon startup You do not have to implement BitTorrent 's incentive based mechanism to encourage good uploaders and dis- courage bad ones But the project adds one complexity: BitTorrent obtains chunks using TCP. Your application will obtain them using UDP, and you will have to implement congestion control and reliability. It is a good idea to review congestion control concepts, particularly TCP, from both lecture and the textbook(Peterson Davie Section 6.3) 4.2 Programming guidelines Your peer must be written in the C programming language, no C++ or STL is allowed. You must use UDP for all the communication for control and data transfer. Your code must compile and run correctly on andrew linux machines Refer to slides from past recitations on designing modular code, editing makefiles, using subversion, and debugging As with project 1, your implementation should be single-threaded For network programming, you are not allowed to use any custom socket classes, only the standard libsocket and csapp libraries. We will provide a hashing library, and you may use public code for basic data structures, but not any code performing higher-level functionality. These guidelines are similar to project 1, except that you may freely use any code from your project (even if you switched partners). However, all code you do not freshly write for this assignment must be clearly documented in the REAdMe 4.3 Provided files Your starter code includes: hups im pl- This file emulates a network topology using topo map(see Section 7 sha. [ch]-The SHA-1 hash generator input buffer. [ch]-Handle user input debug. [ch]-helpful utilities for debugging output bt-parse. [ch]-utilities for parsing commandline arguments peer c-A skeleton peer file. Handles some of the setup and processing for you nodes. map-provides the list of peers in the network topo. map-the hidden network topology used by hupsim pl. This should be interpreted only by the hupsim. pl, our code should not read this file. You may need to modify this file when using hupsim pl to test the conges avoidance part of your program
cryptographic hash of its contents; after a client has downloaded a chunk, it must compute the cryptographic hash to determine whether it obtained the right chunk or not. See Figure 1. To download a particular chunk, the receiving peer obtains from the tracker a list of peers that contain the chunk, and then directly contacts one of those peers to begin the download. BitTorrent uses a ―rarest-chunk-first‖ heuristic where it tries to fetch the rarest chunk first. The peer can download/upload four different chunks in parallel. You can read more about the BitTorrent protocol details from http://www.bittorrent.org/beps/bep\ 0003.html. Bram Cohen, its originator also wrote a paper on the design decisions behind BitTorrent. The paper is available at http://www.bittorrent.org/bittorrentecon.pdf. This project departs from real BitTorrent in several ways: • Instead of implementing a tracker server, your peers will flood the network to find which peers have which chunks of a file. Each peer will know the identities of every other peer in the network; you do not have to implement routing. • To simplify set-up and testing, all file data is actually accessed from a single ―master data file‖. Peers are configured with a file to tell them what chunks from this file they ―own‖ upon startup. • You do not have to implement BitTorrent‘s incentive based mechanism to encourage good uploaders and discourage bad ones. But the project adds one complexity: BitTorrent obtains chunks using TCP. Your application will obtain them using UDP, and you will have to implement congestion control and reliability. It is a good idea to review congestion control concepts, particularly TCP, from both lecture and the textbook (Peterson & Davie Section 6.3). 4.2 Programming Guidelines Your peer must be written in the C programming language, no C++ or STL is allowed. You must use UDP for all the communication for control and data transfer. Your code must compile and run correctly on andrew linux machines. Refer to slides from past recitations on designing modular code, editing makefiles, using subversion, and debugging. As with project 1, your implementation should be single-threaded. For network programming, you are not allowed to use any custom socket classes, only the standard libsocket and csapp libraries. We will provide a hashing library, and you may use public code for basic data structures, but not any code performing higher-level functionality. These guidelines are similar to project 1, except that you may freely use any code from your project1 (even if you switched partners). However, all code you do not freshly write for this assignment must be clearly documented in the README. 4.3 Provided Files Your starter code includes: • hupsim.pl - This file emulates a network topology using topo.map (see Section 7) • sha.[ch] - The SHA-1 hash generator • input buffer.[ch] - Handle user input • debug.[ch] - helpful utilities for debugging output • bt parse.[ch] - utilities for parsing commandline arguments. • peer.c - A skeleton peer file. Handles some of the setup and processing for you. • nodes.map - provides the list of peers in the network • topo.map - the hidden network topology used by hupsim.pl. This should be interpreted only by the hupsim.pl, your code should not read this file. You may need to modify this file when using hupsim.pl to test the congestion avoidance part of your program. 3
make-chunks-program to create new chunk files given an input file that contains chunk-id, hash pairs, useful for creating more larger flle download scenarios 4.4 Terminology master-data-file- The input file that contains alL the data in the network, All nodes will have access to this file, but a peer should only read the chunks that it"owns".A peer owns a chunk if the chunk id and hash was listed in that peer's has-chunk-file, or if the peer has already downloaded the chunk since starting up. The second case only applies if you choose to implement caching as extra credit master-chunk-file-A file that lists the chunk IDs and corresponding hashes for the chunks in the master data peer-list-file-A file containing list of all the peers in the network. For a sample of the peer-list-file, please look at nodes. map has-chunk-file- A per-node file containing list of chunks that a particular node has at startup. However, a peers will have access to more chunks as they download the chunks from other peers in the network get-chunk-file- A file containing the list of chunk ids and hashes a peer wants to download. This filename is provided by the user when requesting a new download max-downloads- The maximum number of simultaneous connections allowed in each direction( download peer-identity- The identity of the current peer. This should be used by the peer to get its hostname and port from peer-list-file debug- level The level of debug statements that should be printed out by DPRINtFo. For more information, please look at debug. [h, c] 4.5 How the file transfer works The code you write should produce an executable file named"peer". The command line options for the program are eer -p <peer-list-file> <has-chunk-file> -m <max-downloads> i <peer-identity>-f <master-chunk-file> -d <debug -level> ain The peer program listens on standard input for commands from the user. The only command is "GET <get-chunk- file> <output filename>. This instruction from the user should cause your program to open the specified chunks file and attempt to download all of the chunks listed in it (you can assume the file names contain no spaces). When your program finishes downloading the specified file, it should print"GOT <get-chunk-fle>"on a line by itself. You do not have to handle multiple concurrent file requests from the user. Our test code will not send another GEt command until the first has completed; you re welcome to do whatever you want internally. The format of different files are given in Section 4.7 To find hosts to download from, the requesting peer sends a"WHOHAS <list>request to all other peers, where <list> is the list of chunk hashes it wants to download. The list specifies the SHA-1 hashes of the chunks it to retrieve. The entire list may be too large to fit into a single UDP packet. You should assume the maximum size for UDP as 1500 bytes. The peer must split the list into multiple Whohas queries if the list is too large single packet. Chunk hashes have a fixed length of 20 bytes. If the file is too large, your client may send out the get equests iteratively, waiting for responses to a gET request's chunks to be downloaded before continuing. For better performance, your client should send these requests in parallel Upon receipt of a WHOHAs query, a peer sends back the list of chunks it contains using the" IHAVE <list> reply. The list again contains the list of hashes for chunks it has. Since the request was made to fit into one packet, the response is guaranteed to fit into a single packet
• make-chunks - program to create new chunk files given an input file that contains chunk-id, hash pairs, useful for creating more larger file download scenarios. 4.4 Terminology • master-data-file - The input file that contains ALL the data in the network. All nodes will have access to this file, but a peer should only read the chunks that it ―owns‖. A peer owns a chunk if the chunk id and hash was listed in that peer‘s has-chunk-file, or if the peer has already downloaded the chunk since starting up. The second case only applies if you choose to implement caching as extra credit. • master-chunk-file - A file that lists the chunk IDs and corresponding hashes for the chunks in the master data file. • peer-list-file - A file containing list of all the peers in the network. For a sample of the peer-list-file, please look at nodes.map. • has-chunk-file - A per-node file containing list of chunks that a particular node has at startup. However, a peers will have access to more chunks as they download the chunks from other peers in the network. • get-chunk-file - A file containing the list of chunk ids and hashes a peer wants to download. This filename is provided by the user when requesting a new download. • max-downloads - The maximum number of simultaneous connections allowed in each direction (download / upload) • peer-identity - The identity of the current peer. This should be used by the peer to get its hostname and port from peer-list-file • debug-level - The level of debug statements that should be printed out by DPRINTF(). For more information, please look at debug.[h,c]. 4.5 How the file transfer works The code you write should produce an executable file named ―peer‖. The command line options for the program are : peer -p <peer-list-file> -c <has-chunk-file> -m <max-downloads> -i <peer-identity> -f <master-chunk-file> -d <debug-level> The peer program listens on standard input for commands from the user. The only command is ―GET <get-chunkfile> <output filename>‖. This instruction from the user should cause your program t o open the specified chunks file and attempt to download all of the chunks listed in it (you can assume the file names contain no spaces). When your program finishes downloading the specified file, it should print ―GOT <get-chunk-file>‖ on a line by itself. You do not have to handle multiple concurrent file requests from the user. Our test code will not send another GET command until the first has completed; you‘re welcome to do whatever you want internally. The format of different files are given in Section 4.7. To find hosts to download from, the requesting peer sends a ―WHOHAS <list>‖ request to all other peers, where <list> is the list of chunk hashes it wants to download. The list specifies the SHA-1 hashes of the chunks it wants to retrieve. The entire list may be too large to fit into a single UDP packet. You should assume the maximum packet size for UDP as 1500 bytes. The peer must split the list into multiple WHOHAS queries if the list is too large for a single packet. Chunk hashes have a fixed length of 20 bytes. If the file is too large, your client may send out the GET requests iteratively, waiting for responses to a GET request‘s chunks to be downloaded before continuing. For better performance, your client should send these requests in parallel. Upon receipt of a WHOHAS query, a peer sends back the list of chunks it contains using the ―IHAVE <list>‖ reply. The list again contains the list of hashes for chunks it has. Since the request was made to fit into one packet, the response is guaranteed to fit into a single packet. 4
The requesting peer looks at all IHAVE replies and decides which remote peer to fetch each of the chunks from. It then downloads each chunk individually using"GET <chunk-hash>"requests. Because you are using UDP, you can think of a"GET request as combining the function of an application-layer"GET request and a the connection-setup function of a TCP SYN packet When a peer receives a gET request for a chunk it owns, it will send back multiple"DATA packets requesting peer(see format below)until the chunk specified in the gEt request has been completely tran These DATA packets are subject to congestion control, as outlined in Section 6. 2. The peer may not be able to satisfy the get request if it is already serving maximum number of other peers. The peer can ignore the request or queue them up or notify the requester about its inability to serve the particular request. Sending this notification is optional, and uses the DENIED code. Each peer can only have I simultaneous download from any other peer in the network, meaning that the IP address and port in the UdP packet will uniquely determine which download a Data packet belongs to. Each peer can however have parallel downloads(one each) from other peers When a peer receives a data packet it sends back an ACK packet to the sender to notify that it successfully eceived the packet Receivers should acknowledge all DATA packets 4.6 Packet formats All the communication between the peers use UDP as the underlying protocol. All packets begin with a common gic Number [2 bytes] sion Number [I byte] 3. Packet Type [I byte] 4. Header Length [2 bytes 5. Total Packet Length [2 bytes 6. Sequence Number [4 bytes] 7. Acknowledgment Number[4 bytes] Just like in the previous assignment, all multi-byte integer fields must be transmitted in network byte order(the magic number, the lengths, and the sequence/acknowledgment numbers ). Also, all integers must be unsigned The magic number should be 15441, and the version number should be 1. Peers should drop packets that do not have these values. The"Packet Type"field determines what kind of payload the peer should expect. The codes for different packet types are given in Table 1. By changing the header length, the peers can provide custom optimizations for all the packets (if you choose). Sequence number and Acknowledgment number are used for congestion control mechanisms similar to tcp as well as reliable transmission If you extend the header length, please begin your extended header with a two-byte extension ID" field set to your groups number, to ensure that you can interoperate cleanly with other people's clients Similarly, if your peer receives an extended header and the extension Id does not match your group number, just ignore the extensions The payload for both WHOHAS and IHAvE contain the number of chunk hashes(I byte), 3 bytes of empty padding space to keep the chunk 32-bit aligned, and the list of hashes(20 bytes each) in them. The format of the packet is shown in Figure 2(b). The payload of geT packet is even more simple: it contains only the chunk hash for the chunk the client wants to fetch(20 bytes) Figure 2(c)shows an example DATa packet. DATA and ACK packets do not have any payload format defined mally they should just contain file data. The sequence number and acknowledgment number fields in the header have meaning only in DATA and ACK packets. In this project the sequence numbers always start from I for a ne GET connection. A receiving peer should send an ACK packet with acknowledgment number 1 to acknowledge that is has received the data packet with sequence number I and so on. Even though there are both a sequence number and an acknowledgment number fields in the header, you should not combine DaTA and ACK packets Do not
The requesting peer looks at all IHAVE replies and decides which remote peer to fetch each of the chunks from. It then downloads each chunk individually using ―GET <chunk-hash>‖ requests. Because you are using UDP, you can think of a ―GET‖ request as combining the function of an application-layer ―GET‖ request and a the connection-setup function of a TCP SYN packet. When a peer receives a GET request for a chunk it owns, it will send back multiple ―DATA‖ packets to the requesting peer (see format below) until the chunk specified in the GET request has been completely transferred. These DATA packets are subject to congestion control, as outlined in Section 6.2. The peer may not be able to satisfy the GET request if it is already serving maximum number of other peers. The peer can ignore the request or queue them up or notify the requester about its inability to serve the particular request. Sending this notification is optional, and uses the DENIED code. Each peer can only have 1 simultaneous download from any other peer in the network, meaning that the IP address and port in the UDP packet will uniquely determine which download a DATA packet belongs to. Each peer can however have parallel downloads (one each) from other peers. When a peer receives a DATA packet it sends back an ACK packet to the sender to notify that it successfully received the packet. Receivers should acknowledge all DATA packets. 4.6 Packet Formats All the communication between the peers use UDP as the underlying protocol. All packets begin with a common header: 1. Magic Number [2 bytes] 2. Version Number [1 byte] 3. Packet Type [1 byte] 4. Header Length [2 bytes] 5. Total Packet Length [2 bytes] 6. Sequence Number [4 bytes] 7. Acknowledgment Number [4 bytes] Just like in the previous assignment, all multi-byte integer fields must be transmitted in network byte order (the magic number, the lengths, and the sequence/acknowledgment numbers). Also, all integers must be unsigned. The magic number should be 15441, and the version number should be 1. Peers should drop packets that do not have these values. The ―Packet Type‖ field determines what kind of payload the peer should expect. The codes for different packet types are given in Table 1. By changing the header length, the peers can provide custom optimizations for all the packets (if you choose). Sequence number and Acknowledgment number are used for congestion control mechanisms similar to TCP as well as reliable transmission. If you extend the header length, please begin your extended header with a two-byte ―extension ID‖ field set to your group‘s number, to ensure that you can interoperate cleanly with other people‘s clients. Similarly, if your peer receives an extended header and the extension ID does not match your group number, just ignore the extensions. The payload for both WHOHAS and IHAVE contain the number of chunk hashes (1 byte), 3 bytes of empty padding space to keep the chunk 32-bit aligned, and the list of hashes (20 bytes each) in them. The format of the packet is shown in Figure 2(b). The payload of GET packet is even more simple: it contains only the chunk hash for the chunk the client wants to fetch (20 bytes). Figure 2(c) shows an example DATA packet. DATA and ACK packets do not have any payload format defined; normally they should just contain file data. The sequence number and acknowledgment number fields in the header have meaning only in DATA and ACK packets. In this project the sequence numbers always start from 1 for a new ―GET connection‖. A receiving peer should send an ACK packet with acknowledgment number 1 to acknowledge that is has received the data packet with sequence number 1 and so on. Even though there are both a sequence number and an acknowledgment number fields in the header, you should not combine DATA and ACK packets. Do not use a 5