TCP/IP Lecture 2

43
TCP/IP TCP/IP Lecture 2 Lecture 2 cs193i – Internet cs193i – Internet Technologies Technologies Summer 2004 Summer 2004 Stanford University Stanford University

description

TCP/IP Lecture 2. cs193i – Internet Technologies Summer 2004 Stanford University. Announcements. Lab #1 due Wednesday HW #1 assigned Extra perl session tomorrow Tuesday, June 29, 2:15-3:05pm, Skilling 193 Broadcast live on E2, Stanford Online - PowerPoint PPT Presentation

Transcript of TCP/IP Lecture 2

Page 1: TCP/IP Lecture 2

TCP/IPTCP/IPLecture 2Lecture 2

cs193i – Internet cs193i – Internet TechnologiesTechnologiesSummer 2004Summer 2004

Stanford UniversityStanford University

Page 2: TCP/IP Lecture 2

AnnouncementsAnnouncements Lab #1 due WednesdayLab #1 due Wednesday HW #1 assignedHW #1 assigned Extra perl session tomorrowExtra perl session tomorrow

Tuesday, June 29, 2:15-3:05pm, Skilling Tuesday, June 29, 2:15-3:05pm, Skilling 193193

Broadcast live on E2, Stanford OnlineBroadcast live on E2, Stanford Online Silas’ Thursday office hours moved to Silas’ Thursday office hours moved to

Wednesday this weekWednesday this week Sweet Hall, 6:30-8:30pmSweet Hall, 6:30-8:30pm

Page 3: TCP/IP Lecture 2

Communicating with Communicating with AnyoneAnyone

Token-ring

[email protected]

[email protected]

How’s theweather inSeattle, Mar?

MSN Messenger

Network

Ethernet

Page 4: TCP/IP Lecture 2

Local Area Network Local Area Network (LAN)(LAN)

High speed, data High speed, data network over small network over small regionregion Few thousand metersFew thousand meters

Network technologies:Network technologies: EthernetEthernet FDDIFDDI Token ringToken ring

Data link layer Data link layer Packets routed based Packets routed based

on physical address on physical address (MAC)(MAC)

Ethernet

Token-ring

LAN 1

LAN 2

Page 5: TCP/IP Lecture 2

Local Area Network Local Area Network (LAN)(LAN)

High speed, data High speed, data network over small network over small regionregion Few thousand metersFew thousand meters

Network technologies:Network technologies: EthernetEthernet FDDIFDDI Token ringToken ring

Data link layer Data link layer Packets routed based Packets routed based

on physical address on physical address (MAC)(MAC)

Ethernet

Token-ring

LAN 1

LAN 2

?

Page 6: TCP/IP Lecture 2

Connecting Below Connecting Below Internet LevelInternet Level

HubHub Center of star topologyCenter of star topology In Ethernet, multiport In Ethernet, multiport

repeater or concentratorrepeater or concentrator BridgeBridge

Connects 2 networks of Connects 2 networks of same technology – same technology – extended LANextended LAN

Filters/forwards/floods Filters/forwards/floods based on MAC based on MAC

Link layer - framesLink layer - frames SwitchSwitch

Connects 2+ networks – Connects 2+ networks – packet-switched networkpacket-switched network

Reduces collisionsReduces collisions

Ethernet Ethernet

Hub

Bridge

Switch

Ethernet Ethernet

CISCOSYSTEMS

CISCOSYS TEMS CISCOSYST EM S

T3 STS-N

Page 7: TCP/IP Lecture 2

Connecting at the Connecting at the Internet LevelInternet Level

RouterRouter Originally gatewayOriginally gateway Forwards packets Forwards packets

based on network based on network layer info layer info (IP)(IP)

Separate broadcast Separate broadcast domainsdomains

In each domain, IP In each domain, IP packet encapsulated packet encapsulated in domain-specific in domain-specific packetpacket

Token-ring

CISCOSYSTEMS

Ethernet

CISCOSYSTEMS

Ethernet

CISCOSYSTEMS

Router

