You are on page 1of 45

Chương 4: Tầng Mạng

Mục tiêu Học cái gì:


 Nguyên tắc triển khai dịch vụ  Các dịch vụ của tầng Mạng
của tầng Mạng:  Nguyên tắc định tuyến: lựa chọn
 Định tuyến (Lựa chọn đường đi
đường đi)  Định tuyến phân cấp
 Mở rộng phạm vi
 Giao thức IP
 Cách thức router hoạt động
 Giao thức định tuyến trên Internet
 Nâng cao: IPv6, multicast
 Cài đặt những dịch vụ này
 Nội miền
trên Internet như thế nào
 Liên miền
 Kiến trúc Router
 IPv6
 NAT, PAT
 multicast routing

4: Network Layer 4a-1


Chức năng của tầng Mạng
 Chuyển gói tin từ máy tính gửi application
đến máy tính nhận transport
network
 Giao thức tầng Mạng có mặt trên data link
physical
network
network data link network
tất cả máy tính, router data link physical data link
physical physical

Ba chức năng cơ bản: network


data link
 Lựa chọn tuyến đường: Tuyến physical network
data link
đường gói tin đi từ nguồn đến physical

đích. Thuật toán định tuyến network


network
data link
data link
 Chuyển mạch: Router chuyển gói physical
physical

tin từ một đầu vào này ra đầu ra network


data link application
thích hợp physical transport
network
 Thiết lập tuyến đường: một số data link
physical
kiến trúc mạng đòi hỏi tuyến
đường gói tin đi qua phải được
thiết lập trước

4: Network Layer 4a-2


Mô hình Dịch vụ tầng Mạng
?: Chọn Mô hình dịch vụ nào
của “kênh truyền” để
Vấn đề quan trọng nhất
chuyển gói dữ liệu từ nơi mà tầng Mạng phải trả lời
gửi đến nơi nhận ? :
Trừu tượng hóa dịch vụ

? ?
 Đảm bảo băng thông không?
 Đảm bảo tốc độ nhận đều không Mạch ảo
(không có hiện tượng jitter)? hay

?
 Không mất mát ?
Mạch gói?
 Đảm bảo thứ tự?
 Có thông báo về tình trạng tắc
nghẽn cho bên gửi không ?

4: Network Layer 4a-3


Chuyển mạch ảo
Tuyến đường từ đích đến nguồn giống như mạch trong mạng
điện thoại
 Quan trọng : Hiệu suất
 Thiết lập kết nối dọc theo tuyến đường

 Thiết lập và Đóng kết nối trước khi truyền dữ liệu


 Mỗi packet mang định danh mạch ảo là VC identifier (Không phải địa chỉ máy đích)
 Tất cả router trên tuyến đường duy trì trạng thái của kết nối đi qua
 Kênh truyền ở tầng giao vận chỉ liên quan đến hai thực thể đầu cuối
 Tài nguyên của đường truyền (Băng thông, Bộ đệm) phải được cấp phát cho mỗi
mạch ảo
 Để đạt được hiệu suất như mạng điện thoại.

4: Network Layer 4a-4


Mạch ảo: Giao thức báo hiệu (Signal)

 Để Thiết lập và Đóng mạch ảo (VC)


 Có trong ATM, Frame-relay, X.25
 Không được sử dụng trên Internet ngày nay

application
6. Nhận dữ liệu application
transport 5. Chuyển dữ liệu
network 4. Thiết lập kết nối 3. Chấp nhận transport
data link 1. Khởi tạo 2. Cuộc gọi đến network
data link
physical
physical

4: Network Layer 4a-5


Mạng chuyển mạch gói: Mô hình Internet
 Không cần thiết lập đường truyền ở tầng Mạng
 routers: Không duy trì trạng thái các kết nối đi qua
 no network-level concept of “connection”

 Gói tin được định tuyến dựa trên địa chỉ gói nhận
 Các gói tin có thể đi theo những tuyến đường khác nhau

application
application
transport
transport
network
data link 1. Gửi dữ liệu 2. Nhận dữ liệu network
data link
physical
physical

4: Network Layer 4a-6


Mô hình Dịch vụ ở tầng Mạng
Guarantees ?
Network Service Congestion
Architecture Model Bandwidth Loss Order Timing feedback

Internet best effort none no no no no (inferred


via loss)
ATM CBR constant yes yes yes no
rate congestion
ATM VBR guaranteed yes yes yes no
rate congestion
ATM ABR guaranteed no yes no yes
minimum
ATM UBR none no yes no no

 Mô hình dịch vụ trên Internet : Intserv, Diffserv


 Chương 6

