Skip to content

Commit

Permalink
Merge pull request #67 from Alopalao/feature/of_v0x01
Browse files Browse the repository at this point in the history
Dropped OpenFlow v0x01 support
  • Loading branch information
viniarck authored Sep 21, 2022
2 parents a509e2c + 80421b2 commit 9938813
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Deprecated

Removed
=======
- Removed support for OpenFlow 1.0

Fixed
=====
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
27 changes: 7 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 2 additions & 11 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,22 @@ 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)

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
38 changes: 6 additions & 32 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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()
Expand Down

0 comments on commit 9938813

Please sign in to comment.