Mercurial > routeflapper
changeset 2:bb3f804f13a0
add random unsynchronization to hourly timer, trust prefix only for same origin AS, ignore self adjacency
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 19 May 2008 21:45:45 -0700 |
parents | 47f787af96c1 |
children | 4a81cc2da570 |
files | src/routeconfig.cpp src/routeflapper.cpp |
diffstat | 2 files changed, 40 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/src/routeconfig.cpp Tue May 13 15:46:53 2008 -0700 +++ b/src/routeconfig.cpp Mon May 19 21:45:45 2008 -0700 @@ -66,6 +66,7 @@ uint32_t prefix() const { return prefix_value; }; bool active() const { return announced; }; adjacent aspair(int i) const { return adjacent(path[i], path[i+1]); }; + bool selfpair(int i) const { return (path[1] == path[i+1]); }; bool empty() const { return !announced && origin_history.empty(); }; void update_history(a_set &adj_set); suspicion suspicious(a_history &adj_history, bool debug = false, int prefix_length = 0, uint32_t ip = 0); @@ -167,7 +168,9 @@ void route_prefix::add_route(aspath path_, a_history &adj_history) { suspicion s = suspicious(adj_history); - trusted = announced && (s == suspicious_none); + int oldorig = path.empty() ? 0 : path [path.size() - 1]; + int neworig = path_.empty() ? 0 : path_[path_.size() - 1]; + trusted = announced && (s == suspicious_none) && (oldorig == neworig); announced = true; path = path_; } @@ -226,7 +229,7 @@ } // update current adjacency set for (int k=0; k<n; k++) { - adj_set.insert(aspair(k)); + if (!selfpair(k)) adj_set.insert(aspair(k)); } } @@ -272,6 +275,7 @@ // check as adjacency stability for (int k=0; k<n; k++) { + if (!selfpair(k)) { adjacent aa = aspair(k); a_history::iterator a = adj_history.find(aa); if (a == adj_history.end()) { @@ -296,6 +300,7 @@ return suspicious_adjacency; } } + } return suspicious_none; }
--- a/src/routeflapper.cpp Tue May 13 15:46:53 2008 -0700 +++ b/src/routeflapper.cpp Mon May 19 21:45:45 2008 -0700 @@ -91,17 +91,22 @@ // void* hourly_update(void *arg); void* hourly_update(void *arg) { + while (loader_run) { + int ran = (rand() % 600) - 300; // random(-5min,+5min) + int hour = 3600 - 60 + ran; // 59 minutes +- random up to 5 minutes. + int period = (hour + 10) / 20; // twenty periods ... int count = 0; while (loader_run) { - sleep(180); - if (!loader_run) break; + sleep(period); + if (!loader_run) break; // ... so we only wait about 3 minutes to terminate count++; if (count == 20) { - routing_hourly_update(); + routing_hourly_update(); // roughly an hour count = 0; }; } } +} ////////////////////////////////////////////////