Sunteți pe pagina 1din 10

Mid-Term Exam for Computer Networks

Fall 2010

>>> SOLUTIONS <<<


Welcome to the Mid-Term Exam for Computer Networks. Read each problem carefully. There are eight required problems (each worth 12 points you get 4 points for correctly following these instructions). There is also an additional extra credit question worth 10 points. You may have with you a calculator, pencils and/or pens, erasers, blank paper, and one 8.5 x 11 inch formula sheet. On this formula sheet you may have anything you want (definitions, formulas, homework answers, old exam answers, etc.) as handwritten by you in pencil or ink on both sides of the sheet. Photocopies, scans, or computer generated and/or printed text are not allowed on this sheet. Note to tablet PC users you may not print-out your handwritten text for the formula sheet. You have 75 minutes for the exam. Please use a separate sheet of paper for the answer to each question. Good luck and be sure to show your work! Problem #1 Answer the following questions regarding the basics of computer networks and the Internet. a) What are the basics tasks of a communications system?
0.25 each and round-up (2 pts total) Message formatting, error detection and recovery, addressing, routing, flow control, system management, security, and QoS

b) What are the fundamental challenges to improve communications systems (hint: think about the fundamental measures of a communications system)?
0.25 each and round-up (2 pts total) Greater throughput, less delay, less loss, lower cost, more mobility, greater robustness, and better secrecy

c) Think about the OSI reference model and the 5-layer Internet reference model we are using in this class. Identify what is different between these two models (be more specific than just saying two layers!).
1 each layer noted (2 pts total) The key difference is that the 5-layer Internet model does not have the presentation and session layers found in the OSI model. Otherwise the models are essentially the same.

d) In the 5-layer Internet reference model which layers handle point-to-point functions and which layers handle end-to-end functions?
0.5 each and round-up (2 pts total) Note: Will accept layer 3 as point-to-point Layers 1 and 2 are point-to-point and layers 3 and 4 are end-to-end.

e) Is sockets a protocol or interface? Carefully explain why.


1 each for key point (2 pts total) An interface is a complete set of rules for information exchange between adjacent layers in a single site and this is the function that sockets provides as an applications programming interface (API) where the underlying protocol is TCP or UDP. So, sockets is an interface.

f) What problems do Information Theory and Coding Theory address? In what department are these areas typically studied.
1 each (2 pts total) Information theory deals with the channel itself to determine the maximum capacity of the channel. Coding theory is the study of coding techniques for the channel (to achieve high data rate approaching the maximum capacity). Information Theory and Coding Theory are usually studied in Electrical Engineering.

Problem #2 Answer the following general questions, each question requiring some simple calculation: a) Consider a 100 meter 100 Mb/s Ethernet link transporting 1500 byte frames. What is the transmission delay for a frame? What is the approximate propagation delay of this link? Which delay dominates for this link?
2 for each delay (4 pts total) A meter is roughly 3 feet. Signal propagates about 1 foot in 1 nanosecond, so the propagation delay is about 300 nanoseconds. The transmission delay is 12000 bits per frame divided by 10 million bits per second, which is 120 microseconds per frame. The transmission delay is about 3 orders of magnitude greater than the propagation delay.

b) Consider a buffer with 100 packets queued, each packet is 1500 bytes in length. The buffer is for an intermediate node with a 100 Mb/s egress (output) link with no throttling. How long will it take for all packets to be transmitted (that is, for the buffer to empty out)?
2 for each calculation (4 pts total) The transmission delay is 12000 bits per frame divided by 10 million bits per second, which is 120 microseconds per frame. The last frame in the queue must wait for 100 transmissions, so 100 x 120 microseconds is 12 milliseconds.

c) It is about 2500 miles to Seattle from here. Is the round-trip-time from here to Seattle and back (assuming no queueing delays) greater or less than the human perception threshold?
2 for each calculation (4 pts total) Signal propagates about 1 foot in 1 nanosecond, there are 5280 feet in a mile, so roughly 5 microseconds delay per mile. Thus, 5000 miles (2500 miles there and back) is about 25 milliseconds, this is less than the human delay threshold of about 100 milliseconds (so, the RTT from here to Seattle will appear instantaneous).

Problem #3 Answer the following questions regarding the Application Layer. a) An application layer protocol typically defines four things. What are these four things?
1 pt each (4 pts total) Types of messages, syntax of messages, semantics of messages, and timing (when and how).

b) What are ping and traceroute used for? Describe the output from each program.
2 each (4 pts total) Ping is used to determine the presence (liveliness) of a remote host and the RTT to this host. The output is host not found (if the host is not there) or a list of RTTs for each ping packet sent. Traceroute is used to determine the hops (by IP address) from a source to a destination. For each hop listed, three sample RTTs are reported.

