Auf dieser Seite
Beispiel: Testen einer Routing-Richtlinie mit komplexen regulären Ausdrücken
In diesem Beispiel wird gezeigt, wie Sie eine Routing-Richtlinie mithilfe des test policy
Befehls testen können, um sicherzustellen, dass die Richtlinie die erwarteten Ergebnisse liefert, bevor Sie sie in einer Produktionsumgebung anwenden. Reguläre Ausdrücke, insbesondere komplexe, können schwierig sein, richtig zu sein. In diesem Beispiel wird gezeigt, wie Sie mithilfe des Befehls test policy
sicherstellen, dass Ihre regulären Ausdrücke den beabsichtigten Effekt haben.
Anforderungen
Vor der Konfiguration dieses Beispiels ist keine spezielle Konfiguration über die Geräte initialisierung hinaus erforderlich.
Überblick
Dieses Beispiel zeigt zwei Routing-Geräte mit einer externen BGP-Verbindung (EBGP). Gerät R2 verwendet die BGP-Sitzung, um Kundenrouten an Gerät R1 zu senden. Diese statischen Routen weisen mehrere Community-Werte auf.
user@R2> show route match-prefix 172.16.* detail inet.0: 7 destinations, 7 routes (7 active, 0 holddown, 0 hidden) 172.16.1.0/24 (1 entry, 1 announced) *Static Preference: 5 Next hop type: Reject Address: 0x8fd0dc4 Next-hop reference count: 8 State: <Active Int Ext> Local AS: 64511 Age: 21:32:13 Validation State: unverified Task: RT Announcement bits (1): 0-KRT AS path: I Communities: 64510:1 64510:10 64510:11 64510:100 64510:111 172.16.2.0/24 (1 entry, 1 announced) *Static Preference: 5 Next hop type: Reject Address: 0x8fd0dc4 Next-hop reference count: 8 State: <Active Int Ext> Local AS: 64511 Age: 21:32:13 Validation State: unverified Task: RT Announcement bits (1): 0-KRT AS path: I Communities: 64510:2 64510:20 64510:22 64510:200 64510:222 172.16.3.0/24 (1 entry, 1 announced) *Static Preference: 5 Next hop type: Reject Address: 0x8fd0dc4 Next-hop reference count: 8 State: <Active Int Ext> Local AS: 64511 Age: 21:32:13 Validation State: unverified Task: RT Announcement bits (1): 0-KRT AS path: I Communities: 64510:3 64510:30 64510:33 64510:300 64510:333 172.16.4.0/24 (1 entry, 1 announced) *Static Preference: 5 Next hop type: Reject Address: 0x8fd0dc4 Next-hop reference count: 8 State: <Active Int Ext> Local AS: 64511 Age: 21:32:13 Validation State: unverified Task: RT Announcement bits (1): 0-KRT AS path: I Communities: 64510:4 64510:40 64510:44 64510:400 64510:444
Zum Testen eines komplexen regulären Ausdrucks verfügt Gerät R2 über eine Richtlinie, die Routen lokalisiert test-regex
. Die Richtlinie ist wie folgendermaßen konfiguriert:
policy-statement test-regex { term find-routes { from community complex-regex; then accept; } term reject-the-rest { then reject; } } community complex-regex members "^64510:[13].*$";
Dieser reguläre Ausdruck entspricht den Community-Werten, die entweder mit 1 oder 3 beginnen.
Topologie
Abbildung 1 zeigt das Beispielnetzwerk.

