Show a patch.

Update a patch.

Update a patch.

GET /api/patches/1551398/
Content-Type: application/json
Vary: Accept

    "id": 1551398,
    "url": "",
    "web_url": "",
    "project": {
        "id": 68,
        "url": "",
        "name": "Open Virtual Network development",
        "link_name": "ovn",
        "list_id": "",
        "list_email": "",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    "msgid": "<>",
    "list_archive_url": null,
    "date": "2021-11-05T14:00:13",
    "name": "[ovs-dev,v10,3/4] controller: Consider plugging VIF on CMS request.",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "b4f2f65d88cae57346964ebd7eeb7b6ebac83daf",
    "submitter": {
        "id": 77851,
        "url": "",
        "name": "Frode Nordahl",
        "email": ""
    "delegate": null,
    "mbox": "",
    "series": [
            "id": 270569,
            "url": "",
            "web_url": "",
            "date": "2021-11-05T14:00:12",
            "name": "Introduce infrastructure for VIF plug providers.",
            "version": 10,
            "mbox": ""
    "comments": "",
    "check": "fail",
    "checks": "",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<>",
        "X-Original-To": [
        "Delivered-To": [
        "Authentication-Results": [
            ";\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected)\n header.a=rsa-sha256 header.s=20210705 header.b=XtuBwId3;\n\tdkim-atps=neutral",
            ";\n spf=pass (sender SPF authorized)\n (client-ip=2605:bc80:3010::138;;\n; receiver=<UNKNOWN>)"
        "Received": [
            "from ( [IPv6:2605:bc80:3010::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 (Postfix) with ESMTPS id 4Hm2GB0NLXz9sfG\n\tfor <>; Sat,  6 Nov 2021 01:00:34 +1100 (AEDT)",
            "from localhost (localhost [])\n\tby (Postfix) with ESMTP id 51B148272D;\n\tFri,  5 Nov 2021 14:00:29 +0000 (UTC)",
            "from ([])\n\tby localhost ( []) (amavisd-new, port 10024)\n\twith ESMTP id 6XAmF0U20eTW; Fri,  5 Nov 2021 14:00:26 +0000 (UTC)",
            "from ( [])\n\tby (Postfix) with ESMTPS id F333482768;\n\tFri,  5 Nov 2021 14:00:24 +0000 (UTC)",
            "from (localhost [])\n\tby (Postfix) with ESMTP id 6C5C3C003F;\n\tFri,  5 Nov 2021 14:00:22 +0000 (UTC)",
            "from ( [IPv6:2605:bc80:3010::138])\n by (Postfix) with ESMTP id 63950C0019\n for <>; Fri,  5 Nov 2021 14:00:19 +0000 (UTC)",
            "from localhost (localhost [])\n by (Postfix) with ESMTP id 537588187F\n for <>; Fri,  5 Nov 2021 14:00:19 +0000 (UTC)",
            "from ([])\n by localhost ( []) (amavisd-new, port 10024)\n with ESMTP id XpRc4DfFest6 for <>;\n Fri,  5 Nov 2021 14:00:18 +0000 (UTC)",
            "from\n ( [])\n by (Postfix) with ESMTPS id 287DD81D5F\n for <>; Fri,  5 Nov 2021 14:00:18 +0000 (UTC)",
            "from frode-threadripper.. ( [])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by (Postfix) with ESMTPSA id 85F4D3F1E5;\n Fri,  5 Nov 2021 14:00:16 +0000 (UTC)"
        "X-Virus-Scanned": [
            "amavisd-new at",
            "amavisd-new at"
        "X-Greylist": "domain auto-whitelisted by SQLgrey-1.8.0",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;;\n s=20210705; t=1636120816;\n bh=+91ycczBYRVylPELCU8/Pxa3iYg0RlsRqZ55DvZYfC0=;\n h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:\n MIME-Version;\n b=XtuBwId3HBtSpch2RE1Y6WNxH0w68ZwWfDX2LDHutoBl8gBI7rGV1mV94eylL9MWr\n ZUg3Julwcye7YoNTSNPr6YViCWkqyhpFAzQP7Bhj9QWqUVjysqzPUIiNCS+mIsv5MT\n JxuECF/qJny54CLdtFR66JuD/NrIikg+pZ/sj9l4fKPbkJa7OwdCgi8QMDI+7BRlo2\n RP3ewCTpktuVvC7txD+YXyuft4XjRoHBlaUzR0IMMOAdZqT9QKwivevGBgu9C0cL0Y\n q+HNGo1tKYUxqouVV10Aal4v4fbEkhn4413dSCh76B3HCvYmbKcBnE74dRcWw/D2eG\n aruyFNu12cstQ==",
        "From": "Frode Nordahl <>",
        "To": "",
        "Date": "Fri,  5 Nov 2021 15:00:13 +0100",
        "Message-Id": "<>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<>",
        "References": "<>",
        "MIME-Version": "1.0",
        "Subject": "[ovs-dev] [PATCH ovn v10 3/4] controller: Consider plugging VIF on\n\tCMS request.",
        "X-BeenThere": "",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "<>",
        "List-Unsubscribe": "<>,\n <>",
        "List-Archive": "<>",
        "List-Post": "<>",
        "List-Help": "<>",
        "List-Subscribe": "<>,\n <>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "",
        "Sender": "\"dev\" <>"
    "content": "When OVN is linked with an appropriate VIF plug provider,\nCMS can request an OVN controller to plug individual lports into\nthe Open vSwitch instance it manages.\n\nThe port and interface record will be maintained throughout the\nlifetime of the lport and it will be removed on release of lport.\n\nAdd port by interfaces index - To be able to effectively remove\nports previously plugged by us we need to look up ports by\ninterface records.\n\nAdd Port_Binding by requested_chassis index - To be able to\neffectively iterate over ports destined to our chassis we need to\nlook up Port_Binding records by requested_chassis.\n\nSigned-off-by: Frode Nordahl <>\n---\n controller/ovn-controller.c |  69 +++++++++++++++++++-\n ovn-nb.xml                  |  21 +++++++\n tests/         |   2 +-\n tests/                | 121 ++++++++++++++++++++++++++++++++++++\n 4 files changed, 211 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c\nindex 1cef04735..f223e0f09 100644\n--- a/controller/ovn-controller.c\n+++ b/controller/ovn-controller.c\n@@ -106,6 +106,7 @@ static unixctl_cb_func debug_delay_nb_cfg_report;\n #define IF_STATUS_MGR_UPDATE_STOPWATCH_NAME \"if-status-mgr-update\"\n #define OFCTRL_SEQNO_RUN_STOPWATCH_NAME \"ofctrl-seqno-run\"\n #define BFD_RUN_STOPWATCH_NAME \"bfd-run\"\n+#define VIF_PLUG_RUN_STOPWATCH_NAME \"vif-plug-run\"\n \n #define OVS_NB_CFG_NAME \"ovn-nb-cfg\"\n #define OVS_NB_CFG_TS_NAME \"ovn-nb-cfg-ts\"\n@@ -937,6 +938,7 @@ ctrl_register_ovs_idl(struct ovsdb_idl *ovs_idl)\n     binding_register_ovs_idl(ovs_idl);\n     bfd_register_ovs_idl(ovs_idl);\n     physical_register_ovs_idl(ovs_idl);\n+    vif_plug_register_ovs_idl(ovs_idl);\n }\n \n #define SB_NODES \\\n@@ -3091,6 +3093,10 @@ main(int argc, char *argv[])\n         ovsdb_idl_create(ovs_remote, &ovsrec_idl_class, false, true));\n     ctrl_register_ovs_idl(ovs_idl_loop.idl);\n \n+    struct ovsdb_idl_index *ovsrec_port_by_interfaces\n+        = ovsdb_idl_index_create1(ovs_idl_loop.idl,\n+                                  &ovsrec_port_col_interfaces);\n+\n     ovsdb_idl_get_initial_snapshot(ovs_idl_loop.idl);\n \n     /* Configure OVN SB database. */\n@@ -3126,6 +3132,9 @@ main(int argc, char *argv[])\n     struct ovsdb_idl_index *sbrec_port_binding_by_type\n         = ovsdb_idl_index_create1(ovnsb_idl_loop.idl,\n                                   &sbrec_port_binding_col_type);\n+    struct ovsdb_idl_index *sbrec_port_binding_by_requested_chassis\n+        = ovsdb_idl_index_create1(ovnsb_idl_loop.idl,\n+                                  &sbrec_port_binding_col_requested_chassis);\n     struct ovsdb_idl_index *sbrec_datapath_binding_by_key\n         = ovsdb_idl_index_create1(ovnsb_idl_loop.idl,\n                                   &sbrec_datapath_binding_col_tunnel_key);\n@@ -3198,6 +3207,7 @@ main(int argc, char *argv[])\n     stopwatch_create(IF_STATUS_MGR_UPDATE_STOPWATCH_NAME, SW_MS);\n     stopwatch_create(OFCTRL_SEQNO_RUN_STOPWATCH_NAME, SW_MS);\n     stopwatch_create(BFD_RUN_STOPWATCH_NAME, SW_MS);\n+    stopwatch_create(VIF_PLUG_RUN_STOPWATCH_NAME, SW_MS);\n \n     /* Define inc-proc-engine nodes. */\n     ENGINE_NODE_WITH_CLEAR_TRACK_DATA_IS_VALID(ct_zones, \"ct_zones\");\n@@ -3429,6 +3439,11 @@ main(int argc, char *argv[])\n     };\n     struct if_status_mgr *if_mgr = ctrl_engine_ctx.if_mgr;\n \n+    struct shash vif_plug_deleted_iface_ids =\n+        SHASH_INITIALIZER(&vif_plug_deleted_iface_ids);\n+    struct shash vif_plug_changed_iface_ids =\n+        SHASH_INITIALIZER(&vif_plug_changed_iface_ids);\n+\n     char *ovn_version = ovn_get_internal_version();\n     VLOG_INFO(\"OVN internal version is : [%s]\", ovn_version);\n \n@@ -3485,6 +3500,7 @@ main(int argc, char *argv[])\n             if (!new_ovnsb_cond_seqno) {\n                 VLOG_INFO(\"OVNSB IDL reconnected, force recompute.\");\n                 engine_set_force_recompute(true);\n+                vif_plug_reset_idl_prime_counter();\n             }\n             ovnsb_cond_seqno = new_ovnsb_cond_seqno;\n         }\n@@ -3639,6 +3655,37 @@ main(int argc, char *argv[])\n                             ovsrec_port_table_get(ovs_idl_loop.idl),\n                             br_int, chassis, &runtime_data->local_datapaths);\n                         stopwatch_stop(PATCH_RUN_STOPWATCH_NAME, time_msec());\n+                        if (vif_plug_provider_has_providers() && ovs_idl_txn) {\n+                            struct vif_plug_ctx_in vif_plug_ctx_in = {\n+                                .ovs_idl_txn = ovs_idl_txn,\n+                                .sbrec_port_binding_by_name =\n+                                    sbrec_port_binding_by_name,\n+                                .sbrec_port_binding_by_requested_chassis =\n+                                    sbrec_port_binding_by_requested_chassis,\n+                                .ovsrec_port_by_interfaces =\n+                                    ovsrec_port_by_interfaces,\n+                                .ovs_table = ovs_table,\n+                                .br_int = br_int,\n+                                .iface_table =\n+                                    ovsrec_interface_table_get(\n+                                                    ovs_idl_loop.idl),\n+                                .chassis_rec = chassis,\n+                                .local_bindings =\n+                                        &runtime_data->lbinding_data.bindings,\n+                            };\n+                            struct vif_plug_ctx_out vif_plug_ctx_out = {\n+                                .deleted_iface_ids =\n+                                    &vif_plug_deleted_iface_ids,\n+                                .changed_iface_ids =\n+                                    &vif_plug_changed_iface_ids,\n+                            };\n+                            stopwatch_start(VIF_PLUG_RUN_STOPWATCH_NAME,\n+                                            time_msec());\n+                            vif_plug_run(&vif_plug_ctx_in,\n+                                         &vif_plug_ctx_out);\n+                            stopwatch_stop(VIF_PLUG_RUN_STOPWATCH_NAME,\n+                                           time_msec());\n+                        }\n                         stopwatch_start(PINCTRL_RUN_STOPWATCH_NAME,\n                                         time_msec());\n                         pinctrl_run(ovnsb_idl_txn,\n@@ -3795,7 +3842,16 @@ main(int argc, char *argv[])\n             engine_set_force_recompute(true);\n         }\n \n-        if (ovsdb_idl_loop_commit_and_wait(&ovs_idl_loop) == 1) {\n+        int ovs_txn_status = ovsdb_idl_loop_commit_and_wait(&ovs_idl_loop);\n+        if (!ovs_txn_status) {\n+            /* The transaction failed. */\n+            vif_plug_clear_deleted(\n+                    &vif_plug_deleted_iface_ids);\n+            vif_plug_clear_changed(\n+                    &vif_plug_changed_iface_ids);\n+        } else if (ovs_txn_status == 1) {\n+            /* The transaction committed successfully\n+             * (or it did not change anything in the database). */\n             ct_zones_data = engine_get_data(&en_ct_zones);\n             if (ct_zones_data) {\n                 struct shash_node *iter, *iter_next;\n@@ -3808,6 +3864,15 @@ main(int argc, char *argv[])\n                     }\n                 }\n             }\n+\n+            vif_plug_finish_deleted(\n+                    &vif_plug_deleted_iface_ids);\n+            vif_plug_finish_changed(\n+                    &vif_plug_changed_iface_ids);\n+        } else if (ovs_txn_status == -1) {\n+            /* The commit is still in progress */\n+        } else {\n+            OVS_NOT_REACHED();\n         }\n \n         ovsdb_idl_track_clear(ovnsb_idl_loop.idl);\n@@ -3883,6 +3948,8 @@ loop_done:\n     pinctrl_destroy();\n     patch_destroy();\n     if_status_mgr_destroy(if_mgr);\n+    shash_destroy(&vif_plug_deleted_iface_ids);\n+    shash_destroy(&vif_plug_changed_iface_ids);\n     vif_plug_provider_destroy_all();\n \n     ovsdb_idl_loop_destroy(&ovs_idl_loop);\ndiff --git a/ovn-nb.xml b/ovn-nb.xml\nindex e31578fb6..036ffa64f 100644\n--- a/ovn-nb.xml\n+++ b/ovn-nb.xml\n@@ -1031,6 +1031,27 @@\n             DHCP reply.\n           </p>\n         </column>\n+\n+        <group title=\"VIF Plugging Options\">\n+          <column name=\"options\" key=\"vif-plug-type\">\n+            If set, OVN will attempt to perform plugging of this VIF.  In order\n+            to get this port plugged by the OVN controller, OVN must be built\n+            with support for VIF plugging.  The default behavior is for the CMS\n+            to do the VIF plugging.  Each VIF plug provider have their own\n+            options namespaced by name, for example \"vif-plug:representor:key\".\n+\n+            Please refer to the VIF plug provider documentation located in\n+            Documentation/topics/vif-plug-providers/ for more information.\n+          </column>\n+\n+          <column name=\"options\" key=\"vif-plug-mtu-request\">\n+            Requested MTU for plugged interfaces.  When set the OVN controller\n+            will fill the <ref table=\"Interface\" column=\"mtu_request\"/> column\n+            of the Open vSwitch database's\n+            <ref table=\"Interface\" db=\"vswitch\"/> table.  This in turn will\n+            make OVS vswitchd update the MTU of the linked interface.\n+          </column>\n+        </group>\n       </group>\n \n       <group title=\"Virtual port Options\">\ndiff --git a/tests/ b/tests/\nindex f06f2e68e..21b7d985e 100644\n--- a/tests/\n+++ b/tests/\n@@ -327,7 +327,7 @@ ovn_az_attach() {\n         -- --may-exist add-br br-int \\\n         -- set bridge br-int fail-mode=secure other-config:disable-in-band=true \\\n         || return 1\n-    start_daemon ovn-controller || return 1\n+    start_daemon ovn-controller --enable-dummy-vif-plug || return 1\n }\n \n # ovn_attach NETWORK BRIDGE IP [MASKLEN]\ndiff --git a/tests/ b/tests/\nindex 6f6f5c2da..8163ad84a 100644\n--- a/tests/\n+++ b/tests/\n@@ -28818,3 +28818,124 @@ AT_CHECK([grep -q \"Not claiming\" hv1/ovn-controller.log], [1], [])\n OVN_CLEANUP([hv1])\n AT_CLEANUP\n ])\n+\n+OVN_FOR_EACH_NORTHD([\n+AT_SETUP([ovn-controller - VIF plugging])\n+AT_KEYWORDS([vif-plug])\n+\n+ovn_start\n+\n+net_add n1\n+sim_add hv1\n+ovs-vsctl add-br br-phys\n+ovn_attach n1 br-phys\n+\n+sim_add hv2\n+ovs-vsctl add-br br-phys\n+ovn_attach n1 br-phys\n+\n+check ovn-nbctl ls-add lsw0\n+\n+check ovn-nbctl lsp-add lsw0 lsp1\n+check ovn-nbctl lsp-set-addresses lsp1 \"f0:00:00:00:00:01\"\n+check ovn-nbctl lsp-set-options lsp1 \\\n+    requested-chassis=hv1 \\\n+    vif-plug-type=dummy \\\n+    vif-plug-mtu-request=42\n+\n+check ovn-nbctl lsp-add lsw0 lsp2\n+check ovn-nbctl lsp-set-addresses lsp2 \"f0:00:00:00:00:02\"\n+check ovn-nbctl lsp-set-options lsp2 \\\n+    requested-chassis=hv2 \\\n+    vif-plug-type=dummy \\\n+    vif-plug-mtu-request=42\n+\n+wait_for_ports_up lsp1 lsp2\n+\n+lsp1_uuid=$(ovn-nbctl --bare --columns _uuid find Logical_Switch_Port name=lsp1)\n+iface1_uuid=$(as hv1 ovs-vsctl --bare --columns _uuid find Interface name=lsp1)\n+\n+lsp2_uuid=$(ovn-nbctl --bare --columns _uuid find Logical_Switch_Port name=lsp2)\n+iface2_uuid=$(as hv2 ovs-vsctl --bare --columns _uuid find Interface name=lsp2)\n+\n+# Check that the lport was plugged\n+AT_CHECK([test xvalue = x$(as hv1 ovs-vsctl get Interface ${iface1_uuid} options:vif-plug-dummy-option)], [0], [])\n+AT_CHECK([test x42 = x$(as hv1 ovs-vsctl get Interface ${iface1_uuid} mtu_request)], [0], [])\n+\n+# Check that updating the lport updates the local iface\n+check ovn-nbctl --wait=hv lsp-set-options lsp1 \\\n+    requested-chassis=hv1 \\\n+    vif-plug-type=dummy \\\n+    vif-plug-mtu-request=43\n+OVS_WAIT_UNTIL([\n+    test x43 = x$(as hv1 ovs-vsctl get Interface ${iface1_uuid} mtu_request)\n+])\n+\n+# Check that local modification of iface will trigger ovn-controller to update\n+# the iface record\n+check as hv1 ovs-vsctl set interface ${iface1_uuid} mtu_request=44\n+OVS_WAIT_UNTIL([\n+    test x43 = x$(as hv1 ovs-vsctl get Interface ${iface1_uuid} mtu_request)\n+])\n+\n+# Check that pointing requested-chassis somewhere else will unplug the port\n+check ovn-nbctl --wait=hv set Logical_Switch_Port lsp1 \\\n+    options:requested-chassis=non-existent-chassis\n+OVS_WAIT_UNTIL([\n+    ! as hv1 ovs-vsctl get Interface ${iface1_uuid} _uuid\n+])\n+\n+# Check that removing an lport will unplug it\n+AT_CHECK([test x${iface2_uuid} = x$(as hv2 ovs-vsctl get Interface ${iface2_uuid} _uuid)], [0], [])\n+check ovn-nbctl --wait=hv lsp-del ${lsp2_uuid}\n+OVS_WAIT_UNTIL([\n+    ! as hv2 ovs-vsctl get Interface ${iface2_uuid} _uuid\n+])\n+\n+# Check that port is unplugged when we simulate presence of a port previously\n+# plugged by us in local OVSDB with no record in SB DB.\n+check as hv2 ovs-vsctl \\\n+    -- add-port br-int vif1\n+\n+# From one moment it's there...\n+vif1_uuid=$(as hv2 ovs-vsctl --bare --columns _uuid find Interface name=vif1)\n+OVS_WAIT_UNTIL([\n+    as hv2 ovs-vsctl get Interface ${vif1_uuid} _uuid\n+])\n+\n+# Add the external-ids we expect\n+check as hv2 ovs-vsctl \\\n+    -- set Interface ${vif1_uuid} \\\n+           external-ids:ovn-plugged=dummy \\\n+           external-ids:iface-id=non-existing-lsp\n+\n+# the next moment it's gone.\n+OVS_WAIT_UNTIL([\n+    ! as hv2 ovs-vsctl get Interface ${vif1_uuid} _uuid\n+])\n+\n+# Check that a warning is logged when CMS requests plugging of an interface\n+# with lbinding already plugged by someone else.\n+check as hv2 ovs-vsctl \\\n+    -- add-port br-int vif3 \\\n+    -- set Interface vif3 \\\n+       external-ids:iface-id=lsp3\n+\n+check ovn-nbctl lsp-add lsw0 lsp3\n+check ovn-nbctl lsp-set-addresses lsp3 \"f0:00:00:00:00:03\"\n+check ovn-nbctl lsp-set-options lsp3 \\\n+    requested-chassis=hv2\n+\n+wait_for_ports_up lsp3\n+\n+check ovn-nbctl --wait=hv lsp-set-options lsp3 \\\n+    requested-chassis=hv2 \\\n+    vif-plug-type=dummy\n+\n+OVS_WAIT_UNTIL([\n+    grep -q \"CMS requested plugging of lport lsp3\" hv2/ovn-controller.log\n+])\n+\n+OVN_CLEANUP([hv1],[hv2])\n+AT_CLEANUP\n+])\n",
    "prefixes": [