OSPF – max-metric 的工作原理(Cisco)

注:机翻,未校。


OSPF – how max-metric works

Two costs for an interface 接口的两种成本

When you configure an OSPF interface with a cost, you can do it directly using ip ospf cost or have the cost calculated for you using auto-cost reference bandwidth. Whichever method you choose, the OSPF RFC 2328 calls it “the cost of sending a packet out this interface”. The Router LSA, or type-1 LSA, has a 16-bit field (65535 in decimal) to represent the “interface output cost”. An interface cost of 65535 is also known as “LSInfinity”.
当您配置 OSPF 接口时,可以直接使用 ip ospf cost 设置成本,也可以通过自动计算参考带宽来获得成本。无论您选择哪种方法,OSPF RFC 2328 都称其为“从该接口发送数据包的成本”。路由器 LSA,或称类型 1 LSA,有一个 16 位字段(以十进制表示为 65535)来表示“接口输出成本”。接口成本为 65535 的情况也被称为“LSInfinity”。

We’ll go through an example using links between routers which have been configured with OSPF network type point-to-point. The links have IP addresses and active adjacencies, so are represented by in the router LSA by both Stub and P2P links.
我们将通过一个示例来说明路由器之间配置为 OSPF 网络类型点对点的链接。这些链接具有 IP 地址和活动的邻接关系,因此在路由器 LSA 中同时表示为 Stub 链接和 P2P 链接。

Router_A#sh ip ospf interface fa1/0
FastEthernet1/0 is up, line protocol is up 
  Internet Address 192.168.12.1/24, Area 0 
  Process ID 100, Router ID 1.1.1.1, Network Type POINT_TO_POINT,  Cost: 10
Router_A#sh ip ospf database router self-originate
OSPF Router with ID (1.1.1.1) (Process ID 100)

Router Link States (Area 0)

LS age: 139
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 1.1.1.1
Advertising Router: 1.1.1.1
LS Seq Number: 80000006
Checksum: 0xCBB0
Length: 84
Number of Links: 3

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: 192.168.12.1
Number of TOS metrics: 0
TOS 0 Metrics: 10                    <--# cost for P2P A_B link

Link connected to: a Stub Network
(Link ID) Network/subnet number: 192.16.12.0
(Link Data) Network Mask: 255.255.255.0
Number of TOS metrics: 0
TOS 0 Metrics: 10                    <--# cost for Stub A_B link

Both the stub and P2P links have a cost specified in the router LSA for the A_B link, and they both reflect the configured “interface output cost”. I guess that makes sense, but which one is used in the the best-path calculations?
在路由器 LSA 中,A_B 链接的 stub 链接和 P2P 链接都有一个指定的成本,并且它们都反映了配置的“接口输出成本”。我想这很有道理,但是在最佳路径计算中使用的是哪一个?

Which link metric is used? 使用哪个链接度量标?

If both stub and P2P links have the same cost, why do we care which one is used in the path calculations? One reason that advanced OSPF features like “stub router” exploit the subtle differences between these costs.
如果 stub 链接和 P2P 链接的成本相同,为什么我们还要关心在路径计算中使用哪个?一个原因是高级 OSPF 特性,比如“stub 路由器”,利用了这些成本之间的微妙差异。

I’ve repeated the format from my previous post on P2P links in the ‘three-in-a-row’ example network below. I’ve broken out links to show them as they are represented in the OSPF router LSA.
我已在下面的“三连”示例网络中重复了之前关于点对点(P2P)链接的格式。我已经将链接拆分出来,以展示它们在 OSPF 路由器 LSA 中的表示方式。

在这里插入图片描述
Let’s look at the cost for router_A to reach router_B’s loopback at address 2.2.2.2. On router A’s interface to router B, the output interface cost used on the A_B link is cost from the point-to-point link (cost = 10). At router_B the output interface cost on the loopback interface is from the stub network link (cost = 1). So the calculation is pretty straight forward with a total path cost of 10 + 1=11 from router_A to router_B’s loopback at address 2.2.2.2.
让我们看一下 router_A 在地址 2.2.2.2 处达到 router_B 环回的成本。 在路由器 A 到路由器 B 的接口上,A_B 链路上使用的输出接口成本是点对点链路的成本 (cost = 10)。router_B 时,环回接口上的输出接口成本来自 stub 网络链路 (cost = 1)。 因此,计算非常简单,从地址 2.2.2.2 的 router_A 到 router_B 环回的总路径成本为 10 + 1=11。