CLI-Schnellkonfiguration zeigt die Konfiguration für alle Geräte in Abbildung 1an.
Der Abschnitt #configuration271__policy-test-regex-st beschreibt die Schritte auf Gerät R2.
Konfiguration
CLI-Schnellkonfiguration
Um dieses Beispiel schnell zu konfigurieren, kopieren Sie die folgenden Befehle, fügen Sie sie in eine Textdatei ein, entfernen Sie alle Zeilenumbrüche, ändern Sie alle Details, die für die Netzwerkkonfiguration erforderlich sind, und kopieren Sie dann die Befehle und fügen Sie sie auf Hierarchieebene in die [edit]
CLI ein.
Gerät R1
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 protocols bgp group ext type external set protocols bgp group ext peer-as 64511 set protocols bgp group ext neighbor 10.0.0.2 set routing-options router-id 192.168.0.1 set routing-options autonomous-system 64510
Gerät R2
set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.2/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 peer-as 64510 set protocols bgp group ext neighbor 10.0.0.1 set policy-options policy-statement send-static term 1 from protocol static set policy-options policy-statement send-static term 1 then accept set policy-options policy-statement send-static term 2 then reject set policy-options policy-statement test-regex term find-routes from community complex-regex set policy-options policy-statement test-regex term find-routes then accept set policy-options policy-statement test-regex term reject-the-rest then reject set policy-options community complex-regex members "^64510:[13].*$" set routing-options static route 172.16.1.0/24 reject set routing-options static route 172.16.1.0/24 community 64510:1 set routing-options static route 172.16.1.0/24 community 64510:10 set routing-options static route 172.16.1.0/24 community 64510:11 set routing-options static route 172.16.1.0/24 community 64510:100 set routing-options static route 172.16.1.0/24 community 64510:111 set routing-options static route 172.16.2.0/24 reject set routing-options static route 172.16.2.0/24 community 64510:2 set routing-options static route 172.16.2.0/24 community 64510:20 set routing-options static route 172.16.2.0/24 community 64510:22 set routing-options static route 172.16.2.0/24 community 64510:200 set routing-options static route 172.16.2.0/24 community 64510:222 set routing-options static route 172.16.3.0/24 reject set routing-options static route 172.16.3.0/24 community 64510:3 set routing-options static route 172.16.3.0/24 community 64510:30 set routing-options static route 172.16.3.0/24 community 64510:33 set routing-options static route 172.16.3.0/24 community 64510:300 set routing-options static route 172.16.3.0/24 community 64510:333 set routing-options static route 172.16.4.0/24 reject set routing-options static route 172.16.4.0/24 community 64510:4 set routing-options static route 172.16.4.0/24 community 64510:40 set routing-options static route 172.16.4.0/24 community 64510:44 set routing-options static route 172.16.4.0/24 community 64510:400 set routing-options static route 172.16.4.0/24 community 64510:444 set routing-options router-id 192.168.0.2 set routing-options autonomous-system 64511
Verfahren
Schritt-für-Schritt-Verfahren
Im folgenden Beispiel müssen Sie in verschiedenen Ebenen in der Konfigurationshierarchie navigieren. Informationen zum Navigieren in der CLI finden Sie unter Verwenden des CLI-Editors im Konfigurationsmodus im CLI-Benutzerhandbuch.
So konfigurieren Sie Gerät R2:
Konfigurieren Sie die Schnittstellen.
[edit interfaces] user@R2# set fe-1/2/0 unit 0 family inet address 10.0.0.2/30 user@R2# set lo0 unit 0 family inet address 192.168.0.2/32
Konfigurieren Sie BGP.
Wenden Sie die Importrichtlinie mit Gerät R2 auf die BGP-Peering-Sitzung an.
[edit protocols bgp group ext] user@R2# set type external user@R2# set peer-as 64510 user@R2# set neighbor 10.0.0.1
Konfigurieren Sie die Routing-Richtlinie, die statische Routen sendet.
[edit policy-options policy-statement send-static] user@R2# set term 1 from protocol static user@R2# set term 1 then accept user@R2# set term 2 then reject
Konfigurieren Sie die Routing-Richtlinie, die einen regulären Ausdruck testet.
[edit policy-options policy-statement test-regex] user@R2# set term find-routes from community complex-regex user@R2# set term find-routes then accept user@R2# set term reject-the-rest then reject [edit policy-options community] user@R2# set complex-regex members "^64510:[13].*$"
Konfigurieren Sie die statischen Routen und fügen Sie Community-Werte an.
[edit routing-options static route 172.16.1.0/24] user@R2# set reject user@R2# set community [ 64510:1 64510:10 64510:11 64510:100 64510:111 ] [edit routing-options static route 172.16.2.0/24] user@R2# set reject user@R2# set community [ 64510:2 64510:20 64510:22 64510:200 64510:222 ] [edit routing-options static route 172.16.3.0/24] user@R2# set reject user@R2# set community [ 64510:3 64510:30 64510:33 64510:300 64510:333 ] [edit routing-options static route 172.16.4.0/24] user@R2# set reject user@R2# set community [ 64510:4 64510:40 64510:44 64510:400 64510:444 ]
Konfigurieren Sie die autonome Systemnummer (AS) und die Router-ID.
Dies wirkt sich auf die Routing-Tabelle von Gerät R2 aus und wirkt sich ohne Auswirkungen auf Gerät R1 und Gerät R3 aus.
[edit routing-options ] user@R2# set router-id 192.168.0.2 user@R2# set autonomous-system 64511
Ergebnisse
Bestätigen Sie Im Konfigurationsmodus Ihre Konfiguration durch Eingabe der show interfaces
Befehle , , show protocols
show policy-options
undshow routing-options
. Wenn die Ausgabe die beabsichtigte Konfiguration nicht anzeigt, wiederholen Sie die Anweisungen in diesem Beispiel, um die Konfiguration zu korrigieren.
user@R2# show interfaces fe-1/2/0 { unit 0 { family inet { address 10.0.0.2/30; } } } lo0 { unit 0 { family inet { address 192.168.0.2/32; } } }
user@R2# show protocols bgp { group ext { type external; peer-as 64510; neighbor 10.0.0.1; } }
user@R2# show policy-options policy-statement send-static { term 1 { from protocol static; then accept; } term 2 { then reject; } } policy-statement test-regex { term find-routes { from community complex-regex; then accept; } term reject-the-rest { then reject; } } community complex-regex members "^64510:[13].*$";
user@R2# show routing-options static { route 172.16.1.0/24 { reject; community [ 64510:1 64510:10 64510:11 64510:100 64510:111 ]; } route 172.16.2.0/24 { reject; community [ 64510:2 64510:20 64510:22 64510:200 64510:222 ]; } route 172.16.3.0/24 { reject; community [ 64510:3 64510:30 64510:33 64510:300 64510:333 ]; } route 172.16.4.0/24 { reject; community [ 64510:4 64510:40 64510:44 64510:400 64510:444 ]; } } router-id 192.168.0.2; autonomous-system 64511;
Wenn Sie die Konfiguration des Geräts durchgeführt haben, geben Sie aus dem Konfigurationsmodus ein commit
.
Überprüfung
Bestätigen Sie, dass die Konfiguration ordnungsgemäß funktioniert.
Testen Sie, um zu sehen, welche Communitys mit dem regulären Ausdruck übereinstimmen
Zweck
Sie können den regulären Ausdruck und seine Richtlinie mithilfe des Befehls test policypolicy-name
testen.
Aktion
Führen Sie auf Gerät R2 den
test policy test-regex 0/0
Befehl aus.user@R2> test policy test-regex 0/0 inet.0: 7 destinations, 7 routes (7 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 172.16.1.0/24 *[Static/5] 1d 00:32:50 Reject 172.16.3.0/24 *[Static/5] 1d 00:32:50 Reject Policy test-regex: 2 prefix accepted, 5 prefix rejected
Ändern Sie auf Gerät R2 den regulären Ausdruck so, dass er mit einem Community-Wert übereinstimmt, der eine beliebige Anzahl von Instanzen der Ziffer 2 enthält.
[edit policy-options community complex-regex] user@R2# delete members "^64510:[13].*$" user@R2# set members "^65020:2+$" user@R2# commit
Führen Sie den
test policy test-regex 0/0
Befehl auf Gerät R2 erneut aus.user@R2> test policy test-regex 0/0 inet.0: 7 destinations, 7 routes (7 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 172.16.2.0/24 *[Static/5] 1d 00:31:36 Reject Policy test-regex: 1 prefix accepted, 6 prefix rejected
Bedeutung
Die Routen 172.16.1.0/24 und 172.16.3.0/24 haben Gemeinschaften, die dem Ausdruck ^64510:[13]. Die Route 172.16.2.0/24 hat Communities, die dem Ausdruck ^65020:2+$ entsprechen.