1. 程式人生 > >OSPF六類LSA與鏈路狀態資料庫

OSPF六類LSA與鏈路狀態資料庫

OSPF六類LSA與鏈路狀態資料庫

OSPF使用LSA(鏈路狀態通告)來在網路中的路由器之間交換網路拓撲資訊。LSA詳盡地描述了網路的拓撲,OSPF總共有LSA-1、LSA-2、LSA-3、LSA-4、LSA-5、LSA-7共6中LSA他們別別擁有不同的職能。

LSA-1 Router LSA

每一臺執行OSPF的裝置都會產生LSA-1,

  • 傳播範圍:只能在本區域傳播,不能跨越ABR
  • 宣告者:每臺路由器
  • 內容:路由和拓撲資訊
  • 檢視方法:show ip ospf database router

Link-id為Router-id,ADV為通告者
注意,在LSA-1中看不到掩碼,掩碼資訊需要在LSA-2中檢視。

LSA-2 Network LSA

只在多路訪問MA網路中存在

  • 傳播範圍:只能在本區傳播,不能跨越ABR
  • 宣告著:DR(通告一共有多少臺路由器執行)
  • 內容:描述又拖少成員以及掩碼資訊
  • 檢視方法:show ip ospf database network

Attached router是成員
我們用下面拓撲圖來驗證一下LSA-1和LSA-2:

這裡寫圖片描述
配置程式碼如下:
在R1上配置:

R1>en
R1#conf t
R1(config)#int lo 0
R1(config-if)#ip add 1.1.1.1 255.255.255.255
R1(config-if)#no sh
R1(config-if)#int f0/0
R1(config-if)#ip add 12.1.1.1 255.255.255.0
R1(config-if)#no sh

R1
(config)#router os 100 R1(config-router)#router-id 1.1.1.1 R1(config-router)#net 1.1.1.1 0.0.0.0 a 0 R1(config-router)#net 12.1.1.0 0.0.0.255 a 0 R1(config-router)#exi

在R2上配置:

R2>en
R2#conf t
R2(config)#int lo 0
R2(config-if)#ip add 2.2.2.2 255.255.255.255
R2(config-if)#no sh
R2(config-if)#int f0/0
R2(config-if)#ip add 12.1.1.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exi
R2(config)#int f0/1
R2(config-if)#ip add 23.1.1.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exi

R2(config)#router os 100
R2(config-router)#router-id 2.2.2.2
R2(config-router)#net 2.2.2.2 0.0.0.0 a 1
R2(config-router)#net 12.1.1.0 0.0.0.255 a 0
R2(config-router)#net 23.1.1.0 0.0.0.255 a 1
R2(config-router)#exi

在R3上配置:

R3>en
R3#conf t
R3(config)#int lo 0
R3(config-if)#ip add 3.3.3.3 255.255.255.255
R3(config-if)#no sh
R3(config-if)#int lo 0
R3(config-if)#int f0/1
R3(config-if)#ip add 23.1.1.3 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exi

R3(config)#router os 100
R3(config-router)#router-id 3.3.3.3
R3(config-router)#net 3.3.3.3 0.0.0.0 a 1
R3(config-router)#net 23.1.1.0 0.0.0.255 a 1
R3(config-router)#exi

一個簡單的OSPF系統,配置完畢之後我們來檢視一下路由表,以R1為例:

R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

Gateway of last resort is not set

     1.0.0.0/32 is subnetted, 1 subnets
C       1.1.1.1 is directly connected, Loopback0
     2.0.0.0/32 is subnetted, 1 subnets
O IA    2.2.2.2 [110/11] via 12.1.1.2, 00:11:19, FastEthernet0/0
     3.0.0.0/32 is subnetted, 1 subnets
O IA    3.3.3.3 [110/21] via 12.1.1.2, 00:10:33, FastEthernet0/0
     23.0.0.0/24 is subnetted, 1 subnets
O IA    23.1.1.0 [110/20] via 12.1.1.2, 00:11:19, FastEthernet0/0
     12.0.0.0/24 is subnetted, 1 subnets
