2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

smap: New function smap_get_ullong().

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Ryan Moats <rmoats@us.ibm.com>
This commit is contained in:
Ben Pfaff
2016-07-20 16:44:09 -07:00
parent f99f67bd87
commit 13c1637f5b
5 changed files with 90 additions and 186 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -2937,17 +2937,9 @@ static void
codel_parse_qdisc_details__(struct netdev *netdev OVS_UNUSED,
const struct smap *details, struct codel *codel)
{
const char *target_s;
const char *limit_s;
const char *interval_s;
target_s = smap_get(details, "target");
limit_s = smap_get(details, "limit");
interval_s = smap_get(details, "interval");
codel->target = target_s ? strtoull(target_s, NULL, 10) : 0;
codel->limit = limit_s ? strtoull(limit_s, NULL, 10) : 0;
codel->interval = interval_s ? strtoull(interval_s, NULL, 10) : 0;
codel->target = smap_get_ullong(details, "target", 0);
codel->limit = smap_get_ullong(details, "limit", 0);
codel->interval = smap_get_ullong(details, "interval", 0);
if (!codel->target) {
codel->target = 5000;
@@ -3168,22 +3160,12 @@ static void
fqcodel_parse_qdisc_details__(struct netdev *netdev OVS_UNUSED,
const struct smap *details, struct fqcodel *fqcodel)
{
const char *target_s;
const char *limit_s;
const char *interval_s;
const char *flows_s;
const char *quantum_s;
fqcodel->target = smap_get_ullong(details, "target", 0);
fqcodel->limit = smap_get_ullong(details, "limit", 0);
fqcodel->interval = smap_get_ullong(details, "interval", 0);
fqcodel->flows = smap_get_ullong(details, "flows", 0);
fqcodel->quantum = smap_get_ullong(details, "quantum", 0);
target_s = smap_get(details, "target");
limit_s = smap_get(details, "limit");
interval_s = smap_get(details, "interval");
flows_s = smap_get(details, "flows");
quantum_s = smap_get(details, "quantum");
fqcodel->target = target_s ? strtoull(target_s, NULL, 10) : 0;
fqcodel->limit = limit_s ? strtoull(limit_s, NULL, 10) : 0;
fqcodel->interval = interval_s ? strtoull(interval_s, NULL, 10) : 0;
fqcodel->flows = flows_s ? strtoull(flows_s, NULL, 10) : 0;
fqcodel->quantum = quantum_s ? strtoull(quantum_s, NULL, 10) : 0;
if (!fqcodel->target) {
fqcodel->target = 5000;
}
@@ -3404,27 +3386,20 @@ static void
sfq_parse_qdisc_details__(struct netdev *netdev,
const struct smap *details, struct sfq *sfq)
{
const char *perturb_s;
const char *quantum_s;
int mtu;
int mtu_error;
sfq->perturb = smap_get_ullong(details, "perturb", 0);
sfq->quantum = smap_get_ullong(details, "quantum", 0);
perturb_s = smap_get(details, "perturb");
quantum_s = smap_get(details, "quantum");
sfq->perturb = perturb_s ? strtoull(perturb_s, NULL, 10) : 0;
sfq->quantum = quantum_s ? strtoull(quantum_s, NULL, 10) : 0;
if (!sfq->perturb) {
sfq->perturb = 10;
}
if (!sfq->quantum) {
mtu_error = netdev_linux_get_mtu__(netdev_linux_cast(netdev), &mtu);
if (!mtu_error) {
int mtu;
if (!netdev_linux_get_mtu__(netdev_linux_cast(netdev), &mtu)) {
sfq->quantum = mtu;
} else {
VLOG_WARN_RL(&rl, "when using SFQ, you must specify quantum on a "
"device without mtu");
return;
}
}
}
@@ -3697,10 +3672,8 @@ htb_parse_qdisc_details__(struct netdev *netdev_,
const struct smap *details, struct htb_class *hc)
{
struct netdev_linux *netdev = netdev_linux_cast(netdev_);
const char *max_rate_s;
max_rate_s = smap_get(details, "max-rate");
hc->max_rate = max_rate_s ? strtoull(max_rate_s, NULL, 10) / 8 : 0;
hc->max_rate = smap_get_ullong(details, "max-rate", 0) / 8;
if (!hc->max_rate) {
enum netdev_features current;
@@ -3718,10 +3691,6 @@ htb_parse_class_details__(struct netdev *netdev,
const struct smap *details, struct htb_class *hc)
{
const struct htb *htb = htb_get__(netdev);
const char *min_rate_s = smap_get(details, "min-rate");
const char *max_rate_s = smap_get(details, "max-rate");
const char *burst_s = smap_get(details, "burst");
const char *priority_s = smap_get(details, "priority");
int mtu, error;
error = netdev_linux_get_mtu__(netdev_linux_cast(netdev), &mtu);
@@ -3733,14 +3702,15 @@ htb_parse_class_details__(struct netdev *netdev,
/* HTB requires at least an mtu sized min-rate to send any traffic even
* on uncongested links. */
hc->min_rate = min_rate_s ? strtoull(min_rate_s, NULL, 10) / 8 : 0;
hc->min_rate = smap_get_ullong(details, "min-rate", 0) / 8;
hc->min_rate = MAX(hc->min_rate, mtu);
hc->min_rate = MIN(hc->min_rate, htb->max_rate);
/* max-rate */
hc->max_rate = (max_rate_s
? strtoull(max_rate_s, NULL, 10) / 8
: htb->max_rate);
hc->max_rate = smap_get_ullong(details, "max-rate", 0) / 8;
if (!hc->max_rate) {
hc->max_rate = htb->max_rate;
}
hc->max_rate = MAX(hc->max_rate, hc->min_rate);
hc->max_rate = MIN(hc->max_rate, htb->max_rate);
@@ -3753,11 +3723,11 @@ htb_parse_class_details__(struct netdev *netdev,
* doesn't include the Ethernet header, we need to add at least 14 (18?) to
* the MTU. We actually add 64, instead of 14, as a guard against
* additional headers get tacked on somewhere that we're not aware of. */
hc->burst = burst_s ? strtoull(burst_s, NULL, 10) / 8 : 0;
hc->burst = smap_get_ullong(details, "burst", 0) / 8;
hc->burst = MAX(hc->burst, mtu + 64);
/* priority */
hc->priority = priority_s ? strtoul(priority_s, NULL, 10) : 0;
hc->priority = smap_get_ullong(details, "priority", 0);
return 0;
}
@@ -4175,12 +4145,8 @@ hfsc_parse_qdisc_details__(struct netdev *netdev_, const struct smap *details,
struct hfsc_class *class)
{
struct netdev_linux *netdev = netdev_linux_cast(netdev_);
uint32_t max_rate;
const char *max_rate_s;
max_rate_s = smap_get(details, "max-rate");
max_rate = max_rate_s ? strtoull(max_rate_s, NULL, 10) / 8 : 0;
uint32_t max_rate = smap_get_ullong(details, "max-rate", 0) / 8;
if (!max_rate) {
enum netdev_features current;
@@ -4200,19 +4166,14 @@ hfsc_parse_class_details__(struct netdev *netdev,
{
const struct hfsc *hfsc;
uint32_t min_rate, max_rate;
const char *min_rate_s, *max_rate_s;
hfsc = hfsc_get__(netdev);
min_rate_s = smap_get(details, "min-rate");
max_rate_s = smap_get(details, "max-rate");
min_rate = min_rate_s ? strtoull(min_rate_s, NULL, 10) / 8 : 0;
min_rate = smap_get_ullong(details, "min-rate", 0) / 8;
min_rate = MAX(min_rate, 1);
min_rate = MIN(min_rate, hfsc->max_rate);
max_rate = (max_rate_s
? strtoull(max_rate_s, NULL, 10) / 8
: hfsc->max_rate);
max_rate = smap_get_ullong(details, "max-rate", hfsc->max_rate * 8) / 8;
max_rate = MAX(max_rate, min_rate);
max_rate = MIN(max_rate, hfsc->max_rate);