예를 들면 다음과 같습니다. 정책 하위 라우팅 구성
이 예에서는 라우팅 정책 일치 조건에서 정책 서브라우틴을 사용하는 것을 보여 줍니다.
요구 사항
이 예제를 구성하기 전에 디바이스 초기화 이외에는 특별한 구성이 필요하지 않습니다.
개요
Device R1에서 호출 main
되는 정책이 구성됩니다.
user@R1# show policy-options policy-statement main { term subroutine-as-a-match { from policy subroutine; then accept; } term nothing-else { then reject; } }
이 기본 정책은 서브로틴을 호출 subroutine
합니다.
user@R1# show policy-options policy-statement subroutine { term get-routes { from protocol static; then accept; } term nothing-else { then reject; } }
라우터는 정의된 방식으로 로 main
직을 평가합니다. 라우팅 디바이스가 서브라우틴을 찾을 수 있도록 하는 일치 기준 from policy subroutine
서브루틴의 모든 용어는 일반적인 정책 처리 규칙에 따라 순서대로 평가됩니다. 이 예에서는 라우팅 테이블의 모든 정적 경로가 서브라우틴과 동의 액션과 일치합니다. 그러면 디바이스에 양수 일치가 발생했음을 알리는 원래 또는 호출 정책에 실제 결과가 반환됩니다. 호출 정책의 작업이 실행되고 경로가 수락됩니다. 라우팅 테이블의 다른 모든 경로는 서브라우틴과 일치하지 않으며 호출 정책에 잘못된 결과를 반환합니다. 디바이스는 두 번째 경로를 main
평가하고 경로를 거부합니다.
서브라우틴의 작업은 특정 경로를 실제로 수락하거나 거부하지 않습니다. 서브루틴 작업은 true 또는 false 결과로만 변환됩니다. 그러나 경로의 속성을 수정하는 작업은 서브라우틴의 결과에 관계없이 루트에 적용됩니다.
AS 64510의 Device R1에는 여러 고객 경로가 있으며, 그 중 일부는 로컬로 구성된 정적 경로이며, 그 중 일부는 IBGP(Internal BGP)를 통해 Device R2 및 Device R3로부터 수신됩니다. AS 64510은 AS 64511의 Device R4에 연결됩니다. 이 정책은 main
Device R1의 BGP 피어링 세션과 Device R4의 내보내기 정책으로 적용됩니다. 이로 인해 Device R1은 고유의 정적 경로만 Device R4로 보냅니다. 정책 main
때문에 Device R1은 내부 피어(Device R2 및 Device R3)로부터 수신된 경로를 전송하지 않습니다.
정책 서브라우틴을 사용할 때 기본 EBGP 내보내기 정책은 학습한 모든 BGP 경로를 모든 EBGP 피어에 광고하는 것입니다. 이 기본 정책은 기본 정책과 서브루틴에서도 적용됩니다. 따라서 이 예에서와 같이 기본 EBGP 내보내기 정책이 적용되는 것을 원치 않는 경우, 주 정책과 정책 서브로틴 모두에서 종료 작업을 최종 용어로 구성 then reject
해야 합니다. 이 예에서는 최종 then reject
용어가 기본 정책이나 정책 서브루틴에서 누락된 경우 발생하는 상황을 보여줍니다.
토폴로지
그림 1 샘플 네트워크를 보여줍니다.