C       12.1.1.0 is directly connected, FastEthernet0/0

我們可以看見,標記O IA的為ospf其他區域路由,和我們宣告的一致,那麼我們來檢視一下LSA-1和LSA-2

R1#show ip ospf database 

            OSPF Router with ID (1.1.1.1) (Process ID 100)

                Router Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum Link count
1.1.1.1         1.1.1.1         816         0x80000003 0x0043A8 2
2.2.2.2         2.2.2.2         817         0x80000002 0x002ACD 1

                Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
12.1.1.2        2.2.2.2         817         0x80000001 0x001204

                Summary Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
2.2.2.2         2.2.2.2         857         0x80000001 0x00FA31
3.3.3.3         2.2.2.2         766         0x80000001 0x0031EC
23.1.1.0        2.2.2.2         842         0x80000001 0x006EA3

可以看見第一個Router Link States就是LSA-1,在這裡我們看到了這個區域的OSPF路由器的Link ID(就是路由器的Router-id)和宣告者(就是自己),檢視具體LSA-1細節使用show ip ospf database router這條命令,由於條目太長這裡就不演示了。
第二個Wet Link States就是LSA-2,在這裡我們只看到了12.1.1.2這一條,因為LSA-2只在本區內傳播,而宣告進區域0的只有R1自身的ip和R2的f0/0埠,所以我們只能看到一條12.1.1.2路由,在這裡Link-id就是路由。檢視LSA-2的具體細節使用如下命令:

R1#show ip ospf database n      
% Ambiguous command:  "show ip ospf database n"
R1#show ip ospf database n
R1#show ip ospf database ne
R1#show ip ospf database network 

            OSPF Router with ID (1.1.1.1) (Process ID 100)

                Net Link States (Area 0)

  Routing Bit Set on this LSA
  LS age: 1334
  Options: (No TOS-capability, DC)
  LS Type: Network Links
  Link State ID: 12.1.1.2 (address of Designated Router)
  Advertising Router: 2.2.2.2
  LS Seq Number: 80000001
  Checksum: 0x1204
  Length: 32
  Network Mask: /24
        Attached Router: 2.2.2.2
        Attached Router: 1.1.1.1

我們可以看到network mask掩碼為/24(這在LSA-1中是看不到的),下面的Attached Router為參與這個區域的路由器的Router-id。

LSA-3 Summary LSA

彙總LSA,可通過操作攔截

  • 傳播範圍:整個OSPF域
  • 通告者:ABR(本區域邊界路由器,可能發生改變)
  • 內容:域間路由,LSA-3穿越多個ABR時,通告者改變
  • 檢視方法:show ip ospf database中的summary

Link-id為路由
我們將拓撲圖稍微改一下:
這裡寫圖片描述
我們將R3上加了三個環回口並宣告進ospf區域,配置在這裡就不演示了,直接在R1檢視路由表:

R1#show ip route 
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

Gateway of last resort is not set

     1.0.0.0/32 is subnetted, 1 subnets
C       1.1.1.1 is directly connected, Loopback0
     2.0.0.0/32 is subnetted, 1 subnets
O IA    2.2.2.2 [110/11] via 12.1.1.2, 00:00:06, FastEthernet0/0
     3.0.0.0/32 is subnetted, 1 subnets
O IA    3.3.3.3 [110/21] via 12.1.1.2, 00:00:06, FastEthernet0/0
     23.0.0.0/24 is subnetted, 1 subnets
O IA    23.1.1.0 [110/20] via 12.1.1.2, 00:00:06, FastEthernet0/0
     192.168.21.0/32 is subnetted, 1 subnets
O IA    192.168.21.1 [110/21] via 12.1.1.2, 00:00:06, FastEthernet0/0
     192.168.20.0/32 is subnetted, 1 subnets
O IA    192.168.20.1 [110/21] via 12.1.1.2, 00:00:08, FastEthernet0/0
     192.168.23.0/32 is subnetted, 1 subnets
O IA    192.168.23.1 [110/21] via 12.1.1.2, 00:00:09, FastEthernet0/0
     192.168.22.0/32 is subnetted, 1 subnets
O IA    192.168.22.1 [110/21] via 12.1.1.2, 00:00:10, FastEthernet0/0
     12.0.0.0/24 is subnetted, 1 subnets
C       12.1.1.0 is directly connected, FastEthernet0/0

我們看見剛加的環回口已經進入了路由表,這時我們先來看一下鏈路狀態資料庫:

R1#show ip ospf database 

            OSPF Router with ID (1.1.1.1) (Process ID 100)

                Router Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum Link count
1.1.1.1         1.1.1.1         202         0x80000005 0x003FAA 2
2.2.2.2         2.2.2.2         811         0x80000003 0x0028CE 1

                Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
12.1.1.2        2.2.2.2         811         0x80000002 0x001005

                Summary Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
2.2.2.2         2.2.2.2         811         0x80000002 0x00F832
3.3.3.3         2.2.2.2         811         0x80000002 0x002FED
23.1.1.0        2.2.2.2         811         0x80000002 0x006CA4
192.168.20.1    2.2.2.2         11          0x80000001 0x002388
192.168.21.1    2.2.2.2         11          0x80000001 0x001892
192.168.22.1    2.2.2.2         11          0x80000001 0x000D9C
192.168.23.1    2.2.2.2         11          0x80000001 0x0002A6

我們看見Summary Net Link States就是LSA-3這裡我們可以看見所有不是Area 0中宣告的路由,宣告者均為R2也就是Area 0的ABR。接下來我們在R2上位192網段做一下彙總,之後再來檢視路由表:

R1#show ip route         
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

Gateway of last resort is not set

     1.0.0.0/32 is subnetted, 1 subnets
C       1.1.1.1 is directly connected, Loopback0
     2.0.0.0/32 is subnetted, 1 subnets
O IA    2.2.2.2 [110/11] via 12.1.1.2, 00:05:54, FastEthernet0/0
     3.0.0.0/32 is subnetted, 1 subnets
O IA    3.3.3.3 [110/21] via 12.1.1.2, 00:05:54, FastEthernet0/0
     23.0.0.0/24 is subnetted, 1 subnets
O IA    23.1.1.0 [110/20] via 12.1.1.2, 00:05:54, FastEthernet0/0
     12.0.0.0/24 is subnetted, 1 subnets
C       12.1.1.0 is directly connected, FastEthernet0/0
O IA 192.168.20.0/22 [110/21] via 12.1.1.2, 00:00:06, FastEthernet0/0

已經成功彙總,那麼檢視一下LSA-3變成了什麼樣子:

R1#show ip ospf database 

            OSPF Router with ID (1.1.1.1) (Process ID 100)

                Router Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum Link count
1.1.1.1         1.1.1.1         375         0x80000005 0x003FAA 2
2.2.2.2         2.2.2.2         984         0x80000003 0x0028CE 1

                Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
12.1.1.2        2.2.2.2         984         0x80000002 0x001005

                Summary Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
2.2.2.2         2.2.2.2         984         0x80000002 0x00F832
3.3.3.3         2.2.2.2         984         0x80000002 0x002FED
23.1.1.0        2.2.2.2         984         0x80000002 0x006CA4
192.168.20.0    2.2.2.2         31          0x80000001 0x001E91

可見LSA-3是一個域間路由彙總的LSA,Link-id就是路由。宣告者就是本區域ABR。

LSA-4 Summary ASB LSA

告訴其他區域ASBR所在的位置,根據LSA-5而來

  • 傳播範圍:除ASBR所在區域外的整個OSPF區域
  • 宣告者:ABR(穿越多個ABR時改變)
  • 內容:ASBR的Router-id

ASBR會通過LSA-1通告自己的ABR自己是ASBR,所以ABR中沒有LSA-4,出現重分發動作後,LSA-1自動改變

LSA-5 External LSA

外部LSA,不屬於任何一個區域

  • 傳播範圍:整個OSPF域
  • 宣告者:ASBR(只有引入了外部路由並且重分發動作執行後才會成為ASBR,通告在穿過多個區域時一直不改變)
  • 內容:域外路由,在路由表中標記為OE2

