OSPF使用LSA(链路状态通告)来在网络中的路由器之间交换网络拓扑信息。LSA详尽地描述了网络的拓扑,OSPF总共有LSA-1、LSA-2、LSA-3、LSA-4、LSA-5、LSA-7共6中LSA他们别别拥有不同的职能。
每一台运行OSPF的设备都会产生LSA-1,
Link-id为Router-id,ADV为通告者
注意,在LSA-1中看不到掩码,掩码信息需要在LSA-2中查看。
只在多路访问MA网络中存在
Attached router是成员
我们用下面拓扑图来验证一下LSA-1和LSA-2:
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,可通过操作拦截
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。
告诉其他区域ASBR所在的位置,根据LSA-5而来
ASBR会通过LSA-1通告自己的ABR自己是ASBR,所以ABR中没有LSA-4,出现重分发动作后,LSA-1自动改变
外部LSA,不属于任何一个区域
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-5只是称呼的不同,都是关于域外路由的
LSA-7只会出现在NSSA区域(关于NSSA区域请看我的另一篇文章:OSPF特殊区域)
我们将上述拓扑图略作修改,将Area 1设置为NSSA区域。
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宣告的)。不出意外的话我们在R1上查看链路状态数据库也是只能看到LSA-5但却没有LSA-4并且LSA-5的宣告者也是R2(R1上是没有LSA-7的,如果不知道为什么说明还是不理解NSSA区域和LSA-5,LSA-7,七转五这些概念):
R1#show ip os d
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 397 0x80000006 0x003DAB 2
2.2.2.2 2.2.2.2 402 0x80000005 0x002AC8 1
Net Link States (Area 0)
Link ID ADV Router Age Seq# Checksum
12.1.1.2 2.2.2.2 908 0x80000003 0x000E06
Summary Net Link States (Area 0)
Link ID ADV Router Age Seq# Checksum
2.2.2.2 2.2.2.2 908 0x80000003 0x00F633
3.3.3.3 2.2.2.2 382 0x80000001 0x0031EC
23.1.1.0 2.2.2.2 908 0x80000003 0x006AA5
Type-5 AS External Link States
Link ID ADV Router Age Seq# Checksum Tag
192.168.20.0 2.2.2.2 381 0x80000001 0x00B35B 0
192.168.21.0 2.2.2.2 383 0x80000001 0x00A865 0
192.168.22.0 2.2.2.2 383 0x80000001 0x009D6F 0
192.168.23.0 2.2.2.2 384 0x80000001 0x009279 0
ok和预测的一样,以上就是OSPF常见的六类LSA的讲解。