Rename BGP peers, introduce BGP communities

This commit is contained in:
graffen 2018-09-11 07:11:22 +00:00
parent 88ae0da48a
commit 1fce4773bc
10 changed files with 82 additions and 9 deletions

View file

@ -4,7 +4,7 @@ protocol device {
protocol static { protocol static {
route 172.20.0.0/14 via 172.20.170.192; route 172.20.0.0/14 via 172.20.170.192;
route 172.20.170.192/28 reject; route 172.20.170.192/27 reject;
import all; import all;
export none; export none;
} }
@ -14,7 +14,8 @@ include "/etc/bird/local4.conf";
# filter helpers # filter helpers
################# #################
##include "/etc/bird/filter4.conf"; #include "/etc/bird/filter4.conf";
include "/etc/bird/community_filters.conf";
protocol kernel { protocol kernel {
scan time 20; scan time 20;

View file

@ -10,7 +10,8 @@ include "/etc/bird/local6.conf";
# filter helpers # filter helpers
################# #################
##include "/etc/bird/filter6.conf"; #include "/etc/bird/filter6.conf";
include "/etc/bird/community_filters.conf";
protocol kernel { protocol kernel {
metric 64; # Use explicit kernel route metric to avoid collisions metric 64; # Use explicit kernel route metric to avoid collisions

67
community_filters.conf Normal file
View file

@ -0,0 +1,67 @@
#/etc/bird/community_filters.conf
function update_latency(int link_latency) {
bgp_community.add((64511, link_latency));
if (64511, 9) ~ bgp_community then { bgp_community.delete([(64511, 1..8)]); return 9; }
else if (64511, 8) ~ bgp_community then { bgp_community.delete([(64511, 1..7)]); return 8; }
else if (64511, 7) ~ bgp_community then { bgp_community.delete([(64511, 1..6)]); return 7; }
else if (64511, 6) ~ bgp_community then { bgp_community.delete([(64511, 1..5)]); return 6; }
else if (64511, 5) ~ bgp_community then { bgp_community.delete([(64511, 1..4)]); return 5; }
else if (64511, 4) ~ bgp_community then { bgp_community.delete([(64511, 1..3)]); return 4; }
else if (64511, 3) ~ bgp_community then { bgp_community.delete([(64511, 1..2)]); return 3; }
else if (64511, 2) ~ bgp_community then { bgp_community.delete([(64511, 1..1)]); return 2; }
else return 1;
}
function update_bandwidth(int link_bandwidth) {
bgp_community.add((64511, link_bandwidth));
if (64511, 21) ~ bgp_community then { bgp_community.delete([(64511, 22..29)]); return 21; }
else if (64511, 22) ~ bgp_community then { bgp_community.delete([(64511, 23..29)]); return 22; }
else if (64511, 23) ~ bgp_community then { bgp_community.delete([(64511, 24..29)]); return 23; }
else if (64511, 24) ~ bgp_community then { bgp_community.delete([(64511, 25..29)]); return 24; }
else if (64511, 25) ~ bgp_community then { bgp_community.delete([(64511, 26..29)]); return 25; }
else if (64511, 26) ~ bgp_community then { bgp_community.delete([(64511, 27..29)]); return 26; }
else if (64511, 27) ~ bgp_community then { bgp_community.delete([(64511, 28..29)]); return 27; }
else if (64511, 28) ~ bgp_community then { bgp_community.delete([(64511, 29..29)]); return 28; }
else return 29;
}
function update_crypto(int link_crypto) {
bgp_community.add((64511, link_crypto));
if (64511, 31) ~ bgp_community then { bgp_community.delete([(64511, 32..34)]); return 31; }
else if (64511, 32) ~ bgp_community then { bgp_community.delete([(64511, 33..34)]); return 32; }
else if (64511, 33) ~ bgp_community then { bgp_community.delete([(64511, 34..34)]); return 33; }
else return 34;
}
function update_flags(int link_latency; int link_bandwidth; int link_crypto)
int dn42_latency;
int dn42_bandwidth;
int dn42_crypto;
{
dn42_latency = update_latency(link_latency);
dn42_bandwidth = update_bandwidth(link_bandwidth) - 20;
dn42_crypto = update_crypto(link_crypto) - 30;
# replace 4 with your calculated bandwidth value
if dn42_bandwidth > 4 then dn42_bandwidth = 4;
return true;
}
# Combines filter from local4.conf/local6.conf and filter4.conf/filter6.conf,
# which means, these must included before this file
function dn42_import_filter(int link_latency; int link_bandwidth; int link_crypto) {
if is_valid_network() && !is_self_net() then {
update_flags(link_latency, link_bandwidth, link_crypto);
accept;
}
reject;
}
function dn42_export_filter(int link_latency; int link_bandwith; int link_crypto) {
if is_valid_network() then {
if source = RTS_STATIC then bgp_community.add((64511, DN42_REGION));
update_flags(link_latency, link_bandwith, link_crypto);
accept;
}
reject;
}

View file

@ -2,6 +2,7 @@ router id 172.20.170.192;
define OWNAS = 4242423934; define OWNAS = 4242423934;
define OWNIP = 172.20.170.192; define OWNIP = 172.20.170.192;
define DN42_REGION = 41;
function is_self_net() { function is_self_net() {
return net ~ [172.20.170.192/27+]; return net ~ [172.20.170.192/27+];

View file

@ -2,6 +2,7 @@ router id 172.20.170.192;
define OWNAS = 4242423934; define OWNAS = 4242423934;
define OWNIP = fd62:77fb:94bf::; define OWNIP = fd62:77fb:94bf::;
define DN42_REGION = 41;
function is_self_net() { function is_self_net() {
return net ~ [fd62:77fb:94bf::/48+]; return net ~ [fd62:77fb:94bf::/48+];

5
peers4/B_dn42_Yamakaja Normal file
View file

@ -0,0 +1,5 @@
protocol bgp B_dn42_Yamakaja from dnpeers {
neighbor 172.20.20.64 as 4242421191;
import where dn42_import_filter(2,24,34);
export where dn42_export_filter(2,24,34);
};

View file

@ -1,3 +1,3 @@
protocol bgp filip from dnpeers { protocol bgp B_dn42_filip from dnpeers {
neighbor 172.20.178.65 as 4242421404; neighbor 172.20.178.65 as 4242421404;
}; };

View file

@ -1,3 +0,0 @@
protocol bgp Yamakaja from dnpeers {
neighbor 172.20.20.64 as 4242421191;
};

View file

@ -1,3 +1,3 @@
protocol bgp Yamakaja from dnpeers { protocol bgp B_dn42_Yamakaja from dnpeers {
neighbor fe80::1191 % 'wg-bgp-Yamakaja' as 4242421191; neighbor fe80::1191 % 'wg-bgp-Yamakaja' as 4242421191;
}; };

View file

@ -1,3 +1,3 @@
protocol bgp filip from dnpeers { protocol bgp B_dn42_filip from dnpeers {
neighbor fe80::feec:daff:fe46:d60e % 'wg-bgp-filip' as 4242421404; neighbor fe80::feec:daff:fe46:d60e % 'wg-bgp-filip' as 4242421404;
}; };