Chapter 7 TCPIP The TCPIP Architecture The Internet

  • Slides: 52
Download presentation
Chapter 7 TCP/IP The TCP/IP Architecture The Internet Protocol Transport Layer Protocols 1

Chapter 7 TCP/IP The TCP/IP Architecture The Internet Protocol Transport Layer Protocols 1

Why Internetworking? l To build a “network of networks” or internet l l operating

Why Internetworking? l To build a “network of networks” or internet l l operating over different network technologies providing ubiquitous connectivity through IP packet transfer achieving huge economies of scale To provide universal communication services l l independent of underlying network technologies providing common interface to user applications H H Net 51 Net G G G H Net 52 Net 53 Net G G Net 55 Net 54 Net G H 2

Internet Protocol Approach l l l IP packets transfer information across Internet Host A

Internet Protocol Approach l l l IP packets transfer information across Internet Host A IP → router…→ router→ Host B IP IP layer in each router determines next hop (router) Network interfaces transfer IP packets across networks Host A Router Transport Layer Internet Layer Network Interface Host B Router Internet Layer Net 51 Net Router Network Interface Net 54 Net 52 Network Interface Internet Layer Network Interface Transport Layer Net 53 Net 3

TCP/IP Protocol Suite SMTP HTTP Reliable stream service Best-effort connectionless packet transfer Network Interface

TCP/IP Protocol Suite SMTP HTTP Reliable stream service Best-effort connectionless packet transfer Network Interface 1 DNS RTP Distributed applications TCP UDP IP Network Interface 2 (ICMP, ARP) Network Interface 3 4

Internet Name & Address l l l l l Each host has a unique

Internet Name & Address l l l l l Each host has a unique Internet name, e. g. , www. northwestern. edu Domain name server (DNS) resolves IP name to IP address Each host has globally unique logical 32 bit IP address Dotted Decimal Notation, e. g. , 128. 100. 13 Routing decision is done based on destination IP address LANs (and other networks) assign physical addresses to the physical attachment to the network The network uses its own address to transfer packets or frames to the appropriate destination IP address needs to be resolved to physical address at each IP network interface IPv 6 l l l 128 -bit address field supports up to 3. 4 x 1038 hosts Simplified header format for speed More flexible, better security, larger packets … 5

Encapsulation TCP Header contains source & destination port numbers HTTP Request IP Header contains

Encapsulation TCP Header contains source & destination port numbers HTTP Request IP Header contains source and destination IP addresses; transport protocol type Ethernet Header contains source & destination MAC addresses; network protocol type Ethernet header TCP header HTTP Request IP header TCP header HTTP Request FCS 6

Internet Protocol l Provides best effort, connectionless packet delivery l l keep routers simple

Internet Protocol l Provides best effort, connectionless packet delivery l l keep routers simple and adapt to failure packets may be lost, out of order, or even duplicated higher layer protocols must deal with these, if necessary IP Packet Header 0 4 Version 8 IHL 16 Type of Service Identification Time to Live 19 24 31 Total Length Flags Protocol Fragment Offset Header Checksum Source IP Address Destination IP Address Options Padding 7

Example of IP Header 8

Example of IP Header 8

IP Addressing Class A 7 bits hostid netid 0 • 24 bits Class B

IP Addressing Class A 7 bits hostid netid 0 • 24 bits Class B 14 bits 0 1 • 16 bits hostid netid 128. 0. 0. 0 to 191. 255 16, 382 networks with up to 64, 000 hosts Class C 22 bits 1 • 1. 0. 0. 0 to 127. 255 126 networks with up to 16 million hosts 1 0 8 bits netid hostid 2 million networks with up to 254 hosts Class D 1 192. 0. 0. 0 to 223. 255 28 bits 1 1 0 multicast address 224. 0. 0. 0 to 239. 255 9

Example of IP Addressing 128. 135. 40. 1 H Interface Address is 128. 135.

