Professional Documents
Culture Documents
Lec02.ReviewComputerNetwork Linhdt
Lec02.ReviewComputerNetwork Linhdt
NETWORKS
1
Contents
• Computer Networks
• Internet protocol stack
• Application layer
• TCP & UDP
• Internet 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
Vì sao phải phân tầng?
airplane routing airplane routing airplane routing airplane routing airplane routing
9
OSI and TCP/IP models
Application layer
Application
Presentation layer HTTP, FTP, SMTP…
Session layer
Transport layer TCP UDP
Network layer IP
Datalink layer Network Interface
Physical layer Physical
OSI and TCP/IP models
• OSI model: reference model
• TCP model: Internet model
• Transport layer: TCP/UDP
• Network layer: IP + routing protocols.
11
Internet protocols mapping on TCP/IP
12
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
13
OSI and TCP/IP models
• Layering Makes it Easier
• Application programmer
• Doesn’t need to send IP packets
• Doesn’t need to send Ethernet frames
• Doesn’t need to know how TCP implements reliability
• Only need a way to pass the data down
• Socket is the API to access transport layer functions
14
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
15
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
16
Application architectures
• Client-server
• Peer-to-peer (P2P)
• Hybrid of client-server and P2P
17
Client-server architecure
client server:
• “Always” online waiting for
requests from clients
client • Permanent IP address
clients:
• Request services from
server
client • May have dynamic IP
Server
addresses
• Do not communicate
directly with each other
E.g: web, mail…
client
18
Pure P2P architecture
• No central server Peer Peer
• Peers have equal role
• Peers can communicate
directly to each other
• Peers do not need to be
always online
Example: Gnutella
Highly scalable
Peer Peer
But difficult to manage
19
Hybrid of client-server and P2P
21
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
22
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 23
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
controlled
by OS
24
Internet connections (TCP/IP)
25
Internet connections (TCP/IP)
26
App-layer protocol defines
• Types of messages exchanged, eg, request &
response messages
• Syntax of message types: what fields in messages &
how fields are delineated
• Semantics of the fields, ie, meaning of information in
fields
• Rules for when and how processes send & respond
to messages
27
What transport service does an app need?
28
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
29
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,
guarantee, security
• connection-oriented: setup orconnection setup,
required between client
and server processes
30
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
31
Transport layer Mux/Demux
32
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
33
UDP: User Datagram Protocol [RFC 768]
34
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
35
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
38
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
40
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
42
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
44
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
45
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)
46
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
47
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
• Classful 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
48
IP addressing: “class-less”
CIDR: Classless InterDomain 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
49
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
50
IP
IP: Internet Protocol
• Forward data packet between distance network nodes (routers or
hosts)
• Using routing table built by routing protocols such as OSPF, RIP …
• IP address
• Is assigned to each network interface
• IP v4: 32 bits
• 133.113.215.10
• IP v6: 128 bits
• 2001:200:0:8803::53
• A host may have a domain name
• Conversion IP <-> domain name: DNS
• Ex: soict.hust.edu.vn <--> 202.191.56.65
51
NAT: network address translation
10.0.0.4
10.0.0.2
138.76.29.7
10.0.0.3
55
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
56
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
57
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
58
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
59
NAT traversal problem
• solution 4: NAT hole punching. Example: STUN protocol
60