Re: [ovs-dev] [PATCH ovn 1/5] Add new table Load_Balancer in Southbound database.

2020-10-26 Thread Numan Siddique
On Sat, Oct 24, 2020 at 2:30 AM Mark Michelson  wrote:
>
> On 10/23/20 4:21 PM, Numan Siddique wrote:
> >
> >
> > On Sat, Oct 24, 2020, 1:29 AM Mark Michelson  > > wrote:
> >
> > On 10/21/20 3:25 AM, num...@ovn.org  wrote:
> >  > From: Numan Siddique mailto:num...@ovn.org>>
> >  >
> >  > This patch adds a new table 'Load_Balancer' in SB DB and syncs
> > the Load_Balancer table rows
> >  > from NB DB to SB DB. An upcoming patch will make use of this
> > table for handling the
> >  > load balancer hairpin traffic.
> >  >
> >  > Signed-off-by: Numan Siddique  > >
> >  > ---
> >  >   northd/ovn-northd.c   | 141
> > ++
> >  >   ovn-sb.ovsschema  |  27 +++-
> >  >   ovn-sb.xml|  47 ++
> >  >   tests/ovn-northd.at    |  81
> > 
> >  >   utilities/ovn-sbctl.c |   3 +
> >  >   5 files changed, 297 insertions(+), 2 deletions(-)
> >  >
> >  > diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
> >  > index 5b76868dfb..ea771afda1 100644
> >  > --- a/northd/ovn-northd.c
> >  > +++ b/northd/ovn-northd.c
> >  > @@ -11896,6 +11896,136 @@ sync_dns_entries(struct northd_context
> > *ctx, struct hmap *datapaths)
> >  >   }
> >  >   hmap_destroy(_map);
> >  >   }
> >  > +
> >  > +/*
> >  > + * struct 'sync_lb_info' is used to sync the load balancer
> > records between
> >  > + * OVN Northbound db and Southbound db.
> >  > + */
> >  > +struct sync_lb_info {
> >  > +struct hmap_node hmap_node;
> >  > +const struct nbrec_load_balancer *nlb; /* LB record in the
> > NB db. */
> >  > +const struct sbrec_load_balancer *slb; /* LB record in the
> > SB db. */
> >  > +
> >  > +/* Datapaths to which the LB entry is associated with it. */
> >  > +const struct sbrec_datapath_binding **sbs;
> >  > +size_t n_sbs;
> >  > +};
> >  > +
> >  > +static inline struct sync_lb_info *
> >  > +get_sync_lb_info_from_hmap(struct hmap *sync_lb_map, struct uuid
> > *uuid)
> >  > +{
> >  > +struct sync_lb_info *lb_info;
> >  > +size_t hash = uuid_hash(uuid);
> >  > +HMAP_FOR_EACH_WITH_HASH (lb_info, hmap_node, hash,
> > sync_lb_map) {
> >  > +if (uuid_equals(_info->nlb->header_.uuid, uuid)) {
> >  > +return lb_info;
> >  > +}
> >  > +}
> >  > +
> >  > +return NULL;
> >  > +}
> >  > +
> >  > +static void
> >  > +sync_lb_entries(struct northd_context *ctx, struct hmap *datapaths)
> >  > +{
> >  > +struct hmap lb_map = HMAP_INITIALIZER(_map);
> >  > +struct ovn_datapath *od;
> >  > +
> >  > +HMAP_FOR_EACH (od, key_node, datapaths) {
> >  > +if (!od->nbs || !od->nbs->n_load_balancer) {
> >  > +continue;
> >  > +}
> >  > +
> >  > +for (size_t i = 0; i < od->nbs->n_load_balancer; i++) {
> >  > +struct sync_lb_info *lb_info =
> >  > +get_sync_lb_info_from_hmap(
> >  > +_map,
> > >nbs->load_balancer[i]->header_.uuid);
> >  > +
> >  > +if (!lb_info) {
> >  > +size_t hash = uuid_hash(
> >  > +>nbs->load_balancer[i]->header_.uuid);
> >  > +lb_info = xzalloc(sizeof *lb_info);;
> >  > +lb_info->nlb = od->nbs->load_balancer[i];
> >  > +hmap_insert(_map, _info->hmap_node, hash);
> >  > +}
> >  > +
> >  > +lb_info->n_sbs++;
> >  > +lb_info->sbs = xrealloc(lb_info->sbs,
> >  > +lb_info->n_sbs * sizeof
> > *lb_info->sbs);
> >  > +lb_info->sbs[lb_info->n_sbs - 1] = od->sb;
> >  > +}
> >  > +}
> >  > +
> >  > +const struct sbrec_load_balancer *sbrec_lb, *next;
> >  > +SBREC_LOAD_BALANCER_FOR_EACH_SAFE (sbrec_lb, next,
> > ctx->ovnsb_idl) {
> >  > +const char *nb_lb_uuid =
> > smap_get(_lb->external_ids, "lb_id");
> >  > +struct uuid lb_uuid;
> >  > +if (!nb_lb_uuid || !uuid_from_string(_uuid,
> > nb_lb_uuid)) {
> >  > +sbrec_load_balancer_delete(sbrec_lb);
> >  > +continue;
> >  > +}
> >  > +
> >  > +struct sync_lb_info *lb_info =
> >  > +get_sync_lb_info_from_hmap(_map, _uuid);
> >  > +if (lb_info) {
> >  > +lb_info->slb = sbrec_lb;
> >  > +} else {
> >  > +sbrec_load_balancer_delete(sbrec_lb);
> >  > +}
> >  > +}
> >  > +
> 

Re: [ovs-dev] [PATCH ovn 1/5] Add new table Load_Balancer in Southbound database.

2020-10-23 Thread Mark Michelson

On 10/23/20 4:21 PM, Numan Siddique wrote:



On Sat, Oct 24, 2020, 1:29 AM Mark Michelson > wrote:


On 10/21/20 3:25 AM, num...@ovn.org  wrote:
 > From: Numan Siddique mailto:num...@ovn.org>>
 >
 > This patch adds a new table 'Load_Balancer' in SB DB and syncs
the Load_Balancer table rows
 > from NB DB to SB DB. An upcoming patch will make use of this
table for handling the
 > load balancer hairpin traffic.
 >
 > Signed-off-by: Numan Siddique mailto:num...@ovn.org>>
 > ---
 >   northd/ovn-northd.c   | 141
++
 >   ovn-sb.ovsschema      |  27 +++-
 >   ovn-sb.xml            |  47 ++
 >   tests/ovn-northd.at    |  81

 >   utilities/ovn-sbctl.c |   3 +
 >   5 files changed, 297 insertions(+), 2 deletions(-)
 >
 > diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
 > index 5b76868dfb..ea771afda1 100644
 > --- a/northd/ovn-northd.c
 > +++ b/northd/ovn-northd.c
 > @@ -11896,6 +11896,136 @@ sync_dns_entries(struct northd_context
*ctx, struct hmap *datapaths)
 >       }
 >       hmap_destroy(_map);
 >   }
 > +
 > +/*
 > + * struct 'sync_lb_info' is used to sync the load balancer
records between
 > + * OVN Northbound db and Southbound db.
 > + */
 > +struct sync_lb_info {
 > +    struct hmap_node hmap_node;
 > +    const struct nbrec_load_balancer *nlb; /* LB record in the
NB db. */
 > +    const struct sbrec_load_balancer *slb; /* LB record in the
SB db. */
 > +
 > +    /* Datapaths to which the LB entry is associated with it. */
 > +    const struct sbrec_datapath_binding **sbs;
 > +    size_t n_sbs;
 > +};
 > +
 > +static inline struct sync_lb_info *
 > +get_sync_lb_info_from_hmap(struct hmap *sync_lb_map, struct uuid
*uuid)
 > +{
 > +    struct sync_lb_info *lb_info;
 > +    size_t hash = uuid_hash(uuid);
 > +    HMAP_FOR_EACH_WITH_HASH (lb_info, hmap_node, hash,
sync_lb_map) {
 > +        if (uuid_equals(_info->nlb->header_.uuid, uuid)) {
 > +            return lb_info;
 > +        }
 > +    }
 > +
 > +    return NULL;
 > +}
 > +
 > +static void
 > +sync_lb_entries(struct northd_context *ctx, struct hmap *datapaths)
 > +{
 > +    struct hmap lb_map = HMAP_INITIALIZER(_map);
 > +    struct ovn_datapath *od;
 > +
 > +    HMAP_FOR_EACH (od, key_node, datapaths) {
 > +        if (!od->nbs || !od->nbs->n_load_balancer) {
 > +            continue;
 > +        }
 > +
 > +        for (size_t i = 0; i < od->nbs->n_load_balancer; i++) {
 > +            struct sync_lb_info *lb_info =
 > +                get_sync_lb_info_from_hmap(
 > +                    _map,
>nbs->load_balancer[i]->header_.uuid);
 > +
 > +            if (!lb_info) {
 > +                size_t hash = uuid_hash(
 > +                    >nbs->load_balancer[i]->header_.uuid);
 > +                lb_info = xzalloc(sizeof *lb_info);;
 > +                lb_info->nlb = od->nbs->load_balancer[i];
 > +                hmap_insert(_map, _info->hmap_node, hash);
 > +            }
 > +
 > +            lb_info->n_sbs++;
 > +            lb_info->sbs = xrealloc(lb_info->sbs,
 > +                                    lb_info->n_sbs * sizeof
*lb_info->sbs);
 > +            lb_info->sbs[lb_info->n_sbs - 1] = od->sb;
 > +        }
 > +    }
 > +
 > +    const struct sbrec_load_balancer *sbrec_lb, *next;
 > +    SBREC_LOAD_BALANCER_FOR_EACH_SAFE (sbrec_lb, next,
ctx->ovnsb_idl) {
 > +        const char *nb_lb_uuid =
smap_get(_lb->external_ids, "lb_id");
 > +        struct uuid lb_uuid;
 > +        if (!nb_lb_uuid || !uuid_from_string(_uuid,
nb_lb_uuid)) {
 > +            sbrec_load_balancer_delete(sbrec_lb);
 > +            continue;
 > +        }
 > +
 > +        struct sync_lb_info *lb_info =
 > +            get_sync_lb_info_from_hmap(_map, _uuid);
 > +        if (lb_info) {
 > +            lb_info->slb = sbrec_lb;
 > +        } else {
 > +            sbrec_load_balancer_delete(sbrec_lb);
 > +        }
 > +    }
 > +
 > +    struct sync_lb_info *lb_info;
 > +    HMAP_FOR_EACH (lb_info, hmap_node, _map) {
 > +        if (!lb_info->slb) {
 > +            sbrec_lb = sbrec_load_balancer_insert(ctx->ovnsb_txn);
 > +            lb_info->slb = sbrec_lb;
 > +            char *lb_id = xasprintf(
 > +                UUID_FMT, UUID_ARGS(_info->nlb->header_.uuid));
 > +            const struct smap external_ids =
 > +                SMAP_CONST1(_ids, "lb_id", lb_id);
 > +            sbrec_load_balancer_set_external_ids(sbrec_lb,

Re: [ovs-dev] [PATCH ovn 1/5] Add new table Load_Balancer in Southbound database.

2020-10-23 Thread Numan Siddique
On Sat, Oct 24, 2020, 1:29 AM Mark Michelson  wrote:

> On 10/21/20 3:25 AM, num...@ovn.org wrote:
> > From: Numan Siddique 
> >
> > This patch adds a new table 'Load_Balancer' in SB DB and syncs the
> Load_Balancer table rows
> > from NB DB to SB DB. An upcoming patch will make use of this table for
> handling the
> > load balancer hairpin traffic.
> >
> > Signed-off-by: Numan Siddique 
> > ---
> >   northd/ovn-northd.c   | 141 ++
> >   ovn-sb.ovsschema  |  27 +++-
> >   ovn-sb.xml|  47 ++
> >   tests/ovn-northd.at   |  81 
> >   utilities/ovn-sbctl.c |   3 +
> >   5 files changed, 297 insertions(+), 2 deletions(-)
> >
> > diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
> > index 5b76868dfb..ea771afda1 100644
> > --- a/northd/ovn-northd.c
> > +++ b/northd/ovn-northd.c
> > @@ -11896,6 +11896,136 @@ sync_dns_entries(struct northd_context *ctx,
> struct hmap *datapaths)
> >   }
> >   hmap_destroy(_map);
> >   }
> > +
> > +/*
> > + * struct 'sync_lb_info' is used to sync the load balancer records
> between
> > + * OVN Northbound db and Southbound db.
> > + */
> > +struct sync_lb_info {
> > +struct hmap_node hmap_node;
> > +const struct nbrec_load_balancer *nlb; /* LB record in the NB db. */
> > +const struct sbrec_load_balancer *slb; /* LB record in the SB db. */
> > +
> > +/* Datapaths to which the LB entry is associated with it. */
> > +const struct sbrec_datapath_binding **sbs;
> > +size_t n_sbs;
> > +};
> > +
> > +static inline struct sync_lb_info *
> > +get_sync_lb_info_from_hmap(struct hmap *sync_lb_map, struct uuid *uuid)
> > +{
> > +struct sync_lb_info *lb_info;
> > +size_t hash = uuid_hash(uuid);
> > +HMAP_FOR_EACH_WITH_HASH (lb_info, hmap_node, hash, sync_lb_map) {
> > +if (uuid_equals(_info->nlb->header_.uuid, uuid)) {
> > +return lb_info;
> > +}
> > +}
> > +
> > +return NULL;
> > +}
> > +
> > +static void
> > +sync_lb_entries(struct northd_context *ctx, struct hmap *datapaths)
> > +{
> > +struct hmap lb_map = HMAP_INITIALIZER(_map);
> > +struct ovn_datapath *od;
> > +
> > +HMAP_FOR_EACH (od, key_node, datapaths) {
> > +if (!od->nbs || !od->nbs->n_load_balancer) {
> > +continue;
> > +}
> > +
> > +for (size_t i = 0; i < od->nbs->n_load_balancer; i++) {
> > +struct sync_lb_info *lb_info =
> > +get_sync_lb_info_from_hmap(
> > +_map, >nbs->load_balancer[i]->header_.uuid);
> > +
> > +if (!lb_info) {
> > +size_t hash = uuid_hash(
> > +>nbs->load_balancer[i]->header_.uuid);
> > +lb_info = xzalloc(sizeof *lb_info);;
> > +lb_info->nlb = od->nbs->load_balancer[i];
> > +hmap_insert(_map, _info->hmap_node, hash);
> > +}
> > +
> > +lb_info->n_sbs++;
> > +lb_info->sbs = xrealloc(lb_info->sbs,
> > +lb_info->n_sbs * sizeof
> *lb_info->sbs);
> > +lb_info->sbs[lb_info->n_sbs - 1] = od->sb;
> > +}
> > +}
> > +
> > +const struct sbrec_load_balancer *sbrec_lb, *next;
> > +SBREC_LOAD_BALANCER_FOR_EACH_SAFE (sbrec_lb, next, ctx->ovnsb_idl) {
> > +const char *nb_lb_uuid = smap_get(_lb->external_ids,
> "lb_id");
> > +struct uuid lb_uuid;
> > +if (!nb_lb_uuid || !uuid_from_string(_uuid, nb_lb_uuid)) {
> > +sbrec_load_balancer_delete(sbrec_lb);
> > +continue;
> > +}
> > +
> > +struct sync_lb_info *lb_info =
> > +get_sync_lb_info_from_hmap(_map, _uuid);
> > +if (lb_info) {
> > +lb_info->slb = sbrec_lb;
> > +} else {
> > +sbrec_load_balancer_delete(sbrec_lb);
> > +}
> > +}
> > +
> > +struct sync_lb_info *lb_info;
> > +HMAP_FOR_EACH (lb_info, hmap_node, _map) {
> > +if (!lb_info->slb) {
> > +sbrec_lb = sbrec_load_balancer_insert(ctx->ovnsb_txn);
> > +lb_info->slb = sbrec_lb;
> > +char *lb_id = xasprintf(
> > +UUID_FMT, UUID_ARGS(_info->nlb->header_.uuid));
> > +const struct smap external_ids =
> > +SMAP_CONST1(_ids, "lb_id", lb_id);
> > +sbrec_load_balancer_set_external_ids(sbrec_lb,
> _ids);
> > +free(lb_id);
> > +}
> > +
> > +/* Set the datapaths and other columns.  If nothing has
> changed, then
> > + * this will be a no-op.
> > + */
> > +sbrec_load_balancer_set_datapaths(
> > +lb_info->slb,
> > +(struct sbrec_datapath_binding **)lb_info->sbs,
> > +lb_info->n_sbs);
> > +
> > +sbrec_load_balancer_set_name(lb_info->slb, lb_info->nlb->name);
> > +sbrec_load_balancer_set_vips(lb_info->slb, _info->nlb->vips);
> > +

Re: [ovs-dev] [PATCH ovn 1/5] Add new table Load_Balancer in Southbound database.

2020-10-23 Thread Mark Michelson

On 10/21/20 3:25 AM, num...@ovn.org wrote:

From: Numan Siddique 

This patch adds a new table 'Load_Balancer' in SB DB and syncs the 
Load_Balancer table rows
from NB DB to SB DB. An upcoming patch will make use of this table for handling 
the
load balancer hairpin traffic.

Signed-off-by: Numan Siddique 
---
  northd/ovn-northd.c   | 141 ++
  ovn-sb.ovsschema  |  27 +++-
  ovn-sb.xml|  47 ++
  tests/ovn-northd.at   |  81 
  utilities/ovn-sbctl.c |   3 +
  5 files changed, 297 insertions(+), 2 deletions(-)

diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index 5b76868dfb..ea771afda1 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -11896,6 +11896,136 @@ sync_dns_entries(struct northd_context *ctx, struct 
hmap *datapaths)
  }
  hmap_destroy(_map);
  }
+
+/*
+ * struct 'sync_lb_info' is used to sync the load balancer records between
+ * OVN Northbound db and Southbound db.
+ */
+struct sync_lb_info {
+struct hmap_node hmap_node;
+const struct nbrec_load_balancer *nlb; /* LB record in the NB db. */
+const struct sbrec_load_balancer *slb; /* LB record in the SB db. */
+
+/* Datapaths to which the LB entry is associated with it. */
+const struct sbrec_datapath_binding **sbs;
+size_t n_sbs;
+};
+
+static inline struct sync_lb_info *
+get_sync_lb_info_from_hmap(struct hmap *sync_lb_map, struct uuid *uuid)
+{
+struct sync_lb_info *lb_info;
+size_t hash = uuid_hash(uuid);
+HMAP_FOR_EACH_WITH_HASH (lb_info, hmap_node, hash, sync_lb_map) {
+if (uuid_equals(_info->nlb->header_.uuid, uuid)) {
+return lb_info;
+}
+}
+
+return NULL;
+}
+
+static void
+sync_lb_entries(struct northd_context *ctx, struct hmap *datapaths)
+{
+struct hmap lb_map = HMAP_INITIALIZER(_map);
+struct ovn_datapath *od;
+
+HMAP_FOR_EACH (od, key_node, datapaths) {
+if (!od->nbs || !od->nbs->n_load_balancer) {
+continue;
+}
+
+for (size_t i = 0; i < od->nbs->n_load_balancer; i++) {
+struct sync_lb_info *lb_info =
+get_sync_lb_info_from_hmap(
+_map, >nbs->load_balancer[i]->header_.uuid);
+
+if (!lb_info) {
+size_t hash = uuid_hash(
+>nbs->load_balancer[i]->header_.uuid);
+lb_info = xzalloc(sizeof *lb_info);;
+lb_info->nlb = od->nbs->load_balancer[i];
+hmap_insert(_map, _info->hmap_node, hash);
+}
+
+lb_info->n_sbs++;
+lb_info->sbs = xrealloc(lb_info->sbs,
+lb_info->n_sbs * sizeof *lb_info->sbs);
+lb_info->sbs[lb_info->n_sbs - 1] = od->sb;
+}
+}
+
+const struct sbrec_load_balancer *sbrec_lb, *next;
+SBREC_LOAD_BALANCER_FOR_EACH_SAFE (sbrec_lb, next, ctx->ovnsb_idl) {
+const char *nb_lb_uuid = smap_get(_lb->external_ids, "lb_id");
+struct uuid lb_uuid;
+if (!nb_lb_uuid || !uuid_from_string(_uuid, nb_lb_uuid)) {
+sbrec_load_balancer_delete(sbrec_lb);
+continue;
+}
+
+struct sync_lb_info *lb_info =
+get_sync_lb_info_from_hmap(_map, _uuid);
+if (lb_info) {
+lb_info->slb = sbrec_lb;
+} else {
+sbrec_load_balancer_delete(sbrec_lb);
+}
+}
+
+struct sync_lb_info *lb_info;
+HMAP_FOR_EACH (lb_info, hmap_node, _map) {
+if (!lb_info->slb) {
+sbrec_lb = sbrec_load_balancer_insert(ctx->ovnsb_txn);
+lb_info->slb = sbrec_lb;
+char *lb_id = xasprintf(
+UUID_FMT, UUID_ARGS(_info->nlb->header_.uuid));
+const struct smap external_ids =
+SMAP_CONST1(_ids, "lb_id", lb_id);
+sbrec_load_balancer_set_external_ids(sbrec_lb, _ids);
+free(lb_id);
+}
+
+/* Set the datapaths and other columns.  If nothing has changed, then
+ * this will be a no-op.
+ */
+sbrec_load_balancer_set_datapaths(
+lb_info->slb,
+(struct sbrec_datapath_binding **)lb_info->sbs,
+lb_info->n_sbs);
+
+sbrec_load_balancer_set_name(lb_info->slb, lb_info->nlb->name);
+sbrec_load_balancer_set_vips(lb_info->slb, _info->nlb->vips);
+sbrec_load_balancer_set_protocol(lb_info->slb, lb_info->nlb->protocol);
+}
+
+HMAP_FOR_EACH (od, key_node, datapaths) {
+if (!od->nbs || !od->nbs->n_load_balancer) {
+continue;
+}
+
+const struct sbrec_load_balancer **lbs =
+xmalloc(od->nbs->n_load_balancer * sizeof *lbs);
+for (size_t i = 0; i < od->nbs->n_load_balancer; i++) {
+lb_info = get_sync_lb_info_from_hmap(
+_map, >nbs->load_balancer[i]->header_.uuid);
+ovs_assert(lb_info);
+lbs[i] =