Lec02 ReviewComputerNetwork
Lec02 ReviewComputerNetwork
1
Contents
• Internet protocol stack
• Application layer
• UDP & TCP
• Network layer
2
What’s the Internet?
mobile network
• Internet: “network of networks”
• Interconnected ISPs global ISP
• protocols control sending,
receiving of msgs home
• e.g., TCP, IP, HTTP, Skype, 802.11 network
regional ISP
• Internet standards
• RFC: Request for comments
• IETF: Internet Engineering Task
Force
institutional
network
3
What’s the Internet?
mobile network
• Infrastructure that provides
services to applications: global ISP
4
What’s a protocol?
human protocols: network protocols:
• “what’s the time?” • machines rather than
• “I have a question” humans
• introductions • all communication
activity in Internet
… specific msgs sent governed by protocols
… specific actions taken protocols define format, order
when msgs received, of msgs sent and received
or other events
among network entities,
and actions taken on msg
transmission, receipt
5
TCP/IP protocol stack
• application: supporting network
applications application
• FTP, SMTP, STTP
transport
• transport: host-host data transfer
• TCP, UDP network
• network: routing of datagrams from
link
source to destination
• IP, routing protocols physical
• link: data transfer between neighboring
network elements
• PPP, Ethernet
• physical: bits “on the wire”
6
source
message M application
Encapsulation
segment Ht M transport
datagram Hn Ht M network
frame Hl Hn Ht M link
physical
link
physical
switch
destination Hn Ht M network
M application Hl Hn Ht M link Hn Ht M
Ht M transport physical
Hn Ht M network
Hl Hn Ht M link router
physical
7
Application layer
• E-mail • Internet telephone
• Web • Real-time video
• Instant messaging conference
• Remote login • Massive parallel
• P2P file sharing
computing
• Multi-user network games
• Streaming stored video
clips
8
Creating a network app
application
Write programs that transport
network
• run on different end systems data link
physical
and
• communicate over a network.
• e.g., Web: Web server software
communicates with browser
software
No software written for
devices in network core application
application
transport
transport network
• Network core devices do not network data link
data link physical
function at app layer??? physical
9
Application architectures
• Client-server
• Peer-to-peer (P2P)
• Hybrid of client-server and P2P
10
Client-server architecure
client clients:
• communicate with server
• may be intermittently
client connected
• may have dynamic IP
addresses
• do not communicate directly
client with each other
Server
server:
• always-on host
client • permanent IP address
• server farms for scaling
11
Pure P2P architecture
• no always on server Peer Peer
• arbitrary end systems
directly communicate
• peers are intermittently
connected and change IP
addresses
• example: Gnutella
Highly scalable
Peer Peer
But difficult to manage
12
Hybrid of client-server and P2P
BitTorrent Client
• File transfer P2P
• File search centralized:
• Peers register content at central
server
• Peers query same central server
to locate content Server
Instant messaging
• Chatting between two users is
P2P
• Presence detection/location
centralized: Client
Client
• User registers its IP address with
central server when it comes
online
• User contacts central server to find P2P Comm.
IP addresses of buddies Client-Server Comm.
13
Processes communicating
Process: program running Client process: process
within a host. that initiates
• within same host, two communication
processes communicate Server process: process
using inter-process that waits to be
communication (defined contacted
by OS).
• processes in different Note: applications with
hosts communicate by P2P architectures have
exchanging messages client processes &
server processes
14
Sockets
host or host or
• process sends/receives server server
messages to/from its socket
controlled by
• Defined by app developer
process process
• Port number Socket
• IP Address address socket socket
15
Processes communicating
• Client process: sends request
• Server process: replies response
• Typically: single server - multiple clients
• The server does not need to know anything about the
client
• The client should always know something about the
server
• at least the socket address of the server
request response
server
wait handle wait
request 16
App-layer protocol defines
• Types of messages exchanged, e.g, request &
response messages
• Syntax of message types: what fields in messages &
how fields are delineated
• Semantics of the fields, e.g., meaning of information
in fields
• Rules for when and how processes send & respond
to messages
17
What transport service does an app need?
18
Transport services and protocols
• provide logical communication application
transport
between app processes running network
data link network
on different hosts physical data link
network physical
• transport protocols run in end data link
physical
systems network
data link
physical network
• send side: breaks app data link
physical
messages into segments,
network
passes to network layer data link
physical
• rcv side: reassembles
segments into messages, application
transport
passes to app layer network
data link
physical
• more than one transport protocol
available to apps
• Internet: TCP and UDP
19
Internet transport protocols services
TCP service: UDP service:
• reliable transport between
sending and receiving • unreliable data transfer
process between sending and
• flow control: sender won’t receiving process
overwhelm receiver
• does not provide:
• congestion control: throttle
sender when network reliability, flow control,
overloaded congestion control,
• does not provide: timing, timing, throughput
minimum throughput guarantee, security, or
guarantee, security
• connection-oriented: setup connection setup,
required between client
and server processes
20
Multiplexing/demultiplexing
multiplexing at sender:
handle data from multiple demultiplexing at receiver:
sockets, add transport header use header info to deliver
(later used for demultiplexing) received segments to correct
socket
application
21
How demultiplexing works
❖host receives IP 32 bits
datagrams source port # dest port #
▪ each datagram has source IP
address, destination IP address
other header fields
▪ each datagram carries one
transport-layer segment
▪ each segment has source,
application
destination port number
data
❖host uses IP addresses (payload)
& port numbers to direct
segment to appropriate TCP/UDP segment format
socket
22
UDP: User Datagram Protocol [RFC 768]
23
UDP demultiplexing
• Create sockets with port • When host receives UDP
numbers: segment:
mySocket = socket(AF_INET, • checks destination port
SOCK_DGRAM, 0) number in segment
• UDP socket identified by two- • directs UDP segment to
tuple: socket with that port number
(dest IP address, dest port number) • IP datagrams with different
source IP addresses and/or
source port numbers
directed to same socket
24
UDP demux
serverSocket =
socket(AF_INET,
mySocket = mySocket =
socket(AF_INET, SOCK_DGRAM, 0);
socket(AF_INET,
SOCK_DGRAM, 0); bind(…) SOCK_DGRAM, 0);
application
application application
P1
P3 P4
transport
transport transport
network
network link network
link physical link
physical physical
• point-to-point: • connection-oriented:
• one sender, one receiver • handshaking (exchange of
control msgs) init’s sender,
• reliable, in-order byte
receiver state before data
steam: exchange
• no “message boundaries”
• flow controlled:
• pipelined: • sender will not overwhelm
• TCP congestion and flow receiver
control set window size
• full duplex data:
• send & receive buffers • bi-directional data flow in
same connection
application application
socket
writes data reads data
socket
• MSS: maximum segment
door
TCP TCP
door
size
send buffer receive buffer
segment
26
TCP Connection Management: Setup
sending receiving
process process
application dat dat
transport a a
sender-side of receiver-side
reliable data of reliable data
Sender, receiver do not know transfer protocol transfer protocol
the “state” of each other, e.g.,
was a message received? transport
network
▪ unless communicated via a unreliable channel
message??????
reliable service implementation
28
TCP segment structure
32 bits
29
TCP sequence numbers, ACKs
outgoing segment from sender
Sequence numbers: source port # dest port #
sequence number
• byte stream “number” of acknowledgement number
rwnd
first byte in segment’s data checksum urg pointer
window size
Acknowledgements: N
30
TCP sequence numbers, ACKs
Host A Host B
User types‘C’
Seq=42, ACK=79, data = ‘C’
host ACKs receipt
of‘C’, echoes back ‘C’
Seq=79, ACK=43, data = ‘C’
host ACKs receipt
of echoed ‘C’
Seq=43, ACK=80
31
TCP: retransmission scenarios
Host A Host B Host A Host B
SendBase=92
Seq=92, 8 bytes of data Seq=92, 8 bytes of data
timeout
ACK=100
X
ACK=100
ACK=120
SendBase=120
32
TCP: retransmission scenarios
Host A Host B
33
TCP flow control
application
Q: What happens if network Application removing
process
from sender
34
TCP flow control
▪ TCP receiver “advertised” free
buffer space in rwnd field in TCP to application process
header
• RcvBuffer size set via socket RcvBuffer buffered data
options (typical default is 4096 bytes)
• many operating systems auto adjust rwnd free buffer space
RcvBuffer
▪ sender limits amount of unACKed
TCP segment payloads
(“in-flight”) data to received rwnd
▪ guarantees receive buffer will not TCP receiver-side buffering
overflow
35
TCP 3-way handshake
Server state
serverSocket = socket(AF_INET,SOCK_STREAM)
Client state serverSocket.bind((‘’,serverPort))
serverSocket.listen(1)
clientSocket = socket(AF_INET, SOCK_STREAM) connectionSocket, addr = serverSocket.accept()
LISTEN
clientSocket.connect((serverName,serverPort)) LISTEN
choose init seq num, x
send TCP SYN msg
SYNSENT SYNbit=1, Seq=x
choose init seq num, y
send TCP SYNACK
msg, acking SYN SYN RCVD
SYNbit=1, Seq=y
ACKbit=1; ACKnum=x+1
received SYNACK(x)
ESTAB indicates server is live;
send ACK for SYNACK;
this segment may contain ACKbit=1, ACKnum=y+1
client-to-server data
received ACK(y)
indicates client is live
ESTAB
36
Connection-oriented demux
• TCP socket identified by • Server host may support
4-tuple: many simultaneous TCP
• source IP address sockets:
• source port number • each socket identified by its
• dest IP address own 4-tuple
• dest port number • Web servers have different
• recv host uses all four sockets for each
values to direct segment connecting client
to appropriate socket
37
Connection-oriented demux: example
application
application P4 P5 P6 application
P3 P2 P3
transport
transport transport
network
network link network
link physical link
physical server: IP physical
address B
39
Network layer
application
layer physical
application
network transport
• network layer protocols in network
data link
physical
network
data link
network
data link
every host, router data link
physical
physical physical
41
Interplay between routing and forwarding
routing algorithm routing algorithm determines
end-end-path through network
value in arriving
packet’s header
0111 1
3 2
42
Why an internet layer?
Why not one big flat LAN?
Different LAN protocols
Flat address space not scalable
IP provides:
Global addressing
Scaling to WANs
Virtualization of network
isolates end-to-end protocols
from network details/changes
“hourglass model”
(Steve Deering)
43
IP addressing: introduction
223.1.1.1
• interface: connection
between host/router and 223.1.3.27
223.1.1.3
physical link 223.1.2.2
44
IP addressing: “class-full”
class
1.0.0.0 to
A 0 network host 127.255.255.255
B network 128.0.0.0 to
10 host
191.255.255.255
192.0.0.0 to
C 110 network host
223.255.255.255
224.0.0.0 to
D 1110 multicast address
239.255.255.255
32 bits
• Class-full addressing:
• inefficient use of address space, address space exhaustion
• e.g., class B net allocated enough addresses for 65K hosts, even
if only 2K hosts in that network
45
IP addressing: “class-less”
CIDR: Classless Inter-Domain Routing
• subnet portion of address of arbitrary length
• address format: a.b.c.d/x, where x is # bits in subnet portion of
address
subnet host
part part
11001000 00010111 00010000 00000000
200.23.16.0/23
46
Address Allocation for Private Internets
• RFC1918
10.0.0.0/8
Private address 172.16.0.0/16 → 172.31.0.0/16
192.168.0.0/24 → 192.168.255.0 /24
Loopback address 127.0.0.0 /8
224.0.0.0
Multicast address
~239.255.255.255
47
NAT: network address translation
10.0.0.4
10.0.0.2
138.76.29.7
10.0.0.3
51
NAT: network address translation
• 16-bit port-number field:
• 60,000 simultaneous connections with a single
LAN-side address!
• NAT is controversial:
• routers should only process up to layer 3
• violates end-to-end argument
• NAT possibility must be taken into account by app
designers, e.g., P2P applications
• address shortage should instead be solved by
IPv6
52
NAT traversal problem
• client wants to connect to
server with address 10.0.0.1 10.0.0.1
• server address 10.0.0.1 local to client
LAN (client can’t use it as ?
destination addr) 10.0.0.4
• only one externally visible NATed
address: 138.76.29.7 138.76.29.7 NAT
router
• solution1: statically configure
NAT to forward incoming
connection requests at given
port to server
• e.g., (123.76.29.7, port 2500)
always forwarded to 10.0.0.1 port
25000
53
NAT traversal problem
• solution 2: Universal Plug and
Play (UPnP) Internet Gateway 10.0.0.1
Device (IGD) Protocol. Allows
NATed host to: IGD
❖ learnpublic IP address
(138.76.29.7)
❖ add/remove port mappings (with NAT
lease times) router
54
NAT traversal problem
• solution 3: relaying (used in Skype)
• NATed client establishes connection to relay
• external client connects to relay
• relay bridges packets between to connections
2. connection to
relay initiated 1. connection to 10.0.0.1
by client relay initiated
by NATed host
3. relaying
client established
138.76.29.7 NAT
router
55
NAT traversal problem
• solution 4: NAT hole punching. Example: STUN protocol
56