Page 8: TCP/IP Lecture 2

Internet SocietyInternet Society Governing body for Internet since 1992Governing body for Internet since 1992

http://www.isoc.orghttp://www.isoc.org Domain names and addresses assignedDomain names and addresses assigned

Upper level: Internet Assigned Numbers Upper level: Internet Assigned Numbers AuthorityAuthority

Regional: Regional: Latin America / CaribbeanLatin America / Caribbean Asia PacificAsia Pacific AmericaAmerica EuropeEurope

Page 9: TCP/IP Lecture 2

How Does Everyone Work How Does Everyone Work Together?Together?

NetworksNetworks MCI Worldcom, Sprint, Earthlink, …MCI Worldcom, Sprint, Earthlink, … Exchange points provide connections between Exchange points provide connections between

networksnetworks Network Access Points – open access policiesNetwork Access Points – open access policies

Network Service Provider Network Service Provider Build national or global networksBuild national or global networks Lease space at NAPsLease space at NAPs Sell bandwidth to regional NSPsSell bandwidth to regional NSPs Regional NSP sell bandwidth to ISPRegional NSP sell bandwidth to ISP

Internet Service Provider sells bandwidth to Internet Service Provider sells bandwidth to end usersend users

Page 10: TCP/IP Lecture 2

How Does Everyone Work How Does Everyone Work Together?Together?

Page 11: TCP/IP Lecture 2

OSI Reference Model OSI Reference Model for Network Designfor Network Design

Application (Layer 7)Presentation

SessionTransportNetworkData Link

Physical (Layer 1)

Page 12: TCP/IP Lecture 2

OSI vs. TCP/IP StackOSI vs. TCP/IP StackLayering: FTP Example

Network

Link

Transport

Application

Presentation

SessionTransportNetwork

Link

Physical

The 7-layer OSI Model The 4-layer Internet model

ApplicationFTP

ASCII/Binary

IP

TCP

Ethernet

Page 13: TCP/IP Lecture 2

Internet ProtocolInternet Protocol

App

Transport

Network

Link

TCP / UDP

IP

Data Hdr

Data Hdr

TCP Segment

IP Datagram

Protocol Stack

Page 14: TCP/IP Lecture 2

IP DatagramIP Datagram

Header

10101011101010101010010101010100101010100110100101010100101011111110100000111011111010000101110101010011010101111010000010100100000000010101000011010000111111010101......... 1011011001010100011001001010110

Data

Page 15: TCP/IP Lecture 2

IP AddressesIP Addresses 4 8-bit numbers (Hierarchical)4 8-bit numbers (Hierarchical)

Specifies both network and hostSpecifies both network and host Number of bits allocated to specify network Number of bits allocated to specify network

variesvaries Three classes:Three classes:

0 net host

1 7 24 bits

110 net host

3 21 8 bits

1 0 net host

2 14 16 bits

A B C

18.26.0.1

network 32-bits host

Page 16: TCP/IP Lecture 2

IP AddressesIP Addresses IP (Version 4) Addresses are 32 bits IP (Version 4) Addresses are 32 bits

longlong IP Addresses Assigned Statically or IP Addresses Assigned Statically or

Dynamically (DHCP)Dynamically (DHCP) IPv6 addresses are 128 bits longIPv6 addresses are 128 bits long

Page 17: TCP/IP Lecture 2

IP Address SpaceIP Address Space Originally, 3 ClassesOriginally, 3 Classes

A, B, CA, B, C ProblemProblem

Classes too rigid (C too small, B too Classes too rigid (C too small, B too big)big)

SolutionSolution Subnetting (e.g. within Stanford)Subnetting (e.g. within Stanford) Classless Interdomain Routing (CIDR)Classless Interdomain Routing (CIDR)

Page 18: TCP/IP Lecture 2

SubnettingSubnetting IP Address plus subnet mask (netmask)IP Address plus subnet mask (netmask) IP Addr: 171.64.15.82IP Addr: 171.64.15.82

