Skip to content

Commit

Permalink
fix: Change client vlan on first switch
Browse files Browse the repository at this point in the history
Client VLAN was being removed in the first switch for issues
with Noviflow. Now it is changed to the final VLAN,
adding again Q-in-Q.
Fix kytos#154
  • Loading branch information
ajoaoff committed Mar 15, 2022
1 parent 9f429a6 commit d8408d0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 46 deletions.
26 changes: 17 additions & 9 deletions models/evc.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ def _install_uni_flows(self, path=None):
path[0].endpoint_a,
in_vlan_a,
out_vlan_a,
in_vlan_z,
queue_id=self.queue_id,
)
flows_a.append(push_flow)
Expand All @@ -653,7 +654,6 @@ def _install_uni_flows(self, path=None):
pop_flow = self._prepare_pop_flow(
path[0].endpoint_a,
self.uni_a.interface,
in_vlan_a,
out_vlan_a,
queue_id=self.queue_id,
)
Expand All @@ -670,6 +670,7 @@ def _install_uni_flows(self, path=None):
path[-1].endpoint_b,
in_vlan_z,
out_vlan_z,
in_vlan_a,
queue_id=self.queue_id,
)
flows_z.append(push_flow)
Expand All @@ -678,7 +679,6 @@ def _install_uni_flows(self, path=None):
pop_flow = self._prepare_pop_flow(
path[-1].endpoint_b,
self.uni_z.interface,
in_vlan_z,
out_vlan_z,
queue_id=self.queue_id,
)
Expand Down Expand Up @@ -755,13 +755,14 @@ def _prepare_push_flow(self, *args, queue_id=None):
out_interface(str): Interface output.
in_vlan(str): Vlan input.
out_vlan(str): Vlan output.
new_in_vlan(str): Interface input.
Return:
dict: An python dictionary representing a FlowMod
"""
# assign all arguments
in_interface, out_interface, in_vlan, out_vlan = args
in_interface, out_interface, in_vlan, out_vlan , new_in_vlan = args

flow_mod = self._prepare_flow_mod(
in_interface, out_interface, queue_id
Expand All @@ -777,24 +778,31 @@ def _prepare_push_flow(self, *args, queue_id=None):
if in_vlan:
# if in_vlan is set, it must be included in the match
flow_mod["match"]["dl_vlan"] = in_vlan
if new_in_vlan:
# new_in_vlan is set, so an action to set it is necessary
new_action = {"action_type": "set_vlan", "vlan_id": new_in_vlan}
flow_mod["actions"].insert(0, new_action)
if not in_vlan:
# new_in_vlan is set, but in_vlan is not, so there was no
# vlan set; then it is set now
new_action = {"action_type": "push_vlan", "tag_type": "c"}
flow_mod["actions"].insert(0, new_action)
elif in_vlan:
# in_vlan is set, but new_in_vlan is not, so the existing vlan
# must be removed
new_action = {"action_type": "pop_vlan"}
flow_mod["actions"].insert(0, new_action)
return flow_mod

def _prepare_pop_flow(
self, in_interface, out_interface, in_vlan, out_vlan, queue_id=None
self, in_interface, out_interface, out_vlan, queue_id=None
):
# pylint: disable=too-many-arguments
"""Prepare pop flow."""
flow_mod = self._prepare_flow_mod(
in_interface, out_interface, queue_id
)
flow_mod["match"]["dl_vlan"] = out_vlan
if in_vlan:
new_action = {"action_type": "set_vlan", "vlan_id": in_vlan}
flow_mod["actions"].insert(0, new_action)
new_action = {"action_type": "push_vlan", "tag_type": "c"}
flow_mod["actions"].insert(0, new_action)
new_action = {"action_type": "pop_vlan"}
flow_mod["actions"].insert(0, new_action)
return flow_mod
Expand Down
83 changes: 46 additions & 37 deletions tests/unit/models/test_evc_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_prepare_pop_flow(self):

# pylint: disable=protected-access
flow_mod = evc._prepare_pop_flow(
interface_a, interface_z, None, in_vlan
interface_a, interface_z, in_vlan
)

expected_flow_mod = {
Expand All @@ -197,30 +197,43 @@ def test_prepare_push_flow(self):
out_vlan_a = 20

for in_vlan_a in (10, None):
with self.subTest(in_vlan_a=in_vlan_a):
# pylint: disable=protected-access
flow_mod = evc._prepare_push_flow(
interface_a, interface_z, in_vlan_a, out_vlan_a
)

expected_flow_mod = {
"match": {"in_port": interface_a.port_number},
"cookie": evc.get_cookie(),
"actions": [
{"action_type": "push_vlan", "tag_type": "s"},
{"action_type": "set_vlan", "vlan_id": out_vlan_a},
{
"action_type": "output",
"port": interface_z.port_number,
},
],
}
if in_vlan_a:
expected_flow_mod["match"]["dl_vlan"] = in_vlan_a
expected_flow_mod["actions"].insert(
0, {"action_type": "pop_vlan"}
)
self.assertEqual(expected_flow_mod, flow_mod)
for in_vlan_z in (3, None):
with self.subTest(in_vlan_a=in_vlan_a, in_vlan_z=in_vlan_z):
# pylint: disable=protected-access
flow_mod = evc._prepare_push_flow(interface_a, interface_z,
in_vlan_a, out_vlan_a,
in_vlan_z)

expected_flow_mod = {
'match': {'in_port': interface_a.port_number},
'cookie': evc.get_cookie(),
'actions': [
{'action_type': 'push_vlan', 'tag_type': 's'},
{'action_type': 'set_vlan', 'vlan_id': out_vlan_a},
{
'action_type': 'output',
'port': interface_z.port_number
}
]
}
if in_vlan_a and in_vlan_z:
expected_flow_mod['match']['dl_vlan'] = in_vlan_a
expected_flow_mod['actions'].insert(0, {
'action_type': 'set_vlan', 'vlan_id': in_vlan_z
})
elif in_vlan_a:
expected_flow_mod['match']['dl_vlan'] = in_vlan_a
expected_flow_mod['actions'].insert(0, {
'action_type': 'pop_vlan'
})
elif in_vlan_z:
expected_flow_mod['actions'].insert(0, {
'action_type': 'set_vlan', 'vlan_id': in_vlan_z
})
expected_flow_mod['actions'].insert(0, {
'action_type': 'push_vlan', 'tag_type': 'c'
})
self.assertEqual(expected_flow_mod, flow_mod)

@staticmethod
@patch("napps.kytos.mef_eline.models.evc.EVC._send_flow_mods")
Expand Down Expand Up @@ -273,7 +286,10 @@ def test_install_uni_flows(send_flow_mods_mock):
},
"cookie": evc.get_cookie(),
"actions": [
{"action_type": "pop_vlan"},
{
"action_type": "set_vlan",
"vlan_id": uni_z.user_tag.value
},
{"action_type": "push_vlan", "tag_type": "s"},
{
"action_type": "set_vlan",
Expand All @@ -297,11 +313,6 @@ def test_install_uni_flows(send_flow_mods_mock):
"cookie": evc.get_cookie(),
"actions": [
{"action_type": "pop_vlan"},
{"action_type": "push_vlan", "tag_type": "c"},
{
"action_type": "set_vlan",
"vlan_id": uni_a.user_tag.value,
},
{
"action_type": "output",
"port": uni_a.interface.port_number,
Expand All @@ -322,7 +333,10 @@ def test_install_uni_flows(send_flow_mods_mock):
},
"cookie": evc.get_cookie(),
"actions": [
{"action_type": "pop_vlan"},
{
"action_type": "set_vlan",
"vlan_id": uni_a.user_tag.value
},
{"action_type": "push_vlan", "tag_type": "s"},
{
"action_type": "set_vlan",
Expand All @@ -346,11 +360,6 @@ def test_install_uni_flows(send_flow_mods_mock):
"cookie": evc.get_cookie(),
"actions": [
{"action_type": "pop_vlan"},
{"action_type": "push_vlan", "tag_type": "c"},
{
"action_type": "set_vlan",
"vlan_id": uni_z.user_tag.value,
},
{
"action_type": "output",
"port": uni_z.interface.port_number,
Expand Down

0 comments on commit d8408d0

Please sign in to comment.