Have just started working on enforcing BGP communities on my network, however I found that the current latency values will only give the worst part of the paths' latency range, which is actually not that valuable for latency optimization, and many DN42 members tend to rely more on the region values rather than latency.
I am thinking of the following new set of values that reserves (64511,60..69)
and is capable of logging a relatively accurate cumulative latency value together with count of participating nodes and I'd like to see more opinions on this.
Update: I would like to hear more thoughts on tie-breaking issue, and whether we should at least add 1 to the cumu_lat or not (so that routes within same locations all with 0-5 routes will probably go through shorter ones?).
## This is a set of BGP Community values that achieves cumulative latency
## calculations for participating routers, which may enhance the ability of
## optimization for latency.
##
## The utilized range is (64511,60..69), of which:
## I. (64511, 60..65) are bits denoting the cumulative latency value in an
## interval of 5ms. Therefore it is capable of carrying latency value from
## 0ms to 320ms. This binary number is bitwise NOT'd, so that routes with
## no participated node would have the value 315ms, so it would not be
## considered as a very good route with 0~5ms latency.
## II. (64511, 66..69) are bits denoting participated nodes' count, supporting
## up to 15 nodes. This binary number isn't bitwize NOT'd, so routes with
## no participating node will automatically have a count of zero.
function get_cumu_lat()
int cumu_lat;
{
cumu_lat = 315;
if (64511, 65) ~ bgp_community then { cumu_lat = cumu_lat - 160; }
if (64511, 64) ~ bgp_community then { cumu_lat = cumu_lat - 80; }
if (64511, 63) ~ bgp_community then { cumu_lat = cumu_lat - 40; }
if (64511, 62) ~ bgp_community then { cumu_lat = cumu_lat - 20; }
if (64511, 61) ~ bgp_community then { cumu_lat = cumu_lat - 10; }
if (64511, 60) ~ bgp_community then { cumu_lat = cumu_lat - 5; }
return cumu_lat;
}
function set_cumu_lat(int cumu_lat)
int tmp;
{
bgp_community.delete([(64511, 60..65)]);
tmp = cumu_lat / 5;
if(tmp > 63) then return;
if(tmp >= 32) then tmp = tmp - 32;
else bgp_community.add((64511, 65));
if(tmp >= 16) then tmp = tmp - 16;
else bgp_community.add((64511, 64));
if(tmp >= 8) then tmp = tmp - 8;
else bgp_community.add((64511, 63));
if(tmp >= 4) then tmp = tmp - 4;
else bgp_community.add((64511, 62));
if(tmp >= 2) then tmp = tmp - 2;
else bgp_community.add((64511, 61));
if(tmp >= 1) then tmp = tmp - 1;
else bgp_community.add((64511, 60));
}
function get_cumu_cnt()
int cumu_cnt;
{
cumu_cnt = 0;
if (64511, 69) ~ bgp_community then { cumu_lat = cumu_lat + 8; }
if (64511, 68) ~ bgp_community then { cumu_lat = cumu_lat + 4; }
if (64511, 67) ~ bgp_community then { cumu_lat = cumu_lat + 2; }
if (64511, 66) ~ bgp_community then { cumu_lat = cumu_lat + 1; }
return cumu_cnt;
}
function set_cumu_cnt(int cnt)
int tmp;
{
if (cnt > 15) then tmp = 15;
else tmp = cnt;
bgp_community.delete([(64511, 66..69)]);
if (tmp >= 8) then { bgp_community.add((64511, 69)); tmp = tmp - 8; }
if (tmp >= 4) then { bgp_community.add((64511, 68)); tmp = tmp - 4; }
if (tmp >= 2) then { bgp_community.add((64511, 67)); tmp = tmp - 2; }
if (tmp >= 1) then { bgp_community.add((64511, 66)); tmp = tmp - 1; }
}
# link_latency: in millisecs unit
function update_cumu_latency(int link_latency)
int cnt;
int cumu_lat;
{
cumu_lat = get_cumu_lat() + link_latency;
set_cumu_lat(cumu_lat);
cnt = 1 + get_cumu_cnt();
set_cumu_cnt(cnt);
return cumu_lat;
}