以前的綜合實驗文章中能夠看到,filter-policy與route-policy都能進行路由的過濾,但這兩種策略卻有着各自的使用場景,本文就來具體介紹下這兩種策略的使用場景 node
filter-policy工做在協議的進程下,從該命令的字面意思爲過濾路由的更新信息,能夠做用於進程的進出兩個方向 網絡
[Huawei]ospf 1 [Huawei-ospf-1]? filter-policy Filtering in routing updates
filter-policy自己沒法設置濾條件,須要調用其它過濾條件來完成路由信息過濾 app
[Huawei-ospf-1]filter-policy ? INTEGER<2000-2999> Apply basic ACL acl-name Specify the ACL name for filtering IPv4 routes ip-prefix IP address prefix-list route-policy Route policy
既然是過濾策略,那麼它最經常使用在的地方就是網元設備的路由過濾上。以前說過filter-policy只能做用在ospf協議import方向時,提到過他不能做用於ospf協議的export方向,緣由就是他只能影響路由器的lsdb加表過程,但不會影響lsa信息,因此不能做用在export方向 ide
route-policy路由策略經常使用於路由重發布時的路由過濾或者更改已有的路由下一跳、開銷等屬性值。相似於acl,一個route-policy下也能夠有多個節點,不一樣節點使用node標識區分,不一樣node之間是「或」的關係,在同一個node節點下: 工具
[R3-route-policy]if-match ? acl Specify an ACL as-path-filter BGP AS path list community-filter Match BGP community filter cost Match metric of route extcommunity-filter Match BGP/*** extended community filter interface Specify the interface matching the first hop of routes ip IP information ip-prefix Specify an address prefix-list ipv6 IPv6 Information mpls-label Give the Label rd-filter Route-distinguisher filter route-type Match route-type of route tag Match tag of route
route-policy在設置時一樣有permit與deny模式,兩種模式的做用分別爲: 測試
用一個實例進行說明,條件以下圖所示,則此時的過濾步驟爲: ui
網絡拓撲以下圖所示,其中R4上的環回接口沒有宣告進ospf,使用impor-route引入,配合route-policy,承擔abr的R3使用filter-policy進行路由過濾
當基礎配置完成後,在R2路由器的import方向使用filter-policy過濾,讓R2只保留10.0.1.0/24路由 code
[R2]ospf 1 [R2-ospf-1]filter-policy ip-prefix A import [R2]ip ip-prefix A permit 10.0.1.0 24
此時查看R2的路由表,發現只剩10.0.1.0/24路由 orm
[R2]display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : OSPF Destinations : 1 Routes : 1 OSPF routing table status : <Active> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.1.0/24 OSPF 10 1 D 12.0.0.1 GigabitEthernet 0/0/0 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
但R3與R4上卻依然有10.0.0.1/24網段的路由 blog
<R3>display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : OSPF Destinations : 3 Routes : 3 OSPF routing table status : <Active> Destinations : 3 Routes : 3 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.0.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 10.0.1.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 12.0.0.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
這就印證了以前說的,他只能影響路由器的lsdb加表過程,但不會影響lsa信息,因此身爲abr的R3仍是會將10.0.0.1/24網段彙總到3類lsa中向area 1中泛洪,當在R3的import方向使用filter-policy過濾,讓R3只保留10.0.1.0/24路由,此時不只R3,連R4上也沒有10.0.0.1/24網段,說明abr在向其餘area發佈3類lsa時,只會根據自己的路由表彙總後發出3類lsa
<R4>display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : OSPF Destinations : 1 Routes : 1 OSPF routing table status : <Active> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.1.0/24 OSPF 10 3 D 34.0.0.3 GigabitEthernet 0/0/0 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
爲了測試R4上route-policy效果,首先刪除R3上的filter-policy過濾策略
[R3-ospf-1]undo filter-policy ip-prefix A import
其次,定義一個名爲A的route-policy策略,並將cost值改成99,此處if-math條件引用的是名爲A的ip-prefix
[R4]route-policy A permit node 10 [R4-route-policy]if-match ip-prefix A [R4-route-policy]apply cost 99
設置名爲A的ip-prefix,讓它只選取192.168.0.0/24網段
[R4]ip ip-prefix A permit 192.168.0.0 24
在ospf 1進程中使用import-route引入route-policy A
[R4]ospf 1 [R4-ospf-1]import-route direct route-policy A
此時在去R3上查看路由表,發現192.168.0.0/24網段表項爲O_ASE,且cost值爲99
[R3]display ip routing-table protocol ospf Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : OSPF Destinations : 4 Routes : 4 OSPF routing table status : <Active> Destinations : 4 Routes : 4 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.0.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 10.0.1.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 12.0.0.0/24 OSPF 10 2 D 23.0.0.2 GigabitEthernet 0/0/1 192.168.0.0/24 O_ASE 150 99 D 34.0.0.4 GigabitEthernet 0/0/0 OSPF routing table status : <Inactive> Destinations : 0 Routes : 0
上述內容能夠總結爲如下幾點: