15630257fSFerruh Yigit.. SPDX-License-Identifier: BSD-3-Clause 25630257fSFerruh Yigit Copyright(c) 2016-2017 Intel Corporation. 3ed2a80fdSPablo de Lara 4ed2a80fdSPablo de LaraServer-Node EFD Sample Application 5ed2a80fdSPablo de Lara================================== 6ed2a80fdSPablo de Lara 7ed2a80fdSPablo de LaraThis sample application demonstrates the use of EFD library as a flow-level 8ed2a80fdSPablo de Laraload balancer, for more information about the EFD Library please refer to the 9ed2a80fdSPablo de LaraDPDK programmer's guide. 10ed2a80fdSPablo de Lara 11ed2a80fdSPablo de LaraThis sample application is a variant of the 12ed2a80fdSPablo de Lara:ref:`client-server sample application <multi_process_app>` 13ed2a80fdSPablo de Larawhere a specific target node is specified for every and each flow 14ed2a80fdSPablo de Lara(not in a round-robin fashion as the original load balancing sample application). 15ed2a80fdSPablo de Lara 16ed2a80fdSPablo de LaraOverview 17ed2a80fdSPablo de Lara-------- 18ed2a80fdSPablo de Lara 19ed2a80fdSPablo de LaraThe architecture of the EFD flow-based load balancer sample application is 20ed2a80fdSPablo de Larapresented in the following figure. 21ed2a80fdSPablo de Lara 22ed2a80fdSPablo de Lara.. _figure_efd_sample_app_overview: 23ed2a80fdSPablo de Lara 24ed2a80fdSPablo de Lara.. figure:: img/server_node_efd.* 25ed2a80fdSPablo de Lara 26ed2a80fdSPablo de Lara Using EFD as a Flow-Level Load Balancer 27ed2a80fdSPablo de Lara 28ed2a80fdSPablo de LaraAs shown in :numref:`figure_efd_sample_app_overview`, 29ed2a80fdSPablo de Larathe sample application consists of a front-end node (server) 30ed2a80fdSPablo de Larausing the EFD library to create a load-balancing table for flows, 31ed2a80fdSPablo de Larafor each flow a target backend worker node is specified. The EFD table does not 32ed2a80fdSPablo de Larastore the flow key (unlike a regular hash table), and hence, it can 33ed2a80fdSPablo de Laraindividually load-balance millions of flows (number of targets * maximum number 34ed2a80fdSPablo de Laraof flows fit in a flow table per target) while still fitting in CPU cache. 35ed2a80fdSPablo de Lara 36ed2a80fdSPablo de LaraIt should be noted that although they are referred to as nodes, the frontend 37ed2a80fdSPablo de Laraserver and worker nodes are processes running on the same platform. 38ed2a80fdSPablo de Lara 39ed2a80fdSPablo de LaraFront-end Server 40ed2a80fdSPablo de Lara~~~~~~~~~~~~~~~~ 41ed2a80fdSPablo de Lara 42ed2a80fdSPablo de LaraUpon initializing, the frontend server node (process) creates a flow 43ed2a80fdSPablo de Laradistributor table (based on the EFD library) which is populated with flow 44ed2a80fdSPablo de Larainformation and its intended target node. 45ed2a80fdSPablo de Lara 46ed2a80fdSPablo de LaraThe sample application assigns a specific target node_id (process) for each of 47ed2a80fdSPablo de Larathe IP destination addresses as follows: 48ed2a80fdSPablo de Lara 49ed2a80fdSPablo de Lara.. code-block:: c 50ed2a80fdSPablo de Lara 51ed2a80fdSPablo de Lara node_id = i % num_nodes; /* Target node id is generated */ 52ed2a80fdSPablo de Lara ip_dst = rte_cpu_to_be_32(i); /* Specific ip destination address is 53ed2a80fdSPablo de Lara assigned to this target node */ 54ed2a80fdSPablo de Lara 55ed2a80fdSPablo de Larathen the pair of <key,target> is inserted into the flow distribution table. 56ed2a80fdSPablo de Lara 57ed2a80fdSPablo de LaraThe main loop of the server process receives a burst of packets, then for 58ed2a80fdSPablo de Laraeach packet, a flow key (IP destination address) is extracted. The flow 59ed2a80fdSPablo de Laradistributor table is looked up and the target node id is returned. Packets are 60ed2a80fdSPablo de Larathen enqueued to the specified target node id. 61ed2a80fdSPablo de Lara 62ed2a80fdSPablo de LaraIt should be noted that flow distributor table is not a membership test table. 63ed2a80fdSPablo de LaraI.e. if the key has already been inserted the target node id will be correct, 64ed2a80fdSPablo de Larabut for new keys the flow distributor table will return a value (which can be 65ed2a80fdSPablo de Laravalid). 66ed2a80fdSPablo de Lara 67ed2a80fdSPablo de LaraBackend Worker Nodes 68ed2a80fdSPablo de Lara~~~~~~~~~~~~~~~~~~~~ 69ed2a80fdSPablo de Lara 70ed2a80fdSPablo de LaraUpon initializing, the worker node (process) creates a flow table (a regular 71ed2a80fdSPablo de Larahash table that stores the key default size 1M flows) which is populated with 72ed2a80fdSPablo de Laraonly the flow information that is serviced at this node. This flow key is 73ed2a80fdSPablo de Laraessential to point out new keys that have not been inserted before. 74ed2a80fdSPablo de Lara 75ed2a80fdSPablo de LaraThe worker node's main loop is simply receiving packets then doing a hash table 76ed2a80fdSPablo de Laralookup. If a match occurs then statistics are updated for flows serviced by 77ed2a80fdSPablo de Larathis node. If no match is found in the local hash table then this indicates 78ed2a80fdSPablo de Larathat this is a new flow, which is dropped. 79ed2a80fdSPablo de Lara 80ed2a80fdSPablo de Lara 81ed2a80fdSPablo de LaraCompiling the Application 82ed2a80fdSPablo de Lara------------------------- 83ed2a80fdSPablo de Lara 847cacb056SHerakliusz LipiecTo compile the sample application see :doc:`compiling`. 85ed2a80fdSPablo de Lara 867cacb056SHerakliusz LipiecThe application is located in the ``server_node_efd`` sub-directory. 87ed2a80fdSPablo de Lara 88ed2a80fdSPablo de LaraRunning the Application 89ed2a80fdSPablo de Lara----------------------- 90ed2a80fdSPablo de Lara 91ed2a80fdSPablo de LaraThe application has two binaries to be run: the front-end server 92ed2a80fdSPablo de Laraand the back-end node. 93ed2a80fdSPablo de Lara 94ed2a80fdSPablo de LaraThe frontend server (server) has the following command line options:: 95ed2a80fdSPablo de Lara 96e2a94f9aSCiara Power ./<build_dir>/examples/dpdk-server [EAL options] -- -p PORTMASK -n NUM_NODES -f NUM_FLOWS 97ed2a80fdSPablo de Lara 98ed2a80fdSPablo de LaraWhere, 99ed2a80fdSPablo de Lara 100ed2a80fdSPablo de Lara* ``-p PORTMASK:`` Hexadecimal bitmask of ports to configure 101ed2a80fdSPablo de Lara* ``-n NUM_NODES:`` Number of back-end nodes that will be used 102ed2a80fdSPablo de Lara* ``-f NUM_FLOWS:`` Number of flows to be added in the EFD table (1 million, by default) 103ed2a80fdSPablo de Lara 104ed2a80fdSPablo de LaraThe back-end node (node) has the following command line options:: 105ed2a80fdSPablo de Lara 106ed2a80fdSPablo de Lara ./node [EAL options] -- -n NODE_ID 107ed2a80fdSPablo de Lara 108ed2a80fdSPablo de LaraWhere, 109ed2a80fdSPablo de Lara 110ed2a80fdSPablo de Lara* ``-n NODE_ID:`` Node ID, which cannot be equal or higher than NUM_MODES 111ed2a80fdSPablo de Lara 112ed2a80fdSPablo de Lara 113ed2a80fdSPablo de LaraFirst, the server app must be launched, with the number of nodes that will be run. 114ed2a80fdSPablo de LaraOnce it has been started, the node instances can be run, with different NODE_ID. 115ed2a80fdSPablo de LaraThese instances have to be run as secondary processes, with ``--proc-type=secondary`` 116ed2a80fdSPablo de Larain the EAL options, which will attach to the primary process memory, and therefore, 117ed2a80fdSPablo de Larathey can access the queues created by the primary process to distribute packets. 118ed2a80fdSPablo de Lara 119ed2a80fdSPablo de LaraTo successfully run the application, the command line used to start the 120ed2a80fdSPablo de Laraapplication has to be in sync with the traffic flows configured on the traffic 121ed2a80fdSPablo de Laragenerator side. 122ed2a80fdSPablo de Lara 123ed2a80fdSPablo de LaraFor examples of application command lines and traffic generator flows, please 124ed2a80fdSPablo de Lararefer to the DPDK Test Report. For more details on how to set up and run the 125ed2a80fdSPablo de Larasample applications provided with DPDK package, please refer to the 126ed2a80fdSPablo de Lara:ref:`DPDK Getting Started Guide for Linux <linux_gsg>` and 127ed2a80fdSPablo de Lara:ref:`DPDK Getting Started Guide for FreeBSD <freebsd_gsg>`. 128ed2a80fdSPablo de Lara 129ed2a80fdSPablo de Lara 130ed2a80fdSPablo de LaraExplanation 131ed2a80fdSPablo de Lara----------- 132ed2a80fdSPablo de Lara 133ed2a80fdSPablo de LaraAs described in previous sections, there are two processes in this example. 134ed2a80fdSPablo de Lara 135ed2a80fdSPablo de LaraThe first process, the front-end server, creates and populates the EFD table, 136ed2a80fdSPablo de Larawhich is used to distribute packets to nodes, which the number of flows 137ed2a80fdSPablo de Laraspecified in the command line (1 million, by default). 138ed2a80fdSPablo de Lara 139ed2a80fdSPablo de Lara 1409a212dc0SConor Fogarty.. literalinclude:: ../../../examples/server_node_efd/server/init.c 1419a212dc0SConor Fogarty :language: c 1429a212dc0SConor Fogarty :start-after: Create EFD table. 8< 1439a212dc0SConor Fogarty :end-before: >8 End of creation EFD table. 144ed2a80fdSPablo de Lara 145ed2a80fdSPablo de LaraAfter initialization, packets are received from the enabled ports, and the IPv4 146ed2a80fdSPablo de Laraaddress from the packets is used as a key to look up in the EFD table, 147ed2a80fdSPablo de Larawhich tells the node where the packet has to be distributed. 148ed2a80fdSPablo de Lara 1499a212dc0SConor Fogarty.. literalinclude:: ../../../examples/server_node_efd/server/main.c 1509a212dc0SConor Fogarty :language: c 1519a212dc0SConor Fogarty :start-after: Processing packets. 8< 1529a212dc0SConor Fogarty :end-before: >8 End of process_packets. 153ed2a80fdSPablo de Lara 154ed2a80fdSPablo de LaraThe burst of packets received is enqueued in temporary buffers (per node), 155ed2a80fdSPablo de Laraand enqueued in the shared ring between the server and the node. 156ed2a80fdSPablo de LaraAfter this, a new burst of packets is received and this process is 157ed2a80fdSPablo de Lararepeated infinitely. 158ed2a80fdSPablo de Lara 1599a212dc0SConor Fogarty.. literalinclude:: ../../../examples/server_node_efd/server/main.c 1609a212dc0SConor Fogarty :language: c 1619a212dc0SConor Fogarty :start-after: Flush rx queue. 8< 1629a212dc0SConor Fogarty :end-before: >8 End of sending a burst of traffic to a node. 163ed2a80fdSPablo de Lara 164ed2a80fdSPablo de LaraThe second process, the back-end node, receives the packets from the shared 165ed2a80fdSPablo de Lararing with the server and send them out, if they belong to the node. 166ed2a80fdSPablo de Lara 167ed2a80fdSPablo de LaraAt initialization, it attaches to the server process memory, to have 168ed2a80fdSPablo de Laraaccess to the shared ring, parameters and statistics. 169ed2a80fdSPablo de Lara 1709a212dc0SConor Fogarty.. literalinclude:: ../../../examples/server_node_efd/node/node.c 1719a212dc0SConor Fogarty :language: c 1729a212dc0SConor Fogarty :start-after: Attaching to the server process memory. 8< 1739a212dc0SConor Fogarty :end-before: >8 End of attaching to the server process memory. 1749a212dc0SConor Fogarty :dedent: 1 175ed2a80fdSPablo de Lara 176ed2a80fdSPablo de LaraThen, the hash table that contains the flows that will be handled 177ed2a80fdSPablo de Laraby the node is created and populated. 178ed2a80fdSPablo de Lara 1799a212dc0SConor Fogarty.. literalinclude:: ../../../examples/server_node_efd/node/node.c 1809a212dc0SConor Fogarty :language: c 1819a212dc0SConor Fogarty :start-after: Creation of hash table. 8< 1829a212dc0SConor Fogarty :end-before: >8 End of creation of hash table. 183ed2a80fdSPablo de Lara 184ed2a80fdSPablo de LaraAfter initialization, packets are dequeued from the shared ring 185ed2a80fdSPablo de Lara(from the server) and, like in the server process, 186ed2a80fdSPablo de Larathe IPv4 address from the packets is used as a key to look up in the hash table. 187ed2a80fdSPablo de LaraIf there is a hit, packet is stored in a buffer, to be eventually transmitted 188ed2a80fdSPablo de Larain one of the enabled ports. If key is not there, packet is dropped, since the 189ed2a80fdSPablo de Laraflow is not handled by the node. 190ed2a80fdSPablo de Lara 1919a212dc0SConor Fogarty.. literalinclude:: ../../../examples/server_node_efd/node/node.c 1929a212dc0SConor Fogarty :language: c 1939a212dc0SConor Fogarty :start-after: Packets dequeued from the shared ring. 8< 194*7be78d02SJosh Soref :end-before: >8 End of packets dequeuing. 195ed2a80fdSPablo de Lara 196ed2a80fdSPablo de LaraFinally, note that both processes updates statistics, such as transmitted, received 197ed2a80fdSPablo de Laraand dropped packets, which are shown and refreshed by the server app. 198ed2a80fdSPablo de Lara 1999a212dc0SConor Fogarty.. literalinclude:: ../../../examples/server_node_efd/server/main.c 2009a212dc0SConor Fogarty :language: c 2019a212dc0SConor Fogarty :start-after: Display recorded statistics. 8< 2029a212dc0SConor Fogarty :end-before: >8 End of displaying the recorded statistics. 203