このページで
例:LSP の管理グループの設定
リンクカラーリングまたはリソースクラスとも呼ばれる管理グループは、リンクのカラーを説明する手動で割り当てられた属性です。同じカラーを持つリンクは概念的に同じクラスに属します。管理グループを使用して、さまざまなポリシーベースの LSP(ラベルスイッチ パス )設定を実装できます。
このコミットスクリプトの例では、 apply-macro
階層レベルに含まれるパラメーターで color
ステートメントを [edit protocols mpls]
検索します。ステートメントごとに apply-macro
、提供されたデータを使用して 一時的な変更 を生成し、マクロをLSPの標準的なJunos OS管理グループに展開します。
要件
この例では、Junos OSを実行しているデバイスを使用しています。
概要とコミット スクリプト
この例では、Junos OS管理プロセス(mgd)がステートメントを探apply-macro
して設定を検査します。apply-macro
階層レベルに[edit protocols mpls]
パラメータがcolor
含まれている各ステートメントに対して、スクリプトはステートメント内apply-macro
で提供されるデータを使用して一時的な変更を生成し、マクロをLSPの標準的なJunos OS管理グループに展開します。
この例を機能させるには、apply-macro
アドレス、パラメーター、color
およびパラメーターgroup-value
のセットを階層レベルに[edit protocols mpls]
含める必要があります。コミット スクリプトは、各アドレスを LSP 設定に変換し、パラメーターをcolor
管理グループに変換します。
このスクリプトの 1 行ごとの説明については、「 例: コミット スクリプトマクロを使用したカスタム設定構文の作成」を参照してください。
このスクリプトの例は、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="mpls" select="protocols/mpls"/> <xsl:for-each select="$mpls/apply-macro[data/name = 'color']"> <xsl:variable name="color" select="data[name = 'color']/value"/> <xsl:for-each select="$mpls/apply-macro[data/name = 'group-value']"> <xsl:variable name="group-value" select="data[name = 'group-value']/value"/> <transient-change> <protocols> <mpls> <admin-groups> <name> <xsl:value-of select="$color"/> </name> <group-value> <xsl:value-of select="$group-value"/> </group-value> </admin-groups> <xsl:for-each select="data[not(value)]/name"> <label-switched-path> <name> <xsl:value-of select="concat($color, '-lsp-', .)"/> </name> <to><xsl:value-of select="."/></to> <admin-group> <include-any> <xsl:value-of select="$color"/> </include-any> </admin-group> </label-switched-path> </xsl:for-each> </mpls> </protocols> </transient-change> </xsl:for-each> </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 $mpls = protocols/mpls; for-each ($mpls/apply-macro[data/name = 'color']) { var $color = data[name = 'color']/value; for-each ($mpls/apply-macro[data/name = 'group-value']) { var $group-value = data[name = 'group-value']/value; <transient-change> { <protocols> { <mpls> { <admin-groups> { <name> $color; <group-value> $group-value; } for-each (data[not(value)]/name) { <label-switched-path> { <name> $color _ '-lsp-' _ .; <to> .; <admin-group> { <include-any> $color; } } } } } } } } }
構成
手順
手順
スクリプトをダウンロード、有効化、テストするには、以下の手順にしたがっています。
スクリプトをテキスト ファイルにコピーし、 lsp-admin.xsl または lsp-admin.slax というファイルに適宜名前を付け、デバイス上の /var/db/scripts/commit/ ディレクトリにコピーします。
以下のテスト構成スタンザを選択し、Ctrl+cを押してクリップボードにコピーします。
スクリプトの SLAX バージョンを使用している場合は、 階層レベルのファイル名を
[edit system scripts commit file]
lsp-admin.slax に変更します。system { scripts { commit { allow-transients; file lsp-admin.xsl; } } } protocols { mpls { apply-macro blue-type-lsp { 10.1.1.1; 10.2.2.2; 10.3.3.3; 10.4.4.4; color blue; group-value 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を押します。
設定をコミットします。
user@host# commit
検証
設定の検証
目的
スクリプトが想定どおりに動作していることを確認します。
アクション
設定モード コマンドを show protocols mpls | display commit-scripts
発行し、出力を確認します。オプションを | display commit-scripts
追加すると、一時的な変更によって生成される設定ステートメントを表示できます。
スクリプトで生成された変更による
設定モード コマンドを show protocols mpls | display commit-scripts
発行すると、以下の出力が表示されます。
[edit] user@host# show protocols mpls | display commit-scripts apply-macro blue-type-lsp { 10.1.1.1; 10.2.2.2; 10.3.3.3; 10.4.4.4; color blue; group-value 0; } admin-groups { blue 0; } label-switched-path blue-lsp-10.1.1.1 { to 10.1.1.1; admin-group include-any blue; } label-switched-path blue-lsp-10.2.2.2 { to 10.2.2.2; admin-group include-any blue; } label-switched-path blue-lsp-10.3.3.3 { to 10.3.3.3; admin-group include-any blue; } label-switched-path blue-lsp-10.4.4.4 { to 10.4.4.4; admin-group include-any blue; }
スクリプトで生成された変更なし
コンフィギュレーション・モード・ show protocols mpls | display commit-scripts no-transients
コマンドの出力は、 ステートメントを label-switched-path
除外します。
[edit] user@host# show protocols mpls | display commit-scripts no-transients apply-macro blue-type-lsp { 10.1.1.1; 10.2.2.2; 10.3.3.3; 10.4.4.4; color blue; group-value 0; }
piped display commit-scripts no-transients
コマンドをshow protocols mpls
使用せずに コマンドを発行すると、このスクリプトは永続的な変更を生成しないため、同じ出力が表示されます。
[edit] user@host# show protocols mpls apply-macro blue-type-lsp { 10.1.1.1; 10.2.2.2; 10.3.3.3; 10.4.4.4; color blue; group-value 0; }