CS326e Spring 2014 – Midterm Exam
Name ________SOLUTIONS______ UTEID _________
The exam has 110 possible points, 10 of which are extra credit. There is a Word Bank
on Page 8. Pages 7-8 can be removed from the exam.
1. [4 Points] In packet switching, to send a message from a source end system to a destination end system, the
source breaks long messages into smaller chunks of data known as packets. Between source and destination,
each packet travels through communication links and switches (for which there are two predominant types,
routers and link-layer switches).
2. [2 Points] The amount of time required to push all of a packet’s bits into a link is called the transmission delay.
3. [2 Points] The time required to send a bit from the beginning of the link to the end of a link is called the
propagation delay.
4. [4 Points] The Internet’s application layer includes many protocols, such as the HTTP protocol (which
provides for Web document request and transfer), SMTP ( which pro-vides for the transfer of e- mail messages),
and FTP (which provides for the transfer of files between two end systems).
5. [2 Point] At the application layer, transmitted information is called a message.
6. [2 Points] At the transport layer, transmitted information is called a segment.
7. [2 Points] At the network layer, transmitted information is called a datagram.
8. [2 Points] At the link layer, transmitted information is called a frame.
9. [4 Points] In the Internet there are two transport protocols, TCP and UDP. The UDP protocol provides a
connectionless service to its applications. This is a no-frills service that provides no reliability, no flow control,
and no congestion control. The TCP protocol provides a connection-oriented service to its applications. This
service includes guaranteed delivery of application-layer information to the destination and flow control ( that
is, sender/ receiver speed matching). TCP also breaks long messages into shorter segments and provides a
congestion-control mechanism, so that a source throttles its transmission rate when the network is congested.
10. [2 Points] How many IP Protocols are there in the Internet? One
11. [2 Points] Give one example of link-layer protocol. Ethernet, WiFi, or DOCSIS.
12. [3 Points] In a client- server architecture, there is an always-on host, called the server, which services requests
from many other hosts, called clients.
13. [3 Points] In a P2P architecture, there is minimal ( or no) reliance on dedicated machines in data centers. Instead
the application exploits direct communication between pairs of intermittently connected hosts, called peers. The
peers are not owned by the service provider, but are instead desktops and laptops controlled by users, with most
of the peers residing in homes, universities, and offices.
14. [2 Points] An application-layer process sends messages into, and receives messages from, the network through a
software interface called a socket. This is also referred to as an API which stands for Application
Programming Interface.
1 15. [2 Points] In the Internet, a host interface is identified by its IP Address which today is usually a 32- bit quantity
that we can think of as uniquely identifying the host interface. In addition to knowing the address of the host
interface to which a message is destined, the sending process must also identify the receiving process running in
the host. This information is needed because in general a host could be running many network applications. A
destination port number serves this purpose.
16. [1 Points] Internet protocols are defined in RFCs.
17. [4 Points] In the HTTP protocol, a basic URL has two components: the hostname that houses the object and the
object’s path. For example, the URL
http://www.someSchool.edu/someDepartment/picture.gif
has www.someSchool edu for a hostname and /someDepartment/picture gif for a path.
18. [1 Points] HTTP uses TCP as its underlying transport protocol.
19. [3 Points] Let’s walk through the steps of transferring a Web page from server to client for the case of nonpersistent connections. Let’s suppose the page consists of a base HTML file and 10 JPEG images, and that all 11
of these objects reside on the same server. Further suppose the URL for the base HTML file is
http://www.someSchool.edu/someDepartment/home.index
Here is what happens:
1. The HTTP client process initiates a TCP connection to the server www. someSchool.edu on port
number 80, which is the default port number for HTTP. Associated with the TCP connection, there will
be a socket at the client and a socket at the server.
2. The HTTP client sends an HTTP request message to the server via its socket. The request message
includes the path /someDepartment/home.index.
3. The HTTP server process receives the request message via its socket, retrieves the object /
someDepartment/ home.index from its storage, encapsulates the object in an HTTP response message,
and sends the response message to the client via its socket.
4. The HTTP server process tells TCP to close the TCP connection.
5. The HTTP client receives the response message. The TCP connection terminates. The message indicates
that the encapsulated object is an HTML file. The client extracts the file from the response message,
examines the HTML file, and finds references to the 10 JPEG objects.
6. The first four steps are then repeated for each of the referenced JPEG objects.
20. [2 Points] The most striking difference HTTP and FTP is that FTP uses two parallel TCP connections to transfer
a file, a control connection and a data connection. The data connection is used to actually send a file. The
control connection is used for sending control information between the two hosts— information such as user
identification, password, commands to change remote directory, and commands to “ put” and “ get” files.
21. [2 Points] SMTP has numerous wonderful qualities, as evidenced by its ubiquity in the Internet, it is
nevertheless a legacy technology that possesses certain archaic characteristics. For example, it restricts the body
( not just the headers) of all mail messages to simple 7-bit ASCII.
2 22. [4 Points] In order to deal with the issue of scale, the DNS uses a large number of servers, organized in a
hierarchical fashion and distributed around the world. No single DNS server has all of the mappings for all of
the hosts in the Internet. Instead, the mappings are distributed across the DNS servers. To a first approximation,
there are three classes of DNS servers— root DNS servers, top-level domain ( TLD) DNS servers, and
authoritative DNS servers
23. [5 Points] In a DNS server, a resource record is a four- tuple that contains the following fields:
( Name, Value, Type, TTL)
The meaning of Name and Value depend on Type:
• If Type= A, then Name is a hostname and Value is the IP address for the host-name. Thus, a Type A
record provides the standard hostname-to-IP address map-ping. As an example, ( relay1.bar.foo. com,
145.37.93.126, A) is a Type A record.
• If Type= NS, then Name is a domain and Value is the host-name of an authoritative DNS server that
knows how to obtain the IP addresses for hosts in the domain. This record is used to route DNS queries
further along in the query chain. As an example, (foo.com, dns.foo.com, NS) is a Type NS record.
In the following 2 problems, we are sending a 50 Mbit MP3 file from a source host to a destination host. All links in
the path between source and destination have a transmission rate of 10 Mbps. Assume that the propagation speed is
2 * 108 meters/sec, and the distance between source and destination is 5,000 km.
24. [5 Points] Suppose there is only one link between source and destination. Also suppose that the entire MP3 file
is sent as one packet. What is the transmission delay? Show your work.
50 Mbits / 10 Mbits/sec = 5 seconds
25. [5 Points] Referring to the above question, what is the end-to-end delay? Show your work.
5 + 5,000,000 / 200,000,000 = 5.025 seconds
3 26. [10 Points} Complete the following TCP Server and Client code.
# ------------------------------------- Server Code
from socket import *
serverSocket = socket(AF_INET, SOCK_STREAM)
serverPort = 6789
serverSocket.bind(("", serverPort))
serverSocket.listen(1)
while True :
print 'Ready to serve...’
connectionSocket, addr = serverSocket.accept()
try:
message = connectionSocket.recv(1024)
print 'Message is: ', message
filename = message.split()[1]
print 'File name is: ', filename
f = open(filename[1:])
outputdata = f.read()
connectionSocket.send("HTTP/1.1 200 OK\r\n\r\n")
for i in range(0, len(outputdata)):
connectionSocket.send(outputdata[i])
connectionSocket.send("\r\n")
connectionSocket.close()
except IOError:
connectionSocket.send("HTTP/1.1 404 Not Found\r\n\r\n")
connectionSocket.send("<html><head></head><body><h1>
404 Not Found</h1></body></html>\r\n”)
connectionSocket.close()
serverSocket.close()
# ------------------------------------- Client Code
import sys, socket
port = 6789
host = sys.argv[1]
filename = sys.argv[2]
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
c.connect((host, port))
fileobj = c.makefile('r', 0)
fileobj.write("GET "+filename+" HTTP/1.0\r\n\r\n")
buff = fileobj.readlines()
for line in buff:
print line
4 27. [10 Points} Complete the following UDP Server and Client code.
# ------------------------------------- Server Code
import random
from socket import *
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('', 12000))
while True:
rand = random.randint(0, 10)
message, address = serverSocket.recvfrom(1024)
message = message.upper()
if rand < 4:
continue
serverSocket.sendto(message, address)
# ------------------------------------- Client Code
import sys, time
from socket import *
argv = sys.argv
host = argv[1]
port = argv[2]
timeout = 1 # in second
clientsocket = socket(AF_INET, SOCK_DGRAM)
clientsocket.settimeout(timeout)
port = int(port)
ptime = 0
while ptime < 10:
ptime += 1
data = "Ping " + str(ptime) + " " + time.asctime()
try:
RTTb = time.time()
clientsocket.sendto(data,(host, port))
message, address = clientsocket.recvfrom(1024)
RTTa = time.time()
print "Reply from " + address[0] + ": " + message
print "RTT: " + str(RTTa - RTTb)
except:
print "Request timed out."
continue
clientsocket.close()
5 28. [10 Points] Referring to Page 7 (you can tear page 7 off of the exam), answer the following
questions.
1. What version of HTTP is the client running? HTTP/1.1
2. What version of HTTP is the server running? HTTP/1.1
3. What languages (if any) does your browser indicate that it can accept to the server?
En-us, en
4. What is the IP address of the client? 192.168.1.102
5. What is the IP address of the server? 128.119.245.21
6. What is the port number of the client? 4127
7. What is the port number of the server? 80
8. What is the status code returned from the server to the browser? 200 OK
9. When was the HTML file that you are retrieving last modified at the server?
Tue, 23 Sep 2003 …
10. How many bytes of content are being returned to your browser? 73
29. [10 Points] Referring to Page 8, answer the following questions.
1. What is the destination port for the DNS query message? 53
2. What is the source port of the DNS response message? 53
3. To what IP address is the DNS query message sent? 192.168.1.1
4. This is likely the IP address of what? Local DNS server.
5. Examine the DNS query message. What “Type” of DNS query is it? A
6. Does the query message contain any “answers? No
7. Examine the DNS response message. How many “answers” are provided? One
8. What is the contents of each of these answers?
www.mit.edu: type A, class IN, addr 18.7.22.83
Name: www.mit.edu
Type: A (Host
address) Class:
IN (0x0001)
Time to live: 1 minute
Data length: 4
Addr: 18.7.22.83
6 7 Word Bank
Not every word needed for the exam is here and
there may be a few words that aren’t needed for the
exam. Pluralisations are left out.
AF_INET
DOCSIS
ethernet
FTP
HTTP
IP address
P2P
propagation
SMTP
SOCK_DGRAM
SOCK_STREAM
TCP
transmission
UDP
WiFi
accept
application layer
Architecture
bind
client- server
clients
close
connect
datagram
delay
domain
hierarchical
hostname
link-layer
listen
message
packet
peers.
record
recv
recvfrom
resource
router
segment
send
sendto
sendtoargv
server
settimeout
Socket
switch
8
© Copyright 2026 Paperzz