Tóm tắt: IOS XR dùng RPL: khai báo prefix-set, community-set, as-path-set rồi viết logic if ... then ... endif trong route-policy ... end-policy. Junos dùng policy-options: prefix-list, community, as-path và policy-statement gồm nhiều term với from (điều kiện) và then (hành động). Khái niệm attribute xem BGP – khái niệm cốt lõi, danh sách community xem BGP communities.
Ví dụ: ISP AS 64500, khách hàng AS 65001 (neighbor 198.51.100.6) chỉ được quảng bá 203.0.113.0/24, upstream AS 64510 (neighbor 198.51.100.2). Route khách được gắn 64500:100 và local-preference 200; ra upstream chỉ gửi route có 64500:100.
Luồng hoạt động
flowchart LR CE["CE AS65001"] -->|"203.0.113.0/24"| IN["CUST-65001-IN"] IN -->|"prefix + AS_PATH đúng"| TAG["Xoá 64500:*, gắn 64500:100, LP 200"] IN -->|"sai"| DROP["drop / reject"] TAG --> RIB["BGP table"] RIB --> OUT["UPSTREAM-OUT"] OUT -->|"có 64500:100"| UP["Upstream AS64510"] OUT -->|"còn lại"| DROP
Cấu hình
Ngữ nghĩa hành động
| Ý nghĩa | IOS XR (RPL) | Junos |
|---|---|---|
| Chấp nhận, vẫn chạy tiếp các lệnh sau | pass |
Không có terminating action, sang term kế |
| Chấp nhận và dừng | done |
accept |
| Loại và dừng | drop |
reject |
| Sang term / policy kế | (logic if/elseif/else) |
next term / next policy |
| Hết policy mà chưa quyết định | drop | Rơi vào default policy của BGP: import thì accept |
| Gọi policy con | apply SET-LP(80) |
Chuỗi policy import [ A B ] hoặc from policy |
Junos: policy import thiếu term cuối then reject thì route không match vẫn được nhận (default BGP import là accept). Luôn kết thúc bằng term REJECT.
IOS XR
prefix-set CUST-65001
203.0.113.0/24
end-set
!
community-set CUSTOMER-ROUTES
64500:100
end-set
!
community-set OUR-INTERNAL
64500:*
end-set
!
as-path-set AS65001-ONLY
ios-regex '^65001(_65001)*$'
end-set
!
route-policy CUST-65001-IN
if not destination in CUST-65001 then
drop
endif
if not as-path in AS65001-ONLY then
drop
endif
delete community in OUR-INTERNAL
set community CUSTOMER-ROUTES additive
set local-preference 200
done
end-policy
!
route-policy UPSTREAM-OUT
if community matches-any CUSTOMER-ROUTES then
delete community in OUR-INTERNAL
pass
else
drop
endif
end-policy
!
router bgp 64500
neighbor 198.51.100.6
remote-as 65001
address-family ipv4 unicast
route-policy CUST-65001-IN in
route-policy PASS out
!
!
neighbor 198.51.100.2
remote-as 64510
address-family ipv4 unicast
route-policy UPSTREAM-OUT out
!
!
!PASS là policy chỉ có pass (xem L3VPN). Bỏ additive thì set community thay thế toàn bộ community cũ.
Policy có tham số, dùng lại cho nhiều neighbor:
route-policy SET-LP($lp)
set local-preference $lp
end-policy
!
route-policy UPSTREAM-B-IN
apply SET-LP(80)
pass
end-policy
!
route-policy UPSTREAM-B-OUT
if community matches-any CUSTOMER-ROUTES then
prepend as-path 64500 2
pass
endif
end-policyJunos
set policy-options prefix-list CUST-65001 203.0.113.0/24
set policy-options community CUSTOMER-ROUTES members 64500:100
set policy-options community OUR-INTERNAL members "^64500:.*$"
set policy-options as-path AS65001-ONLY "65001+"
set policy-options policy-statement CUST-65001-IN term SCRUB then community delete OUR-INTERNAL
set policy-options policy-statement CUST-65001-IN term OK from prefix-list-filter CUST-65001 exact
set policy-options policy-statement CUST-65001-IN term OK from as-path AS65001-ONLY
set policy-options policy-statement CUST-65001-IN term OK then community add CUSTOMER-ROUTES
set policy-options policy-statement CUST-65001-IN term OK then local-preference 200
set policy-options policy-statement CUST-65001-IN term OK then accept
set policy-options policy-statement CUST-65001-IN term REJECT then reject
set policy-options policy-statement UPSTREAM-OUT term CUST from community CUSTOMER-ROUTES
set policy-options policy-statement UPSTREAM-OUT term CUST then community delete OUR-INTERNAL
set policy-options policy-statement UPSTREAM-OUT term CUST then accept
set policy-options policy-statement UPSTREAM-OUT term REJECT then reject
set protocols bgp group CUST-65001 type external
set protocols bgp group CUST-65001 peer-as 65001
set protocols bgp group CUST-65001 import CUST-65001-IN
set protocols bgp group CUST-65001 neighbor 198.51.100.6
set protocols bgp group ISP-A export UPSTREAM-OUTQuy tắc khớp trong một term: các điều kiện from khác loại là AND (prefix và AS_PATH), nhiều giá trị cùng loại là OR. Term SCRUB không có from nên khớp mọi route, không có terminating action nên đi tiếp sang OK.
Prepend và local-preference trên Junos:
set policy-options policy-statement UPSTREAM-B-IN term ALL then local-preference 80
set policy-options policy-statement UPSTREAM-B-IN term ALL then accept
set policy-options policy-statement UPSTREAM-B-OUT term CUST from community CUSTOMER-ROUTES
set policy-options policy-statement UPSTREAM-B-OUT term CUST then as-path-prepend "64500 64500"
set policy-options policy-statement UPSTREAM-B-OUT term CUST then accept
set policy-options policy-statement UPSTREAM-B-OUT term REJECT then rejectKiểm tra
| Mục đích | IOS XR | Junos |
|---|---|---|
| Xem policy và set | show rpl route-policy CUST-65001-IN |
show configuration policy-options policy-statement CUST-65001-IN |
| Policy gắn ở neighbor nào | show rpl route-policy CUST-65001-IN attachment-points |
show configuration protocols bgp | display set | match CUST-65001-IN |
| Thử policy với prefix | — | test policy CUST-65001-IN 203.0.113.0/24 |
| Route nhận sau policy | show bgp ipv4 unicast neighbor 198.51.100.6 routes |
show route receive-protocol bgp 198.51.100.6 extensive |
| Community và LP thực tế | show bgp ipv4 unicast 203.0.113.0/24 |
show route 203.0.113.0/24 detail |
| Route gửi upstream | show bgp ipv4 unicast neighbor 198.51.100.2 advertised-routes |
show route advertising-protocol bgp 198.51.100.2 |
Lỗi thường gặp
| Triệu chứng | Nguyên nhân | Cách xử lý |
|---|---|---|
XR commit lỗi trong prefix-set |
Thiếu dấu , giữa các dòng (dòng cuối không có dấu phẩy) |
203.0.113.0/24, rồi dòng kế |
XR: route bị loại dù không gặp drop |
Đi hết policy mà không gặp pass/done thì mặc định drop |
Thêm pass ở nhánh muốn nhận |
| XR: community cũ của khách biến mất | set community X không có additive |
Thêm additive |
| Junos: nhận cả prefix lạ từ khách | Thiếu term cuối reject, default policy accept |
Thêm term REJECT then reject |
Junos: /25 của khách bị loại |
prefix-list-filter ... exact chỉ khớp đúng /24 |
Dùng orlonger hoặc route-filter 203.0.113.0/24 upto /24 |
| Junos: community regex không khớp | Quên nháy kép hoặc regex sai | members "^64500:.*$", kiểm bằng test policy |
| Upstream không nhận route khách | Route chưa được gắn 64500:100 vì policy in sai thứ tự |
Xem community thực tế bằng lệnh chi tiết prefix ở trên |
| XR: sửa policy mà route chưa đổi | Chưa yêu cầu route-refresh từ peer | clear bgp ipv4 unicast 198.51.100.6 soft in, xem thêm BGP troubleshooting |