이 페이지의 내용
예: 논리적 인터페이스 및 IP 주소 자동 구성
구성하는 모든 인터페이스에는 하나 이상의 논리 장치와 하나의 IP 주소가 필요합니다. 또한 ATM( Asynchronous Transfer Mode ) 인터페이스에는 각 논리 인터페이스에 대한 VCI(Virtual Circuit Identifier)가 필요합니다. 인터페이스에서 여러 논리 단위를 구성해야 하는 경우 , 커밋 스크립트와 매크로를 사용하여 오류 없이 신속하게 작업을 완료할 수 있습니다.
요구 사항
이 예에서는 물리적 ATM 인터페이스를 통해 Junos OS를 실행하는 디바이스를 사용합니다.
개요 및 커밋 스크립트
다음 커밋 스크립트는 물리적 ATM 인터페이스의 이름과 인터페이스에서 여러 논리적 단위를 구성하는 방법을 지정하는 매개 변수 집합을 제공하는 문을 확장합니다apply-macro. 단위 및 VCI 번호는 변수에서 변수까지 max 순차적으로 번호가 매겨지며 변수에서 unit 시작하는 IP 주소가 부여됩니다address. 논리 단위를 반복하기 위해 XSLT(Extensible Stylesheet Language Transformations)는 템플릿에 구현된 재귀를 <emit-interface> 사용합니다. 다음 주소의 계산은 템플릿에서 <next-address> 수행됩니다.
예제 스크립트는 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:for-each select="interfaces/apply-macro"> <xsl:variable name="device" select="name"/> <xsl:variable name="address" select="data[name='address']/value"/> <xsl:variable name="max" select="data[name='max']/value"/> <xsl:variable name="unit" select="data[name='unit']/value"/> <xsl:variable name="real-max"> <xsl:choose> <xsl:when test="string-length($max) > 0"> <xsl:value-of select="$max"/> </xsl:when> <xsl:otherwise>0</xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="real-unit"> <xsl:choose> <xsl:when test="string-length($unit) > 0"> <xsl:value-of select="$unit"/> </xsl:when> <xsl:when test="contains($device, '.')"> <xsl:value-of select="substring-after($device, '.')"/> </xsl:when> <xsl:otherwise>0</xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="real-device"> <xsl:choose> <xsl:when test="contains($device, '.')"> <xsl:value-of select="substring-before($device, '.')"/> </xsl:when> <xsl:otherwise><xsl:value-of select="$device"/></xsl:otherwise> </xsl:choose> </xsl:variable> <transient-change> <interfaces> <interface> <name><xsl:value-of select="$real-device"/></name> <xsl:call-template name="emit-interface"> <xsl:with-param name="address" select="$address"/> <xsl:with-param name="unit" select="$real-unit"/> <xsl:with-param name="max" select="$real-max"/> </xsl:call-template> </interface> </interfaces> </transient-change> </xsl:for-each> </xsl:template> <xsl:template name="emit-interface"> <xsl:param name="$max"/> <xsl:param name="$unit"/> <xsl:param name="$address"/> <unit> <name><xsl:value-of select="$unit"/></name> <vci><xsl:value-of select="$unit"/></vci> <family> <inet> <address><xsl:value-of select="$address"/></address> </inet> </family> </unit> <xsl:if test="$max > $unit"> <xsl:call-template name="emit-interface"> <xsl:with-param name="address"> <xsl:call-template name="next-address"> <xsl:with-param name="address" select="$address"/> </xsl:call-template> </xsl:with-param> <xsl:with-param name="unit" select="$unit + 1"/> <xsl:with-param name="max" select="$max"/> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template name="next-address"> <xsl:param name="address"/> <xsl:variable name="arg-prefix" select="substring-after($address, '/')"/> <xsl:variable name="arg-addr" select="substring-before($address, '/')"/> <xsl:variable name="addr"> <xsl:choose> <xsl:when test="string-length($arg-addr) > 0"> <xsl:value-of select="$arg-addr"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$address"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="prefix"> <xsl:choose> <xsl:when test="string-length($arg-prefix) > 0"> <xsl:value-of select="$arg-prefix"/> </xsl:when> <xsl:otherwise>32</xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="a1" select="substring-before($addr, '.')"/> <xsl:variable name="a234" select="substring-after($addr, '.')"/> <xsl:variable name="a2" select="substring-before($a234, '.')"/> <xsl:variable name="a34" select="substring-after($a234, '.')"/> <xsl:variable name="a3" select="substring-before($a34, '.')"/> <xsl:variable name="a4" select="substring-after($a34, '.')"/> <xsl:variable name="r3"> <xsl:choose> <xsl:when test="$a4 < 255"> <xsl:value-of select="$a3"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$a3 + 1"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="r4"> <xsl:choose> <xsl:when test="$a4 < 255"> <xsl:value-of select="$a4 + 1"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="0"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:value-of select="$a1"/> <xsl:text>.</xsl:text> <xsl:value-of select="$a2"/> <xsl:text>.</xsl:text> <xsl:value-of select="$r3"/> <xsl:text>.</xsl:text> <xsl:value-of select="$r4"/> <xsl:text>/</xsl:text> <xsl:value-of select="$prefix"/> </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 {
for-each (interfaces/apply-macro) {
var $device = name;
var $address = data[name='address']/value;
var $max = data[name='max']/value;
var $unit = data[name='unit']/value;
var $real-max = {
if (string-length($max) > 0) {
expr $max;
} else {
expr "0";
}
}
var $real-unit = {
if (string-length($unit) > 0) {
expr $unit;
} else if (contains($device, '.')) {
expr substring-after($device, '.');
} else {
expr "0";
}
}
var $real-device = {
if (contains($device, '.')) {
expr substring-before($device, '.');
} else {
expr $device;
}
}
<transient-change> {
<interfaces> {
<interface> {
<name> $real-device;
call emit-interface($address, $unit = $real-unit, $max = $real-max);
}
}
}
}
}
emit-interface ($max, $unit, $address) {
<unit> {
<name> $unit;
<vci> $unit;
<family> {
<inet> {
<address> $address;
}
}
}
if ($max > $unit) {
call emit-interface($unit = $unit + 1, $max) {
with $address = {
call next-address($address);
}
}
}
}
next-address ($address) {
var $arg-prefix = substring-after($address, '/');
var $arg-addr = substring-before($address, '/');
var $addr = {
if (string-length($arg-addr) > 0) {
expr $arg-addr;
} else {
expr $address;
}
}
var $prefix = {
if (string-length($arg-prefix) > 0) {
expr $arg-prefix;
} else {
expr "32";
}
}
var $a1 = substring-before($addr, '.');
var $a234 = substring-after($addr, '.');
var $a2 = substring-before($a234, '.');
var $a34 = substring-after($a234, '.');
var $a3 = substring-before($a34, '.');
var $a4 = substring-after($a34, '.');
var $r3 = {
if ($a4 < 255) {
expr $a3;
} else {
expr $a3 + 1;
}
}
var $r4 = {
if ($a4 < 255) {
expr $a4 + 1;
} else {
expr 0;
}
}
expr $a1;
expr ".";
expr $a2;
expr ".";
expr $r3;
expr ".";
expr $r4;
expr "/";
expr $prefix;
}
구성
절차
단계별 절차
스크립트를 다운로드, 사용 및 실행하려면:To download, enable, and run the script:
스크립트를 텍스트 파일에 복사하고 파일 이름을 atm-logical.xsl 또는 atm-logical.slax로 적절하게 지정한 다음 디바이스의 /var/db/scripts/commit/ 디렉터리에 다운로드합니다.
다음 테스트 구성 스탠자를 선택하고 Ctrl+c를 눌러 클립보드에 복사하십시오.
SLAX 버전의 스크립트를 사용하는 경우 계층 수준에서 파일 이름을
[edit system scripts commit file]atm-logical.slax로 변경합니다.system { scripts { commit { allow-transients; file atm-logical.xsl; } } } interfaces { apply-macro at-1/2/3 { address 10.12.13.14/20; max 200; unit 32; } at-1/2/3 { atm-options { pic-type atm2; vpi 0; } } }구성 모드에서 명령을 실행하여
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를 누릅니다.
commit명령을 실행하여 구성을 커밋합니다.user@host# commit
확인
구성 확인
목적
올바른 변경 사항이 구성에 통합되었는지 확인합니다.
작업
구성을 커밋하기 전에 구성 모드 명령을 실행하여 커밋 스크립트가 show interfaces at-1/2/3 | display commit-scripts 올바른 결과를 생성하는지 확인할 수 있습니다. 구성을 커밋한 후 운영 모드 명령을 실행하여 show configuration interfaces at-1/2/3 활성 구성을 검토할 수 있습니다. 다음과 같은 출력이 나타납니다.
atm-options {
pic-type atm2;
vpi 0;
}
unit 32 {
vci 32;
family inet {
address 10.12.13.14/20;
}
}
unit 33 {
vci 33;
family inet {
address 10.12.13.15/20;
}
}
unit 34 {
vci 34;
family inet {
address 10.12.13.16/20;
}
}
unit 35 {
vci 35;
family inet {
address 10.12.13.17/20;
}
}
... Logical units 36 through 199 are omitted for brevity ...
unit 200 {
vci 200 ;
family inet {
address 10.12.13.182/20;
}
}
의미
이 옵션은 모든 커밋 스크립트가 | display commit-scripts 적용된 후의 구성 데이터를 표시합니다. 출력에는 지속적 변경과 일시적 변경이 모두 포함됩니다. 각 ATM 인터페이스에 적절한 unit 및 vci 이 구성된 경우 커밋 작업 중에 커밋 스크립트가 성공적으로 실행됩니다. 구성을 커밋한 후 운영 모드 명령을 실행하여 show configuration interfaces at-1/2/3 활성 구성을 검토할 수 있습니다.