31
Lecture Topics: 11/29 • IP • UDP • TCP • DNS

Lecture Topics: 11/29 IP UDP TCP DNS. Homework 9 Write a simple web server –not as hard as it sounds…

Embed Size (px)

DESCRIPTION

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:

Citation preview

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/1.0 200 OKDate: Wed, 29 Nov 2000 20:14:10 GMTServer: Apache/1.1.1Content-Length: 183Content-Type: text/htmlConnection: close

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><HTML><HEAD><TITLE>410 Web Page</TITLE></HEAD><BODY><p>410 is my favorite class.</p></body></html>

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

packetApplication Data

IP Header Application DataTCP HeaderEthernet Header

Ethernet Checksum

Ethernet Frame

IP Header Application DataTCP Header

IP Datagram

Application DataTCP Header

TCP Segment

Application layerTransport 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

RRHH

H

H

H

R

RH

R

Routers send packet to next closest point

H: Hosts

R: Routers

YOUCNN

IP Addresses• IP addresses are 4 bytes (e.g.

128.95.8.137)– part of the address designates the network

(e.g. 128.95)– the rest of the address designates the

machine on the network (e.g. 8.137)• 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 == 128.95, 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?

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

INTERNETHello World Hello WorldArrive in order

INTERNETHello World WorldLose a packet

INTERNETHello World World HelloReorder packets

INTERNETHello World Hello Hello WorldDuplicate packets

INTERNETHello World Goodbye WorldCorrupt Packets

Checksum

chksum hash

10101001011101001100101010110101010110111010001011010101011010101010110101001011101001100101010110101010110111010011000101110100

Sent Data & Checksum1010100101110100110010101011010101011011101000101101010101101010101011010100101110100110010101011010101011011101

Data to Send

10101001011101001100101010110101010110111010001011010100100010101010110101001011101001100101010110101010110111010011000101110100

Received Data & Checksum

chksum hash 1001010110101010

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 65535– 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 messageGot your message

Timing Out

Packet

ACK

Tim

eou

t

Packet

ACK

Tim

eout

Packet

Tim

eout

Packet

ACK

Tim

eout

Packet

ACK

Tim

eou

t

Packet

ACK

Tim

eout

ACK lost Packet lost Early timeout

Tim

e

Sender Receiver Sender Receiver Sender Receiver

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 0Pkt 0

ACK 1

Pkt 1ACK 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)

01234

23

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

01234

3

ACK 0 ACK 1

ACK 2

ACK 4

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

01234

3

ACK 0 ACK 1

ACK 2

ACK 4

Deliver Packet 0Deliver Packet 1Deliver Packet 2Save 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

windowPacket # 0 1 2 3 4 5 6 7 8 9Received? X X X X XAcknowledged?

X X X

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 # 0 1 2 3 4 5 6 7 8 9Sent? X X X X X X XReceived ack? X X

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. 128.95.4.112• You want to type

http://www.cs.washington.edu, not http://128.95.4.112

• 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(128.95.1.4)

What’s the IP address for www.netscape.com?

Your computer(128.95.1.24)

Oh, you can find it at 207.200.89.226