僞裝網絡工程師16——路由策略filter-policy與route-policy

1、背景介紹

以前的綜合實驗文章中能夠看到,filter-policy與route-policy都能進行路由的過濾,但這兩種策略卻有着各自的使用場景,本文就來具體介紹下這兩種策略的使用場景 node

2、filter-policy介紹

1.filter-policy工做模式

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

2.filter-policy使用場景

既然是過濾策略,那麼它最經常使用在的地方就是網元設備的路由過濾上。以前說過filter-policy只能做用在ospf協議import方向時,提到過他不能做用於ospf協議的export方向,緣由就是他只能影響路由器的lsdb加表過程,但不會影響lsa信息,因此不能做用在export方向 ide

3、route-policy介紹

1.route-policy的工做模式

route-policy路由策略經常使用於路由重發布時的路由過濾或者更改已有的路由下一跳、開銷等屬性值。相似於acl,一個route-policy下也能夠有多個節點,不一樣節點使用node標識區分,不一樣node之間是「或」的關係,在同一個node節點下: 工具

  • 能夠有多個if-match和apply字句,多個if-match字句之間是「與」的關係
  • if-match字句能夠引用其餘的過濾工具
    [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模式,兩種模式的做用分別爲: 測試

  • permit:當路由知足當前結點的if-match字句時,則被容許經過並執行apply字句,若是不知足當前結點的if-match字句,轉到下一節點進行if-match匹配,若是全部節點都不知足,則丟棄
  • deny:當路由知足當前結點的if-match字句,將被拒絕經過,且不會進入下一個節點

    2.route-policy過濾詳解

    用一個實例進行說明,條件以下圖所示,則此時的過濾步驟爲:
    僞裝網絡工程師16——路由策略filter-policy與route-policy ui

    1. 路由進入node 10,由於是deny語句,因此Pref1挑選中的1.1.2.0/24與5.5.5.5/32路由條目不會繼續進入下一個節點
    2. 除掉1.1.2.0/24與5.5.5.5/32,剩下的路由進入node 20,Pref2不挑選6.6.6.6/32,但沒指定挑選哪一個,ip-prefix隱含所有挑選,因此儘管node 20是permit,但Pref2沒有挑選中任何一條路由,此節點無任何操做
    3. 除掉1.1.2.0/24與5.5.5.5/32,剩下的路由進入node 30,第一個if-match語句是要匹配acl 2001,因爲acl不會區分掩碼位數,因此1.1.3.0/24與1.1.3.0/25都被選中,其結果同時知足第二個if-match語句的結果,因此下一跳的13.13.13.1,並將cost值改成21
    4. 除掉1.1.2.0/24,5.5.5.5/32;1.1.3.0/24,1.1.3.0/25(下一跳是13.13.13.1),剩下的路由進入node 40,選中的是1.1.3.0/25(下一跳是34.34.34.2),並將cost值改成11
    5. 如今只剩下1.1.3.0/24(下一跳34.34.34.2)與6.6.6.6/32路由進入node 50,因爲node 50沒有設置if-match條件,且有事permit模式,因此容許剩下的全部路由經過
    6. 最後,過濾後的路由條目如左下角所示(示例不對,缺乏6.6.6.6/32)

      4、實驗

      網絡拓撲以下圖所示,其中R4上的環回接口沒有宣告進ospf,使用impor-route引入,配合route-policy,承擔abr的R3使用filter-policy進行路由過濾
      僞裝網絡工程師16——路由策略filter-policy與route-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

5、總結

上述內容能夠總結爲如下幾點:

  1. filter-policy經常使用在的地方就是網元設備的路由過濾上
  2. oute-policy經常使用於路由重發布時的路由過濾或者更改已有的路由下一跳、開銷等屬性值
  3. 在ospf協議中,過濾只會影響lsdb的加表過程,不會影響到lsa,因此做用在路由器的import方向
  4. 若是ospf的邊界路由器執行過濾,他只會對其餘area泛洪自身已加表的路由
相關文章
相關標籤/搜索