2018-02-01 17:18:17 +00:00
|
|
|
.. SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
Copyright(c) 2015 Intel Corporation.
|
2015-02-25 19:46:02 +00:00
|
|
|
|
|
|
|
RX/TX Callbacks Sample Application
|
|
|
|
==================================
|
|
|
|
|
|
|
|
The RX/TX Callbacks sample application is a packet forwarding application that
|
|
|
|
demonstrates the use of user defined callbacks on received and transmitted
|
|
|
|
packets. The application performs a simple latency check, using callbacks, to
|
|
|
|
determine the time packets spend within the application.
|
|
|
|
|
|
|
|
In the sample application a user defined callback is applied to all received
|
|
|
|
packets to add a timestamp. A separate callback is applied to all packets
|
|
|
|
prior to transmission to calculate the elapsed time, in CPU cycles.
|
|
|
|
|
2019-05-02 12:11:35 +00:00
|
|
|
If hardware timestamping is supported by the NIC, the sample application will
|
|
|
|
also display the average latency since the packet was timestamped in hardware,
|
|
|
|
on top of the latency since the packet was received and processed by the RX
|
|
|
|
callback.
|
2015-02-25 19:46:02 +00:00
|
|
|
|
|
|
|
Compiling the Application
|
|
|
|
-------------------------
|
|
|
|
|
2017-10-25 15:50:59 +00:00
|
|
|
To compile the sample application see :doc:`compiling`.
|
2015-02-25 19:46:02 +00:00
|
|
|
|
2017-10-25 15:50:59 +00:00
|
|
|
The application is located in the ``rxtx_callbacks`` sub-directory.
|
2015-02-25 19:46:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
Running the Application
|
|
|
|
-----------------------
|
|
|
|
|
2019-03-06 16:22:42 +00:00
|
|
|
To run the example in a ``linux`` environment:
|
2015-02-25 19:46:02 +00:00
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2020-10-21 08:17:20 +00:00
|
|
|
./<build_dir>/examples/dpdk-rxtx_callbacks -l 1 -n 4 -- [-t]
|
2019-05-02 12:11:35 +00:00
|
|
|
|
|
|
|
Use -t to enable hardware timestamping. If not supported by the NIC, an error
|
|
|
|
will be displayed.
|
2015-02-25 19:46:02 +00:00
|
|
|
|
|
|
|
Refer to *DPDK Getting Started Guide* for general information on running
|
|
|
|
applications and the Environment Abstraction Layer (EAL) options.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Explanation
|
|
|
|
-----------
|
|
|
|
|
|
|
|
The ``rxtx_callbacks`` application is mainly a simple forwarding application
|
|
|
|
based on the :doc:`skeleton`. See that section of the documentation for more
|
|
|
|
details of the forwarding part of the application.
|
|
|
|
|
|
|
|
The sections below explain the additional RX/TX callback code.
|
|
|
|
|
|
|
|
|
|
|
|
The Main Function
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
The ``main()`` function performs the application initialization and calls the
|
|
|
|
execution threads for each lcore. This function is effectively identical to
|
|
|
|
the ``main()`` function explained in :doc:`skeleton`.
|
|
|
|
|
|
|
|
The ``lcore_main()`` function is also identical.
|
|
|
|
|
|
|
|
The main difference is in the user defined ``port_init()`` function where the
|
|
|
|
callbacks are added. This is explained in the next section:
|
|
|
|
|
|
|
|
|
|
|
|
The Port Initialization Function
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
The main functional part of the port initialization is shown below with
|
|
|
|
comments:
|
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
.. literalinclude:: ../../../examples/rxtx_callbacks/main.c
|
|
|
|
:language: c
|
|
|
|
:start-after: Port initialization. 8<
|
|
|
|
:end-before: >8 End of port initialization.
|
2015-02-25 19:46:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
The RX and TX callbacks are added to the ports/queues as function pointers:
|
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
.. literalinclude:: ../../../examples/rxtx_callbacks/main.c
|
|
|
|
:language: c
|
|
|
|
:start-after: RX and TX callbacks are added to the ports. 8<
|
|
|
|
:end-before: >8 End of RX and TX callbacks.
|
|
|
|
:dedent: 1
|
2015-02-25 19:46:02 +00:00
|
|
|
|
|
|
|
More than one callback can be added and additional information can be passed
|
|
|
|
to callback function pointers as a ``void*``. In the examples above ``NULL``
|
|
|
|
is used.
|
|
|
|
|
|
|
|
The ``add_timestamps()`` and ``calc_latency()`` functions are explained below.
|
|
|
|
|
|
|
|
|
|
|
|
The add_timestamps() Callback
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
The ``add_timestamps()`` callback is added to the RX port and is applied to
|
|
|
|
all packets received:
|
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
.. literalinclude:: ../../../examples/rxtx_callbacks/main.c
|
|
|
|
:language: c
|
|
|
|
:start-after: Callback added to the RX port and applied to packets. 8<
|
|
|
|
:end-before: >8 End of callback addition and application.
|
2015-02-25 19:46:02 +00:00
|
|
|
|
|
|
|
The DPDK function ``rte_rdtsc()`` is used to add a cycle count timestamp to
|
|
|
|
each packet (see the *cycles* section of the *DPDK API Documentation* for
|
|
|
|
details).
|
|
|
|
|
|
|
|
|
|
|
|
The calc_latency() Callback
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
The ``calc_latency()`` callback is added to the TX port and is applied to all
|
|
|
|
packets prior to transmission:
|
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
.. literalinclude:: ../../../examples/rxtx_callbacks/main.c
|
|
|
|
:language: c
|
|
|
|
:start-after: Callback is added to the TX port. 8<
|
|
|
|
:end-before: >8 End of callback addition.
|
2015-02-25 19:46:02 +00:00
|
|
|
|
|
|
|
The ``calc_latency()`` function accumulates the total number of packets and
|
|
|
|
the total number of cycles used. Once more than 100 million packets have been
|
|
|
|
transmitted the average cycle count per packet is printed out and the counters
|
|
|
|
are reset.
|