Neutron ovs agent: set mtu of smartnic port

The smartnic port's MTU should be set according to the network's MTU
which the port belongs to.

Closes-Bug: #1899864
Change-Id: Ibcc29c998065da521b35e5845727794a68782db0
Signed-off-by: Xiaoyu Min <jackmin@nvidia.com>
This commit is contained in:
Xiaoyu Min 2020-10-12 10:21:17 +08:00 committed by Moshe Levi
parent e59a7c9aca
commit fc1fe016aa
2 changed files with 58 additions and 22 deletions

View File

@ -546,7 +546,8 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
local_link[0]['port_id'],
port_data['id'],
port_binding['vif_type'],
port_data['device_id'])
port_data['device_id'],
self._get_network_mtu(port_data['network_id']))
elif (not port_binding['host'] and port_binding['vif_type'] ==
portbindings.VIF_TYPE_UNBOUND and port['id'] in
self.current_smartnic_ports_map.keys()):
@ -571,9 +572,10 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
rep_port = smartnic_port_data['vif_name']
iface_id = smartnic_port_data['iface_id']
vif_type = smartnic_port_data['vif_type']
mtu = smartnic_port_data['mtu']
instance_info = vif_instance_object.InstanceInfo(uuid=vm_uuid)
vif = self._get_vif_object(iface_id, rep_port, mac)
vif = self._get_vif_object(iface_id, rep_port, mac, mtu)
try:
if vif_type == portbindings.VIF_TYPE_OVS:
os_vif.plug(vif, instance_info)
@ -598,9 +600,9 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
'port_id': iface_id,
'error': e})
def _get_vif_object(self, iface_id, rep_port, mac):
def _get_vif_object(self, iface_id, rep_port, mac, mtu):
network = vif_network_object.Network(
bridge=self.conf.OVS.integration_bridge)
bridge=self.conf.OVS.integration_bridge, mtu=mtu)
port_profile = vif_obj.VIFPortProfileOpenVSwitch(
interface_id=iface_id, create_port=True)
return vif_obj.VIFOpenVSwitch(
@ -608,13 +610,15 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
network=network, address=str(mac))
def _add_port_to_updated_smartnic_ports(self, mac, vif_name, iface_id,
vif_type, vm_uuid=''):
vif_type, vm_uuid='',
mtu=plugin_utils.get_deployment_physnet_mtu()):
self.updated_smartnic_ports.append({
'mac': mac,
'vm_uuid': vm_uuid,
'vif_name': vif_name,
'iface_id': iface_id,
'vif_type': vif_type})
'vif_type': vif_type,
'mtu': mtu})
@profiler.trace("rpc")
def port_delete(self, context, **kwargs):
@ -742,7 +746,8 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
local_link[0]['port_id'],
smartnic_port['id'],
smartnic_port['binding:vif_type'],
smartnic_port['device_id'])
smartnic_port['device_id'],
self._get_network_mtu(smartnic_port['network_id']))
def _process_removed_ports(removed_ports):
for ovs_port in removed_ports:
@ -2739,6 +2744,11 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
"underlays require L2-pop to be enabled, "
"in both the Agent and Server side."))
def _get_network_mtu(self, network_id):
port_network = self.plugin_rpc.get_network_details(self.context,
network_id, self.agent_id, self.conf.host)
return port_network['mtu']
def validate_local_ip(local_ip):
"""Verify if the ip exists on the agent's host."""

View File

