Skip to content

Add PSA meter example demonstrating indirect Meter and DirectMeter with color-aware policing#1402

Merged
jafingerhut merged 2 commits into
p4lang:mainfrom
Devansh-567:fix/psa-meter-example-doc-cleanup
May 24, 2026
Merged

Add PSA meter example demonstrating indirect Meter and DirectMeter with color-aware policing#1402
jafingerhut merged 2 commits into
p4lang:mainfrom
Devansh-567:fix/psa-meter-example-doc-cleanup

Conversation

@Devansh-567

Copy link
Copy Markdown
Contributor

Adds psa-example-meters.p4, a new PSA example demonstrating traffic policing using the Meter and DirectMeter externs. The example covers:

  • Per-port indirect Meter for aggregate port rate limiting
  • Per-prefix DirectMeter attached to an LPM table for per-route policing
  • Color-aware metering (RFC 2698) where port color is passed to the DirectMeter
  • Egress rate limiting using a second indirect Meter

A meter example was missing from the PSA examples directory despite Meter and DirectMeter being defined in psa-for-bmv2.p4.

While psa-example-counters.p4 covers counters, meters have different semantics (rate limiting vs counting), which justify a dedicated example.

…th color-aware policing

Signed-off-by: Devansh-567 <devansh.jay.singh@gmail.com>
@jafingerhut

Copy link
Copy Markdown
Collaborator

Overall, this looks very good! Thanks for submitting it.

@Devansh-567

Copy link
Copy Markdown
Contributor Author

Overall, this looks very good! Thanks for submitting it.

Thank you for the feedback! Could you submit a formal review approval when you get a chance so this can be merged?

@jafingerhut

Copy link
Copy Markdown
Collaborator

Overall, this looks very good! Thanks for submitting it.

Thank you for the feedback! Could you submit a formal review approval when you get a chance so this can be merged?

I have added 4 comments that I hope you can make changes to address before I approve.

@Devansh-567

Copy link
Copy Markdown
Contributor Author

Hi, thank you for the review! I am having trouble viewing the inline comments on GitHub. Could you please paste them here so I can address them? I want to make sure I implement all your suggestions correctly before you approve.

@jafingerhut

Copy link
Copy Markdown
Collaborator

Can you not see comments when you go to the page for the PR and scroll down? #1402

@Devansh-567

Copy link
Copy Markdown
Contributor Author

Can you not see comments when you go to the page for the PR and scroll down? #1402

Hi @jafingerhut, thanks for following up.

When I open the PR conversation and “Files changed” tabs, I’m unfortunately not seeing the 4 inline review comments you mentioned, it may be a GitHub UI/loading issue on my side.

Could you please either:

  • re-post the comments in the conversation thread, or
  • point me to the affected file/line locations?

Once I can see the requested changes, I’ll address them promptly. Thanks again for the review.

@jafingerhut jafingerhut left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Trying to leave publicly viewable comments requesting changes.

@@ -0,0 +1,380 @@
/*
Copyright 2026 Contributors to the P4 Language Consortium

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please change to "Copyright 2026 The P4 Language Consortium". Minor nit, I know. I am on a sweep of issues for copyright and license details across p4lang repos.

/*
Copyright 2026 Contributors to the P4 Language Consortium

Licensed under the Apache License, Version 2.0 (the "License");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can replace all of these paragraphs with:

 * SPDX-License-Identifier: Apache-2.0

EgressDeparserImpl()) ep;

PSA_Switch(ip, PacketReplicationEngine(), ep, BufferingQueueingEngine()) main;
// end::Meter_Example_Package[] No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please remove the lines beginning with "// tag::" and "// end::". They are only needed for examples that we want to show an excerpt of in the PSA specification document.

Comment thread p4-16/psa/examples/psa-example-meters.p4 Outdated
@jafingerhut

Copy link
Copy Markdown
Collaborator

Once I can see the requested changes, I’ll address them promptly. Thanks again for the review.

Sorry, I think it was my fault in that I did not click the correct sequence of buttons to make my comments visible. Please look again. I can see them now even when I look at this issue from a browser where I am not logged in to Github with any account at all.

Signed-off-by: Devansh-567 <devansh.jay.singh@gmail.com>
@Devansh-567
Devansh-567 force-pushed the fix/psa-meter-example-doc-cleanup branch from 45686a9 to adedcea Compare May 24, 2026 16:33
@Devansh-567

Copy link
Copy Markdown
Contributor Author

Thanks for the review comments. I’ve addressed all requested changes:

  • Updated the copyright line to “The P4 Language Consortium”
  • Replaced the Apache boilerplate with the SPDX identifier
  • Removed all // tag:: and // end:: lines
  • Fixed the inconsistent egress metering comment to match the implemented RED packet drop behavior
  • Ensured the file ends with a newline

Please take another look when you have time. Thanks again for the review.

@jafingerhut
jafingerhut merged commit c5ee2c4 into p4lang:main May 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants