2022-12-26 15:41:18 +00:00
|
|
|
function pub_add_communities(int ASN, int type) {
|
|
|
|
|
|
|
|
# DIRECT PEER
|
|
|
|
if (type=0) then {
|
|
|
|
bgp_large_community.add((LOCAL_ASN, 110, 0));
|
|
|
|
bgp_large_community.add((LOCAL_ASN, 110, 2));
|
|
|
|
|
|
|
|
# PEER via IX
|
|
|
|
} else if (type=1) then {
|
|
|
|
bgp_large_community.add((LOCAL_ASN, 110, 0));
|
|
|
|
bgp_large_community.add((LOCAL_ASN, 110, 1));
|
|
|
|
j
|
|
|
|
# UPSTREAM
|
|
|
|
}else if (type=10) then {
|
|
|
|
bgp_large_community.add((LOCAL_ASN, 110, 10));
|
|
|
|
|
|
|
|
# DOWNSTREAM
|
|
|
|
} else if (type=20) 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));
|
|
|
|
|
|
|
|
# Finished (LOCAL_ASN, 120~130, *);
|
|
|
|
}
|
|
|
|
|
|
|
|
function pub_preprocess_communities() {
|
|
|
|
if (LOCAL_ASN, 115, 1) ~ bgp_large_community then bgp_path.prepend(bgp_path.last);
|
|
|
|
if (LOCAL_ASN, 115, 3) ~ bgp_large_community then {
|
|
|
|
bgp_path.prepend(bgp_path.last);
|
|
|
|
bgp_path.prepend(bgp_path.last);
|
|
|
|
bgp_path.prepend(bgp_path.last);
|
|
|
|
}
|
|
|
|
if (LOCAL_ASN, 115, 5) ~ bgp_large_community then {
|
|
|
|
bgp_path.prepend(bgp_path.last);
|
|
|
|
bgp_path.prepend(bgp_path.last);
|
|
|
|
bgp_path.prepend(bgp_path.last);
|
|
|
|
bgp_path.prepend(bgp_path.last);
|
|
|
|
bgp_path.prepend(bgp_path.last);
|
|
|
|
}
|
|
|
|
# Finished (LOCAL_ASN, 115, *);
|
|
|
|
}
|
|
|
|
|
|
|
|
function pub_process_communities(int ASN, int type) {
|
|
|
|
|
|
|
|
if (LOCAL_ASN, 125, POP) ~ bgp_large_community then {
|
|
|
|
bgp_community.add((65535, 65282));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LOCAL_ASN, 126, REGION) ~ bgp_large_community then {
|
|
|
|
bgp_community.add((65535, 65283));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
if (LOCAL_ASN, 2, ASN) ~ bgp_large_community then reject
|
|
|
|
|
|
|
|
# PEER
|
|
|
|
if (type<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
|
|
|
|
} else if (type=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
|
|
|
|
} else if (type=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-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-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-26 16:39:44 +00:00
|
|
|
if !is_valid() then return false;
|
2022-12-26 15:41:18 +00:00
|
|
|
# Delete Self eBGP Confed Path.
|
|
|
|
bgp_path.delete([4200000000..4225479999]);
|
|
|
|
pub_process_communities(ASN, 10);
|
2022-12-26 16:39:44 +00:00
|
|
|
if bgp_path.last !~ DOWNSTREAM_ASN then return false;
|
|
|
|
return true;
|
2022-12-26 15:41:18 +00:00
|
|
|
}
|