@ -67,6 +67,8 @@ TEST_PORT_ID3 = 'port-id-3'
TEST_NETWORK_ID1 = 'net-id-1'
TEST_NETWORK_ID2 = 'net-id-2'
TEST_MTU = 7824
DEVICE_OWNER_COMPUTE = n_const.DEVICE_OWNER_COMPUTE_PREFIX + 'fake'
@ -1283,13 +1285,19 @@ class TestOvsNeutronAgent(object):
def test_port_update_smartnic(self):
cfg.CONF.set_default('baremetal_smartnic', True, group='AGENT')
port_arg = {"id": TEST_PORT_ID1}
network_id = 'e850ed99-5f46-47bc-8c06-86d9d519c46b'
port_arg = {"id": TEST_PORT_ID1, "network_id": network_id}
network = {'id': network_id, 'mtu': TEST_MTU}
with mock.patch.object(self.agent.plugin_rpc.remote_resource_cache,
"get_resource_by_id") as mocked_resource:
"get_resource_by_id") as mocked_resource,\
mock.patch.object(self.agent.plugin_rpc,
"get_network_details",
return_value=network):
port = Port()
port['id'] = 'd850ed99-5f46-47bc-8c06-86d9d519c46a'
port['mac_address'] = netaddr.EUI(FAKE_MAC)
port['device_id'] = '0'
port['network_id'] = network_id
bindings_data = PortBinding()
bindings_data['host'] = 'host'
bindings_data['vnic_type'] = portbindings.VNIC_SMARTNIC
@ -1305,7 +1313,8 @@ class TestOvsNeutronAgent(object):
'vm_uuid': port['device_id'],
'vif_name': 'rep_port',
'iface_id': port['id'],
'vif_type': bindings_data['vif_type']
'vif_type': bindings_data['vif_type'],
'mtu': TEST_MTU
}
self.assertEqual({TEST_PORT_ID1}, self.agent.updated_ports)
self.assertEqual([expected_smartnic_port_data],
@ -1317,6 +1326,7 @@ class TestOvsNeutronAgent(object):
vif_name = "rep0-0"
vif_id = port_arg["id"]
vif_mac = FAKE_MAC
default_mtu = 1500
self.agent.current_smartnic_ports_map = {
vif_id: {
'vif_mac': vif_mac,
@ -1342,7 +1352,8 @@ class TestOvsNeutronAgent(object):
'vm_uuid': '',
'vif_name': 'rep0-0',
'iface_id': port['id'],
'vif_type': portbindings.VIF_TYPE_UNBOUND
'vif_type': portbindings.VIF_TYPE_UNBOUND,
'mtu': default_mtu
}]
mocked_resource.assert_called_with(resources.PORT, port['id'])
self.assertEqual({port['id']}, self.agent.updated_ports)
@ -2602,12 +2613,13 @@ class TestOvsNeutronAgent(object):
'vm_uuid': vm_uuid,
'vif_name': rep_port,
'iface_id': iface_id,
'vif_type': vif_type}
'vif_type': vif_type,
'mtu': TEST_MTU}
cfg.CONF.set_default('baremetal_smartnic', True, group='AGENT')
agent = self._make_agent()
instance_info = vif_instance_object.InstanceInfo(uuid=vm_uuid)
vif = agent._get_vif_object(iface_id, rep_port, mac)
vif = agent._get_vif_object(iface_id, rep_port, mac, TEST_MTU)
with mock.patch.object(os_vif, 'plug') as plug_mock, \
mock.patch.object(os_vif, 'unplug') as unplug_mock, \
mock.patch('os_vif.objects.instance_info.InstanceInfo',
@ -2637,12 +2649,14 @@ class TestOvsNeutronAgent(object):
ovs_port.port_name = rep_port
ovs_port.vif_id = port_id
ports_int_br = [ovs_port]
default_mtu = 1500
expected_smartnic_ports_processed_list = [
{'iface_id': port_id,
'vif_name': rep_port,
'mac': mac,
'vif_type': portbindings.VIF_TYPE_UNBOUND,
'vm_uuid': ''}]
'vm_uuid': '',
'mtu': default_mtu}]
expected_current_smartnic_ports_map = {
port_id: {
'vif_mac': mac,
@ -2668,6 +2682,8 @@ class TestOvsNeutronAgent(object):
ovs_port.port_name = rep_port
ovs_port.vif_id = port_id
ports_int_br = [ovs_port]
default_mtu = 1500
network = {'id': TEST_NETWORK_ID1, 'mtu': TEST_MTU}
PORT_TO_PROCESS = {
'binding:profile': {'local_link_information': [
@ -2675,19 +2691,22 @@ class TestOvsNeutronAgent(object):
'mac_address': FAKE_MAC,
'device_id': "407a79e0-e0be-4b7d-92a6-513b2161011e",
'id': "407a79e0-e0be-4b7d-92a6-513b2161011c",
'binding:vif_type': portbindings.VIF_TYPE_OVS
'binding:vif_type': portbindings.VIF_TYPE_OVS,
'network_id': TEST_NETWORK_ID1
}
expected_smartnic_ports_processed_list = [
{'iface_id': port_id,
'vif_name': rep_port,
'mac': mac,
'vif_type': portbindings.VIF_TYPE_UNBOUND,
'vm_uuid': ''},
'vm_uuid': '',
'mtu': default_mtu},
{'iface_id': "407a79e0-e0be-4b7d-92a6-513b2161011c",
'vif_name': rep_port,
'mac': mac,
'vif_type': portbindings.VIF_TYPE_OVS,
'vm_uuid': "407a79e0-e0be-4b7d-92a6-513b2161011e"}]
'vm_uuid': "407a79e0-e0be-4b7d-92a6-513b2161011e",
'mtu': TEST_MTU}]
expected_current_smartnic_ports_map = {
port_id: {
'vif_mac': mac,
@ -2697,7 +2716,10 @@ class TestOvsNeutronAgent(object):
return_value=[PORT_TO_PROCESS]),\
mock.patch.object(self.agent.int_br,
"get_vif_ports",
return_value=ports_int_br):
return_value=ports_int_br),\
mock.patch.object(self.agent.plugin_rpc,
"get_network_details",
return_value=network):
self.agent.process_smartnic_ports()
self.assertEqual(expected_smartnic_ports_processed_list,
self.agent.updated_smartnic_ports)
@ -2714,14 +2736,16 @@ class TestOvsNeutronAgent(object):
rep_port,
iface_id,
portbindings.VIF_TYPE_OVS,
vm_uuid,)
vm_uuid,
TEST_MTU)
smartnic_data = {
'mac': mac,
'vm_uuid': vm_uuid,
'vif_name': rep_port,
'iface_id': iface_id,
'vif_type': portbindings.VIF_TYPE_OVS}
'vif_type': portbindings.VIF_TYPE_OVS,
'mtu': TEST_MTU}
self.assertEqual([smartnic_data],
self.agent.updated_smartnic_ports)
@ -2733,13 +2757,15 @@ class TestOvsNeutronAgent(object):
vif_mac,
vif_name,
vif_id,
portbindings.VIF_TYPE_UNBOUND)
portbindings.VIF_TYPE_UNBOUND,
mtu=TEST_MTU)
smartnic_data = {
'mac': vif_mac,
'vm_uuid': '',
'vif_name': vif_name,
'iface_id': vif_id,
'vif_type': portbindings.VIF_TYPE_UNBOUND}
'vif_type': portbindings.VIF_TYPE_UNBOUND,
'mtu': TEST_MTU}
self.assertEqual([smartnic_data],
self.agent.updated_smartnic_ports)