@@ -36,6 +36,7 @@
#include "lport.h"
#include "ovn-controller.h"
#include "patch.h"
+#include "ovsport.h"
VLOG_DEFINE_THIS_MODULE(binding);
@@ -175,17 +176,11 @@ get_qos_params(const struct sbrec_port_binding *pb, struct hmap *queue_map,
static void
add_ovs_qos_table_entry(struct ovsdb_idl_txn *ovs_idl_txn,
const struct ovsrec_qos_table *qos_table,
- const struct ovsrec_port_table *port_table,
+ struct ovsdb_idl_index *ovsrec_port_by_name,
struct qos_queue *sb_info)
{
- const struct ovsrec_port *port = NULL, *iter;
- OVSREC_PORT_TABLE_FOR_EACH (iter, port_table) {
- if (!strcmp(iter->name, sb_info->port_name)) {
- port = iter;
- break;
- }
- }
-
+ const struct ovsrec_port *port =
+ ovsport_lookup_by_name(ovsrec_port_by_name, sb_info->port_name);
if (!port) {
return;
}
@@ -257,9 +252,9 @@ add_ovs_qos_table_entry(struct ovsdb_idl_txn *ovs_idl_txn,
}
static void
-remove_stale_ovs_qos_entry(const struct ovsrec_port_table *port_table,
- const struct ovsrec_qos_table *qos_table,
+remove_stale_ovs_qos_entry(const struct ovsrec_qos_table *qos_table,
const struct sbrec_port_binding_table *pb_table,
+ struct ovsdb_idl_index *ovsrec_port_by_qos,
struct smap *egress_ifaces)
{
const struct ovsrec_qos *qos, *qos_next;
@@ -268,14 +263,8 @@ remove_stale_ovs_qos_entry(const struct ovsrec_port_table *port_table,
continue;
}
- const struct ovsrec_port *port = NULL, *iter;
- OVSREC_PORT_TABLE_FOR_EACH (iter, port_table) {
- if (iter->qos == qos) {
- port = iter;
- break;
- }
- }
-
+ const struct ovsrec_port *port =
+ ovsport_lookup_by_qos(ovsrec_port_by_qos, qos);
struct ovsrec_queue *queue = qos->value_queues[0];
bool stale = true;
const struct sbrec_port_binding *pb;
@@ -323,22 +312,24 @@ remove_stale_ovs_qos_entry(const struct ovsrec_port_table *port_table,
static void
configure_ovs_qos(struct hmap *queue_map,
struct ovsdb_idl_txn *ovs_idl_txn,
- const struct ovsrec_port_table *port_table,
const struct ovsrec_qos_table *qos_table,
const struct sbrec_port_binding_table *pb_table,
+ struct ovsdb_idl_index *ovsrec_port_by_name,
+ struct ovsdb_idl_index *ovsrec_port_by_qos,
struct smap *egress_ifaces)
{
struct qos_queue *sb_info;
HMAP_FOR_EACH (sb_info, node, queue_map) {
/* Add new QoS entries. */
- add_ovs_qos_table_entry(ovs_idl_txn, qos_table, port_table, sb_info);
+ add_ovs_qos_table_entry(ovs_idl_txn, qos_table,
+ ovsrec_port_by_name, sb_info);
}
if (ovs_idl_txn) {
/* Remove stale QoS entries. */
- remove_stale_ovs_qos_entry(port_table, qos_table, pb_table,
- egress_ifaces);
+ remove_stale_ovs_qos_entry(qos_table, pb_table,
+ ovsrec_port_by_qos, egress_ifaces);
}
}
@@ -2035,8 +2026,10 @@ binding_run(struct binding_ctx_in *b_ctx_in, struct binding_ctx_out *b_ctx_out)
shash_destroy(&bridge_mappings);
configure_ovs_qos(&qos_map, b_ctx_in->ovs_idl_txn,
- b_ctx_in->port_table, b_ctx_in->qos_table,
+ b_ctx_in->qos_table,
b_ctx_in->port_binding_table,
+ b_ctx_in->ovsrec_port_by_name,
+ b_ctx_in->ovsrec_port_by_qos,
b_ctx_out->egress_ifaces);
destroy_qos_map(&qos_map);
@@ -2509,8 +2502,10 @@ binding_handle_ovs_interface_changes(struct binding_ctx_in *b_ctx_in,
if (handled) {
configure_ovs_qos(&qos_map, b_ctx_in->ovs_idl_txn,
- b_ctx_in->port_table, b_ctx_in->qos_table,
+ b_ctx_in->qos_table,
b_ctx_in->port_binding_table,
+ b_ctx_in->ovsrec_port_by_name,
+ b_ctx_in->ovsrec_port_by_qos,
b_ctx_out->egress_ifaces);
}
destroy_qos_map(&qos_map);
@@ -3033,8 +3028,10 @@ delete_done:
if (handled) {
configure_ovs_qos(&qos_map, b_ctx_in->ovs_idl_txn,
- b_ctx_in->port_table, b_ctx_in->qos_table,
+ b_ctx_in->qos_table,
b_ctx_in->port_binding_table,
+ b_ctx_in->ovsrec_port_by_name,
+ b_ctx_in->ovsrec_port_by_qos,
b_ctx_out->egress_ifaces);
}
@@ -46,7 +46,8 @@ struct binding_ctx_in {
struct ovsdb_idl_index *sbrec_datapath_binding_by_key;
struct ovsdb_idl_index *sbrec_port_binding_by_datapath;
struct ovsdb_idl_index *sbrec_port_binding_by_name;
- const struct ovsrec_port_table *port_table;
+ struct ovsdb_idl_index *ovsrec_port_by_name;
+ struct ovsdb_idl_index *ovsrec_port_by_qos;
const struct ovsrec_qos_table *qos_table;
const struct sbrec_port_binding_table *port_binding_table;
const struct ovsrec_bridge *br_int;
@@ -1494,9 +1494,6 @@ init_binding_ctx(struct engine_node *node,
= chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
ovs_assert(chassis);
- const struct ovsrec_port_table *port_table =
- EN_OVSDB_GET(engine_get_input("OVS_port", node));
-
struct ed_type_ovs_interface_shadow *iface_shadow =
engine_get_input_data("ovs_interface_shadow", node);
@@ -1521,6 +1518,14 @@ init_binding_ctx(struct engine_node *node,
engine_get_input("SB_port_binding", node),
"datapath");
+ struct ovsdb_idl_index *ovsrec_port_by_name =
+ engine_ovsdb_node_get_index(
+ engine_get_input("OVS_port", node), "name");
+
+ struct ovsdb_idl_index *ovsrec_port_by_qos =
+ engine_ovsdb_node_get_index(
+ engine_get_input("OVS_port", node), "qos");
+
struct controller_engine_ctx *ctrl_ctx = engine_get_context()->client_ctx;
b_ctx_in->ovnsb_idl_txn = engine_get_context()->ovnsb_idl_txn;
@@ -1528,7 +1533,8 @@ init_binding_ctx(struct engine_node *node,
b_ctx_in->sbrec_datapath_binding_by_key = sbrec_datapath_binding_by_key;
b_ctx_in->sbrec_port_binding_by_datapath = sbrec_port_binding_by_datapath;
b_ctx_in->sbrec_port_binding_by_name = sbrec_port_binding_by_name;
- b_ctx_in->port_table = port_table;
+ b_ctx_in->ovsrec_port_by_name = ovsrec_port_by_name;
+ b_ctx_in->ovsrec_port_by_qos = ovsrec_port_by_qos;
b_ctx_in->iface_table = iface_shadow->iface_table;
b_ctx_in->iface_table_external_ids_old =
&iface_shadow->iface_table_external_ids_old;
@@ -4471,6 +4477,9 @@ main(int argc, char *argv[])
struct ovsdb_idl_index *ovsrec_port_by_name
= ovsdb_idl_index_create1(ovs_idl_loop.idl,
&ovsrec_port_col_name);
+ struct ovsdb_idl_index *ovsrec_port_by_qos
+ = ovsdb_idl_index_create1(ovs_idl_loop.idl,
+ &ovsrec_port_col_qos);
struct ovsdb_idl_index *ovsrec_flow_sample_collector_set_by_id
= ovsdb_idl_index_create2(ovs_idl_loop.idl,
&ovsrec_flow_sample_collector_set_col_bridge,
@@ -4825,6 +4834,8 @@ main(int argc, char *argv[])
sbrec_chassis_template_var_index_by_chassis);
engine_ovsdb_node_add_index(&en_ovs_flow_sample_collector_set, "id",
ovsrec_flow_sample_collector_set_by_id);
+ engine_ovsdb_node_add_index(&en_ovs_port, "name", ovsrec_port_by_name);
+ engine_ovsdb_node_add_index(&en_ovs_port, "qos", ovsrec_port_by_qos);
struct ed_type_lflow_output *lflow_output_data =
engine_get_internal_data(&en_lflow_output);
@@ -216,6 +216,38 @@ ovsrec_port * ovsport_lookup_by_interface(
interfaces, 1);
}
+const struct ovsrec_port *
+ovsport_lookup_by_name(struct ovsdb_idl_index *ovsrec_port_by_name,
+ const char *name)
+{
+ const struct ovsrec_port *port =
+ ovsrec_port_index_init_row(ovsrec_port_by_name);
+ ovsrec_port_index_set_name(port, name);
+
+ const struct ovsrec_port *retval =
+ ovsrec_port_index_find(ovsrec_port_by_name, port);
+
+ ovsrec_port_index_destroy_row(port);
+
+ return retval;
+}
+
+const struct ovsrec_port *
+ovsport_lookup_by_qos(struct ovsdb_idl_index *ovsrec_port_by_qos,
+ const struct ovsrec_qos *qos)
+{
+ const struct ovsrec_port *port =
+ ovsrec_port_index_init_row(ovsrec_port_by_qos);
+ ovsrec_port_index_set_qos(port, qos);
+
+ const struct ovsrec_port *retval =
+ ovsrec_port_index_find(ovsrec_port_by_qos, port);
+
+ ovsrec_port_index_destroy_row(port);
+
+ return retval;
+}
+
/* Update an interface map column with the key/value pairs present in the
* provided smap, only applying changes when necessary. */
static void
@@ -33,6 +33,7 @@ struct ovsrec_bridge;
struct ovsrec_port;
struct ovsrec_interface;
struct ovsdb_idl_index;
+struct ovsrec_qos;
void ovsport_create(struct ovsdb_idl_txn *ovs_idl_txn,
const struct ovsrec_bridge *bridge,
@@ -56,5 +57,9 @@ const struct ovsrec_port * ovsport_lookup_by_interfaces(
const size_t n_interfaces);
const struct ovsrec_port * ovsport_lookup_by_interface(
struct ovsdb_idl_index *, struct ovsrec_interface *);
+const struct ovsrec_port * ovsport_lookup_by_name(
+ struct ovsdb_idl_index *, const char *);
+const struct ovsrec_port * ovsport_lookup_by_qos(
+ struct ovsdb_idl_index *, const struct ovsrec_qos *);
#endif /* lib/ovsport.h */
Introduce ovsport_lookup_by_name and ovsport_lookup_by_qos routines in order to speed-up ovs port lookup based on port name or qos. Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> --- controller/binding.c | 49 +++++++++++++++++-------------------- controller/binding.h | 3 ++- controller/ovn-controller.c | 19 +++++++++++--- controller/ovsport.c | 32 ++++++++++++++++++++++++ controller/ovsport.h | 5 ++++ 5 files changed, 77 insertions(+), 31 deletions(-)