一:链路状态数据库简述: <?xml:namespace prefix = o />

每一台 OSPF 路由器都会把所有有效的 LSA 放入自己的链路状态数据库中,这些 LSA 代表着这个路由器对这个区域的认识,区域内的每一个 OSPF 路由器都要利用到这些 LSA 去计算路由,因此,保证同区域内的链路状态数据库的统一性和正确性就显得尤为重要。

我们知道,每一条 LSA 都有着其最大老化时间(时间是一小时),一旦该条 LSA 到达了老化时间,他将被路由器从链路状态数据库中清除。那么为了避免出现这种状况,路由器引入一种

重刷新机制( l ink-state refresh ),每隔 30 分钟(这个时间称为

LSRefreshTime ,即重刷新计时器 ), LSA 的始发路由器将会将这条 LSA 泛洪出去。并将该条 LSA 的序列号加一,老化时间设为 0 ,其他路由器收到此新的拷贝信息后,将会用这条新的拷贝来替换该条 LSA 的原来的拷贝。

这里需要注意的是,由于每条 LSA 都是使用的单独的重刷新计时器,那么这里就会出现一个问题,那就是可能在单位时间内泛洪出去的 LSA 很少,甚至只有一条,那么链路带宽的使用将会变得效率极低。
在早期的 IOS 中,思科路由器是采用的一个单独的 LSRefreshTime ,即所有的的 LSA 共用一个 LSRefreshTime ,这样做固然是可以提高带宽的使用效率,但是其所带来的问题是,如果 LSA 的数量非常多的话,那么网络每隔 30 分钟将会出现一次区域通信量和 CPU 使用率的高峰。

为了平衡这种问题,思科引入了一种 LSA 的组步调机制( group pacing ),即作为一种每个 LSA 使用一个单独的重刷新计时器和所有 LSA 共用一个重刷新计时器之间的一个折衷方法。在此机制下,每一个 LSA 都会有自己单独的重刷新计时器,但是当其计时器到期后,路由器不会立即将其泛洪出去,而是会引入一个时延来延迟这些 LSA 的发送,通过这种方法,可以将更多的 LSA 编制成一组发送出去,思科默认的时延是 240 秒,可以通过命令 timers lsa-group-pacing 来修改这个时间。如果说链路状态数据库非常的庞大( LSA 的数量大于 10000 条),那么适当减小这个延迟时间是有好处的,如果链路状态数据库比较小的话,那么适当增减这个延迟时间是有好处的。

 

二: LSA 1

每一个 OSPF 路由器都会产生一类 LSA ,此类 LSA 描述了路由器所连接的全部链路或接口,以及此链路上所连接的邻居。可以通过命令:

Ship ospf database router 来查看:

 

 LS age: 385

  Options: (No TOS-capability, DC)

  LS Type: Router Links

  Link State ID:<?xml:namespace prefix = st1 />1.1.1.1

  Advertising Router: 1.1.1.1

  LS Seq Number: 80000003

  Checksum: 0x1743

  Length: 60 

Number of Links: 5

Link connected to: a Stub Network

     (Link ID) Network/subnet number: 1.1.1.1

     (Link Data) Network Mask: 255.255.255.255

      Number of TOS metrics: 0

       TOS 0 Metrics: 1

 

    Link connected to: another Router (point-to-point)

     (Link ID) Neighboring Router ID: 2.2.2.2

     (Link Data) Router Interface address: 12.0.0.1

      Number of TOS metrics: 0

       TOS 0 Metrics: 64

 

    Link connected to: a Stub Network

     (Link ID) Network/subnet number: 12.0.0.0

     (Link Data) Network Mask: 255.255.255.0

      Number of TOS metrics: 0

       TOS 0 Metrics: 64

 

    Link connected to: a Transit Network

     (Link ID) Designated Router address: 10.0.0.1

     (Link Data) Router Interface address: 10.0.0.1

      Number of TOS metrics: 0

       TOS 0 Metrics: 1

 

    Link connected to: a Virtual Link

     (Link ID) Neighboring Router ID: 2.2.2.2

     (Link Data) Router Interface address: 12.0.0.2

      Number of TOS metrics: 0

       TOS 0 Metrics: 64

 

 

 

 

 

