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