Example of IP Addressing 128. 135. 40. 1 H Interface Address is 128. 135. 10. 2 Network Interface Address is 128. 140. 5. 35 128. 135. 10. 20 Network R 128. 135. 0. 0 H 128. 140. 5. 40 H 128. 140. 0. 0 H 128. 135. 10. 21 Address with host ID=all 0 s refers to the network Address with host ID=all 1 s refers to a broadcast packet H 128. 140. 5. 36 R = router H = host 10

Subnet Addressing l l l Subnet addressing introduces another hierarchical level Masking used to

Subnet Addressing l l l Subnet addressing introduces another hierarchical level Masking used to find subnet number Example Class B address (16 host ID bits): 150. 100. 0. 0 l l Create subnets with up to 100 hosts each, 9 bits for subnet ID Apply subnet mask to IP addresses to find corresponding subnet l l l Example: Find subnet for 150. 100. 12. 176 IP add = 100101100100 00001100 10110000 Mask = 11111111 10000000 AND = 100101100100 00001100 10000000 Subnet = 150. 100. 128 Subnet address used by routers within organization 11

Subnet Example H 1 H 2 150. 100. 12. 154 150. 100. 12. 176

Subnet Example H 1 H 2 150. 100. 12. 154 150. 100. 12. 176 150. 100. 128 150. 100. 129 150. 100. 0. 1 To the rest of the Internet R 1 150. 100. 12. 4 H 3 H 4 150. 100. 12. 24 150. 100. 12. 0 150. 100. 12. 55 150. 100. 12. 1 R 2 H 5 150. 100. 15. 54 150. 100. 15. 11 150. 100. 15. 0 12

Routing with Subnetworks l l IP layer in hosts and routers maintain a routing

Routing with Subnetworks l l IP layer in hosts and routers maintain a routing table Originating host: To send an IP packet, consult routing table l l l If destination host is in same network, send packet directly using appropriate network interface (physical address) Otherwise, send packet indirectly; typically, routing table indicates a default router Router: Examine IP destination address in arriving packet l If dest IP address not own, router consults routing table to determine next-hop and associated network interface & forwards packet 13

Routing Table Example: Host H 5 sends packet to host H 2 H 1

Routing Table Example: Host H 5 sends packet to host H 2 H 1 H 2 150. 100. 12. 154 150. 100. 12. 176 150. 100. 128 150. 100. 129 150. 100. 0. 1 To the rest of the Internet R 1 150. 100. 12. 4 H 3 H 4 150. 100. 12. 24 150. 100. 12. 0 150. 100. 12. 55 150. 100. 12. 1 R 2 H 5 150. 100. 15. 54 Routing Table at H 5 Destination Next-Hop Flags Net I/F 127. 0. 0. 1 H lo 0 default 150. 100. 15. 54 G emd 0 150. 100. 15. 11 150. 100. 15. 0 150. 100. 12. 176 14

Example: Host H 5 sends packet to host H 2 H 1 H 2

Example: Host H 5 sends packet to host H 2 H 1 H 2 150. 100. 12. 154 150. 100. 12. 176 150. 100. 128 150. 100. 129 150. 100. 0. 1 To the rest of the Internet R 1 150. 100. 12. 4 H 3 H 4 150. 100. 12. 24 150. 100. 12. 0 Routing Table at R 2 150. 100. 12. 176 Destination Next-Hop Flags Net I/F 127. 0. 0. 1 H lo 0 default 150. 100. 12. 4 G emd 0 150. 100. 15. 54 emd 1 150. 100. 12. 0 150. 100. 12. 1 emd 0 150. 100. 12. 55 150. 100. 12. 1 R 2 H 5 150. 100. 15. 54 150. 100. 15. 11 150. 100. 15. 0 15

Example: Host H 5 sends packet to host H 2 H 1 H 2

Example: Host H 5 sends packet to host H 2 H 1 H 2 150. 100. 12. 154 150. 100. 12. 176 150. 100. 128 150. 100. 129 150. 100. 0. 1 150. 100. 12. 176 R 1 To the rest of the Internet 150. 100. 12. 4 H 3 H 4 150. 100. 12. 24 150. 100. 12. 0 150. 100. 12. 55 150. 100. 12. 1 R 2 Routing Table at R 1 Destination Next-Hop Flags Net I/F 127. 0. 0. 1 H lo 0 150. 100. 12. 176 emd 0 150. 100. 12. 4 emd 1 150. 100. 15. 0 150. 100. 12. 1 G emd 1 H 5 150. 100. 15. 54 150. 100. 15. 11 150. 100. 15. 0 16

