第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer...

79
第第第 第第第第第第第 Network Layer Protocols
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    254
  • download

    9

Transcript of 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer...

Page 1: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

第四章 網路層通訊協定

Network Layer Protocols

Page 2: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Protocol Stack

Physical Layer

Network Layer

Data Link Layer

Transport Layer

Application Layer

Page 3: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

網路層的特色

• 底層可以連結數種不同介質的網路。– 底層不同的網路介質可以透過網路層傳輸協定互相連結。

• Internet 的主要定址層– 網路層的位址 (Address) 為階層式 (Hierarchical) 定義,鄰近的節點往往具有相似的網路層位址 prefix 。可以依照網路層位址找到節點的所在位置。

– 鏈結層 (Data Link Layer) 的位址為平面式 (flat) ,位址與實際的地域位置 (Location) 大多無相關。無法依照鏈結層位址找到節點所在的位置。

Page 4: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

網路層的主要功能• Routing: 決定封包 (packet) 適當的傳輸路徑。

– Routing Algorithms: 計算傳輸路徑的演算法。• Switching: 將封包轉送至適當的出口埠。• Call Setup: 在傳送資料前建立整條傳輸路徑。

– 協助通訊的兩端在資料 (Data Flow) 真正開始傳送之前建立連線 (example: TCP 3-way handshaking, ATM) 。

Page 5: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Service Model

• Service Model: 描述傳送端與接收端之間資料傳輸的特性,如 :– 封包是否照著傳輸順序到達接收端 (in the order)?

– 傳送的間距與接收的間距是否相同 (jitter)?

– 壅塞時的處理方法 (congestion)?

– 封包是否會在傳輸過程中遺失 (loss-free)?

– …

Page 6: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Virtual Circuit

• VC 的生命週期主要有三個部分 :– VC Setup: 傳送端告知網路接收端的位址,由網路層依照

傳送端以及接收端的位址開始建立 VC 。– Data Transfer: 開始傳送資料。– Virtual-Circuit teardown: 結束資料傳送並且釋放之前建立

的 VC 。• 傳輸層的連線與網路層 VC 的重要差異 :

– 傳輸層連線為 End-To-End 的連線,中間的 router 不必紀錄連線狀態。

– VC: 中間的 router 必須紀錄現有的 VC 狀態 (state) 。

Page 7: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Virtual Circuit

• 每個封包都包含 VC identifier 而不是目的地位址 (Destination) 。

• Signaling Message: 用來建立或是結束 VC 。• Signaling Protocol: 交換 signaling message 的協定。

1. Initiate call 2. incoming call

3. Accept call4. Call connected5. Data flow begins 6. Receive data

Physical

Data Link

Network

Transport

Application

Physical

Data Link

Network

Transport

Application

Page 8: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Datagram Network

• 每個封包傳送時都含有接收端的位址 (address) ,不需要先行建立 path , router 查詢 routing table 決定出口埠。

• Routing table 可以動態改變– 同一個資料流 (flow) 的封包不一定會依照相同路徑傳送。– 同一個資料流的封包不一定依照傳送順序到達。

1. Send data 2. Receive data

Physical

Data Link

Network

Transport

Application

Physical

Data Link

Network

Transport

Application

Page 9: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Network Service Model

NetworkArchitecture

Internet

ATM

ATM

ATM

ATM

ServiceModel

best effort

CBR

VBR

ABR

UBR

Bandwidth

none

constantrateguaranteedrateguaranteed minimumnone

Loss

no

yes

yes

no

no

Order

no

yes

yes

yes

yes

Timing

no

yes

yes

no

no

Congestionfeedback

no (inferredvia loss)nocongestionnocongestionyes

no

Guarantees ?

Page 10: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Network Service Model

• Best-Effort: 不保證封包傳送的時間,接收時不保證順序正確,不保證不會遺失。

• CBR (Constant bit rate): ATM service model 中適合即時性以及穩定輸出量的資料流。可以保證延遲、封包遺失率小於某特定值。

