114d7ea25SSunil Kumar Kori.. SPDX-License-Identifier: BSD-3-Clause 214d7ea25SSunil Kumar Kori Copyright(c) 2010-2014 Intel Corporation. 314d7ea25SSunil Kumar Kori 414d7ea25SSunil Kumar KoriL2 Forwarding Eventdev Sample Application 514d7ea25SSunil Kumar Kori========================================= 614d7ea25SSunil Kumar Kori 7*8750576fSNandini PersadThe L2 Forwarding eventdev sample application is an example of 8*8750576fSNandini Persadpacket processing using the Data Plane Development Kit (DPDK) 9*8750576fSNandini Persadto demonstrate the usage of the poll and event mode packet I/O mechanism. 1014d7ea25SSunil Kumar Kori 1114d7ea25SSunil Kumar KoriOverview 1214d7ea25SSunil Kumar Kori-------- 1314d7ea25SSunil Kumar Kori 14*8750576fSNandini PersadThe L2 forwarding eventdev sample application performs 15*8750576fSNandini PersadL2 forwarding for each packet that is received on an Rx port. 16*8750576fSNandini PersadThe destination port is the adjacent port from the enabled portmask. 17*8750576fSNandini PersadIf the first four ports are enabled (portmask=0x0f), 18*8750576fSNandini Persadports 1 and 2 forward into each other, 19*8750576fSNandini Persadand ports 3 and 4 forward into each other. 20*8750576fSNandini PersadAlso, if MAC address updating is enabled, 21*8750576fSNandini Persadthe MAC addresses are affected as follows: 2214d7ea25SSunil Kumar Kori 23*8750576fSNandini Persad* The source MAC address is replaced by the Tx port MAC address 24*8750576fSNandini Persad* The destination MAC address is replaced by 02:00:00:00:00:<Tx port> 2514d7ea25SSunil Kumar Kori 26*8750576fSNandini PersadApplication receives packets from Rx port using these methods: 2714d7ea25SSunil Kumar Kori 2814d7ea25SSunil Kumar Kori* Poll mode 2914d7ea25SSunil Kumar Kori* Eventdev mode (default) 3014d7ea25SSunil Kumar Kori 3114d7ea25SSunil Kumar KoriThis application can be used to benchmark performance using a traffic-generator, 3214d7ea25SSunil Kumar Korias shown in the :numref:`figure_l2fwd_event_benchmark_setup`. 3314d7ea25SSunil Kumar Kori 3414d7ea25SSunil Kumar Kori.. _figure_l2fwd_event_benchmark_setup: 3514d7ea25SSunil Kumar Kori 3614d7ea25SSunil Kumar Kori.. figure:: img/l2_fwd_benchmark_setup.* 3714d7ea25SSunil Kumar Kori 3814d7ea25SSunil Kumar Kori Performance Benchmark Setup (Basic Environment) 3914d7ea25SSunil Kumar Kori 4014d7ea25SSunil Kumar KoriCompiling the Application 4114d7ea25SSunil Kumar Kori------------------------- 4214d7ea25SSunil Kumar Kori 43*8750576fSNandini PersadTo compile the sample application, see :doc:`compiling`. 4414d7ea25SSunil Kumar Kori 4514d7ea25SSunil Kumar KoriThe application is located in the ``l2fwd-event`` sub-directory. 4614d7ea25SSunil Kumar Kori 4714d7ea25SSunil Kumar KoriRunning the Application 4814d7ea25SSunil Kumar Kori----------------------- 4914d7ea25SSunil Kumar Kori 5014d7ea25SSunil Kumar KoriThe application requires a number of command line options: 5114d7ea25SSunil Kumar Kori 5214d7ea25SSunil Kumar Kori.. code-block:: console 5314d7ea25SSunil Kumar Kori 54796b07e9SShijith Thotton ./<build_dir>/examples/dpdk-l2fwd-event [EAL options] -- -p PORTMASK 55796b07e9SShijith Thotton [-q NQ] 56796b07e9SShijith Thotton [--[no-]mac-updating] 57796b07e9SShijith Thotton [--mode=MODE] 58796b07e9SShijith Thotton [--eventq-sched=SCHED_MODE] 59796b07e9SShijith Thotton [--event-vector [--event-vector-size SIZE] [--event-vector-tmo NS]] 6014d7ea25SSunil Kumar Kori 6114d7ea25SSunil Kumar Koriwhere, 6214d7ea25SSunil Kumar Kori 6314d7ea25SSunil Kumar Kori* p PORTMASK: A hexadecimal bitmask of the ports to configure 6414d7ea25SSunil Kumar Kori 65885807aeSStephen Hemminger* q NQ: Maximum number of queues per lcore (default is 1) 6614d7ea25SSunil Kumar Kori 6714d7ea25SSunil Kumar Kori* --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default). 6814d7ea25SSunil Kumar Kori 6914d7ea25SSunil Kumar Kori* --mode=MODE: Packet transfer mode for I/O, poll or eventdev. Eventdev by default. 7014d7ea25SSunil Kumar Kori 7114d7ea25SSunil Kumar Kori* --eventq-sched=SCHED_MODE: Event queue schedule mode, Ordered, Atomic or Parallel. Atomic by default. 7214d7ea25SSunil Kumar Kori 73092454d9SPavan Nikhilesh* --config: Configure forwarding port pair mapping. Alternate port pairs by default. 74092454d9SPavan Nikhilesh 75796b07e9SShijith Thotton* --event-vector: Enable event vectorization. Only valid if --mode=eventdev. 76796b07e9SShijith Thotton 77796b07e9SShijith Thotton* --event-vector-size: Max vector size if event vectorization is enabled. 78796b07e9SShijith Thotton 79796b07e9SShijith Thotton* --event-vector-tmo: Max timeout to form vector in nanoseconds if event vectorization is enabled. 80796b07e9SShijith Thotton 81*8750576fSNandini PersadSample usage commands are given below to run the application into different modes: 8214d7ea25SSunil Kumar Kori 8314d7ea25SSunil Kumar KoriPoll mode with 4 lcores, 16 ports and 8 RX queues per lcore and MAC address updating enabled, 8414d7ea25SSunil Kumar Koriissue the command: 8514d7ea25SSunil Kumar Kori 8614d7ea25SSunil Kumar Kori.. code-block:: console 8714d7ea25SSunil Kumar Kori 88e2a94f9aSCiara Power ./<build_dir>/examples/dpdk-l2fwd-event -l 0-3 -n 4 -- -q 8 -p ffff --mode=poll 8914d7ea25SSunil Kumar Kori 90*8750576fSNandini PersadEventdev mode with 4 lcores, 16 ports, schedule method ordered and MAC address updating enabled, 9114d7ea25SSunil Kumar Koriissue the command: 9214d7ea25SSunil Kumar Kori 9314d7ea25SSunil Kumar Kori.. code-block:: console 9414d7ea25SSunil Kumar Kori 95e2a94f9aSCiara Power ./<build_dir>/examples/dpdk-l2fwd-event -l 0-3 -n 4 -- -p ffff --eventq-sched=ordered 9614d7ea25SSunil Kumar Kori 9714d7ea25SSunil Kumar Korior 9814d7ea25SSunil Kumar Kori 9914d7ea25SSunil Kumar Kori.. code-block:: console 10014d7ea25SSunil Kumar Kori 101e2a94f9aSCiara Power ./<build_dir>/examples/dpdk-l2fwd-event -l 0-3 -n 4 -- -q 8 -p ffff --mode=eventdev --eventq-sched=ordered 10214d7ea25SSunil Kumar Kori 10314d7ea25SSunil Kumar KoriRefer to the *DPDK Getting Started Guide* for general information on running 104*8750576fSNandini Persadapplications and Environment Abstraction Layer (EAL) options. 10514d7ea25SSunil Kumar Kori 106*8750576fSNandini PersadTo run the application with S/W scheduler, it uses following DPDK services: 10714d7ea25SSunil Kumar Kori 10814d7ea25SSunil Kumar Kori* Software scheduler 10914d7ea25SSunil Kumar Kori* Rx adapter service function 11014d7ea25SSunil Kumar Kori* Tx adapter service function 11114d7ea25SSunil Kumar Kori 112*8750576fSNandini PersadThe application needs service cores to run the above mentioned services. 113*8750576fSNandini PersadService cores must be provided as EAL parameters 114*8750576fSNandini Persadalong with the ``--vdev=event_sw0`` to enable S/W scheduler. 115*8750576fSNandini PersadThe following is the sample command: 11614d7ea25SSunil Kumar Kori 11714d7ea25SSunil Kumar Kori.. code-block:: console 11814d7ea25SSunil Kumar Kori 119e2a94f9aSCiara Power ./<build_dir>/examples/dpdk-l2fwd-event -l 0-7 -s 0-3 -n 4 --vdev event_sw0 -- -q 8 -p ffff --mode=eventdev --eventq-sched=ordered 12014d7ea25SSunil Kumar Kori 12114d7ea25SSunil Kumar KoriExplanation 12214d7ea25SSunil Kumar Kori----------- 12314d7ea25SSunil Kumar Kori 124*8750576fSNandini PersadThe following sections provide an explanation of the code. 12514d7ea25SSunil Kumar Kori 12614d7ea25SSunil Kumar Kori.. _l2_fwd_event_app_cmd_arguments: 12714d7ea25SSunil Kumar Kori 12814d7ea25SSunil Kumar KoriCommand Line Arguments 12914d7ea25SSunil Kumar Kori~~~~~~~~~~~~~~~~~~~~~~ 13014d7ea25SSunil Kumar Kori 131*8750576fSNandini PersadThe L2 forwarding eventdev sample application takes specific parameters 132*8750576fSNandini Persadand Environment Abstraction Layer (EAL) arguments. 133*8750576fSNandini PersadThe preferred way to parse parameters is to use the ``getopt()`` function 13414d7ea25SSunil Kumar Korisince it is part of a well-defined and portable library. 13514d7ea25SSunil Kumar Kori 136*8750576fSNandini PersadThe parsing of arguments is done in the ``l2fwd_parse_args()`` function 137*8750576fSNandini Persadfor non-eventdev parameters 138*8750576fSNandini Persadand in ``parse_eventdev_args()`` for eventdev parameters. 139*8750576fSNandini PersadThis method of argument parsing is not described here. 140*8750576fSNandini PersadRefer to the *glibc getopt(3)* main page for details. 14114d7ea25SSunil Kumar Kori 142*8750576fSNandini PersadEAL arguments are parsed first, then application-specific arguments follow. 143*8750576fSNandini PersadThis is done at the beginning of the ``main()`` function and eventdev parameters 144*8750576fSNandini Persadare parsed in ``eventdev_resource_setup()`` function during eventdev setup: 14514d7ea25SSunil Kumar Kori 1469a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/main.c 1479a212dc0SConor Fogarty :language: c 1489a212dc0SConor Fogarty :start-after: Init EAL. 8< 1499a212dc0SConor Fogarty :end-before: >8 End of init EAL. 1509a212dc0SConor Fogarty :dedent: 1 15114d7ea25SSunil Kumar Kori 15214d7ea25SSunil Kumar KoriMbuf Pool Initialization 15314d7ea25SSunil Kumar Kori~~~~~~~~~~~~~~~~~~~~~~~~ 15414d7ea25SSunil Kumar Kori 15514d7ea25SSunil Kumar KoriOnce the arguments are parsed, the mbuf pool is created. 15614d7ea25SSunil Kumar KoriThe mbuf pool contains a set of mbuf objects that will be used by the driver 15714d7ea25SSunil Kumar Koriand the application to store network packet data: 15814d7ea25SSunil Kumar Kori 1599a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/main.c 1609a212dc0SConor Fogarty :language: c 1619a212dc0SConor Fogarty :start-after: Create the mbuf pool. 8< 1629a212dc0SConor Fogarty :end-before: >8 End of creation of mbuf pool. 1639a212dc0SConor Fogarty :dedent: 1 16414d7ea25SSunil Kumar Kori 16514d7ea25SSunil Kumar KoriThe rte_mempool is a generic structure used to handle pools of objects. 16614d7ea25SSunil Kumar KoriIn this case, it is necessary to create a pool that will be used by the driver. 167*8750576fSNandini PersadThe number of allocated mbufs is ``NB_MBUF``, 168*8750576fSNandini Persadwith a data room size of ``RTE_MBUF_DEFAULT_BUF_SIZE`` each. 16914d7ea25SSunil Kumar KoriA per-lcore cache of 32 mbufs is kept. 17014d7ea25SSunil Kumar KoriThe memory is allocated in NUMA socket 0, 17114d7ea25SSunil Kumar Koribut it is possible to extend this code to allocate one mbuf pool per socket. 17214d7ea25SSunil Kumar Kori 173*8750576fSNandini PersadThe ``rte_pktmbuf_pool_create()`` function uses the default mbuf pool 174*8750576fSNandini Persadand mbuf initializers, respectively ``rte_pktmbuf_pool_init()`` and ``rte_pktmbuf_init()``. 17514d7ea25SSunil Kumar KoriAn advanced application may want to use the mempool API to create the 17614d7ea25SSunil Kumar Korimbuf pool with more control. 17714d7ea25SSunil Kumar Kori 17814d7ea25SSunil Kumar Kori.. _l2_fwd_event_app_drv_init: 17914d7ea25SSunil Kumar Kori 18014d7ea25SSunil Kumar KoriDriver Initialization 18114d7ea25SSunil Kumar Kori~~~~~~~~~~~~~~~~~~~~~ 18214d7ea25SSunil Kumar Kori 183*8750576fSNandini PersadThe main part of the code in the ``main()`` function relates to the initialization 18414d7ea25SSunil Kumar Koriof the driver. To fully understand this code, it is recommended to study the 185*8750576fSNandini Persadchapters related to the Poll Mode and Event mode Driver in the 18614d7ea25SSunil Kumar Kori*DPDK Programmer's Guide* - Rel 1.4 EAR and the *DPDK API Reference*. 18714d7ea25SSunil Kumar Kori 1889a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/main.c 1899a212dc0SConor Fogarty :language: c 1909a212dc0SConor Fogarty :start-after: Reset l2fwd_dst_ports. 8< 1919a212dc0SConor Fogarty :end-before: >8 End of reset l2fwd_dst_ports. 1929a212dc0SConor Fogarty :dedent: 1 19314d7ea25SSunil Kumar Kori 19414d7ea25SSunil Kumar KoriThe next step is to configure the RX and TX queues. For each port, there is only 19514d7ea25SSunil Kumar Korione RX queue (only one lcore is able to poll a given port). The number of TX 196*8750576fSNandini Persadqueues depends on the number of available lcores. The ``rte_eth_dev_configure()`` 19714d7ea25SSunil Kumar Korifunction is used to configure the number of queues for a port: 19814d7ea25SSunil Kumar Kori 1999a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_common.c 2009a212dc0SConor Fogarty :language: c 2019a212dc0SConor Fogarty :start-after: Configure RX and TX queue. 8< 2029a212dc0SConor Fogarty :end-before: >8 End of configuration RX and TX queue. 2039a212dc0SConor Fogarty :dedent: 2 20414d7ea25SSunil Kumar Kori 20514d7ea25SSunil Kumar KoriRX Queue Initialization 20614d7ea25SSunil Kumar Kori~~~~~~~~~~~~~~~~~~~~~~~ 20714d7ea25SSunil Kumar Kori 20814d7ea25SSunil Kumar KoriThe application uses one lcore to poll one or several ports, depending on the -q 20914d7ea25SSunil Kumar Korioption, which specifies the number of queues per lcore. 21014d7ea25SSunil Kumar Kori 21114d7ea25SSunil Kumar KoriFor example, if the user specifies -q 4, the application is able to poll four 21214d7ea25SSunil Kumar Koriports with one lcore. If there are 16 ports on the target (and if the portmask 21314d7ea25SSunil Kumar Koriargument is -p ffff ), the application will need four lcores to poll all the 21414d7ea25SSunil Kumar Koriports. 21514d7ea25SSunil Kumar Kori 2169a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_common.c 2179a212dc0SConor Fogarty :language: c 2189a212dc0SConor Fogarty :start-after: Using lcore to poll one or several ports. 8< 2199a212dc0SConor Fogarty :end-before: >8 End of using lcore to poll one or several ports. 2209a212dc0SConor Fogarty :dedent: 2 22114d7ea25SSunil Kumar Kori 22214d7ea25SSunil Kumar KoriThe list of queues that must be polled for a given lcore is stored in a private 22314d7ea25SSunil Kumar Koristructure called struct lcore_queue_conf. 22414d7ea25SSunil Kumar Kori 2259a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd/main.c 2269a212dc0SConor Fogarty :language: c 2279a212dc0SConor Fogarty :start-after: List of queues to be polled for a given lcore. 8< 2289a212dc0SConor Fogarty :end-before: >8 End of list of queues to be polled for a given lcore. 22914d7ea25SSunil Kumar Kori 23014d7ea25SSunil Kumar KoriThe values n_rx_port and rx_port_list[] are used in the main packet processing 23114d7ea25SSunil Kumar Koriloop (see :ref:`l2_fwd_event_app_rx_tx_packets`). 23214d7ea25SSunil Kumar Kori 23314d7ea25SSunil Kumar Kori.. _l2_fwd_event_app_tx_init: 23414d7ea25SSunil Kumar Kori 23514d7ea25SSunil Kumar KoriTX Queue Initialization 23614d7ea25SSunil Kumar Kori~~~~~~~~~~~~~~~~~~~~~~~ 23714d7ea25SSunil Kumar Kori 238*8750576fSNandini PersadEach lcore should be able to transmit on any port. For each port, a single TX 23914d7ea25SSunil Kumar Koriqueue is initialized. 24014d7ea25SSunil Kumar Kori 2419a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_common.c 2429a212dc0SConor Fogarty :language: c 2439a212dc0SConor Fogarty :start-after: Init one TX queue on each port. 8< 2449a212dc0SConor Fogarty :end-before: >8 End of init one TX queue on each port. 2459a212dc0SConor Fogarty :dedent: 2 24614d7ea25SSunil Kumar Kori 247*8750576fSNandini PersadTo configure eventdev support, the application sets up following components: 24814d7ea25SSunil Kumar Kori 24914d7ea25SSunil Kumar Kori* Event dev 25014d7ea25SSunil Kumar Kori* Event queue 25114d7ea25SSunil Kumar Kori* Event Port 25214d7ea25SSunil Kumar Kori* Rx/Tx adapters 25314d7ea25SSunil Kumar Kori* Ethernet ports 25414d7ea25SSunil Kumar Kori 25514d7ea25SSunil Kumar Kori.. _l2_fwd_event_app_event_dev_init: 25614d7ea25SSunil Kumar Kori 25714d7ea25SSunil Kumar KoriEvent device Initialization 25814d7ea25SSunil Kumar Kori~~~~~~~~~~~~~~~~~~~~~~~~~~~ 259*8750576fSNandini Persad 26014d7ea25SSunil Kumar KoriApplication can use either H/W or S/W based event device scheduler 26114d7ea25SSunil Kumar Koriimplementation and supports single instance of event device. It configures event 262*8750576fSNandini Persaddevice as per the following configuration: 26314d7ea25SSunil Kumar Kori 2649a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_event_generic.c 2659a212dc0SConor Fogarty :language: c 2669a212dc0SConor Fogarty :start-after: Configures event device as per below configuration. 8< 2679a212dc0SConor Fogarty :end-before: >8 End of configuration event device as per below configuration. 2689a212dc0SConor Fogarty :dedent: 1 26914d7ea25SSunil Kumar Kori 270*8750576fSNandini PersadIn case of S/W scheduler, the application runs eventdev 271*8750576fSNandini Persadscheduler service on the service core. 272*8750576fSNandini PersadThe application retrieves the service id 273*8750576fSNandini Persadand finds the best possible service core to run S/W scheduler. 27414d7ea25SSunil Kumar Kori 2759a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_event.c 2769a212dc0SConor Fogarty :language: c 2779a212dc0SConor Fogarty :start-after: Running eventdev scheduler service on service core. 8< 2789a212dc0SConor Fogarty :end-before: >8 End of running eventdev scheduler service on service core. 2799a212dc0SConor Fogarty :dedent: 1 28014d7ea25SSunil Kumar Kori 28114d7ea25SSunil Kumar KoriEvent queue Initialization 28214d7ea25SSunil Kumar Kori~~~~~~~~~~~~~~~~~~~~~~~~~~ 283*8750576fSNandini Persad 28414d7ea25SSunil Kumar KoriEach Ethernet device is assigned a dedicated event queue which will be linked 285*8750576fSNandini Persadto all available event ports, i.e. each lcore can dequeue packets from any of the 28614d7ea25SSunil Kumar KoriEthernet ports. 28714d7ea25SSunil Kumar Kori 2889a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_event_generic.c 2899a212dc0SConor Fogarty :language: c 2909a212dc0SConor Fogarty :start-after: Event queue initialization. 8< 2919a212dc0SConor Fogarty :end-before: >8 End of event queue initialization. 2929a212dc0SConor Fogarty :dedent: 1 29314d7ea25SSunil Kumar Kori 29414d7ea25SSunil Kumar KoriIn case of S/W scheduler, an extra event queue is created which will be used for 29514d7ea25SSunil Kumar KoriTx adapter service function for enqueue operation. 29614d7ea25SSunil Kumar Kori 29714d7ea25SSunil Kumar Kori.. _l2_fwd_app_event_port_init: 29814d7ea25SSunil Kumar Kori 29914d7ea25SSunil Kumar KoriEvent port Initialization 30014d7ea25SSunil Kumar Kori~~~~~~~~~~~~~~~~~~~~~~~~~ 301*8750576fSNandini Persad 30214d7ea25SSunil Kumar KoriEach worker thread is assigned a dedicated event port for enq/deq operations 303*8750576fSNandini Persadto/from an event device. 304*8750576fSNandini PersadAll event ports are linked to all available event queues. 30514d7ea25SSunil Kumar Kori 3069a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_event_generic.c 3079a212dc0SConor Fogarty :language: c 3089a212dc0SConor Fogarty :start-after: Event port initialization. 8< 3099a212dc0SConor Fogarty :end-before: >8 End of event port initialization. 3109a212dc0SConor Fogarty :dedent: 1 31114d7ea25SSunil Kumar Kori 312*8750576fSNandini PersadIn case of S/W scheduler, an extra event port is created by the DPDK library 313*8750576fSNandini Persadwhich is retrieved by the application. 314*8750576fSNandini PersadIt will be used by Tx adapter service. 31514d7ea25SSunil Kumar Kori 3169a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_event_generic.c 3179a212dc0SConor Fogarty :language: c 3189a212dc0SConor Fogarty :start-after: Extra port created. 8< 3199a212dc0SConor Fogarty :end-before: >8 End of extra port created. 3209a212dc0SConor Fogarty :dedent: 1 32114d7ea25SSunil Kumar Kori 32214d7ea25SSunil Kumar KoriRx/Tx adapter Initialization 32314d7ea25SSunil Kumar Kori~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 324*8750576fSNandini Persad 32514d7ea25SSunil Kumar KoriEach Ethernet port is assigned a dedicated Rx/Tx adapter for H/W scheduler. Each 32614d7ea25SSunil Kumar KoriEthernet port's Rx queues are connected to its respective event queue at 32714d7ea25SSunil Kumar Koripriority 0 via Rx adapter configuration and Ethernet port's tx queues are 32814d7ea25SSunil Kumar Koriconnected via Tx adapter. 32914d7ea25SSunil Kumar Kori 3309a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_event_internal_port.c 3319a212dc0SConor Fogarty :language: c 3329a212dc0SConor Fogarty :start-after: Assigned ethernet port. 8< 3339a212dc0SConor Fogarty :end-before: >8 End of assigned ethernet port. 3349a212dc0SConor Fogarty :dedent: 1 33514d7ea25SSunil Kumar Kori 33614d7ea25SSunil Kumar KoriFor S/W scheduler instead of dedicated adapters, common Rx/Tx adapters are 337*8750576fSNandini Persadconfigured which will be shared among all the Ethernet ports. 338*8750576fSNandini PersadAlso, the DPDK library needs service cores to run internal services for Rx/Tx adapters. 339*8750576fSNandini PersadThe application gets a service id for Rx/Tx adapters. 340*8750576fSNandini PersadAfter a successful setup, it runs the services on dedicated service cores. 34114d7ea25SSunil Kumar Kori 3429a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_event.c 3439a212dc0SConor Fogarty :language: c 3449a212dc0SConor Fogarty :start-after: Gets service ID for RX/TX adapters. 8< 3459a212dc0SConor Fogarty :end-before: >8 End of get service ID for RX/TX adapters. 3469a212dc0SConor Fogarty :dedent: 1 34714d7ea25SSunil Kumar Kori 34814d7ea25SSunil Kumar Kori.. _l2_fwd_event_app_rx_tx_packets: 34914d7ea25SSunil Kumar Kori 35014d7ea25SSunil Kumar KoriReceive, Process and Transmit Packets 35114d7ea25SSunil Kumar Kori~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 35214d7ea25SSunil Kumar Kori 353*8750576fSNandini PersadIn the ``l2fwd_main_loop()`` function, 354*8750576fSNandini Persadthe main task is to read ingress packets from the Rx queues. 355*8750576fSNandini PersadThis is done using the following code: 35614d7ea25SSunil Kumar Kori 3579a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_poll.c 3589a212dc0SConor Fogarty :language: c 3599a212dc0SConor Fogarty :start-after: Reading ingress packets. 8< 3609a212dc0SConor Fogarty :end-before: >8 End of reading ingress packets. 3619a212dc0SConor Fogarty :dedent: 2 36214d7ea25SSunil Kumar Kori 363*8750576fSNandini PersadPackets are read in a burst of size ``MAX_PKT_BURST``. 364*8750576fSNandini PersadThe ``rte_eth_rx_burst()`` function writes the mbuf pointers 365*8750576fSNandini Persadin a local table and returns the number of available mbufs in the table. 36614d7ea25SSunil Kumar Kori 367*8750576fSNandini PersadThen, each mbuf in the table is processed by the ``l2fwd_simple_forward()`` function. 368*8750576fSNandini PersadThe processing is very simple: process the Tx port from the Rx port, 369*8750576fSNandini Persadthen replace the source and destination MAC addresses if MAC address updating is enabled. 37014d7ea25SSunil Kumar Kori 37114d7ea25SSunil Kumar KoriDuring the initialization process, a static array of destination ports 372*8750576fSNandini Persad(``l2fwd_dst_ports[]``) is filled so that for each source port, a destination port 37314d7ea25SSunil Kumar Koriis assigned that is either the next or previous enabled port from the portmask. 374*8750576fSNandini PersadIf the number of ports are odd in portmask, then the packet from the last port will be 37514d7ea25SSunil Kumar Koriforwarded to first port i.e. if portmask=0x07, then forwarding will take place 37614d7ea25SSunil Kumar Korilike p0--->p1, p1--->p2, p2--->p0. 37714d7ea25SSunil Kumar Kori 378*8750576fSNandini PersadAlso, to optimize enqueue operation, ``l2fwd_simple_forward()`` stores incoming mbufs 379*8750576fSNandini Persadup to ``MAX_PKT_BURST``. 380*8750576fSNandini PersadOnce it reaches the limit, all packets are transmitted to destination ports. 38114d7ea25SSunil Kumar Kori 3829a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd/main.c 3839a212dc0SConor Fogarty :language: c 3849a212dc0SConor Fogarty :start-after: Simple forward. 8< 3859a212dc0SConor Fogarty :end-before: >8 End of simple forward. 38614d7ea25SSunil Kumar Kori 38714d7ea25SSunil Kumar KoriFor this test application, the processing is exactly the same for all packets 38814d7ea25SSunil Kumar Koriarriving on the same RX port. Therefore, it would have been possible to call 389*8750576fSNandini Persadthe ``rte_eth_tx_buffer()`` function directly from the main loop to send all the 39014d7ea25SSunil Kumar Korireceived packets on the same TX port, using the burst-oriented send function, 39114d7ea25SSunil Kumar Koriwhich is more efficient. 39214d7ea25SSunil Kumar Kori 393*8750576fSNandini PersadHowever, in real-life applications (such as L3 routing), 39414d7ea25SSunil Kumar Koripacket N is not necessarily forwarded on the same port as packet N-1. 395*8750576fSNandini PersadThe application is implemented to illustrate so the same approach can be 39614d7ea25SSunil Kumar Korireused in a more complex application. 39714d7ea25SSunil Kumar Kori 39814d7ea25SSunil Kumar KoriTo ensure that no packets remain in the tables, each lcore does a draining of TX 39914d7ea25SSunil Kumar Koriqueue in its main loop. This technique introduces some latency when there are 400*8750576fSNandini Persadnot many packets to send. However, it improves performance: 40114d7ea25SSunil Kumar Kori 4029a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_poll.c 4039a212dc0SConor Fogarty :language: c 4049a212dc0SConor Fogarty :start-after: Draining TX queue in main loop. 8< 4059a212dc0SConor Fogarty :end-before: >8 End of draining TX queue in main loop. 4069a212dc0SConor Fogarty :dedent: 2 40714d7ea25SSunil Kumar Kori 408*8750576fSNandini PersadIn the ``l2fwd_event_loop()`` function, 409*8750576fSNandini Persadthe main task is to read ingress packets from the event ports. 410*8750576fSNandini PersadThis is done using the following code: 41114d7ea25SSunil Kumar Kori 4129a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_event.c 4139a212dc0SConor Fogarty :language: c 4149a212dc0SConor Fogarty :start-after: Read packet from eventdev. 8< 4159a212dc0SConor Fogarty :end-before: >8 End of reading packets from eventdev. 4169a212dc0SConor Fogarty :dedent: 2 41714d7ea25SSunil Kumar Kori 418*8750576fSNandini PersadBefore reading packets, ``deq_len`` is fetched 419*8750576fSNandini Persadto ensure the correct allowed deq length by the eventdev. 420*8750576fSNandini PersadThe ``rte_event_dequeue_burst()`` function writes the mbuf pointers in a local table 42114d7ea25SSunil Kumar Koriand returns the number of available mbufs in the table. 42214d7ea25SSunil Kumar Kori 423*8750576fSNandini PersadThen, each mbuf in the table is processed by the ``l2fwd_eventdev_forward()`` 42414d7ea25SSunil Kumar Korifunction. The processing is very simple: process the TX port from the RX port, 425*8750576fSNandini Persadthen replace the source and destination MAC addresses if MAC address updating 42614d7ea25SSunil Kumar Koriis enabled. 42714d7ea25SSunil Kumar Kori 42814d7ea25SSunil Kumar KoriDuring the initialization process, a static array of destination ports 429*8750576fSNandini Persad(``l2fwd_dst_ports[]``) is filled so that for each source port, a destination port 43014d7ea25SSunil Kumar Koriis assigned that is either the next or previous enabled port from the portmask. 43114d7ea25SSunil Kumar KoriIf number of ports are odd in portmask then packet from last port will be 43214d7ea25SSunil Kumar Koriforwarded to first port i.e. if portmask=0x07, then forwarding will take place 43314d7ea25SSunil Kumar Korilike p0--->p1, p1--->p2, p2--->p0. 43414d7ea25SSunil Kumar Kori 435*8750576fSNandini Persad``l2fwd_eventdev_forward()`` does not stores incoming mbufs. 436*8750576fSNandini PersadThe packet will forwarded to destination ports 437*8750576fSNandini Persadvia Tx adapter or generic event dev enqueue API 43814d7ea25SSunil Kumar Koridepending H/W or S/W scheduler is used. 43914d7ea25SSunil Kumar Kori 4409a212dc0SConor Fogarty.. literalinclude:: ../../../examples/l2fwd-event/l2fwd_event.c 4419a212dc0SConor Fogarty :language: c 4429a212dc0SConor Fogarty :start-after: Read packet from eventdev. 8< 4439a212dc0SConor Fogarty :end-before: >8 End of reading packets from eventdev. 4449a212dc0SConor Fogarty :dedent: 2 445