Address Resolution Protocol Although IP address identifies a host, the packet is physically delivered

Address Resolution Protocol Although IP address identifies a host, the packet is physically delivered by an underlying network (e. g. , Ethernet) which uses its own physical address (MAC address in Ethernet). How to map an IP address to a physical address? H 1 wants to learn physical address of H 3 -> broadcasts an ARP request H 1 H 2 150. 100. 76. 20 150. 100. 76. 21 H 3 150. 100. 76. 22 H 4 150. 100. 76. 23 ARP request (what is the MAC address of 150. 100. 76. 22? ) Every host receives the request, but only H 3 reply with its physical address H 1 H 2 H 3 ARP response (my MAC address is 08: 00: 5 a: 3 b: 94) H 4 17

Example of ARP 18

Example of ARP 18

User Datagram Protocol (UDP) l l UDP is an unreliable, connectionless transport layer protocol.

User Datagram Protocol (UDP) l l UDP is an unreliable, connectionless transport layer protocol. It makes a best effort to send a packet. Only 2 additional services beyond IP l l l Multiplexing (deliver to application according to port number) Error checking on data (IP only checks header) Applications of UDP l multimedia (e. g. RTP), network services (e. g. DNS, RIP, SNMP) l Other applications which can tolerate non-zero loss 0 16 31 Source Port Destination Port UDP Length UDP Checksum Data 19

Transmission Control Protocol (TCP) l l TCP provides a reliable full-duplex connection for byte

Transmission Control Protocol (TCP) l l TCP provides a reliable full-duplex connection for byte streams between two application layer peer processes. Rather complex transmitter & receiver l l l Connection-oriented: full-duplex connection between client & server processes Error control Flow control Congestion control Most Internet applications use TCP l HTTP, SMTP, FTP, TELNET, POP 3, … 20

Reliable Byte-Stream Service l Stream Data Transfer l l transfers a contiguous stream of

Reliable Byte-Stream Service l Stream Data Transfer l l transfers a contiguous stream of bytes across the network, with no indication of boundaries groups bytes into segments transmits segments as convenient Error Control l ARQ Application Write 45 bytes Write 15 bytes Write 20 bytes Transport Error Detection & Retransmission Read 40 bytes segments buffer ACKS, sequence # buffer 21

Flow Control l l Buffer limitations & speed mismatch can result in loss of

Flow Control l l Buffer limitations & speed mismatch can result in loss of data that arrives at destination Receiver controls rate at which sender transmits to prevent buffer overflow Application Transport segments buffer advertised window size < B buffer used buffer available = B 22

Congestion Control l Available bandwidth to destination varies with activity of other users Transmitter

Congestion Control l Available bandwidth to destination varies with activity of other users Transmitter dynamically adjusts transmission rate according to network congestion as indicated by RTT (round trip time) & ACKs Elastic utilization of network bandwidth Application Transport buffer RTT Estimation segments ACKS buffer 23

