ofagent: Ignore unknown l2pop entry removals

l2pop can send us entry removal without the corresponding addition.
Gracefully ignore it instead of crashing.

Closes-Bug: #1357198
Change-Id: I5a0cc44ba62faf15d6fe3730a9532a3826647820
This commit is contained in:
YAMAMOTO Takashi 2014-08-15 14:20:00 +09:00
parent 71d2f093df
commit 18f2f81951
2 changed files with 23 additions and 1 deletions

View File

@ -120,7 +120,12 @@ class ArpLib(object):
@log.log @log.log
def del_arp_table_entry(self, network, ip): def del_arp_table_entry(self, network, ip):
del self._arp_tbl[network][ip] if network not in self._arp_tbl:
LOG.debug("removal of unknown network %s", network)
return
if self._arp_tbl[network].pop(ip, None) is None:
LOG.debug("removal of unknown ip %s", ip)
return
if not self._arp_tbl[network]: if not self._arp_tbl[network]:
del self._arp_tbl[network] del self._arp_tbl[network]

View File

@ -16,6 +16,7 @@
import collections import collections
import contextlib import contextlib
import copy
import mock import mock
@ -203,6 +204,22 @@ class TestArpLib(OFAAgentTestCase):
self.arplib.del_arp_table_entry(self.nets[0].net, self.nets[0].ip) self.arplib.del_arp_table_entry(self.nets[0].net, self.nets[0].ip)
self.assertEqual(self.arplib._arp_tbl, {}) self.assertEqual(self.arplib._arp_tbl, {})
def test_del_arp_table_entry_unknown_network(self):
self.arplib._arp_tbl = {
100: {"192.0.2.1": "fa:16:3e:e2:37:37"},
}
orig = copy.deepcopy(self.arplib._arp_tbl)
self.arplib.del_arp_table_entry(200, "192.0.2.1")
self.assertEqual(orig, self.arplib._arp_tbl)
def test_del_arp_table_entry_unknown_ip(self):
self.arplib._arp_tbl = {
100: {"192.0.2.1": "fa:16:3e:e2:37:37"},
}
orig = copy.deepcopy(self.arplib._arp_tbl)
self.arplib.del_arp_table_entry(100, "192.0.2.9")
self.assertEqual(orig, self.arplib._arp_tbl)
def test_del_arp_table_entry_multiple_net(self): def test_del_arp_table_entry_multiple_net(self):
self.arplib._arp_tbl = { self.arplib._arp_tbl = {
self.nets[0].net: {self.nets[0].ip: self.nets[0].mac}, self.nets[0].net: {self.nets[0].ip: self.nets[0].mac},