示例:使用提交脚本分配分类器
对于使用 IPv4 协议家族配置的每个接口,此提交脚本会自动分配一个指定的分类器,该分类器会将传入数据包与转发类和丢失优先级相关联,并将数据包分配给输出队列。
要求
此示例使用运行 Junos OS 的设备。
概述和提交脚本
在 Junos OS 服务等级 (CoS) 中,分类器允许您将传入数据包与转发类和丢失优先级相关联,并根据关联的转发类将数据包分配给输出队列。配置分类器后,必须将其分配给输入接口。
对于使用 IPv4 协议家族配置的每个接口,此脚本会自动分配一个名为的 fc-q3
指定分类器。 fc-q3
分类器必须在层次结构级别上 [edit class-of-service]
配置。
示例脚本同时以 XSLT 和 SLAX 语法显示:
XSLT 语法
<?xml version="1.0" standalone="yes"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:junos="http://xml.juniper.net/junos/*/junos" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0"> <xsl:import href="../import/junos.xsl"/> <xsl:template match="configuration"> <xsl:variable name="cos-all" select="class-of-service"/> <xsl:for-each select="interfaces/interface[contains(name, '/')]/unit[family/inet]"> <xsl:variable name="ifname" select="../name"/> <xsl:variable name="unit" select="name"/> <xsl:variable name="cos" select="$cos-all/interfaces[name = $ifname]"/> <xsl:if test="not($cos/unit[name = $unit])"> <xsl:call-template name="jcs:emit-change"> <xsl:with-param name="message"> <xsl:text>Adding CoS forwarding class for </xsl:text> <xsl:value-of select="concat($ifname, '.', $unit)"/> </xsl:with-param> <xsl:with-param name="dot" select="$cos-all"/> <xsl:with-param name="content"> <interfaces> <name><xsl:value-of select="$ifname"/></name> <unit> <name><xsl:value-of select="$unit"/></name> <forwarding-class>fc-q3</forwarding-class> </unit> </interfaces> </xsl:with-param> </xsl:call-template> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet>
SLAX 语法
version 1.0; ns junos = "http://xml.juniper.net/junos/*/junos"; ns xnm = "http://xml.juniper.net/xnm/1.1/xnm"; ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0"; import "../import/junos.xsl"; match configuration { var $cos-all = class-of-service; for-each (interfaces/interface[contains(name, '/')]/unit[family/inet]) { var $ifname = ../name; var $unit = name; var $cos = $cos-all/interfaces[name = $ifname]; if (not($cos/unit[name = $unit])) { call jcs:emit-change($dot = $cos-all) { with $message = { expr "Adding CoS forwarding class for "; expr $ifname _ '.' _ $unit; } with $content = { <interfaces> { <name> $ifname; <unit> { <name> $unit; <forwarding-class> "fc-q3"; } } } } } } }
配置
程序
逐步过程
要下载、启用和测试脚本:
将脚本复制到文本文件中,根据需要将文件 命名为 classifier.xsl 或 classifier.slax ,并将其复制到设备上的 /var/db/script/commit/ 目录中。
选择以下测试配置部分,然后按 Ctrl+c 将它们复制到该测试板。
如果您使用的脚本的 SLAX 版本,请从层次结构级别将文件名
[edit system scripts commit file]
更改为 classifier.slax。system { scripts { commit { file classifier.xsl; } } } interfaces { fe-0/0/0 { unit 0 { family inet { address 10.168.16.2/24; } } } } class-of-service { forwarding-classes { queue 3 fc-q3; } classifiers { inet-precedence fc-q3 { forwarding-class fc-q3 { loss-priority low code-points 010; } } } }
在配置模式下,发出
load merge terminal
命令,将各节合并到设备配置中。[edit] user@host# load merge terminal [Type ^D at a new line to end input] ... Paste the contents of the clipboard here ...
出现提示时,使用鼠标和粘贴图标来粘贴分文功能板的内容。
按 Enter。
按 Ctrl+d。
提交配置。
user@host# commit
验证
验证配置
目的
验证脚本是否按预期运行。
行动
查看命令的 commit
输出。在测试配置节中,使用 family inet
语句配置 fe-0/0/0.0 接口。由于接口配置了 IPv4 协议家族,因此脚本会自动将 fc-q3
分类器分配给接口,这在命令输出中 commit
所示。
[edit] user@host# commit [edit interfaces interface fe-0/0/0 unit 0] warning: Adding CoS forwarding class for fe-0/0/0.0 commit complete
查看配置,验证脚本生成的更改是否存在。发出 show class-of-service
配置模式命令。输出显示,已为 fe-0/0/0.0 接口分配了 fc-q3
分类器:
[edit] user@host# show class-of-service classifiers { inet-precedence fc-q3 { forwarding-class fc-q3 { loss-priority low code-points 010; } } } forwarding-classes { queue 3 fc-q3; } interfaces { fe-0/0/0 { unit 0 { forwarding-class fc-q3; # Added by commit script } } }