public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Rémi PAETA" <remi.paeta@comaite.com>
To: pve-devel@lists.proxmox.com
Subject: [RFC PATCH v2 network 09/15] sdn: ovn: bind guest ports to the chassis of their node
Date: Fri, 27 Nov 2026 11:28:30 +0100	[thread overview]
Message-ID: <20261127102836.313797-10-remi.paeta@comaite.com> (raw)
In-Reply-To: <20261127102836.313797-1-remi.paeta@comaite.com>

During a live migration, QEMU already runs on the destination node
while the memory gets copied, so both ovn-controller instances see an
interface for the logical switch port and keep claiming it from each
other, every 500 ms, until the source releases it. Traffic goes to the
wrong node in the meantime: 2 to 3 s of loss were measured, while QEMU
reported a downtime of about 20 ms.

Set the requested-chassis option of guest ports to the local node when
plugging them. On the destination of a live migration, set it to both
nodes with activation-strategy=rarp instead, as recommended by OVN for
this case: the source stays the main chassis while the memory gets
copied. qemu-server calls add_bridge_fdb on the destination right
before resuming the guest, which binds the port to the destination
only.

QEMU keeps PVE_MIGRATED_FROM in its environment for its whole lifetime
and passes it on to the script plugging hotplugged NICs, so it is only
taken into account while the guest configuration is still on the
source node, which qemu-server only moves once the memory is copied.

requested-chassis refers to the chassis hostname, which Open vSwitch
sets to the FQDN, so set it to the node name when configuring the
chassis.

With this, the loss went down to 0.4 to 0.8 s, close to the resolution
of the probe used.

Signed-off-by: Rémi PAETA <remi.paeta@comaite.com>
---
Changes since v1:
- only take PVE_MIGRATED_FROM into account while the guest
  configuration is still on the source node: QEMU keeps it in its
  environment, so NICs hotplugged after a migration were bound to two
  chassis and never activated
- commit message: describe the source as the main chassis during the
  migration

 src/PVE/Network/SDN/Ovn.pm             | 87 +++++++++++++++++++++++---
 src/PVE/Network/SDN/Zones/OvnPlugin.pm | 15 ++++-
 src/test/run_test_ovn.pl               | 82 +++++++++++++++++++++++-
 3 files changed, 171 insertions(+), 13 deletions(-)

diff --git a/src/PVE/Network/SDN/Ovn.pm b/src/PVE/Network/SDN/Ovn.pm
index a2327c2..12e03ce 100644
--- a/src/PVE/Network/SDN/Ovn.pm
+++ b/src/PVE/Network/SDN/Ovn.pm
@@ -36,6 +36,9 @@ our $CONTROLLER_UNIT_FILE = '/usr/lib/systemd/system/ovn-controller.service';
 our $CONTROLLER_DROPIN = '/run/systemd/system/ovn-controller.service.d/pve-sdn-ssl.conf';
 our $SYSTEMCTL = '/usr/bin/systemctl';
 
+# guest configurations, per node
+our $NODES_DIR = '/etc/pve/nodes';
+
 # external_ids keys tagging the objects managed by PVE. Northbound objects
 # without them are never touched, so the OVN deployment can be shared with
 # other consumers.
@@ -46,7 +49,7 @@ my $EXT_VMID = 'pve-sdn-vmid';
 my $EXT_MAC = 'pve-sdn-mac';
 
 # chassis settings written to the local Open_vSwitch table
-my @CHASSIS_KEYS = ('ovn-remote', 'ovn-encap-type', 'ovn-encap-ip', $EXT_CONTROLLER);
+my @CHASSIS_KEYS = ('ovn-remote', 'ovn-encap-type', 'ovn-encap-ip', 'hostname', $EXT_CONTROLLER);
 
 =head3 ovn_controllers(\%running_cfg)
 
@@ -694,16 +697,75 @@ sub port_vnet {
     return $output eq '' ? undef : $output;
 }
 
