Lecture Topics: 11/29 IP UDP TCP DNS
Homework 9 Write a simple web server –not as hard as it sounds Specification out tonight Skeleton code out by tomorrow morning Base implementation (80%) –return a requested file –report a few errors –<100 lines of code
Simple Web Server HTTP/ OK Date: Wed, 29 Nov :14:10 GMT Server: Apache/1.1.1 Content-Length: 183 Content-Type: text/html Connection: close 410 Web Page 410 is my favorite class. GET /index.html HTTP/1.0 Web Client Request:: Web Server Reply:
Homework 9 Continued Additional features (25%) do some of the following –generate an HTML index file based on the contents of a directory –create a web log that stores all accesses –keep “hit” counters for each file that are reported when the user accesses /hits –many more options You will need to learn how to use sockets –there will be links on the homework page and sample programs –not too hard You may need to read a little on HTTP and HTML –links on the web page
Open Issues What happens to the L1 cache on system calls? –the OS uses the L1 cache as usual –it only replaces invalid entries –user code will have to What is hub? –a hub logically only connects the wires between multiple computers or networks –a packet received on any wire is immediately forwarded to every other wire –it increases the size of the collision domain What is a switch? –a switch is like a hub except it only forwards packets towards the destination –it learns where other computers are by listening to where they send their packets from
Hubs vs. Switches Hubs forward packets everywhere (broadcast) –cheap –work best if the network is small Switches only forward toward the destination –more expensive –self-configuring –good for large networks C3 HUB C4 C1 C2 C5 C3 SWITCH C4 C1 C2 C5
Protocol Stack These layers comprise the protocol stack Each layer of the stack adds extra info to the packet Application Data IP HeaderApplication DataTCP Header Ethernet Header Ethernet Checksum Ethernet Frame IP HeaderApplication DataTCP Header IP Datagram Application DataTCP Header TCP Segment Application layer Transport layer Network layer Data link layer
IP Ethernet allows packets to be sent between nodes on the same network Internet Protocol (IP) allows packets to be sent between nodes on different networks Key idea: some machines (i.e. routers) are on multiple networks Ethernet is still used to send packets between routers
IP Routers R R R R R HH H H H R R H R Routers send packet to next closest point H: Hosts R: Routers YOU CNN
IP Addresses IP addresses are 4 bytes (e.g ) –part of the address designates the network (e.g ) –the rest of the address designates the machine on the network (e.g ) A router sends the packet to the correct network, and the network sends the packet to the correct node –this greatly reduces the information a router must store
How do routers know where to send packets? Forwarding tables at each router –Network == , then send to router X Original Internet: manual update Now: automatic update based on “cost” –exchange tables with neighbors –use neighbor with smallest hop count –what if node says zero cost to everywhere?
Setting up Routing Tables Graph theory to compute “shortest path” –routers = nodes –links = edges –delay, hops = cost Need dynamic computation to adapt to changes in topology –if a router goes down, might need to find another path
IP Routing Protocols There are two basic kinds of routing protocols Distance Vector –exchange routing tables with neighbors –no one knows complete topology –now used between admin domains (i.e. AT&T and MCI Link state –tell everyone who your neighbors are –everyone computes shortest path –now used within admin domains (within AT&T)
IP Service Model IP's service model is best-effort unreliable data-gram delivery IP does it's best to get a message from source to destination But it makes no guarantees that –the packet will arrive –the packets will arrive in order –the contents of the packet won't be changed –only one copy of the packet will arrive Aren't you glad the designers of IP don't design cars?
What IP can do Some are uncommon, but they all happen INTERNET HelloWorldHelloWorld Arrive in order INTERNET HelloWorld Lose a packet INTERNET HelloWorld Hello Reorder packets INTERNET HelloWorldHello World Duplicate packets INTERNET HelloWorldGoodbyeWorld Corrupt Packets
Checksum chksum hash Sent Data & Checksum Data to Send Received Data & Checksum chksum hash Calculated and stored checksum differ, so data is corrupt INTERNET Corrupted bits
User Datagram Protocol (UDP) UDP is basically IP with a data checksum and ports The checksum ensures that corrupted data isn't accepted Ports allow multiple connections to be de- multiplexed (TCP has ports too) –a port is a number between 0 and –common applications such as web servers run on "well-known ports" so web browsers know which port to contact –a UDP/TCP "connection" is determined by the Source IP address, Source port number, Destination IP address and Destination port number
UDP UDP characteristics (similar to IP) –unreliable (no guarantees the packet arrives) –packets could be reordered or duplicated –corrupted packets are discarded, but not retransmitted Who would ever want this? –common for low-latency applications where loss is tolerable (streaming media, games) –because reliable protocols (TCP) can be slower
Transmission Control Protocol TCP is what you usually want –reliable (messages guaranteed to eventually arrive) –dropped packets are retransmitted –duplicate packets are discarded –reordered packets are unreordered TCP is a bi-directional (i.e. full-duplex) stream based protocol –Both nodes can send and receive –Don't explicitly send packets, instead send a stream of bytes
Ensuring Packets Arrive w/ UDP Will you marry me? INTERNET ? No Answer--Did she get my proposal? Was the packet lost or corrupted? I better send it again Will you marry me? INTERNET ? Will you marry me? INTERNET ? Will you marry me? INTERNET ? Stalker!
Reliability with TCP With TCP, the receiver is obligated to send an acknowledgment (ACK), when it receives a packet The receiver is not obligated to respond with an answer, only an acknowledgement of receipt If the sender does not receive an ACK, it eventually retransmits the packet –can the receiver ever receive two copies of a packet? Will you marry me? INTERNET Will you marry me? Got your message
Timing Out Packet ACK Timeout Packet ACK Timeout Packet Timeout Packet ACK Timeout Packet ACK Timeout Packet ACK Timeout ACK lostPacket lost Early timeout Time SenderReceiverSenderReceiverSenderReceiver
Eliminating Duplicate Packets Problem: The receiver can still receive duplicate packets (either due to the Internet or a retransmission) –how do we distinguish a duplicate from another packet with the same contents? Solution: Send a sequence number with each packet –1st packet gets sequence number 0 –2nd packet gets sequence number 1 –retransmitted 1st packet has sequence number 0
Sequence Numbers Each new packet gets a new sequence number Don't send the next packet until the previous packet is acknowledged Pkt 0 ACK 0 Pkt 0 ACK 1 Pkt 1 ACK 0 Discard Duplicate
Sending Multiple Packets Sending one packet at a time is too slow –round trip time is 100ms –network has enough buffer space to hold several packets Idea: send lots of packets at once –receiver acknowledges the packets they receive –retransmit only unacked packets
Sending Multiple Packets Sender sends multiple packets at once Each packet that was not acknowledged is retransmitted Problem: –retransmit packets even if only ACKs are lost (e.g. packet 2) ACK 0 ACK 1 ACK 4 ACK 3 ACK 2
TCP Sending Packets In TCP, the receiver sends an acknowledgement after every packet The receiver acknowledges up to the last consecutive packet it received –receive "0" send "ack 0" I've received 0-0 –receive "1" send "ack 1" I've received 0-1 –receive "2" send "ack 2" I've received 0-2 –receive "4" send "ack 2" I've received 0-2 –receive "5" send "ack 2" I've received 0-2 It's okay if ACKs get lost –e.g. "ack 1" can be lost because "ack 2" covers it The sender can recognize if a packet was lost –Mmmmm? I've received 3 "ack 2"s, maybe packet 3 got lost
TCP ACKing The receiver acknowledges up to the last consecutive packet it received Packet 3 was lost, so the receiver sends an "ACK 2" when it receives packet 4, not an "ACK 4" The receiver must remember which packets it has received –it sends an "ACK 4" when it receives packet 3 because it received packet 4 earlier
Handling Reordered Packets TCP ensures that the data stream is delivered in-order Packets may arrive out- of-order TCP must buffer out-of- order packets until the missing packets arrive Packets are delivered to the application in the order they were sent, not the order they arrived ACK 0 ACK 1 ACK 2 ACK 4 Deliver Packet 0 Deliver Packet 1 Deliver Packet 2 Save Packet 4 Deliver Packets 3-4
Receive Window From the receiver's perspective there are three types of packets –packets received and acked –packets received out of order –packets not yet received The first missing packet through the highest received packet is known as the receive window –the receiver only has to buffer packets in the receive window Packet # Received?XXXXX Acknowledged?XXX Receive Window
Send Window From the sender's perspective there are three types of packets –packets sent and acked –packets sent and unacked –packets not yet sent All sent and unacked packets make up the send window –the sender must buffer all sent and unacked packets and all packets not yet sent Packet # Sent?XXXXXXX Received ack?XX Send Window
Sliding Window TCP is known as a sliding window protocol As packets are sent/received/ acknowledged, the sender and receiver windows slide through sequence numbers
Domain Name Service (DNS) IP must use IP addresses, e.g You want to type not DNS handles making this translation If the local DNS server doesn't know the translation, it asks one of the 13 root name- servers, which have known IP addresses Local DNS server ( ) What’s the IP address for Your computer ( ) Oh, you can find it at