You are on page 1of 82

Bài 4 Network Layer and IP

❑ Hiểu được nguyên lý hoạt động của tầng Network


❑ Hiểu được các thuật toán Routing

❑ 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

 Vận chuyển Segment từ host application


transport
gửi đến host nhận. network
data link
physical
 Bên phía gửi sẽ đóng gói network network
data link data link
(encapsulates) các segment network
data link
physical physical
physical
vào trong datagram. network
data link
network
data link
physical physical

 Bên phía nhận, chuyển các


network network
segment lên tầng Transport. data link
physical
data link
physical
network

 Giao thức tầng Network có data link


physical
application
trong mọi host, mọi router. network transport
network
data link network
data link
 Router sẽ xem xét các trường network
data link
physical data link
physical
physical

của header trong tất cả các physical

IP datagam đi qua nó.


4-4
Chức năng chính của tầng Network

 forwarding: di chuyển các packet từ đầu vào của


router sang đầu ra thích hợp của router.

 routing: Xác định đường đi cho packet từ nguồn


đến đích.
 routing algorithms (thuật toán định tuyến)
Tác động giữa forwarding và routing

routing algorithm Thuật toán routing xác định


đường đi của gói giữa 2 đầu
local forwarding table
cuối thông qua network
header output
value
0100 3 link
0101 2
0111 2 Bảng forwarding xác định việc
1001 1
chuyển gói bên trong một router

Giá trị trong header


Của Packet đến

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

 Định dạng Datagram  4.5 Routing in the Internet


 IPv4 addressing  RIP
 ICMP  OSPF
 IPv6  BGP
 4.6 Broadcast and multicast
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

Các chức năng tầng network của host và router:

Transport layer: TCP, UDP

Routing protocols IP protocol


•path selection •Các quy ước IP
•RIP, OSPF, BGP •Định dạng datagram
Network •Quy ước xử lý packet
layer forwarding
ICMP protocol
table
•Thông báo lỗi
•Tín hiệu router

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)

N = tập hợp các router = { u, v, w, x, y, z }

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)

Hỏi: Chi phí đường đi thấp nhất từ u đến z?

Thuật toán Routing: Tìm đường đi có chi phí thấp nhất


Phân loại thuật toán Routing
Thông tin toàn cục hay phân cấp?
Toàn cục:
 Tất cả router đều có toàn bộ thông tin chi phí kết nối,
cấu trúc mạng.
 Thuật toán: “link state”

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

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


 Biết chi phí kết nối, cấu trúc  c(x,y): chi phí từ node x
mạng của tất cả các node tới node y; = ∞ nếu không
 Được thực hiện thông phải là neighbor
qua: “link state  D(v): giá trị hiện tại của
broadcast” chi phí đường đi từ nguồn
 Tất cả các node đều có tới đích V
cùng thông tin
 p(v): node trước nằm trên
 Tính toán các đường dẫn đường đi từ nguồn tới đích
chi phí thấp nhất từ 1 node V
đến tất cả các node khác
 Lặp lại: sau k lần lặp lại,
 N’: tập hợp các node mà
có chi phí đường đi thấp
biết được đường đi có chi
nhất đã được xác định
phí thấp nhất của k đích.
Dijsktra’s Algorithm
1 Khởi tạo:
2 N' = {u}
3 for all nodes v
4 if v adjacent to u
5 then D(v) = c(u,v)
6 else D(v) = ∞
7
8 Lặp:
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 /* chi phí mới đến v là chính nó hoặc chi phí đường đi ngắn nhất
cộng với cho phí từ w tới v*/
15 until all nodes in N'
Dijkstra’s algorithm: Ví dụ

Step N' D(v),p(v) D(w),p(w) D(x),p(x) D(y),p(y) D(z),p(z)


0 u 2,u 5,u 1,u ∞ ∞
1 ux 2,u 4,x 2,x ∞
2 uxy 2,u 3,y 4,y
3 uxyv 3,y 4,y
4 uxyvw 4,y
5 uxyvwz

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

Resulting forwarding table in u:


destination link
v (u,v)
x (u,x)
y (u,x)
w (u,x)
z (u,x)
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(n2)

 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
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

 Định dạng Datagram  4.5 Routing in the Internet


 IPv4 addressing  RIP
 ICMP  OSPF
 IPv6  BGP
 4.6 Broadcast and multicast
routing

4-22
IP Addressing: giới thiệu

 IP address: 32-bit 223.1.1.1