LSA-4和LSA-5通常是一起出現的,LSA-5講述的是外部路由,而LSA-4則是說ASBR的位置,所以是先有LSA-5再有LSA-4,我們將上面的拓撲稍微修改一下,將R3上的192網段從ospf中取消宣告(別忘了在R2上取消彙總),然後宣告進入rip之後對OSPF進行重分發,操作如下:

R3(config)#router os 100
R3(config-router)#no net 192.168.20.0 0.0.0.255 a 1         
R3(config-router)#no net 192.168.21.0 0.0.0.255 a 1
R3(config-router)#no net 192.168.22.0 0.0.0.255 a 1
R3(config-router)#no net 192.168.23.0 0.0.0.255 a 1
R3(config-router)#exi
R3(config)#router rip
R3(config-router)#v 2
R3(config-router)#no au
R3(config-router)#net 192.168.20.0
R3(config-router)#net 192.168.21.0
R3(config-router)#net 192.168.22.0
R3(config-router)#net 192.168.23.0
R3(config-router)#exi
R3(config)#router os 100
R3(config-router)#redistribute rip subnets 
R3(config-router)#exi
R2(config)#router os 100
R2(config-router)#no area 1 range 192.168.20.0 255.255.252.0

然後我們在R1檢視路由表:

R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route

Gateway of last resort is not set

     1.0.0.0/32 is subnetted, 1 subnets
C       1.1.1.1 is directly connected, Loopback0
     2.0.0.0/32 is subnetted, 1 subnets
O IA    2.2.2.2 [110/11] via 12.1.1.2, 00:23:09, FastEthernet0/0
     3.0.0.0/32 is subnetted, 1 subnets
O IA    3.3.3.3 [110/21] via 12.1.1.2, 00:23:09, FastEthernet0/0
     23.0.0.0/24 is subnetted, 1 subnets
O IA    23.1.1.0 [110/20] via 12.1.1.2, 00:23:09, FastEthernet0/0
O E2 192.168.21.0/24 [110/20] via 12.1.1.2, 00:01:58, FastEthernet0/0
O E2 192.168.20.0/24 [110/20] via 12.1.1.2, 00:02:20, FastEthernet0/0
O E2 192.168.23.0/24 [110/20] via 12.1.1.2, 00:01:54, FastEthernet0/0
O E2 192.168.22.0/24 [110/20] via 12.1.1.2, 00:01:57, FastEthernet0/0
     12.0.0.0/24 is subnetted, 1 subnets
C       12.1.1.0 is directly connected, FastEthernet0/0

ok,我們發現O E2已經寫入到路由表了,接下來我們檢視一下鏈路狀態資料庫:

R1#show ip ospf database 

            OSPF Router with ID (1.1.1.1) (Process ID 100)

                Router Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum Link count
1.1.1.1         1.1.1.1         1461        0x80000005 0x003FAA 2
2.2.2.2         2.2.2.2         56          0x80000004 0x0026CF 1

                Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
12.1.1.2        2.2.2.2         56          0x80000003 0x000E06

                Summary Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
2.2.2.2         2.2.2.2         56          0x80000003 0x00F633
3.3.3.3         2.2.2.2         56          0x80000003 0x002DEE
23.1.1.0        2.2.2.2         56          0x80000003 0x006AA5

                Summary ASB Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
3.3.3.3         2.2.2.2         621         0x80000001 0x001905

                Type-5 AS External Link States

Link ID         ADV Router      Age         Seq#       Checksum Tag
192.168.20.0    3.3.3.3         220         0x80000001 0x00FE18 0
192.168.21.0    3.3.3.3         201         0x80000001 0x00F322 0
192.168.22.0    3.3.3.3         199         0x80000001 0x00E82C 0
192.168.23.0    3.3.3.3         197         0x80000001 0x00DD36 0

