Creating queues in P4

Hello everyone,

I want to implement some Active Queue Management algorithms in a P4 program, such as queue priority. But I don’t know how to express a queue in P4 code and whether it is possible to create multiple queues in a single P4 target. Do you have any suggestion on this?

Thanks!

I am not aware of any P4 targets that let you create or destroy packet queues from the P4 source code.

There are targets that let you create or destroy packet queues from the control plane code, e.g. Tofino switches let you configure up to a chip-specific maximum number of queues per physical output port, for different classes of service, and also configure what packet scheduling algorithm and parameters are used to select which queue to dequeue a packet from next for that output port, if more than one of them is non-empty.

The BMv2 software switch (if compiled from source code dated 2022-Apr-05 or later) has a command line option --priority-queue <num_queues> that lets you specify the number of class of service queues per output port that the traffic manager has.

In Tofino or BMv2 ingress code, you can assign a value to a queue id that selects which of the multiple class-of-service queues for the destination output port of the packet that the packet will be enqueued in.

Even though you are unlikely to find a target that lets you create new queues at the time scale of arriving packets, if you create a lot of them before packets arrive, you can use P4 code to select which of those existing queues a packet will go into, and the subset of queues you actually choose to use can grow and shrink over time, as long as it is always a subset of those that have been created.

1 Like

Thank you, @andyfingerhut. I’m using a Development VM, so if I want to change the number of queues per output port, I have to log in as user vagrant and go to the behavioral-model/targets/… and change the parameter, I have seen a variable named nb_queues_per_port. Is that right?

If your simple_switch_grpc binary was built from source code more recent than 2022-Apr-05, then you do not need to change the source code at all (and I would recommend getting a version of simple_switch_grpc built from source code more recent than that, if you do not already). You need to ensure that when simple_switch_grpc processes are started, that they are started with the desired command line options, including --priority-queue <number_of_queues>. If you are using the tutorials repository scripts, that might require finding the proper Python source file that is constructing the simple_switch_grpc command lines that are executed, and modify that Python file to add those options.

Hello @andyfingerhut, sorry for the late reply.

I’ve followed your suggestion but unfortunately, I still didn’t figure it out. So I think I need to provide you the context of my situation and what steps that I’ve done so that you may better understand it. And also, I’m totally a newbie in this field, so I hope that you’ll understand if I have too many naive questions and my limited capabilities. Thank you!

My context:
I’m using the latest “Development VM” (2023-Apr-03), I have cloned the tutorials repo from Github and working on the basic.p4 exercise.

What I want to do is to create 2 queues per port on each switch in the topology. I’ve opened the MakeFile, and it said that I’m using simple_switch_grpc
MakeFile

I go to the basic exercise directory in the terminal and make build the program. You’ve said if I use the tutorials repo, I need to find a Python file and modify it to add the --priority-queues option. But when I go to the build folder and type in simple_switch_grpc --help and I see the --priority-queues command. So I assume that it is not necessary, also because I’m not familiar with the suggest of modifying some Python file.

Then I type in the following:

And I make run the program on a second terminal and I got this error:

This is the s1-log

So I guess the command I have typed earlier (simple_switch_grpc basic.json -- --priority-queues 2) is not related to switches in the basic exercise, they’re just two different processes.

I try to change the grpc-server-addr to the one to which s1 connects, which is 127.0.0.0:50051

And I got this result:

My questions are:

  1. Does finding and modifying the specific Python file you’ve mention is a must, because I was able to type in the command simple_switch_grpc basic.json -- --priority-queues 2 in the basic exercise directory?
    This is the content of the utils folder in the tutorials repo:

  2. More important, how can I “implement” the --priority-queues <number of queue> on switches in the basic exercise? I’ll be able to do that just by the command above if everything is configured properly or I need to do something else.

  3. I went into the /home/vagrant/behavioral-model/targets/simple_switch_grpc and opened switch_runner.h file. I saw this:
    image
    Am I supposed to change the default_nb_queues_per_port to another value, does that make any different?

Thank you for taking the time to read this post, I know this is a very long post, but I really need this problem to be solved. And if I have some misconception, it would be great if you could point out them to me.

I’m looking forward to hearing your answers, they will mean the world to me.