Skip to content

Commit

Permalink
prevent re-announcement of identical routes
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-mangin committed Aug 30, 2013
1 parent 344f03b commit 379cf91
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Version explained:

Version 3.2.6
* Fix: bug in collision detection
* Fix: prevent re-announcement of identical routes

Version 3.2.5
* Improvement: FlowSpec decoding (ExaBGP can decode incoming FlowSpec)
Expand Down
36 changes: 27 additions & 9 deletions lib/exabgp/rib/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def insert_announced (self,change,force=False):
dict_nlri = self._modify_nlri
dict_attr = self._cache_attribute

# Removing a route befone we had time to announe it ?
# removing a route befone we had time to announe it ?
if change_nlri_index in dict_nlri:
old_attr_index = dict_nlri[change_nlri_index].attributes.index()
# pop removes the entry
Expand All @@ -111,11 +111,11 @@ def insert_announced (self,change,force=False):
del dict_sorted[old_attr_index][change_nlri_index]
if not dict_sorted[old_attr_index]:
del dict_sorted[old_attr_index]
# Route removed before announcement, all goo
# route removed before announcement, all goo
if old_change.nlri.action == OUT.announce and change.nlri.action == OUT.withdraw:
return

# Add the route to the list to be announced
# add the route to the list to be announced
dict_sorted.setdefault(change_attr_index,{})[change_nlri_index] = change
dict_nlri[change_nlri_index] = change
if change_attr_index not in dict_attr:
Expand All @@ -127,20 +127,38 @@ def updates (self,grouped):
dict_nlri = self._modify_nlri
dict_attr = self._cache_attribute

for attr_index,dict_new_nlri in list(dict_sorted.iteritems()):
if not dict_new_nlri:
for attr_index,full_dict_change in list(dict_sorted.iteritems()):
if self.cache:
dict_change = {}
for nlri_index,change in full_dict_change.iteritems():
family = change.nlri.family()
announced = self._announced.get(family,{})
if change.nlri.action == OUT.announce:
if nlri_index in announced:
old_change = announced[nlri_index]
# it is a duplicate route
if old_change.attributes.index() == change.attributes.index():
continue
elif change.nlri.action == OUT.withdraw:
if nlri_index not in announced:
continue
dict_change[nlri_index] = change
else:
dict_change = full_dict_change

if not dict_change:
continue

attributes = dict_attr[attr_index].attributes

# we NEED the copy provided by list() here as clear_sent or insert_announced can be called while we iterate
changed = list(dict_new_nlri.itervalues())
changed = list(dict_change.itervalues())

if grouped:
update = Update([dict_nlri[nlri_index].nlri for nlri_index in dict_new_nlri],attributes)
update = Update([dict_nlri[nlri_index].nlri for nlri_index in dict_change],attributes)
for change in changed:
nlri_index = change.nlri.index()
del dict_new_nlri[nlri_index]
del dict_change[nlri_index]
del dict_nlri[nlri_index]
# only yield once we have a consistent state, otherwise it will go wrong
# as we will try to modify things we are using
Expand All @@ -149,7 +167,7 @@ def updates (self,grouped):
updates = [Update([change.nlri,],attributes) for change in changed]
for change in changed:
nlri_index = change.nlri.index()
del dict_new_nlri[nlri_index]
del dict_change[nlri_index]
del dict_nlri[nlri_index]
# only yield once we have a consistent state, otherwise it will go wrong
# as we will try to modify things we are using
Expand Down

0 comments on commit 379cf91

Please sign in to comment.