Re: [ovs-dev] [PATCH ovn 3/5] northd: Move port group processing to its separate module.
On Thu, Aug 10, 2023 at 5:45 AM Dumitru Ceara wrote: > > No functional differences in this commit, just abstract out the > processing a bit. > > Signed-off-by: Dumitru Ceara > --- > northd/automake.mk |2 > northd/en-port-group.c | 237 ++ > northd/en-port-group.h | 63 > northd/northd.c| 246 > northd/northd.h| 26 + > 5 files changed, 350 insertions(+), 224 deletions(-) > create mode 100644 northd/en-port-group.c > create mode 100644 northd/en-port-group.h > > diff --git a/northd/automake.mk b/northd/automake.mk > index b17f1fdb54..0fc634b4b4 100644 > --- a/northd/automake.mk > +++ b/northd/automake.mk > @@ -14,6 +14,8 @@ northd_ovn_northd_SOURCES = \ > northd/en-lflow.h \ > northd/en-northd-output.c \ > northd/en-northd-output.h \ > + northd/en-port-group.c \ > + northd/en-port-group.h \ > northd/en-sync-sb.c \ > northd/en-sync-sb.h \ > northd/en-sync-from-sb.c \ > diff --git a/northd/en-port-group.c b/northd/en-port-group.c > new file mode 100644 > index 00..b83926c351 > --- /dev/null > +++ b/northd/en-port-group.c > @@ -0,0 +1,237 @@ > +/* > + * Copyright (c) 2023, Red Hat, Inc. > + * > + * Licensed under the Apache License, Version 2.0 (the "License"); > + * you may not use this file except in compliance with the License. > + * You may obtain a copy of the License at: > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > + * See the License for the specific language governing permissions and > + * limitations under the License. > + */ > + > +#include > + > +#include "openvswitch/vlog.h" > + > +#include "en-port-group.h" > +#include "northd.h" > + > +VLOG_DEFINE_THIS_MODULE(en_port_group); > + > +static struct ls_port_group *ls_port_group_create( > +struct ls_port_group_table *, > +const struct nbrec_logical_switch *, > +const struct sbrec_datapath_binding *); > + > +static void ls_port_group_destroy(struct ls_port_group_table *, > + struct ls_port_group *); > + > +static struct ls_port_group_record *ls_port_group_record_add( > +struct ls_port_group *, > +const struct nbrec_port_group *, > +const char *port_name); > + > +static void ls_port_group_record_destroy( > +struct ls_port_group *, > +struct ls_port_group_record *); > + > +void > +ls_port_group_table_init(struct ls_port_group_table *table) > +{ > +*table = (struct ls_port_group_table) { > +.entries = HMAP_INITIALIZER(>entries), > +}; > +} > + > +void > +ls_port_group_table_clear(struct ls_port_group_table *table) > +{ > +struct ls_port_group *ls_pg; > +HMAP_FOR_EACH_SAFE (ls_pg, key_node, >entries) { > +ls_port_group_destroy(table, ls_pg); > +} > +} > + > +void > +ls_port_group_table_destroy(struct ls_port_group_table *table) > +{ > +ls_port_group_table_clear(table); > +hmap_destroy(>entries); > +} > + > +struct ls_port_group * > +ls_port_group_table_find(const struct ls_port_group_table *table, > + const struct nbrec_logical_switch *nbs) > +{ > +struct ls_port_group *ls_pg; > + > +HMAP_FOR_EACH_WITH_HASH (ls_pg, key_node, uuid_hash(>header_.uuid), > + >entries) { > +if (nbs == ls_pg->nbs) { > +return ls_pg; > +} > +} > +return NULL; > +} > + > +void > +ls_port_group_table_build(struct ls_port_group_table *ls_port_groups, > + const struct nbrec_port_group_table *pg_table, > + const struct hmap *ls_ports) > +{ > +const struct nbrec_port_group *nb_pg; > +NBREC_PORT_GROUP_TABLE_FOR_EACH (nb_pg, pg_table) { > +for (size_t i = 0; i < nb_pg->n_ports; i++) { > +const char *port_name = nb_pg->ports[i]->name; > +const struct ovn_datapath *od = > +northd_get_datapath_for_port(ls_ports, port_name); > + > +if (!od) { > +static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); > +VLOG_ERR_RL(, "lport %s in port group %s not found.", > +port_name, nb_pg->name); > +continue; > +} > + > +if (!od->nbs) { > +static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); > +VLOG_WARN_RL(, "lport %s in port group %s has no lswitch.", > + nb_pg->ports[i]->name, > + nb_pg->name); > +continue; > +} > + > +struct ls_port_group *ls_pg = > +
Re: [ovs-dev] [PATCH ovn 3/5] northd: Move port group processing to its separate module.
On Thu, Aug 10, 2023 at 2:45 PM Dumitru Ceara wrote: > No functional differences in this commit, just abstract out the > processing a bit. > > Signed-off-by: Dumitru Ceara > --- > northd/automake.mk |2 > northd/en-port-group.c | 237 > ++ > northd/en-port-group.h | 63 > northd/northd.c| 246 > > northd/northd.h| 26 + > 5 files changed, 350 insertions(+), 224 deletions(-) > create mode 100644 northd/en-port-group.c > create mode 100644 northd/en-port-group.h > > diff --git a/northd/automake.mk b/northd/automake.mk > index b17f1fdb54..0fc634b4b4 100644 > --- a/northd/automake.mk > +++ b/northd/automake.mk > @@ -14,6 +14,8 @@ northd_ovn_northd_SOURCES = \ > northd/en-lflow.h \ > northd/en-northd-output.c \ > northd/en-northd-output.h \ > + northd/en-port-group.c \ > + northd/en-port-group.h \ > northd/en-sync-sb.c \ > northd/en-sync-sb.h \ > northd/en-sync-from-sb.c \ > diff --git a/northd/en-port-group.c b/northd/en-port-group.c > new file mode 100644 > index 00..b83926c351 > --- /dev/null > +++ b/northd/en-port-group.c > @@ -0,0 +1,237 @@ > +/* > + * Copyright (c) 2023, Red Hat, Inc. > + * > + * Licensed under the Apache License, Version 2.0 (the "License"); > + * you may not use this file except in compliance with the License. > + * You may obtain a copy of the License at: > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or > implied. > + * See the License for the specific language governing permissions and > + * limitations under the License. > + */ > + > +#include > + > +#include "openvswitch/vlog.h" > + > +#include "en-port-group.h" > +#include "northd.h" > + > +VLOG_DEFINE_THIS_MODULE(en_port_group); > + > +static struct ls_port_group *ls_port_group_create( > +struct ls_port_group_table *, > +const struct nbrec_logical_switch *, > +const struct sbrec_datapath_binding *); > + > +static void ls_port_group_destroy(struct ls_port_group_table *, > + struct ls_port_group *); > + > +static struct ls_port_group_record *ls_port_group_record_add( > +struct ls_port_group *, > +const struct nbrec_port_group *, > +const char *port_name); > + > +static void ls_port_group_record_destroy( > +struct ls_port_group *, > +struct ls_port_group_record *); > + > +void > +ls_port_group_table_init(struct ls_port_group_table *table) > +{ > +*table = (struct ls_port_group_table) { > +.entries = HMAP_INITIALIZER(>entries), > +}; > +} > + > +void > +ls_port_group_table_clear(struct ls_port_group_table *table) > +{ > +struct ls_port_group *ls_pg; > +HMAP_FOR_EACH_SAFE (ls_pg, key_node, >entries) { > +ls_port_group_destroy(table, ls_pg); > +} > +} > + > +void > +ls_port_group_table_destroy(struct ls_port_group_table *table) > +{ > +ls_port_group_table_clear(table); > +hmap_destroy(>entries); > +} > + > +struct ls_port_group * > +ls_port_group_table_find(const struct ls_port_group_table *table, > + const struct nbrec_logical_switch *nbs) > +{ > +struct ls_port_group *ls_pg; > + > +HMAP_FOR_EACH_WITH_HASH (ls_pg, key_node, > uuid_hash(>header_.uuid), > + >entries) { > +if (nbs == ls_pg->nbs) { > +return ls_pg; > +} > +} > +return NULL; > +} > + > +void > +ls_port_group_table_build(struct ls_port_group_table *ls_port_groups, > + const struct nbrec_port_group_table *pg_table, > + const struct hmap *ls_ports) > +{ > +const struct nbrec_port_group *nb_pg; > +NBREC_PORT_GROUP_TABLE_FOR_EACH (nb_pg, pg_table) { > +for (size_t i = 0; i < nb_pg->n_ports; i++) { > +const char *port_name = nb_pg->ports[i]->name; > +const struct ovn_datapath *od = > +northd_get_datapath_for_port(ls_ports, port_name); > + > +if (!od) { > +static struct vlog_rate_limit rl = > VLOG_RATE_LIMIT_INIT(1, 1); > +VLOG_ERR_RL(, "lport %s in port group %s not found.", > +port_name, nb_pg->name); > +continue; > +} > + > +if (!od->nbs) { > +static struct vlog_rate_limit rl = > VLOG_RATE_LIMIT_INIT(1, 1); > +VLOG_WARN_RL(, "lport %s in port group %s has no > lswitch.", > + nb_pg->ports[i]->name, > + nb_pg->name); > +continue; > +} > + > +struct ls_port_group *ls_pg = > +
[ovs-dev] [PATCH ovn 3/5] northd: Move port group processing to its separate module.
No functional differences in this commit, just abstract out the processing a bit. Signed-off-by: Dumitru Ceara --- northd/automake.mk |2 northd/en-port-group.c | 237 ++ northd/en-port-group.h | 63 northd/northd.c| 246 northd/northd.h| 26 + 5 files changed, 350 insertions(+), 224 deletions(-) create mode 100644 northd/en-port-group.c create mode 100644 northd/en-port-group.h diff --git a/northd/automake.mk b/northd/automake.mk index b17f1fdb54..0fc634b4b4 100644 --- a/northd/automake.mk +++ b/northd/automake.mk @@ -14,6 +14,8 @@ northd_ovn_northd_SOURCES = \ northd/en-lflow.h \ northd/en-northd-output.c \ northd/en-northd-output.h \ + northd/en-port-group.c \ + northd/en-port-group.h \ northd/en-sync-sb.c \ northd/en-sync-sb.h \ northd/en-sync-from-sb.c \ diff --git a/northd/en-port-group.c b/northd/en-port-group.c new file mode 100644 index 00..b83926c351 --- /dev/null +++ b/northd/en-port-group.c @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2023, Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "openvswitch/vlog.h" + +#include "en-port-group.h" +#include "northd.h" + +VLOG_DEFINE_THIS_MODULE(en_port_group); + +static struct ls_port_group *ls_port_group_create( +struct ls_port_group_table *, +const struct nbrec_logical_switch *, +const struct sbrec_datapath_binding *); + +static void ls_port_group_destroy(struct ls_port_group_table *, + struct ls_port_group *); + +static struct ls_port_group_record *ls_port_group_record_add( +struct ls_port_group *, +const struct nbrec_port_group *, +const char *port_name); + +static void ls_port_group_record_destroy( +struct ls_port_group *, +struct ls_port_group_record *); + +void +ls_port_group_table_init(struct ls_port_group_table *table) +{ +*table = (struct ls_port_group_table) { +.entries = HMAP_INITIALIZER(>entries), +}; +} + +void +ls_port_group_table_clear(struct ls_port_group_table *table) +{ +struct ls_port_group *ls_pg; +HMAP_FOR_EACH_SAFE (ls_pg, key_node, >entries) { +ls_port_group_destroy(table, ls_pg); +} +} + +void +ls_port_group_table_destroy(struct ls_port_group_table *table) +{ +ls_port_group_table_clear(table); +hmap_destroy(>entries); +} + +struct ls_port_group * +ls_port_group_table_find(const struct ls_port_group_table *table, + const struct nbrec_logical_switch *nbs) +{ +struct ls_port_group *ls_pg; + +HMAP_FOR_EACH_WITH_HASH (ls_pg, key_node, uuid_hash(>header_.uuid), + >entries) { +if (nbs == ls_pg->nbs) { +return ls_pg; +} +} +return NULL; +} + +void +ls_port_group_table_build(struct ls_port_group_table *ls_port_groups, + const struct nbrec_port_group_table *pg_table, + const struct hmap *ls_ports) +{ +const struct nbrec_port_group *nb_pg; +NBREC_PORT_GROUP_TABLE_FOR_EACH (nb_pg, pg_table) { +for (size_t i = 0; i < nb_pg->n_ports; i++) { +const char *port_name = nb_pg->ports[i]->name; +const struct ovn_datapath *od = +northd_get_datapath_for_port(ls_ports, port_name); + +if (!od) { +static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); +VLOG_ERR_RL(, "lport %s in port group %s not found.", +port_name, nb_pg->name); +continue; +} + +if (!od->nbs) { +static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); +VLOG_WARN_RL(, "lport %s in port group %s has no lswitch.", + nb_pg->ports[i]->name, + nb_pg->name); +continue; +} + +struct ls_port_group *ls_pg = +ls_port_group_table_find(ls_port_groups, od->nbs); +if (!ls_pg) { +ls_pg = ls_port_group_create(ls_port_groups, od->nbs, od->sb); +} +ls_port_group_record_add(ls_pg, nb_pg, port_name); +} +} +} + +/* Each port group in Port_Group table in OVN_Northbound has a corresponding + * entry in Port_Group