kytos-ng / mef_eline

Kytos NApp to create and manage point-to-point L2 circuits
https://kytos-ng.github.io/api/mef_eline.html
MIT License
0 stars 9 forks source link

assessment to avoid unnecessary vlan if no vlan translation is needed #389

Closed viniarck closed 1 year ago

viniarck commented 1 year ago

This is for a development assessment to avoid unnecessary vlan if no vlan translation is needed that Jeronimo and Italo have asked for when they were debugging a perf issue when stress testing network traffic for SC23.

viniarck commented 1 year ago

The lowest risk and easiest way to support this would be to augment this conditional on _prepare_push_flow:

diff --git a/models/evc.py b/models/evc.py
index c9e6300..88a2705 100644
--- a/models/evc.py
+++ b/models/evc.py
@@ -1209,7 +1209,7 @@ class EVCDeploy(EVCBase):
             # if in_vlan is set, it must be included in the match
             flow_mod["match"]["dl_vlan"] = in_vlan

-        if new_c_vlan not in self.special_cases:
+        if new_c_vlan not in self.special_cases and in_vlan != new_c_vlan:
             # new_in_vlan is an integer but zero, action to set is required
             new_action = {"action_type": "set_vlan", "vlan_id": new_c_vlan}
             flow_mod["actions"].insert(0, new_action)

End result

Before

cookie=0xaaa73f765873d841, duration=12.858s, table=0, n_packets=0, n_bytes=0, send_flow_rem priority=20000,in_port="s3-eth1",dl_vlan=101 actions=set_field:4197->vlan_vid,push_vlan:0x88a8,set_field:4097->vlan_vid,output:"s3-eth3"
{
            "flow": {
                "owner": "mef_eline",
                "cookie": 12271464045111059785,
                "match": {
                    "in_port": 1,
                    "dl_vlan": 101
                },
                "actions": [
                    {
                        "action_type": "set_vlan",
                        "vlan_id": 101
                    },
                    {
                        "action_type": "push_vlan",
                        "tag_type": "s"
                    },
                    {
                        "action_type": "set_vlan",
                        "vlan_id": 1
                    },
                    {
                        "action_type": "output",
                        "port": 4
                    }
                ],
                "table_id": 0,
                "table_group": "evpl",
                "priority": 20000,
                "idle_timeout": 0,
                "hard_timeout": 0
            },
            "flow_id": "b586365ad419c3a102e23117751a0400",
            "id": "ae60baf217bc417dfdacfd7278210259",
            "inserted_at": "2023-10-31T18:09:14.836000",
            "state": "installed",
            "switch": "00:00:00:00:00:00:00:01",
            "updated_at": "2023-10-31T18:09:14.846000"
        },

After

cookie=0xaa2125e27a604843, duration=12.487s, table=0, n_packets=0, n_bytes=0, send_flow_rem priority=20000,in_port="s1-eth1",dl_vlan=101 actions=push_vlan:0x88a8,set_field:4097->vlan_vid,output:"s1-eth4"
{
            "flow": {
                "owner": "mef_eline",
                "cookie": 12259121315325167683,
                "match": {
                    "in_port": 1,
                    "dl_vlan": 101
                },
                "actions": [
                    {
                        "action_type": "push_vlan",
                        "tag_type": "s"
                    },
                    {
                        "action_type": "set_vlan",
                        "vlan_id": 1
                    },
                    {
                        "action_type": "output",
                        "port": 4
                    }
                ],
                "table_id": 0,
                "table_group": "evpl",
                "priority": 20000,
                "idle_timeout": 0,
                "hard_timeout": 0
            },
            "flow_id": "b5d395eb05316e97559b2e15987aaf26",
            "id": "9e69461fa99f236c580819f0640bc8e0",
            "inserted_at": "2023-10-31T18:01:40.389000",
            "state": "installed",
            "switch": "00:00:00:00:00:00:00:01",
            "updated_at": "2023-10-31T18:01:40.398000"
        }

I've also confirmed that both sdntrace_cp and sdntrace still traced correctly.

viniarck commented 1 year ago

Trying to not use a s-vlan would be tricker though, even though the code has been partially structured to push a vlan, but it would still further require extra arguments, fixing unit tests and also making sure that when popping it would conflict with other flows, so it's riskier.