vmm: api: Match VhostUserNetConfig defaults between CLI and HTTP API

In order to let the CLI and the HTTP API behave the same regarding the
VhostUserNetConfig structure, this patch defines some default values
for num_queues, queue_size and mac.

num_queues is 2 since that's a pair of TX/RX queues, queue_size is 256
and mac is a randomly generated value.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-12-10 17:09:28 +01:00 committed by Rob Bradford
parent 5e0bbf9c3b
commit 1c2587f8cb
2 changed files with 22 additions and 6 deletions

View File

@ -375,17 +375,16 @@ components:
VhostUserNetConfig:
required:
- sock
- num_queues
- queue_size
- mac
type: object
properties:
sock:
type: string
num_queues:
type: integer
default: 2
queue_size:
type: integer
default: 256
mac:
type: string

View File

@ -15,6 +15,8 @@ use std::result;
pub const DEFAULT_VCPUS: u8 = 1;
pub const DEFAULT_MEMORY_MB: u64 = 512;
pub const DEFAULT_RNG_SOURCE: &str = "/dev/urandom";
pub const DEFAULT_NUM_QUEUES_VUNET: usize = 2;
pub const DEFAULT_QUEUE_SIZE_VUNET: u16 = 256;
/// Errors associated with VM configuration parameters.
#[derive(Debug)]
@ -696,11 +698,26 @@ impl DeviceConfig {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct VhostUserNetConfig {
pub sock: String,
#[serde(default = "default_vunetconfig_num_queues")]
pub num_queues: usize,
#[serde(default = "default_vunetconfig_queue_size")]
pub queue_size: u16,
#[serde(default = "default_vunetconfig_mac")]
pub mac: MacAddr,
}
fn default_vunetconfig_num_queues() -> usize {
DEFAULT_NUM_QUEUES_VUNET
}
fn default_vunetconfig_queue_size() -> u16 {
DEFAULT_QUEUE_SIZE_VUNET
}
fn default_vunetconfig_mac() -> MacAddr {
MacAddr::local_random()
}
impl VhostUserNetConfig {
pub fn parse(vhost_user_net: &str) -> Result<Self> {
// Split the parameters based on the comma delimiter
@ -723,9 +740,9 @@ impl VhostUserNetConfig {
}
}
let mut mac: MacAddr = MacAddr::local_random();
let mut num_queues: usize = 2;
let mut queue_size: u16 = 256;
let mut mac: MacAddr = default_vunetconfig_mac();
let mut num_queues: usize = default_vunetconfig_num_queues();
let mut queue_size: u16 = default_vunetconfig_queue_size();
if !mac_str.is_empty() {
mac = MacAddr::parse_str(mac_str).map_err(Error::ParseVuNetMacParam)?;