-=head3 update_port($controller, $iface, $level, \%running_cfg, $vnetid, $mac)
+=head3 chassis_commands($iface, $nodename, $migrated_from)
+
+Returns the C<ovn-nbctl> commands binding the logical switch port C<$iface> to
+the chassis of the node C<$nodename>, so that no other chassis claims it.
+
+During a live migration from the node C<$migrated_from>, the port is bound to
+both chassis, the source one staying the main one. The destination chassis only
+gets the traffic of the port once the guest announces itself there (QEMU sends a
+RARP after the switchover). Otherwise, both chassis keep claiming the port while
+the memory gets copied, and traffic goes to the wrong node for seconds.
+
+=cut
+
+sub chassis_commands {
+    my ($iface, $nodename, $migrated_from) = @_;
+
+    if (defined($migrated_from)) {
+        return [[
+            'set',
+            'Logical_Switch_Port',
+            $iface,
+            "options:requested-chassis=$migrated_from,$nodename",
+            'options:activation-strategy=rarp',
+        ]];
+    }
+
+    return [
+        ['set', 'Logical_Switch_Port', $iface, "options:requested-chassis=$nodename"],
+        ['remove', 'Logical_Switch_Port', $iface, 'options', 'activation-strategy'],
+    ];
+}
+
+=head3 migration_source($iface)
+
+Returns the node that the guest of C<$iface> is being live migrated from, if
+this node is the destination of an ongoing migration.
+
+qemu-server sets C<PVE_MIGRATED_FROM> before starting QEMU on the destination
+node, and QEMU passes its environment on to the script plugging the interfaces
+it hotplugs later on. The variable thus stays set after the migration, so it
+only counts while the guest configuration is still on the source node, as
+qemu-server only moves it once the memory is copied. The configuration file is
+checked directly, as the plugging script does not load the cluster VM list.
+
+=cut
+
+sub migration_source {
+    my ($iface) = @_;
+
+    my $source = $ENV{PVE_MIGRATED_FROM} or return undef;
+    my ($vmid) = $iface =~ m/^tap(\d+)i\d+$/ or return undef;
+
+    return -f "$NODES_DIR/$source/qemu-server/$vmid.conf" ? $source : undef;
+}
+
+=head3 update_port($controller, $iface, $level, \%running_cfg, $vnetid, $mac, $nodename)
 
 Sets the guest MAC C<$mac> and its IPAM IPs on the logical switch port C<$iface>
 according to the port security C<$level>, and records the MAC so that later
 syncs can update the port.
 
+Also binds the port to the chassis of C<$nodename> only. qemu-server calls this
+on the destination node when resuming a guest after a live migration, which
+ends the binding to both chassis set up by C<ensure_port>.
+
 =cut
 
 sub update_port {
-    my ($controller, $iface, $level, $running_cfg, $vnetid, $mac) = @_;
+    my ($controller, $iface, $level, $running_cfg, $vnetid, $mac, $nodename) = @_;
 
     # Without an answer from the IPAM, only the MAC can be enforced: the guest
     # keeps its connectivity, and the next sync applies the IPs.
@@ -716,19 +778,21 @@ sub update_port {
             port_addresses_commands($iface, $addresses, $port_security)->@*,
             # as written in the guest config, which is what the IPAM is keyed by
             ['set', 'Logical_Switch_Port', $iface, "external_ids:$EXT_MAC=$mac"],
+            chassis_commands($iface, $nodename)->@*,
         ],
     );
 }
 
-=head3 ensure_port($controllerid, $controller, $zoneid, $vnetid, $iface)
+=head3 ensure_port($controllerid, $controller, $zoneid, $vnetid, $iface, $nodename, $migrated_from)
 
 Creates or updates the logical switch port of the guest interface C<$iface> on