4: Network Layer 4a-7


Chuyển Mạch hay Chuyển Gói?

Internet ATM
 Dữ liệu trao đổi giữa máy tính  Phát triển từ Mạng điện thoại
Dịch vụ mang tính “co giãn”,  Hội thoại của con người:
không đòi hỏi chặt chẽ thời  Yêu cầu nghiêm ngặt về
gian.
Thời gian và Độ tin cậy
 Thiết bị đầu cuối “thông minh”
 Đảm bảo chất lượng dịch
 Có thể thích nghi, Kiểm soát,
vụ
Khắc phục lỗi  Thiết bị đầu cuối đơn giản
 “Lõi” mạng đơn giản, Phức
 Máy điện thoại
tạp đặt ở “Rìa”
 Phức tạp đặt ở bên trong
 Nhiều kiểu môi trường truyền dẫn
Mạng
 Các đặc điểm khác nhau
 Không thể có chung chất
lượng dịch vụ

4: Network Layer 4a-8


Định tuyến
Giao thức định tuyến
Mục tiêu: xác định tuyến đường 5
“tốt” (dãy các router) trên mạng
3
từ nút gửi đến nút nhận. B C 5
2
A 2 1 F
3
Đồ thị để xây dựng thuật 1 2
toán định tuyến: D E
1
 Đỉnh là Router
 Cạnh là các đường kết nối  Đường đi “tốt”:
trực tiếp  Thường có giá trung bình

 Giá của cạnh: Độ trễ, Chi nhỏ nhất


phí, hay Mức độ Tắc nghẽn  Có thể có định nghĩa khác

4: Network Layer 4a-9


Phân loại Thuật toán Định tuyến
Thông tin Toàn cục hay Động hay Tĩnh?
Phân tán? Tĩnh (Static):
Toàn cục (Global):  Router rất ít thay đổi
 Mọi router đều biết về toàn bộ Động (Dynamic):
topo của đồ thị  Router thay đổi thường xuyên
 Thuật toán “link state”  Cập nhật định kỳ
Phân tán (Decentralized):  Chạy lại thuật toán khi có 1
 Mỗi router chỉ biết về router và giá đường đi thay đổi
giá đến các router hàng xóm
 Thực hiện quá trình trao đổi
thông tin với các “hàng xóm”
 Thuật toán “distance vector”

4: Network Layer 4a-10


Thuật toán Định tuyến Link-State

Thuật toán Dijkstra Ký hiệu:


 net topology, link costs known  c(i,j): link cost from node i to
to all nodes j. cost infinite if not direct
 accomplished via “link state neighbors
broadcast”  D(v): current value of cost of
 all nodes have same info
path from source to dest. V
 computes least cost paths from  p(v): predecessor node along
one node (‘source”) to all other path from source to v, that is
nodes next v
 gives routing table for that
 N: set of nodes whose least
node
cost path definitively known
 iterative: after k iterations,
know least cost path to k dest.’s

4: Network Layer 4a-11


Dijsktra’s Algorithm
1 Initialization:
2 N = {A}
3 for all nodes v
4 if v adjacent to A
5 then D(v) = c(A,v)
6 else D(v) = infty
7
8 Loop
9 find w not in N such that D(w) is a minimum
10 add w to N
11 update D(v) for all v adjacent to w and not in N:
12 D(v) = min( D(v), D(w) + c(w,v) )
13 /* new cost to v is either old cost to v or known
14 shortest path cost to w plus cost from w to v */
15 until all nodes in N

4: Network Layer 4a-12


Dijkstra’s algorithm: example
Step start N D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E) D(F),p(F)
0 A 2,A 5,A 1,A infinity infinity
1 AD 2,A 4,D 2,D infinity
2 ADE 2,A 3,E 4,E
3 ADEB 3,E 4,E
4 ADEBC 4,E
5 ADEBCF

5
3
B C 5
2
A 2 1 F
3
1 2
D E
1

4: Network Layer 4a-13


Dijkstra’s algorithm, discussion
Algorithm complexity: n nodes
 each iteration: need to check all nodes, w, not in N
 n*(n+1)/2 comparisons: O(n**2)
 more efficient implementations possible: O(nlogn)

Oscillations possible:
 e.g., link cost = amount of carried traffic

1 A A A A
1+e 2+e 0 0 2+e 2+e 0
D 0 0 B D 1+e 1 B D B D 1+e 1 B
0 0
0 e 0 0 1 1+e 0 e
1
C C C C
1
e
… recompute … recompute … recompute
initially
routing
4: Network Layer 4a-14
Distance Vector Routing Algorithm
iterative:
 continues until no nodes
