nit: for the commit title: s/Template_Var/Chassis_Template_Var Acked-by: Han Zhou <[email protected]>
On Tue, Nov 22, 2022 at 6:14 AM Dumitru Ceara <[email protected]> wrote: > > Propagate the contents of the NB table to the Southbound. > > Signed-off-by: Dumitru Ceara <[email protected]> > --- > Note: > - ovn-trace doesn't support template variables (yet). > > V3: > - Addressed Mark's comments: > - Removed template-var.[ch] and just used shash instead. > - Added note to the documentation about non-instantiated > template variables. > V2: > - Fixed TEMPLATE_VAR_TABLE_INITIALIZER definition so that GCC doesn't > complain anymore. > - Addressed Han's comments: > - Rename tables to Chassis_Template_Var. > - Fix man page. > - Simplify function prototypes. > - Changed schema as suggested by Ilya. > --- > northd/en-northd.c | 4 ++++ > northd/inc-proc-northd.c | 8 ++++++-- > northd/northd.c | 39 +++++++++++++++++++++++++++++++++++++++ > northd/northd.h | 4 ++++ > ovn-nb.ovsschema | 17 ++++++++++++++--- > ovn-nb.xml | 34 ++++++++++++++++++++++++++++++++++ > ovn-sb.ovsschema | 12 ++++++++++-- > ovn-sb.xml | 15 +++++++++++++++ > tests/ovn-northd.at | 35 +++++++++++++++++++++++++++++++++++ > utilities/ovn-nbctl.c | 3 +++ > utilities/ovn-sbctl.c | 3 +++ > 11 files changed, 167 insertions(+), 7 deletions(-) > > diff --git a/northd/en-northd.c b/northd/en-northd.c > index 7fe83db642..030ee25d8f 100644 > --- a/northd/en-northd.c > +++ b/northd/en-northd.c > @@ -80,6 +80,8 @@ void en_northd_run(struct engine_node *node, void *data) > EN_OVSDB_GET(engine_get_input("NB_acl", node)); > input_data.nbrec_static_mac_binding_table = > EN_OVSDB_GET(engine_get_input("NB_static_mac_binding", node)); > + input_data.nbrec_chassis_template_var_table = > + EN_OVSDB_GET(engine_get_input("NB_chassis_template_var", node)); > > input_data.sbrec_sb_global_table = > EN_OVSDB_GET(engine_get_input("SB_sb_global", node)); > @@ -113,6 +115,8 @@ void en_northd_run(struct engine_node *node, void *data) > EN_OVSDB_GET(engine_get_input("SB_chassis_private", node)); > input_data.sbrec_static_mac_binding_table = > EN_OVSDB_GET(engine_get_input("SB_static_mac_binding", node)); > + input_data.sbrec_chassis_template_var_table = > + EN_OVSDB_GET(engine_get_input("SB_chassis_template_var", node)); > > northd_run(&input_data, data, > eng_ctx->ovnnb_idl_txn, > diff --git a/northd/inc-proc-northd.c b/northd/inc-proc-northd.c > index 54e0ad3b05..da791f035d 100644 > --- a/northd/inc-proc-northd.c > +++ b/northd/inc-proc-northd.c > @@ -64,7 +64,8 @@ VLOG_DEFINE_THIS_MODULE(inc_proc_northd); > NB_NODE(ha_chassis_group, "ha_chassis_group") \ > NB_NODE(ha_chassis, "ha_chassis") \ > NB_NODE(bfd, "bfd") \ > - NB_NODE(static_mac_binding, "static_mac_binding") > + NB_NODE(static_mac_binding, "static_mac_binding") \ > + NB_NODE(chassis_template_var, "chassis_template_var") > > enum nb_engine_node { > #define NB_NODE(NAME, NAME_STR) NB_##NAME, > @@ -114,7 +115,8 @@ VLOG_DEFINE_THIS_MODULE(inc_proc_northd); > SB_NODE(load_balancer, "load_balancer") \ > SB_NODE(bfd, "bfd") \ > SB_NODE(fdb, "fdb") \ > - SB_NODE(static_mac_binding, "static_mac_binding") > + SB_NODE(static_mac_binding, "static_mac_binding") \ > + SB_NODE(chassis_template_var, "chassis_template_var") > > enum sb_engine_node { > #define SB_NODE(NAME, NAME_STR) SB_##NAME, > @@ -186,6 +188,7 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb, > engine_add_input(&en_northd, &en_nb_ha_chassis_group, NULL); > engine_add_input(&en_northd, &en_nb_ha_chassis, NULL); > engine_add_input(&en_northd, &en_nb_static_mac_binding, NULL); > + engine_add_input(&en_northd, &en_nb_chassis_template_var, NULL); > > engine_add_input(&en_northd, &en_sb_sb_global, NULL); > engine_add_input(&en_northd, &en_sb_chassis, NULL); > @@ -215,6 +218,7 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb, > engine_add_input(&en_northd, &en_sb_load_balancer, NULL); > engine_add_input(&en_northd, &en_sb_fdb, NULL); > engine_add_input(&en_northd, &en_sb_static_mac_binding, NULL); > + engine_add_input(&en_northd, &en_sb_chassis_template_var, NULL); > engine_add_input(&en_mac_binding_aging, &en_nb_nb_global, NULL); > engine_add_input(&en_mac_binding_aging, &en_sb_mac_binding, NULL); > engine_add_input(&en_mac_binding_aging, &en_northd, NULL); > diff --git a/northd/northd.c b/northd/northd.c > index 00ff8f9333..123127e9c1 100644 > --- a/northd/northd.c > +++ b/northd/northd.c > @@ -15406,6 +15406,43 @@ sync_dns_entries(struct northd_input *input_data, > } > hmap_destroy(&dns_map); > } > + > +static void > +sync_template_vars(struct northd_input *input_data, > + struct ovsdb_idl_txn *ovnsb_txn) > +{ > + struct shash nb_tvs = SHASH_INITIALIZER(&nb_tvs); > + > + const struct nbrec_chassis_template_var *nb_tv; > + const struct sbrec_chassis_template_var *sb_tv; > + > + NBREC_CHASSIS_TEMPLATE_VAR_TABLE_FOR_EACH ( > + nb_tv, input_data->nbrec_chassis_template_var_table) { > + shash_add(&nb_tvs, nb_tv->chassis, nb_tv); > + } > + > + SBREC_CHASSIS_TEMPLATE_VAR_TABLE_FOR_EACH_SAFE ( > + sb_tv, input_data->sbrec_chassis_template_var_table) { > + nb_tv = shash_find_and_delete(&nb_tvs, sb_tv->chassis); > + if (!nb_tv) { > + sbrec_chassis_template_var_delete(sb_tv); > + continue; > + } > + if (!smap_equal(&sb_tv->variables, &nb_tv->variables)) { > + sbrec_chassis_template_var_set_variables(sb_tv, > + &nb_tv->variables); > + } > + } > + > + struct shash_node *node; > + SHASH_FOR_EACH (node, &nb_tvs) { > + nb_tv = node->data; > + sb_tv = sbrec_chassis_template_var_insert(ovnsb_txn); > + sbrec_chassis_template_var_set_chassis(sb_tv, nb_tv->chassis); > + sbrec_chassis_template_var_set_variables(sb_tv, &nb_tv->variables); > + } > + shash_destroy(&nb_tvs); > +} > > static void > destroy_datapaths_and_ports(struct hmap *datapaths, struct hmap *ports, > @@ -15922,6 +15959,8 @@ ovnnb_db_run(struct northd_input *input_data, > sync_port_groups(input_data, ovnsb_txn, &data->port_groups); > sync_meters(input_data, ovnsb_txn, &data->meter_groups); > sync_dns_entries(input_data, ovnsb_txn, &data->datapaths); > + sync_template_vars(input_data, ovnsb_txn); > + > cleanup_stale_fdb_entries(input_data, &data->datapaths); > stopwatch_stop(CLEAR_LFLOWS_CTX_STOPWATCH_NAME, time_msec()); > > diff --git a/northd/northd.h b/northd/northd.h > index da90e28155..1935c80d40 100644 > --- a/northd/northd.h > +++ b/northd/northd.h > @@ -36,6 +36,8 @@ struct northd_input { > const struct nbrec_acl_table *nbrec_acl_table; > const struct nbrec_static_mac_binding_table > *nbrec_static_mac_binding_table; > + const struct nbrec_chassis_template_var_table > + *nbrec_chassis_template_var_table; > > /* Southbound table references */ > const struct sbrec_sb_global_table *sbrec_sb_global_table; > @@ -55,6 +57,8 @@ struct northd_input { > const struct sbrec_chassis_private_table *sbrec_chassis_private_table; > const struct sbrec_static_mac_binding_table > *sbrec_static_mac_binding_table; > + const struct sbrec_chassis_template_var_table > + *sbrec_chassis_template_var_table; > > /* Indexes */ > struct ovsdb_idl_index *sbrec_chassis_by_name; > diff --git a/ovn-nb.ovsschema b/ovn-nb.ovsschema > index 174364c8b1..6f9d38f47b 100644 > --- a/ovn-nb.ovsschema > +++ b/ovn-nb.ovsschema > @@ -1,7 +1,7 @@ > { > "name": "OVN_Northbound", > - "version": "6.3.0", > - "cksum": "4042813038 31869", > + "version": "6.4.0", > + "cksum": "3512158873 32360", > "tables": { > "NB_Global": { > "columns": { > @@ -620,6 +620,17 @@ > "mac": {"type": "string"}, > "override_dynamic_mac": {"type": "boolean"}}, > "indexes": [["logical_port", "ip"]], > - "isRoot": true} > + "isRoot": true}, > + "Chassis_Template_Var": { > + "columns": { > + "chassis": {"type": "string"}, > + "variables": { > + "type": {"key": "string", "value": "string", > + "min": 0, "max": "unlimited"}}, > + "external_ids": { > + "type": {"key": "string", "value": "string", > + "min": 0, "max": "unlimited"}}}, > + "indexes": [["chassis"]], > + "isRoot": true} > } > } > diff --git a/ovn-nb.xml b/ovn-nb.xml > index 0a4340529a..553c0e48c3 100644 > --- a/ovn-nb.xml > +++ b/ovn-nb.xml > @@ -4444,4 +4444,38 @@ > </column> > </group> > </table> > + > + <table name="Chassis_Template_Var"> > + <p> > + One record per chassis, each containing a map, <code>variables</code>, > + between template variable names and their value for that specific > + chassis. A template variable has a name and potentially different > + values on different hypervisors in the OVN cluster. For example, > + two rows, <code>R1 = (.chassis=C1, variables={(N: V1)}</code> and > + <code>R2 = (.chassis=C2, variables={(N: V2)}</code> will make > + <code>ovn-controller</code> running on chassis <code>C1</code> and > + <code>C2</code> interpret the token <code>N</code> either as > + <code>V1</code> (on <code>C1</code>) or as <code>V2</code> (on > + <code>C2</code>). Users can refer to template variables from > + within other logical components, e.g., within ACL, QoS or > + Logical_Router_Policy matches or from Load_Balancer VIP and > + backend definitions. > + </p> > + <p> > + If a template variable is referenced on a chassis for which that > + variable is not defined then <code>ovn-controller</code> running > + on that chassis will just interpret it as a raw string literal. > + </p> > + <column name="chassis"> > + The chassis this set of variable values applies to. > + </column> > + <column name="variables"> > + The set of variable values for a given chassis. > + </column> > + <group title="Common Columns"> > + <column name="external_ids"> > + See <em>External IDs</em> at the beginning of this document. > + </column> > + </group> > + </table> > </database> > diff --git a/ovn-sb.ovsschema b/ovn-sb.ovsschema > index 576ebbdeb0..95c7c2d7e3 100644 > --- a/ovn-sb.ovsschema > +++ b/ovn-sb.ovsschema > @@ -1,7 +1,7 @@ > { > "name": "OVN_Southbound", > - "version": "20.25.0", > - "cksum": "53184112 28845", > + "version": "20.26.0", > + "cksum": "3311869408 29176", > "tables": { > "SB_Global": { > "columns": { > @@ -565,6 +565,14 @@ > "key": {"type": "uuid", > "refTable": "Datapath_Binding"}}}}, > "indexes": [["logical_port", "ip"]], > + "isRoot": true}, > + "Chassis_Template_Var": { > + "columns": { > + "chassis": {"type": "string"}, > + "variables": { > + "type": {"key": "string", "value": "string", > + "min": 0, "max": "unlimited"}}}, > + "indexes": [["chassis"]], > "isRoot": true} > } > } > diff --git a/ovn-sb.xml b/ovn-sb.xml > index 4fe466134a..f156d5de7b 100644 > --- a/ovn-sb.xml > +++ b/ovn-sb.xml > @@ -4847,4 +4847,19 @@ tcp.flags = RST; > The logical datapath to which the logical router port belongs. > </column> > </table> > + > + <table name="Chassis_Template_Var"> > + <p> > + Each record represents the set of template variable instantiations > + for a given chassis and is populated by <code>ovn-northd</code> > + from the contents of the <code>OVN_Northbound.Chassis_Template_Var</code> > + table. > + </p> > + <column name="chassis"> > + The chassis this set of variable values applies to. > + </column> > + <column name="variables"> > + The set of variable values for a given chassis. > + </column> > + </table> > </database> > diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at > index 92b7f4be20..86ab376fd6 100644 > --- a/tests/ovn-northd.at > +++ b/tests/ovn-northd.at > @@ -8007,3 +8007,38 @@ AT_CHECK([grep "lr_in_lb_aff_learn" R1flows | sort], [0], [dnl > > AT_CLEANUP > ]) > + > +OVN_FOR_EACH_NORTHD_NO_HV([ > +AT_SETUP([NB to SB Chassis_Template_Var propagation]) > +AT_KEYWORDS([templates]) > +ovn_start > + > +AT_CHECK([ovn-nbctl create Chassis_Template_Var chassis="hv1"], [0], [ignore]) > +AT_CHECK([ovn-nbctl create Chassis_Template_Var chassis="hv2"], [0], [ignore]) > + > +check ovn-nbctl set Chassis_Template_Var hv1 variables:tv=v1 > +check ovn-nbctl set Chassis_Template_Var hv2 variables:tv=v2 > + > +AS_BOX([Ensure values are propagated to SB]) > +check ovn-nbctl --wait=sb sync > +check_column "tv=v1" sb:Chassis_Template_Var variables chassis="hv1" > +check_column "tv=v2" sb:Chassis_Template_Var variables chassis="hv2" > + > +AS_BOX([Ensure SB is reconciled]) > +check ovn-sbctl --all destroy Chassis_Template_Var > +check ovn-nbctl --wait=sb sync > +check_column "tv=v1" sb:Chassis_Template_Var variables chassis="hv1" > +check_column "tv=v2" sb:Chassis_Template_Var variables chassis="hv2" > + > +AS_BOX([Ensure SB is reconciled - deletion]) > +check ovn-nbctl destroy Chassis_Template_Var hv1 > +check ovn-nbctl --wait=sb sync > +check_column "tv=v2" sb:Chassis_Template_Var variables chassis="hv2" > + > +AS_BOX([Ensure SB is reconciled - cleanup]) > +check ovn-nbctl destroy Chassis_Template_Var hv2 > +check ovn-nbctl --wait=sb sync > +check_row_count sb:Chassis_Template_Var 0 > + > +AT_CLEANUP > +]) > diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c > index 811468dc66..d2dee6b31c 100644 > --- a/utilities/ovn-nbctl.c > +++ b/utilities/ovn-nbctl.c > @@ -7300,6 +7300,9 @@ static const struct ctl_table_class tables[NBREC_N_TABLES] = { > [NBREC_TABLE_NAT].row_ids[0] > = {&nbrec_nat_col_external_ip, NULL, NULL}, > > + [NBREC_TABLE_CHASSIS_TEMPLATE_VAR].row_ids[0] > + = {&nbrec_chassis_template_var_col_chassis, NULL, NULL}, > + > [NBREC_TABLE_CONNECTION].row_ids[0] > = {&nbrec_connection_col_target, NULL, NULL}, > }; > diff --git a/utilities/ovn-sbctl.c b/utilities/ovn-sbctl.c > index f60dde1b67..00b2f785a5 100644 > --- a/utilities/ovn-sbctl.c > +++ b/utilities/ovn-sbctl.c > @@ -1457,6 +1457,9 @@ static const struct ctl_table_class tables[SBREC_N_TABLES] = { > > [SBREC_TABLE_LOAD_BALANCER].row_ids[0] > = {&sbrec_load_balancer_col_name, NULL, NULL}, > + > + [SBREC_TABLE_CHASSIS_TEMPLATE_VAR].row_ids[0] > + = {&sbrec_chassis_template_var_col_chassis, NULL, NULL}, > }; > > static const struct ctl_command_syntax sbctl_commands[] = { > _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
