Skip to content

Commit

Permalink
ovn-northd ipam: handle the static MAC updates by the user
Browse files Browse the repository at this point in the history
Changing the logical port's address from "MAC1 dynamic"
to "MAC2 dynamic" is not handled by ovn-northd. This patch
fixes this issue.

Reported-at: https://bugzilla.redhat.com/show_bug.cgi?id=1408121
Signed-off-by: Numan Siddique <[email protected]>
Signed-off-by: Russell Bryant <[email protected]>
  • Loading branch information
numansiddique authored and russellb committed Feb 15, 2017
1 parent 9948793 commit 6c4f7a8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
37 changes: 37 additions & 0 deletions ovn/northd/ovn-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,41 @@ tag_alloc_create_new_tag(struct hmap *tag_alloc_table,
}


/*
* This function checks if the MAC in "address" parameter (if present) is
* different from the one stored in Logical_Switch_Port.dynamic_addresses
* and updates it.
*/
static void
check_and_update_mac_in_dynamic_addresses(
const char *address,
const struct nbrec_logical_switch_port *nbsp)
{
if (!nbsp->dynamic_addresses) {
return;
}
int buf_index = 0;
struct eth_addr ea;
if (!ovs_scan_len(address, &buf_index,
ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(ea))) {
return;
}

struct eth_addr present_ea;
buf_index = 0;
if (ovs_scan_len(nbsp->dynamic_addresses, &buf_index,
ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(present_ea))
&& !eth_addr_equals(ea, present_ea)) {
/* MAC address has changed. Update it */
char *new_addr = xasprintf(
ETH_ADDR_FMT"%s", ETH_ADDR_ARGS(ea),
&nbsp->dynamic_addresses[buf_index]);
nbrec_logical_switch_port_set_dynamic_addresses(
nbsp, new_addr);
free(new_addr);
}
}

static void
join_logical_ports(struct northd_context *ctx,
struct hmap *datapaths, struct hmap *ports,
Expand Down Expand Up @@ -1243,6 +1278,8 @@ join_logical_ports(struct northd_context *ctx,
}
if (is_dynamic_lsp_address(nbsp->addresses[j])) {
if (nbsp->dynamic_addresses) {
check_and_update_mac_in_dynamic_addresses(
nbsp->addresses[j], nbsp);
if (!extract_lsp_addresses(nbsp->dynamic_addresses,
&op->lsp_addrs[op->n_lsp_addrs])) {
static struct vlog_rate_limit rl
Expand Down
19 changes: 19 additions & 0 deletions tests/ovn.at
Original file line number Diff line number Diff line change
Expand Up @@ -4893,6 +4893,25 @@ AT_CHECK([ovn-nbctl get Logical-Switch-Port p31 dynamic_addresses], [0],
["fe:dc:ba:98:76:54 192.168.1.18"
])

# Update the static MAC address with dynamically allocated IP and check
# if the MAC address is updated in 'Logical_Switch_Port.dynamic_adddresses'
ovn-nbctl --wait=sb lsp-set-addresses p31 "fe:dc:ba:98:76:55 dynamic"
ovn-nbctl get Logical-Switch-Port p31 dynamic_addresses

AT_CHECK([ovn-nbctl get Logical-Switch-Port p31 dynamic_addresses], [0],
["fe:dc:ba:98:76:55 192.168.1.18"
])

ovn-nbctl --wait=sb lsp-set-addresses p31 "dynamic"
AT_CHECK([ovn-nbctl get Logical-Switch-Port p31 dynamic_addresses], [0],
["fe:dc:ba:98:76:55 192.168.1.18"
])

ovn-nbctl --wait=sb lsp-set-addresses p31 "fe:dc:ba:98:76:56 dynamic"
AT_CHECK([ovn-nbctl get Logical-Switch-Port p31 dynamic_addresses], [0],
["fe:dc:ba:98:76:56 192.168.1.18"
])

as ovn-sb
OVS_APP_EXIT_AND_WAIT([ovsdb-server])

Expand Down

0 comments on commit 6c4f7a8

Please sign in to comment.