我們看見,比之剛才,多了一個叫做Summary ASB Link States和一個Type-5 AS External LInk States的表,這兩個分別是LSA-4和LSA-5,顯然,LSA-4和LSA-5的內容和剛才介紹的一樣,LSA-5講述的是域外路由,Link-id就是路由,宣告者是ASBR也就是R3的Router-id。LSA-4講述的是ASBR的Router-id,Link-id是ASBR的Router-id,宣告者就是ASBR所在區域的ABR的Router-id。

LSA-7 AS External LSA

與LSA-5只是稱呼的不同,都是關於域外路由的

  • 傳播範圍:整個NSSA區域
  • 宣告者:ASBR(穿過多個區域時一直不改變)
  • 內容:域外路由

LSA-7只會出現在NSSA區域(關於NSSA區域請看我的另一篇文章:OSPF特殊區域
我們將上述拓撲圖略作修改,將Area 1設定為NSSA區域。

這裡寫圖片描述
在R2和R3上配置:

R2(config)#router os 100
R2(config-router)#area 1 nssa 
R3(config)#router os 100
R3(config-router)#area 1 nssa 

配置好之後我們在R2上檢視鏈路狀態資料庫(注意是R2不是R1)

R2#show ip os database 

            OSPF Router with ID (2.2.2.2) (Process ID 100)

                Router Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum Link count
1.1.1.1         1.1.1.1         60          0x80000006 0x003DAB 2
2.2.2.2         2.2.2.2         63          0x80000005 0x002AC8 1

                Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
12.1.1.2        2.2.2.2         569         0x80000003 0x000E06

                Summary Net Link States (Area 0)

Link ID         ADV Router      Age         Seq#       Checksum
2.2.2.2         2.2.2.2         569         0x80000003 0x00F633
3.3.3.3         2.2.2.2         43          0x80000001 0x0031EC
23.1.1.0        2.2.2.2         569         0x80000003 0x006AA5

                Router Link States (Area 1)

Link ID         ADV Router      Age         Seq#       Checksum Link count
2.2.2.2         2.2.2.2         48          0x80000008 0x00CCEC 2
3.3.3.3         3.3.3.3         51          0x80000015 0x00C3DC 2

                Net Link States (Area 1)

Link ID         ADV Router      Age         Seq#       Checksum
23.1.1.3        3.3.3.3         51          0x80000005 0x004CA7

                Summary Net Link States (Area 1)

Link ID         ADV Router      Age         Seq#       Checksum
1.1.1.1         2.2.2.2         67          0x80000006 0x0029F1
12.1.1.0        2.2.2.2         68          0x80000004 0x009D76

                Type-7 AS External Link States (Area 1)

Link ID         ADV Router      Age         Seq#       Checksum Tag
192.168.20.0    3.3.3.3         59          0x80000001 0x0001FF 0
192.168.21.0    3.3.3.3         60          0x80000001 0x00F50A 0
192.168.22.0    3.3.3.3         60          0x80000001 0x00EA14 0
192.168.23.0    3.3.3.3         60          0x80000001 0x00DF1E 0

                Type-5 AS External Link States

Link ID         ADV Router      Age         Seq#       Checksum Tag
192.168.20.0    2.2.2.2         50          0x80000001 0x00B35B 0
192.168.21.0    2.2.2.2         52          0x80000001 0x00A865 0
192.168.22.0    2.2.2.2         52          0x80000001 0x009D6F 0
192.168.23.0    2.2.2.2         52          0x80000001 0x009279 0

我們可以看見,首先在Type-5 AS External Link States上方出現了一個Type-7 AS External Link States的Link-id完全一樣但宣告者不同的LSA,這就是LSA-7,只有在NSSA去榆中的外部路由採用LSA-7來表示。注意這裡LSA_5,宣告者由之前的R3變成了E2,在之前的那篇OSPF特殊區域中提到過,在NSSA區域和普通票哪個區域的ABR處(這張圖中是R2)會進行一個叫做七轉五的操作,而有能力發LSA-5的路由器才能稱為ASBR。而因為NSSA區域過濾LSA-4和LSA-5所以這裡看不見LSA-4(LSA-5是ABR進行的七轉五得到的,而不是ASBR宣告的)。不出意外