get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/1558018/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1558018,
    "url": "http://patchwork.ozlabs.org/api/patches/1558018/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/openvswitch/patch/20211122112256.2011194-3-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-3-amorenoz@redhat.com>",
    "list_archive_url": null,
    "date": "2021-11-22T11:22:40",
    "name": "[ovs-dev,v1,02/18] python: add mask, ip and eth decoders",
    "commit_ref": null,
    "pull_url": null,
    "state": "changes-requested",
    "archived": false,
    "hash": "0d05d74c37fe62ac6be396e5557ae6842d340c1f",
    "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-3-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/1558018/comments/",
    "check": "fail",
    "checks": "http://patchwork.ozlabs.org/api/patches/1558018/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=BXHepHfD;\n\tdkim-atps=neutral",
            "ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org\n (client-ip=2605:bc80:3010::133; helo=smtp2.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 smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133])\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 4HyPyz2xshz9sX3\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 22 Nov 2021 22:23:22 +1100 (AEDT)",
            "from localhost (localhost [127.0.0.1])\n\tby smtp2.osuosl.org (Postfix) with ESMTP id EA08840236;\n\tMon, 22 Nov 2021 11:23:14 +0000 (UTC)",
            "from smtp2.osuosl.org ([127.0.0.1])\n\tby localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id h0Y5KnSNMg1W; Mon, 22 Nov 2021 11:23:13 +0000 (UTC)",
            "from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56])\n\tby smtp2.osuosl.org (Postfix) with ESMTPS id 5002C400F3;\n\tMon, 22 Nov 2021 11:23:12 +0000 (UTC)",
            "from lf-lists.osuosl.org (localhost [127.0.0.1])\n\tby lists.linuxfoundation.org (Postfix) with ESMTP id 1EE94C001E;\n\tMon, 22 Nov 2021 11:23:12 +0000 (UTC)",
            "from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136])\n by lists.linuxfoundation.org (Postfix) with ESMTP id 92EB2C0012\n for <dev@openvswitch.org>; Mon, 22 Nov 2021 11:23:10 +0000 (UTC)",
            "from localhost (localhost [127.0.0.1])\n by smtp3.osuosl.org (Postfix) with ESMTP id 7B58E6066D\n for <dev@openvswitch.org>; Mon, 22 Nov 2021 11:23:10 +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 oLE4xU3HFi_c for <dev@openvswitch.org>;\n Mon, 22 Nov 2021 11:23:09 +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 852F560663\n for <dev@openvswitch.org>; Mon, 22 Nov 2021 11:23:09 +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-195-MOiXuvqqNk6jv-YQ2YbWaw-1; Mon, 22 Nov 2021 06:23:06 -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 E53CD1006AA1\n for <dev@openvswitch.org>; Mon, 22 Nov 2021 11:23:05 +0000 (UTC)",
            "from amorenoz.users.ipa.redhat.com (unknown [10.2.16.196])\n by smtp.corp.redhat.com (Postfix) with ESMTP id C07605BAE0;\n Mon, 22 Nov 2021 11:23:04 +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=1637580188;\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=4fMYR2CqW/6F24wzW4uxBXxaTx/LqgcjGyru+ufpfqs=;\n b=BXHepHfDggUck2xdYehFpC4QKW4JyHPo3cz4jeF4Wi+AFs/llBed+KUtYGgE8lvJRi6nZg\n AjSd9MpHd394gyw3GR5gsf1hvWUy9APG3ewAI+jdJMwYV+pG3VPG5No2XUXQo8BAdNzl0E\n CuvoNVBjmzjFkPuLT5qykMuRrcIYklU=",
        "X-MC-Unique": "MOiXuvqqNk6jv-YQ2YbWaw-1",
        "From": "Adrian Moreno <amorenoz@redhat.com>",
        "To": "dev@openvswitch.org",
        "Date": "Mon, 22 Nov 2021 12:22:40 +0100",
        "Message-Id": "<20211122112256.2011194-3-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 02/18] python: add mask, ip and eth decoders",
        "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": "Add more decoders that can be used by KVParser.\n\nFor IPv4 and IPv6 addresses, create a new class that wraps\nnetaddr.IPAddress.\nFor Ethernet addresses, create a new class that wraps netaddr.EUI.\nFor Integers, create a new class that performs basic bitwise mask\ncomparisons\n\nSigned-off-by: Adrian Moreno <amorenoz@redhat.com>\n---\n python/ovs/flows/decoders.py | 341 +++++++++++++++++++++++++++++++++++\n python/setup.py              |   2 +-\n 2 files changed, 342 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/python/ovs/flows/decoders.py b/python/ovs/flows/decoders.py\nindex bfb64e70e..bf7a94ae8 100644\n--- a/python/ovs/flows/decoders.py\n+++ b/python/ovs/flows/decoders.py\n@@ -5,6 +5,15 @@ A decoder is generally a callable that accepts a string and returns the value\n object.\n \"\"\"\n \n+import netaddr\n+\n+\n+class Decoder:\n+    \"\"\"Base class for all decoder classes\"\"\"\n+\n+    def to_json(self):\n+        assert \"function must be implemented by derived class\"\n+\n \n def decode_default(value):\n     \"\"\"Default decoder.\n@@ -17,3 +26,335 @@ def decode_default(value):\n         return ival\n     except ValueError:\n         return value\n+\n+\n+def decode_flag(value):\n+    \"\"\"Default a flag. It's exising is just flagged by returning True\"\"\"\n+    return True\n+\n+\n+def decode_int(value):\n+    \"\"\"integer decoder\n+\n+    Both base10 and base16 integers are supported\n+\n+    Used for fields such as:\n+        n_bytes=34\n+        metadata=0x4\n+    \"\"\"\n+    return int(value, 0)\n+\n+\n+def decode_time(value):\n+    \"\"\"time decoder\n+\n+    Used for fields such as:\n+        duration=1234.123s\n+    \"\"\"\n+    if value == \"never\":\n+        return value\n+\n+    time_str = value.rstrip(\"s\")\n+    return float(time_str)\n+\n+\n+class IntMask(Decoder):\n+    \"\"\"Base class for Integer Mask decoder classes\n+\n+    It supports decoding a value/mask pair. It has to be derived and size\n+    has to be set to a specific value\n+    \"\"\"\n+\n+    size = None  # size in bits\n+\n+    def __init__(self, string):\n+        if not self.size:\n+            assert \"IntMask should be derived and size should be fixed\"\n+\n+        parts = string.split(\"/\")\n+        if len(parts) > 1:\n+            self._value = int(parts[0], 0)\n+            self._mask = int(parts[1], 0)\n+            if self._mask.bit_length() > self.size:\n+                raise ValueError(\n+                    \"Integer mask {} is bigger than size {}\".format(\n+                        self._mask, self.size\n+                    )\n+                )\n+        else:\n+            self._value = int(parts[0], 0)\n+            self._mask = 2 ** self.size - 1\n+\n+        if self._value.bit_length() > self.size:\n+            raise ValueError(\n+                \"Integer value {} is bigger than size {}\".format(\n+                    self._value, self.size\n+                )\n+            )\n+\n+    @property\n+    def value(self):\n+        return self._value\n+\n+    @property\n+    def mask(self):\n+        return self._mask\n+\n+    def max_mask(self):\n+        return 2 ** self.size - 1\n+\n+    def fully(self):\n+        \"\"\"Returns if it's fully masked\"\"\"\n+        return self._mask == self.max_mask()\n+\n+    def min(self):\n+        return self._value & self._mask\n+\n+    def max(self):\n+        return (self.max_mask() & ~self._mask) | (self._value & self._mask)\n+\n+    def __str__(self):\n+        if self.fully():\n+            return str(self._value)\n+        else:\n+            return \"{}/{}\".format(hex(self._value), hex(self._mask))\n+\n+    def __repr__(self):\n+        return \"%s('%s')\" % (self.__class__.__name__, self)\n+\n+    def __eq__(self, other):\n+        if isinstance(other, IntMask):\n+            return self.value == other.value and self.mask == other.mask\n+        elif isinstance(other, int):\n+            return self.value == other and self.mask == self.max_mask()\n+        else:\n+            raise ValueError(\"Cannot compare against \", other)\n+\n+    def __contains__(self, other):\n+        if isinstance(other, IntMask):\n+            if other.fully():\n+                return other.value in self\n+            return other.min() in self and other.max() in self\n+        else:\n+            return other & self._mask == self._value & self._mask\n+\n+    def dict(self):\n+        return {\"value\": self._value, \"mask\": self._mask}\n+\n+    def to_json(self):\n+        return self.dict()\n+\n+\n+class Mask8(IntMask):\n+    size = 8\n+\n+\n+class Mask16(IntMask):\n+    size = 16\n+\n+\n+class Mask32(IntMask):\n+    size = 32\n+\n+\n+class Mask64(IntMask):\n+    size = 64\n+\n+\n+class Mask128(IntMask):\n+    size = 128\n+\n+\n+class Mask992(IntMask):\n+    size = 992\n+\n+\n+def decode_mask(mask_size):\n+    \"\"\"value/mask decoder for values of specific size (bits)\n+\n+    Used for fields such as:\n+        reg0=0x248/0xff\n+    \"\"\"\n+\n+    class Mask(IntMask):\n+        size = mask_size\n+        __name__ = \"Mask{}\".format(size)\n+\n+    return Mask\n+\n+\n+class EthMask(Decoder):\n+    \"\"\"EthMask represents an Ethernet address with optional mask\n+\n+    It uses netaddr.EUI\n+\n+    Attributes:\n+        eth (netaddr.EUI): the ethernet address\n+        mask (netaddr.EUI): Optional, the ethernet address mask\n+\n+    Args:\n+        string (str): A string representing the masked ethernet address\n+            e.g: 00.11:22:33:44:55 or 01:00:22:00:33:00/01:00:00:00:00:00\n+    \"\"\"\n+\n+    def __init__(self, string):\n+        mask_parts = string.split(\"/\")\n+        self._eth = netaddr.EUI(mask_parts[0])\n+        if len(mask_parts) == 2:\n+            self._mask = netaddr.EUI(mask_parts[1])\n+        else:\n+            self._mask = None\n+\n+    @property\n+    def eth(self):\n+        \"\"\"The ethernet address\"\"\"\n+        return self._eth\n+\n+    @property\n+    def mask(self):\n+        \"\"\"The ethernet address mask\"\"\"\n+        return self._mask\n+\n+    def __eq__(self, other):\n+        \"\"\"Returns True if this EthMask is numerically the same as other\"\"\"\n+        return self._mask == other._mask and self._eth == other._eth\n+\n+    def __contains__(self, other):\n+        \"\"\"\n+        Args:\n+            other (netaddr.EUI): another Ethernet address\n+\n+        Returns:\n+            True if other falls into the masked address range\n+        \"\"\"\n+        if isinstance(other, EthMask):\n+            if other._mask:\n+                raise ValueError(\"EthMask mask comparison not supported\")\n+            return other._eth in self\n+\n+        if self._mask:\n+            return (other.value & self._mask.value) == (\n+                self._eth.value & self._mask.value\n+            )\n+        else:\n+            return other == self._eth\n+\n+    def __str__(self):\n+        if self._mask:\n+            return \"/\".join(\n+                [\n+                    self._eth.format(netaddr.mac_unix),\n+                    self._mask.format(netaddr.mac_unix),\n+                ]\n+            )\n+        else:\n+            return self._eth.format(netaddr.mac_unix)\n+\n+    def __repr__(self):\n+        return \"%s('%s')\" % (self.__class__.__name__, self)\n+\n+    def to_json(self):\n+        return str(self)\n+\n+\n+class IPMask(Decoder):\n+    \"\"\"IPMask stores an IPv6 or IPv4 and a mask\n+\n+    It uses netaddr.IPAddress. The IPMask can be represented by a\n+    netaddr.IPNetwork (if it's a valid cidr) or by an ip and a mask\n+\n+    Args:\n+        string (str): A string representing the ip/mask\n+    \"\"\"\n+\n+    def __init__(self, string):\n+        \"\"\"Constructor\"\"\"\n+        self._ipnet = None\n+        self._ip = None\n+        self._mask = None\n+        try:\n+            self._ipnet = netaddr.IPNetwork(string)\n+        except netaddr.AddrFormatError:\n+            pass\n+\n+        if not self._ipnet:\n+            # It's not a valid CIDR. Store ip and mask indendently\n+            parts = string.split(\"/\")\n+            if len(parts) != 2:\n+                raise ValueError(\n+                    \"value {}: is not an ipv4 or ipv6 address\".format(string)\n+                )\n+            try:\n+                self._ip = netaddr.IPAddress(parts[0])\n+                self._mask = netaddr.IPAddress(parts[1])\n+            except netaddr.AddrFormatError as exc:\n+                raise ValueError(\n+                    \"value {}: is not an ipv4 or ipv6 address\".format(string)\n+                ) from exc\n+\n+    def __eq__(self, other):\n+        \"\"\"Returns True if this IPMask is numerically the same as other\"\"\"\n+        if isinstance(other, netaddr.IPNetwork):\n+            return self._ipnet and self._ipnet == other\n+        if isinstance(other, netaddr.IPAddress):\n+            return self._ipnet and self._ipnet.ip == other\n+        elif isinstance(other, IPMask):\n+            if self._ipnet:\n+                return self._ipnet == other._ipnet\n+\n+            return self._ip == other._ip and self._mask == other._mask\n+        else:\n+            return False\n+\n+    def __contains__(self, other):\n+        \"\"\"\n+        Args:\n+            other (netaddr.IPAddres): another IP address\n+\n+        Returns:\n+            True if other falls into the masked ip range\n+        \"\"\"\n+        if isinstance(other, IPMask):\n+            if not other._ipnet:\n+                raise ValueError(\"ip/mask comparisons not supported\")\n+\n+            return (\n+                netaddr.IPAddress(other._ipnet.first) in self\n+                and netaddr.IPAddress(other._ipnet.last) in self\n+            )\n+\n+        elif isinstance(other, netaddr.IPAddress):\n+            if self._ipnet:\n+                return other in self._ipnet\n+            return (other & self._mask) == (self._ip & self._mask)\n+\n+    def cidr(self):\n+        \"\"\"\n+        Returns True if the IPMask is a valid CIDR\n+        \"\"\"\n+        return self._ipnet is not None\n+\n+    @property\n+    def ip(self):\n+        \"\"\"The IP address\"\"\"\n+        if self._ipnet:\n+            return self._ipnet.ip\n+        return self._ip\n+\n+    @property\n+    def mask(self):\n+        \"\"\"The IP mask\"\"\"\n+        if self._ipnet:\n+            return self._ipnet.netmask\n+        return self._mask\n+\n+    def __str__(self):\n+        if self._ipnet:\n+            return str(self._ipnet)\n+        return \"/\".join([str(self._ip), str(self._mask)])\n+\n+    def __repr__(self):\n+        return \"%s('%s')\" % (self.__class__.__name__, self)\n+\n+    def to_json(self):\n+        return str(self)\ndiff --git a/python/setup.py b/python/setup.py\nindex 0e6b0ea39..b06370bd9 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'],\n+    install_requires=['sortedcontainers', 'netaddr'],\n     extras_require={':sys_platform == \"win32\"': ['pywin32 >= 1.0']},\n )\n \n",
    "prefixes": [
        "ovs-dev",
        "v1",
        "02/18"
    ]
}