sapcc / asr1k-neutron-l3

Cisco ASR 1000 Neutron L3 driver
Apache License 2.0
4 stars 1 forks source link

Reduce likelyhood to reuse BDI ids / RDs to reduce risk of race condition #36

Closed swagner-de closed 4 years ago

swagner-de commented 4 years ago

In order to avoid a race condition in the ASR firmware, we reduce the likelyhood of BDI ids beeing reused soon after they have been deleted. We do that by randomly picking a seconddot1q id (which is later set as BDI id) from all free seconddot1q ids. Hence, BDI id reuse probability is 1/len(free_seconddot1qs). We employ the same principal for VRF Route Distinguishers as a VRF RD might still be bound to a to-be-deleted VRF when it was assigned to a to-be-created VRF. The configuration of the new VRF then triggers the deletion of the old VRF immediatly followed by the new VRF's creation. This is expected to cause a race condition in the ASR firmware. In order to avoid this behaviour we randomize RD values to avoid a create-after-delete situation.

The former implementations went by numeric order and just selected the next available id thus having a much larger risk of reuse.

In this PR we also move the fetch of the available seconddot1qs into the database transaction, removing the possibilty of another thread then executing a dirty read.**