Fix: bgp route selection
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -1,27 +1,32 @@
|
||||
function pub_add_communities(int ASN; int PeerType) {
|
||||
# DIRECT PEER
|
||||
if (PeerType=0) then {
|
||||
bgp_large_community.add((LOCAL_ASN, 110, 0));
|
||||
bgp_large_community.add((LOCAL_ASN, 110, 2));
|
||||
if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then {
|
||||
bgp_large_community.add((LOCAL_ASN, 110, 0));
|
||||
bgp_large_community.add((LOCAL_ASN, 110, 2));
|
||||
}
|
||||
|
||||
# PEER via IX
|
||||
} else if (PeerType=1) then {
|
||||
bgp_large_community.add((LOCAL_ASN, 110, 0));
|
||||
bgp_large_community.add((LOCAL_ASN, 110, 1));
|
||||
if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then {
|
||||
bgp_large_community.add((LOCAL_ASN, 110, 0));
|
||||
bgp_large_community.add((LOCAL_ASN, 110, 1));
|
||||
}
|
||||
|
||||
|
||||
# UPSTREAM
|
||||
}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
|
||||
} 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, *);
|
||||
|
||||
if (LOCAL_ASN, 120, POP) ~ bgp_large_community 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, 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));
|
||||
|
||||
# Finished (LOCAL_ASN, 120~130, *);
|
||||
return true;
|
||||
@ -67,18 +72,33 @@ function pub_process_communities(int ASN; int PeerType) {
|
||||
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) {
|
||||
if !is_valid() then return false;
|
||||
pub_add_communities(ASN, 10);
|
||||
pub_preprocess_communities();
|
||||
bgp_local_pref = 400 - bgp_path.len * 10;
|
||||
return true;
|
||||
}
|
||||
|
||||
function transit_export_filter(int ASN) {
|
||||
# Delete Self eBGP Confed Path.
|
||||
bgp_path.delete([4200000000..4225479999]);
|
||||
pub_process_path();
|
||||
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;
|
||||
pub_add_communities(ASN, 10);
|
||||
if pub_process_communities(ASN, 10) then return true;
|
||||
else return false;
|
||||
}
|
Reference in New Issue
Block a user