Fix: bgp route selection
All checks were successful
continuous-integration/drone/push Build is passing

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

View File

@ -4,12 +4,10 @@ function net186_import_filter(int POPID)
{
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 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));
# ROUTE_DECIDER Start
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;
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;
else if bgp_large_community ~ [(LOCAL_ASN, 110, 1), (LOCAL_ASN, 110, 10)] then bgp_local_pref = 400;
else bgp_local_pref = 300;
viaRegion = 0;
@ -20,13 +18,16 @@ function net186_import_filter(int POPID)
# Route is via East Asia & Oceania
if bgp_large_community ~ [(LOCAL_ASN, 122, 400..500)] then viaRegion = viaRegion + 1;
if viaRegion > 2 then return false;
else if viaRegion = 2 then bgp_local_pref = bgp_local_pref - 50;
if viaRegion >= 3 then bgp_local_pref = bgp_local_pref - 50;
# 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;
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) {
@ -46,5 +47,8 @@ function net186_export_filter(int POPID) {
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;
};