TCP Multiplexing l A TCP connection is specified by a 4 -tuple (source IP,

TCP Multiplexing l A TCP connection is specified by a 4 -tuple (source IP, source port, destination IP, destination port) l l TCP allows multiplexing of multiple connections between end systems to support multiple applications simultaneously Arriving segment directed according to connection 4 -tuple 1 2 A . . . m 1 2 . . . n 1 . . . 2 TCP TCP IP IP IP (A, 6234, B, 80) (A, 5234, B, 80) B k C (C, 5234, B, 80) 24

TCP Segment Format 0 4 10 16 Source port 24 31 Destination port Sequence

TCP Segment Format 0 4 10 16 Source port 24 31 Destination port Sequence number Acknowledgment number Header length Reserved U A P R S F R C S S Y I GK H T N N Checksum Window size Urgent pointer Options Padding Data • Each TCP segment has header of 20 or more bytes + 0 or more bytes of data 25

TCP Header Port Numbers l A socket identifies a connection endpoint l l IP

TCP Header Port Numbers l A socket identifies a connection endpoint l l IP address + port Well-known ports l l FTP Telnet DNS HTTP 20 23 53 80 Sequence Number l 32 bits long l 0 SN 232 -1 l Indicates the position of the first byte in segment in the entire byte stream l Initial sequence number selected during connection setup 26

TCP Header Acknowledgement Number l SN of next byte expected by receiver l Acknowledges

TCP Header Acknowledgement Number l SN of next byte expected by receiver l Acknowledges that all prior bytes in stream have been received correctly l Valid if ACK flag is set Header length l 4 bits l Length of header in multiples of 32 -bit words Reserved l 6 bits 27

TCP Header Control l 6 bits l URG: urgent pointer flag l l l

TCP Header Control l 6 bits l URG: urgent pointer flag l l l Urgent message end = SN + urgent pointer ACK: ACK packet flag PSH: override TCP buffering RST: reset connection SYN: establish connection FIN: close connection 28

TCP Header Window Size l 16 bits to advertise window size l Used for

TCP Header Window Size l 16 bits to advertise window size l Used for flow control l Sender will accept bytes with SN from ACK to ACK + window l Maximum window size is 65535 bytes TCP Checksum 29

TCP Connection Establishment “Three-way Handshake” Host A Host B SYN, Seq _no = x

TCP Connection Establishment “Three-way Handshake” Host A Host B SYN, Seq _no = x _no = YN, Seq no = _ k c A , CK y, A x+1 S Seq_n o = x+ 1, ACK , Ack_ no = y +1 30

Initial Sequence Number (ISN) l l Select ISN to protect against segments from prior

Initial Sequence Number (ISN) l l Select ISN to protect against segments from prior connections which may come late Use local clock to select ISN sequence number. Time for clock to go through a full cycle should be greater than the maximum lifetime of a segment (MSL); Typically MSL=120 seconds High bandwidth connections pose a problem 2 n > 2 * max packet life * R bytes/second Host A Host B k ACK, Ac , n = o n _ YN, Seq 1 _no = n+ S Seq_n o = n+ 1, ACK , Ack_ no = n +1 Delayed segment with Seq_no = n+2 will be accepted 31

Maximum Segment Size l l l Maximum Segment Size l largest block of data

Maximum Segment Size l l l Maximum Segment Size l largest block of data that TCP sends to other end Each end can announce its MSS during connection establishment Default is 576 bytes including 20 bytes for IP header and 20 bytes for TCP header Ethernet implies MSS of 1460 bytes IEEE 802. 3 implies 1452 32

Near End: Connection Request 33

Near End: Connection Request 33

Far End: Ack and Request 34

Far End: Ack and Request 34

Near End: Ack 35

Near End: Ack 35

Client-Server Application Host B (server) Host A (client) socket t 1 connect (blocks) t

Client-Server Application Host B (server) Host A (client) socket t 1 connect (blocks) t SYN, Seq socket bind listen accept (blocks) _no = x 2 _no k c A , K , AC = x+1 o=y eq_n SYN, S connect returns t 3 Seq_n o = x+ write read (blocks) 1, ACK , Ack_ Reques t 5 t messa no = y ge +1 t 4 accept returns read (blocks) t 6 age eply mess R read returns write read (blocks) 36

TCP Window Flow Control Host A = Seq_no 1024 bytes to transmit Host B

TCP Window Flow Control Host A = Seq_no 1024 bytes to transmit Host B t 1 t 2 Seq_no = 1, Ac 48, No Win = 20 , 0 0 0 2 k_no = 2000, Ack _no = 1, W in = 1024 3024, Ack , Data = 2 _no = 1, W in = 1024 = Seq_no 1024 bytes to transmit t 4 Seq_no = 12, , Win = 5 8 4 0 4 = o 1, Ack_n 4048, Ack _ no = 129, 000 -3023 , Data = 3 1024 bytes to transmit Win = 102 t 0 Data 024 -4047 -128 Data = 1 4, Data = 128 bytes to transmit 4048 -455 t 3 9 can only send 512 bytes 37

Silly Window Syndrome l Situation: l l l Transmitter sends large amount of data

Silly Window Syndrome l Situation: l l l Transmitter sends large amount of data Receiver buffer depleted slowly, so buffer fills Every time a few bytes read from buffer, a new advertisement to transmitter is generated Sender immediately sends data & fills buffer Many small, inefficient segments are transmitted Solution: l l Receiver does not advertise window until window is at least ½ of receiver buffer or maximum segment size Transmitter refrains from sending small segments 38

TCP Connection Closing “Graceful Close” Host A Host B FIN, seq = 50 86

TCP Connection Closing “Graceful Close” Host A Host B FIN, seq = 50 86 7 Ack = 508 Deliver 150 bytes D k=5087 c A , 3 0 3 = ata, seq. Ack = 453 q. FIN, se 087 k=5 c A , 3 5 =4 Ack = 454 39

TIME_WAIT state l When TCP receives ACK to last FIN, TCP enters TIME_WAIT state

TIME_WAIT state l When TCP receives ACK to last FIN, TCP enters TIME_WAIT state l l Protects future incarnations of connection from delayed segments TIME_WAIT = 2 x MSL Only valid segment that can arrive while in TIME_WAIT state is FIN retransmission l If such segment arrives, resent ACK & restart TIME_WAIT timer When timer expires, close TCP connection & delete connection record 40

TCP State Transition Diagram e tiv ac CLOSED Applipassive open, cation create TCB close

TCP State Transition Diagram e tiv ac CLOSED Applipassive open, cation create TCB close , YN CK LISTEN S e A v i , e se rec d SYN nd e iv n e e c SY s re application close T N RS or timeout, receive SYN, SYN_SENT SYN_RCVD delete TCB send ACK e , v i K rece ce , AC CK ive A e r CK A N SY end application s ESTABLISHED re close, ceiv e, send s sen e FIN lo d. A c , n FIN C o K i N t ca d FI i l p CLOSE_WAIT ap senreceive FIN application close CLOSING FIN_WAIT_1 send ACK send FIN re receive c se eiv nd e LAST_ACK receive AC FIN ACK K , A ACK CK receive FIN 2 MSL timeout FIN_WAIT_2 TIME_WAIT send ACK delete TCB en op B TC N e Y at S re nd , c se 41

TCP Congestion Control l l Advertised window size ensures that receiver’s buffer will not

TCP Congestion Control l l Advertised window size ensures that receiver’s buffer will not overflow However, buffers at intermediate routers between source and destination may overflow Router Packet flows from many sources l l R bps Congestion occurs when total arrival rate from all packet flows exceeds R over a sustained period of time 42 Buffers at multiplexer will fill and packets will be lost

Throughput (bps) Phases of Congestion Behavior 1. Light traffic R l l l Knee

Throughput (bps) Phases of Congestion Behavior 1. Light traffic R l l l Knee (congestion onset) 2. Arrival Rate l Delay (sec) l l R Arrival rate approaches R Delay increases rapidly Throughput begins to saturate Congestion collapse 3. Arrival Rate << R Low delay Can accommodate more l l l Arrival rate > R Large delays, packet loss 43 Useful application

Window Congestion Control l l Desired operating point: just before knee TCP sender maintains

Window Congestion Control l l Desired operating point: just before knee TCP sender maintains a congestion window (Cwnd) to control congestion at intermediate routers Effective window is minimum of congestion window and advertised window Problem: source doesn’t know its “fair” share of available bandwidth Solution: adapt dynamically to available BW l l Sources probe the network by increasing cwnd When congestion detected, sources reduce rate Ideally, sources sending rate stabilizes near ideal point TCP congestion control algorithm l l l At light traffic: segment is ACKed quickly, increase Cwnd aggresively At knee: ACKs arrive, but more slowly, slow down increase in cwnd At congestion: segments encounter large delays (so retransmission timeouts occur); segments are dropped in router buffers (resulting in duplicate ACKs). Reduce transmission rate, then probe again. 44

TCP Congestion Control: Slow Start l Slow start: increase congestion window size by one

TCP Congestion Control: Slow Start l Slow start: increase congestion window size by one segment upon receiving an ACK from receiver l l l initialized at 2 segments used at (re)start of data transfer congestion window increases exponentially cwnd Seg 8 4 ACK 2 1 RTTs 45

TCP Congestion Control: Congestion Avoidance l Algorithm progressively sets a congestion threshold cwnd When

TCP Congestion Control: Congestion Avoidance l Algorithm progressively sets a congestion threshold cwnd When cwnd > threshold, slow down rate at which cwnd is increased 8 l l Increase congestion window size by one segment per round-triptime (RTT) l l l Each time an ACK arrives, cwnd is increased by 1/cwnd In one RTT, cwnd segments are sent, so total increase in cwnd is cwnd x 1/cwnd = 1 cwnd grows linearly with time threshold 4 2 1 RTTs 46

TCP Congestion Control: Congestion 20 l Congestion avoidance Congestion window Time-out l 15 l

TCP Congestion Control: Congestion 20 l Congestion avoidance Congestion window Time-out l 15 l Threshold 10 5 l l Slow start l Congestion is detected upon timeout or receipt of duplicate ACKs Assume current cwnd corresponds to available bandwidth Adjust congestion threshold = ½ x current cwnd Reset cwnd to 1 Go back to slow-start Over several cycles expect to converge to congestion threshold equal to about ½ the available bandwidth 0 Round-trip times 47

Fast Retransmit & Fast Recovery l l l Congestion causes many segments to be

Fast Retransmit & Fast Recovery l l l Congestion causes many segments to be dropped If only a single segment is dropped, then subsequent segments trigger duplicate SN=1 ACKs before timeout SN=2 Can avoid large decrease in cwnd as SN=3 follows: SN=4 l When three duplicate ACKs arrive, SN=5 retransmit lost segment immediately l Reset congestion threshold to ½ cwnd l Reset cwnd to congestion threshold + 3 to account for the three segments that triggered duplicate ACKs l Remain in congestion avoidance phase l However if timeout expires, reset cwnd to 1 l In absence of timeouts, cwnd will oscillate around optimal value ACK=2 48

TCP Congestion Control: Fast Retransmit & Fast Recovery 20 Congestion avoidance Congestion window Time-out

TCP Congestion Control: Fast Retransmit & Fast Recovery 20 Congestion avoidance Congestion window Time-out 15 Threshold 10 5 Slow start 0 Round-trip times 49

Nagle Algorithm l Situation: user types 1 character at a time l l l

Nagle Algorithm l Situation: user types 1 character at a time l l l Transmitter sends TCP segment per character (41 B) Receiver sends ACK (40 B) Receiver echoes received character (41 B) Transmitter ACKs echo (40 B) 162 bytes transmitted to transfer 1 character! Solution: l l TCP sends data & waits for ACK New characters buffered Send new characters when ACK arrives Algorithm adjusts to RTT l Short RTT send frequently at low efficiency l Long RTT send less frequently at greater efficiency 50

Sequence Number Wraparound l 232 = 4. 29 x 109 bytes = 34. 3

Sequence Number Wraparound l 232 = 4. 29 x 109 bytes = 34. 3 x 109 bits l l At 1 Gbps, sequence number wraparound in 34. 3 seconds. Timestamp option: Insert 32 bit timestamp in header of each segment l l Timestamp + sequence no → 64 -bit seq. no Timestamp clock must: l tick forward at least once every 231 bits l Not complete cycle in less than one MSL l Example: clock tick every 1 ms @ 8 Tbps wraps around in 25 days 51

Delay-BW Product & Advertised Window Size l Suppose RTT=100 ms, R=2. 4 Gbps l

Delay-BW Product & Advertised Window Size l Suppose RTT=100 ms, R=2. 4 Gbps l l If single TCP process occupies pipe, then required advertised window size is l l l # bits in pipe = 3 Mbytes RTT x Bit rate = 3 Mbytes Normal maximum window size is 65535 bytes Solution: Window Scale Option l l Window size up to 65535 x 214 = 1 Gbyte allowed Requested in SYN segment 52