[NSX-P] Ensure multicast setting is specified in all cases

Every time a segment is updated with subnet, we need to explicitly
set the multicast setting to ensure it is disabled when only an
IPv6 subnet is present on the segment.

Change-Id: Ie75c87ac56f7d690c1dd6453001affcc7b1a035a
This commit is contained in:
Salvatore Orlando 2021-08-27 00:21:50 -07:00 committed by Salvatore Orlando
parent 817f7d939a
commit 93d06b9253
2 changed files with 25 additions and 12 deletions

View File

@ -1156,12 +1156,17 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
with db_api.CONTEXT_READER.using(context):
network = self._get_network(context, net_id)
for subnet in network.subnets:
if(subnet.enable_dhcp and
(subnet.ip_version == 4 or
subnet.ipv6_address_mode != const.IPV6_SLAAC)):
versions.add(subnet.ip_version)
versions.add(subnet.ip_version)
return versions
def _get_segment_multicast_setting(self, context, net_id):
seg_subnets_ip_ver = self._get_segment_subnets_versions(
context, net_id)
# Multicast cannot be enabled on segments with v6 subnets only
if len(seg_subnets_ip_ver) == 1 and seg_subnets_ip_ver.pop() == 6:
return False
return True
def _get_segment_subnets(self, context, net_id, net_az=None,
interface_subnets=None,
deleted_dhcp_subnets=None):
@ -1254,15 +1259,9 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
# Update the DHCP server on the segment
net_id = network['id']
segment_id = self._get_network_nsx_segment_id(context, net_id)
seg_subnets_ip_ver = self._get_segment_subnets_versions(
context, net_id)
multicast = self._get_segment_multicast_setting(context, net_id)
seg_subnets = self._get_segment_subnets(context, net_id, net_az=az)
dhcp_config = self._get_segment_dhcp_server_config(segment_id, az)
# Multicast cannot be enabled on segments with v6 subnets only
if len(seg_subnets_ip_ver) == 1 and seg_subnets_ip_ver.pop() == 6:
multicast = False
else:
multicast = True
# Update dhcp server config on the segment
self.nsxpolicy.segment.update(
segment_id=segment_id,
@ -1285,6 +1284,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
net_id = network['id']
net_dhcp_subnets = self._get_net_dhcp_subnets(context, net_id)
segment_id = self._get_network_nsx_segment_id(context, net_id)
multicast = self._get_segment_multicast_setting(context, net_id)
if subnet_id and len(net_dhcp_subnets) > 1:
# remove dhcp only from this subnet
@ -1292,6 +1292,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
context, net_id, deleted_dhcp_subnets=[subnet_id])
self.nsxpolicy.segment.update(
segment_id,
multicast=multicast,
subnets=seg_subnets)
self._delete_subnet_dhcp_port(context, net_id, subnet_id=subnet_id)
else:
@ -1300,6 +1301,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
context, net_id, deleted_dhcp_subnets=net_dhcp_subnets)
self.nsxpolicy.segment.update(
segment_id=segment_id,
multicast=multicast,
subnets=seg_subnets,
dhcp_server_config_id=None)
@ -1337,9 +1339,11 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
ports = self.get_ports(context, filters=filters)
dhcp_server_config = self._get_segment_dhcp_server_config(
segment_id, az)
multicast = self._get_segment_multicast_setting(context, net_id)
self.nsxpolicy.segment.update(
segment_id=segment_id,
dhcp_server_config_id=dhcp_server_config,
multicast=multicast,
subnets=seg_subnets)
# Update DHCP bindings for all the ports.
@ -3201,8 +3205,11 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
# overlay interface
pol_subnets = self._get_segment_subnets(
context, network_id, interface_subnets=rtr_subnets)
multicast = self._get_segment_multicast_setting(
context, network_id)
self.nsxpolicy.segment.update(segment_id,
tier1_id=router_id,
multicast=multicast,
subnets=pol_subnets)
# will update the router only if needed
@ -3291,7 +3298,8 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
# (it is possible to have both IPv4 & 6 subnets)
seg_subnets = self._get_segment_subnets(
context, network_id, interface_subnets=net_rtr_subnets)
multicast = self._get_segment_multicast_setting(
context, network_id)
if not net_rtr_subnets and not seg_subnets:
# Remove the tier1 connectivity of this segment
# This must be done is a separate call as it uses PUT
@ -3307,6 +3315,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
# update remaining (DHCP/ipv4/6) subnets
if seg_subnets:
self.nsxpolicy.segment.update(segment_id,
multicast=multicast,
subnets=seg_subnets)
# will update the router only if needed

View File

@ -1494,6 +1494,7 @@ class NsxPTestSubnets(common_v3.NsxV3TestSubnets,
seg_update.assert_called_with(
dhcp_server_config_id=NSX_DHCP_PROFILE_ID,
segment_id=subnet['subnet']['network_id'],
multicast=False,
subnets=[mock.ANY])
def test_subnet_disable_dhcpv6(self):
@ -1513,6 +1514,7 @@ class NsxPTestSubnets(common_v3.NsxV3TestSubnets,
seg_update.assert_called_once_with(
dhcp_server_config_id=None,
segment_id=subnet['subnet']['network_id'],
multicast=False,
subnets=[])
def test_delete_ipv6_dhcp_subnet(self):
@ -1531,6 +1533,7 @@ class NsxPTestSubnets(common_v3.NsxV3TestSubnets,
seg_update.assert_called_once_with(
dhcp_server_config_id=None,
segment_id=subnet['subnet']['network_id'],
multicast=False,
subnets=[])
@ -2081,6 +2084,7 @@ class NsxPTestL3NatTestCase(NsxPTestL3NatTest,
# We expect two subnet objects on segment
seg_update.assert_called_with(
n['network']['id'],
multicast=True,
subnets=[mock.ANY, mock.ANY],
tier1_id=r['router']['id'])