下面来看下一类 LSA 的字段:

<?xml:namespace prefix = v />

 

Link State ID for Router LSAs is the originating router's Router ID. (不同的 LSA 此字段的含义也将会不同)

V, or Virtual Link Endpoint bit, is set to one when the originating router is an endpoint of one or more fully adjacent virtual links

having the described area as the transit area.

 

E, or External bit, is set to one when the originating router is an ASBR.

提出问题: 一类 LSA 中,此字段的作用是什么?

解决问题: OSPF 某一区域引入了外部路由时,那么在此区域内的路由器是不需要 LSA 4 的,那么此时,就依靠 LSA 1 当中的 E 字段来确定 ASBR 的位置。

 

B, or Border bit, is set to one when the originating router is an ABR.

提出问题: 一类 LSA 中,此字段的作用是什么?

解决问题: 先思考下三类 LSA 的作用: ABR 路由器会将一个区域的的信息发送到另一个区域去(特殊区域除外),通过的就是三类 LSA ,那么区域路由器有必要知道 ABR 的位置,而如果三类 LSA 中,宣告者的 route-id B 位中的显示的不一致的话,那么接收路由器将会认为这条 LSA 3 是非法的,而拒绝把它放入路由表

 

Number of Links specifies the number of router links the LSA describes. The Router LSA must describe all of the originating

router's links, or interfaces, to the area in which the LSA is flooded.

 

Link Type describes the general type of connection the link provides. Table 8-9 lists the possible values of the field and the

associated connection types.

Table 8-9. Link type values.

Link Type Connection

1 Point-to-point connection to another router

2 Connection to a transit network

3 Connection to a stub network

4 Virtual link

请注意: Link type value 将会导致 Link ID Link Date 的不同

 

Link ID identifies the object to which the link connects. This is dependent on the link type, as shown in Table 8-10 . Note that

when the connected object is another router, the Link ID is the same as the Link State ID in the header of the neighboring

router's LSA. During the routing table calculation, this value is used to find the neighbor's LSA in the link-state database.

Table 8-10. Link ID values.

Link Type Value of Link ID Field

1 Neighboring router's Router ID

2 IP address of the DR's interface

3 IP network or subnet address

4 Neighboring router's Router ID

Link Data also depends on the value of the Link Type field, as shown in Table 8-11 .

Table 8-11. Link data values.

Link Type Value of Link Data Field

1 IP address of the originating router's interface to the network [*]

2 IP address of the originating router's interface to the network

3 Network's IP address or subnet mask

4 The MIB-II ifIndex value for the originating router's interface

[*] If the point-to-point link is unnumbered, this field will instead carry the MIB-II ifIndex value of the interface.

 

二: LSA-2

 

LSA 1 LSA 2 的关系:

OSPF 中, LSA 2 是由网络中的 DR 产生的,而 LSA 2 类的信息是极为简洁的,如下所示:

二类 LSA 示例:

  Routing Bit Set on this LSA

  LS age: 257

  Options: (No TOS-capability, DC)

  LS Type: Network Links

  Link State ID: 10.0.0.1 (address of Designated Router)

  Advertising Router: 1.1.1.1

  LS Seq Number: 80000003

  Checksum: 0x9761

  Length: 40

  Network Mask: /24

        Attached Router: 1.1.1.1

        Attached Router: 2.2.2.2

        Attached Router: 3.3.3.3

        Attached Router: 4.4.4.4

