kytos-ng / flow_manager

Kytos NApp that manages OpenFlow 1.3 entries
https://kytos-ng.github.io/api/flow_manager.html
MIT License
0 stars 7 forks source link

Flow top level `instructions` and `actions` (historic OF1.0 format) should be mutually exclusive #159

Closed viniarck closed 1 year ago

viniarck commented 1 year ago

Historically, most NApps have been using actions, which on OF1.3 context, it'll be converted as OF FlowMod instruction when being serialized, but we've been also supporting actions to avoid breaking APIs and having to change NApps that use this format. There's no issues or harm to still use actions in the old format, and it'll be maintained, but it should be mutually exclusive with instructions, otherwise it can result in OFPT_ERROR:

Example of invalid payload:

{
    "force": false,
    "flows": [
        {
            "priority": 38000,
            "match": {
                "in_port": 1,
                "dl_vlan": 1004
            },
            "instructions": [
                {
                    "instruction_type": "apply_actions",
                    "actions": [
                        {
                            "action_type": "output",
                            "port": 10
                        }
                    ]
                }
            ],
            "actions": [
                {
                    "action_type": "output",
                    "port": 11
                }
            ]
        }
    ]
}

20230726_111257

20230726_111310

Alopalao commented 1 year ago

I think the problem lies in of_core, specifically here. The final dictionary of instructions ends up like:

            "instructions": [
                {   
                    "instruction_type": "apply_actions", 
                    "actions": [{"port": 11, "action_type": "output"}]
                },
                {
                    "instruction_type": "apply_actions", 
                    "actions": [{"port": 10, "action_type": "output"}]
                }
            ]

I see other examples that multiple actions should be:

            "instructions": [
                {
                    "instruction_type": "apply_actions",
                    "actions": [
                        {"action_type": "output", "port": 10},
                        {"action_type": "output", "port": 1}
                    ]
                }
            ]

Do we want to support instructions with multiple apply_actions? If not, I see that actions list should be ordered, which field from the request should be first, actions should be added to existent instructions last?

viniarck commented 1 year ago

Do we want to support instructions with multiple apply_actions?

That's a good point, based on the spec and OvS man page, for each instruction, it should not repeat the "instruction_type":

Every version of OpenFlow includes actions. OpenFlow 1.1 introduced the higher-level, related concept of instructions. In OpenFlow 1.1 and later, actions within a flow are always encapsulated within an instruction. Each flow has at most one instruction of each kind, which are executed in the following fixed order defined in the OpenFlow specification:

      1. Meter

      2. Apply-Actions

      3. Clear-Actions

      4. Write-Actions

      5. Write-Metadata

      6. Stat-Trigger (not supported by Open vSwitch)

      7. Goto-Table

and probably for each action, we probably shouldn't allow repeated action_type either, but I confirmed in practice, that at least with OvS it didn't crash though, here's an example with multiple output action_type:

 cookie=0x0, duration=1024.068s, table=0, n_packets=0, n_bytes=0, send_flow_rem priority=38000,in_port="s1-eth1",dl_vlan=1004 actions=output:10,output:11

so for the action_type, let's leave it for another iteration and issue, just so there are cases like this one above that it still be great to still keep paring this flow without crashing or discarding it (which is important for consistency check when also detecting alien flows).

In summary

Let me know if you agree and share the same understanding @Alopalao.

cc'ing also @italovalcy in case he wants to confirm or point out any other requirement.

Alopalao commented 1 year ago

Makes sense to me, I'm on it.