Skip to content

Commit

Permalink
Merge pull request #3487 from anarkiwi/cs
Browse files Browse the repository at this point in the history
Add tests for mirror/unmirror, fix FaucetUntaggedPortSwapIPv4InterVLANRouteTest
  • Loading branch information
anarkiwi authored Mar 10, 2020
2 parents a074fc1 + 964f657 commit b73ec09
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 38 deletions.
25 changes: 17 additions & 8 deletions faucet/dp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,11 +1458,13 @@ def _get_port_config_changes(self, logger, new_dp, changed_vlans, deleted_vlans,

# Detect changes to VLANs and ACLs based on port changes.
if not all_ports_changed:
def _add_changed_vlan_port(port):
def _add_changed_vlan_port(port, port_dp):
if port.native_vlan:
changed_vlans.add(port.native_vlan.vid)
if port.tagged_vlans:
changed_vlans.update({vlan.vid for vlan in port.tagged_vlans})
if port.stack:
changed_vlans.update({vlan.vid for vlan in port_dp.vlans.values()})

for port_no in changed_ports:
old_port = self.ports[port_no]
Expand All @@ -1477,24 +1479,28 @@ def _add_changed_vlan_port(port):
for port in (old_port, new_port):
if port.tagged_vlans:
changed_vlans.update({vlan.vid for vlan in port.tagged_vlans})
# stacking dis/enabled on a port.
if bool(old_port.stack) != bool(new_port.stack):
changed_vlans.update({vlan.vid for vlan in new_dp.vlans.values()})

# ports deleted or added.
for port_no in deleted_ports:
port = self.ports[port_no]
_add_changed_vlan_port(port)
_add_changed_vlan_port(port, self)
for port_no in added_ports:
port = new_dp.ports[port_no]
_add_changed_vlan_port(port)
_add_changed_vlan_port(port, new_dp)
for port_no in same_ports:
old_port = self.ports[port_no]
new_port = new_dp.ports[port_no]
# mirror options changed.
if old_port.mirror != new_port.mirror:
logger.info('port %s mirror options changed: %s' % (
port_no, new_port.mirror))
for mirrored_port in (old_port, new_port):
changed_ports.add(port_no)
for mirrored_port, port_dp in ((old_port, self), (new_port, new_dp)):
if mirrored_port.mirror:
_add_changed_vlan_port(mirrored_port)
_add_changed_vlan_port(mirrored_port, port_dp)
# ACL changes
new_acl_ids = new_port.acls_in
port_acls_changed = set()
Expand All @@ -1517,6 +1523,7 @@ def _add_changed_vlan_port(port):
same_ports -= changed_acl_ports
logger.info('ports where ACL only changed: %s' % changed_acl_ports)

same_ports -= changed_ports
changed_vlans -= deleted_vlans
# TODO: limit scope to only routers that have affected VLANs.
changed_vlans_with_vips = []
Expand All @@ -1541,8 +1548,9 @@ def _get_meter_config_changes(self, logger, new_dp):
deleted_meters (set): deleted Meter IDs.
changed_meters (set): changed/added Meter IDs.
"""
all_meters_changed, deleted_meters, added_meters, changed_meters, _, _ = self._get_conf_changes(
logger, 'METERS', self.meters, new_dp.meters)
(all_meters_changed, deleted_meters,
added_meters, changed_meters, _, _) = self._get_conf_changes(
logger, 'METERS', self.meters, new_dp.meters)

return (all_meters_changed, deleted_meters, added_meters, changed_meters)

Expand Down Expand Up @@ -1574,7 +1582,8 @@ def get_config_changes(self, logger, new_dp):
logger.info('Stack root change - requires cold start')
elif new_dp.routers != self.routers:
logger.info('DP routers config changed - requires cold start')
elif not self.ignore_subconf(new_dp, ignore_keys=['interfaces', 'interfaces_range', 'routers']):
elif not self.ignore_subconf(
new_dp, ignore_keys=['interfaces', 'interface_ranges', 'routers']):
logger.info('DP config changed - requires cold start: %s' % self.conf_diff(new_dp))
else:
changed_acls = self._get_acl_config_changes(logger, new_dp)
Expand Down
13 changes: 7 additions & 6 deletions tests/integration/mininet_multidp_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,17 +1136,18 @@ def restart_on_down_lag_port(self, port_dp_index, cold_start_dp_index):
del self.host_information[_id]
break
break
self.reload_conf(conf, self.faucet_config_path, restart=True,
cold_start=True, change_expected=False)
time.sleep(5)
self.reload_conf(
conf, self.faucet_config_path, restart=True,
cold_start=True, change_expected=False)
# Bring LACP port UP
self.set_port_up(port_no, chosen_dpid)
self.verify_num_lag_up_ports(2, chosen_dpid)
# Take down all of the other ports
for dpid, ports in self.host_information[self.LACP_HOST]['ports'].items():
for port in ports:
if dpid != chosen_dpid and port != port_no:
self.set_port_down(port, dpid)
if dpid != chosen_dpid:
for port in ports:
if port != port_no:
self.set_port_down(port, dpid)

def test_mclag_coldstart(self):
"""Test LACP MCLAG after a cold start"""
Expand Down
60 changes: 36 additions & 24 deletions tests/integration/mininet_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4949,19 +4949,31 @@ class FaucetUntaggedMirrorTest(FaucetUntaggedTest):
%(port_2)d:
native_vlan: 100
%(port_3)d:
# port 3 will mirror port 1
mirror: %(port_1)d
output_only: True
%(port_4)d:
native_vlan: 100
"""

def test_untagged(self):
first_host, second_host, mirror_host = self.hosts_name_ordered()[0:3]
first_host_ip = ipaddress.ip_address(first_host.IP())
second_host_ip = ipaddress.ip_address(second_host.IP())
self.flap_all_switch_ports()
# Add mirror, test performance.
self.change_port_config(
self.port_map['port_3'], 'mirror', self.port_map['port_1'],
restart=True, cold_start=False)
self.verify_ping_mirrored(first_host, second_host, mirror_host)
self.verify_bcast_ping_mirrored(first_host, second_host, mirror_host)
first_host_ip = ipaddress.ip_address(first_host.IP())
second_host_ip = ipaddress.ip_address(second_host.IP())
self.verify_iperf_min(
((first_host, self.port_map['port_1']),
(second_host, self.port_map['port_2'])),
MIN_MBPS, first_host_ip, second_host_ip,
sync_counters_func=lambda: self.one_ipv4_ping(first_host, second_host_ip))
# Remove mirror, test performance.
self.change_port_config(
self.port_map['port_3'], 'mirror', [],
restart=True, cold_start=False)
self.verify_iperf_min(
((first_host, self.port_map['port_1']),
(second_host, self.port_map['port_2'])),
Expand Down Expand Up @@ -6102,30 +6114,30 @@ def test_untagged(self):
second_host_ip = ipaddress.ip_interface('10.200.0.1/24')
second_faucet_vip = ipaddress.ip_interface('10.200.0.254/24')
first_host, second_host, third_host = self.hosts_name_ordered()[:3]
first_host.setIP(str(first_host_ip.ip), prefixLen=24)
second_host.setIP(str(second_host_ip.ip), prefixLen=24)
self.add_host_route(first_host, second_host_ip, first_faucet_vip.ip)
self.add_host_route(second_host, first_host_ip, second_faucet_vip.ip)
self.one_ipv4_ping(first_host, second_host_ip.ip)
self.one_ipv4_ping(second_host, first_host_ip.ip)
self.assertEqual(
self._ip_neigh(first_host, first_faucet_vip.ip, 4), self.FAUCET_MAC)
self.assertEqual(
self._ip_neigh(second_host, second_faucet_vip.ip, 4), self.FAUCET_MAC2)
# Delete port 2

def test_connectivity(host_a, host_b):
host_a.setIP(str(first_host_ip.ip), prefixLen=24)
host_b.setIP(str(second_host_ip.ip), prefixLen=24)
self.add_host_route(host_a, second_host_ip, first_faucet_vip.ip)
self.add_host_route(host_b, first_host_ip, second_faucet_vip.ip)
self.one_ipv4_ping(host_a, second_host_ip.ip)
self.one_ipv4_ping(host_b, first_host_ip.ip)
self.assertEqual(
self._ip_neigh(host_a, first_faucet_vip.ip, 4), self.FAUCET_MAC)
self.assertEqual(
self._ip_neigh(host_b, second_faucet_vip.ip, 4), self.FAUCET_MAC2)

test_connectivity(first_host, second_host)

# Delete port 1, add port 3
self.change_port_config(
self.port_map['port_2'], None, None,
self.port_map['port_1'], None, None,
restart=False, cold_start=False)
# Add port 3
self.add_port_config(
self.port_map['port_3'], {'native_vlan': 'vlanb'},
self.port_map['port_3'], {'native_vlan': 'vlana'},
restart=True, cold_start=True)
third_host.setIP(str(second_host_ip.ip), prefixLen=24)
self.add_host_route(third_host, first_host_ip, second_faucet_vip.ip)
self.one_ipv4_ping(first_host, second_host_ip.ip)
self.one_ipv4_ping(third_host, first_host_ip.ip)
self.assertEqual(
self._ip_neigh(third_host, second_faucet_vip.ip, 4), self.FAUCET_MAC2)

test_connectivity(third_host, second_host)


class FaucetUntaggedExpireIPv4InterVLANRouteTest(FaucetUntaggedTest):
Expand Down

0 comments on commit b73ec09

Please sign in to comment.