kytos-ng / of_core

Kytos Main OpenFlow Network Application (NApp)
MIT License
0 stars 5 forks source link

bug: `cookie` shouldn't be a factor of `match_id` #136

Closed viniarck closed 1 month ago

viniarck commented 2 months ago

Currently, cookie is being used to hash a value for match_id. But, this isn't correct since we this to uniquetly identify the uniqueness of a match, and as described in the OpenFlow spec:

If the cookie_mask field is non-zero, it is used with the cookie field to restrict flow matching while modifying or deleting flow entries. This field is ignored by OFPFC_ADD messages.

This can also be verified on both OvS and NoviFlow switches, if you try to add flows with same matches but different cookie, the cookie will be overwritten:

❯ sudo ovs-ofctl add-flow s1 in_port=s1-eth1,dl_vlan:3001,cookie=10,actions=output:2 -O OpenFlow13         
❯ sudo ovs-ofctl add-flow s1 in_port=s1-eth1,dl_vlan:3001,cookie=20,actions=output:2 -O OpenFlow13

❯ sudo ovs-ofctl -O OpenFlow13 dump-flows s1
 cookie=0x14, duration=1.605s, table=0, n_packets=0, n_bytes=0, in_port="s1-eth1",dl_vlan=3001 actions=output:"s1-eth2"

But, currently on our DB they won't be overwritten since they'll have a different match_id, consequently with consistency check it'll detect as a missing flow and it'll keep trying to forward it again which would result in the flow cycling as it was observed on this bug here https://github.com/kytos-ng/telemetry_int/issues/106, here's another simplified example of the issue but without using INT flow instructions:

kytos $> 2024-07-03 11:21:23,418 - INFO [kytos.napps.kytos/flow_manager] (thread_pool_sb_4) Consistency check: missing flow on switch 00:00:00:00:00:00:00:01.
2024-07-03 11:21:23,419 - INFO [kytos.napps.kytos/flow_manager] (thread_pool_sb_4) Flow forwarded to switch 00:00:00:00:00:00:00:01 to be installed. Flow: {'flows': [{'table_id': 0, 't
able_group': 'base', 'priority': 20000, 'cookie': 10, 'idle_timeout': 0, 'hard_timeout': 0, 'match': {'in_port': 18}, 'instructions': []}]}
2024-07-03 11:23:23,440 - INFO [kytos.napps.kytos/flow_manager] (thread_pool_sb_11) Consistency check: missing flow on switch 00:00:00:00:00:00:00:01.
2024-07-03 11:23:23,442 - INFO [kytos.napps.kytos/flow_manager] (thread_pool_sb_11) Flow forwarded to switch 00:00:00:00:00:00:00:01 to be installed. Flow: {'flows': [{'table_id': 0, '
table_group': 'base', 'priority': 20000, 'cookie': 20, 'idle_timeout': 0, 'hard_timeout': 0, 'match': {'in_port': 18}, 'instructions': []}]}