Netmask: 0xFFFFFF00 Netmask: 0xFFFFFF00 (111...1100000000)(111...1100000000) First 24 bits are the Subnet ID (the First 24 bits are the Subnet ID (the

neighborhood)neighborhood) Last 8 bits are Host ID (the street address)Last 8 bits are Host ID (the street address)

Can be written as “Prefix + Length”Can be written as “Prefix + Length” 171.64.15.0/24 or 171.64.15/24171.64.15.0/24 or 171.64.15/24

Page 19: TCP/IP Lecture 2

Subnetting at StanfordSubnetting at Stanford

Gates-rtr 171.64.74.58

171.64.74.0/24

171.64.1.178

yuba

border-rtr

dcl-rtr

bbr2-rtr

171.64.1.161

171.64.1.160/27171.64.0.0/16

Stanford Class BAddress

171.64.74.1

171.64.1.132To: cenic.net

To: cogentco.com

171.64.1.152

171.64.1.145

171.64.1.133

171.64.1.144/28

171.64.1.132/30

Page 20: TCP/IP Lecture 2

IP RoutingIP Routing Routers are not omniscientRouters are not omniscient

Next-HopNext-Hop Hop-by-HopHop-by-Hop Thus IP makes no guaranteesThus IP makes no guarantees

except to try it’s best (”Best Effort”)except to try it’s best (”Best Effort”) packets may get there out of order, packets may get there out of order,

garbled, duplicatedgarbled, duplicated may not get there at all!may not get there at all! Unreliable datagram serviceUnreliable datagram service

Page 21: TCP/IP Lecture 2

IP Routing Hop-by-HopIP Routing Hop-by-Hop

128.9/16128.9.16/20

128.9.176/20

128.9.19/24128.9.25/24

142.12/19

65/8Prefix Port

3227213

128.17.14.1128.17.14.1

128.17.20.1

128.17.10.1128.17.14.1

128.17.16.1

128.17.16.1Next-hop

R1

R2

R3

R4

12

3

128.17.20.1

128.17.16.1

e.g. 128.9.16.14 => Port 2

Forwarding/routing table

How a Router Forwards Datagrams

Page 22: TCP/IP Lecture 2

Classless Interdomain Classless Interdomain Routing (CIDR)Routing (CIDR)

0 232-1

Page 23: TCP/IP Lecture 2

Classless Interdomain Classless Interdomain Routing (CIDR)Routing (CIDR)

0 232-1

128.9/16

128.9.0.0

216

142.12/1965/8

128.9.16.14

Page 24: TCP/IP Lecture 2

Classless Interdomain Classless Interdomain Routing (CIDR)Routing (CIDR)

0 232-1

128.9/16

128.9.16.14

128.9.16/20128.9.176/20

128.9.19/24128.9.25/24

Page 25: TCP/IP Lecture 2

Classless Interdomain Classless Interdomain Routing (CIDR)Routing (CIDR)

0 232-1

128.9/16

128.9.16.14

128.9.16/20128.9.176/20

128.9.19/24128.9.25/24

Page 26: TCP/IP Lecture 2

Five Minute Break Five Minute Break

Page 27: TCP/IP Lecture 2

Network ProgramsNetwork Programs hosthost pingping traceroutetraceroute nslookupnslookup

Page 28: TCP/IP Lecture 2

Summary of IPSummary of IP Connectionless/DatagramConnectionless/Datagram Unreliable/Best EffortUnreliable/Best Effort

Page 29: TCP/IP Lecture 2

Transmission Control Transmission Control ProtocolProtocol

App

Transport

Network

Link

TCP / UDP

IP

Data Hdr

Data Hdr

TCP Segment

IP Datagram

Protocol Stack

Page 30: TCP/IP Lecture 2

CharacteristicsCharacteristics Connection-OrientedConnection-Oriented ReliableReliable Byte-StreamByte-Stream Flow Control Flow Control

(aka Congestion Control)(aka Congestion Control)

Page 31: TCP/IP Lecture 2

Three PhasesThree Phases Establish ConnectionEstablish Connection Data TransferData Transfer Terminate ConnectionTerminate Connection

Page 32: TCP/IP Lecture 2

Establishing the Establishing the ConnectionConnection

Connection Setup3-way handshake

(Active)Client

(Passive)Server

Syn

Syn + Ack

Ack

Page 33: TCP/IP Lecture 2

Data TransferData Transfer

Byte 0

Byte 1

Byte 2

Byte 3

Byte 0

Byte 1

Byte 2

Byte 3

Host A

Host B

Byte 80

Byte 80

Page 34: TCP/IP Lecture 2

Data TransferData Transfer

Byte 0

Byte 1

Byte 2

Byte 3

Byte 0

Byte 1

Byte 2

Byte 3

Host A

Host B

Byte 80

TCP Data

TCP DataB

yte 80

Page 35: TCP/IP Lecture 2

Maintaining the Maintaining the “Connection”“Connection”

IP HdrIP Data

TCP HdrTCP Data

Src port Dst port

Sequence #

Ack Sequence #HLEN

4RSVD

6 URG

ACK

PSH

RST

SYN

FIN

Flags Window Size

Checksum Urg Pointer

(TCP Options)

0 15 31

TCP Data

Src/dst port numbersand IP addresses

uniquely identify socket

Page 36: TCP/IP Lecture 2

Terminating the Terminating the ConnectionConnection

Connection Close/Teardown2 x 2-way handshake

(Active)Client

(Passive)Server

Fin

(Data +) Ack

Fin

Ack

Page 37: TCP/IP Lecture 2

Connection-OrientedConnection-Oriented ReliableReliable Byte-StreamByte-Stream Flow Control Flow Control

(aka Congestion Control)(aka Congestion Control)

Page 38: TCP/IP Lecture 2

Reliability & Flow ControlReliability & Flow Control Sequence numbers & Acknowledgements Sequence numbers & Acknowledgements

(ACKs)(ACKs) Receiver detects Corrupt, Lost, Duplicated, Receiver detects Corrupt, Lost, Duplicated,

Out-of-order Out-of-order Tell sender which packets it has received Tell sender which packets it has received

correctlycorrectly Sender can resendSender can resend

In Flight Window (Window Size)In Flight Window (Window Size) Sender only has N unacknowledged packets Sender only has N unacknowledged packets

“in“in

Page 39: TCP/IP Lecture 2

Sending a MessageSending a Message

Network Layer

Link Layer

Ron Leslie

Leland.Stanford.edu Arachne.Berkeley.eduApplication Layer

Transport Layer

O.S. O.S.HeaderData HeaderData

HD

HD

HD

HD HD

HD

Page 40: TCP/IP Lecture 2

Connection-OrientedConnection-Oriented ReliableReliable Byte-StreamByte-Stream Flow Control Flow Control

(aka Congestion Control)(aka Congestion Control)

Page 41: TCP/IP Lecture 2

UDPUDP

App

Transport

Network

Link

TCP / UDP

IP

Data Hdr

Data Hdr

TCP Segment

IP Datagram

Protocol Stack

Page 42: TCP/IP Lecture 2

User Datagram Protocol User Datagram Protocol (UDP)(UDP)

Like TCP, in the Transport LayerLike TCP, in the Transport Layer CharacteristicsCharacteristics

Connectionless, Datagram, UnreliableConnectionless, Datagram, Unreliable Adds only Adds only application application

multiplexing/demultiplexingmultiplexing/demultiplexing and and checksummingchecksumming to IP to IP

Good for Streaming Media, Real-Good for Streaming Media, Real-time Multiplayer Networked Games, time Multiplayer Networked Games, VoIPVoIP

Page 43: TCP/IP Lecture 2

SummarySummary IP is the basis of InternetworkingIP is the basis of Internetworking TCP builds on top of IPTCP builds on top of IP

adds reliable, congestion-controlled, adds reliable, congestion-controlled, connection-oriented byte-stream.connection-oriented byte-stream.

UDP builds on top of IPUDP builds on top of IPallows access to IP functionalityallows access to IP functionality