Sampling primitives in P4


As traffic volumes grow, sampling becomes indispensable for building memory- and communication-efficient in-network monitoring applications. Traditional switches only implement uniform random sampling [2], which is too restrictive for building a larger class of applications. For example, networks that want to prove their performance to end-users must sample packet reports using a special, secure version of sampling [4]. Programmable switches [1] offer the opportunity to have custom sampling algorithms implemented in the data plane, but lack the ability to perform complex computations, e.g., no support for loops.

Work packages

This thesis will implement different sampling primitives in P4 and explore performance/security trade-offs with increasing traffic volumes.

  • WP1: Get familiar with the P4 language and the Tofino switch [3].
  • WP2: Implement random uniform sampling (e.g., using the available CRC 16/32 bit checksums) and evaluate: i) its ability to produce uniform, unbiased samples and ii) how it scales with increasing traffic volumes.
  • WP3: Leverage the uniform sampling primitive to implement Retroactive Sampling (RS) [4]. Experiment with increasing traffic volumes and evaluate how the memory/compute limitations of programmable switches affect the security properties of RS, given that RS requires that switches buffer and iterate over packets reports.


  • Knowledge in P4 programming or knowledge in C and motivation to learn about P4 at the beginning of the thesis.