Distance Table data structure
 each node has its own
exchange info.
 self-terminating: no  row for each possible destination

“signal” to stop  column for each directly-attached


neighbor to node
asynchronous:
 example: in node X, for dest. Y via
 nodes need not exchange
neighbor Z:
info/iterate in lock step!
distributed:
 each node communicates distance from X to
X = Y, via Z as next hop
only with directly-attached D (Y,Z)
neighbors Z
= c(X,Z) + minw{D (Y,w)}

4: Network Layer 4a-15


Distance Table: example

1 cost to destination via


B C E
7 D () A B D
A 8 2
1 A 1 14 5
E D
2
B 7 8 5

destination
E D
D (C,D) = c(E,D) + minw {D (C,w)}
= 2+2 = 4 C 6 9 4
E D
D (A,D) = c(E,D) + min {D (A,w)}
w D 4 11 2
= 2+3 = 5 loop!
E B
D (A,B) = c(E,B) + minw{D (A,w)}
= 8+6 = 14
loop!
4: Network Layer 4a-16
Distance table gives routing table
cost to destination via
E Outgoing link
D () A B D to use, cost

A 1 14 5 A A,1

B 7 8 5 B D,5
destination

destination
C 6 9 4 C D,4

D 4 11 2 D D,4

Distance table Routing table

4: Network Layer 4a-17


Distance Vector Routing: overview
Iterative, asynchronous: each Each node:
local iteration caused by:
 local link cost change
 message from neighbor: its wait for (change in local link
least cost path change from cost of msg from neighbor)
neighbor
Distributed:
 each node notifies neighbors
recompute distance table
only when its least cost path to
any destination changes
if least cost path to any dest
 neighbors then notify their
neighbors if necessary has changed, notify
neighbors

4: Network Layer 4a-18


Distance Vector Algorithm:

At all nodes, X:
1 Initialization:
2 for all adjacent nodes v:
3 D X(*,v) = infty /* the * operator means "for all rows" */
X
4 D (v,v) = c(X,v)
5 for all destinations, y
X
6 send min D (y,w) to each neighbor /* w over all X's neighbors */
w

4: Network Layer 4a-19


Distance Vector Algorithm (cont.):
8 loop
9 wait (until I see a link cost change to neighbor V
10 or until I receive update from neighbor V)
11
12 if (c(X,V) changes by d)
13 /* change cost to all dest's via neighbor v by d */
14 /* note: d could be positive or negative */
15 for all destinations y: D X(y,V) = DX(y,V) + d
16
17 else if (update received from V wrt destination Y)
18 /* shortest path from V to some Y has changed */
19 /* V has sent a new value for its min w DV(Y,w) */
20 /* call this received new value is "newval" */
21 for the single destination y: D X(Y,V) = c(X,V) + newval
22
X
23 if we have a new minw D (Y,w)for any destination Y
X
24 send new value of min w D (Y,w) to all neighbors
25
26 forever 4: Network Layer 4a-20
Distance Vector Algorithm: example

Y
2 1
X Z
7

4: Network Layer 4a-21


Distance Vector Algorithm: example

Y
2 1
X Z X Z
7 D (Y,Z) = c(X,Z) + minw{D (Y,w)}
= 7+1 = 8

X Y
D (Z,Y) = c(X,Y) + minw {D (Z,w)}
= 2+1 = 3

4: Network Layer 4a-22


Distance Vector: link cost changes
Link cost changes:
 node detects local link cost change
1
Y
 updates distance table (line 15) 4 1
 if cost change in least cost path, notify X Z
50
neighbors (lines 23,24)

algorithm
terminates
“good
news
travels
fast”

4: Network Layer 4a-23


Distance Vector: link cost changes

Link cost changes: 60


 good news travels fast Y
4 1
 bad news travels slow - “count
X Z
to infinity” problem! 50

algorithm
continues
on!

4: Network Layer 4a-24


Distance Vector: poisoned reverse
If Z routes through Y to get to X : 60
 Z tells Y its (Z’s) distance to X is infinite (so Y won’t Y
route to X via Z) 4 1
 will this completely solve count to infinity problem? X Z
50

algorithm
terminates

4: Network Layer 4a-25


Comparison of LS and DV algorithms
Message complexity Robustness: what happens if
 LS: with n nodes, E links, O(nE) router malfunctions?
msgs sent each
LS:
 DV: exchange between neighbors
only
 node can advertise incorrect
link cost
 convergence time varies
 each node computes only its
Speed of Convergence own table
 LS: O(n**2) algorithm requires DV:
O(nE) msgs  DV node can advertise
 may have oscillations