định danh cho host và 223.1.1.2


223.1.2.1

router interface 223.1.1.4 223.1.2.9

 interface: kết nối giữa 223.1.2.2


223.1.1.3 223.1.3.27
host/router và đường
kết nối vật lý.
 Router thường có nhiều 223.1.3.2
223.1.3.1
interface
 Host thường có 1 hoặc
2 interface
 Mỗi địa chỉ IP được liên223.1.1.1 = 11011111 00000001 00000001 00000001
kết với 1 interface 223 1 1 1
Subnets (mạng con)
 IP address: 223.1.1.1
 Phần subnet: các bit có 223.1.2.1
trọng số cao 223.1.1.2
 Phần host: các bit có 223.1.1.4 223.1.2.9
trọng số thấo
223.1.2.2
223.1.1.3
 Subnet là gi? 223.1.3.27

 Các interface của phần subnet


thiết bị có phần subnet
của địa chỉ IP giống 223.1.3.1 223.1.3.2
nhau.
 Có thể giao tiếp vật lý
với nhau mà không cần Mạng bao gồm 3 subnets
router trung gian can
thiệp.
Subnets (mạng con)
Phương pháp: 223.1.1.0/24
223.1.2.0/24

 Để xác định các


subnet, hãy tách mỗi
interface từ host hoặc
router của nó, tạo ra
các vùng của các
mạng độc lập.
 Mỗi mạng độc lập

được gọi là Subnet, 223.1.3.0/24

Subnet mask: /24


Subnets 223.1.1.2

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

223.1.2.1 223.1.2.2 223.1.3.1 223.1.3.2


IP addressing: CIDR (định địa chỉ IP)
CIDR: Classless InterDomain Routing
 Phần subnet của địa chỉ có độ dài bất kỳ.
 Định dạng địa chỉ: a.b.c.d/x, trong đó: x là
các số bits trong phần subnet của địa chỉ.
Phần Phàn
subnet Host

11001000 00010111 00010000 00000000

200.23.16.0/23
IP addresses: Làm sao để lấy 1 địa chỉ?

Q: How does a host get IP address?

 hard-coded by system admin in a file


 Windows: control-panel->network->configuration->tcp/ip-
>properties
 UNIX: /etc/rc.config
 DHCP: Dynamic Host Configuration Protocol: dynamically get
address from as server
 “plug-and-play”
DHCP: Dynamic Host Configuration Protocol

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

A 223.1.1.1 DHCP 223.1.2.1


server
223.1.1.2
223.1.1.4 223.1.2.9
B
223.1.2.2 arriving DHCP
223.1.1.3 223.1.3.27 E client needs
address in this
223.1.3.1 223.1.3.2
network
DHCP client-server: Kịch bản
DHCP server: 223.1.2.5 arriving
DHCP discover
client
src : 0.0.0.0, 68
dest.: 255.255.255.255,67
yiaddr: 0.0.0.0
transaction ID: 654

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

rest of local network


Internet (e.g., home network)
10.0.0/24 10.0.0.1

10.0.0.4
10.0.0.2
138.76.29.7

10.0.0.3

All datagrams leaving local Datagrams with source or


network have same single source NAT IP destination in this network
address: 138.76.29.7, have 10.0.0/24 address for
different source port numbers source, destination (as usual)
NAT: Network Address Translation

 Động lực: Mạng cục bộ chỉ dùng 1 địa chỉ IP để ra


Internet:
 Chỉ cần 1 địa chỉ IP của ISP cung cấp dành cho tất cả
thiết bị.
 Có thể thay đổi địa chỉ IP của các thiết bị trong mạng
LAN mà không cần thông báo.
 Có thể thay đổi ISP mà không cần thay đổi địa chỉ IP
của các thiết bị trong mạng LAN
 Bảo mật các địa chỉ trong mạng LAN
NAT: Network Address Translation

Implementation: NAT router must:


 outgoing datagrams: replace (source IP address, port #) of
every outgoing datagram to (NAT IP address, new port #)
. . . remote clients/servers will respond using (NAT IP address,
new port #) as destination addr.
 remember (in NAT translation table) every (source IP
address, port #) to (NAT IP address, new port #)
translation pair
 incoming datagrams: replace (NAT IP address, new port #)
in dest fields of every incoming datagram with
corresponding (source IP address, port #) stored in NAT
table
NAT: Network Address Translation

NAT translation table


2: NAT router 1: host 10.0.0.1
WAN side addr LAN side addr
changes datagram sends datagram to
138.76.29.7, 5001 10.0.0.1, 3345 128.119.40.186, 80
source addr from
…… ……
10.0.0.1, 3345 to
138.76.29.7, 5001, S: 10.0.0.1, 3345
updates table D: 128.119.40.186, 80
10.0.0.1
1
S: 138.76.29.7, 5001
2 D: 128.119.40.186, 80 10.0.0.4
10.0.0.2
138.76.29.7 S: 128.119.40.186, 80
D: 10.0.0.1, 3345 4
S: 128.119.40.186, 80
D: 138.76.29.7, 5001 3 10.0.0.3
4: NAT router
3: Reply arrives changes datagram
dest. address: dest addr from
138.76.29.7, 5001 138.76.29.7, 5001 to 10.0.0.1, 3345
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

 Định dạng Datagram  4.5 Routing in the Internet


 IPv4 addressing  RIP
 ICMP  OSPF
 IPv6  BGP
 4.6 Broadcast and multicast
routing

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

 Định dạng Datagram  4.5 Routing in the Internet


 IPv4 addressing  RIP
 ICMP  OSPF
 IPv6  BGP
 4.6 Broadcast and multicast
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:

 Tăng tốc xử lý/forwading


 Header thay đổi tạo điều kiện thuận lợi cho QoS

ĐỊnh dạng IPv6 Datagram


 40 byte header, độ dài cố định

 Không có phép phân mảnh


IPv6 Header (Cont)
Priority: xác định độ ưu tiên của các datagram trong luồng
Flow Label: xác định các datagram trong cùng luồng
Next header: Xác định giao thức lớp trên dữ liệu
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-51
Distance Vector Algorithm
Bellman-Ford Equation (dynamic programming)
Define
dx(y) := cost of least-cost path from x to y

Then

dx(y) = min {c(x,v) + dv(y) }


v

where min is taken over all neighbors v of x


Bellman-Ford example
5
3
Clearly, dv(z) = 5, dx(z) = 3, dw(z) = 3
v w 5
2
u 2 1 z B-F equation says:
3
1 2 du(z) = min { c(u,v) + dv(z),
x y
1 c(u,x) + dx(z),
c(u,w) + dw(z) }
= min {2 + 5,
1 + 3,
5 + 3} = 4
Node that achieves minimum is next
hop in shortest path ➜ forwarding table
Distance Vector Algorithm
 Dx(y) = estimate of least cost from x to y
 Node x knows cost to each neighbor v: c(x,v)
 Node x maintains distance vector Dx = [Dx(y): y є
N]
 Node x also maintains its neighbors’ distance
vectors
 Foreach neighbor v, x maintains
Dv = [Dv(y): y є N ]
Distance vector algorithm (4)
Basic idea:
 From time-to-time, each node sends its own distance vector
estimate to neighbors
 Asynchronous

 When a node x receives new DV estimate from neighbor, it


updates its own DV using B-F equation:
Dx(y) ← minv{c(x,v) + Dv(y)} for each node y ∊ N

 Under minor, natural conditions, the estimate Dx(y) converge


to the actual least cost dx(y)
Distance Vector Algorithm (5)

Iterative, asynchronous: each Each node:


local iteration caused by:
 local link cost change
 DV update message from
wait for (change in local link
cost or msg from neighbor)
neighbor
Distributed:
 each node notifies neighbors recompute estimates
only when its DV changes
 neighbors then notify their
neighbors if necessary if DV to any dest has
changed, notify neighbors
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
x y z x y z
x 0 2 7 x 0 2 3
from

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

Link cost changes: 1


 node detects local link cost change y
4 1
 updates routing info, recalculates
x z
distance vector 50
 if DV changes, notify neighbors

At time t0, y detects the link-cost change, updates its DV,


and informs its neighbors.
“good
At time t1, z receives the update from y and updates its table.
news
It computes a new least cost to x and sends its neighbors its DV.
travels
fast” At time t2, y receives z’s update and updates its distance table.
y’s least costs do not change and hence y does not send any
message to z.
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

Message complexity Robustness: what happens if


 LS: with n nodes, E links, O(nE) router malfunctions?
msgs sent LS:
 DV: exchange between neighbors  node can advertise incorrect
only link cost
 convergence time varies
 each node computes only its
Speed of Convergence own table
 LS: O(n2) algorithm requires O(nE) DV:
msgs  DV node can advertise
 may have oscillations incorrect path cost
 DV: convergence time varies  each node’s table used by
others
 may be routing loops
◼ error propagate thru network
 count-to-infinity problem
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
Hierarchical Routing
Our routing study thus far - idealization
 all routers identical
 network “flat”
… not true in practice

scale: with 200 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!
Hierarchical Routing

 aggregate routers into Gateway router


regions, “autonomous
 Direct link to router in
systems” (AS)
another AS
 routers in same AS run
same routing protocol
 “intra-AS” routing protocol
 routers in different AS can
run different intra-AS routing
protocol

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

 suppose AS1 learns (via inter-AS protocol) that subnet x


reachable via AS3 (gateway 1c) but not via AS2.
 inter-AS protocol propagates reachability info to all internal
routers.
 router 1d determines from intra-AS routing info that its interface I
is on the least cost path to 1c.
 installs forwarding table entry (x,I)
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!

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.

Use routing info Determine from


Learn from inter-AS Hot potato routing: forwarding table the
from intra-AS
protocol that subnet Choose the gateway interface I that leads
protocol to determine
x is reachable via that has the to least-cost gateway.
costs of least-cost
multiple gateways smallest least cost Enter (x,I) in
paths to each
of the gateways forwarding table
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
Intra-AS Routing

 also known as Interior Gateway Protocols (IGP)


 most common Intra-AS routing protocols:

 RIP: Routing Information Protocol


 OSPF: Open Shortest Path First

 IGRP: Interior Gateway Routing Protocol (Cisco


proprietary)
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-72
RIP ( Routing Information Protocol)

 distance vector algorithm


 included in BSD-UNIX Distribution in 1982
 distance metric: # of hops (max = 15 hops)

From router A to subnets:

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

 neighbors in turn send out new advertisements (if tables


changed)
 link failure info quickly (?) propagates to entire net

 poison reverse used to prevent ping-pong loops (infinite


distance = 16 hops)
RIP Table processing

 RIP routing tables managed by application-level process


called route-d (daemon)
 advertisements sent in UDP packets, periodically repeated

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

 OSPF advertisement carries one entry per neighbor router


 advertisements disseminated to entire AS (via flooding)
 carried in OSPF messages directly over IP (rather than TCP or UDP
Link-State Advertisement (LSA)
OSPF “advanced” features (not in RIP)

 security: all OSPF messages authenticated (to prevent malicious


intrusion)
 multiple same-cost paths allowed (only one path in RIP)
 For each link, multiple cost metrics for different TOS (e.g.,
satellite link cost set “low” for best effort; high for real time)
 integrated uni- and multicast support:
 Multicast OSPF (MOSPF) uses same topology data base
as OSPF
 hierarchical OSPF in large domains.
Hierarchical OSPF
Hierarchical OSPF

 two-level hierarchy: local area, backbone.


 Link-state advertisements only in area
 each nodes has detailed area topology; only know
direction (shortest path) to nets in other areas.
 area border routers: “summarize” distances to nets in own area,
advertise to other Area Border routers.
 backbone routers: run OSPF routing limited to backbone.
 boundary routers: connect to other AS’s.
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
Internet inter-AS routing: BGP

 BGP (Border Gateway Protocol): the de facto


standard
 BGP provides each AS a means to:
1. Obtain subnet reachability information from
neighboring ASs.
2. Propagate reachability information to all AS-internal
routers.
3. Determine “good” routes to subnets based on
reachability information and policy.
 allows subnet to advertise its existence to rest of
Internet: “I am here”
BGP basics
 pairs of routers (BGP peers) exchange routing info over
semi-permanent TCP connections: BGP sessions
 BGP sessions need not correspond to physical links.
 when AS2 advertises a prefix to AS1:
 AS2 promises it will forward datagrams towards that
prefix.
 AS2 can aggregate prefixes in its advertisement

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

 BGP messages exchanged using TCP.


 BGP messages:
 OPEN: opens TCP connection to peer and authenticates
sender
 UPDATE: advertises new path (or withdraws old)

 KEEPALIVE keeps connection alive in absence of


UPDATES; also ACKs OPEN request
 NOTIFICATION: reports errors in previous msg; also
used to close connection
BGP routing policy

legend: provider
B network
X
W A
customer
C network:

 A,B,C are provider networks


 X,W,Y are customer (of provider networks)
 X is dual-homed: attached to two networks
 X does not want to route from B via X to C
 .. so X will not advertise to B a route to C
BGP routing policy (2)
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

 Inter-AS: policy may dominate over performance

You might also like