c) What is a web cache used for (i.e., what benefits are derived from using a web cache)? Where can a web cache be located or placed?
2 pt each subquestion (4 pts total) A web cache may be used to reduce response time as experienced by a user, reduce load on a link, and/or reduce load on a web server. A web cache may be placed in the user client (e.g., within the browser application), at my network edge (we call this a proxy server), and/or at the edge of the network containing the server (we call this a transparent cache).

d) What is DNS and what is it used for? If all DNS servers could be crashed (taken offline), what would happen to the Internet (be precise).
2 pts each for DNS use and for what would happen (4 pts total) DNS is Domain Name Service and is used to associate host names (as in say, www.yahoo.com or christen@csee.usf.edu) with IP addresses. If all DNS servers were to be crashed one would be unable to use hostnames and could only use IP addresses when using Internet services.

Problem #4 Appendix A contains tcpClient.c with some bugs and Appendix B contains tcpServer.c with some bugs. Identify the bugs and explain how to fix them. Note that the programs compile and link successfully (using bcc32 in Windows, at least). The bugs are all quite major in scope and may be related and/or common between the two programs. Write your answer directly on the code listings (i.e., in Appendix A and B) of this exam handout.
1 each (12 pts total) The following are the bugs in tcpClient.c: #define IP_ADDR "grad.csee.usf.edu" is wrong (should be an IP address, not host name) client_s = socket(AF_INET, SOCK_DGRAM, 0); should contain SOCK_STREAMS if (client_s > 0) should be < The block of code to receive from the server must come after the connect retcode = send(server_s, out_buf, (strlen(out_buf) + 1), 0); must be to client_s (server_s makes no sense) The following are the bugs in tcpServer.c: welcome_s = socket(AF_INET, SOCK_DGRAM, 0); should contain SOCK_STREAMS if (welcome_s > 0) should be < bind() and error check for successful binding is missing after filling-in of server address information listen(connect_s, 1); must be listening on welcome_s connect_s = accept(connect_s, (struct sockaddr *)&client_addr, &addr_len); must accept for welcome_s and not itself retcode = send(welcome_s, out_buf, (strlen(out_buf) + 1), 0); must send on connect_s and not welcome_s retcode = recv(welcome_s, in_buf, sizeof(in_buf), 0); must send on connect_s and not welcome_s

Problem #5 Answer the following questions about the transport layer: a) What are the fundamental services provided by the transport layer? Very briefly, how does TCP implement each of these services.
1 pt each service and TCP implementation (6 pts total) The fundamental services are 1) multiplexing/demultiplexing, 2) reliable data transfer (assured delivery), and congestion control. TCP provides service (1) using port numbers, a port for each application, (2) by checksumming for error detection, time-outs for loss detections, and resend to recover from an error or loss, (3) by using a sliding windows and decreasing the window size on time-out (implicit detection of overflow packet loss).

b) There are two ways to terminate a TCP connection, what are they? What are the implications (that is, what happens) of each way?
1 pt each (2 pts total) The normal way to terminate a TCP connection is with a FIN/ACK sequence a two-way close with all sent bytes being delivered and ACKed. Another way to terminate a TCP connection is with a reset (RST flag set). In this case, any data in transit may not be fully delivered (i.e., may be lost unknown to the sender).

c) What are the goals of congestion control? List at last four key goals.
1 pt each (4 pts total)

Key goals include: minimize frame discard, maintain agreed-upon QoS, minimize possibility that on end user can monopolize, be simple to implement, create minimal additional traffic, and limit the spread of congestion.

Problem #6 Sketch the FSMs for the sender and receiver of RDT 1.0 from the textbook and lecture. RDT 1.0 is a reliable data transfer protocol where one assumes that there are no bit errors and no packet loss.
6 pts each need to show basic transitions (12 pts total)

SENDER ----+---| call | ------->| rdt_send(data) +----------------------------------+ | packet = make_pkt(data) | | udt_send(packet) | | | +<---------------------------------+ | Waits for a call from above (application layer)

RECEIVER ----+---| call | ------->| rdt_rcv(packet) +----------------------------------+ | extract(packet,data) | | deliver_data(data) | | | +<---------------------------------+ | Waits for a call from below (network layer) Problem #7 What window size (in bytes) would a TCP connection need to maintain 100% throughput for a connection from Earth to Mars. The distance from Earth to Mars is about 36 million miles in the best case (the exact distance depends on the relative orbital positions of the two planets and can be much more). Assume a link rate of 1 Mb/s and packet length of 1500 bytes. Can the window size you computed be used with the current TCP standard (why or why not)?
5 pts for set-up, 5 pts for calculation, 2 pts for use with TCP (12 pts total) The sliding window formula is U W t fr 2t pr t fr where we want U to be 1.0. We first compute t pr and t fr as follows. Light propagates about 1 foot in 1 nanosecond, so 1 mile is about 5 microseconds (5280 feet in a mile), and then 36 million miles would be about 180 seconds, to t pr 180 s . The transmit time is packet length divided by link rate, which is t fr 1500 8 1000000 0.012 s . The only unknown now is W, which we can solve for and we get W = 30001 packets. Each packet is 1500 bytes, so the windows size would be 45001500 bytes. The window

