mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vhost_user_net: Allow user to set MTU
Adding the support for the user to set the MTU for the vhost-user-net backend, which allows the integration test to be extended with the test of the MTU parameter. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
committed by
Rob Bradford
parent
903c08f8a1
commit
3bf3cca70a
@@ -202,23 +202,25 @@ fn prepare_vhost_user_net_daemon(
|
|||||||
tmp_dir: &TempDir,
|
tmp_dir: &TempDir,
|
||||||
ip: &str,
|
ip: &str,
|
||||||
tap: Option<&str>,
|
tap: Option<&str>,
|
||||||
|
mtu: Option<u16>,
|
||||||
num_queues: usize,
|
num_queues: usize,
|
||||||
client_mode: bool,
|
client_mode: bool,
|
||||||
) -> (std::process::Command, String) {
|
) -> (std::process::Command, String) {
|
||||||
let vunet_socket_path = String::from(tmp_dir.as_path().join("vunet.sock").to_str().unwrap());
|
let vunet_socket_path = String::from(tmp_dir.as_path().join("vunet.sock").to_str().unwrap());
|
||||||
|
|
||||||
// Start the daemon
|
// Start the daemon
|
||||||
let net_params = if let Some(tap_str) = tap {
|
let mut net_params = format!(
|
||||||
format!(
|
"ip={},mask=255.255.255.0,socket={},num_queues={},queue_size=1024,client={}",
|
||||||
"tap={},ip={},mask=255.255.255.0,socket={},num_queues={},queue_size=1024,client={}",
|
ip, vunet_socket_path, num_queues, client_mode
|
||||||
tap_str, ip, vunet_socket_path, num_queues, client_mode
|
);
|
||||||
)
|
|
||||||
} else {
|
if let Some(tap) = tap {
|
||||||
format!(
|
net_params.push_str(format!(",tap={}", tap).as_str());
|
||||||
"ip={},mask=255.255.255.0,socket={},num_queues={},queue_size=1024,client={}",
|
}
|
||||||
ip, vunet_socket_path, num_queues, client_mode
|
|
||||||
)
|
if let Some(mtu) = mtu {
|
||||||
};
|
net_params.push_str(format!(",mtu={}", mtu).as_str());
|
||||||
|
}
|
||||||
|
|
||||||
let mut command = Command::new(clh_command("vhost_user_net"));
|
let mut command = Command::new(clh_command("vhost_user_net"));
|
||||||
command.args(["--net-backend", net_params.as_str()]);
|
command.args(["--net-backend", net_params.as_str()]);
|
||||||
@@ -757,8 +759,14 @@ fn _test_power_button(acpi: bool) {
|
|||||||
handle_child_output(r, &output);
|
handle_child_output(r, &output);
|
||||||
}
|
}
|
||||||
|
|
||||||
type PrepareNetDaemon =
|
type PrepareNetDaemon = dyn Fn(
|
||||||
dyn Fn(&TempDir, &str, Option<&str>, usize, bool) -> (std::process::Command, String);
|
&TempDir,
|
||||||
|
&str,
|
||||||
|
Option<&str>,
|
||||||
|
Option<u16>,
|
||||||
|
usize,
|
||||||
|
bool,
|
||||||
|
) -> (std::process::Command, String);
|
||||||
|
|
||||||
fn test_vhost_user_net(
|
fn test_vhost_user_net(
|
||||||
tap: Option<&str>,
|
tap: Option<&str>,
|
||||||
@@ -779,16 +787,19 @@ fn test_vhost_user_net(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mtu = Some(3000);
|
||||||
|
|
||||||
let (mut daemon_command, vunet_socket_path) = prepare_daemon(
|
let (mut daemon_command, vunet_socket_path) = prepare_daemon(
|
||||||
&guest.tmp_dir,
|
&guest.tmp_dir,
|
||||||
&guest.network.host_ip,
|
&guest.network.host_ip,
|
||||||
tap,
|
tap,
|
||||||
|
mtu,
|
||||||
num_queues,
|
num_queues,
|
||||||
client_mode_daemon,
|
client_mode_daemon,
|
||||||
);
|
);
|
||||||
|
|
||||||
let net_params = format!(
|
let net_params = format!(
|
||||||
"vhost_user=true,mac={},socket={},num_queues={},queue_size=1024{},vhost_mode={}",
|
"vhost_user=true,mac={},socket={},num_queues={},queue_size=1024{},vhost_mode={},mtu=3000",
|
||||||
guest.network.guest_mac,
|
guest.network.guest_mac,
|
||||||
vunet_socket_path,
|
vunet_socket_path,
|
||||||
num_queues,
|
num_queues,
|
||||||
@@ -843,6 +854,19 @@ fn test_vhost_user_net(
|
|||||||
assert_eq!(String::from_utf8_lossy(&mac_count.stdout).trim(), "1");
|
assert_eq!(String::from_utf8_lossy(&mac_count.stdout).trim(), "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
let iface = "enp0s4";
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
let iface = "ens4";
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
guest
|
||||||
|
.ssh_command(format!("cat /sys/class/net/{}/mtu", iface).as_str())
|
||||||
|
.unwrap()
|
||||||
|
.trim(),
|
||||||
|
"3000"
|
||||||
|
);
|
||||||
|
|
||||||
// 1 network interface + default localhost ==> 2 interfaces
|
// 1 network interface + default localhost ==> 2 interfaces
|
||||||
// It's important to note that this test is fully exercising the
|
// It's important to note that this test is fully exercising the
|
||||||
// vhost-user-net implementation and the associated backend since
|
// vhost-user-net implementation and the associated backend since
|
||||||
|
|||||||
@@ -119,10 +119,12 @@ pub struct VhostUserNetBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl VhostUserNetBackend {
|
impl VhostUserNetBackend {
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn new(
|
fn new(
|
||||||
ip_addr: Ipv4Addr,
|
ip_addr: Ipv4Addr,
|
||||||
host_mac: MacAddr,
|
host_mac: MacAddr,
|
||||||
netmask: Ipv4Addr,
|
netmask: Ipv4Addr,
|
||||||
|
mtu: Option<u16>,
|
||||||
num_queues: usize,
|
num_queues: usize,
|
||||||
queue_size: u16,
|
queue_size: u16,
|
||||||
ifname: Option<&str>,
|
ifname: Option<&str>,
|
||||||
@@ -133,7 +135,7 @@ impl VhostUserNetBackend {
|
|||||||
Some(ip_addr),
|
Some(ip_addr),
|
||||||
Some(netmask),
|
Some(netmask),
|
||||||
&mut Some(host_mac),
|
&mut Some(host_mac),
|
||||||
None,
|
mtu,
|
||||||
num_queues / 2,
|
num_queues / 2,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@@ -182,6 +184,7 @@ impl VhostUserBackendMut<VringRwLock<GuestMemoryAtomic<GuestMemoryMmap>>, Atomic
|
|||||||
| 1 << VIRTIO_NET_F_CTRL_VQ
|
| 1 << VIRTIO_NET_F_CTRL_VQ
|
||||||
| 1 << VIRTIO_NET_F_MQ
|
| 1 << VIRTIO_NET_F_MQ
|
||||||
| 1 << VIRTIO_NET_F_MAC
|
| 1 << VIRTIO_NET_F_MAC
|
||||||
|
| 1 << VIRTIO_NET_F_MTU
|
||||||
| 1 << VIRTIO_F_NOTIFY_ON_EMPTY
|
| 1 << VIRTIO_F_NOTIFY_ON_EMPTY
|
||||||
| 1 << VIRTIO_F_VERSION_1
|
| 1 << VIRTIO_F_VERSION_1
|
||||||
| VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits()
|
| VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits()
|
||||||
@@ -273,6 +276,7 @@ pub struct VhostUserNetBackendConfig {
|
|||||||
pub ip: Ipv4Addr,
|
pub ip: Ipv4Addr,
|
||||||
pub host_mac: MacAddr,
|
pub host_mac: MacAddr,
|
||||||
pub mask: Ipv4Addr,
|
pub mask: Ipv4Addr,
|
||||||
|
pub mtu: Option<u16>,
|
||||||
pub socket: String,
|
pub socket: String,
|
||||||
pub num_queues: usize,
|
pub num_queues: usize,
|
||||||
pub queue_size: u16,
|
pub queue_size: u16,
|
||||||
@@ -289,6 +293,7 @@ impl VhostUserNetBackendConfig {
|
|||||||
.add("ip")
|
.add("ip")
|
||||||
.add("host_mac")
|
.add("host_mac")
|
||||||
.add("mask")
|
.add("mask")
|
||||||
|
.add("mtu")
|
||||||
.add("queue_size")
|
.add("queue_size")
|
||||||
.add("num_queues")
|
.add("num_queues")
|
||||||
.add("socket")
|
.add("socket")
|
||||||
@@ -309,6 +314,7 @@ impl VhostUserNetBackendConfig {
|
|||||||
.convert("mask")
|
.convert("mask")
|
||||||
.map_err(Error::FailedConfigParse)?
|
.map_err(Error::FailedConfigParse)?
|
||||||
.unwrap_or_else(|| Ipv4Addr::new(255, 255, 255, 0));
|
.unwrap_or_else(|| Ipv4Addr::new(255, 255, 255, 0));
|
||||||
|
let mtu = parser.convert("mtu").map_err(Error::FailedConfigParse)?;
|
||||||
let queue_size = parser
|
let queue_size = parser
|
||||||
.convert("queue_size")
|
.convert("queue_size")
|
||||||
.map_err(Error::FailedConfigParse)?
|
.map_err(Error::FailedConfigParse)?
|
||||||
@@ -328,6 +334,7 @@ impl VhostUserNetBackendConfig {
|
|||||||
ip,
|
ip,
|
||||||
host_mac,
|
host_mac,
|
||||||
mask,
|
mask,
|
||||||
|
mtu,
|
||||||
socket,
|
socket,
|
||||||
num_queues,
|
num_queues,
|
||||||
queue_size,
|
queue_size,
|
||||||
@@ -355,6 +362,7 @@ pub fn start_net_backend(backend_command: &str) {
|
|||||||
backend_config.ip,
|
backend_config.ip,
|
||||||
backend_config.host_mac,
|
backend_config.host_mac,
|
||||||
backend_config.mask,
|
backend_config.mask,
|
||||||
|
backend_config.mtu,
|
||||||
backend_config.num_queues,
|
backend_config.num_queues,
|
||||||
backend_config.queue_size,
|
backend_config.queue_size,
|
||||||
tap,
|
tap,
|
||||||
|
|||||||
@@ -1366,9 +1366,7 @@ impl NetConfig {
|
|||||||
.map_err(Error::ParseNetwork)?
|
.map_err(Error::ParseNetwork)?
|
||||||
.unwrap_or_else(default_netconfig_mac);
|
.unwrap_or_else(default_netconfig_mac);
|
||||||
let host_mac = parser.convert("host_mac").map_err(Error::ParseNetwork)?;
|
let host_mac = parser.convert("host_mac").map_err(Error::ParseNetwork)?;
|
||||||
let mtu = parser
|
let mtu = parser.convert("mtu").map_err(Error::ParseNetwork)?;
|
||||||
.convert("mtu")
|
|
||||||
.map_err(Error::ParseNetwork)?;
|
|
||||||
let iommu = parser
|
let iommu = parser
|
||||||
.convert::<Toggle>("iommu")
|
.convert::<Toggle>("iommu")
|
||||||
.map_err(Error::ParseNetwork)?
|
.map_err(Error::ParseNetwork)?
|
||||||
|
|||||||
Reference in New Issue
Block a user