Skip to content

Commit

Permalink
ovn-northd: Make use of svec for storing lists of addresses.
Browse files Browse the repository at this point in the history
Get rid of what is, esentially, an open-coded version of svec.

Signed-off-by: Jakub Sitnicki <[email protected]>
Acked-by: Han Zhou <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
Jakub Sitnicki authored and blp committed Jul 31, 2018
1 parent f67d9e6 commit 2342c26
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 32 deletions.
47 changes: 15 additions & 32 deletions ovn/northd/ovn-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "openvswitch/poll-loop.h"
#include "smap.h"
#include "sset.h"
#include "svec.h"
#include "stream.h"
#include "stream-ssl.h"
#include "unixctl.h"
Expand Down Expand Up @@ -6499,54 +6500,36 @@ sync_address_sets(struct northd_context *ctx)
/* sync port group generated address sets first */
const struct nbrec_port_group *nb_port_group;
NBREC_PORT_GROUP_FOR_EACH (nb_port_group, ctx->ovnnb_idl) {
char **ipv4_addrs = xcalloc(1, sizeof *ipv4_addrs);
size_t n_ipv4_addrs = 0;
size_t n_ipv4_addrs_buf = 1;
char **ipv6_addrs = xcalloc(1, sizeof *ipv6_addrs);
size_t n_ipv6_addrs = 0;
size_t n_ipv6_addrs_buf = 1;
struct svec ipv4_addrs = SVEC_EMPTY_INITIALIZER;
struct svec ipv6_addrs = SVEC_EMPTY_INITIALIZER;
for (size_t i = 0; i < nb_port_group->n_ports; i++) {
for (size_t j = 0; j < nb_port_group->ports[i]->n_addresses; j++) {
struct lport_addresses laddrs;
extract_lsp_addresses(nb_port_group->ports[i]->addresses[j],
&laddrs);
while (n_ipv4_addrs_buf < n_ipv4_addrs + laddrs.n_ipv4_addrs) {
n_ipv4_addrs_buf *= 2;
ipv4_addrs = xrealloc(ipv4_addrs,
n_ipv4_addrs_buf * sizeof *ipv4_addrs);
}
for (size_t k = 0; k < laddrs.n_ipv4_addrs; k++) {
ipv4_addrs[n_ipv4_addrs++] =
xstrdup(laddrs.ipv4_addrs[k].addr_s);
}
while (n_ipv6_addrs_buf < n_ipv6_addrs + laddrs.n_ipv6_addrs) {
n_ipv6_addrs_buf *= 2;
ipv6_addrs = xrealloc(ipv6_addrs,
n_ipv6_addrs_buf * sizeof *ipv6_addrs);
svec_add(&ipv4_addrs, laddrs.ipv4_addrs[k].addr_s);
}
for (size_t k = 0; k < laddrs.n_ipv6_addrs; k++) {
ipv6_addrs[n_ipv6_addrs++] =
xstrdup(laddrs.ipv6_addrs[k].addr_s);
svec_add(&ipv6_addrs, laddrs.ipv6_addrs[k].addr_s);
}
destroy_lport_addresses(&laddrs);
}
}
char *ipv4_addrs_name = xasprintf("%s_ip4", nb_port_group->name);
char *ipv6_addrs_name = xasprintf("%s_ip6", nb_port_group->name);
sync_address_set(ctx, ipv4_addrs_name, (const char **)ipv4_addrs,
n_ipv4_addrs, &sb_address_sets);
sync_address_set(ctx, ipv6_addrs_name, (const char **)ipv6_addrs,
n_ipv6_addrs, &sb_address_sets);
sync_address_set(ctx, ipv4_addrs_name,
/* "char **" is not compatible with "const char **" */
(const char **)ipv4_addrs.names,
ipv4_addrs.n, &sb_address_sets);
sync_address_set(ctx, ipv6_addrs_name,
/* "char **" is not compatible with "const char **" */
(const char **)ipv6_addrs.names,
ipv6_addrs.n, &sb_address_sets);
free(ipv4_addrs_name);
free(ipv6_addrs_name);
for (size_t i = 0; i < n_ipv4_addrs; i++) {
free(ipv4_addrs[i]);
}
free(ipv4_addrs);
for (size_t i = 0; i < n_ipv6_addrs; i++) {
free(ipv6_addrs[i]);
}
free(ipv6_addrs);
svec_destroy(&ipv4_addrs);
svec_destroy(&ipv6_addrs);
}

/* sync user defined address sets, which may overwrite port group
Expand Down
50 changes: 50 additions & 0 deletions tests/ovn.at
Original file line number Diff line number Diff line change
Expand Up @@ -10260,6 +10260,56 @@ done
OVN_CLEANUP([hv1], [hv2], [hv3])
AT_CLEANUP

AT_SETUP([ovn -- Address Set generation from Port Groups (static addressing)])
ovn_start

ovn-nbctl ls-add ls1

ovn-nbctl lsp-add ls1 lp1
ovn-nbctl lsp-add ls1 lp2
ovn-nbctl lsp-add ls1 lp3

ovn-nbctl lsp-set-addresses lp1 "02:00:00:00:00:01 10.0.0.1 2001:db8::1"
ovn-nbctl lsp-set-addresses lp2 "02:00:00:00:00:02 10.0.0.2 2001:db8::2"
ovn-nbctl lsp-set-addresses lp3 "02:00:00:00:00:03 10.0.0.3 2001:db8::3"

ovn-nbctl create Port_Group name=pg1
ovn-nbctl create Port_Group name=pg2

ovn-nbctl --id=@p get Logical_Switch_Port lp1 -- add Port_Group pg1 ports @p
ovn-nbctl --id=@p get Logical_Switch_Port lp2 -- add Port_Group pg1 ports @p
ovn-nbctl --id=@p get Logical_Switch_Port lp2 -- add Port_Group pg2 ports @p
ovn-nbctl --id=@p get Logical_Switch_Port lp3 -- add Port_Group pg2 ports @p

ovn-nbctl --wait=sb sync

dnl Check if port group address sets were populated with ports' addresses
AT_CHECK([ovn-sbctl get Address_Set pg1_ip4 addresses],
[0], [[["10.0.0.1", "10.0.0.2"]]
])
AT_CHECK([ovn-sbctl get Address_Set pg2_ip4 addresses],
[0], [[["10.0.0.2", "10.0.0.3"]]
])
AT_CHECK([ovn-sbctl get Address_Set pg1_ip6 addresses],
[0], [[["2001:db8::1", "2001:db8::2"]]
])
AT_CHECK([ovn-sbctl get Address_Set pg2_ip6 addresses],
[0], [[["2001:db8::2", "2001:db8::3"]]
])

ovn-nbctl --wait=sb lsp-set-addresses lp1 \
"02:00:00:00:00:01 10.0.0.11 2001:db8::11"

dnl Check if updated address got propagated to the port group address sets
AT_CHECK([ovn-sbctl get Address_Set pg1_ip4 addresses],
[0], [[["10.0.0.11", "10.0.0.2"]]
])
AT_CHECK([ovn-sbctl get Address_Set pg1_ip6 addresses],
[0], [[["2001:db8::11", "2001:db8::2"]]
])

AT_CLEANUP

AT_SETUP([ovn -- ACL conjunction])
ovn_start

Expand Down

0 comments on commit 2342c26

Please sign in to comment.