-the logical switch of C<$vnetid>, moving it over from another switch if needed.
+the logical switch of C<$vnetid>, moving it over from another switch if needed,
+and binds it to the chassis of C<$nodename>, see C<chassis_commands>.
 
 =cut
 
 sub ensure_port {
-    my ($controllerid, $controller, $zoneid, $vnetid, $iface) = @_;
+    my ($controllerid, $controller, $zoneid, $vnetid, $iface, $nodename, $migrated_from) = @_;
 
     eval {
         my $current_switch;
@@ -748,6 +812,7 @@ sub ensure_port {
 
         my $external_ids = port_external_ids($controllerid, $zoneid, $vnetid, $iface);
         my $commands = port_commands($vnetid, $iface, $external_ids, $current_switch);
+        push @$commands, chassis_commands($iface, $nodename, $migrated_from)->@*;
         nbctl_transaction($controller, $commands);
     };
     die "unable to create OVN logical switch port '$iface' on '$vnetid' - $@" if $@;
@@ -841,20 +906,24 @@ sub parse_remote_ip {
     die "unable to parse OVN database connection '$first'\n";
 }
 
-=head3 chassis_settings($controllerid, $controller, $encap_ip)
+=head3 chassis_settings($controllerid, $controller, $encap_ip, $nodename)
 
 Returns the external_ids to set in the local Open_vSwitch table so that
 ovn-controller joins the OVN deployment of C<$controller>.
 
+The chassis hostname is set to the node name, which logical switch ports refer
+to in their requested-chassis option. Open vSwitch would use the FQDN instead.
+
 =cut
 
 sub chassis_settings {
-    my ($controllerid, $controller, $encap_ip) = @_;
+    my ($controllerid, $controller, $encap_ip, $nodename) = @_;
 
     return {
         'ovn-remote' => $controller->{'sb-connection'},
         'ovn-encap-type' => $controller->{'encap-type'} // 'geneve',
         'ovn-encap-ip' => $encap_ip,
+        hostname => $nodename,
         $EXT_CONTROLLER => $controllerid,
     };
 }
@@ -923,7 +992,7 @@ sub configure_chassis {
         uses_ssl($controller->{'sb-connection'}) ? $id : undef, $nodename,
     );
 
-    my $settings = chassis_settings($id, $controller, $encap_ip);
+    my $settings = chassis_settings($id, $controller, $encap_ip, $nodename);
     run_command([
         $VSCTL,
         @VSCTL_OPTS,
diff --git a/src/PVE/Network/SDN/Zones/OvnPlugin.pm b/src/PVE/Network/SDN/Zones/OvnPlugin.pm
index 6c78fc0..fded449 100644
--- a/src/PVE/Network/SDN/Zones/OvnPlugin.pm
+++ b/src/PVE/Network/SDN/Zones/OvnPlugin.pm
@@ -3,6 +3,7 @@ package PVE::Network::SDN::Zones::OvnPlugin;
 use v5.36;
 
 use PVE::Exception qw(raise_param_exc);
+use PVE::INotify;
 use PVE::Network;
 
 use PVE::Network::SDN::Ovn;
@@ -102,7 +103,13 @@ sub tap_plug {
         if !$controller;
 
     PVE::Network::SDN::Ovn::ensure_port(
-        $controllerid, $controller, $vnet->{zone}, $vnetid, $iface,
+        $controllerid,
+        $controller,
+        $vnet->{zone},
+        $vnetid,
+        $iface,
+        PVE::INotify::nodename(),
+        PVE::Network::SDN::Ovn::migration_source($iface),
     );
 
     # detach from any previous bridge
@@ -114,8 +121,9 @@ sub tap_plug {
     die "VLAN tags and trunks are not supported on OVN vnet '$vnetid'\n" if $tag || $trunks;
 }
 
-# Called by qemu-server on guest start and by pve-container on plug, with the
-# guest MAC, which tap_plug does not get.
+# Called by qemu-server on guest start and resume, including after a live
+# migration, and by pve-container on plug, with the guest MAC, which tap_plug
+# does not get.
 sub add_bridge_fdb {
     my ($class, $plugin_config, $iface, $macaddr) = @_;
 
@@ -145,6 +153,7 @@ sub add_bridge_fdb {
             $running_config,
             $vnetid,
             $macaddr,
+            PVE::INotify::nodename(),
         );
     };
     warn "unable to set the addresses of OVN logical switch port '$iface' - $@" if $@;
diff --git a/src/test/run_test_ovn.pl b/src/test/run_test_ovn.pl
index ddf0f0a..7632bd9 100755
--- a/src/test/run_test_ovn.pl
+++ b/src/test/run_test_ovn.pl
@@ -5,6 +5,7 @@ use warnings;
 
 use lib qw(..);
 
+use File::Path qw(make_path);
 use File::Temp qw(tempdir);
 use JSON;
 use Test::More;
@@ -278,6 +279,82 @@ is_deeply(
     'port_commands: port moved to another vnet',
 );
 
+is_deeply(
+    PVE::Network::SDN::Ovn::chassis_commands('tap100i0', 'node1'),
+    [
+        ['set', 'Logical_Switch_Port', 'tap100i0', 'options:requested-chassis=node1'],
+        ['remove', 'Logical_Switch_Port', 'tap100i0', 'options', 'activation-strategy'],
+    ],
+    'chassis_commands: bound to the local chassis',
+);
+is_deeply(
+    PVE::Network::SDN::Ovn::chassis_commands('tap100i0', 'node2', 'node1'),
+    [[
+        'set',
+        'Logical_Switch_Port',
+        'tap100i0',
+        'options:requested-chassis=node1,node2',
+        'options:activation-strategy=rarp',
+    ]],
+    'chassis_commands: live migration, bound to both chassis until the guest announces itself',
+);
+
+{
+    local $ENV{PVE_MIGRATED_FROM};
+    local $PVE::Network::SDN::Ovn::NODES_DIR = "$tmpdir/nodes";
+    make_path("$tmpdir/nodes/node1/qemu-server", "$tmpdir/nodes/node2/qemu-server");
+    is(
+        PVE::Network::SDN::Ovn::migration_source('tap100i0'),
+        undef,
+        'migration_source: no migration',
+    );
+
+    $ENV{PVE_MIGRATED_FROM} = 'node1';
+    PVE::Tools::file_set_contents("$tmpdir/nodes/node1/qemu-server/100.conf", '');
+    is(
+        PVE::Network::SDN::Ovn::migration_source('tap100i0'),
+        'node1',
+        'migration_source: incoming migration, the configuration is still on the source',
+    );
+    is(PVE::Network::SDN::Ovn::migration_source('veth100i0'), undef, 'migration_source: container');
+
+    rename(
+        "$tmpdir/nodes/node1/qemu-server/100.conf", "$tmpdir/nodes/node2/qemu-server/100.conf",
+    );
+    is(
+        PVE::Network::SDN::Ovn::migration_source('tap100i0'),
+        undef,
+        'migration_source: hotplug after a migration, QEMU kept the variable',
+    );
+}
+
+{
+    my $transactions = [];
+    no warnings 'redefine';
+    local *PVE::Network::SDN::Ovn::nbctl = sub { return '' };
+    local *PVE::Network::SDN::Ovn::nbctl_transaction = sub { push @$transactions, $_[1] };
+
+    PVE::Network::SDN::Ovn::ensure_port(
+        'ovnctl', $controller, 'zone1', 'vnet1', 'tap100i0', 'node2', 'node1',
+    );
+    is_deeply(
+        $transactions->[0]->[-1],
+        PVE::Network::SDN::Ovn::chassis_commands('tap100i0', 'node2', 'node1')->[0],
+        'ensure_port: binds the port to both chassis on an incoming migration',
+    );
+
+    $transactions = [];
+    local *PVE::Network::SDN::Ovn::guest_ips = sub { return [] };
+    PVE::Network::SDN::Ovn::update_port(
+        $controller, 'tap100i0', 'off', {}, 'vnet1', 'BC:24:11:00:00:01', 'node2',
+    );
+    is_deeply(
+        [$transactions->[0]->@[-2, -1]],
+        PVE::Network::SDN::Ovn::chassis_commands('tap100i0', 'node2'),
+        'update_port: binds the port to the local chassis only',
+    );
+}
+
 {
     no warnings 'redefine';
     local *PVE::Network::SDN::Ovn::run_command = sub {
@@ -644,11 +721,12 @@ is_deeply(
 );
 
 is_deeply(
-    PVE::Network::SDN::Ovn::chassis_settings('ovnctl', $controller, '192.168.0.10'),
+    PVE::Network::SDN::Ovn::chassis_settings('ovnctl', $controller, '192.168.0.10', 'node1'),
     {
         'ovn-remote' => $controller->{'sb-connection'},
         'ovn-encap-type' => 'geneve',
         'ovn-encap-ip' => '192.168.0.10',
+        hostname => 'node1',
         'pve-sdn-controller' => 'ovnctl',
     },
     'chassis_settings',
@@ -682,6 +760,7 @@ is_deeply(
         'set',
         'Open_vSwitch',
         '.',
+        'external_ids:hostname=node1',
         'external_ids:ovn-encap-ip=192.168.0.10',
         'external_ids:ovn-encap-type=geneve',
         "external_ids:ovn-remote=$controller->{'sb-connection'}",
@@ -708,6 +787,7 @@ is_deeply(
         'ovn-remote',
         'ovn-encap-type',
         'ovn-encap-ip',
+        'hostname',
         'pve-sdn-controller',
     ]],
     'configure_chassis: detach chassis',
-- 
2.47.3




  parent reply	other threads:[~2026-11-27 10:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 10:28 [RFC PATCH v2 network/manager/docs 00/15] sdn: add OVN zone and controller plugins Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 network 01/15] sdn: controllers: add ovn plugin Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 network 02/15] sdn: zones: " Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 network 03/15] sdn: ovn: sync the northbound database on reload Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 network 04/15] sdn: ovn: configure the chassis on boot and on network reload Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 network 05/15] sdn: ovn: add port security Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 network 06/15] sdn: ovn: allow overriding the port security per vnet Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 network 07/15] sdn: subnets: refuse gateway, snat and dhcp on ovn zones Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 network 08/15] sdn: ovn: support ssl connections to the databases Rémi PAETA
2026-11-27 10:28 ` Rémi PAETA [this message]
2026-11-27 10:28 ` [RFC PATCH v2 manager 10/15] ui: sdn: controller selector: allow filtering by controller type Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 manager 11/15] ui: sdn: add ovn controller Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 manager 12/15] ui: sdn: add ovn zone Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 manager 13/15] ui: sdn: vnet: add port security for ovn zones Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 manager 14/15] ui: sdn: vnet: disable isolate ports " Rémi PAETA
2026-11-27 10:28 ` [RFC PATCH v2 docs 15/15] sdn: document ovn zones and controllers Rémi PAETA

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127102836.313797-10-remi.paeta@comaite.com \
    --to=remi.paeta@comaite.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal