Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add units for meter rate to documentation of simple_switch #753

Merged
merged 16 commits into from
Apr 25, 2019
Merged
5 changes: 5 additions & 0 deletions docs/simple_switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -685,3 +685,8 @@ you have two actions for table `t` where one has the action
`m.read(result_field2)`, or if both of those calls are in the same
action. All calls to the `read()` method for `m` must have the same
result parameter where the result is written.

### BMv2 `meter rate units` implementation notes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this documentation for? The runtime CLI? The Thrift service? The PD API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simple_switch_CLI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not accurate then
IIRC, the burst size is in "units" (packets or bytes) and the rate is in "units per microsecond" (https://github.com/p4lang/behavioral-model/blob/master/thrift_src/standard.thrift#L88)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, even I quoted the same line of code in the Slack channel today. But, seeing the code in pd_helpers.cpp, I saw the conversion from kbps and kbits. This cpp code also happens to be the only code in the behavioral-model repo converting rate and burst_size and thus I assumed the code is used with simpe_switch_CLI as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not accurate then
IIRC, the burst size is in "units" (packets or bytes) and the rate is in "units per microsecond" (https://github.com/p4lang/behavioral-model/blob/master/thrift_src/standard.thrift#L88)

There is some confusion. Based on your reply for meter type as packet, its "units in microsecond" and this is the relevant code in pd_helpers.cpp. I see the division by 10^6 for microseconds.

info_rate = static_cast<double>(meter_spec->cir_pps) / 1000000.;

Isn't the user input captured by simple_switch_CLI in meter_spec->cir_pps and thus the user inputs in pps units? Or is the code in pd_helpers.cpp not used at all by simple_switch_CLI?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PD layer is not used at all by the CLI. If you look at the CLI code, you will see that it calls the Thrift service directly.
It is fine to have this information in simple_switch.md BTW, but it would be far more useful to improve the runtime_CLI help message for the meter_set_rates CLI command, so that users can get this information directly from the CLI a they are using it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will edit the simple_switch.md doc for CLI rates and burst_size. Even, I was thinking of adding the help message for the meter_set_rates. I will add that. Thanks!


The user enters the meter rate and burtsize in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds reasonable that the meter rate is in units of bytes per microsec, but the units of "burst size" should be some kind of unit like bytes. It has nothing to do with time. I do not know if simple_switch uses bytes or some other unit like kilobytes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the names of variables and some of the math done to convert units, it appears like perhaps the burst sizes are specified in multiples of 1000 bits (Kbits would be confusing to many people, I think, as it would often be interpreted as multiples of 1024 bits).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, these are likely the units used when a meter has meter type equal to MeterType.bytes in v1model.

Does BMv2 support different behavior for meters that have a type equal to MeterType.packets ?

If so, what are the units of the meter rates and burst sizes for such meters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds reasonable that the meter rate is in units of bytes per microsec, but the units of "burst size" should be some kind of unit like bytes. It has nothing to do with time. I do not know if simple_switch uses bytes or some other unit like kilobytes.

Sorry, I missed the burst_size in bytes. I will change the doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the names of variables and some of the math done to convert units, it appears like perhaps the burst sizes are specified in multiples of 1000 bits (Kbits would be confusing to many people, I think, as it would often be interpreted as multiples of 1024 bits).

Makes sense to use number of kilo octets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, these are likely the units used when a meter has meter type equal to MeterType.bytes in v1model.

Does BMv2 support different behavior for meters that have a type equal to MeterType.packets ?

If so, what are the units of the meter rates and burst sizes for such meters?

pps and packets.

units of bytes/microsec.
12 changes: 8 additions & 4 deletions pdfixed/src/pd_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ pd_bytes_meter_spec_to_rates(p4_pd_bytes_meter_spec_t *meter_spec) {
// bytes per microsecond
info_rate = static_cast<double>(meter_spec->cir_kbps) / 8000.;
burst_size = meter_spec->cburst_kbits * 1000 / 8;
rate.units_per_micros = info_rate; rate.burst_size = burst_size;
rate.units_per_micros = info_rate;
rate.burst_size = burst_size;
rates.push_back(rate);

info_rate = static_cast<double>(meter_spec->pir_kbps) / 8000.;
burst_size = meter_spec->pburst_kbits * 1000 / 8;
rate.units_per_micros = info_rate; rate.burst_size = burst_size;
rate.units_per_micros = info_rate;
rate.burst_size = burst_size;
rates.push_back(rate);

return rates;
Expand All @@ -55,12 +57,14 @@ pd_packets_meter_spec_to_rates(p4_pd_packets_meter_spec_t *meter_spec) {

info_rate = static_cast<double>(meter_spec->cir_pps) / 1000000.;
burst_size = meter_spec->cburst_pkts;
rate.units_per_micros = info_rate; rate.burst_size = burst_size;
rate.units_per_micros = info_rate;
rate.burst_size = burst_size;
rates.push_back(rate);

info_rate = static_cast<double>(meter_spec->pir_pps) / 1000000.;
burst_size = meter_spec->pburst_pkts;
rate.units_per_micros = info_rate; rate.burst_size = burst_size;
rate.units_per_micros = info_rate;
rate.burst_size = burst_size;
rates.push_back(rate);

return rates;
Expand Down