[ovs-dev] [PATCH v2] ovn-controller: Add datapath-type in chassis:external_ids
Numan Siddique
nusiddiq at redhat.com
Fri Jul 29 13:02:42 UTC 2016
This patch reads the Bridge.datapath_type column value of the integration
bridge and sets it in the external_ids:datapath-type of Chassis table.
This will provide hints to the CMS or clients monitoring OVN SB DB to
determine the datapath type (DPDK or non-DPDK) configured and take some
actions based on it.
One usecase is, OVN neutron plugin can use this information to set the
vif_type (ovs or vhostuser) during the port binding.
Signed-off-by: Numan Siddique <nusiddiq at redhat.com>
---
ovn/controller/chassis.c | 38 ++++++++++++++++++++++++++----
ovn/controller/chassis.h | 3 ++-
ovn/controller/ovn-controller.8.xml | 17 +++++++++++++-
ovn/controller/ovn-controller.c | 2 +-
ovn/ovn-sb.xml | 8 +++++++
tests/ovn-controller.at | 46 +++++++++++++++++++++++++++++++++++++
6 files changed, 106 insertions(+), 8 deletions(-)
v1 -> v2
--------
* Addressed the review comments. Reading the datapath-type from Bridge.datapath_type column
instead of adding a new configuration option.
diff --git a/ovn/controller/chassis.c b/ovn/controller/chassis.c
index a1545ec..86f3ef5 100644
--- a/ovn/controller/chassis.c
+++ b/ovn/controller/chassis.c
@@ -38,6 +38,8 @@ chassis_register_ovs_idl(struct ovsdb_idl *ovs_idl)
{
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_open_vswitch);
ovsdb_idl_add_column(ovs_idl, &ovsrec_open_vswitch_col_external_ids);
+ ovsdb_idl_add_table(ovs_idl, &ovsrec_table_bridge);
+ ovsdb_idl_add_column(ovs_idl, &ovsrec_bridge_col_datapath_type);
}
static const char *
@@ -67,7 +69,8 @@ get_bridge_mappings(const struct smap *ext_ids)
/* Returns this chassis's Chassis record, if it is available and is currently
* amenable to a transaction. */
const struct sbrec_chassis *
-chassis_run(struct controller_ctx *ctx, const char *chassis_id)
+chassis_run(struct controller_ctx *ctx, const char *chassis_id,
+ const struct ovsrec_bridge *br_int)
{
if (!ctx->ovnsb_idl_txn) {
return NULL;
@@ -114,6 +117,8 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id)
}
const char *bridge_mappings = get_bridge_mappings(&cfg->external_ids);
+ const char *datapath_type =
+ br_int && br_int->datapath_type ? br_int->datapath_type : "";
const struct sbrec_chassis *chassis_rec
= get_chassis(ctx->ovnsb_idl, chassis_id);
@@ -125,10 +130,30 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id)
const char *chassis_bridge_mappings
= get_bridge_mappings(&chassis_rec->external_ids);
- if (strcmp(bridge_mappings, chassis_bridge_mappings)) {
+ const char *chassis_datapath_type
+ = smap_get(&chassis_rec->external_ids, "datapath-type");
+ if (!chassis_datapath_type) {
+ chassis_datapath_type = "";
+ }
+
+ if (!strcmp(bridge_mappings, chassis_bridge_mappings)) {
+ bridge_mappings = NULL;
+ }
+ if (!strcmp(datapath_type, chassis_datapath_type)) {
+ datapath_type = NULL;
+ }
+
+ if (bridge_mappings || datapath_type) {
struct smap new_ids;
smap_clone(&new_ids, &chassis_rec->external_ids);
- smap_replace(&new_ids, "ovn-bridge-mappings", bridge_mappings);
+ if (bridge_mappings) {
+ smap_replace(&new_ids, "ovn-bridge-mappings", bridge_mappings);
+ }
+
+ if (datapath_type) {
+ smap_replace(&new_ids, "datapath-type", datapath_type);
+ }
+
sbrec_chassis_verify_external_ids(chassis_rec);
sbrec_chassis_set_external_ids(chassis_rec, &new_ids);
smap_destroy(&new_ids);
@@ -169,12 +194,15 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id)
chassis_id);
if (!chassis_rec) {
- struct smap ext_ids = SMAP_CONST1(&ext_ids, "ovn-bridge-mappings",
- bridge_mappings);
+ struct smap ext_ids = SMAP_INITIALIZER(&ext_ids);
+ smap_add(&ext_ids, "ovn-bridge-mappings", bridge_mappings);
+ smap_add(&ext_ids, "datapath-type", datapath_type);
+
chassis_rec = sbrec_chassis_insert(ctx->ovnsb_idl_txn);
sbrec_chassis_set_name(chassis_rec, chassis_id);
sbrec_chassis_set_hostname(chassis_rec, hostname);
sbrec_chassis_set_external_ids(chassis_rec, &ext_ids);
+ smap_destroy(&ext_ids);
}
int n_encaps = count_1bits(req_tunnels);
diff --git a/ovn/controller/chassis.h b/ovn/controller/chassis.h
index a14da1c..016d71c 100644
--- a/ovn/controller/chassis.h
+++ b/ovn/controller/chassis.h
@@ -24,7 +24,8 @@ struct ovsrec_bridge;
void chassis_register_ovs_idl(struct ovsdb_idl *);
const struct sbrec_chassis *chassis_run(struct controller_ctx *,
- const char *chassis_id);
+ const char *chassis_id,
+ const struct ovsrec_bridge *br_int);
bool chassis_cleanup(struct controller_ctx *, const char *chassis_id);
#endif /* ovn/chassis.h */
diff --git a/ovn/controller/ovn-controller.8.xml b/ovn/controller/ovn-controller.8.xml
index 3fda8e7..d2fd9b4 100644
--- a/ovn/controller/ovn-controller.8.xml
+++ b/ovn/controller/ovn-controller.8.xml
@@ -156,6 +156,21 @@
</dd>
</dl>
+ <p>
+ <code>ovn-controller</code> reads the following values from the
+ <ref table="Bridge" db="Open_vSwitch"/> table of the local OVS integration
+ bridge.
+ </p>
+
+ <dl>
+ <dt><code>datapath-type</code></dt>
+ <dd>
+ This value is populated in <ref key="datapath-type" table="Chassis"
+ column="external_ids" db="OVN_Southbound"/> in the OVN_Southbound
+ database's <ref table="Chassis" db="OVN_Southbound"/> table.
+ </dd>
+ </dl>
+
<h1>Open vSwitch Database Usage</h1>
<p>
@@ -173,7 +188,7 @@
integration bridge as one created by <code>ovn-controller</code> to
reach a remote chassis. Its value is the chassis ID of the remote
chassis.
- </dd>
+ /dd>
<dt>
<code>external-ids:ovn-localnet-port</code> in the <code>Port</code>
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 5c74186..971735a 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -432,7 +432,7 @@ main(int argc, char *argv[])
const struct sbrec_chassis *chassis = NULL;
if (chassis_id) {
- chassis = chassis_run(&ctx, chassis_id);
+ chassis = chassis_run(&ctx, chassis_id, br_int);
encaps_run(&ctx, br_int, chassis_id);
binding_run(&ctx, br_int, chassis_id, &local_datapaths);
}
diff --git a/ovn/ovn-sb.xml b/ovn/ovn-sb.xml
index c5f236e..2512754 100644
--- a/ovn/ovn-sb.xml
+++ b/ovn/ovn-sb.xml
@@ -213,6 +213,14 @@
information.
</column>
+ <column name="external_ids" key="datapath-type">
+ <code>ovn-controller</code> populates this key with the datapath type
+ configured in the <ref table="Bridge" column="datapath_type"/> of the
+ Open_vSwitch database's <ref table="Bridge" db="Open_vSwitch"/> table.
+ Other applications should treat this key as read-only. See
+ <code>ovn-controller</code>(8) for more information.
+ </column>
+
<group title="Common Columns">
The overall purpose of these columns is described under <code>Common
Columns</code> at the beginning of this document.
diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
index a2349a4..e1e47a6 100644
--- a/tests/ovn-controller.at
+++ b/tests/ovn-controller.at
@@ -151,3 +151,49 @@ OVS_APP_EXIT_AND_WAIT_BY_TARGET([$ovs_base/ovn-sb/ovsdb-server-2.ctl], [$ovs_bas
OVS_APP_EXIT_AND_WAIT([ovsdb-server])
AT_CLEANUP
+
+AT_SETUP([ovn-controller - datapath-type])
+AT_KEYWORDS([ovn])
+ovn_init_db ovn-sb
+
+net_add n1
+sim_add hv
+as hv
+ovs-vsctl \
+ -- add-br br-phys \
+ -- add-br br-eth0 \
+ -- add-br br-eth1 \
+ -- add-br br-eth2
+ovn_attach n1 br-phys 192.168.0.1
+
+# Make sure that the datapath_type set in the bridge table
+# is mirrored into the Chassis record in the OVN_Southbound db.
+check_datapath_type () {
+ datapath_type=$1
+ sysid=$(ovs-vsctl get Open_vSwitch . external_ids:system-id)
+ chassis_datapath_type=$(ovn-sbctl get Chassis ${sysid} external_ids:datapath-type | sed -e 's/\"//g')
+ AT_CHECK([test "${datapath_type}" = "${chassis_datapath_type}"])
+}
+
+check_datapath_type ""
+
+ovs-vsctl set Bridge br-int datapath-type=foo
+check_datapath_type foo
+
+# Change "ovn-bridge-mappings" value. It should not change the "datapath-type".
+ovs-vsctl set Open_vSwitch . external_ids:ovn-bridge-mappings=foo-mapping
+check_datapath_type foo
+
+ovs-vsctl set Bridge br-int datapath-type=bar
+check_datapath_type bar
+
+ovs-vsctl set Bridge br-int datapath-type=\"\"
+check_datapath_type ""
+
+# Gracefully terminate daemons
+OVN_CLEANUP_SBOX([hv])
+OVN_CLEANUP_VSWITCH([main])
+as ovn-sb
+OVS_APP_EXIT_AND_WAIT([ovsdb-server])
+
+AT_CLEANUP
--
2.7.4
More information about the dev
mailing list