Skip to content

Commit

Permalink
Add support for different meter types. (#484)
Browse files Browse the repository at this point in the history
* Add all changes from PR#473

* Add generated files.

* Remove redundant paragraph.

* Add note about how changing MeterConfig is a non-breaking change.
  • Loading branch information
jonathan-dilorenzo committed Aug 9, 2024
1 parent 6e8c018 commit 48e9ce8
Show file tree
Hide file tree
Showing 7 changed files with 931 additions and 682 deletions.
80 changes: 73 additions & 7 deletions docs/v1/P4Runtime-Spec.mdk
Original file line number Diff line number Diff line change
Expand Up @@ -1749,14 +1749,39 @@ Both `Meter` and `DirectMeter` messages share the following fields:
extern instance.

* `spec`, a message of type `MeterSpec` used to describe the capabilities of
this meter extern instance. Currently, the `MeterSpec` message is used to
carry only the meter unit, which can be any of the `MeterSpec.Unit` enum
values:
this meter extern instance. The `MeterSpec` message is used to describe the
meter unit and the meter type. The meter unit can be any of the
`MeterSpec.Unit` enum values:
* `UNSPECIFIED`: reserved value.
* `BYTES`, which signifies that this meter can be configured with rates
expressed in bytes/second.
* `PACKETS`, for rates expressed in packets/second.

The meter type can be any of the `MeterSpec.Type` enum values:
* `TWO_RATE_THREE_COLOR`: This is the *Two Rate Three Color Marker* (trTCM)
defined in RFC 2698 [@RFC2698]. This is the standard P4Runtime meter type
and allows meters to use two rates to split packets into three potential
colors: GREEN, YELLOW, or RED. This mode is the default, but can also be
set explicitly in a P4 program by adding the `@two_rate_three_color`
annotation to the meter definition.
For example, in a V1Model P4 program, we might define a trTCM direct meter
as follows:
~ Begin P4Example
@two_rate_three_color
direct_meter<color_type>(MeterType.bytes) my_meter;
~ End P4Example
* `SINGLE_RATE_THREE_COLOR`: This is the *Single Rate Three Color Marker*
(srTCM) defined in RFC 2697 [@RFC2697]. This allows meters to use one rate
and an Excess Burst Size (EBS) to split packets into three potential
colors: GREEN, YELLOW, or RED. In a P4 program, this mode can be set by
adding the `@single_rate_three_color` annotation to the meter definition.
* `SINGLE_RATE_TWO_COLOR`: This is a simplified version of RFC 2697
[@RFC2697], and the `SINGLE_RATE_THREE_COLOR` mode above.
`SINGLE_RATE_TWO_COLOR` restricts meters to use only a single rate
specified by the Committed Information Rate (CIR) and Committed Burst Size
(CBS) to mark packets GREEN or RED. In a P4 program, this mode can be set
by adding the `@single_rate_two_color` annotation to the meter definition.

For indexed meters, the `Meter` message contains also a `size` field, an `int64`
representing the maximum number of independent cells that can be held by this
meter. Conversely, the `DirectMeter` message contains a `direct_table_id` field
Expand Down Expand Up @@ -4269,10 +4294,26 @@ entity for each of the instances, specifying the `counter_id` and
Meters are an advanced mechanism for keeping statistics, involving stateful
"marking" and usually "throttling" of packets based on configured rates of
traffic. The PSA metering function is based on the *Two Rate Three Color Marker*
(trTCM) defined in RFC 2698 [@RFC2698]. The trTCM meters an arbitrary packet
stream using two configured rates --- the Peak Information Rate (PIR) and
Committed Information Rate (CIR), and their associated burst sizes --- and
"marks" its packets as GREEN, YELLOW or RED based on the observed rate.
(trTCM) defined in RFC 2698 [@RFC2698]. P4Runtime clients may additionally
restrict meter usage on a table to RFC 2697's [@RFC2697] *Single Rate Three
Color Marker* (srTCM) or a simplified version of it that we call *Single Rate
Two Color Marker*. The type of a table's meter is set by the `MeterSpec.Type` as
described in the [Meter & DirectMeter section](#sec-meter-directmeter).

The trTCM meters an arbitrary packet stream using two configured rates ---
the Peak Information Rate (PIR) and Committed Information Rate (CIR), and their
associated burst sizes --- and "marks" its packets as GREEN, YELLOW or RED based
on the observed rate.

The srTCM meters an arbitrary packet stream using a single configured rate ---
the Committed Information Rate (CIR) and its associated burst size --- as well
as the Excess Burst Size (EBS) and "marks" its packets as GREEN, YELLOW or RED
based on the observed rate.

The *Single Rate Two Color Marker* meters an arbitary packet stream using a
single configured rate --- the Committed Information Rate (CIR) and its
associated burst size --- and "marks" its packets as GREEN or RED based on the
observed rate.

`MeterEntry` & `DirectMeterEntry` have an additional field `counter_data` that
may hold per color counter data for targets that support it, and that must
Expand All @@ -4292,9 +4333,28 @@ message MeterConfig {
int64 cburst = 2; // Committed Burst Size
int64 pir = 3; // Peak Information Rate
int64 pburst = 4; // Peak Burst Size
int64 eburst = 5; // Excess burst size (only used for srTCM)
}
~ End Proto

A MeterConfig for a trTCM typed meter must only be accepted if `eburst` is
unset. Otherwise, the server should return an `INVALID_ARGUMENT` error.

A MeterConfig for a srTCM typed meter must only be accepted if `pir` and
`pburst` are equal to `cir` and `cburst` respectively. Otherwise, the server
should return an `INVALID_ARGUMENT` error.

A MeterConfig for a *Single Rate Two Color Marker* typed meter must only be
accepted if `pir` and `pburst` are equal to `cir` and `cburst` respectively and
`eburst` is unset. Otherwise, the server should return an `INVALID_ARGUMENT`
error.

Note: Any acceptable MeterConfig for a *Single Rate Two Color Marker* typed
meter is also acceptable for either of the other two meter types and will mark
packets identically in all three cases. Thus, changing the meter type from
*Single Rate Two Color Marker* to *Single Rate Three Color Marker* or
*Two Rate Three Color Marker* is a non-breaking change.

### `DirectMeterEntry`

A direct meter is a direct resource associated with a `TableEntry` (see [Direct
Expand Down Expand Up @@ -6482,6 +6542,9 @@ properties, but we may include on in future versions of the API.

### Changes in v1.4.0

* Add a `Type` field to the `MeterSpec` message allowing users to restrict the
type of meters that can be used for a table and a new `eburst` field to the
`MeterConfig` message for use with one of the new `MeterSpec` types.
* Add a `PlatformProperties` message specifying desired underlying platform
properties to the `PkgInfo` message.
* Add a `metadata` field to the `MulticastGroupEntry` message.
Expand Down Expand Up @@ -6588,6 +6651,9 @@ the purpose of adding features for the P4Runtime API.
| `@max_group_size` | See sections [#sec-p4info-action-profile], [#sec-action-profile-group-programming] |
| `@selector_size_semantics` | See section [#sec-p4info-action-profile] |
| `@max_member_weight` | See section [#sec-p4info-action-profile] |
| `@two_rate_three_color` | See section [#sec-meter-directmeter] |
| `@single_rate_three_color` | See section [#sec-meter-directmeter] |
| `@single_rate_two_color` | See section [#sec-meter-directmeter] |
| `@pkginfo` | See section [#sec-annotating-p4-code-with-pkginfo] |
| `@platform_property` | See section [#sec-annotating-p4-code-with-pkginfo] |
| `@p4runtime_translation` | See sections [#sec-user-defined-types], [#sec-translation-of-port-numbers] |
Expand Down
Loading

0 comments on commit 48e9ce8

Please sign in to comment.