2022-12-26 17:01:37 +00:00
|
|
|
function pub_add_communities(int ASN; int PeerType) {
|
2022-12-26 15:41:18 +00:00
|
|
|
# DIRECT PEER
|
2022-12-26 17:01:37 +00:00
|
|
|
if (PeerType=0) then {
|
2022-12-27 17:14:15 +00:00
|
|
|
if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then {
|
|
|
|
bgp_large_community.add((LOCAL_ASN, 110, 0));
|
|
|
|
bgp_large_community.add((LOCAL_ASN, 110, 2));
|
|
|
|
}
|
2022-12-26 15:41:18 +00:00
|
|
|
|
|
|
|
# PEER via IX
|
2022-12-26 17:01:37 +00:00
|
|
|
} else if (PeerType=1) then {
|
2022-12-27 17:14:15 +00:00
|
|
|
if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then {
|
|
|
|
bgp_large_community.add((LOCAL_ASN, 110, 0));
|
|
|
|
bgp_large_community.add((LOCAL_ASN, 110, 1));
|
|
|
|
}
|
|
|
|
|
2022-12-26 17:01:37 +00:00
|
|
|
|
2022-12-26 15:41:18 +00:00
|
|
|
# UPSTREAM
|
2022-12-26 17:01:37 +00:00
|
|
|
}else if (PeerType=10) then {
|
2022-12-27 17:14:15 +00:00
|
|
|
if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then bgp_large_community.add((LOCAL_ASN, 110, 10));
|
2022-12-26 15:41:18 +00:00
|
|
|
|
|
|
|
# DOWNSTREAM
|
2022-12-26 17:01:37 +00:00
|
|
|
} else if (PeerType=20) then {
|
2022-12-27 17:14:15 +00:00
|
|
|
if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then bgp_large_community.add((LOCAL_ASN, 110, 20));
|
2022-12-28 01:51:41 +00:00
|
|
|
# Self Route
|
|
|
|
} else if (PeerType=30) then {
|
|
|
|
if bgp_large_community !~ [(LOCAL_ASN, 110, *)] then bgp_large_community.add((LOCAL_ASN, 110, 30));
|
2022-12-26 15:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Finished (LOCAL_ASN, 110, *);
|
|
|
|
|
2022-12-27 17:14:15 +00:00
|
|
|
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));
|
2022-12-27 07:31:54 +00:00
|
|
|
|
2022-12-26 15:41:18 +00:00
|
|
|
# Finished (LOCAL_ASN, 120~130, *);
|
2022-12-27 07:31:54 +00:00
|
|
|
return true;
|
2022-12-26 15:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function pub_preprocess_communities() {
|
2023-01-04 16:41:54 +00:00
|
|
|
if (LOCAL_ASN, 115, 1) ~ bgp_large_community then bgp_path.prepend(LOCAL_ASN);
|
2022-12-26 15:41:18 +00:00
|
|
|
if (LOCAL_ASN, 115, 3) ~ bgp_large_community then {
|
2023-01-04 16:41:54 +00:00
|
|
|
bgp_path.prepend(LOCAL_ASN);
|
|
|
|
bgp_path.prepend(LOCAL_ASN);
|
|
|
|
bgp_path.prepend(LOCAL_ASN);
|
2022-12-26 15:41:18 +00:00
|
|
|
}
|
|
|
|
if (LOCAL_ASN, 115, 5) ~ bgp_large_community then {
|
2023-01-04 16:41:54 +00:00
|
|
|
bgp_path.prepend(LOCAL_ASN);
|
|
|
|
bgp_path.prepend(LOCAL_ASN);
|
|
|
|
bgp_path.prepend(LOCAL_ASN);
|
|
|
|
bgp_path.prepend(LOCAL_ASN);
|
|
|
|
bgp_path.prepend(LOCAL_ASN);
|
2022-12-26 15:41:18 +00:00
|
|
|
}
|
|
|
|
# Finished (LOCAL_ASN, 115, *);
|
2022-12-27 07:31:54 +00:00
|
|
|
return true;
|
2022-12-26 15:41:18 +00:00
|
|
|
}
|
|
|
|
|
2022-12-26 17:01:37 +00:00
|
|
|
function pub_process_communities(int ASN; int PeerType) {
|
2022-12-26 16:39:44 +00:00
|
|
|
if (65535, 65281) ~ bgp_community then return false;
|
|
|
|
if (65535, 65282) ~ bgp_community then return false;
|
|
|
|
if (65535, 65283) ~ bgp_community then return false;
|
2022-12-26 15:41:18 +00:00
|
|
|
|
2022-12-26 17:01:37 +00:00
|
|
|
if (LOCAL_ASN, 2, ASN) ~ bgp_large_community then return false;
|
2022-12-26 15:41:18 +00:00
|
|
|
|
|
|
|
# PEER
|
2022-12-26 17:01:37 +00:00
|
|
|
if (PeerType<10) then {
|
2022-12-26 16:39:44 +00:00
|
|
|
if (LOCAL_ASN, 1, 1) ~ bgp_large_community then return false;
|
2022-12-26 15:41:18 +00:00
|
|
|
|
|
|
|
# UPSTREAM
|
2022-12-26 17:01:37 +00:00
|
|
|
} else if (PeerType=10) then {
|
2022-12-26 16:39:44 +00:00
|
|
|
if (LOCAL_ASN, 1, 0) ~ bgp_large_community then return false;
|
2022-12-26 15:41:18 +00:00
|
|
|
|
|
|
|
# DOWNSTREAM
|
2022-12-26 17:01:37 +00:00
|
|
|
} else if (PeerType=20) then {
|
2022-12-26 16:39:44 +00:00
|
|
|
if (LOCAL_ASN, 1, 2) ~ bgp_large_community then return false;
|
2022-12-26 15:41:18 +00:00
|
|
|
}
|
2022-12-27 07:31:54 +00:00
|
|
|
return true;
|
2022-12-26 15:41:18 +00:00
|
|
|
}
|
|
|
|
|
2022-12-27 17:14:15 +00:00
|
|
|
function pub_process_path() {
|
|
|
|
# Delete Self eBGP Confed Path.
|
|
|
|
bgp_path.delete([4200000000..4225479999]);
|
2022-12-29 09:56:01 +00:00
|
|
|
# Route is via or locate Europe & Africa & Middle East
|
|
|
|
if bgp_large_community ~ [(LOCAL_ASN, 122, 100), (LOCAL_ASN, 122, 300..310), (LOCAL_ASN, 122, 600), (LOCAL_ASN, 121, 100), (LOCAL_ASN, 121, 300..310), (LOCAL_ASN, 121, 600)] then bgp_path.prepend(LOCAL_ASN);
|
|
|
|
# Route is via or locate America
|
|
|
|
if bgp_large_community ~ [(LOCAL_ASN, 122, 200..299), (LOCAL_ASN, 121, 200..299)] then bgp_path.prepend(LOCAL_ASN);
|
|
|
|
# Route is via or locate East Asia & Oceania
|
|
|
|
if bgp_large_community ~ [(LOCAL_ASN, 122, 400..500), (LOCAL_ASN, 121, 200..299)] then bgp_path.prepend(LOCAL_ASN);
|
2022-12-27 17:14:15 +00:00
|
|
|
# Self PoP
|
2022-12-29 17:38:04 +00:00
|
|
|
if (LOCAL_ASN, 120, POP) ~ bgp_large_community then {
|
|
|
|
bgp_path.delete(LOCAL_ASN);
|
|
|
|
bgp_path.prepend(LOCAL_ASN);
|
|
|
|
}
|
2022-12-27 17:14:15 +00:00
|
|
|
}
|
|
|
|
|
2022-12-26 16:16:27 +00:00
|
|
|
function transit_import_filter(int ASN) {
|
2022-12-26 16:39:44 +00:00
|
|
|
if !is_valid() then return false;
|
2022-12-26 15:41:18 +00:00
|
|
|
pub_add_communities(ASN, 10);
|
|
|
|
pub_preprocess_communities();
|
2022-12-27 17:14:15 +00:00
|
|
|
bgp_local_pref = 400 - bgp_path.len * 10;
|
2023-01-02 18:51:46 +00:00
|
|
|
if LOCAL_ASN ~ bgp_path then bgp_local_pref = 1;
|
2022-12-26 16:39:44 +00:00
|
|
|
return true;
|
2022-12-26 15:41:18 +00:00
|
|
|
}
|
|
|
|
|
2022-12-26 16:16:27 +00:00
|
|
|
function transit_export_filter(int ASN) {
|
2022-12-27 17:14:15 +00:00
|
|
|
pub_process_path();
|
2022-12-26 17:17:37 +00:00
|
|
|
if !is_valid() then return false;
|
2022-12-27 17:14:15 +00:00
|
|
|
if bgp_large_community ~ [(LOCAL_ASN, 110, 0), (LOCAL_ASN, 110, 10)] then return false;
|
2022-12-29 17:38:04 +00:00
|
|
|
if bgp_path.last !~ DOWNSTREAM_ASN && source = RTS_BGP then {
|
|
|
|
print "transit exporter: for ", net, " ASN ", bgp_path.last;
|
|
|
|
return false;
|
|
|
|
}
|
2022-12-28 01:51:41 +00:00
|
|
|
pub_add_communities(ASN, 30);
|
2022-12-27 07:31:54 +00:00
|
|
|
if pub_process_communities(ASN, 10) then return true;
|
|
|
|
else return false;
|
2022-12-26 15:41:18 +00:00
|
|
|
}
|