Skip to content

Commit

Permalink
northd: Move ovn_lb_datapaths from lib to northd module.
Browse files Browse the repository at this point in the history
Signed-off-by: Numan Siddique <numans@ovn.org>
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
numansiddique authored and ovsrobot committed Oct 24, 2023
1 parent 0d57164 commit 95e9322
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 153 deletions.
96 changes: 0 additions & 96 deletions lib/lb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,99 +1071,3 @@ remove_ips_from_lb_ip_set(struct ovn_lb_ip_set *lb_ips,
}
}
}

/* lb datapaths functions */
struct ovn_lb_datapaths *
ovn_lb_datapaths_create(const struct ovn_northd_lb *lb, size_t n_ls_datapaths,
size_t n_lr_datapaths)
{
struct ovn_lb_datapaths *lb_dps = xzalloc(sizeof *lb_dps);
lb_dps->lb = lb;
lb_dps->nb_ls_map = bitmap_allocate(n_ls_datapaths);
lb_dps->nb_lr_map = bitmap_allocate(n_lr_datapaths);

return lb_dps;
}

struct ovn_lb_datapaths *
ovn_lb_datapaths_find(const struct hmap *lb_dps_map,
const struct uuid *lb_uuid)
{
struct ovn_lb_datapaths *lb_dps;
size_t hash = uuid_hash(lb_uuid);
HMAP_FOR_EACH_WITH_HASH (lb_dps, hmap_node, hash, lb_dps_map) {
if (uuid_equals(&lb_dps->lb->nlb->header_.uuid, lb_uuid)) {
return lb_dps;
}
}
return NULL;
}

void
ovn_lb_datapaths_destroy(struct ovn_lb_datapaths *lb_dps)
{
bitmap_free(lb_dps->nb_lr_map);
bitmap_free(lb_dps->nb_ls_map);
free(lb_dps);
}

void
ovn_lb_datapaths_add_lr(struct ovn_lb_datapaths *lb_dps, size_t n,
struct ovn_datapath **ods)
{
for (size_t i = 0; i < n; i++) {
if (!bitmap_is_set(lb_dps->nb_lr_map, ods[i]->index)) {
bitmap_set1(lb_dps->nb_lr_map, ods[i]->index);
lb_dps->n_nb_lr++;
}
}
}

void
ovn_lb_datapaths_add_ls(struct ovn_lb_datapaths *lb_dps, size_t n,
struct ovn_datapath **ods)
{
for (size_t i = 0; i < n; i++) {
if (!bitmap_is_set(lb_dps->nb_ls_map, ods[i]->index)) {
bitmap_set1(lb_dps->nb_ls_map, ods[i]->index);
lb_dps->n_nb_ls++;
}
}
}

struct ovn_lb_group_datapaths *
ovn_lb_group_datapaths_create(const struct ovn_lb_group *lb_group,
size_t max_ls_datapaths,
size_t max_lr_datapaths)
{
struct ovn_lb_group_datapaths *lb_group_dps =
xzalloc(sizeof *lb_group_dps);
lb_group_dps->lb_group = lb_group;
lb_group_dps->ls = xmalloc(max_ls_datapaths * sizeof *lb_group_dps->ls);
lb_group_dps->lr = xmalloc(max_lr_datapaths * sizeof *lb_group_dps->lr);

return lb_group_dps;
}

void
ovn_lb_group_datapaths_destroy(struct ovn_lb_group_datapaths *lb_group_dps)
{
free(lb_group_dps->ls);
free(lb_group_dps->lr);
free(lb_group_dps);
}

struct ovn_lb_group_datapaths *
ovn_lb_group_datapaths_find(const struct hmap *lb_group_dps_map,
const struct uuid *lb_group_uuid)
{
struct ovn_lb_group_datapaths *lb_group_dps;
size_t hash = uuid_hash(lb_group_uuid);

HMAP_FOR_EACH_WITH_HASH (lb_group_dps, hmap_node, hash, lb_group_dps_map) {
if (uuid_equals(&lb_group_dps->lb_group->uuid, lb_group_uuid)) {
return lb_group_dps;
}
}
return NULL;
}
57 changes: 0 additions & 57 deletions lib/lb.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,63 +167,6 @@ void ovn_lb_group_reinit(
const struct nbrec_load_balancer_group *,
const struct hmap *lbs);

struct ovn_lb_datapaths {
struct hmap_node hmap_node;

const struct ovn_northd_lb *lb;
size_t n_nb_ls;
unsigned long *nb_ls_map;

size_t n_nb_lr;
unsigned long *nb_lr_map;
};

struct ovn_lb_datapaths *ovn_lb_datapaths_create(const struct ovn_northd_lb *,
size_t n_ls_datapaths,
size_t n_lr_datapaths);
struct ovn_lb_datapaths *ovn_lb_datapaths_find(const struct hmap *,
const struct uuid *);
void ovn_lb_datapaths_destroy(struct ovn_lb_datapaths *);
void ovn_lb_datapaths_add_lr(struct ovn_lb_datapaths *, size_t n,
struct ovn_datapath **);
void ovn_lb_datapaths_add_ls(struct ovn_lb_datapaths *, size_t n,
struct ovn_datapath **);

struct ovn_lb_group_datapaths {
struct hmap_node hmap_node;

const struct ovn_lb_group *lb_group;

/* Datapaths to which 'lb_group' is applied. */
size_t n_ls;
struct ovn_datapath **ls;
size_t n_lr;
struct ovn_datapath **lr;
};

struct ovn_lb_group_datapaths *ovn_lb_group_datapaths_create(
const struct ovn_lb_group *, size_t max_ls_datapaths,
size_t max_lr_datapaths);

void ovn_lb_group_datapaths_destroy(struct ovn_lb_group_datapaths *);
struct ovn_lb_group_datapaths *ovn_lb_group_datapaths_find(
const struct hmap *lb_group_dps, const struct uuid *);

static inline void
ovn_lb_group_datapaths_add_ls(struct ovn_lb_group_datapaths *lbg_dps, size_t n,
struct ovn_datapath **ods)
{
memcpy(&lbg_dps->ls[lbg_dps->n_ls], ods, n * sizeof *ods);
lbg_dps->n_ls += n;
}

static inline void
ovn_lb_group_datapaths_add_lr(struct ovn_lb_group_datapaths *lbg_dps,
struct ovn_datapath *lr)
{
lbg_dps->lr[lbg_dps->n_lr++] = lr;
}

