示例:将源前缀和目标前缀分组为转发类
此示例说明如何将源前缀和目标前缀分组到转发类中。
要求
配置此示例之前,不需要除设备初始化之外的特殊配置。
概述
此示例使用三个路由设备:客户边缘 (CE) 设备、提供商边缘 (PE) 设备和提供商核心 (P) 设备。
图 1 显示了示例网络。
源类使用情况 (SCU) 通过对 IP 源地址和 IP 目标地址执行查找,对发送到客户边缘的数据包进行计数。SCU 可以跟踪源自提供商核心上特定前缀并发往客户边缘特定前缀的流量。
DCU 通过查找 IP 目标地址来对来自客户的数据包进行计数。通过 DCU,可以跟踪源自客户边缘并发往提供商核心路由器上特定前缀的流量。
在设备 PE 的 fe-1/2/1 接口上,面向提供商核心(由设备 P 表示),SCU 输入配置了语句, source-class-usage input
以跟踪源自设备 P 并发往设备 CE 的流量。在同一接口上,语句 destination-class-usage input
配置为跟踪源自设备 CE 的、发往提供商核心的流量。
user@PE# show interfaces fe-1/2/1 unit 0 family inet
accounting {
source-class-usage {
input; # tracks traffic destined to customer edge
}
destination-class-usage; # tracks traffic destined to provider core
}
address 10.1.0.1/30;
与只需要在单个接口上实现的目标类使用 (DCU) 不同,必须在两个接口上启用 SCU 核算:源类遍历的入站和出站接口。您必须显式定义 SCU 监控的流量预期到达和离开的两个接口。这是因为 SCU 在路由表中执行两次查找:源地址 (SA) 和目标地址 (DA) 查找。相比之下,DCU 只有一个目标地址查找。
在设备 PE 的 fe-1/2/0 接口上,面向设备 CE,SCU 输出配置了 source-class-usage output
语句。
user@PE# show interfaces fe-1/2/0 unit 0 family inet
accounting {
source-class-usage {
output;
}
}
address 10.0.0.2/30;
为了考虑发往客户的流量,名为 scu_class 的策略使用路由过滤器将流量放入 gold1、gold2 和 gold3 类中。
user@PE# show policy-options
policy-statement scu_class {
term gold1 {
from {
route-filter 172.16.2.0/24 orlonger;
}
then source-class gold1;
}
term gold2 {
from {
route-filter 172.16.3.0/24 orlonger;
}
then source-class gold2;
}
term gold3 {
from {
route-filter 172.16.4.0/24 orlonger;
}
then source-class gold3;
}
}
为了考虑发往提供商的流量,名为 dcu_class 的策略使用路由过滤器将流量放入 silver1、silver2 和 silver3 类中。
user@PE# show policy-options
policy-statement dcu_class {
term silver1 {
from {
route-filter 172.16.5.0/24 orlonger;
}
then destination-class silver1;
}
term silver2 {
from {
route-filter 172.16.6.0/24 orlonger;
}
then destination-class silver2;
}
term silver3 {
from {
route-filter 172.16.7.0/24 orlonger;
}
then destination-class silver3;
}
}
然后将这些策略应用于转发表。
forwarding-table { export [ dcu_class scu_class ]; }
该示例使用静态路由提供用于测试操作的连接和环路接口地址。
#configuration715__scu-dcu-sample-st本节介绍设备 PE 上的步骤。
配置
程序
CLI 快速配置
要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改与您的网络配置匹配所需的任何详细信息,然后将命令复制并粘贴到层次结构级别的 CLI [edit]
中。
设备 CE
set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.1/30 set interfaces lo0 unit 0 family inet address 192.168.0.1/32 set interfaces lo0 unit 0 family inet address 172.16.0.1/32 set interfaces lo0 unit 0 family inet address 172.16.0.1/32 set interfaces lo0 unit 0 family inet address 172.16.0.1/32 set interfaces lo0 unit 0 family inet address 172.16.0.1/32 set interfaces lo0 unit 0 family inet address 172.16.0.1/32 set interfaces lo0 unit 0 family inet address 172.16.0.1/32 set protocols bgp group ext type external set protocols bgp group ext export send-direct set protocols bgp group ext export send-static set protocols bgp group ext peer-as 200 set protocols bgp group ext neighbor 10.0.0.2 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set policy-options policy-statement send-static term 1 from protocol static set policy-options policy-statement send-static term 1 then accept set routing-options static route 10.1.0.0/30 next-hop 10.0.0.2 set routing-options autonomous-system 100
设备 PE
set interfaces fe-1/2/0 unit 0 family inet accounting source-class-usage output set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.2/30 set interfaces fe-1/2/1 unit 0 family inet accounting source-class-usage input set interfaces fe-1/2/1 unit 0 family inet accounting destination-class-usage set interfaces fe-1/2/1 unit 0 family inet address 10.1.0.1/30 set interfaces lo0 unit 0 family inet address 192.168.0.2/32 set protocols bgp group ext type external set protocols bgp group ext export send-direct set protocols bgp group ext neighbor 10.0.0.1 peer-as 100 set protocols bgp group ext neighbor 10.1.0.2 peer-as 300 set policy-options policy-statement dcu_class term silver1 from route-filter 172.16.5.0/24 orlonger set policy-options policy-statement dcu_class term silver1 then destination-class silver1 set policy-options policy-statement dcu_class term silver2 from route-filter 172.16.6.0/24 orlonger set policy-options policy-statement dcu_class term silver2 then destination-class silver2 set policy-options policy-statement dcu_class term silver3 from route-filter 172.16.7.0/24 orlonger set policy-options policy-statement dcu_class term silver3 then destination-class silver3 set policy-options policy-statement scu_class term gold1 from route-filter 172.16.2.0/24 orlonger set policy-options policy-statement scu_class term gold1 then source-class gold1 set policy-options policy-statement scu_class term gold2 from route-filter 172.16.3.0/24 orlonger set policy-options policy-statement scu_class term gold2 then source-class gold2 set policy-options policy-statement scu_class term gold3 from route-filter 172.16.4.0/24 orlonger set policy-options policy-statement scu_class term gold3 then source-class gold3 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set routing-options autonomous-system 200 set routing-options forwarding-table export dcu_class set routing-options forwarding-table export scu_class
设备 P
set interfaces fe-1/2/1 unit 0 family inet address 10.1.0.2/30 set interfaces lo0 unit 0 family inet address 192.168.0.3/32 set interfaces lo0 unit 0 family inet address 172.16.0.3/32 set interfaces lo0 unit 0 family inet address 172.16.0.3/32 set interfaces lo0 unit 0 family inet address 172.16.0.3/32 set interfaces lo0 unit 0 family inet address 172.16.0.3/32 set interfaces lo0 unit 0 family inet address 172.16.0.3/32 set interfaces lo0 unit 0 family inet address 172.16.0.3/32 set protocols bgp group ext type external set protocols bgp group ext export send-direct set protocols bgp group ext export send-static set protocols bgp group ext peer-as 200 set protocols bgp group ext neighbor 10.1.0.1 set policy-options policy-statement send-direct term 1 from protocol direct set policy-options policy-statement send-direct term 1 then accept set policy-options policy-statement send-static term 1 from protocol static set policy-options policy-statement send-static term 1 then accept set routing-options static route 10.0.0.0/30 next-hop 10.1.0.1 set routing-options static route 172.16.2.0/24 discard set routing-options static route 172.16.3.0/24 discard set routing-options static route 172.16.4.0/24 discard set routing-options static route 172.16.5.0/24 discard set routing-options static route 172.16.6.0/24 discard set routing-options static route 172.16.7.0/24 discard set routing-options autonomous-system 300
分步过程
下面的示例要求您在各个配置层级中进行导航。有关如何执行此操作的说明,请参阅 在配置模式下使用 CLI 编辑器Junos OS CLI 用户指南。
要将源前缀和目标前缀分组到转发类中:
创建路由器接口。
[edit interfaces] user@PE# set fe-1/2/0 unit 0 family inet accounting source-class-usage output user@PE# set fe-1/2/0 unit 0 family inet address 10.0.0.2/30 user@PE# set fe-1/2/1 unit 0 family inet accounting source-class-usage input user@PE# set fe-1/2/1 unit 0 family inet accounting destination-class-usage user@PE# set fe-1/2/1 unit 0 family inet address 10.1.0.1/30 user@PE# set lo0 unit 0 family inet address 192.168.0.2/32
配置 BGP。
[edit protocols bgp group ext] user@PE# set type external user@PE# set export send-direct user@PE# set neighbor 10.0.0.1 peer-as 100 user@PE# set neighbor 10.1.0.2 peer-as 300
配置 DCU 策略。
[edit policy-options policy-statement dcu_class] user@PE# set term silver1 from route-filter 172.16.5.0/24 orlonger user@PE# set term silver1 then destination-class silver1 user@PE# set term silver2 from route-filter 172.16.6.0/24 orlonger user@PE# set term silver2 then destination-class silver2 user@PE# set term silver3 from route-filter 172.16.7.0/24 orlonger user@PE# set term silver3 then destination-class silver3
配置 SCU 策略。
[edit policy-options policy-statement scu_class] user@PE# set term gold1 from route-filter 172.16.2.0/24 orlonger user@PE# set term gold1 then source-class gold1 user@PE# set term gold2 from route-filter 172.16.3.0/24 orlonger user@PE# set term gold2 then source-class gold2 user@PE# set term gold3 from route-filter 172.16.4.0/24 orlonger user@PE# set term gold3 then source-class gold3
将策略应用于转发表。
[edit routing-options forwarding-table] user@PE# set export dcu_class user@PE# set export scu_class
注:您可以在相同或不同的导出语句中引用同一路由策略一次或多次。
(可选)配置通告直接路由的路由策略。
[edit policy-options policy-statement send-direct term 1] user@PE# set from protocol direct user@PE# set then accept
配置自治系统 (AS) 编号。
[edit routing-options] user@PE# set autonomous-system 200
结果
在配置模式下,通过发出 show interfaces
、 show protocols
、 show policy-options
和 show routing-options
命令来确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以便进行更正。
user@PE# show interfaces fe-1/2/0 { unit 0 { family inet { accounting { source-class-usage { output; } } address 10.0.0.2/30; } } } fe-1/2/1 { unit 0 { family inet { accounting { source-class-usage { input; } destination-class-usage; } address 10.1.0.1/30; } } } lo0 { unit 0 { family inet { address 192.168.0.2/32; } } }
user@PE# show protocols bgp { group ext { type external; export send-direct; neighbor 10.0.0.1 { peer-as 100; } neighbor 10.1.0.2 { peer-as 300; } } }
user@PE# show policy-options policy-statement dcu_class { term silver1 { from { route-filter 172.16.5.0/24 orlonger; } then destination-class silver1; } term silver2 { from { route-filter 172.16.6.0/24 orlonger; } then destination-class silver2; } term silver3 { from { route-filter 172.16.7.0/24 orlonger; } then destination-class silver3; } } policy-statement scu_class { term gold1 { from { route-filter 172.16.2.0/24 orlonger; } then source-class gold1; } term gold2 { from { route-filter 172.16.3.0/24 orlonger; } then source-class gold2; } term gold3 { from { route-filter 172.16.4.0/24 orlonger; } then source-class gold3; } } policy-statement send-direct { term 1 { from protocol direct; then accept; } }
user@PE# show routing-options autonomous-system 200; forwarding-table { export [ dcu_class scu_class ]; }
如果完成设备配置,请从配置模式输入 commit
。
验证
确认配置工作正常。
确保 DCU 策略正常工作
目的
验证从提供商核心发送到客户网络的流量是否导致 DCU 策略计数器递增。
操作
从设备 P 对客户网络中的地址执行 ping 操作。
user@P> ping rapid count 10000000 172.16.0.1 PING 172.16.0.1 (6.0.0.1): 56 data bytes !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
在设备 PE 上,检查面向提供商核心的接口上的接口统计信息。
user@PE> show interfaces statistics fe-1/2/1.0 Logical interface fe-1/2/1.0 (Index 108) (SNMP ifIndex 546) Flags: SNMP-Traps 0x4000 Encapsulation: ENET2 Input packets : 251956 Output packets: 251961 Protocol inet, MTU: 1500 Flags: Sendbcast-pkt-to-re, DCU, SCU-in Packets Bytes Destination class (packet-per-second) (bits-per-second) silver1 7460 626640 ( 0) ( 0) silver2 22440 2401416 ( 256) ( 171963) silver3 9004 756336 ( 0) ( 0) Addresses, Flags: Is-Preferred Is-Primary Destination: 10.1.0.0/30, Local: 10.1.0.1, Broadcast: 10.1.0.3
确保 SCU 策略正常工作
目的
验证从客户网络发送到提供商核心的流量是否会导致 SCU 策略计数器递增。
操作
从设备 CE 中,对客户网络中的地址执行 ping 操作。
user@CE> ping rapid count 10000000 172.16.0.1 PING 172.16.0.1 (6.0.0.1): 56 data bytes !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
在设备 PE 上,检查面向客户网络的接口上的接口统计信息。
user@PE> show interfaces statistics fe-1/2/0.0 Logical interface fe-1/2/0.0 (Index 93) (SNMP ifIndex 554) Flags: SNMP-Traps 0x4000 Encapsulation: ENET2 Input packets : 32246 Output packets: 32245 Protocol inet, MTU: 1500 Flags: Sendbcast-pkt-to-re, Is-Primary, SCU-out Packets Bytes Source class (packet-per-second) (bits-per-second) gold1 8871 745164 ( 259) ( 174497) gold2 1812 152208 ( 0) ( 0) gold3 5711 479724 ( 0) ( 0) Addresses, Flags: Is-Preferred Is-Primary Destination: 10.0.0.0/30, Local: 10.0.0.2, Broadcast: 10.0.0.3