定义:
策略路由PBR(Policy-Based Routing)是一种依据用户制定的策略进行路由选择的机制,其优先级高于直连路由、静态路由和通过动态路由协议生成的路由。设备配置策略路由后,若接收的报文(包括二层报文)匹配策略路由的规则,则按照规则转发;若匹配失败,则根据目的地址按照正常转发流程转发。
注意:策略路由与路由策略(Routing Policy)存在以下不同
- 策略路由的操作对象是数据包,在路由表已经产生的情况下,不按照路由表进行转发,而是根据需要,依照某种策略改变数据包转发路径。
- 路由策略的操作对象是路由信息。路由策略主要实现了路由过滤和路由属性设置等功能,它通过改变路由属性(包括可达性)来改变网络流量所经过的路径。
目的:
传统的路由转发原理是首先根据报文的目的地址查找路由表,然后进行报文转发。但是目前越来越多的用户希望能够在传统路由转发的基础上根据自己定义的策略进行报文转发和选路。
如下图所示,汇聚层Switch做三层转发设备,接入层设备LSW做用户网关,接入层LSW和汇聚层Switch之间路由可达。汇聚层Switch通过两条链路连接到两个核心路由器上,一条是高速链路,网关为10.1.20.1/24;另外一条是低速链路,网关为10.1.30.1/24。
采用重定向方式实现策略路由,进而提供差分服务,具体配置思路如下:
# 在Switch上创建VLAN100和VLAN200。
system-view
[Huawei]sysname Switch
[Switch]vlan batch 100 200
# 配置Switch上接口GE0/0/1、GE0/0/2和GE0/0/3的接口类型为Trunk,并加入VLAN100和VLAN200。
[Switch]interface GigabitEthernet 0/0/1
[Switch-GigabitEthernet0/0/1]port link-type trunk
[Switch-GigabitEthernet0/0/1]port trunk allow-pass vlan 100 200
[Switch-GigabitEthernet0/0/1]quit
[Switch]interface GigabitEthernet 0/0/2
[Switch-GigabitEthernet0/0/2]port link-type trunk
[Switch-GigabitEthernet0/0/2]port trunk allow-pass vlan 100 200
[Switch-GigabitEthernet0/0/2]quit
[Switch]interface GigabitEthernet 0/0/3
[Switch-GigabitEthernet0/0/3]port link-type trunk
[Switch-GigabitEthernet0/0/3]port trunk allow-pass vlan 100 200
[Switch-GigabitEthernet0/0/3]quit
# 创建VLANIF100和VLANIF200,并配置各虚拟接口IP地址。
[Switch]interface Vlanif 100
[Switch-Vlanif100]ip address 10.1.20.2 24
[Switch-Vlanif100]quit
[Switch]interface Vlanif 200
[Switch-Vlanif200]ip address 10.1.30.2 24
[Switch-Vlanif200]quit
# 在Switch上创建编码为3001、3002的高级ACL,规则分别为允许源IP地址为192.168.100.0/24和192.168.101.0/24的报文通过。
[Switch]acl 3001
[Switch-acl-adv-3001]rule permit ip source 192.168.100.0 0.0.0.255
[Switch-acl-adv-3001]quit
[Switch]acl 3002
[Switch-acl-adv-3002]rule permit ip source 192.168.101.0 0.0.0.255
[Switch-acl-adv-3002]quit
在Switch上创建流分类c1、c2,匹配规则分别为ACL 3001和ACL 3002。
[Switch]traffic classifier c1 operator or
[Switch-classifier-c1]if-match acl 3001
[Switch-classifier-c1]quit
[Switch]traffic classifier c2 operator or
[Switch-classifier-c2]if-match acl 3002
[Switch-classifier-c2]quit
# 在Switch上创建流行为b1、b2,并分别指定重定向到10.1.20.1/24和10.1.30.1/24的动作。
[Switch]traffic behavior b1
[Switch-behavior-b1]redirect ip-nexthop 10.1.20.1
[Switch-behavior-b1]quit
[Switch]traffic behavior b2
[Switch-behavior-b2]redirect ip-nexthop 10.1.30.1
[Switch-behavior-b2]quit
# 在Switch上创建流策略p1,将流分类和对应的流行为进行绑定。
[Switch]traffic policy p1
[Switch-trafficpolicy-p1]classifier c1 behavior b1
[Switch-trafficpolicy-p1]classifier c2 behavior b2
[Switch-trafficpolicy-p1]quit
# 将流策略p1应用到接口GE0/0/3的入方向上。
[Switch]interface GigabitEthernet 0/0/3
[Switch-GigabitEthernet0/0/3]traffic-policy p1 inbound
[Switch-GigabitEthernet0/0/3]return
# 查看ACL规则的配置信息。
display acl 3001
Advanced ACL 3001, 1 rule
Acl's step is 5
rule 5 permit ip source 192.168.100.0 0.0.0.255
display acl 3002
Advanced ACL 3002, 1 rule
Acl's step is 5
rule 5 permit ip source 192.168.101.0 0.0.0.255
# 查看流分类的配置信息。
display traffic classifier user-defined
User Defined Classifier Information:
Classifier: c2
Operator: OR
Rule(s) : if-match acl 3002
Classifier: c1
Operator: OR
Rule(s) : if-match acl 3001
Total classifier number is 2
# 查看流策略的配置信息。
display traffic policy user-defined p1
User Defined Traffic Policy Information:
Policy: p1
Classifier: c1
Operator: OR
Behavior: b1
Redirect: no forced
Redirect ip-nexthop
10.1.20.1
Classifier: c2
Operator: OR
Behavior: b2
Redirect: no forced
Redirect ip-nexthop
10.1.30.1
Switch的配置文件
#
sysname Switch
#
vlan batch 100 200
#
acl number 3001
rule 5 permit ip source 192.168.100.0 0.0.0.255
acl number 3002
rule 5 permit ip source 192.168.101.0 0.0.0.255
#
traffic classifier c1 operator or
if-match acl 3001
traffic classifier c2 operator or
if-match acl 3002
#
traffic behavior b1
redirect ip-nexthop 10.1.20.1
traffic behavior b2
redirect ip-nexthop 10.1.30.1
#
traffic policy p1 match-order config
classifier c1 behavior b1
classifier c2 behavior b2
#
interface Vlanif100
ip address 10.1.20.2 255.255.255.0
#
interface Vlanif200
ip address 10.1.30.2 255.255.255.0
#
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 100 200
#
interface GigabitEthernet0/0/2
port link-type trunk
port trunk allow-pass vlan 100 200
#
interface GigabitEthernet0/0/3
port link-type trunk
port trunk allow-pass vlan 100 200
traffic-policy p1 inbound
#
return