Professional Documents
Culture Documents
Chapter - 05 - Network Layer and IP
Chapter - 05 - Network Layer and IP
❑ Cài đặt, tính toán chi phí thấp nhất của packet
Mục tiêu
Hiểu các nguyên lý nền tảng của các dịnh vụ
tầng network:
Các mô hình dịch vụ tầng network
forwarding so với routing
Cách mà router hoạt động
routing (chọn đường)
broadcast, multicast
Hiện thực trong Internet
Nội dung
4.1 Giới thiệu 4.4 IP: Internet Protocol
4.2 Cấu trúc bên trong của Định dạng Datagram
Router IPv4 addressing
4.3 Các thuật toán Routing ICMP
IPv6
Link state
Distance Vector 4.5 Routing in the Internet
Hierarchical routing RIP
OSPF
BGP
4.6 Broadcast and multicast
routing
4-3
Tầng Network
0111 1
3 2
Nội dung
4.1 Giới thiệu 4.4 Các thuật toán Routing
4.2 Cấu trúc bên trong của Link state
Router Distance Vector
4.3 IP: Internet Protocol Hierarchical routing
4-9
Tổng quan kiến trúc Router
2 chức năng chính của Router:
Chạy các giao thức/thuật toán routing (định tuyến):
RIP, OSPF, BGP.
Chuyển tiếp các Datagram từ đường link vào tới
đường link ra.
Tầng Internet Network
Link layer
physical layer
Nội dung
4.1 Giới thiệu 4.4 IP: Internet Protocol
4.2 Cấu trúc bên trong của Định dạng Datagram
Router IPv4 addressing
4.3 Các thuật toán Routing ICMP
IPv6
Link state
Distance Vector 4.5 Routing in the Internet
Hierarchical routing RIP
OSPF
BGP
4.6 Broadcast and multicast
routing
4-12
Mô hình đồ thị
5
3
v w 5
2
u 2 1 z
3
1 2
x 1
y
Đồ thị: G = (N,E)
E = tập hợp các kết nối ={ (u,v), (u,x), (v,x), (v,w), (x,w), (x,y), (w,y), (w,z), (y,z) }
Ghi chú: Mô hình đồ thị cũng hữu ích trong các ngữ cảnh khác nhau
Ví dụ:: P2P, Trong đó, N là các peer, E là tập các kết nối TCP
Mô hình đồ thị: Chi phí
5
• c(x,x’) chi phí kết nối (x,x’)
3
v w 5 - vd:, c(w,z) = 5
2
u 2 1 z
3
1 • Chi phí có thể là 1 hoặc liên
2
x 1
y nghịch với băng thông hoặc
tắc nghẽn.
Chi phí đường đi (x1, x2, x3,…, xp) = c(x1,x2) + c(x2,x3) + … + c(xp-1,xp)
Phân cấp:
Router biết neighbor kết nối vật lý và chi phí liên kết
đó
Lặp lại quá trình tính toán, trao đổi thông tin với các
neighbor.
Thuật toán: “distance vector”
Thuật toán Routing Link-State
5
3
v w 5
2
u 2 1 z
3
1 2
x 1
y
Dijkstra’s algorithm: example (2)
Resulting shortest-path tree from u:
v w
u z
x y
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
IP datagram format
Số hiệu version 32 bits
giao thức IP Tổng độ dài
Dộ dài header Datagram (bytes)
ver head. type of length
(bytes) len service Dành cho phân
Kiểu dữ liệu fragment Mảnh/tổng hợp
16-bit identifier flgs
offset
Số hops còn lại tối đa time to upper header
(decremented at live layer checksum
each router)
32 bit source IP address
32 bit destination IP address
upper layer protocol
to deliver payload to Options (if any) Ví dụ: trường time
ghi lại đường đi,
data danh sách router
(variable length, đi đến.
typically a TCP
or UDP segment)
Nội dung
4.1 Giới thiệu 4.4 Các thuật toán Routing
4.2 Cấu trúc bên trong của Link state
Router Distance Vector
4.3 IP: Internet Protocol Hierarchical routing
4-22
IP Addressing: giới thiệu
223.1.1.1 223.1.1.4
Có bao nhiêu Subnet?
223.1.1.3
223.1.9.2 223.1.7.0
223.1.9.1 223.1.7.1
223.1.8.1 223.1.8.0
223.1.2.6 223.1.3.27
200.23.16.0/23
IP addresses: Làm sao để lấy 1 địa chỉ?
Mục tiêu: Cho phép các host tự động lấy địa chỉ
IP từ náy chủ khi nó tham gia mạng.
Nguyên tắc hoạt động của DHCP:
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
DHCP client-server: Kịch bản
DHCP offer
src: 223.1.2.5, 67
dest: 255.255.255.255, 68
yiaddrr: 223.1.2.4
transaction ID: 654
Lifetime: 3600 secs
DHCP request
src: 0.0.0.0, 68
dest:: 255.255.255.255, 67
yiaddrr: 223.1.2.4
transaction ID: 655
time Lifetime: 3600 secs
DHCP ACK
src: 223.1.2.5, 67
dest: 255.255.255.255, 68
yiaddrr: 223.1.2.4
transaction ID: 655
Lifetime: 3600 secs
NAT: Network Address Translation
10.0.0.4
10.0.0.2
138.76.29.7
10.0.0.3
4-36
ICMP - Internet Control Message Protocol
Được sử dụng bởi các host và router để truyền thông tin
tầng network.
Routers sử dụng ICMP để thông báo các vấn đề cho IP
nguồn.
Được sử dụng cho các chức năng chẩn đoán và khắc phục
sự cố.
Các thông điệp ICMP được gói gọn trong 1 gói dữ liệu IP.
Nội dung
4.1 Giới thiệu 4.4 Các thuật toán Routing
4.2 Cấu trúc bên trong của Link state
Router Distance Vector
4.3 IP: Internet Protocol Hierarchical routing
4-38
IPv6
Động lực ban đầu: không gian địa chỉ 32-bit
được cấp phát cạn kiệt.
Động lực bổ sung:
4-51
Distance Vector Algorithm
Bellman-Ford Equation (dynamic programming)
Define
dx(y) := cost of least-cost path from x to y
Then
from
y ∞∞ ∞ y 2 0 1
z ∞∞ ∞ z 7 1 0
node y table
cost to
x y z y
2 1
x ∞ ∞ ∞
x z
y 2 0 1 7
from
z ∞∞ ∞
node z table
cost to
x y z
x ∞∞ ∞
from
y ∞∞ ∞
z 7 1 0
4-57
time
Dx(y) = min{c(x,y) + Dy(y), c(x,z) + Dz(y)} Dx(z) = min{c(x,y) +
= min{2+0 , 7+1} = 2 Dy(z), c(x,z) + Dz(z)}
node x table = min{2+1 , 7+0} = 3
cost to cost to cost to
x y z x y z x y z
x 0 2 7 x 0 2 3 x 0 2 3
from
from
y ∞∞ ∞ y 2 0 1
from
y 2 0 1
z ∞∞ ∞ z 7 1 0 z 3 1 0
node y table
cost to cost to cost to
x y z x y z x y z y
2 1
x ∞ ∞ ∞ x 0 2 7 x 0 2 3 x z
from
y 2 0 1 y 2 0 1 7
from
from
y 2 0 1
z ∞∞ ∞ z 7 1 0 z 3 1 0
node z table
cost to cost to cost to
x y z x y z x y z
x ∞∞ ∞ x 0 2 7 x 0 2 3
from
from
y 2 0 1 y 2 0 1
from
y ∞∞ ∞
z 7 1 0 z 3 1 0 z 3 1 0
4-58
time
Distance Vector: link cost changes
Example:
Consider the three-node topology shown in Figure 4.30.
Rather than having the link costs shown in Figure 4.30, the
link costs are c(x,y) = 3, c(y,z) = 6, c(z,x) = 4. Compute the
distance tables after the initialization step and after each
iteration of a synchronous version of the distance-vector
algorithm
y
3 6
x z
4
Comparison of LS and DV algorithms
4-64
Interconnected ASes
3c
3a 2c
3b 2a
AS3 2b
1c AS2
1a 1b AS1
1d forwarding table
configured by both intra-
and inter-AS routing
Intra-AS
Routing
Inter-AS
Routing algorithm
algorithm algorithm
intra-AS sets entries for
Forwarding internal dests
table
inter-AS & intra-As sets
entries for external dests
Inter-AS tasks AS1 must:
suppose router in AS1 1. learn which dests are
receives datagram reachable through AS2,
destined outside of AS1: which through AS3
router should forward 2. propagate this
packet to gateway reachability info to all
router, but which one? routers in AS1
Job of inter-AS routing!
3c
3a 2c
3b 2a
AS3 2b
1c AS2
1a 1b AS1
1d
Example: Setting forwarding table in router 1d
x
3c
3a 2c
3b 2a
AS3 2b
1c AS2
1a 1b AS1
1d
Example: Choosing among multiple ASes
now suppose AS1 learns from inter-AS protocol that subnet x
is reachable from AS3 and from AS2.
to configure forwarding table, router 1d must determine
towards which gateway it should forward packets for dest x.
this is also job of inter-AS routing protocol!
hot potato routing: send packet towards closest of two
routers.
4-72
RIP ( Routing Information Protocol)
u destination hops
v
u 1
A B w v 2
w 2
x 3
x y 3
z C D z 2
y
RIP advertisements
distance vectors: exchanged among neighbors every
30 sec via Response Message (also called
advertisement)
each advertisement: list of up to 25 destination
subnets within AS
RIP: Example
z
w x y
A D B
C
Destination Network Next Router Num. of hops to dest.
w A 2
y B 2
z B 7
x -- 1
…. …. ....
Routing/Forwarding table in D
RIP: Example
Dest Next hops
w - 1 Advertisement
x - 1 from A to D
z C 4
…. … ...
z
w x y
A D B
C
Destination Network Next Router Num. of hops to dest.
w A 2
y B 2
z BA 75
x -- 1
…. …. ....
Routing/Forwarding table in D
RIP: Link Failure and Recovery
If no advertisement heard after 180 sec --> neighbor/link
declared dead
routes via neighbor invalidated
new advertisements sent to neighbors
routed routed
Transprt Transprt
(UDP) (UDP)
network forwarding forwarding network
(IP) table table (IP)
link link
physical physical
Chapter 4: Network Layer
4.1 Introduction 4.4 Routing algorithms
4.2 What’s inside a router Link state
Distance Vector
4.3 IP: Internet Protocol
Hierarchical routing
Datagram format
IPv4 addressing 4.5 Routing in the Internet
ICMP RIP
IPv6 OSPF
BGP
4.6 Broadcast and multicast
routing
4-79
OSPF (Open Shortest Path First)
“open”: publicly available
uses Link State algorithm
LS packet dissemination
topology map at each node
route computation using Dijkstra’s algorithm
eBGP session
3c iBGP session
3a 2c
3b 2a
AS3 2b
1c AS2
1a 1b
AS1 1d
Distributing reachability info
using eBGP session between 3a and 1c, AS3 sends prefix
reachability info to AS1.
1c can then use iBGP do distribute new prefix info to all
routers in AS1
1b can then re-advertise new reachability info to AS2
over 1b-to-2a eBGP session
when router learns of new prefix, it creates entry for prefix in its
forwarding table.
eBGP session
3c iBGP session
3a 2c
3b 2a
AS3 2b
1c AS2
1a 1b
AS1 1d
Path attributes & BGP routes
advertised prefix includes BGP attributes.
prefix + attributes = “route”
two important attributes:
AS-PATH: contains ASs through which prefix
advertisement has passed: e.g, AS 67, AS 17
NEXT-HOP: indicates specific internal-AS router to next-
hop AS. (may be multiple links from current AS to next-
hop-AS)
when gateway router receives route advertisement,
uses import policy to accept/decline.
BGP route selection
router may learn about more than 1 route to some
prefix. Router must select route.
elimination rules:
1. local preference value attribute: policy decision
2. shortest AS-PATH
3. closest NEXT-HOP router: hot potato routing
4. additional criteria
BGP messages
legend: provider
B network
X
W A
customer
C network:
A advertises path AW to B
B advertises path BAW to X
Should B advertise path BAW to C?
No way! B gets no “revenue” for routing CBAW since neither
W nor C are B’s customers
B wants to force C to route to w via A
B wants to route only to/from its customers!
Why different Intra- and Inter-AS routing ?
Policy:
Inter-AS: admin wants control over how its traffic routed, who
routes through its net.
Intra-AS: single admin, so no policy decisions needed
Scale:
hierarchical routing saves table size, reduced update traffic
Performance:
Intra-AS: can focus on performance