因此在广播多路访问网络中,要想构建出一个完整的网络拓扑,还必须借助 LSA 1 的帮助。可是我们会问,在多路访问网络中,为什么还需要 LSA 2 类呢?要知道 LSA 2 类中仅仅只包含了 DR 自身的信息以及连入此多路访问网络中路由器的 ID ,而 DR 的基本信息在每个路由器连入此网络的接口的数据库中都有保存,因此 LSA 2 看起来似乎多余。但是仔细想想在多路访问网络中每个路由器之间的关系我们会发现, Drother 之间所建立的仅仅只是 2 way 关系。我们现在来假设有三台路由器,分别是 A B C 。其中 A 路由器是 DR ,其余两台是 Drother ,当 B 路由器向 A 发送了一条 LSA 1 的更新信息,由于 LSA 1 的特性是在整个 OSPF 区域内泛洪,所以 DR 会将此信息转发 C 路由器,假设没有 LSA 2 ,那么由于 B 路由器与 C 路由器所建立的仅仅只是 2 way 关系,所以 C 路由器会认为这条信息不可信,而拒绝使用此条 LSA 进行路由的计算。而此时若有 LSA 2 的话,情况就不一样了,我们来看下 LSA 2 中的这样一段信息:

Attached Router: 1.1.1.1

        Attached Router: 2.2.2.2

        Attached Router: 3.3.3.3

        Attached Router: 4.4.4.4

这个字段中的含义是,连入此多路访问网络中的路由器有哪些。由于 DR 与多路访问网络中的其他路由器建立的是完全邻接关系,换而言之, DR 对整个网络有着完全清晰的认识,所以当 C 路由器接受到了 B 路由器的更新信息以后,如果在 LSA 2 类所显示的连入此多路访问网络中的路由器包含有 B 路由器的话,那么 C 路由器就会认为此条 LSA 更新信息合法,将会把它用于路由选择计算,否则就认为不合法,而不被用于路由计算。

LSA 3

每台 ABR 路由器都会将他所连的某一区域的的路由信息告诉 ABR 所连的其他的区域,

 

三类LSA示例:

  LS age: 586

  Options: (No TOS-capability, DC, Upward)

  LS Type: Summary Links(Network)

  Link State ID: 10.0.0.0 (summary Network Number)

  Advertising Router: 2.2.2.2

  LS Seq Number: 80000001

  Checksum: 0x2FF1

  Length: 28

  Network Mask: /24

        TOS: 0  Metric: 10

 

该条 LSA 中, ABR 向其他区域宣告了某个区域的一条汇总信息(注意:一条 LSA 3 信息只包含了一个网段 ),当区域内路由器受到了 LSA 3 类信息后,不会进行 SPF 算法进行计算,而只会简单的将 3 LSA 中所宣告的网段的 cost 值简单的与其到 ABR 路由器之间的 cost 值进行简单的累加,这有点像距离矢量路由协议的做法,因此这也就带来了潜在环路的可能,所以必需得要有一种防环机制,也就是:任何非骨干区域的必须要和骨干区域相连,而且非骨干区域不能传送 LSA

提出疑问: 如果 ABR 路由器连接了两个区域,分别是区域 0 和区域 1 ,区域 0 中有一个网段是 1.1.1.1/32 ,且 ABR 路由器有两条路径到该网段,那么 ABR 路由器又该产生怎样的 LSA 3 向区域 1 宣告呢?

解决疑问: 这个问题要分两种情况:第一种是: ABR 1.1.1.1 的两条路径的 cost 值不等,第二种是: ABR 1.1.1.1 的两条路径的 cost 值相等。这里需要说明的是,无论如何, ABR 都将宣告 1.1.1.1 这个网段的信息,而至于 ABR 会选择哪条路径则是通过其中的 cost 值来体现

首先来讨论第一种情况:在此种情况下, ABR 会选择 cost 值最低的那条路径来产生 3 LSA

第二种情况: 这种情况貌似多余的,因为选择哪条路径来产生 3 LSA 是通过 cost 值来决定的,而两条路径的 cost 值都相等,所以无论选择哪条,其所产生的 3 LSA 都是相同的,那么这里我们就会问,假设区域 1 的某台路由器发送了一个到 1.1.1.1 ping 包,那么 ABR 是否会进行负载均衡的转发呢?答案是否定的,因为这时候的 ABR 路由器作为转发路由器,会进行快速交换,即在缓存表中建立一个映射关系,即:

 

R2#sh ip cache

Prefix/Length           Age       Interface       Next Hop

1.1.1.1/32              00:10:03  Serial0         12.0.0.1

 

一般而言,负载均衡只是针对始发路由器而言的