I’m new here. I’m working on a load test project for the p4 language, and I am trying to implement a simple network, including a switch and a host. In network communication, I need timing functions to record the timestamp and calculate the time cost for further analysis, such as measuring the sending/receiving rate and speed. I’d like to know if there is any existing implementation of such functions or modules so that I can apply them to my project. Thank you!
The answer to your question really depends on the P4 target you plan to use and its P4 architecture. You can read the detailed explanation here.
In general, I can say that most P4 architectures offer at least one (ingress) timestamp in the form of intrinsic metadata. The precision of that timestamp is also target-dependent, although many hardware targets typically provide 1ns resolution.
However, there is a big difference between an ingress timestamp and the ability to calculate the packet or the data rate. Those require you to be able to keep some sort of a state, the ability to use that state to calculate EWMA and (in case of the data rate) the ability to get the packet length (which is not always trivial, especially in ingress).
Obviously, there is usually no problem doing all that (and more) on an unrestricted SW target (or in the control plane), but a real HW target will typically require some advanced capabilities. For example, Intel Tofino offers a special Lpf() extern that is capable of calculating packet or data rates in the data plane.
Ultimately, though, I’d start with the precise definition of what you are trying to measure and why. There are a lot of ways of performing measurements and choosing the right one depends on the task at hand.
Of course, I have done this in the context of TFS controller, but I believe that with some modifications, you can do it for your case if you are using another controller.
(I also believe that there had been developments in the Monitoring part of TFS and I remember some discussions regarding INT in the past, but unfortunately I have stopped following TFS closely the last year. So maybe you can also ask in TFS slack)