Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/1558027/?format=api
{ "id": 1558027, "url": "http://patchwork.ozlabs.org/api/patches/1558027/?format=api", "web_url": "http://patchwork.ozlabs.org/project/openvswitch/patch/20211122112256.2011194-10-amorenoz@redhat.com/", "project": { "id": 47, "url": "http://patchwork.ozlabs.org/api/projects/47/?format=api", "name": "Open vSwitch", "link_name": "openvswitch", "list_id": "ovs-dev.openvswitch.org", "list_email": "ovs-dev@openvswitch.org", "web_url": "http://openvswitch.org/", "scm_url": "git@github.com:openvswitch/ovs.git", "webscm_url": "https://github.com/openvswitch/ovs", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20211122112256.2011194-10-amorenoz@redhat.com>", "list_archive_url": null, "date": "2021-11-22T11:22:47", "name": "[ovs-dev,v1,09/18] python: add flow filtering syntax", "commit_ref": null, "pull_url": null, "state": "changes-requested", "archived": false, "hash": "0ee12a4d1b7e44546887fab505ab373b599f7b97", "submitter": { "id": 77477, "url": "http://patchwork.ozlabs.org/api/people/77477/?format=api", "name": "Adrian Moreno", "email": "amorenoz@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/openvswitch/patch/20211122112256.2011194-10-amorenoz@redhat.com/mbox/", "series": [ { "id": 273222, "url": "http://patchwork.ozlabs.org/api/series/273222/?format=api", "web_url": "http://patchwork.ozlabs.org/project/openvswitch/list/?series=273222", "date": "2021-11-22T11:22:39", "name": "python: add flow parsing library", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/273222/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/1558027/comments/", "check": "fail", "checks": "http://patchwork.ozlabs.org/api/patches/1558027/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<ovs-dev-bounces@openvswitch.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "dev@openvswitch.org" ], "Delivered-To": [ "patchwork-incoming@bilbo.ozlabs.org", "ovs-dev@lists.linuxfoundation.org" ], "Authentication-Results": [ "bilbo.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=aH+Ji2aV;\n\tdkim-atps=neutral", "ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org\n (client-ip=140.211.166.138; helo=smtp1.osuosl.org;\n envelope-from=ovs-dev-bounces@openvswitch.org; receiver=<UNKNOWN>)", "smtp3.osuosl.org (amavisd-new);\n dkim=pass (1024-bit key) header.d=redhat.com", "relay.mimecast.com;\n auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com" ], "Received": [ "from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby bilbo.ozlabs.org (Postfix) with ESMTPS id 4HyQ0G0MMPz9sRR\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 22 Nov 2021 22:24:30 +1100 (AEDT)", "from localhost (localhost [127.0.0.1])\n\tby smtp1.osuosl.org (Postfix) with ESMTP id A455681B58;\n\tMon, 22 Nov 2021 11:24:27 +0000 (UTC)", "from smtp1.osuosl.org ([127.0.0.1])\n\tby localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id YmI7ObHcHZBi; Mon, 22 Nov 2021 11:24:23 +0000 (UTC)", "from lists.linuxfoundation.org (lf-lists.osuosl.org\n [IPv6:2605:bc80:3010:104::8cd3:938])\n\tby smtp1.osuosl.org (Postfix) with ESMTPS id CAE9381BB0;\n\tMon, 22 Nov 2021 11:24:21 +0000 (UTC)", "from lf-lists.osuosl.org (localhost [127.0.0.1])\n\tby lists.linuxfoundation.org (Postfix) with ESMTP id 960CCC0037;\n\tMon, 22 Nov 2021 11:24:18 +0000 (UTC)", "from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136])\n by lists.linuxfoundation.org (Postfix) with ESMTP id 4FFDDC0043\n for <dev@openvswitch.org>; Mon, 22 Nov 2021 11:24:17 +0000 (UTC)", "from localhost (localhost [127.0.0.1])\n by smtp3.osuosl.org (Postfix) with ESMTP id 4B303607BB\n for <dev@openvswitch.org>; Mon, 22 Nov 2021 11:23:38 +0000 (UTC)", "from smtp3.osuosl.org ([127.0.0.1])\n by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n with ESMTP id UPiSA5j6xXbD for <dev@openvswitch.org>;\n Mon, 22 Nov 2021 11:23:37 +0000 (UTC)", "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by smtp3.osuosl.org (Postfix) with ESMTPS id 5BEA660A56\n for <dev@openvswitch.org>; Mon, 22 Nov 2021 11:23:37 +0000 (UTC)", "from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com\n [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n us-mta-243-U5VJsr0_OououSm-NVCCdg-1; Mon, 22 Nov 2021 06:23:33 -0500", "from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com\n [10.5.11.13])\n (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n (No client certificate requested)\n by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0939806688\n for <dev@openvswitch.org>; Mon, 22 Nov 2021 11:23:32 +0000 (UTC)", "from amorenoz.users.ipa.redhat.com (unknown [10.2.16.196])\n by smtp.corp.redhat.com (Postfix) with ESMTP id CF53660862;\n Mon, 22 Nov 2021 11:23:31 +0000 (UTC)" ], "X-Virus-Scanned": [ "amavisd-new at osuosl.org", "amavisd-new at osuosl.org" ], "X-Greylist": "domain auto-whitelisted by SQLgrey-1.8.0", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1637580216;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=EPTwZcMJwV/2exYpHYlDsnzI72IeJNC+nn42yg5lx4E=;\n b=aH+Ji2aVXaFYNj17mH+rRl/Gg4ITvg1uP86Tjcv6xDuWgxvpPcyvdaMTHPfeowmTxII5wo\n RxPnvXfE9P+jIPppGnTR4ZDciG9dYQa+njC4sWmdChbkkmHlXh/7fOMLtoL/YCRGptlyPF\n GlV8BSQ+UJCxw85SP8g8TJx9JeOqwcU=", "X-MC-Unique": "U5VJsr0_OououSm-NVCCdg-1", "From": "Adrian Moreno <amorenoz@redhat.com>", "To": "dev@openvswitch.org", "Date": "Mon, 22 Nov 2021 12:22:47 +0100", "Message-Id": "<20211122112256.2011194-10-amorenoz@redhat.com>", "In-Reply-To": "<20211122112256.2011194-1-amorenoz@redhat.com>", "References": "<20211122112256.2011194-1-amorenoz@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.13", "X-Mimecast-Spam-Score": "0", "X-Mimecast-Originator": "redhat.com", "Subject": "[ovs-dev] [PATCH v1 09/18] python: add flow filtering syntax", "X-BeenThere": "ovs-dev@openvswitch.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "<ovs-dev.openvswitch.org>", "List-Unsubscribe": "<https://mail.openvswitch.org/mailman/options/ovs-dev>,\n <mailto:ovs-dev-request@openvswitch.org?subject=unsubscribe>", "List-Archive": "<http://mail.openvswitch.org/pipermail/ovs-dev/>", "List-Post": "<mailto:ovs-dev@openvswitch.org>", "List-Help": "<mailto:ovs-dev-request@openvswitch.org?subject=help>", "List-Subscribe": "<https://mail.openvswitch.org/mailman/listinfo/ovs-dev>,\n <mailto:ovs-dev-request@openvswitch.org?subject=subscribe>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "ovs-dev-bounces@openvswitch.org", "Sender": "\"dev\" <ovs-dev-bounces@openvswitch.org>" }, "content": "Based on pyparsing, create a very simple filtering syntax\n\nIt supports basic logic statements (and, &, or, ||, not, !), numerical\noperations (<, >), equality (=) and masking (~=). The latter is only\nsupported in certain fields (IntMask, EthMask, IPMask).\n\nMasking operation is semantically equivalent to \"includes\",\ntherefore:\n\nip_src ~= 192.168.1.1\n\nmeans that ip_src field is either a host IP address equal to 192.168.1.1\nor an IPMask that includes it (e.g: 192.168.1.1/24)\n\nSigned-off-by: Adrian Moreno <amorenoz@redhat.com>\n---\n python/automake.mk | 3 +-\n python/ovs/flows/filter.py | 225 +++++++++++++++++++++++++++++++++++++\n python/setup.py | 2 +-\n 3 files changed, 228 insertions(+), 2 deletions(-)\n create mode 100644 python/ovs/flows/filter.py", "diff": "diff --git a/python/automake.mk b/python/automake.mk\nindex 8b0713cfc..21aa897f2 100644\n--- a/python/automake.mk\n+++ b/python/automake.mk\n@@ -49,7 +49,8 @@ ovs_pyfiles = \\\n \tpython/ovs/flows/flow.py \\\n \tpython/ovs/flows/ofp.py \\\n \tpython/ovs/flows/ofp_act.py \\\n-\tpython/ovs/flows/odp.py\n+\tpython/ovs/flows/odp.py \\\n+\tpython/ovs/flows/filter.py\n \n # These python files are used at build time but not runtime,\n # so they are not installed.\ndiff --git a/python/ovs/flows/filter.py b/python/ovs/flows/filter.py\nnew file mode 100644\nindex 000000000..2d3555a60\n--- /dev/null\n+++ b/python/ovs/flows/filter.py\n@@ -0,0 +1,225 @@\n+\"\"\" Defines a Flow Filtering syntax\n+\"\"\"\n+import pyparsing as pp\n+import netaddr\n+from functools import reduce\n+from operator import and_, or_\n+\n+from ovs.flows.decoders import (\n+ decode_default,\n+ decode_int,\n+ Decoder,\n+ IPMask,\n+ EthMask,\n+)\n+\n+\n+class EvaluationResult:\n+ \"\"\"An EvaluationResult is the result of an evaluation. It contains the\n+ boolean result and the list of key-values that were evaluated\n+\n+ Note that since boolean operations (and, not, or) are based only on\n+ __bool__ we use bitwise alternatives (&, ||, ~)\n+ \"\"\"\n+\n+ def __init__(self, result, *kv):\n+ self.result = result\n+ self.kv = kv if kv else list()\n+\n+ def __and__(self, other):\n+ \"\"\"Logical and operation\"\"\"\n+ return EvaluationResult(\n+ self.result and other.result, *self.kv, *other.kv\n+ )\n+\n+ def __or__(self, other):\n+ \"\"\"Logical or operation\"\"\"\n+ return EvaluationResult(\n+ self.result or other.result, *self.kv, *other.kv\n+ )\n+\n+ def __invert__(self):\n+ \"\"\"Logical not operation\"\"\"\n+ return EvaluationResult(not self.result, *self.kv)\n+\n+ def __bool__(self):\n+ \"\"\"Boolean operation\"\"\"\n+ return self.result\n+\n+ def __repr__(self):\n+ return \"{} [{}]\".format(self.result, self.kv)\n+\n+\n+class ClauseExpression:\n+ operators = {}\n+ type_decoders = {\n+ int: decode_int,\n+ netaddr.IPAddress: IPMask,\n+ netaddr.EUI: EthMask,\n+ bool: bool,\n+ }\n+\n+ def __init__(self, tokens):\n+ self.field = tokens[0]\n+ self.value = \"\"\n+ self.operator = \"\"\n+\n+ if len(tokens) > 1:\n+ self.operator = tokens[1]\n+ self.value = tokens[2]\n+\n+ def __repr__(self):\n+ return \"{}(field: {}, operator: {}, value: {})\".format(\n+ self.__class__.__name__, self.field, self.operator, self.value\n+ )\n+\n+ def _find_data_in_kv(self, kv_list):\n+ \"\"\"Find a KeyValue for evaluation in a list of KeyValue\n+\n+ Args:\n+ kv_list (list[KeyValue]): list of KeyValue to look into\n+\n+ Returns:\n+ If found, tuple (kv, data) where kv is the KeyValue that matched\n+ and data is the data to be used for evaluation. None if not found.\n+ \"\"\"\n+ key_parts = self.field.split(\".\")\n+ field = key_parts[0]\n+ kvs = [kv for kv in kv_list if kv.key == field]\n+ if not kvs:\n+ return None\n+\n+ for kv in kvs:\n+ if kv.key == self.field:\n+ # exact match\n+ return (kv, kv.value)\n+ if len(key_parts) > 1:\n+ data = kv.value\n+ for subkey in key_parts[1:]:\n+ try:\n+ data = data.get(subkey)\n+ except Exception:\n+ data = None\n+ break\n+ if not data:\n+ break\n+ if data:\n+ return (kv, data)\n+ return None\n+\n+ def _find_keyval_to_evaluate(self, flow):\n+ \"\"\"Finds the key-value and data to use for evaluation on a flow\n+\n+ Args:\n+ flow(Flow): The flow where the lookup is performed\n+\n+ Returns:\n+ If found, tuple (kv, data) where kv is the KeyValue that matched\n+ and data is the data to be used for evaluation. None if not found.\n+\n+ \"\"\"\n+ for section in flow.sections:\n+ data = self._find_data_in_kv(section.data)\n+ if data:\n+ return data\n+ return None\n+\n+ def evaluate(self, flow):\n+ \"\"\"\n+ Return whether the clause is satisfied by the flow\n+\n+ Args:\n+ flow (Flow): the flow to evaluate\n+ \"\"\"\n+ result = self._find_keyval_to_evaluate(flow)\n+\n+ if not result:\n+ return EvaluationResult(False)\n+\n+ keyval, data = result\n+\n+ if not self.value and not self.operator:\n+ # just asserting the existance of the key\n+ return EvaluationResult(True, keyval)\n+\n+ # Decode the value based on the type of data\n+ if isinstance(data, Decoder):\n+ decoder = data.__class__\n+ else:\n+ decoder = self.type_decoders.get(data.__class__) or decode_default\n+\n+ decoded_value = decoder(self.value)\n+\n+ if self.operator == \"=\":\n+ return EvaluationResult(decoded_value == data, keyval)\n+ elif self.operator == \"<\":\n+ return EvaluationResult(data < decoded_value, keyval)\n+ elif self.operator == \">\":\n+ return EvaluationResult(data > decoded_value, keyval)\n+ elif self.operator == \"~=\":\n+ return EvaluationResult(decoded_value in data, keyval)\n+\n+\n+class BoolNot:\n+ def __init__(self, t):\n+ self.op, self.args = t[0]\n+\n+ def __repr__(self):\n+ return \"NOT({})\".format(self.args)\n+\n+ def evaluate(self, flow):\n+ return ~self.args.evaluate(flow)\n+\n+\n+class BoolAnd:\n+ def __init__(self, pattern):\n+ self.args = pattern[0][0::2]\n+\n+ def __repr__(self):\n+ return \"AND({})\".format(self.args)\n+\n+ def evaluate(self, flow):\n+ return reduce(and_, [arg.evaluate(flow) for arg in self.args])\n+\n+\n+class BoolOr:\n+ def __init__(self, pattern):\n+ self.args = pattern[0][0::2]\n+\n+ def evaluate(self, flow):\n+ return reduce(or_, [arg.evaluate(flow) for arg in self.args])\n+\n+ def __repr__(self):\n+ return \"OR({})\".format(self.args)\n+\n+\n+class OFFilter:\n+ w = pp.Word(pp.alphanums + \".\" + \":\" + \"_\" + \"/\" + \"-\")\n+ operators = (\n+ pp.Literal(\"=\")\n+ | pp.Literal(\"~=\")\n+ | pp.Literal(\"<\")\n+ | pp.Literal(\">\")\n+ | pp.Literal(\"!=\")\n+ )\n+\n+ clause = (w + operators + w) | w\n+ clause.setParseAction(ClauseExpression)\n+\n+ statement = pp.infixNotation(\n+ clause,\n+ [\n+ (\"!\", 1, pp.opAssoc.RIGHT, BoolNot),\n+ (\"not\", 1, pp.opAssoc.RIGHT, BoolNot),\n+ (\"&&\", 2, pp.opAssoc.LEFT, BoolAnd),\n+ (\"and\", 2, pp.opAssoc.LEFT, BoolAnd),\n+ (\"||\", 2, pp.opAssoc.LEFT, BoolOr),\n+ (\"or\", 2, pp.opAssoc.LEFT, BoolOr),\n+ ],\n+ )\n+\n+ def __init__(self, expr):\n+ self._filter = self.statement.parseString(expr)\n+\n+ def evaluate(self, flow):\n+ return self._filter[0].evaluate(flow)\ndiff --git a/python/setup.py b/python/setup.py\nindex b06370bd9..4e8a9761a 100644\n--- a/python/setup.py\n+++ b/python/setup.py\n@@ -87,7 +87,7 @@ setup_args = dict(\n ext_modules=[setuptools.Extension(\"ovs._json\", sources=[\"ovs/_json.c\"],\n libraries=['openvswitch'])],\n cmdclass={'build_ext': try_build_ext},\n- install_requires=['sortedcontainers', 'netaddr'],\n+ install_requires=['sortedcontainers', 'netaddr', 'pyparsing'],\n extras_require={':sys_platform == \"win32\"': ['pywin32 >= 1.0']},\n )\n \n", "prefixes": [ "ovs-dev", "v1", "09/18" ] }