On Sat, Jul 6, 2019 at 1:24 PM Ilias Stamatis <stamatis.iliass@xxxxxxxxx> wrote: > > Signed-off-by: Ilias Stamatis <stamatis.iliass@xxxxxxxxx> > --- > src/test/test_driver.c | 97 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 97 insertions(+) > > diff --git a/src/test/test_driver.c b/src/test/test_driver.c > index 7dd448bb20..fd57c8c572 100644 > --- a/src/test/test_driver.c > +++ b/src/test/test_driver.c > @@ -2945,6 +2945,102 @@ testDomainGetNumaParameters(virDomainPtr dom, > } > > > +static int > +testDomainSetInterfaceParameters(virDomainPtr dom, > + const char *device, > + virTypedParameterPtr params, > + int nparams, > + unsigned int flags) > +{ > + virDomainObjPtr vm = NULL; > + virDomainDefPtr def; > + virDomainNetDefPtr net = NULL; > + virNetDevBandwidthPtr bandwidth = NULL; > + size_t i; > + int ret = -1; > + > + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | > + VIR_DOMAIN_AFFECT_CONFIG, -1); > + > + if (virTypedParamsValidate(params, nparams, > + VIR_DOMAIN_BANDWIDTH_IN_AVERAGE, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_IN_PEAK, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_IN_BURST, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_IN_FLOOR, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_OUT_PEAK, > + VIR_TYPED_PARAM_UINT, > + VIR_DOMAIN_BANDWIDTH_OUT_BURST, > + VIR_TYPED_PARAM_UINT, > + NULL) < 0) > + return -1; > + > + if (!(vm = testDomObjFromDomain(dom))) > + return -1; > + > + if (!(def = virDomainObjGetOneDef(vm, flags))) > + goto cleanup; > + > + if (!(net = virDomainNetFind(def, device))) > + goto cleanup; > + > + if ((VIR_ALLOC(bandwidth) < 0) || > + (VIR_ALLOC(bandwidth->in) < 0) || > + (VIR_ALLOC(bandwidth->out) < 0)) > + goto cleanup; > + > + for (i = 0; i < nparams; i++) { > + virTypedParameterPtr param = ¶ms[i]; > + > + if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_AVERAGE)) { > + bandwidth->in->average = param->value.ui; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_PEAK)) { > + bandwidth->in->peak = param->value.ui; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_BURST)) { > + bandwidth->in->burst = param->value.ui; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_IN_FLOOR)) { > + bandwidth->in->floor = param->value.ui; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE)) { > + bandwidth->out->average = param->value.ui; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_PEAK)) { > + bandwidth->out->peak = param->value.ui; > + } else if (STREQ(param->field, VIR_DOMAIN_BANDWIDTH_OUT_BURST)) { > + bandwidth->out->burst = param->value.ui; > + } > + } > + > + /* average or floor are mandatory, peak and burst are optional */ > + if (!bandwidth->in->average && !bandwidth->in->floor) > + VIR_FREE(bandwidth->in); > + if (!bandwidth->out->average) > + VIR_FREE(bandwidth->out); > + > + if (!net->bandwidth) { > + VIR_STEAL_PTR(net->bandwidth, bandwidth); > + } else { > + if (bandwidth->in) { > + VIR_FREE(net->bandwidth->in); > + VIR_STEAL_PTR(net->bandwidth->in, bandwidth->in); > + } > + if (bandwidth->out) { > + VIR_FREE(net->bandwidth->out); > + VIR_STEAL_PTR(net->bandwidth->out, bandwidth->out); > + } > + } > + > + ret = 0; > + cleanup: > + virNetDevBandwidthFree(bandwidth); > + virDomainObjEndAPI(&vm); > + return ret; > +} > + > + > static int > testDomainGetInterfaceParameters(virDomainPtr dom, > const char *device, > @@ -7617,6 +7713,7 @@ static virHypervisorDriver testHypervisorDriver = { > .domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */ > .domainGetMemoryParameters = testDomainGetMemoryParameters, /* 5.6.0 */ > .domainGetNumaParameters = testDomainGetNumaParameters, /* 5.6.0 */ > + .domainSetInterfaceParameters = testDomainSetInterfaceParameters, /* 5.6.0 */ > .domainGetInterfaceParameters = testDomainGetInterfaceParameters, /* 5.6.0 */ > .connectListDefinedDomains = testConnectListDefinedDomains, /* 0.1.11 */ > .connectNumOfDefinedDomains = testConnectNumOfDefinedDomains, /* 0.1.11 */ > -- > 2.22.0 > Oops, I forgot to prepend the subject / commit message with "test_driver: " -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list