Skip to content

Commit

Permalink
Merge pull request #199 from kytos-ng/hotfix/flow_dict_size
Browse files Browse the repository at this point in the history
hotfix 2024.1.1: handled flow xid key error on barrier reply and logged error
  • Loading branch information
viniarck authored Sep 3, 2024
2 parents 13bd947 + 75e8535 commit 3e8b02c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ file.
[UNRELEASED] - Under development
********************************

[2024.1.1] - 2024-08-30
***********************

Changed
=======

- Increased ``settings.FLOWS_DICT_MAX_SIZE`` to 70k

Fixed
=====

- Logged flow xid key error on barrier reply as an error

[2024.1.0] - 2024-07-23
***********************

Expand Down
2 changes: 1 addition & 1 deletion kytos.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"username": "kytos",
"name": "flow_manager",
"description": "Manage switches' flows through a REST API.",
"version": "2024.1.0",
"version": "2024.1.1",
"napp_dependencies": ["kytos/of_core"],
"license": "MIT",
"url": "https://github.com/kytos/flow_manager.git",
Expand Down
9 changes: 8 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,14 @@ def _on_ofpt_barrier_reply(self, event):
flows = []
with self._flow_mods_sent_lock:
for flow_xid in flow_xids:
flow, cmd, _ = self._flow_mods_sent[flow_xid]
try:
flow, cmd, _ = self._flow_mods_sent[flow_xid]
except KeyError:
length = len(self._flow_mods_sent)
log.error(
f"Failled to pop flow_xid {flow_xid}, dict length: {length}"
)
continue
if (
cmd != "add"
or flow_xid not in self._flow_mods_sent
Expand Down
2 changes: 1 addition & 1 deletion settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Settings from flow_manager NApp."""

FLOWS_DICT_MAX_SIZE = 10000
FLOWS_DICT_MAX_SIZE = 70000
ENABLE_CONSISTENCY_CHECK = True
ENABLE_BARRIER_REQUEST = True

Expand Down
36 changes: 36 additions & 0 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,42 @@ def test_on_ofpt_barrier_reply(self, mock_publish):
self.napp._on_ofpt_barrier_reply(event)
mock_publish.assert_called()

@patch("napps.kytos.flow_manager.main.log")
@patch("napps.kytos.flow_manager.main.Main._publish_installed_flow")
def test_on_ofpt_barrier_reply_error_case_1(self, mock_publish, mock_log):
"""Test on_ofpt barrier reply error case 1."""
self.napp._on_ofpt_barrier_reply(MagicMock())
mock_log.error.assert_called()
mock_publish.assert_not_called()

@patch("napps.kytos.flow_manager.main.log")
@patch("napps.kytos.flow_manager.main.Main._publish_installed_flow")
def test_on_ofpt_barrier_reply_error_case_2(self, mock_publish, mock_log):
"""Test on_ofpt barrier reply error case 2."""
dpid = "00:00:00:00:00:00:00:01"
switch = get_switch_mock(dpid, 0x04)
switch.id = dpid
flow_mods_xids = [123]
flow_mods = [MagicMock(header=MagicMock(xid=xid)) for xid in flow_mods_xids]
self.napp._send_barrier_request(switch, flow_mods)
assert (
list(self.napp._pending_barrier_reply[switch.id].values())[-1]
== flow_mods_xids
)
barrier_xid = list(self.napp._pending_barrier_reply[switch.id].keys())[-1]
event = MagicMock()
event.message.header.xid = barrier_xid
assert barrier_xid
assert (
self.napp._pending_barrier_reply[switch.id][barrier_xid] == flow_mods_xids
)
event.source.switch = switch
assert not self.napp._flow_mods_sent
self.napp._on_ofpt_barrier_reply(event)
assert not self.napp._flow_mods_sent
mock_log.error.assert_called()
mock_publish.assert_not_called()

@patch("napps.kytos.flow_manager.main.Main._send_napp_event")
def test_on_openflow_connection_error(self, mock_send_napp_event):
"""Test on_openflow_connection_error."""
Expand Down

0 comments on commit 3e8b02c

Please sign in to comment.