示例:配置 RPD 基础架构中路由前缀的优先级
此示例说明如何在 RPD 基础架构中为 OSPF、LDP 和 BGP 协议配置路由前缀的优先级。
要求
此示例使用以下硬件和软件组件:
ACX 系列、M 系列、MX 系列、PTX 系列和 T 系列组合的三款路由器。
在所有设备上运行的 Junos OS 16.1 或更高版本。
准备工作:
配置设备接口。
配置以下协议:
BGP
MPLS
OSPF
LDP
概述
在具有大量路由的网络中,控制路由的更新顺序以实现更好的收敛并提供差异化服务有时非常重要。前缀优先级可帮助用户确定某些路由/前缀的优先级,并控制路由在 RIB(路由表)和 FIB(转发表)中的更新顺序。在 Junos OS 16.1 版及更高版本中,您可以控制路由从 LDP/OSPF 更新到 rpd 以及从 rpd 更新到内核的顺序。您可以指定协议中现有导入策略的high
low
优先级或通过协议中的现有导入策略指定优先级。如果拓扑发生更改,将首先在路由表中更新高优先级前缀,然后更新低优先级前缀。通常,未显式分配优先级的路由被视为中等优先级。在同一优先级内,路由将继续按字典顺序更新。
在此示例中,路由设备位于区域 0.0.0.0 中,接口 ge-1/3/0 连接到相邻设备。您可以配置三个导入路由策略:下一跃点自身、OSPF-PRIO 和prio_for_bgp。路由策略下一跃点自接受来自 BGP 的路由。对于 OSPF 路由策略,将首先安装与 172.16.25.3/32 匹配的路由,因为它们的优先级为高。LDP 从 OSPF 导入路由。对于 BGP 优先级,首先安装与 172.16.50.1/32 匹配的路由,因为它们的优先级为高。与这些前缀关联的路由将按前缀的指定优先级顺序安装在路由表中。
配置
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改详细信息,以便与网络配置匹配,将命令复制并粘贴到 [edit] 层级的 CLI 中,然后从配置模式进入 commit
。
R1
set interfaces ge-1/3/0 unit 0 family inet address 172.16.12.1/24 set interfaces ge-1/3/0 unit 0 family mpls set interfaces lo0 unit 0 family inet address 172.16.25.1/32 set protocols mpls interface ge-1/3/0.0 set protocols bgp group prio_internal type internal set protocols bgp group prio_internal local-address 172.16.25.1 set protocols bgp group prio_internal import prio_for_bgp set protocols bgp group prio_internal neighbor 172.16.25.3 family inet unicast set protocols bgp group prio_internal neighbor 172.16.25.3 export next-hop-self sset protocols ospf import ospf_prio set protocols ospf area 0.0.0.0 interface ge-1/3/0.0 set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ldp interface ge-1/3/0.0 set protocols ldp interface lo0.0 set policy-options policy-statement next-hop-self term nhself from protocol bgp set policy-options policy-statement next-hop-self term nhself then next-hop self set policy-options policy-statement next-hop-self term nhself then accept set policy-options policy-statement ospf_prio term ospf_ldp from protocol ospf set policy-options policy-statement ospf_prio term ospf_ldp from route-filter 172.16.25.3/32 exact set policy-options policy-statement ospf_prio term ospf_ldp then priority high set policy-options policy-statement ospf_prio term ospf_ldp then accept set policy-options policy-statement prio_for_bgp term bgp_prio from protocol bgp set policy-options policy-statement prio_for_bgp term bgp_prio from route-filter 172.16.50.1/32 exact set policy-options policy-statement prio_for_bgp term bgp_prio then priority high set routing-options nonstop-routing set routing-options router-id 172.16.25.1 set routing-options autonomous-system 2525
R2
set interfaces ge-1/0/5 unit 0 family inet address 172.16.12.2/24 set interfaces ge-1/0/5 unit 0 family mpls set interfaces ge-1/3/0 unit 0 family inet address 172.16.23.2/24 set interfaces ge-1/3/0 unit 0 family mpls set interfaces lo0 unit 0 family inet address 172.16.25.2/32 set protocols mpls interface ge-1/0/5.0 set protocols mpls interface ge-1/3/0.0 set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ospf area 0.0.0.0 interface ge-1/0/5.0 set protocols ospf area 0.0.0.0 interface ge-1/3/0.0 set protocols ldp interface ge-1/0/5.0 set protocols ldp interface ge-1/3/0.0 set protocols ldp interface lo0.0 set routing-options nonstop-routing set routing-options router-id 172.16.25.2 set routing-options autonomous-system 2525
R3
set interfaces ge-1/0/1 unit 0 family inet address 172.16.23.3/24 set interfaces ge-1/0/1 unit 0 family mpls set interfaces lo0 unit 0 family inet address 172.16.25.3/32 set protocols mpls interface ge-1/0/1.0 set protocols bgp group prio_internal type internal set protocols bgp group prio_internal local-address 172.16.25.3 set protocols bgp group prio_internal neighbor 172.16.25.1 family inet unicast set protocols bgp group prio_internal neighbor 172.16.25.1 export next-hop-self set protocols bgp group prio_internal neighbor 172.16.25.1 export static_to_bgp set protocols ospf area 0.0.0.0 interface lo0.0 passive set protocols ospf area 0.0.0.0 interface ge-1/0/1.0 set protocols ldp interface ge-1/0/1.0 set protocols ldp interface lo0.0 set policy-options policy-statement next-hop-self term nhself from protocol bgp set policy-options policy-statement next-hop-self term nhself then next-hop self set policy-options policy-statement next-hop-self term nhself then accept set policy-options policy-statement static_to_bgp term s_to_b from protocol static set policy-options policy-statement static_to_bgp term s_to_b from route-filter 172.16.50.1/32 exact set policy-options policy-statement static_to_bgp term s_to_b from route-filter 172.16.50.2/32 exact set policy-options policy-statement static_to_bgp term s_to_b then accept set routing-options nonstop-routing set routing-options static route 172.16.50.1/32 receive set routing-options static route 172.16.50.2/32 receive set routing-options router-id 172.16.25.3 set routing-options autonomous-system 2525
配置设备 R1
分步过程
以下示例要求您在配置层次结构中导航各个级别。有关导航 CLI 的信息,请参阅 在配置模式下使用 CLI 编辑器CLI 用户指南。
要配置设备 R1:
配置接口。
[edit interfaces]
user@R1# set interfaces ge-1/3/0 unit 0 family inet address 172.16.12.1/24 user@R1# set interfaces ge-1/3/0 unit 0 family mpls user@R1# set interfaces lo0 unit 0 family inet address 172.16.25.1/32将环路地址分配给设备。
[edit lo0 unit 0 family]
user@R1# set address 172.16.25.1/32配置 MPLS。
[edit protocols]
user@R1# set protocols mpls interface ge-1/3/0.0配置路由器 R1 的路由器 ID 和自治系统。
[edit routing-options]
user@R1# set router-id 172.16.7.7 user@R1# set autonomous-system 100在路由器 R1 的接口上启用 OSPF。
[edit protocols]
user@R1# set protocols ospf import ospf_prio user@R1# set protocols ospf area 0.0.0.0 interface ge-1/3/0.0 user@R1# set protocols ospf area 0.0.0.0 interface lo0.0 passive在接口上配置 LDP 协议。
[edit protocols]
user@R1# set protocols ldp interface ge-1/3/0.0 user@R1# set protocols ldp interface lo0.0配置 BGP。
[edit protocols]
user@R1# set protocols bgp group prio_internal type internal user@R1# set protocols bgp group prio_internal local-address 172.16.25.1 user@R1# set protocols bgp group prio_internal import prio_for_bgp user@R1# set protocols bgp group prio_internal neighbor 172.16.25.3 family inet unicast user@R1# set protocols bgp group prio_internal neighbor 172.16.25.3 export next-hop-self配置策略选项以确定路由的优先级。策略下一跃点自身接受来自 BGP 的路由。您可以配置三个导入路由策略:下一跃点自身、OSPF-PRIO 和prio_for_bgp。路由策略下一跃点自接受来自 BGP 的路由。对于 ospf-prio 路由策略,将首先安装与 172.16.25.3/32 匹配的路由,因为它们的优先级为高。LDP 从 OSPF 导入路由。对于prio_for_bgp策略,首先安装与 172.16.50.1/32 匹配的路由,因为它们的优先级为高。
[edit policy-options policy-statement]
user@R1# set policy-options policy-statement next-hop-self term nhself from protocol bgp user@R1# set policy-options policy-statement next-hop-self term nhself then next-hop self user@R1# set policy-options policy-statement next-hop-self term nhself then accept user@R1# set policy-options policy-statement ospf_prio term ospf_ldp from protocol ospf user@R1# set policy-options policy-statement ospf_prio term ospf_ldp from route-filter 172.16.25.3/32 exact set policy-options policy-statement ospf_prio term ospf_ldp then priority high set policy-options policy-statement ospf_prio term ospf_ldp then accept set policy-options policy-statement prio_for_bgp term bgp_prio from protocol bgp set policy-options policy-statement prio_for_bgp term bgp_prio from route-filter 172.16.50.1/32 exact set policy-options policy-statement prio_for_bgp term bgp_prio then priority high
结果
在配置模式下,输入 show interfaces 、show protocols、show routing-options 和 show policy-options 命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以便进行更正。
[edit] user@R1# show interfaces ge-1/3/0 { unit 0 { family inet { address 172.16.12.1/24; } family mpls; } } lo0 { unit 0 { family inet { address address 172.16.25.1/32; } } }
[edit] user@R1# show protocols mpls { interface ge-1/3/0.0; } bgp { group prio_internal { type internal; local-address 172.16.25.1; import prio_for_bgp neighbor 172.16.25.3 { family inet { unicast; } export next-hop-self; } } } ospf { import ospf_prio; area 0.0.0.0 { interface ge-1/3/0.0; interface lo0.0 { passive; } } } ldp { interface ge-1/3/0.0; interface lo0.0; } }
[edit] user@R1# show routing-options nonstop-routing; router-id 172.16.25.1; autonomous-system 2525;
[edit] user@R1# show policy-options policy-statement next-hop-self { term nhself { from protocol bgp; then { next-hop self; accept; } } } policy-statement ospf_prio { term ospf_ldp { from { protocol ospf; route-filter 172.16.25.3/32 exact; } then { priority high; accept; } } } policy-statement prio_for_bgp { term bgp_prio { from { protocol bgp; route-filter 172.16.50.1/32 exact; } then priority high; } }
如果完成设备配置,请从配置模式输入 commit
。
验证
确认配置工作正常。
验证 OSPF 路由的优先级
目的
验证是否已为 OSPF 中的预期路由设置优先级。
操作
在设备 R1 上,从操作模式下运行 show ospf route 172.16.25.3/32 extensive
命令。高优先级应用于 OSPF 路由 172.16.25.3。
user@R1> show ospf route 172.16.25.3/32 extensive
Topology default Route Table:
Prefix Path Route NH Metric NextHop Nexthop
Type Type Type Interface Address/LSP
172.16.25.3 Intra Router IP 2 ge-1/3/0.0 172.16.12.2
area 0.0.0.0, origin 172.16.25.3, optional-capability 0x0
172.16.25.3/32 Intra Network IP 2 ge-1/3/0.0 172.16.12.2
area 0.0.0.0, origin 172.16.25.3, priority high
意义
输出显示优先级 high
应用于 OSPF 路由 172.16.25.3。
验证 LDP 路由的优先级
目的
验证 LDP 是否继承自 OSPF。
操作
在操作模式下,输入命令以 show route 172.16.25.3
验证 LDP 是否已从 OSPF 继承路由。
user@R1> show route 172.16.25.3
inet.0: 24 destinations, 24 routes (24 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.25.3/32 *[OSPF/10] 00:10:27, metric 2
> to 172.16.25.2 via ge-1/3/0.0
inet.3: 2 destinations, 2 routes (2 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.25.3/32 *[LDP/9] 00:10:24, metric 1
> to 172.16.25.2 via ge-1/3/0.0, Push 299824
在操作模式下,输入命令以 show route 172.16.25.3 extensive
验证 LDP 是否继承了优先级。
user@R1> show route 172.16.25.3 extensive
inet.0: 24 destinations, 24 routes (24 active, 0 holddown, 0 hidden)
172.16.25.3/32 (1 entry, 1 announced)
State:<Flashall>
TSI:
KRT in-kernel 172.16.25.3/32 -> {172.16.12.2}
*OSPF Preference: 10
Next hop type: Router, Next hop index: 549
Address: 0xa463390
Next-hop reference count: 6
Next hop: 172.16.12.2 via ge-1/3/0.0, selected
Session Id: 0x0
State:<Active Int HighPriority>
Local AS: 2525
Age: 10:43 Metric: 2
Validation State: unverified
Area: 0.0.0.0
Task: OSPF
Announcement bits (4): 0-KRT 4-LDP 6-Resolve tree 2 7-Resolve_IGP_FRR task
AS path: I
inet.3: 2 destinations, 2 routes (2 active, 0 holddown, 0 hidden)
172.16.25.3/32 (1 entry, 1 announced)
State:<Flashall>
LDP Preference: 9
Next hop type: Router, Next hop index: 582
Address: 0xa477810
Next-hop reference count: 12
Next hop: 172.16.12.2 via ge-1/3/0.0, selected
Label operation: Push 299824
Label TTL action: prop-ttl
Load balance label: Label 299824: None;
Label element ptr: 0xa17ad00
Label parent element ptr: 0x0
Label element references: 1
Label element child references: 0
Label element lsp id: 0
Session Id: 0x0
State:<Active Int HighPriority>
Local AS: 2525
Age: 10:40 Metric: 1
Validation State: unverified
Task: LDP
Announcement bits (3): 2-Resolve tree 1 3-Resolve tree 2 4-Resolve_IGP_FRR task
AS path: I
意义
输出显示 LDP 从 OSPF 继承路由 172.16.25.3 的优先级 high
。
验证 BGP 路由的优先级
目的
验证是否已在 BGP 中为预期路由设置优先级。
操作
在设备 R1 上,在操作模式下,运行 show route protocol bgp
命令以显示从 BGP 获知的路由。
user@R1> show route protocol bgp
inet.0: 24 destinations, 24 routes (24 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.50.1/32 *[BGP/170] 00:11:24, localpref 100, from 172.16.25.3
AS path: I, validation-state: unverified
> to 172.16.12.2 via ge-1/3/0.0, Push 299824
172.16.50.2/32 *[BGP/170] 00:11:24, localpref 100, from 172.16.25.3
AS path: I, validation-state: unverified
> to 172.16.12.2 via ge-1/3/0.0, Push 299824
inet.3: 2 destinations, 2 routes (2 active, 0 holddown, 0 hidden)
mpls.0: 9 destinations, 9 routes (9 active, 0 holddown, 0 hidden)
在设备 R1 上,从操作模式下运行 show route 172.16.50.1 extensive
命令。高优先级应用于 BGP 路由 172.16.50.1。
user@R1> show route 172.16.50.1 extensive
inet.0: 24 destinations, 24 routes (24 active, 0 holddown, 0 hidden)
172.16.50.1/32 (1 entry, 1 announced)
TSI:
KRT in-kernel 172.16.50.1/32 -> {indirect(1048574)}
*BGP Preference: 170/-101
Next hop type: Indirect, Next hop index: 0
Address: 0xa487b10
Next-hop reference count: 4
Source: 172.16.25.3
Next hop type: Router, Next hop index: 582
Next hop: 172.16.12.2 via ge-1/3/0.0, selected
Label operation: Push 299824
Label TTL action: prop-ttl
Load balance label: Label 299824: None;
Label element ptr: 0xa17ad00
Label parent element ptr: 0x0
Label element references: 1
Label element child references: 0
Label element lsp id: 0
Session Id: 0x0
Protocol next hop: 172.16.25.3
Indirect next hop: 0xa4a9800 1048574 INH Session ID: 0x0
State: <Active Int Ext HighPriority>
Local AS: 2525 Peer AS: 2525
Age: 11:49 Metric2: 1
Validation State: unverified
Task: BGP_2525.172.16.25.3
Announcement bits (2): 0-KRT 6-Resolve tree 2
AS path: I (Atomic)
Accepted
Localpref: 100
Router ID: 172.16.25.3
Indirect next hops: 1
Protocol next hop: 172.16.25.3 Metric: 1
Indirect next hop: 0xa4a9800 1048574 INH Session ID: 0x0
Indirect path forwarding next hops: 1
Next hop type: Router
Next hop: 172.16.12.2 via ge-1/3/0.0
Session Id: 0x0
172.16.25.3/32 Originating RIB: inet.3
Metric: 1 Node path count: 1
Forwarding nexthops: 1
Nexthop: 172.16.12.2 via ge-1/3/0.0
意义
输出显示优先级 high
应用于 BGP 路由 172.16.50.1。