struct ovn_controller_lb {
struct hmap_node hmap_node;

Expand Down
111 changes: 111 additions & 0 deletions northd/northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3522,6 +3522,117 @@ build_lb_vip_actions(const struct ovn_northd_lb *lb,
return reject;
}

/* lb datapaths functions */
static struct ovn_lb_datapaths *
ovn_lb_datapaths_create(const struct ovn_northd_lb *lb, size_t n_ls_datapaths,
size_t n_lr_datapaths)
{
struct ovn_lb_datapaths *lb_dps = xzalloc(sizeof *lb_dps);
lb_dps->lb = lb;
lb_dps->nb_ls_map = bitmap_allocate(n_ls_datapaths);
lb_dps->nb_lr_map = bitmap_allocate(n_lr_datapaths);

return lb_dps;
}

static void
ovn_lb_datapaths_destroy(struct ovn_lb_datapaths *lb_dps)
{
bitmap_free(lb_dps->nb_lr_map);
bitmap_free(lb_dps->nb_ls_map);
free(lb_dps);
}

static void
ovn_lb_datapaths_add_lr(struct ovn_lb_datapaths *lb_dps, size_t n,
struct ovn_datapath **ods)
{
for (size_t i = 0; i < n; i++) {
if (!bitmap_is_set(lb_dps->nb_lr_map, ods[i]->index)) {
bitmap_set1(lb_dps->nb_lr_map, ods[i]->index);
lb_dps->n_nb_lr++;
}
}
}

static void
ovn_lb_datapaths_add_ls(struct ovn_lb_datapaths *lb_dps, size_t n,
struct ovn_datapath **ods)
{
for (size_t i = 0; i < n; i++) {
if (!bitmap_is_set(lb_dps->nb_ls_map, ods[i]->index)) {
bitmap_set1(lb_dps->nb_ls_map, ods[i]->index);
lb_dps->n_nb_ls++;
}
}
}

static struct ovn_lb_group_datapaths *
ovn_lb_group_datapaths_create(const struct ovn_lb_group *lb_group,
size_t max_ls_datapaths,
size_t max_lr_datapaths)
{
struct ovn_lb_group_datapaths *lb_group_dps =
xzalloc(sizeof *lb_group_dps);
lb_group_dps->lb_group = lb_group;
lb_group_dps->ls = xmalloc(max_ls_datapaths * sizeof *lb_group_dps->ls);
lb_group_dps->lr = xmalloc(max_lr_datapaths * sizeof *lb_group_dps->lr);

return lb_group_dps;
}

static void
ovn_lb_group_datapaths_destroy(struct ovn_lb_group_datapaths *lb_group_dps)
{
free(lb_group_dps->ls);
free(lb_group_dps->lr);
free(lb_group_dps);
}

static void
ovn_lb_group_datapaths_add_ls(struct ovn_lb_group_datapaths *lbg_dps, size_t n,
struct ovn_datapath **ods)
{
memcpy(&lbg_dps->ls[lbg_dps->n_ls], ods, n * sizeof *ods);
lbg_dps->n_ls += n;
}

static void
ovn_lb_group_datapaths_add_lr(struct ovn_lb_group_datapaths *lbg_dps,
struct ovn_datapath *lr)
{
lbg_dps->lr[lbg_dps->n_lr++] = lr;
}

struct ovn_lb_datapaths *
ovn_lb_datapaths_find(const struct hmap *lb_dps_map,
const struct uuid *lb_uuid)
{
struct ovn_lb_datapaths *lb_dps;
size_t hash = uuid_hash(lb_uuid);
HMAP_FOR_EACH_WITH_HASH (lb_dps, hmap_node, hash, lb_dps_map) {
if (uuid_equals(&lb_dps->lb->nlb->header_.uuid, lb_uuid)) {
return lb_dps;
}
}
return NULL;
}

struct ovn_lb_group_datapaths *
ovn_lb_group_datapaths_find(const struct hmap *lb_group_dps_map,
const struct uuid *lb_group_uuid)
{
struct ovn_lb_group_datapaths *lb_group_dps;
size_t hash = uuid_hash(lb_group_uuid);

HMAP_FOR_EACH_WITH_HASH (lb_group_dps, hmap_node, hash, lb_group_dps_map) {
if (uuid_equals(&lb_group_dps->lb_group->uuid, lb_group_uuid)) {
return lb_group_dps;
}
}
return NULL;
}

static void
build_lb_datapaths(const struct hmap *lbs, const struct hmap *lb_groups,
struct ovn_datapaths *ls_datapaths,
Expand Down
28 changes: 28 additions & 0 deletions northd/northd.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ struct ovn_datapaths {
struct ovn_datapath **array;
};

struct ovn_lb_datapaths {
struct hmap_node hmap_node;

const struct ovn_northd_lb *lb;
size_t n_nb_ls;
unsigned long *nb_ls_map;

size_t n_nb_lr;
unsigned long *nb_lr_map;
};

struct ovn_lb_group_datapaths {
struct hmap_node hmap_node;

const struct ovn_lb_group *lb_group;

/* Datapaths to which 'lb_group' is applied. */
size_t n_ls;
struct ovn_datapath **ls;
size_t n_lr;
struct ovn_datapath **lr;
};

struct tracked_ovn_ports {
/* tracked created ports.
* hmapx node data is 'struct ovn_port *' */
Expand All @@ -98,6 +121,11 @@ struct tracked_ovn_ports {
struct hmapx deleted;
};

struct ovn_lb_datapaths *ovn_lb_datapaths_find(const struct hmap *,
const struct uuid *);
struct ovn_lb_group_datapaths *ovn_lb_group_datapaths_find(
const struct hmap *lb_group_dps, const struct uuid *);

struct tracked_lbs {
/* Tracked created or updated load balancers.
* hmapx node data is 'struct ovn_lb_datapaths' */
Expand Down

0 comments on commit 95e9322

Please sign in to comment.