incorrect path cost
 DV: convergence time varies  each node’s table used by
 may be routing loops others
 count-to-infinity problem • error propagate thru network

4: Network Layer 4a-26


Hierarchical Routing
Our routing study thus far - idealization
 all routers identical
 network “flat”
… not true in practice

scale: with 50 million administrative autonomy


destinations:  internet = network of networks
 can’t store all dest’s in routing  each network admin may want to
tables! control routing in its own network
 routing table exchange would
swamp links!

4: Network Layer 4a-27


Hierarchical Routing
 aggregate routers into gateway routers
regions, “autonomous  special routers in AS
systems” (AS)  run intra-AS routing
 routers in same AS run protocol with all other
routers in AS
same routing protocol
 also responsible for routing
 “intra-AS” routing protocol
to destinations outside AS
 routers in different AS can  run inter-AS routing
run different intra-AS
protocol with other
routing protocol
gateway routers

4: Network Layer 4a-28


Intra-AS and Inter-AS routing
C.b Gateways:
B.a
•perform inter-AS
A.a routing amongst
b A.c c themselves
a C a
b •perform intra-AS
a B
routers with other
d c routers in their
A b
AS

network layer
inter-AS, intra-AS link layer
routing in
gateway A.c physical layer

4: Network Layer 4a-29


Intra-AS and Inter-AS routing
Inter-AS
C.b routing
between B.a
A.a A and B Host
b A.c c h2
a C a
b
a B
Host d c Intra-AS routing
h1 b
A within AS B
Intra-AS routing
within AS A

 We’ll examine specific inter-AS and intra-AS Internet


routing protocols shortly

4: Network Layer 4a-30


The Internet Network layer
Host, router network layer functions:

Transport layer: TCP, UDP

Routing protocols IP protocol


•path selection •addressing conventions
•RIP, OSPF, BGP •datagram format
Network •packet handling conventions
layer routing
table ICMP protocol
•error reporting
•router “signaling”

Link layer

physical layer

4: Network Layer 4a-31


IP Addressing: introduction
 IP address: 32-bit 223.1.1.1

identifier for host, router 223.1.2.1


223.1.1.2
interface 223.1.1.4 223.1.2.9
 interface: connection
223.1.2.2
between host, router and 223.1.1.3 223.1.3.27

physical link
 router’s typically have
multiple interfaces 223.1.3.1 223.1.3.2
 host may have multiple
interfaces
 IP addresses associated
with interface, not host, 223.1.1.1 = 11011111 00000001 00000001 00000001
router
223 1 1 1

4: Network Layer 4a-32


IP Addressing
 IP address: 223.1.1.1

 network part (high order 223.1.2.1


223.1.1.2
bits) 223.1.1.4 223.1.2.9
 host part (low order bits)
223.1.2.2
 What’s a network ? (from 223.1.1.3 223.1.3.27
IP address perspective)
 device interfaces with LAN
same network part of IP 223.1.3.1 223.1.3.2
address
 can physically reach each
other without intervening
router network consisting of 3 IP networks
(for IP addresses starting with 223,
first 24 bits are network address)

4: Network Layer 4a-33


IP Addressing
223.1.1.2
How to find the networks? 223.1.1.1 223.1.1.4

 Detach each interface 223.1.1.3


from router, host
 create “islands of isolated 223.1.9.2 223.1.7.0
networks

223.1.9.1 223.1.7.1
223.1.8.1 223.1.8.0

223.1.2.6 223.1.3.27

Interconnected 223.1.2.1 223.1.2.2 223.1.3.1 223.1.3.2


system consisting
of six networks

4: Network Layer 4a-34


IP Addresses
given notion of “network”, let’s re-examine IP addresses:
“class-full” addressing:

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

4: Network Layer 4a-35


IP addressing: CIDR
 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
 CIDR: Classless InterDomain Routing
 network portion of address of arbitrary length
 address format: a.b.c.d/x, where x is # bits in network portion of
address

network host
part part
11001000 00010111 00010000 00000000
200.23.16.0/23
4: Network Layer 4a-36
IP addresses: how to get one?

Hosts (host portion):


 hard-coded by system admin in a file
 DHCP: Dynamic Host Configuration Protocol: dynamically
get address: “plug-and-play”
 host broadcasts “DHCP discover” msg
 DHCP server responds with “DHCP offer” msg
 host requests IP address: “DHCP request” msg
 DHCP server sends address: “DHCP ack” msg

4: Network Layer 4a-37


IP addresses: how to get one?
Network (network portion):
 get allocated portion of ISP’s address space:

ISP's block 11001000 00010111 00010000 00000000 200.23.16.0/20

Organization 0 11001000 00010111 00010000 00000000 200.23.16.0/23

Organization 1 11001000 00010111 00010010 00000000 200.23.18.0/23

Organization 2 11001000 00010111 00010100 00000000 200.23.20.0/23


... ….. …. ….

Organization 7 11001000 00010111 00011110 00000000 200.23.30.0/23

4: Network Layer 4a-38


Hierarchical addressing: route aggregation
Hierarchical addressing allows efficient advertisement of routing
information:

Organization 0
200.23.16.0/23
Organization 1
“Send me anything
200.23.18.0/23 with addresses
Organization 2 beginning
200.23.20.0/23 . Fly-By-Night-ISP 200.23.16.0/20”
.
. . Internet
.
Organization 7 .
200.23.30.0/23
“Send me anything
ISPs-R-Us
with addresses
beginning
199.31.0.0/16”

4: Network Layer 4a-39


Hierarchical addressing: more specific routes

ISPs-R-Us has a more specific route to Organization 1


Organization 0
200.23.16.0/23

“Send me anything
with addresses
Organization 2 beginning
200.23.20.0/23 . Fly-By-Night-ISP 200.23.16.0/20”
.
. . Internet
.
Organization 7 .
200.23.30.0/23
“Send me anything
ISPs-R-Us
with addresses
Organization 1 beginning 199.31.0.0/16
or 200.23.18.0/23”
200.23.18.0/23

4: Network Layer 4a-40


IP addressing: the last word...

Q: How does an ISP get block of addresses?


A: ICANN: Internet Corporation for Assigned
Names and Numbers
 allocates addresses
 manages DNS
 assigns domain names, resolves disputes

4: Network Layer 4a-41


Getting a datagram from source to dest.
routing table in A
Dest. Net. next router Nhops
223.1.1 1
223.1.2 223.1.1.4 2
IP datagram: 223.1.3 223.1.1.4 2
misc source dest
data
fields IP addr IP addr A 223.1.1.1
 datagram remains unchanged, as it 223.1.2.1
travels source to destination 223.1.1.2
 addr fields of interest here 223.1.1.4 223.1.2.9
B
223.1.2.2
223.1.1.3 223.1.3.27 E

223.1.3.1 223.1.3.2

4: Network Layer 4a-42


Getting a datagram from source to dest.

misc Dest. Net. next router Nhops


data
fields 223.1.1.1 223.1.1.3
223.1.1 1
223.1.2 223.1.1.4 2
Starting at A, given IP datagram
223.1.3 223.1.1.4 2
addressed to B:
 look up net. address of B
A 223.1.1.1
 find B is on same net. as A
223.1.2.1
 link layer will send datagram directly 223.1.1.2
to B inside link-layer frame 223.1.1.4 223.1.2.9
 B and A are directly connected B
223.1.2.2
223.1.1.3 223.1.3.27 E

223.1.3.1 223.1.3.2

4: Network Layer 4a-43


Getting a datagram from source to dest.

misc Dest. Net. next router Nhops


data
fields 223.1.1.1 223.1.2.3
223.1.1 1
223.1.2 223.1.1.4 2
Starting at A, dest. E:
223.1.3 223.1.1.4 2
 look up network address of E
 E on different network
A 223.1.1.1
 A, E not directly attached
223.1.2.1
 routing table: next hop router to E 223.1.1.2
is 223.1.1.4 223.1.1.4 223.1.2.9
 link layer sends datagram to B
223.1.2.2
router 223.1.1.4 inside link-layer 223.1.1.3 223.1.3.27 E
frame
223.1.3.1 223.1.3.2
 datagram arrives at 223.1.1.4
 continued…..
4: Network Layer 4a-44
Getting a datagram from source to dest.
Dest. next
misc network router Nhops interface
data
fields 223.1.1.1 223.1.2.3
223.1.1 - 1 223.1.1.4
Arriving at 223.1.4, destined for 223.1.2 - 1 223.1.2.9
223.1.3 - 1 223.1.3.27
223.1.2.2
 look up network address of E
A 223.1.1.1
 E on same network as router’s
223.1.2.1
interface 223.1.2.9 223.1.1.2
 router, E directly attached 223.1.1.4 223.1.2.9
B
 link layer sends datagram to 223.1.2.2
223.1.2.2 inside link-layer frame 223.1.1.3 223.1.3.27 E
via interface 223.1.2.9 223.1.3.1 223.1.3.2
 datagram arrives at 223.1.2.2!!!
(hooray!)
4: Network Layer 4a-45

You might also like