Router_A#sh ip route 2.2.2.2
Routing entry for 2.2.2.2/32
Known via "ospf 100", distance 110, metric 11, type intra area
Last update from 192.16.12.2 on FastEthernet1/0, 00:13:45 ago
Routing Descriptor Blocks:
* 192.16.12.2, from 2.2.2.2, 00:13:45 ago, via FastEthernet1/0
Route metric is 11, traffic share count is 1

What if we wanted to reach router_B’s interface on the B_C link, at address 192.168.23.1. Once again, the output interface cost used on the A_B link is cost from the point-to-point link (cost = 10). As the B_C link is our destination, we use the cost of router_B’s stub network link on the B_C link (cost = 10). Thus, the total path cost of 10 + 10 = 20 from router_A to router_B’s interface on the B_C link at address 192.168.23.1.
如果我们想在 B_C 链路上访问 router_B 的接口,地址为 192.168.23.1,同样,A_B 链路上使用的输出接口成本是点对点链路的成本(成本 = 10)。 由于 B_C 链路是我们的目的地,因此我们在 B_C 链路上使用 router_B 的 stub 网络链路的成本 (cost = 10)。 因此,在地址为 192.168.23.1 的 B_C 链路上,从 router_A 到 router_B 接口的总路径成本为 10 + 10 = 20。

Router_A#sh ip route 192.168.23.1
Routing entry for 192.168.23.0/24
Known via "ospf 100", distance 110, metric 20, type intra area
Last update from 192.168.12.2 on FastEthernet1/0, 00:03:52 ago
Routing Descriptor Blocks:
* 192.168.12.2, from 2.2.2.2, 00:03:52 ago, via FastEthernet1/0
Route metric is 20, traffic share count is 1

I really want to drive home the fact that the stub link cost is only considered when calculating the path cost for the subnet assigned to that link.
我想强调一点:stub 链接的成本仅在计算分配给该链接的子网的路径成本时才会被考虑

Adding a second path 添加第二条路径

Let’s amend our diagram slightly and introduce a new link from router A to router C.
让我们稍微修改一下我们的图表,并引入从路由器 A 到路由器 C 的新链路。

在这里插入图片描述

I’ve set a cost of 100 on this A_C link to artificially force traffic over the A_B_C path under steady state conditions. If router_A was to ping router_C’s loopback at 3.3.3.3, there is a path cost of 21 via A_B_C, or a cost of 101 via A_C
我在此 A_C 链路上设置了 100 的成本,以便在稳态条件下人为地强制流量通过 A_B_C 路径。 如果 router_A 在 3.3.3.3 处对 router_C 的环回执行 ping 操作,则路径开销为 21 via A_B_C,或 101 的路径开销为 A_C

Router_A#sh ip route 3.3.3.3
Routing entry for 3.3.3.3/32
Known via "ospf 100", distance 110, metric 21, type intra area
Last update from 192.168.12.2 on FastEthernet1/0, 00:13:12 ago
Routing Descriptor Blocks:
* 192.168.12.2, from 3.3.3.3, 00:13:12 ago, via FastEthernet1/0
Route metric is 21, traffic share count is 1

Max-metric & LSInfinity Max-metric 和 LSInfinity

But what if we want to take router B out of service and shift traffic gracefully back to the A_C link. RFC 3137 introduces the ‘Stub Router’ feature that allows you to set the transit interfaces to their maximum link cost (or LSInfinity). Setting high costs on a router’s non-stub links, makes paths via that router look pretty crappy, thus shifting transit traffic away from that router.
但是,如果我们想将路由器 B 下线并优雅地将流量转回 A_C 链接呢?RFC 3137 引入了“Stub Router”特性,允许您将中继接口设置为其最大链路成本(或 LSInfinity)。在路由器的非 stub 链接上设置高成本,会使经该路由器的路径看起来不太理想,从而将中继流量引导离开该路由器。

IOS implements the ‘Stub router’ feature using the ‘max-metric command. Let’s start our traffic shift by configuring “max-metric router-lsa” under the ospf process 100 on router_B.
IOS 使用 “max-metric” 命令实现 “存根路由器” 功能。 让我们通过在 router_B 上的 ospf 进程 100 下配置 “max-metric router-lsa” 来开始我们的流量转移。

Router_B (config)#router ospf 100
Router_B (config-router)#max-metric router-lsa

The OSPF process on router_B immediately sets the P2P link cost to LSInfinity and floods a new router LSA with this information.
router_B 上的 OSPF 进程会立即将 P2P 链路成本设置为 LSInfinity,并将此信息淹没到新的路由器 LSA。