size file is 16 bits and 45001500 is great than 216 , thus this large window size could not be achieved using existing TCP.

Problem #8 Answer the following questions about the network layer. a) What are the two key functions of the network layer
1 each (2 pts total) Forwarding of packets and routing

b) What is the fundamental difference between virtual circuit and datagram service?
1 each (2 pts total) In a virtual circuit the path is set-up at connection establishment and all packets in a connection flow across this route, in datagram service each packet in a connection is routed indvidiually.

c) What are the criteria for a good routing algorithm? List at least four key criteria.
0.5 each and round-up (4 pts total) Key criteria are fast, simple, not generate much network traffic, not create loops, stable, and converges to an optimum solution.

d) Describe Dijkstras shortest path algorithm. Which routing protocol uses Dijkstras shortest path algorithm?
2 pts total To determine that shortest path from node A to node B in a connected graph add edges (hops) starting at A in order of least path cost from node A until node B is reached. This will be the lowest cost path. OSPF (also Ciscos IGRP) uses Dijkstras shortest path algorithm.

e) IP addresses are split into net_id and host_id. Why is this done?
2 pts (2 pts total) This is done to reduce the size of routing tables (routers have only to route by net_id).

Extra Credit In the ARP protocol the ARP request is broadcast and the ARP response is unicast (that is, sent directly and only to the sender of the ARP request). What might the advantages and disadvantages be of broadcasting the ARP response?
5 pts for each (10 pts total) Advantages: Allow all hosts on a subnet to learn about a given IP-MAC address relationship and enter it into their ARP cache. This may be useful for future use by a host (and the host will not need to send an ARP request because the desired IP-MAC is already in its ARP cache courtesy of another host). Thus, this may reduce ARP request traffic on the subnet. So, in short, less traffic. Disadvantage: The processing load on all hosts is now increased and many hosts may never need the IP-MAC address associations learned. So, in short, more processing at hosts.

Appendix A Program tcpClient.c with some bugs


<< SNIP SNIP header removed >> #define WIN // WIN for Winsock and BSD for BSD sockets

//----- Include files --------------------------------------------------------#include <stdio.h> // Needed for printf() #include <string.h> // Needed for memcpy() and strcpy() #ifdef WIN #include <windows.h> // Needed for all Winsock stuff #endif #ifdef BSD #include <sys/types.h> // Needed for sockets stuff #include <netinet/in.h> // Needed for sockets stuff #include <sys/socket.h> // Needed for sockets stuff #include <arpa/inet.h> // Needed for sockets stuff #include <fcntl.h> // Needed for sockets stuff #include <netdb.h> // Needed for sockets stuff #endif //----- Defines --------------------------------------------------------------#define PORT_NUM 1050 // Port number used at the server #define IP_ADDR "grad.csee.usf.edu" // IP address of server (HARDWIRED) //===== Main program ========================================================== void main(void) { #ifdef WIN WORD wVersionRequested = MAKEWORD(1,1); // Stuff for WSA functions WSADATA wsaData; // Stuff for WSA functions #endif int client_s; // Client socket descriptor int server_s; // Server socket descriptor struct sockaddr_in server_addr; // Server Internet address char out_buf[4096]; // Output buffer for data char in_buf[4096]; // Input buffer for data int retcode; // Return code #ifdef WIN // This stuff initializes winsock WSAStartup(wVersionRequested, &wsaData); #endif // Create a client socket // - AF_INET is Address Family Internet and SOCK_STREAM is streams client_s = socket(AF_INET, SOCK_DGRAM, 0); if (client_s > 0) { printf("*** ERROR - socket() failed \n"); exit(-1); } // Receive from the server retcode = recv(client_s, in_buf, sizeof(in_buf), 0); if (retcode < 0) { printf("*** ERROR - recv() failed \n"); exit(-1); }

