Skip to content

Commit

Permalink
Extracted _match_keys in a func
Browse files Browse the repository at this point in the history
  • Loading branch information
viniarck committed Dec 2, 2021
1 parent b8fc4e5 commit 2fe09ea
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions match.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ def _match_cookie(flow_to_install, stored_flow_dict):
return True


def _match_keys(flow_to_install, stored_flow_dict, flow_to_install_keys):
"""Check if certain keys on flow_to_install match on stored_flow_dict."""
for key in flow_to_install_keys:
if key not in stored_flow_dict["match"]:
return False
if flow_to_install["match"][key] != stored_flow_dict["match"].get(key):
return False
return True


def match13_no_strict(flow_to_install, stored_flow_dict):
"""Match a flow that is either exact or more specific (non-strict) (OF1.3).
Expand All @@ -142,12 +152,10 @@ def match13_no_strict(flow_to_install, stored_flow_dict):
if len(flow_to_install["match"]) > len(stored_flow_dict["match"]):
return False

for key, value in flow_to_install.get("match").items():
if key not in stored_flow_dict["match"]:
return False
if value != stored_flow_dict["match"].get(key):
return False

if not _match_keys(
flow_to_install, stored_flow_dict, flow_to_install["match"].keys()
):
return False
return stored_flow_dict


Expand All @@ -171,10 +179,8 @@ def match13_strict(flow_to_install, stored_flow_dict):
if len(flow_to_install["match"]) != len(stored_flow_dict["match"]):
return False

for key, value in flow_to_install.get("match").items():
if key not in stored_flow_dict["match"]:
return False
if value != stored_flow_dict["match"].get(key):
return False

if not _match_keys(
flow_to_install, stored_flow_dict, flow_to_install["match"].keys()
):
return False
return stored_flow_dict

0 comments on commit 2fe09ea

Please sign in to comment.