3. Protocol Independent Routing and VRFs
Route Policy For JUNOS/IOS
Test Topology
1. About IP routing
IOS XR routing tables
路由表可以使用 AFI SAFI 过滤 如 ipv4 unicast
administrative distance (preference)
通过多个来源收到相同路由时,用于选择活动路由,数字越小越优先
| protocol | value |
|---|---|
| directly connected interface | 0 |
| static route | 1 |
| DMNR | 3 |
| EIGRP (summary route) | 5 |
| eBGP | 20 |
| EIGRP (internal route) | 90 |
| IGRP | 100 |
| OSPF | 110 |
| IS-IS | 115 |
| RIP | 120 |
| EGP | 140 |
| ODR | 160 |
| EIGRP (external route) | 170 |
| iBGP | 200 |
| Unknown | 255 |
查看路由表
路由表可以使用 AFI SAFI 过滤 如 ipv4 unicast ,以下均以 ipv4 unicast 为例子
查看 RIB(仅最优路由)
RP/0/RP0/CPU0:R1-XR(config)#do show route ipv4 unicastFri Nov 1 04:50:55.224 UTC
Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path 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, E - EGP i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, su - IS-IS summary null, * - candidate default U - per-user static route, o - ODR, L - local, G - DAGR, l - LISP A - access/subscriber, a - Application route M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
Gateway of last resort is not set
C 1.1.1.0/24 is directly connected, 4w0d, GigabitEthernet0/0/0/0L 1.1.1.1/32 is directly connected, 4w0d, GigabitEthernet0/0/0/0C 2.2.2.0/24 is directly connected, 4w0d, GigabitEthernet0/0/0/1L 2.2.2.1/32 is directly connected, 4w0d, GigabitEthernet0/0/0/1B 22.22.22.22/32 [20/0] via 2.2.2.2, 00:03:25查看 RIB(非最优路由)
RP/0/RP0/CPU0:R1-XR(config)#do show route ipv4 unicast backupFri Nov 1 04:51:54.889 UTC
Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path 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, E - EGP i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, su - IS-IS summary null, * - candidate default U - per-user static route, o - ODR, L - local, G - DAGR, l - LISP A - access/subscriber, a - Application route M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
C 1.1.1.0/24 is directly connected, 4w0d, GigabitEthernet0/0/0/0 Backup i L1 [115/20] via 1.1.1.2, GigabitEthernet0/0/0/0B 22.22.22.22/32 [20/0] via 2.2.2.2, 00:04:25 Backup i L1 [115/10] via 1.1.1.2, GigabitEthernet0/0/0/0查看单协议路由表(以 IGP/BGP 为例)
RP/0/RP0/CPU0:R1-XR(config)#do show isis ipv4 unicast routeFri Nov 1 04:54:01.677 UTC
IS-IS 0 IPv4 Unicast routes
Codes: L1 - level 1, L2 - level 2, ia - interarea (leaked into level 1) df - level 1 default (closest attached router), su - summary null C - connected, S - static, R - RIP, B - BGP, O - OSPF E - EIGRP, A - access/subscriber, M - mobile, a - application i - IS-IS (redistributed from another instance)
Maximum parallel path count: 8
C 1.1.1.0/24 is directly connected, GigabitEthernet0/0/0/0L1 22.22.22.22/32 [10/115] via 1.1.1.2, GigabitEthernet0/0/0/0, R2-MX, Weight: 0RP/0/RP0/CPU0:R1-XR(config)#do show bgp ipv4 unicastFri Nov 1 04:55:30.438 UTCBGP router identifier 2.2.2.1, local AS number 100BGP generic scan interval 60 secsNon-stop routing is enabledBGP table state: ActiveTable ID: 0xe0000000 RD version: 3BGP main routing table version 3BGP NSR Initial initsync version 2 (Reached)BGP NSR/ISSU Sync-Group versions 0/0BGP scan interval 60 secs
Status codes: s suppressed, d damped, h history, * valid, > best i - internal, r RIB-failure, S stale, N Nexthop-discardOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path*> 22.22.22.22/32 2.2.2.2 0 200 i转发表
RP/0/RP0/CPU0:R1-XR(config)#do show cef ipv4Fri Nov 1 04:56:40.827 UTC
Prefix Next Hop Interface------------------- ------------------- ------------------0.0.0.0/0 drop default handler0.0.0.0/32 broadcast1.1.1.0/24 attached GigabitEthernet0/0/0/01.1.1.0/32 broadcast GigabitEthernet0/0/0/01.1.1.1/32 receive GigabitEthernet0/0/0/01.1.1.255/32 broadcast GigabitEthernet0/0/0/02.2.2.0/24 attached GigabitEthernet0/0/0/12.2.2.0/32 broadcast GigabitEthernet0/0/0/12.2.2.1/32 receive GigabitEthernet0/0/0/12.2.2.2/32 2.2.2.2/32 GigabitEthernet0/0/0/12.2.2.255/32 broadcast GigabitEthernet0/0/0/122.22.22.22/32 2.2.2.2/32 <recursive>224.0.0.0/4 0.0.0.0/32224.0.0.0/24 receive255.255.255.255/32 broadcastBGP 对某一个邻居的收发路由
RP/0/RP0/CPU0:R1-XR(config-bgp-nbr-af)#do show bgp ipv4 unicast neighbors 2.2.2.2 routesFri Nov 1 10:37:56.369 UTCBGP router identifier 2.2.2.1, local AS number 100BGP generic scan interval 60 secsNon-stop routing is enabledBGP table state: ActiveTable ID: 0xe0000000 RD version: 8BGP main routing table version 8BGP NSR Initial initsync version 2 (Reached)BGP NSR/ISSU Sync-Group versions 0/0BGP scan interval 60 secs
Status codes: s suppressed, d damped, h history, * valid, > best i - internal, r RIB-failure, S stale, N Nexthop-discardOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path*> 22.22.22.22/32 2.2.2.2 0 200 7 8 iRP/0/RP0/CPU0:R1-XR(config-bgp-nbr-af)#do show bgp ipv4 unicast advertised neighbor 2.2.2.2 summaryFri Nov 1 10:39:17.646 UTCNetwork Next Hop From AS Path33.33.33.33/32 2.2.2.1 Local 100 8 7?2. Static route
静态路由
此处给出 静态路由/静态黑洞路由/浮动静态路由的配置
router static address-family ipv4 unicast 33.33.33.33/32 Null0 44.44.44.44/32 1.1.1.2 55.55.55.55/32 1.1.1.2 100 55.55.55.55/32 2.2.2.2 100查看效果
RP/0/RP0/CPU0:R1-XR(config-static-afi)#do show route ipv4 unicastFri Nov 1 14:16:25.426 UTC
Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path 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, E - EGP i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, su - IS-IS summary null, * - candidate default U - per-user static route, o - ODR, L - local, G - DAGR, l - LISP A - access/subscriber, a - Application route M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
Gateway of last resort is not set
C 1.1.1.0/24 is directly connected, 4w1d, GigabitEthernet0/0/0/0L 1.1.1.1/32 is directly connected, 4w1d, GigabitEthernet0/0/0/0C 2.2.2.0/24 is directly connected, 4w1d, GigabitEthernet0/0/0/1L 2.2.2.1/32 is directly connected, 4w1d, GigabitEthernet0/0/0/1B 22.22.22.22/32 [20/0] via 2.2.2.2, 04:07:15S 33.33.33.33/32 is directly connected, 04:13:46, Null0S 44.44.44.44/32 [1/0] via 1.1.1.2, 00:14:02S 55.55.55.55/32 [1/0] via 1.1.1.2, 00:00:37 [1/0] via 2.2.2.2, 00:00:37
RP/0/RP0/CPU0:R1-XR(config-static-afi)#do show route ipv4 unicast staticFri Nov 1 14:16:29.082 UTC
S 33.33.33.33/32 is directly connected, 04:13:50, Null0S 44.44.44.44/32 [1/0] via 1.1.1.2, 00:14:06S 55.55.55.55/32 [1/0] via 2.2.2.2, 00:00:41 [1/0] via 1.1.1.2, 00:00:41静态路由可以修改 admin distance 和 metric
在静态路由后直接加数字为修改 admin distance ,加 metric 数字则为修改 metric 值 也可以一起修改
如:
55.55.55.55/32 1.1.1.2 100 metric 20 55.55.55.55/32 2.2.2.2 metric 20load balance
思科设备会对 metric+distance+prefix 完全一致的路由进行自动 ECMP
负载均衡算法:
RP/0/RP0/CPU0:R1-XR(config)#cef load-balancing fields ? L3 L3 information only hash computation L4 Include L4 information for hash computation ipv6 Use ipv6 fields for load-balancing mpls Use mpls fields for load-balancing3.VRF
IOS-XR 内 只有一种 VRF,你需要配 RD 值
不用于 MPLS-VPN 且不需要与其他 VRF 导表的时候可以没有 import/export 的 RT 值
建立 VRF
vrf test rd 100:1
# below is not force required # required if RT required address-family ipv4 unicast import route-target 100:1 ! export route-target 100:1也可以使用 route-policy 执行 VRF import/export(详见 MPLS VPN 部分)
vrf test rd 100:1
# below is not force required # required if RT required address-family ipv4 unicast import route-policy vrf-test-i export route-policy vrf-test-e将接口加入 VRF
interface GigabitEthernet0/0/0/0 vrf test ipv4 address 2.2.2.1 255.255.255.0!注意:先加 VRF 再配 IP 思科会要求先删除所有 IP 才能变更 VRF
向 VRF 内加入静态路由
router static vrf test address-family ipv4 unicast 1.1.1.1/32 2.2.2.2查看 VRF 路由
RP/0/RP0/CPU0:ios(config)#do show route vrf test ipv4 unicastThu Jun 12 12:53:58.063 UTC
Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path 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, E - EGP i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, su - IS-IS summary null, * - candidate default U - per-user static route, o - ODR, L - local, G - DAGR, l - LISP A - access/subscriber, a - Application route M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
Gateway of last resort is not set
S 1.1.1.1/32 [1/0] via 2.2.2.2, 02:10:32C 2.2.2.0/24 is directly connected, 02:12:07, GigabitEthernet0/0/0/0L 2.2.2.1/32 is directly connected, 02:12:07, GigabitEthernet0/0/0/0查看 VRF BGP 表
RP/0/RP0/CPU0:ios(config)#do show bgp vrf test ipv4 unicastThu Jun 12 15:12:52.429 UTCBGP VRF test, state: ActiveBGP Route Distinguisher: 100:1VRF ID: 0x60000001BGP router identifier 2.2.2.1, local AS number 100Non-stop routing is enabledBGP table state: ActiveTable ID: 0xe0000001 RD version: 41BGP main routing table version 46BGP NSR Initial initsync version 3 (Reached)BGP NSR/ISSU Sync-Group versions 0/0
Status codes: s suppressed, d damped, h history, * valid, > best i - internal, r RIB-failure, S stale, N Nexthop-discardOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight PathRoute Distinguisher: 100:1 (default for vrf test)*> 1.1.1.1/32 2.2.2.2 0 32768 ?*> 2.2.2.0/24 0.0.0.0 0 32768 ?*> 3.3.3.3/32 0.0.0.0 0 32768 ?查看全局 L3VPN 路由表
RP/0/RP0/CPU0:ios(config)#do show bgp vpnv4 unicastThu Jun 12 15:14:06.811 UTCBGP router identifier 2.2.2.1, local AS number 100BGP generic scan interval 60 secsNon-stop routing is enabledBGP table state: ActiveTable ID: 0x0 RD version: 0BGP main routing table version 46BGP NSR Initial initsync version 3 (Reached)BGP NSR/ISSU Sync-Group versions 0/0BGP scan interval 60 secs
Status codes: s suppressed, d damped, h history, * valid, > best i - internal, r RIB-failure, S stale, N Nexthop-discardOrigin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight PathRoute Distinguisher: 100:1 (default for vrf test)*> 1.1.1.1/32 2.2.2.2 0 32768 ?*> 2.2.2.0/24 0.0.0.0 0 32768 ?*> 3.3.3.3/32 0.0.0.0 0 32768 ?Route Distinguisher: 100:2 (default for vrf dst)*> 1.1.1.1/32 2.2.2.2 0 32768 ?
Processed 4 prefixes, 4 paths使用show vrf VRFNAME unresolved查询未解析的路由
VRF 的导入和导出
VRF 内的路由和全局 BGP L3VPN 表(show bgp vpnv4 unicast)互相导入导出
VRF 内的 PREFIX 导出时会带上 RD,变为 RD,PREFIX,同时加上 RT
导入导出 RT 和导入导出策略的关系
Export: Use export route-policy OR export route-target DO NOT USE SAME TIME
Import: LIST ALL ROUTE-TARGET NEED TO BE IMPORTED in import route-target Then filter these route use import route-policy
VRF 到全局路由表的路由导入导出
测试用的初始静态路由如下
router static address-family ipv4 unicast 3.3.3.3/32 Null0 ! vrf test address-family ipv4 unicast 1.1.1.1/32 2.2.2.2 !将全局路由表的 3.3.3.3/32 导入 VRF
路由策略匹配路由
route-policy global-to-vrf if destination in (3.3.3.3/32) then done endif dropend-policy建立 BGP
router bgp 100 #<-- Local AS bgp router-id 2.2.2.1 #<-- Router ID address-family ipv4 unicast #<-- Enable af inet unicast redistribute static #<-- Redistribute route into bgp table ! address-family vpnv4 unicast #<-- Enable af inet-vpn unicast ! vrf test #<-- VRF rd 100:1 #<-- RD, MUST SAME address-family ipv4 unicast #<-- Enable address family for vrf ! !VRF 内应用导入策略
vrf test address-family ipv4 unicast import from default-vrf route-policy global-to-vrf # Basic export/import not required, if you have MPLS VPN just add them验证
RP/0/RP0/CPU0:ios(config-bgp)#do show route vrf testThu Jun 12 13:28:10.973 UTC
Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path 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, E - EGP i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, su - IS-IS summary null, * - candidate default U - per-user static route, o - ODR, L - local, G - DAGR, l - LISP A - access/subscriber, a - Application route M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
Gateway of last resort is not set
S 1.1.1.1/32 [1/0] via 2.2.2.2, 02:44:45C 2.2.2.0/24 is directly connected, 02:46:19, GigabitEthernet0/0/0/0L 2.2.2.1/32 is directly connected, 02:46:19, GigabitEthernet0/0/0/0B 3.3.3.3/32 is directly connected, 00:03:55, Null0 (nexthop in vrf default)将全局路由表的 1.1.1.1 导入 VRF
路由策略匹配路由
route-policy vrf-to-global if destination in (1.1.1.1/32) then done endif dropend-policy建立 BGP
router bgp 100 bgp router-id 2.2.2.1 address-family ipv4 unicast redistribute static ! address-family vpnv4 unicast ! vrf test #<-- VRF rd 100:1 #<-- RD, MUST SAME address-family ipv4 unicast redistribute static # <-- New add, need to redistribute VRF static to bgp table ! !VRF 内应用导出策略
vrf test address-family ipv4 unicast export to default-vrf route-policy vrf-to-global # Basic export/import not required, if you have MPLS VPN just add them验证
RP/0/RP0/CPU0:ios(config)#do show routeThu Jun 12 13:47:43.256 UTC
Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path 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, E - EGP i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, su - IS-IS summary null, * - candidate default U - per-user static route, o - ODR, L - local, G - DAGR, l - LISP A - access/subscriber, a - Application route M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
Gateway of last resort is not set
B 1.1.1.1/32 [200/0] via 2.2.2.2 (nexthop in vrf test), 00:04:19S 3.3.3.3/32 is directly connected, 00:50:49, Null0VRF 之间的路由导入导出
将 VRF test 的路由 1.1.1.1/32 导出到 VRF dst
基础 BGP 配置
router bgp 100 bgp router-id 2.2.2.1 address-family ipv4 unicast redistribute static ! address-family vpnv4 unicast ! vrf dst rd 100:2 address-family ipv4 unicast ! ! vrf test rd 100:1 address-family ipv4 unicast redistribute static建立导出和导入策略
route-policy dst-i if destination in (1.1.1.1/32) and extcommunity rt matches-any 100:999 then done endif if extcommunity rt matches-any 100:2 then done endif dropend-policy!
route-policy test-e if destination in (1.1.1.1/32) then #<-- match set extcommunity rt (100:1, 100:999) additive #<-- add self + share done endif set extcommunity rt 100:1 additive #<-- self, no share, for other routes doneend-policy定义 ext community set
extcommunity-set rt 100:1 100:1end-set!extcommunity-set rt 100:2 100:2end-set!extcommunity-set rt 100:999 100:999end-set在 VRF test 内应用导出策略
vrf test ....... export route-policy test-e ......在 VRF dst 内加入 RT 并应用导入过滤策略
vrf dst rd 100:2 address-family ipv4 unicast import route-policy dst-i #<--- policy import route-target 100:2 #<--- self 100:999 #<--- all ! export route-target 100:2验证
RP/0/RP0/CPU0:ios(config)#do show route vrf dstThu Jun 12 15:08:55.752 UTC
Codes: C - connected, S - static, R - RIP, B - BGP, (>) - Diversion path 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, E - EGP i - ISIS, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, su - IS-IS summary null, * - candidate default U - per-user static route, o - ODR, L - local, G - DAGR, l - LISP A - access/subscriber, a - Application route M - mobile route, r - RPL, t - Traffic Engineering, (!) - FRR Backup path
Gateway of last resort is not set
B 1.1.1.1/32 [200/0] via 2.2.2.2 (nexthop in vrf test), 00:00:10VRF 内的动态路由
参见对应的动态路由部分