Merge "Revert "Remove native openflow driver 'deferred' code""

This commit is contained in:
Zuul 2020-03-26 00:46:52 +00:00 committed by Gerrit Code Review
commit c6f01728bd
4 changed files with 123 additions and 59 deletions

View File

@ -269,3 +269,26 @@ class OVSTunnelBridge(ovs_bridge.OVSAgentBridge,
# REVISIT(yamamoto): match in_port as well?
self.uninstall_flows(table_id=constants.DVR_NOT_LEARN,
eth_src=mac)
def deferred(self):
# REVISIT(yamamoto): This is for API compat with "ovs-ofctl"
# interface. Consider removing this mechanism when obsoleting
# "ovs-ofctl" interface.
# For "ovs-ofctl" interface, "deferred" mechanism would improve
# performance by batching flow-mods with a single ovs-ofctl command
# invocation.
# On the other hand, for this "native" interface, the overheads of
# each flow-mods are already minimum and batching doesn't make much
# sense. Thus this method is left as no-op.
# It might be possible to send multiple flow-mods with a single
# barrier. But it's unclear that level of performance optimization
# is desirable while it would certainly complicate error handling.
return self
def __enter__(self):
# REVISIT(yamamoto): See the comment on deferred().
return self
def __exit__(self, exc_type, exc_value, traceback):
# REVISIT(yamamoto): See the comment on deferred().
pass

View File

@ -653,33 +653,35 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
self.deleted_ports -= port_info['removed']
deleted_ports = list(self.deleted_ports)
while self.deleted_ports:
port_id = self.deleted_ports.pop()
port = self.int_br.get_vif_port_by_id(port_id)
with self.int_br.deferred(full_ordered=True,
use_bundle=True) as int_br:
while self.deleted_ports:
port_id = self.deleted_ports.pop()
port = self.int_br.get_vif_port_by_id(port_id)
if (isinstance(self.sg_agent.firewall,
agent_firewall.NoopFirewallDriver) or
not agent_sg_rpc.is_firewall_enabled()):
try:
self.delete_accepted_egress_direct_flow(
self.int_br,
port.ofport,
port.mac, self._get_port_local_vlan(port_id))
except Exception as err:
LOG.debug("Failed to remove accepted egress flows "
"for port %s, error: %s", port_id, err)
if (isinstance(self.sg_agent.firewall,
agent_firewall.NoopFirewallDriver) or
not agent_sg_rpc.is_firewall_enabled()):
try:
self.delete_accepted_egress_direct_flow(
int_br,
port.ofport,
port.mac, self._get_port_local_vlan(port_id))
except Exception as err:
LOG.debug("Failed to remove accepted egress flows "
"for port %s, error: %s", port_id, err)
self._clean_network_ports(port_id)
self.ext_manager.delete_port(self.context,
{"vif_port": port,
"port_id": port_id})
# move to dead VLAN so deleted ports no
# longer have access to the network
if port:
# don't log errors since there is a chance someone will be
# removing the port from the bridge at the same time
self.port_dead(port, log_errors=False)
self.port_unbound(port_id)
self._clean_network_ports(port_id)
self.ext_manager.delete_port(self.context,
{"vif_port": port,
"port_id": port_id})
# move to dead VLAN so deleted ports no
# longer have access to the network
if port:
# don't log errors since there is a chance someone will be
# removing the port from the bridge at the same time
self.port_dead(port, log_errors=False)
self.port_unbound(port_id)
# Flush firewall rules after ports are put on dead VLAN to be
# more secure
@ -768,17 +770,27 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
for lvm, agent_ports in self.get_agent_ports(fdb_entries):
agent_ports.pop(self.local_ip, None)
if len(agent_ports):
self.fdb_add_tun(context, self.tun_br, lvm,
agent_ports, self._tunnel_port_lookup)
if not self.enable_distributed_routing:
with self.tun_br.deferred() as deferred_br:
self.fdb_add_tun(context, deferred_br, lvm,
agent_ports, self._tunnel_port_lookup)
else:
self.fdb_add_tun(context, self.tun_br, lvm,
agent_ports, self._tunnel_port_lookup)
def fdb_remove(self, context, fdb_entries):
LOG.debug("fdb_remove received")
for lvm, agent_ports in self.get_agent_ports(fdb_entries):
agent_ports.pop(self.local_ip, None)
if len(agent_ports):
self.fdb_remove_tun(context, self.tun_br, lvm,
agent_ports,
self._tunnel_port_lookup)
if not self.enable_distributed_routing:
with self.tun_br.deferred() as deferred_br:
self.fdb_remove_tun(context, deferred_br, lvm,
agent_ports,
self._tunnel_port_lookup)
else:
self.fdb_remove_tun(context, self.tun_br, lvm,
agent_ports, self._tunnel_port_lookup)
def add_fdb_flow(self, br, port_info, remote_ip, lvm, ofport):
if port_info == n_const.FLOODING_ENTRY:
@ -814,7 +826,9 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
def _fdb_chg_ip(self, context, fdb_entries):
LOG.debug("update chg_ip received")
self.fdb_chg_ip_tun(context, self.tun_br, fdb_entries, self.local_ip)
with self.tun_br.deferred() as deferred_br:
self.fdb_chg_ip_tun(context, deferred_br, fdb_entries,
self.local_ip)
def setup_entry_for_arp_reply(self, br, action, local_vid, mac_address,
ip_address):
@ -2064,16 +2078,17 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
if (isinstance(self.sg_agent.firewall,
agent_firewall.NoopFirewallDriver) or
not agent_sg_rpc.is_firewall_enabled()):
for port in ports:
try:
self.install_accepted_egress_direct_flow(port,
self.int_br)
# give other coroutines a chance to run
eventlet.sleep(0)
except Exception as err:
LOG.debug("Failed to install accepted egress flows "
"for port %s, error: %s",
port['port_id'], err)
with self.int_br.deferred(full_ordered=True,
use_bundle=True) as int_br:
for port in ports:
try:
self.install_accepted_egress_direct_flow(port, int_br)
# give other coroutines a chance to run
eventlet.sleep(0)
except Exception as err:
LOG.debug("Failed to install accepted egress flows "
"for port %s, error: %s",
port['port_id'], err)
def install_accepted_egress_direct_flow(self, port_detail, br_int):
lvm = self.vlan_manager.get(port_detail['network_id'])

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import contextlib
import sys
import time
@ -1321,6 +1322,11 @@ class TestOvsNeutronAgent(object):
self.agent.sg_agent = mock.Mock()
self.agent.int_br = mock.Mock()
@contextlib.contextmanager
def bridge_deferred(*args, **kwargs):
yield
self.agent.int_br.deferred = mock.Mock(side_effect=bridge_deferred)
self.agent.process_deleted_ports(port_info={})
self.assertEqual(set(), self.agent.network_ports[TEST_NETWORK_ID1])
@ -1762,12 +1768,13 @@ class TestOvsNeutronAgent(object):
{'agent_ip':
[l2pop_rpc.PortInfo(FAKE_MAC, FAKE_IP1),
n_const.FLOODING_ENTRY]}}}
with mock.patch.object(self.agent, 'tun_br', autospec=True) as tun_br:
with mock.patch.object(self.agent.tun_br,
"deferred") as defer_fn:
self.agent.fdb_add(None, fdb_entry)
tun_br.add_port.assert_not_called()
defer_fn.assert_not_called()
self.agent.fdb_remove(None, fdb_entry)
tun_br.delete_port.assert_not_called()
defer_fn.assert_not_called()
def test_fdb_add_flows(self):
self._prepare_l2_pop_ofports()
@ -1785,12 +1792,14 @@ class TestOvsNeutronAgent(object):
autospec=True) as add_tun_fn:
self.agent.fdb_add(None, fdb_entry)
add_tun_fn.assert_not_called()
deferred_br_call = mock.call.deferred().__enter__()
expected_calls = [
mock.call.install_arp_responder('vlan1', FAKE_IP1, FAKE_MAC),
mock.call.install_unicast_to_tun('vlan1', 'seg1', '2',
FAKE_MAC),
mock.call.install_flood_to_tun('vlan1', 'seg1',
set(['1', '2'])),
deferred_br_call.install_arp_responder('vlan1', FAKE_IP1,
FAKE_MAC),
deferred_br_call.install_unicast_to_tun('vlan1', 'seg1', '2',
FAKE_MAC),
deferred_br_call.install_flood_to_tun('vlan1', 'seg1',
set(['1', '2'])),
]
tun_br.assert_has_calls(expected_calls)
@ -1805,12 +1814,17 @@ class TestOvsNeutronAgent(object):
n_const.FLOODING_ENTRY]}}}
with mock.patch.object(self.agent, 'tun_br', autospec=True) as br_tun:
self.agent.fdb_remove(None, fdb_entry)
deferred_br_call = mock.call.deferred().__enter__()
expected_calls = [
mock.call.delete_arp_responder('vlan2', FAKE_IP1),
mock.call.delete_unicast_to_tun('vlan2', FAKE_MAC),
mock.call.install_flood_to_tun('vlan2', 'seg2', set(['1'])),
mock.call.delete_port('gre-02020202'),
mock.call.cleanup_tunnel_port('2'),
mock.call.deferred(),
mock.call.deferred().__enter__(),
deferred_br_call.delete_arp_responder('vlan2', FAKE_IP1),
deferred_br_call.delete_unicast_to_tun('vlan2', FAKE_MAC),
deferred_br_call.install_flood_to_tun('vlan2', 'seg2',
set(['1'])),
deferred_br_call.delete_port('gre-02020202'),
deferred_br_call.cleanup_tunnel_port('2'),
mock.call.deferred().__exit__(None, None, None),
]
br_tun.assert_has_calls(expected_calls)
@ -1829,8 +1843,9 @@ class TestOvsNeutronAgent(object):
fdb_entry['net1']['ports']['10.10.10.10'] = [
l2pop_rpc.PortInfo(FAKE_MAC, FAKE_IP1)]
self.agent.fdb_add(None, fdb_entry)
deferred_br = tun_br.deferred().__enter__()
add_tun_fn.assert_called_with(
tun_br, 'gre-0a0a0a0a', '10.10.10.10', 'gre')
deferred_br, 'gre-0a0a0a0a', '10.10.10.10', 'gre')
def test_fdb_del_port(self):
self._prepare_l2_pop_ofports()
@ -1838,9 +1853,13 @@ class TestOvsNeutronAgent(object):
{'network_type': 'gre',
'segment_id': 'tun2',
'ports': {'2.2.2.2': [n_const.FLOODING_ENTRY]}}}
with mock.patch.object(self.agent, 'tun_br', autospec=True) as tun_br:
with mock.patch.object(self.agent.tun_br, 'deferred') as defer_fn,\
mock.patch.object(self.agent.tun_br,
'delete_port') as delete_port_fn:
self.agent.fdb_remove(None, fdb_entry)
tun_br.delete_port.assert_called_once_with('gre-02020202')
deferred_br = defer_fn().__enter__()
deferred_br.delete_port.assert_called_once_with('gre-02020202')
delete_port_fn.assert_not_called()
def test_fdb_update_chg_ip(self):
self._prepare_l2_pop_ofports()
@ -1849,9 +1868,10 @@ class TestOvsNeutronAgent(object):
{'agent_ip':
{'before': [l2pop_rpc.PortInfo(FAKE_MAC, FAKE_IP1)],
'after': [l2pop_rpc.PortInfo(FAKE_MAC, FAKE_IP2)]}}}}
with mock.patch.object(self.agent, 'tun_br', autospec=True) as tun_br:
with mock.patch.object(self.agent.tun_br, 'deferred') as deferred_fn:
self.agent.fdb_update(None, fdb_entries)
tun_br.assert_has_calls([
deferred_br = deferred_fn().__enter__()
deferred_br.assert_has_calls([
mock.call.install_arp_responder('vlan1', FAKE_IP2, FAKE_MAC),
mock.call.delete_arp_responder('vlan1', FAKE_IP1)
])

View File

@ -576,8 +576,14 @@ class TunnelTest(object):
self.mock_int_bridge_expected += [
mock.call.check_canary_table(),
mock.call.deferred(full_ordered=True, use_bundle=True),
mock.call.deferred().__enter__(),
mock.call.deferred().__exit__(None, None, None),
mock.call.cleanup_flows(),
mock.call.check_canary_table(),
mock.call.deferred(full_ordered=True, use_bundle=True),
mock.call.deferred().__enter__(),
mock.call.deferred().__exit__(None, None, None),
]
self.mock_map_tun_bridge_expected += [
mock.call.cleanup_flows(),