• UBR (Unspecified bit rate): 僅比 Best-Effort 的傳送方式多了保證順序正確的特性。

• ABR (available bit rate): – 保證最少的傳輸量 (MCR, Minimum Cell Transmission)– 具有告知傳送端網路有壅塞的情形發生,必須調整 MCR 以

及 PCR (Peak Cell Rate)• VBR (Variable bit rate).

Page 11: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Routing

• Routing: 尋找一條適當的路徑,將封包從傳送端傳遞到接收端。

• 如圖 : A, B, C, D, E, F 為 router ,由實體連線互相連結。每條實體連線都會因為傳輸延遲、壅塞的情況賦予一個 cost 值。

• Good Path: 一般是指 cost 累加最小的路徑,但是也有可能因為實際需求的不同而有不同的定義。

A

ED

CB

F

2

2

13

1

1

2

53

5

Page 12: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Routing Algorithm 的分類

• Routing Algorithm 可依照兩方面來分類 :– Router 所蒐集的資訊範圍 (Global or decentralized)

– Route 是靜態 (static) 還是動態 (dynamic) 變化• Global or decentralized information:

– Global: 每個 router 都知道整個網路的狀態及拓樸 (Topology) ,如” Link State” algorithms.

– Decentralized: router 只知道與鄰近節點的位址以及連線的cost 。利用 router 間交換這些資訊,可以計算出完整的 routing table 。如” distance vector” algorithms.

Page 13: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Link-State Algorithm (Global)

• Link-State Algorithm 的特色:– 每個 router 都擁有相同且完整網路拓樸及 cost 的資訊。

• Example: Dijkstra’s Algorithm– 初始條件:以本身為起始點,設定相鄰的節點的 cost 值,無

直接連結的節點 cost 設定為無限大。– 替換條件:選擇最小 cost 的節點作為下一個起始點,不斷更

新 ( 比原來 cost 小 ) 鄰近的節點所具有的 cost 值。– 終結條件:執行替換條件到鄰近的節點所具有的 cost 值都不

需要在更新時,計算完成。

Page 14: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Dijkstra’s Algorithm

• 符號定義:– C(i,j): 節點 i 到節點 j 的 cost ,若 i, j 不相鄰,此值為無限大。

– D(v): 目前從起始點到 v 的最少 cost( 可能會被更新 ) 。– p(v): 從起始點到 v 的前一個點 (predecessor node) 。– N: 已經確定與起始點最短路徑的所有點所成的集合

(set) 。

Page 15: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Dijkstra’s Algorithm (Example)

Step012345

start NA

ADADE

ADEBADEBC

ADEBCF

D(B),p(B)2,A2,A2,A

D(C),p(C)5,A4,D3,E3,E

D(D),p(D)1,A

D(E),p(E)infinity

2,D

D(F),p(F)infinityinfinity

4,E4,E4,E

A

ED

CB

F

2

2

13

1

1

2

53

5

Page 16: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Dijkstra’s Algorithm1 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

Page 17: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Dijkstra’s Algorithm: 時間複雜度

• Dijkstra’s Algorithm 的計算時間複雜度 (Time Complexity) :– 假設共有 n 個節點。– 需要 n*(n+1)/2次比較 :O(n2)

Page 18: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Distance Vector Algorithm (decentralized)

• Distance Vector Algorithm 的特色:– 反覆交換訊息 (iterative) 。– 非對稱性 (asynchronous) 。– 分散式 (distributed) 。

• Router 只需要知道最佳路徑的 next hop 即可傳送。• distance table 是用來計算 route 的主要資料結構。• Table 中的每個 element 的定義如下:

D (Y,Z)X

distance from X toY, via Z as next hop

c(X,Z) + min {D (Y,w)}Z

w

=

=

Page 19: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Distance Vector Algorithm: Distance Table

A

E D

CB7

8

1

