From 608f69e8c97e77049ba0d7191dd108207ec09f44 Mon Sep 17 00:00:00 2001 From: Aldo Ortega Date: Fri, 16 Sep 2022 15:01:56 -0400 Subject: [PATCH 1/2] Dropped OpenFlow v0x01 support - Removed `0x01` switch from helpers.py - Modified `main.py` so it return None for 0x01 - Modified `test_main.py` accordingly --- main.py | 27 +++++++-------------------- tests/helpers.py | 13 ++----------- tests/unit/test_main.py | 38 ++++++-------------------------------- 3 files changed, 15 insertions(+), 63 deletions(-) diff --git a/main.py b/main.py index 9aa4b00..3791b4b 100644 --- a/main.py +++ b/main.py @@ -4,11 +4,8 @@ import requests from flask import jsonify, request -from pyof.foundation.basic_types import DPID, UBInt16, UBInt32 +from pyof.foundation.basic_types import DPID, UBInt32 from pyof.foundation.network_types import LLDP, VLAN, Ethernet, EtherType -from pyof.v0x01.common.action import ActionOutput as AO10 -from pyof.v0x01.common.phy_port import Port as Port10 -from pyof.v0x01.controller2switch.packet_out import PacketOut as PO10 from pyof.v0x04.common.action import ActionOutput as AO13 from pyof.v0x04.common.port import PortNo as Port13 from pyof.v0x04.controller2switch.packet_out import PacketOut as PO13 @@ -61,10 +58,7 @@ def execute(self): if not switch.is_connected(): continue - if of_version == 0x01: - port_type = UBInt16 - local_port = Port10.OFPP_LOCAL - elif of_version == 0x04: + if of_version == 0x04: port_type = UBInt32 local_port = Port13.OFPP_LOCAL else: @@ -275,7 +269,7 @@ def _retry_if_status_code(response, endpoint, data, status_codes, f" data: {data}") _retry_if_status_code(res, endpoint, data, [424, 500]) - @alisten_to('kytos/of_core.v0x0[14].messages.in.ofpt_packet_in') + @alisten_to('kytos/of_core.v0x04.messages.in.ofpt_packet_in') async def on_ofpt_packet_in(self, event): """Dispatch two KytosEvents to notify identified NNI interfaces. @@ -301,14 +295,13 @@ async def on_ofpt_packet_in(self, event): switch_b = None port_b = None - # in_port is currently a UBInt16 in v0x01 and an Int in v0x04. + # in_port is currently an Int in v0x04. if isinstance(port_a, int): port_a = UBInt32(port_a) try: switch_b = self.controller.get_switch_by_dpid(dpid.value) - of_version = switch_b.connection.protocol.version - port_type = UBInt16 if of_version == 0x01 else UBInt32 + port_type = UBInt32 port_b = self._unpack_non_empty(port_type, lldp.port_id.sub_value) except AttributeError: @@ -365,10 +358,7 @@ def _build_lldp_packet_out(version, port_number, data): None if the OpenFlow version is not supported. """ - if version == 0x01: - action_output_class = AO10 - packet_out_class = PO10 - elif version == 0x04: + if version == 0x04: action_output_class = AO13 packet_out_class = PO13 else: @@ -408,10 +398,7 @@ def _build_lldp_flow(self, version, cookie, match['dl_vlan'] = self.vlan_id flow['match'] = match - if version == 0x01: - flow['actions'] = [{'action_type': 'output', - 'port': Port10.OFPP_CONTROLLER}] - elif version == 0x04: + if version == 0x04: flow['actions'] = [{'action_type': 'output', 'port': Port13.OFPP_CONTROLLER}] else: diff --git a/tests/helpers.py b/tests/helpers.py index 2626d86..89b6725 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -9,7 +9,6 @@ def get_topology_mock(): """Create a default topology.""" switch_a = get_switch_mock("00:00:00:00:00:00:00:01", 0x04) switch_b = get_switch_mock("00:00:00:00:00:00:00:02", 0x04) - switch_c = get_switch_mock("00:00:00:00:00:00:00:03", 0x01) interface_a1 = get_interface_mock("s1-eth1", 1, switch_a) interface_a2 = get_interface_mock("s1-eth2", 2, switch_a) @@ -17,23 +16,15 @@ def get_topology_mock(): interface_b1 = get_interface_mock("s2-eth1", 1, switch_b) interface_b2 = get_interface_mock("s2-eth2", 2, switch_b) - interface_c1 = get_interface_mock("s3-eth1", 1, switch_c) - interface_c2 = get_interface_mock("s3-eth2", 2, switch_c) - switch_a.interfaces = {interface_a1.id: interface_a1, interface_a2.id: interface_a2} switch_b.interfaces = {interface_b1.id: interface_b1, interface_b2.id: interface_b2} - switch_c.interfaces = {interface_c1.id: interface_c1, - interface_c2.id: interface_c2} link_1 = get_link_mock(interface_a1, interface_b1) - link_2 = get_link_mock(interface_a2, interface_c1) - link_3 = get_link_mock(interface_b2, interface_c2) topology = MagicMock() - topology.links = {"1": link_1, "2": link_2, "3": link_3} + topology.links = {"1": link_1} topology.switches = {switch_a.dpid: switch_a, - switch_b.dpid: switch_b, - switch_c.dpid: switch_c} + switch_b.dpid: switch_b} return topology diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index d6880a8..6b0d0be 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -159,33 +159,21 @@ def test_handle_lldp_flows_retries(self, mock_post, _): self.assertTrue(mock_post.call_count, 3) @patch('napps.kytos.of_lldp.main.PO13') - @patch('napps.kytos.of_lldp.main.PO10') @patch('napps.kytos.of_lldp.main.AO13') - @patch('napps.kytos.of_lldp.main.AO10') def test_build_lldp_packet_out(self, *args): """Test _build_lldp_packet_out method.""" - (mock_ao10, mock_ao13, mock_po10, mock_po13) = args + (mock_ao13, mock_po13) = args - ao10 = MagicMock() ao13 = MagicMock() - po10 = MagicMock() - po10.actions = [] po13 = MagicMock() po13.actions = [] - mock_ao10.return_value = ao10 mock_ao13.return_value = ao13 - mock_po10.return_value = po10 mock_po13.return_value = po13 - packet_out10 = self.napp._build_lldp_packet_out(0x01, 1, 'data1') packet_out13 = self.napp._build_lldp_packet_out(0x04, 2, 'data2') packet_out14 = self.napp._build_lldp_packet_out(0x05, 3, 'data3') - self.assertEqual(packet_out10.data, 'data1') - self.assertEqual(packet_out10.actions, [ao10]) - self.assertEqual(packet_out10.actions[0].port, 1) - self.assertEqual(packet_out13.data, 'data2') self.assertEqual(packet_out13.actions, [ao13]) self.assertEqual(packet_out13.actions[0].port, 2) @@ -195,13 +183,11 @@ def test_build_lldp_packet_out(self, *args): @patch('napps.kytos.of_lldp.main.settings') @patch('napps.kytos.of_lldp.main.EtherType') @patch('napps.kytos.of_lldp.main.Port13') - @patch('napps.kytos.of_lldp.main.Port10') def test_build_lldp_flow(self, *args): """Test _build_lldp_flow method.""" - (mock_v0x01_port, mock_v0x04_port, mock_ethertype, + (mock_v0x04_port, mock_ethertype, mock_settings) = args self.napp.vlan_id = None - mock_v0x01_port.OFPP_CONTROLLER = 123 mock_v0x04_port.OFPP_CONTROLLER = 1234 mock_ethertype.LLDP = 10 @@ -217,23 +203,17 @@ def test_build_lldp_flow(self, *args): match['dl_type'] = 10 flow['match'] = match - expected_flow_v0x01 = flow.copy() expected_flow_v0x04 = flow.copy() - expected_flow_v0x01['cookie'] = get_cookie(dpid) - expected_flow_v0x01['cookie_mask'] = 0xffffffffffffffff expected_flow_v0x04['cookie'] = get_cookie(dpid) expected_flow_v0x04['cookie_mask'] = 0xffffffffffffffff - expected_flow_v0x01['actions'] = [{'action_type': 'output', - 'port': 123}] - expected_flow_v0x04['actions'] = [{'action_type': 'output', 'port': 1234}] flow_mod10 = self.napp._build_lldp_flow(0x01, get_cookie(dpid)) flow_mod13 = self.napp._build_lldp_flow(0x04, get_cookie(dpid)) - self.assertDictEqual(flow_mod10, expected_flow_v0x01) + self.assertIsNone(flow_mod10) self.assertDictEqual(flow_mod13, expected_flow_v0x04) def test_unpack_non_empty(self): @@ -306,9 +286,7 @@ def test_get_lldp_interfaces(self): expected_interfaces = ['00:00:00:00:00:00:00:01:1', '00:00:00:00:00:00:00:01:2', '00:00:00:00:00:00:00:02:1', - '00:00:00:00:00:00:00:02:2', - '00:00:00:00:00:00:00:03:1', - '00:00:00:00:00:00:00:03:2'] + '00:00:00:00:00:00:00:02:2'] self.assertEqual(lldp_interfaces, expected_interfaces) @@ -321,9 +299,7 @@ def test_rest_get_lldp_interfaces(self): expected_data = {"interfaces": ['00:00:00:00:00:00:00:01:1', '00:00:00:00:00:00:00:01:2', '00:00:00:00:00:00:00:02:1', - '00:00:00:00:00:00:00:02:2', - '00:00:00:00:00:00:00:03:1', - '00:00:00:00:00:00:00:03:2']} + '00:00:00:00:00:00:00:02:2']} self.assertEqual(response.json, expected_data) self.assertEqual(response.status_code, 200) @@ -332,9 +308,7 @@ def test_enable_disable_lldp_200(self): data = {"interfaces": ['00:00:00:00:00:00:00:01:1', '00:00:00:00:00:00:00:01:2', '00:00:00:00:00:00:00:02:1', - '00:00:00:00:00:00:00:02:2', - '00:00:00:00:00:00:00:03:1', - '00:00:00:00:00:00:00:03:2']} + '00:00:00:00:00:00:00:02:2']} api = get_test_client(self.napp.controller, self.napp) self.napp.publish_liveness_status = MagicMock() From 80421b2b36fe410f10a6e1aa62c745c214463ebb Mon Sep 17 00:00:00 2001 From: Aldo Ortega Date: Wed, 21 Sep 2022 11:42:11 -0400 Subject: [PATCH 2/2] Updated CHANGELOG.rst - Dropped support in README.rst --- CHANGELOG.rst | 1 + README.rst | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 37cb6b5..064b4d3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,6 +16,7 @@ Deprecated Removed ======= +- Removed support for OpenFlow 1.0 Fixed ===== diff --git a/README.rst b/README.rst index bd33263..686e114 100644 --- a/README.rst +++ b/README.rst @@ -95,7 +95,7 @@ Events Subscribed ---------- -- ``kytos/of_core.v0x0[14].messages.in.ofpt_packet_in`` +- ``kytos/of_core.v0x04.messages.in.ofpt_packet_in`` - ``kytos/topology.switch.enabled`` - ``kytos/topology.switch.disabled`` - ``kytos/topology.topology_loaded``