[P4-dev] How to dynamically set egress output port

Eric Ruan ruanweizhang at gmail.com
Sat Jul 15 00:19:33 EDT 2017

Hi Antonin,

Thanks for your kind replay. I am new to p4, your answer indeed solves some
questions in my mind.


2017-07-15 5:34 GMT+08:00 Antonin Bas <antonin at barefootnetworks.com>:

> Hi Eric,
> You are confusing port speed configuration with link utilization I think.
> The switchapi snippet lists all the supported port speeds. An application
> using switchapi can use this to configure ports on the device. Note that
> port speed configuration is completely out of scope of the P4 language. But
> this is different from link utilization... For example a 40Gbps port can be
> transmitting at 30Gbps and the link is utilized at 75%.
> It seems that what you are trying to do is adapt your routing algorithm to
> link utilization. There is no standard way in P4 to access live link
> utilization. You may have a hardware target that exposes this information
> to your program (e.g. through a P4_16 extern). You may also find a way to
> approximate this number by using a moving average and by using stateful
> registers, but that's actually pretty hard (no division...).
> I think you need to make sure you understand the scope of P4 as well as
> what switchapi is. switchapi is part of a control plane stack that was
> written specifically for switch.p4, which is one example of a P4 program.
> In your question, you ask how to call a switchapi method for the P4 code,
> which doesn't make sense.
> Best,
> Antonin
> On Fri, Jul 14, 2017 at 3:01 AM, Eric Ruan <ruanweizhang at gmail.com> wrote:
>> Hello everyone,
>> I am trying to dynamically set egress port for a packet.
>> I think the possible way is to request the current port
>> bit rate of physical output ports and then use if-else sentences to
>> dynamically set up the egress port in the ingress pipeline stage.
>> Then I came up with some questions.
>> Q1: in this link *https://goo.gl/jqmD64 <https://goo.gl/jqmD64>*
>> /** port speed */
>> typedef enum {
>>   SWITCH_API_PORT_SPEED_NONE, /**< Port Speed Not set */
>>   SWITCH_API_PORT_SPEED_1G,   /**< port speed 1G */
>>   SWITCH_API_PORT_SPEED_10G,  /**< port speed 10G */
>>   SWITCH_API_PORT_SPEED_25G,  /**< port speed 25G */
>>   SWITCH_API_PORT_SPEED_40G,  /**< port speed 40G */
>>   SWITCH_API_PORT_SPEED_50G,  /**< port speed 50G */
>>   SWITCH_API_PORT_SPEED_100G  /**< port speed 100G */
>> } switch_port_speed_t;
>> where switch_port_speed_t is not continuous number, how can it
>> accurately record the current bit rate of a physical output port?
>> Q2: again in the same link *https://goo.gl/jqmD64
>> <https://goo.gl/jqmD64>*
>> the get function is like this, but I couldn't find any example on Internet
>> on how to use this. Since it is written in C/C++ language, I don't know
>> how
>> to call this function in p4 program.
>> switch_status_t switch_api_port_speed_get(switch_device_t device,
>>                                           switch_port_t port,
>>                                           switch_port_speed_t *speed) {
>> }
>> Thanks in advance.
>> Best,
>> Eric
>> _______________________________________________
>> P4-dev mailing list
>> P4-dev at lists.p4.org
>> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
> --
> Antonin

Eric Yuen
交通大學 網路工程所 博士班
Institute of Network Engineering
National Chiao Tung University

Email: ruanweizhang at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170715/bb73b861/attachment-0002.html>

More information about the P4-dev mailing list