在这里插入图片描述
Looking at router_B’s new LSA we see that the A_B and B_C links have been set to LSInfinity (65535) by the ‘max-metric; command. Also note that the associated stub links on router_B have not been changed.
查看 router_B 的新 LSA,我们看到 A_B 和 B_C 链接已通过 “max-metric; 命令。 另请注意,router_B 上的关联存根链接尚未更改。

Router_A#sh ip ospf database router adv-router 2.2.2.2

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

Router Link States (Area 0)

LS age: 264
Options: (No TOS-capability, DC)
LS Type: Router Links
Link State ID: 2.2.2.2
Advertising Router: 2.2.2.2
LS Seq Number: 80000007
Checksum: 0x2A99
Length: 84
Number of Links: 5

Link connected to: a Stub Network
(Link ID) Network/subnet number: 2.2.2.2
(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: 3.3.3.3
(Link Data) Router Interface address: 192.168.23.2
Number of TOS metrics: 0
TOS 0 Metrics: 65535

Link connected to: a Stub Network
(Link ID) Network/subnet number: 192.168.23.0
(Link Data) Network Mask: 255.255.255.0
Number of TOS metrics: 0
TOS 0 Metrics: 10

Link connected to: another Router (point-to-point)
(Link ID) Neighboring Router ID: 1.1.1.1
(Link Data) Router Interface address: 192.168.12.2
Number of TOS metrics: 0
TOS 0 Metrics: 65535

Link connected to: a Stub Network
(Link ID) Network/subnet number: 192.168.12.0
(Link Data) Network Mask: 255.255.255.0
Number of TOS metrics: 0
TOS 0 Metrics: 10

Also note that the cost from router_A to router_B’s B_C link is unchanged, because router_B didn’t change the cost for it’s stub network on the B_C link.
另请注意,从 router_A 到 router_B B_C 链路的成本保持不变,因为 router_B 没有更改 B_C 链路上的短节网络的成本。

Router_A#sh ip route 192.168.23.2
Routing entry for 192.168.23.0/24
  Known via "ospf 100", distance 110, metric 20, type intra area
  Last update from 192.168.12.2 on FastEthernet1/0, 00:25:12 ago
  Routing Descriptor Blocks:
  * 192.168.12.2, from 2.2.2.2, 00:25:12 ago, via FastEthernet1/0
      Route metric is 20, traffic share count is 1

But what about our path from router_A to router_C’s loopback. Well, it looks like we’ve found a better path, and traffic to 3.3.3.3 will now follow our A_C link using the path cost of 101.
但是,我们从 router_A 到 router_C 环回的路径又如何呢?好吧,看起来我们已经找到了更好的路径,到 3.3.3.3 的流量现在将使用 101 的路径成本跟随我们的 A_C 链接。

Router_A#sh ip route 3.3.3.3
Routing entry for 3.3.3.3/32
  Known via "ospf 100", distance 110, metric 101, type intra area
  Last update from 192.168.13.3 on FastEthernet1/1, 00:09:06 ago
  Routing Descriptor Blocks:
  * 192.168.13.3, from 3.3.3.3, 00:09:06 ago, via FastEthernet1/1
      Route metric is 101, traffic share count is 1

De-preferenced but still available 降权但仍然可用

Setting link-costs to LSinfinity doesn’t make paths via those links invalid in OSPF terms, it just makes it less preferable. Let’s fail the A_C link and look at how OSPF responds.
将链接成本设置为 LSInfinity 并不会在 OSPF 的条目中使通过这些链接的路径无效,只会降低其可取性。让我们对 A_C 链接故障,看看 OSPF 如何响应。

Router_A#sh ip route 3.3.3.3
Routing entry for 3.3.3.3/32
  Known via "ospf 100", distance 110, metric 65546, type intra area
  Last update from 192.168.12.2 on FastEthernet1/0, 00:00:03 ago
  Routing Descriptor Blocks:
  * 192.168.12.2, from 3.3.3.3, 00:00:03 ago, via FastEthernet1/0
      Route metric is 65546, traffic share count is 1

We’ve fallen back to the A_B_C path, but traffic will still flow. The total cost is little ugly thanks to the stub-router feature still costing all it’s P2P links at 65535.
我们已经回退到 A_B_C 路径,但流量仍然会流动。由于 stub-router 特性仍将所有 P2P 链接的成本设置为 65535,总体成本看起来有些难看。

Total path cost is 10 (router_A interface to RouterB) + 65535 (router_B LSinfinity interface to router_C) + 1 (router_C loopback cost) = 65546.
总路径成本为 10(router_A 个接口到 RouterB)+ 65535(router_B 个 LSinfinity 接口到 router_C)+ 1(router_C 个环回成本)= 65546。


via:

  • 18
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值