CLI 빠른 구성 에 있는 모든 디바이스 그림 1의 구성을 보여줍니다.
이 섹션에서 #configuration318__policy-subroutine-st 는 Device R1의 단계를 설명합니다.
구성
CLI 빠른 구성
이 예제를 신속하게 구성하려면 다음 명령을 복사하여 텍스트 파일에 붙여넣고, 줄 바꿈을 제거하고, 네트워크 구성에 필요한 세부 정보를 변경한 다음, 명령을 복사하여 계층적 수준에서 CLI [edit]
에 붙여넣습니다.
디바이스 R1
set interfaces fe-1/2/0 unit 0 description to_R2 set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.1/30 set interfaces fe-1/2/2 unit 0 description to_R3 set interfaces fe-1/2/2 unit 0 family inet address 10.0.0.5/30 set interfaces fe-1/2/3 unit 0 description to_R4 set interfaces fe-1/2/3 unit 0 family inet address 10.1.0.5/30 set interfaces lo0 unit 0 family inet address 192.168.0.1/32 set protocols bgp group int type internal set protocols bgp group int local-address 192.168.0.1 set protocols bgp group int neighbor 192.168.0.2 set protocols bgp group int neighbor 192.168.0.3 set protocols bgp group to_64511 type external set protocols bgp group to_64511 export main set protocols bgp group to_64511 neighbor 10.1.0.6 peer-as 64511 set protocols ospf area 0.0.0.0 interface fe-1/2/0.0 set protocols ospf area 0.0.0.0 interface fe-1/2/2.0 set protocols ospf area 0.0.0.0 interface lo0.0 passive set policy-options policy-statement main term subroutine-as-a-match from policy subroutine set policy-options policy-statement main term subroutine-as-a-match then accept set policy-options policy-statement main term nothing-else then reject set policy-options policy-statement subroutine term get-routes from protocol static set policy-options policy-statement subroutine term get-routes then accept set policy-options policy-statement subroutine term nothing-else then reject set routing-options static route 172.16.1.16/28 discard set routing-options static route 172.16.1.32/28 discard set routing-options static route 172.16.1.48/28 discard set routing-options static route 172.16.1.64/28 discard set routing-options router-id 192.168.0.1 set routing-options autonomous-system 64510
디바이스 R2
set interfaces fe-1/2/0 unit 0 description to_R1 set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.2/30 set interfaces fe-1/2/1 unit 0 description to_R3 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 int type internal set protocols bgp group int local-address 192.168.0.2 set protocols bgp group int neighbor 192.168.0.1 export send-static set protocols bgp group int neighbor 192.168.0.3 set protocols ospf area 0.0.0.0 interface fe-1/2/0.0 set protocols ospf area 0.0.0.0 interface fe-1/2/1.0 set protocols ospf area 0.0.0.0 interface lo0.0 passive 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 172.16.2.16/28 discard set routing-options static route 172.16.2.32/28 discard set routing-options static route 172.16.2.48/28 discard set routing-options static route 172.16.2.64/28 discard set routing-options router-id 192.168.0.2 set routing-options autonomous-system 64510
디바이스 R3
set interfaces fe-1/2/1 unit 0 description to_R2 set interfaces fe-1/2/1 unit 0 family inet address 10.1.0.2/30 set interfaces fe-1/2/2 unit 0 description to_R1 set interfaces fe-1/2/2 unit 0 family inet address 10.0.0.6/30 set interfaces lo0 unit 0 family inet address 192.168.0.3/32 set protocols bgp group int type internal set protocols bgp group int local-address 192.168.0.3 set protocols bgp group int neighbor 192.168.0.1 export send-static set protocols bgp group int neighbor 192.168.0.2 set protocols ospf area 0.0.0.0 interface fe-1/2/2.6 set protocols ospf area 0.0.0.0 interface fe-1/2/0.4 set protocols ospf area 0.0.0.0 interface lo0.0 passive set policy-options policy-statement send-static from protocol static set policy-options policy-statement send-static then accept set routing-options static route 172.16.3.16/28 discard set routing-options static route 172.16.3.32/28 discard set routing-options static route 172.16.3.48/28 discard set routing-options static route 172.16.3.64/28 discard set routing-options router-id 192.168.0.3 set routing-options autonomous-system 64510
디바이스 R4
set interfaces fe-1/2/3 unit 0 description to_R1 set interfaces fe-1/2/3 unit 0 family inet address 10.1.0.6/30 set interfaces lo0 unit 0 family inet address 192.168.0.4/32 set protocols bgp group ext type external set protocols bgp group ext peer-as 64510 set protocols bgp group ext neighbor 10.1.0.5 set routing-options autonomous-system 64511
절차
단계별 절차
다음 예제에서는 구성 계층에서 다양한 레벨을 탐색해야 합니다. CLI 탐색에 대한 자세한 내용은 Junos OS CLI 사용자 가이드에서 확인하십시오구성 모드에서 CLI 편집기 사용.
디바이스 R1을 구성하려면:
디바이스 인터페이스를 구성합니다.
[edit interfaces] user@R1# set fe-1/2/0 unit 0 description to_R2 user@R1# set fe-1/2/0 unit 0 family inet address 10.0.0.1/30 user@R1# set fe-1/2/2 unit 0 description to_R3 user@R1# set fe-1/2/2 unit 0 family inet address 10.0.0.5/30 user@R1# set fe-1/2/3 unit 0 description to_R4 user@R1# set fe-1/2/3 unit 0 family inet address 10.1.0.5/30 user@R1# set lo0 unit 0 family inet address 192.168.0.1/32
장비 R2 및 디바이스 R3에 대한 내부 BGP(IBGP) 연결을 구성합니다.
[edit protocols bgp group int] user@R1# set type internal user@R1# set local-address 192.168.0.1 user@R1# set neighbor 192.168.0.2 user@R1# set neighbor 192.168.0.3
디바이스 R4에 대한 EBGP 연결을 구성합니다.
[edit protocols bgp group to_64511] user@R1# set type external user@R1# set export main user@R1# set neighbor 10.1.0.6 peer-as 64511
디바이스 R2 및 디바이스 R3에 대한 OSPF 연결을 구성합니다.
[edit protocols ospf area 0.0.0.0] user@R1# set interface fe-1/2/0.0 user@R1# set interface fe-1/2/2.0 user@R1# set interface lo0.0 passive
정책을
main
구성합니다.[edit policy-options policy-statement main term subroutine-as-a-match] user@R1# set from policy subroutine user@R1# set then accept [edit policy-options policy-statement main term nothing-else] user@R1# set then reject
정책을
subroutine
구성합니다.[edit policy-options policy-statement subroutine term get-routes] user@R1# set from protocol static user@R1# set then accept [edit policy-options policy-statement subroutine term nothing-else] user@R1# set then reject
172.16.5.0/24 네트워크에 정적 경로를 구성합니다.
[edit routing-options static] user@R1# set route 172.16.1.16/28 discard user@R1# set route 172.16.1.32/28 discard user@R1# set route 172.16.1.48/28 discard user@R1# set route 172.16.1.64/28 discard
AS(Autonomous System) 번호와 라우터 ID를 구성합니다.
[edit routing-options] user@R1# set router-id 192.168.0.1 user@R1# set autonomous-system 64510
결과
구성 모드에서 , show protocols
show policy-options
및 show routing-options
명령을 입력show interfaces
하여 구성을 확인합니다. 출력이 의도한 구성을 표시하지 않는 경우 이 예제의 지침을 반복하여 구성을 수정합니다.
user@R1# show interfaces fe-1/2/0 { unit 0 { description to_R2; family inet { address 10.0.0.1/30; } } } fe-1/2/2 { unit 0 { description to_R3; family inet { address 10.0.0.5/30; } } } fe-1/2/3 { unit 0 { description to_R4; family inet { address 10.1.0.5/30; } } } lo0 { unit 0 { family inet { address 192.168.0.1/32; } } }
user@R1# show protocols bgp { group int { type internal; local-address 192.168.0.1; neighbor 192.168.0.2; neighbor 192.168.0.3; } group to_64511 { type external; export main; neighbor 10.1.0.6 { peer-as 64511; } } } ospf { area 0.0.0.0 { interface fe-1/2/0.0; interface fe-1/2/2.0; interface lo0.0 { passive; } } }
user@R1# show policy-options policy-statement main { term subroutine-as-a-match { from policy subroutine; then accept; } term nothing-else { then reject; } } policy-statement subroutine { term get-routes { from protocol static; then accept; } term nothing-else { then reject; } }
user@R1# show routing-options static { route 172.6.1.16/28 discard; route 172.6.1.32/28 discard; route 172.6.1.48/28 discard; route 172.6.1.64/28 discard; } router-id 192.168.0.1; autonomous-system 64510;
디바이스 구성을 완료한 경우 구성 모드에서 입력 commit
합니다.
확인
구성이 올바르게 작동하는지 확인합니다.
디바이스 R1의 경로 검증
목적
Device R1에서 라우팅 테이블의 정적 경로를 확인합니다.
실행
user@R1> show route protocol static inet.0: 23 destinations, 23 routes (23 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 172.16.1.16/28 *[Static/5] 1d 02:02:13 Discard 172.16.1.32/28 *[Static/5] 1d 02:02:13 Discard 172.16.1.48/28 *[Static/5] 1d 02:02:13 Discard 172.16.1.64/28 *[Static/5] 1d 02:02:13 Discard
의미
디바이스 R1에는 4개의 정적 경로가 있습니다.
장비에 대한 경로 광고 검증 R4
목적
Device R1에서 정적 경로가 Device R4에 광고되는지 확인합니다.
실행
user@R1> show route advertising-protocol bgp 10.1.0.6 inet.0: 23 destinations, 23 routes (23 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.1.16/28 Self I * 172.16.1.32/28 Self I * 172.16.1.48/28 Self I * 172.16.1.64/28 Self I
의미
예상대로 Device R1은 Device R4에 대한 정적 경로만 광고합니다.
기본 BGP 내보내기 정책 실험
목적
정책 또는 정책 main
subroutine
에서 최종 then reject
용어를 제거할 때 어떤 일이 발생할 수 있는지 확인합니다.
실행
Device R1에서 정책
main
의 최종 용어를 비활성화합니다.[edit policy-options policy-statement main] user@R1# deactivate term nothing-else user@R1# commit
Device R1에서 디바이스 R4에 어떤 경로가 광고되는지 확인합니다.
user@R1> show route advertising-protocol bgp 10.1.0.6 inet.0: 23 destinations, 23 routes (23 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.1.16/28 Self I * 172.16.1.32/28 Self I * 172.16.1.48/28 Self I * 172.16.1.64/28 Self I * 172.16.2.16/28 Self I * 172.16.2.32/28 Self I * 172.16.2.48/28 Self I * 172.16.2.64/28 Self I * 172.16.3.16/28 Self I * 172.16.3.32/28 Self I * 172.16.3.48/28 Self I * 172.16.3.64/28 Self I
이제 Device R1의 모든 BGP 경로가 Device R4로 전송됩니다. 이는 프로세싱이 정책
main
으로 반환된 후 기본 BGP 내보내기 정책이 적용되므로Device R1에서 정책의 최종 용어를 다시 활성화하고 정책
main
subroutine
의 최종 용어를 비활성화합니다.[edit policy-options policy-statement main] user@R1# activate term nothing-else [edit policy-options policy-statement subroutine] user@R1# deactivate term nothing-else user@R1# commit
Device R1에서 디바이스 R4에 어떤 경로가 광고되는지 확인합니다.
user@R1> show route advertising-protocol bgp 10.1.0.6 inet.0: 23 destinations, 23 routes (23 active, 0 holddown, 0 hidden) Prefix Nexthop MED Lclpref AS path * 172.16.1.16/28 Self I * 172.16.1.32/28 Self I * 172.16.1.48/28 Self I * 172.16.1.64/28 Self I * 172.16.2.16/28 Self I * 172.16.2.32/28 Self I * 172.16.2.48/28 Self I * 172.16.2.64/28 Self I * 172.16.3.16/28 Self I * 172.16.3.32/28 Self I * 172.16.3.48/28 Self I * 172.16.3.64/28 Self I
이제 Device R1의 모든 BGP 경로가 Device R4로 전송됩니다. 이는 프로세싱이 정책
main
으로 반환되기 전에 기본 BGP 내보내기 정책이 정책에subroutine
적용되기 때문입니다.
의미
기본 BGP 내보내기 정책이 적용되지 않도록 하려면 기본 정책과 참조된 모든 서브라우틴에 최종 then reject
용어를 포함해야 합니다.