// Fill-in the server's address information and do a connect with the // listening server using the client socket - the connect() will block. server_addr.sin_family = AF_INET; // Address family to use server_addr.sin_port = htons(PORT_NUM); // Port num to use server_addr.sin_addr.s_addr = inet_addr(IP_ADDR); // IP address to use retcode = connect(client_s, (struct sockaddr *)&server_addr, sizeof(server_addr)); if (retcode < 0) { printf("*** ERROR - connect() failed \n"); exit(-1); } // Output the received message printf("Received from server: %s \n", in_buf); // Send to the server strcpy(out_buf, "This is a reply message from CLIENT to SERVER"); retcode = send(server_s, out_buf, (strlen(out_buf) + 1), 0); if (retcode < 0) { printf("*** ERROR - send() failed \n"); exit(-1); } // Close the client socket #ifdef WIN retcode = closesocket(client_s); if (retcode < 0) { printf("*** ERROR - closesocket() failed \n"); exit(-1); } #endif #ifdef BSD retcode = close(client_s); if (retcode < 0) { printf("*** ERROR - close() failed \n"); exit(-1); } #endif #ifdef WIN // Clean-up winsock WSACleanup(); #endif }

Appendix B Program tcpServer.c with some bugs


<< SNIP SNIP header removed >> #define WIN // WIN for Winsock and BSD for BSD sockets

//----- Include files --------------------------------------------------------#include <stdio.h> // Needed for printf() #include <string.h> // Needed for memcpy() and strcpy() #ifdef WIN #include <windows.h> // Needed for all Winsock stuff #endif #ifdef BSD #include <sys/types.h> // Needed for sockets stuff #include <netinet/in.h> // Needed for sockets stuff #include <sys/socket.h> // Needed for sockets stuff #include <arpa/inet.h> // Needed for sockets stuff #include <fcntl.h> // Needed for sockets stuff #include <netdb.h> // Needed for sockets stuff #endif //----- Defines --------------------------------------------------------------#define PORT_NUM 1050 // Arbitrary port number for the server //===== Main program ========================================================== void main(void) { #ifdef WIN WORD wVersionRequested = MAKEWORD(1,1); // Stuff for WSA functions WSADATA wsaData; // Stuff for WSA functions #endif int welcome_s; // Welcome socket descriptor struct sockaddr_in server_addr; // Server Internet address int connect_s; // Connection socket descriptor struct sockaddr_in client_addr; // Client Internet address struct in_addr client_ip_addr; // Client IP address int addr_len; // Internet address length char out_buf[4096]; // Output buffer for data char in_buf[4096]; // Input buffer for data int retcode; // Return code #ifdef WIN // This stuff initializes winsock WSAStartup(wVersionRequested, &wsaData); #endif // Create a welcome socket // - AF_INET is Address Family Internet and SOCK_STREAM is streams welcome_s = socket(AF_INET, SOCK_DGRAM, 0); if (welcome_s > 0) { printf("*** ERROR - socket() failed \n"); exit(-1); } // Fill-in server (my) address information server_addr.sin_family = AF_INET; server_addr.sin_port = htons(PORT_NUM); server_addr.sin_addr.s_addr = htonl(INADDR_ANY);

// Address family to use // Port number to use // Listen on any IP address

// Listen for a connection listen(connect_s, 1); // Accept a connection. The accept() will block and then return with // connect_s assigned and client_addr filled-in. printf("Waiting for accept() to complete... \n"); addr_len = sizeof(client_addr); connect_s = accept(connect_s, (struct sockaddr *)&client_addr, &addr_len); if (connect_s < 0) { printf("*** ERROR - accept() failed \n"); exit(-1); } // Copy the four-byte client IP address into an IP address structure memcpy(&client_ip_addr, &client_addr.sin_addr.s_addr, 4); // Print an informational message that accept completed printf("Accept completed (IP address of client = %s port = %d) \n", inet_ntoa(client_ip_addr), ntohs(client_addr.sin_port)); // Send to the client strcpy(out_buf, "This is a message from SERVER to CLIENT"); retcode = send(welcome_s, out_buf, (strlen(out_buf) + 1), 0); if (retcode < 0) { printf("*** ERROR - send() failed \n"); exit(-1); } // Receive from the client retcode = recv(welcome_s, in_buf, sizeof(in_buf), 0); if (retcode < 0) { printf("*** ERROR - recv() failed \n"); exit(-1); } printf("Received from client: %s \n", in_buf); // Close the welcome and connect sockets #ifdef WIN retcode = closesocket(welcome_s); if (retcode < 0) { printf("*** ERROR - closesocket() failed \n"); exit(-1); } retcode = closesocket(connect_s); if (retcode < 0) { printf("*** ERROR - closesocket() failed \n"); exit(-1); } #endif #ifdef BSD retcode = close(welcome_s); if (retcode < 0) { printf("*** ERROR - close() failed \n"); exit(-1); }

retcode = close(connect_s); if (retcode < 0) { printf("*** ERROR - close() failed \n"); exit(-1); } #endif #ifdef WIN // Clean-up winsock WSACleanup(); #endif }

S-ar putea să vă placă și