Fix: bgp route selection
continuous-integration/drone/push Build is passing Details

This commit is contained in:
186526 2022-12-28 01:14:15 +08:00
parent db8827f83e
commit dcfe9c677a
5 changed files with 50 additions and 23 deletions

View File

@ -1,27 +1,32 @@
function pub_add_communities(int ASN; int PeerType) { function pub_add_communities(int ASN; int PeerType) {
# DIRECT PEER # DIRECT PEER
if (PeerType=0) then { if (PeerType=0) then {
bgp_large_community.add((LOCAL_ASN, 110, 0)); if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then {
bgp_large_community.add((LOCAL_ASN, 110, 2)); bgp_large_community.add((LOCAL_ASN, 110, 0));
bgp_large_community.add((LOCAL_ASN, 110, 2));
}
# PEER via IX # PEER via IX
} else if (PeerType=1) then { } else if (PeerType=1) then {
bgp_large_community.add((LOCAL_ASN, 110, 0)); if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then {
bgp_large_community.add((LOCAL_ASN, 110, 1)); bgp_large_community.add((LOCAL_ASN, 110, 0));
bgp_large_community.add((LOCAL_ASN, 110, 1));
}
# UPSTREAM # UPSTREAM
}else if (PeerType=10) then { }else if (PeerType=10) then {
bgp_large_community.add((LOCAL_ASN, 110, 10)); if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then bgp_large_community.add((LOCAL_ASN, 110, 10));
# DOWNSTREAM # DOWNSTREAM
} else if (PeerType=20) then { } else if (PeerType=20) then {
bgp_large_community.add((LOCAL_ASN, 110, 20)); if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then bgp_large_community.add((LOCAL_ASN, 110, 20));
} }
# Finished (LOCAL_ASN, 110, *); # Finished (LOCAL_ASN, 110, *);
if (LOCAL_ASN, 120, POP) ~ bgp_large_community then bgp_large_community.add((LOCAL_ASN, 120, POP)); if bgp_large_community !~ [(LOCAL_ASN, 120, *)] then bgp_large_community.add((LOCAL_ASN, 120, POP));
if (LOCAL_ASN, 121, REGION) ~ bgp_large_community then bgp_large_community.add((LOCAL_ASN, 121, REGION)); if bgp_large_community !~ [(LOCAL_ASN, 121, *)] then bgp_large_community.add((LOCAL_ASN, 121, REGION));
# Finished (LOCAL_ASN, 120~130, *); # Finished (LOCAL_ASN, 120~130, *);
return true; return true;
@ -67,18 +72,33 @@ function pub_process_communities(int ASN; int PeerType) {
return true; return true;
} }
function pub_process_path() {
# Delete Self eBGP Confed Path.
bgp_path.delete([4200000000..4225479999]);
# Route is via Europe & Africa & Middle East
if bgp_large_community ~ [(LOCAL_ASN, 122, 100), (LOCAL_ASN, 122, 300..310), (LOCAL_ASN, 122, 600)] then bgp_path.prepend(LOCAL_ASN);
# Route is via America
if bgp_large_community ~ [(LOCAL_ASN, 122, 200..299)] then bgp_path.prepend(LOCAL_ASN);
# Route is via East Asia & Oceania
if bgp_large_community ~ [(LOCAL_ASN, 122, 400..500)] then bgp_path.prepend(LOCAL_ASN);
# Self PoP
if (LOCAL_ASN, 120, POP) ~ bgp_large_community then bgp_path.delete(LOCAL_ASN);
}
function transit_import_filter(int ASN) { function transit_import_filter(int ASN) {
if !is_valid() then return false; if !is_valid() then return false;
pub_add_communities(ASN, 10); pub_add_communities(ASN, 10);
pub_preprocess_communities(); pub_preprocess_communities();
bgp_local_pref = 400 - bgp_path.len * 10;
return true; return true;
} }
function transit_export_filter(int ASN) { function transit_export_filter(int ASN) {
# Delete Self eBGP Confed Path. pub_process_path();
bgp_path.delete([4200000000..4225479999]);
if !is_valid() then return false; if !is_valid() then return false;
if bgp_large_community ~ [(LOCAL_ASN, 110, 0), (LOCAL_ASN, 110, 10)] then return false;
if bgp_path.last !~ DOWNSTREAM_ASN && source = RTS_BGP then return false; if bgp_path.last !~ DOWNSTREAM_ASN && source = RTS_BGP then return false;
pub_add_communities(ASN, 10);
if pub_process_communities(ASN, 10) then return true; if pub_process_communities(ASN, 10) then return true;
else return false; else return false;
} }

View File

@ -3,12 +3,14 @@ function downstream_import_filter(int ASN) {
if bgp_path.last !~ DOWNSTREAM_ASN then return false; if bgp_path.last !~ DOWNSTREAM_ASN then return false;
pub_add_communities(ASN, 20); pub_add_communities(ASN, 20);
pub_preprocess_communities(); pub_preprocess_communities();
bgp_local_pref = 500 - bgp_path.len * 10;
return true; return true;
} }
function downstream_export_filter(int ASN) { function downstream_export_filter(int ASN) {
pub_process_path();
if !is_valid() then return false; if !is_valid() then return false;
bgp_path.delete([4200000000..4225479999]); pub_add_communities(ASN, 10);
if pub_process_communities(ASN, 20) then return true; if pub_process_communities(ASN, 20) then return true;
else return false; else return false;
} }

View File

@ -4,12 +4,10 @@ function net186_import_filter(int POPID)
{ {
public_bgp_path = delete(bgp_path, [4200000000..4225479999]); public_bgp_path = delete(bgp_path, [4200000000..4225479999]);
if filter(bgp_large_community, [(LOCAL_ASN, 120, *)]).len != 0 then bgp_large_community.add((LOCAL_ASN, 120, POP)); if (LOCAL_ASN, 122, REGION) !~ bgp_large_community then bgp_large_community.add((LOCAL_ASN, 122, REGION));
if filter(bgp_large_community, [(LOCAL_ASN, 121, *)]).len != 0 then bgp_large_community.add((LOCAL_ASN, 121, REGION));
if (LOCAL_ASN, 122, REGION) ~ bgp_large_community then bgp_large_community.add((LOCAL_ASN, 122, REGION)); if bgp_large_community ~ [(LOCAL_ASN, 110, 0), (LOCAL_ASN, 110, 2), (LOCAL_ASN, 110, 20)] then bgp_local_pref = 500;
# ROUTE_DECIDER Start else if bgp_large_community ~ [(LOCAL_ASN, 110, 1), (LOCAL_ASN, 110, 10)] then bgp_local_pref = 400;
if (LOCAL_ASN, 110, 2) ~ bgp_large_community then bgp_local_pref = 500;
else if (LOCAL_ASN, 110, 1) ~ bgp_large_community then bgp_local_pref = 400;
else bgp_local_pref = 300; else bgp_local_pref = 300;
viaRegion = 0; viaRegion = 0;
@ -20,13 +18,16 @@ function net186_import_filter(int POPID)
# Route is via East Asia & Oceania # Route is via East Asia & Oceania
if bgp_large_community ~ [(LOCAL_ASN, 122, 400..500)] then viaRegion = viaRegion + 1; if bgp_large_community ~ [(LOCAL_ASN, 122, 400..500)] then viaRegion = viaRegion + 1;
if viaRegion > 2 then return false; if viaRegion >= 3 then bgp_local_pref = bgp_local_pref - 50;
else if viaRegion = 2 then bgp_local_pref = bgp_local_pref - 50;
# Route is via China mainland but not advertise in China mainland. # Route is via China mainland but not advertise in China mainland.
if (LOCAL_ASN, 122, 430) ~ bgp_large_community && REGION != 430 && (LOCAL_ASN, 120, 430) ~ bgp_large_community then return false; if (LOCAL_ASN, 122, 430) ~ bgp_large_community && REGION != 430 && (LOCAL_ASN, 120, 430) ~ bgp_large_community then return false;
bgp_local_pref = bgp_local_pref - filter(bgp_large_community, [(LOCAL_ASN, 122, *)]).len * 10; bgp_local_pref = bgp_local_pref - filter(bgp_large_community, [(LOCAL_ASN, 122, *)]).len * 5;
bgp_local_pref = bgp_local_pref - public_bgp_path.len * 10;
return true;
}; };
function net186_export_filter(int POPID) { function net186_export_filter(int POPID) {
@ -46,5 +47,8 @@ function net186_export_filter(int POPID) {
return false; return false;
} }
if bgp_large_community !~ [(LOCAL_ASN, 120, *)] then bgp_large_community.add((LOCAL_ASN, 120, POP));
if bgp_large_community !~ [(LOCAL_ASN, 121, *)] then bgp_large_community.add((LOCAL_ASN, 121, REGION));
return true; return true;
}; };

View File

@ -12,14 +12,15 @@ function direct_peer_import_filter(int ASN) {
if !is_peer_route() then return false; if !is_peer_route() then return false;
pub_add_communities(ASN, 0); pub_add_communities(ASN, 0);
pub_preprocess_communities(); pub_preprocess_communities();
bgp_local_pref = 500 - bgp_path.len * 10;
return true; return true;
} }
function direct_peer_export_filter(int ASN) { function direct_peer_export_filter(int ASN) {
# Delete Self eBGP Confed Path. pub_process_path();
bgp_path.delete([4200000000..4225479999]);
if !is_valid() then return false; if !is_valid() then return false;
if !is_peer_route() then return false; if !is_peer_route() then return false;
pub_add_communities(ASN, 10);
if pub_process_communities(ASN, 0) then return true; if pub_process_communities(ASN, 0) then return true;
else return false; else return false;
} }

View File

@ -13,7 +13,7 @@ protocol kernel {
# Blackhole (LOCAL_ASN, 0, 666) # Blackhole (LOCAL_ASN, 0, 666)
if (LOCAL_ASN, 0, 666) ~ bgp_large_community then dest = RTD_BLACKHOLE; if (LOCAL_ASN, 0, 666) ~ bgp_large_community then dest = RTD_BLACKHOLE;
# Only Announced (LOCAL_ASN, 0, 665) # Only Announced (LOCAL_ASN, 0, 665)
if (LOCAL_ASN, 0, 665) ~ bgp_large_community then reject; if (LOCAL_ASN, 0, 665) ~ bgp_large_community && bgp_path.last !~ [4200000000..4225479999] then reject;
krt_prefsrc = ROUTER_IP; krt_prefsrc = ROUTER_IP;
accept; accept;
}; };