2

1

2

D ()

A

B

C

D

A

1

7

6

4

B

14

8

9

11

D

5

5

4

2

Ecost to destination via

dest

inat

ion

D (C,D)E

c(E,D) + min {D (C,w)}D

w== 2+2 = 4

D (A,D)E

c(E,D) + min {D (A,w)}D

w== 2+3 = 5

D (A,B)E

c(E,B) + min {D (A,w)}B

w== 8+6 = 14

loop!

Page 20: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Distance Vector Algorithm: Distance Table -> Routing

Table• Router 可以依照 distance

table 找出具有到某個目的節點最少 cost 的 next- hop 。

• 依照 next-hop就可以知道routing table 。

A

B

C

D

A,1

D,5

D,4

D,4

Outgoing link to use, cost

dest

inat

ion

Routing table

Page 21: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Distance Vector Algorithm

• 重新交換訊息的原因:– 週遭的 Link-cost 改變。– 鄰近的 router 告知到某節點的的最少 cost 改變。

• 運作的流程圖如右:

wait for (change in local link cost of msg from neighbor)

recompute distance table

if least cost path to any dest

has changed, notify neighbors

Page 22: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Distance Vector Algorithm

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

Page 23: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

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 (y,V) = D (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 DV(Y,w) */ 20 /* call this received new value is "newval" */ 21 for the single destination y: D (Y,V) = c(X,V) + newval 22 23 if we have a new min D (Y,w)for any destination Y 24 send new value of min D (Y,w) to all neighbors 25 26 forever

Page 24: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Distance Vector Algorithm

X Z12

7

Y

Page 25: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Distance Vector Algorithm

X Z12

7

Y

D (Y,Z)X

c(X,Z) + min {D (Y,w)}w=

= 7+1 = 8

Z

D (Z,Y)X

c(X,Y) + min {D (Z,w)}w=

= 2+1 = 3

Y

Page 26: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Distance Vector: link cost changes

algorithmterminates

• Y偵測到與 X 的連線 cost減少 (Good news travel fast) 。• Y修改自己的 distance table 。• 如果這條路徑在 least cost上,必須通知鄰近的 router 。

X Z14

50

Y1

Page 27: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Distance Vector: link cost changes

• Y偵測到與 X 的連線 cost增加• bad news travels slow: 防止“ count to infinity” 。

X Z

14

50

Y60 algorithm

continueson!

Page 28: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Distance Vector: Poison reverse

• Z經過 Y 到達 X ,通知 Y經過 Z 到達 X 的 cost 為無限大( 本身的 distance table仍要紀錄真實的值 ) 。

• 當 X, Y 之間連線的 cost 值變大, Z就不會再透過 Y 連到X ,而是直接連結。此時 Z 告知 Y 到達 X 的 cost 為 50 。

• 可以避免” count to infinity” 。

X Z14

50

Y60

algorithmterminates

Page 29: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Hierarchical Routing

• 在龐大的網際網路中,往往不只有一種 routing protocol ,原因為– Scale: 當連結的網路變大,每個 router 的 routing table就會擴張

的很迅速,因此必須要想辦法減少 routing table 所佔的記憶體空間。

– Administrative autonomy: 某些單位可能希望自己所管理的網域採用某種 routing protocol ,與外界無關。

• 在同一個 AS (Autonomous System) 中的 router採用相同的 routing protocol 。

• Gateway router: AS對外連結的 router ,對內跑 intra-AS routing protocol ,對外則跑 inter-system routing protocol 。

Page 30: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Intra-AS and Inter-AS routing

• A 、 B 、 C 為三個不同的 AS 。必須由 Gateway router 連結。

inter-AS, intra-AS routing in

gateway A.c

network layer

link layer

a

b

b

aaC

A

Bd

A.a

A.c

C.bB.a

cb

c

Page 31: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Intra-AS and Inter-AS routing

Host h2

a

b

b

aaC

A

Bd c

A.a

A.c

C.bB.a

cb

Hosth1

Intra-AS routingwithin AS A

Inter-AS routingbetween A and B

Intra-AS routingwithin AS B

Page 32: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

網路層通訊協定

routingtable

Routing protocols•path selection•RIP, OSPF, BGP

IP protocol•addressing conventions•datagram format•packet handling conventions

ICMP protocol•error reporting•router “signaling”

Transport layer: TCP, UDP

Link layer

physical layer

Networklayer

Page 33: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IP addressing

• IP address: 由 32bits所組成,用來辨識在網際網路上主機 (Host) 或介面 (Interface)的數值。

• Router上通常有多個介面,一個主機上也允許有多個介面,每個介面具有各自的 IP address 。

223.1.1.1

223.1.1.2

223.1.1.3

223.1.1.4 223.1.2.9

223.1.2.2

223.1.2.1

223.1.3.2223.1.3.1

223.1.3.27

223.1.1.1 = 11011111 00000001 00000001 00000001

223 1 11

LAN

Page 34: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IP addressing

• IP address 由兩個部分組成:– Network part:較高位 (High order part) 的位元用來辨識網域。

– Host Part (Interface part):較低位 (Low order part)的位元用來辨識主機。

• 何謂一個網域 (Network)?– IP address 具有相同高位位元 (Network Part) 的介面所成的統稱。

– 這些介面彼此互相連接而不透過 router (Layer-3 Device) 。

Page 35: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IP addressing• 網路遮罩 (Network Mask): 用來判斷 IP 位址中的 Network Part 以

及 Host Part 。– Example: 223.1.1.4/24 ,代表左邊 24 個位元是 Network part ,剩下的 8

位元是 host part 。• IP 網路位址可以依照前面若干個位元來區分是屬於哪個 class (A, B, C,

D) 。

0network host

10 network host

110 network host

1110 multicast address

A

B

C

D

class1.0.0.0 to127.255.255.255

128.0.0.0 to191.255.255.255

192.0.0.0 to223.255.255.255

224.0.0.0 to239.255.255.255

32 bits

Page 36: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IP addressing

• 如果完全依照 class 來分配 IP 位址,可能無法有效的利用 IP 位址 (空著很多 IP 並未使用 ) 。

• CIDR: Classless InterDomain Routing– IP 位址的 Network part長度並未固定,可以依照 Netw

ork Mask 來決定 Network part 的長度。

11001000 00010111 00010000 00000000

networkpart

hostpart

200.23.16.0/23

Page 37: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IP addressing

• 如何取得一個 IP?– 經過人工設定,將 IP 位址寫入設定檔中。– Dynamic Host Configuration Protocol (DHCP): 啟動後與鄰近的 DHCP伺服器取得 IP 。

• 利用 DHCP取得 IP 的步驟:– 客戶端廣播 (broadcast) DHCP Discovery 的訊息。– DHCP伺服器用 DHCP Offer 訊息告知客戶端有伺服器存在。

– 客戶端送出 DHCP Request 的訊息要求取得 IP 。– DHCP伺服器送回 DHCP Ack 的訊息夾帶派發的 IP 位址。

Page 38: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IP addressing

• 利用網路遮罩 (Network Mask) 可以將取得的一段 IP再度分割成更小段的子網路 (sub-network) 。

“Send me anythingwith addresses beginning 200.23.16.0/20”

200.23.16.0/23

200.23.18.0/23

200.23.30.0/23

Fly-By-Night-ISP

Organization 0

Organization 7Internet

Organization 1

ISPs-R-Us“Send me anythingwith addresses beginning 199.31.0.0/16”

200.23.20.0/23Organization 2

...

...

Page 39: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IP addressing

• ICANN: Internet Corporation for Assigned Names and Numbers.– 分配 IP 位址。– 管理 root DNS 。– 分派 Domain Name 。

• 要申請 IP 位址網段必須要向 ICANN申請。

Page 40: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

傳送 IP 封包的過程• 封包 (Layer-3 packe

t)內容並未改變。• 傳送時依靠封包標頭

(Header)內的目的地IP 位置以及 Routing table 決定出口埠。 223.1.1.1

223.1.1.2

223.1.1.3

223.1.1.4 223.1.2.9

223.1.2.2

223.1.2.1

223.1.3.2223.1.3.1

223.1.3.27

A

BE

Dest. Net. next router Nhops

223.1.1 1223.1.2 223.1.1.4 2223.1.3 223.1.1.4 2

miscfields

sourceIP addr

destIP addr data

Page 41: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

傳送 IP 封包的過程

• A 要送封包到 B ,封包內容如上。• A 與 B 直接連線 (Layer-2) 。• A 利用子網路遮罩判斷 B跟本身屬於同一個子網路。

• 鏈結層會直接將此封包給 B 。

223.1.1.1

223.1.1.2

223.1.1.3

223.1.1.4 223.1.2.9

223.1.2.2

223.1.2.1

223.1.3.2223.1.3.1

223.1.3.27

A

BE

Dest. Net. next router Nhops

223.1.1 1223.1.2 223.1.1.4 2223.1.3 223.1.1.4 2

miscfields 223.1.1.1223.1.1.3data

Page 42: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

傳送 IP 封包的過程

• A 要傳送封包給 E ,內容如上。• 利用子網路遮罩判斷, A 與 E 並沒有在同一個子網路上,並未直接連線。

• A 將此訊息 ( 用鏈結層 frame 包裝 ) 傳送給 router (223.1.1.4) ,封包 (Layer-3)內容不變。

• Router 查詢 routing table後發現目的地 E 所屬的子網路在 223.1.2.9 的埠。

• Router 將封包轉送 ( 用鏈結層的frame 包裝 ) 至 E 所屬的子網路。

• E 收到這個封包。

223.1.1.1

223.1.1.2

223.1.1.3

223.1.1.4 223.1.2.9

223.1.2.2

223.1.2.1

223.1.3.2223.1.3.1

223.1.3.27

A

BE

Dest. Net. next router Nhops

223.1.1 1223.1.2 223.1.1.4 2223.1.3 223.1.1.4 2

miscfields 223.1.1.1223.1.2.3 data

Page 43: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

傳送 IP 封包的過程

223.1.1.1

223.1.1.2

223.1.1.3

223.1.1.4 223.1.2.9

223.1.2.2

223.1.2.1

223.1.3.2223.1.3.1

223.1.3.27

A

BE

network router Nhops interface

223.1.1 - 1 223.1.1.4 223.1.2 - 1 223.1.2.9

223.1.3 - 1 223.1.3.27

Dest. next• Routing table 如右:

Page 44: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IP 封包格式ver length

32 bits

data (variable length,typically a TCP

or UDP segment)

16-bit identifier

Internet checksum

time tolive

32 bit source IP address

IP protocol versionnumber

header length (bytes)

max numberremaining hops

(decremented at each router)

forfragmentation/reassembly

total datagramlength (bytes)

upper layer protocolto deliver payload to

head.len

type ofservice

“type” of data flgs fragment offset

upper layer

32 bit destination IP address

Options (if any) E.g. timestamp,record routetaken, pecifylist of routers to visit.

Page 45: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IP 封包切割與重組• MTU (Maximum Transfer

Unit): 表示 Link-Layer 所能夠傳送封包的最大長度( 會因不同的 Link-Layer而有不同的 MTU) 。

• IP 封包的切割:– 在傳送過程中將一個封包切割 (fragmentation) 為若干個小封包。

– 在接收端接收到以後利用 Header 中的 identifier 重新組合(reassembly) 。

fragmentation: in: one large datagramout: 3 smaller datagrams

reassembly

Page 46: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IP 封包切割與重組ID=x

offset=0

fragflag=0

length=4000

ID=x

offset=0

fragflag=1

length=1500

ID=x

offset=1480

fragflag=1

length=1500

ID=x

offset=2960

fragflag=0

length=1040

One large datagram becomesseveral smaller datagrams

4040=4000+2*Header長度

Page 47: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

ICMP: Internet Control Message Protocol

• ICMP 是用來讓 Host 、 Router 以及 Gateway 交換網路層訊息的通訊協定。– Error reporting: unreachable

host, network, protocol.

– Echo request/reply: ping.

• ICMP 訊息是利用 IP 封包傳送。

Type Code description0 0 echo reply (ping)3 0 dest. network unreachable3 1 dest host unreachable3 2 dest protocol unreachable3 3 dest port unreachable3 6 dest network unknown3 7 dest host unknown4 0 source quench (congestion control - not used)8 0 echo request (ping)9 0 route advertisement10 0 router discovery11 0 TTL expired12 0 bad IP header

Page 48: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Routing in the Internet

• 網際網路由數個 AS (Autonomous System) 互相連結所組成。

• 考慮 AS 的 routing :– Intra AS: 管理者可以自由選擇在所屬 AS內的 Routing

Protocol 。– Inter AS: 必須與外界跑相同的 Routing Protocol 。

Page 49: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Internet AS HierarchyIntra-AS border (exterior gateway) routers

Inter-AS interior (gateway) routers

Page 50: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Intra-AS Routing

• IGP: Interior Gateway Protocols 。• 一般常見的 IGP:

– RIP: Routing Information Protocol.– OSPF: Open Shortest Path First.– IGRP: Interior Gateway Routing Protocol (Cisco propri

etary)

Page 51: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

RIP (Routing Information Protocol)

• 採用” Distance Vector Algorithm”• RFC 1058(version 1), RFC 1723(version 2)• 所紀錄的路徑長度最多通過 15 個 hop 。• 透過每三十秒傳送的 RIP response message 與相鄰的 router 交換 routing table ,也稱作 RIP advertisement 。

• 每次利用 RIP advertisement 交換 routing table 最多可包含 25 個 destination network.

Page 52: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

RIP (Routing Information Protocol)

Destination Network Next Router Num. of hops to dest. w A 2

y B 2 z B 7

x -- 1…. …. ....

w x y

z

A

C

D B

Routing table in D

Page 53: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

RIP 處理連結 (Link) 變化的方式• 如果超過 180秒沒有聽到定期的廣播,則 RIP就會認為此條路徑已經不復存在 ( 與 Neighbor 斷線 ) 。– 經過這個 neighbor 的路徑已經不在。– 傳送新的 advertisement給其他 neighbor 。– 如果 neighbor 的 routing table 有所更動,就會再度傳送出去。

– 可以透過這種方式將連結變化傳送到整個網路。– 設定 Max Hop=15 的目的是避免 Count-To-Infinity 。

Page 54: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

管理 RIP 的 Routing Table• 利用在應用層執行的 process routed 來管理 RIP

routing table 。 (daemon)• 定期傳送 UDP 封包 (advertisement) , routed再依照封包的內容修改本身的 routing table 。

Page 55: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

RIP Table 的範例

• 第一行為 Loop-Back 。• 具有三個介面 192.168.2.5 、 193.55.114.6 、 192.168.3.5 。• 第五行為 IP multicast 。• 最後一行表示在表中查詢不到的 IP就送往 193.55.114.129 。

Destination Gateway Flags Ref Use Interface -------------------- -------------------- ----- ----- ------ --------- 127.0.0.1 127.0.0.1 UH 0 26492 lo0 192.168.2. 192.168.2.5 U 2 13 fa0 193.55.114. 193.55.114.6 U 3 58503 le0 192.168.3. 192.168.3.5 U 2 25 qaa0 224.0.0.0 193.55.114.6 U 3 0 le0 default 193.55.114.129 UG 0 143454

Router: giroflee.eurocom.fr

Page 56: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

OSPF (Open Shortest Path First)

• OSPF: RFC 2178 (Version 2)• OSPF 是一種 Link-State Algorithm ,每個 route

r 都知道整個 AS 的拓樸 (Topology) 狀況。• Flooding: 每個 router 必須要將本身與哪些 neig

hbor 相鄰的訊息傳送到整個 AS 。• Security: 所有 router 間交換的訊息需要被認可

(authenticated) ,防止錯誤的訊息影響到正常的routing table 。

• Multiple same-cost paths: 到達某目的地可能有多重路徑 ( 相同 cost) 可以選擇。

Page 57: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

OSPF (Open Shortest Path First)

• 可以依照 IP Header 中不同的 TOS 計算出不同的路徑。

• Multicast OSPF (MOSPF, RFC 1584): 利用原有的OSPF 資料再加上新的 link-state advertisement 。

• Hierarchical OSPF :– 分成兩層: Local area, backbone 。– Area border routers: 收集本身所在 area內的資訊,並告知其他 Area border routers 。

– Backbone routers: 採用 OSPF ,僅收集 backbone 的資訊。

– Boundary routers: 連結其他 AS 的 router 。

Page 58: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Hierarchical OSPF

Page 59: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IGRP (Interior Gateway Routing Protocol)

• EIGRP (Enhanced Interior Gateway Routing Protocol): 一種改進 RIP 的 Distance Vector Algorithm 。

• 計算 path cost 時不僅以 hop 數為 cost ,也考量: – 延遲 (Delay)– 頻寬 (Bandwidth)– 可靠度 (Reliability)– 負載 (load)

Page 60: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Inter-AS routing

Page 61: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Internet inter-AS routing: BGP

• BGP: Border Gateway Protocol.• Path Vector Protocol:

– 與 Distance Vector 相似。– Mechanism: router 告知 neighbor 通往某個目的地的 p

ath (sequence of ASs) 。– Policy:管理者決定是否將這個 path 加入 routing table 。– Ex : Gateway X 告知 neighbor 從 X 到達 Z 的路徑如下:

Path (X,Z) = X, Y1, Y2, Y3,…,Z

Page 62: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Internet inter-AS routing: BGP

考慮 X 將到 Z 的 path 告知 W 的各種情況 :• W 可能因為下列原因不採用 X 所提供的路徑:

– Cost較高。– 不欲通過競爭性的 AS 。– 避免產生 Loop 。

• 如果W採用了 X 所提供的路徑:– Path (W,Z) = W, Path (X,Z)

• X 本身也可以透過控制 advertisement 的方式做出一些管理的決策:– X 不希望別的封包透過 X 到達 Z 不廣播有關於 Z 的 Pa

th 。

Page 63: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Internet inter-AS routing: BGP

• BGP 的透過 TCP 作訊息交換。• BGP message 的種類:

– OPEN: 與對方建立 TCP 連線並且確認 Sender 。– UPDATE: 廣播新的 path ,或是取消舊的 path 。– KEEPALIVE: 目的是維持 TCP 連線 ( 可能一段時間沒有 UPDATE 訊息 ) ,也用來產生 OPEN 的 ACKs 。

– NOTIFICATION:回報上述的訊息所產生的錯誤或是關閉連線。

Page 64: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Intra- 與 Inter-AS routing 的不同

• Policy:– Inter-AS: AS 的管理者需要 Policy 來控制是否讓其他 A

S 的封包通過。– Intra-AS: 單一管理者。

• Scale:– 利用 Hierarchy 的方式可以減少 routing table 的大小,也減少 update 的流量。

• Performance:– Intra-AS: 在乎 performance 。– Inter-AS: policy 的重要性勝於 performance 的重要性。

Page 65: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Router Architecture

• Router 的主要兩個功能:– 與其他 router溝通 (routing protocol)

– 交換封包到適當的出口 (outgoing link)

Page 66: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Input Port

• Decentralized Switching– 依照封包的 dest欄位決定要往哪個

output port 傳送。– 當封包流入的速度比處理的速度快,就儲存在 queue 中等待處理。

Physical layer:bit-level reception

Data link layer:e.g., Ethernetsee chapter 5

Page 67: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Input Port Queuing

• 當封包流入的總和比交換 switch 的速度快封包會被儲存在 input queue等待交換。

• Head-of-the-Line (HOL) blocking: 在等待交換的封包影響後來的封包進行交換 (queue 的特性 ) 。

Page 68: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Switch fabrics 的三種類型

Page 69: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

透過記憶體 (Memory) 作交換• 第一代 router:

– CPU 將封包複製到記憶體中– 瓶頸是在記憶體存取的速度。

InputPort

OutputPort

Memory

System Bus

• 現代的 router:– 放置在 input port 的前端處理器負責將封包複製到記憶體。– Ex: Cisco Catalyst 8500系列

Page 70: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

透過 BUS 作交換• 封包從 input port 的記憶體透過共享的 bus 轉換到 output 的記憶體中。

• Bus contention: 交換的瓶頸在於BUS 的頻寬。

• Ex: Cisco 1900, 1Gbps 。

Page 71: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

透過 Interconnection Network 作交換

• 可以避免 bus 所造成的瓶頸。• Banyan networks.• 進階的設計 (Keshav 1998)

– 將不同長度的封包切割成等大小的 cell ,等到 output port後再重新組合。

• Example: Cisco 12000

Page 72: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Output Ports

• 當封包處理的速率大於 output port 的傳輸速率時,必須將封包儲存在 output buffer 中。

• Scheduling discipline: 從 queue 中選擇封包傳送。

Page 73: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Output port queuing

• 當封包進入 output buffer 的速率大於 link 傳輸的速率時。

• Output buffer overflow 會造成封包遺失

Page 74: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IPv6

• 推動 IPv6 的動機:– 預估在 2008年的時候現有的 32bits IP 位址將會被分配完畢。

– 希望能設計更容易 /快速作交換處理的 header 。– 希望 header內含 QoS 的欄位。– 支援 anycast: 在若干個 server 中尋找最適當的 server 。

• IPv6 封包格式:– Header固定為 40bytes 。– 不允許分割

Page 75: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IPv6 packet format• Priority :紀錄優先權的欄位 (traffic class) 。• Flow label: 辨別這個封包是屬於哪個 flow 。• Payload length: 紀錄 data 的長度。• Next header :用來分辨上層的通訊協定。• Hop limit: 通訊時最多通過幾個節點。每過一個節點就減

一,當 router 發現此欄位的值為零時,就會剔除 (discard) 這個封包。

Page 76: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

IPv6 packet format

與 IPv4 不同處:• Checksum: 為了增加處理速度所以不再加上 che

cksum 的欄位。• Options: 在標準 header 中並沒有規定此欄位,但可以透過 Next-header 的欄位來表示。

• ICMPv6 (RFC 2463)– 增加新的訊息種類,如:” Packet Too Big” 或” unre

cognized IPv6 options” 。– 管理 multicast group 的功能。

Page 77: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

從 IPv4 轉換到 IPv6• 面臨的困難:

– 世界上的 router 不可能同時更新至 IPv6 的版本。– 如何讓 IPv4 與 IPv6共存?

• 解決的方法:– Dual Stack: 某些 router 可以接收不同版本的封包,並且轉換成適當的版本格式傳送出去。

– Tunneling: 利用 IPv4 作穿隧的技術,將 IPv6 的封包包含在 IPv4 封包的 payload 中。

Page 78: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Dual Stack Approach

Page 79: 第四章 網路層通訊協定 Network Layer Protocols. Protocol Stack Physical Layer Network Layer Data Link Layer Transport Layer Application Layer.

Tunneling

IPv6 inside IPv4 where needed