From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f171.google.com (mail-pf0-f171.google.com [209.85.192.171]) by dpdk.org (Postfix) with ESMTP id ED20FDE0 for ; Mon, 8 May 2017 23:00:57 +0200 (CEST) Received: by mail-pf0-f171.google.com with SMTP id v14so38704216pfd.2 for ; Mon, 08 May 2017 14:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NKlYwKxxngIfdbzX/xL1XLoB4cS4CAFgpNEYykktRpI=; b=mmIWS2l5pNy4u9VNb1J8cimh2h+pUxxqTITZdLFhZwCQ+I+MzhsFgAWfyZlrm3JXBh 4z1GCC1KOZPvcdlgfxmWw1euMdFc0RBHkxT3HEec79fDJuWjyNQafB7wCyokQiHe34y3 X4e8Rywllhxe6R4bIam8+0X4fj34TonS5aJ/F8NitwJeg9WJklJnncuLBvGe87ovKx6q hfX/PDzr1CQ8QGTUygr2yF9Wd3amTNYB94RO0HtzZGeoFBOFT+D/H88pmiGLghQEBIfx QM2YNThLrO9sJ7t5XqWzxIxqIxbMv682sIXSHIopHfNSMLPGe5lyRUvgnVTrZ/IdabZ7 IrDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NKlYwKxxngIfdbzX/xL1XLoB4cS4CAFgpNEYykktRpI=; b=Ts/uPsqPvpF0KYfQ6O/w4pt27N6f1m6J/cI3jpDAVCT0xQ8yfIdDjlR6HW0Nj4cciB N0lIO93P1Csf75doKpELHs4mKzY8PdWZkCJeX5OqHX9UuejQAAJ8WTQW9drILoOXSLt5 DlvwDhkx2YRgmd520bJ3HWcppUDkQMgjT/ZuVQXw8daPrrw43JXFyne9rPGr5P+RF2+h iYpnDSzaCOE9ZuFLwjr8RaBkOpCDVGB51PpIZlc6OQiIoLVGsm1jiG4/UuOU7/r2g5Xn iHmNs/hkRITNG+iHOvPgIh1SgMhjLzfDdo3W2lrWTQR6mbH5sXr5xN809sq4c9PCJ7qD bnSw== X-Gm-Message-State: AN3rC/7of3wFh/6zj9GD0YlMrdYmYSc/aVpXj7pz0bC3iv70ca18oRtE V9FUzUOqmGUVbQ== X-Received: by 10.99.9.66 with SMTP id 63mr20927526pgj.22.1494277255509; Mon, 08 May 2017 14:00:55 -0700 (PDT) Received: from user-PC.hsd1.ca.comcast.net ([2601:646:8602:ebb1:c165:c180:4195:d2c6]) by smtp.gmail.com with ESMTPSA id p80sm23044483pfk.50.2017.05.08.14.00.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 14:00:54 -0700 (PDT) From: Ravi Kerur To: dev@dpdk.org Cc: john.mcnamara@intel.com, thomas@monjalon.net, Ravi Kerur Date: Mon, 8 May 2017 14:00:27 -0700 Message-Id: <1494277227-25876-1-git-send-email-rkerur@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493145557-17160-1-git-send-email-rkerur@gmail.com> References: <1493145557-17160-1-git-send-email-rkerur@gmail.com> Subject: [dpdk-dev] [PATCH v2] doc: Merge l3fwd and l3fwd-acl documentation files X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 May 2017 21:00:58 -0000 Merge l3fwd and l3fwd-acl documentation to reflect the code. Add examples of LPM and Exact Match rules in .svg files. Signed-off-by: Ravi Kerur --- v2: Remove binary PNG from .svg files. v1: Merge relevant contents of l3fwd and l3fwd-acl documentation. Modify l3fwd document with ACL specific information. Remove l3fwd-acl documentation file. --- doc/guides/sample_app_ug/img/ipv4_hash_rule.svg | 108 ++++++ doc/guides/sample_app_ug/img/ipv4_lpm_rule.svg | 96 +++++ doc/guides/sample_app_ug/index.rst | 1 - doc/guides/sample_app_ug/l3_forward.rst | 326 ++++++++++++++++- .../sample_app_ug/l3_forward_access_ctrl.rst | 385 --------------------- 5 files changed, 521 insertions(+), 395 deletions(-) create mode 100644 doc/guides/sample_app_ug/img/ipv4_hash_rule.svg create mode 100644 doc/guides/sample_app_ug/img/ipv4_lpm_rule.svg delete mode 100644 doc/guides/sample_app_ug/l3_forward_access_ctrl.rst diff --git a/doc/guides/sample_app_ug/img/ipv4_hash_rule.svg b/doc/guides/sample_app_ug/img/ipv4_hash_rule.svg new file mode 100644 index 0000000..76edfda --- /dev/null +++ b/doc/guides/sample_app_ug/img/ipv4_hash_rule.svg @@ -0,0 +1,108 @@ + + + + + + + + + + image/svg+xml + + + + + + + E101.0.0.0 100.10.0.0 101 11 0x06 0 + + + + + + Src Addr Dest Addr Src port Dest port Protocol Fwd + diff --git a/doc/guides/sample_app_ug/img/ipv4_lpm_rule.svg b/doc/guides/sample_app_ug/img/ipv4_lpm_rule.svg new file mode 100644 index 0000000..1b7f02c --- /dev/null +++ b/doc/guides/sample_app_ug/img/ipv4_lpm_rule.svg @@ -0,0 +1,96 @@ + + + + + + + + + + image/svg+xml + + + + + + + L101.10.1.0/24 0 + + Dest Addr/Prefix Fwd + diff --git a/doc/guides/sample_app_ug/index.rst b/doc/guides/sample_app_ug/index.rst index 02611ef..62cafb0 100644 --- a/doc/guides/sample_app_ug/index.rst +++ b/doc/guides/sample_app_ug/index.rst @@ -53,7 +53,6 @@ Sample Applications User Guides l2_forward_cat l3_forward l3_forward_power_man - l3_forward_access_ctrl l3_forward_virtual link_status_intr load_balancer diff --git a/doc/guides/sample_app_ug/l3_forward.rst b/doc/guides/sample_app_ug/l3_forward.rst index 6a6b8fb..69063bd 100644 --- a/doc/guides/sample_app_ug/l3_forward.rst +++ b/doc/guides/sample_app_ug/l3_forward.rst @@ -1,5 +1,5 @@ .. BSD LICENSE - Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + Copyright(c) 2010-2017 Intel Corporation. All rights reserved. All rights reserved. Redistribution and use in source and binary forms, with or without @@ -31,12 +31,18 @@ L3 Forwarding Sample Application ================================ -The L3 Forwarding application is a simple example of packet processing using the DPDK. -The application performs L3 forwarding. +The L3 Forwarding with Hash, LPM or Access Control application is a simple example of packet processing using the DPDK. +The application performs L3 forwarding when Hash or LPM is used. +The application performs a security check on received packets when Access Control is used. +Packets that are in the Access Control List (ACL), which is loaded during initialization, are dropped. +Others are forwarded to the correct port. Overview -------- +Hash and LPM +~~~~~~~~~~~~ + The application demonstrates the use of the hash and LPM libraries in the DPDK to implement packet forwarding. The initialization and run-time paths are very similar to those of the :doc:`l2_forward_real_virtual`. The main difference from the L2 Forwarding sample application is that the forwarding decision @@ -49,15 +55,263 @@ The hash object is used in correlation with a flow table to map each input packe The hash lookup key is represented by a DiffServ 5-tuple composed of the following fields read from the input packet: Source IP Address, Destination IP Address, Protocol, Source Port and Destination Port. The ID of the output interface for the input packet is read from the identified flow table entry. -The set of flows used by the application is statically configured and loaded into the hash at initialization time. When the selected lookup method is LPM based, an LPM object is used to emulate the forwarding stage for IPv4 packets. The LPM object is used as the routing table to identify the next hop for each input packet at runtime. The LPM lookup key is represented by the Destination IP Address field read from the input packet. The ID of the output interface for the input packet is the next hop returned by the LPM lookup. -The set of LPM rules used by the application is statically configured and loaded into the LPM object at initialization time. -In the sample application, hash-based forwarding supports IPv4 and IPv6. LPM-based forwarding supports IPv4 only. +In the sample application, both hash-based and LPM forwarding supports IPv4 and IPv6. + +The application loads rules at initialization which are used for L3 forwarding. +The application needs to acquire route rules before it runs. + +To read data from the specified file successfully, the application assumes the following: + +* Each rule occupies a single line. + +* Only the following four rule line types are valid in this application: + +* Route rule line starts with a leading character 'L' for LPM + +* Route rule line starts with a leading character 'E' for hash-based + +* Comment line, which starts with a leading character '#' + +* Empty line, which consists of a space, form-feed ('\f'), newline ('\n'), + carriage return ('\r'), horizontal tab ('\t'), or vertical tab ('\v'). + +Other lines types are considered invalid. + +* A typical IPv4 LPM rule line should have a format as shown below: + + +.. _figure_ipv4_lpm_rule: + +.. figure:: img/ipv4_lpm_rule.* + + A typical IPv4 LPM rule + +* A typical IPv4 hash rule line should have a format as shown below: + + +.. _figure_ipv4_hash_rule: + +.. figure:: img/ipv4_hash_rule.* + + A typical IPv4 hash rule + +Access Control +~~~~~~~~~~~~~~ +The application demonstrates the use of the ACL library in the DPDK to implement access control +and packet L3 forwarding. +The application loads two types of rules at initialization: + +* Route information rules, which are used for L3 forwarding + +* Access Control List (ACL) rules that blacklist (or block) packets with a specific characteristic + +When packets are received from a port, +the application extracts the necessary information from the TCP/IP header of the received packet and +performs a lookup in the rule database to figure out whether the packets should be dropped (in the ACL range) +or forwarded to desired ports. +The initialization and run-time paths are similar to those of the :doc:`l3_forward`. +However, there are significant differences in the two applications. +For example, the original L3 forwarding application uses either LPM or +an exact match algorithm to perform forwarding port lookup, +while this application uses the ACL library to perform both ACL and route entry lookup. +The following sections provide more detail. + +Classification for both IPv4 and IPv6 packets is supported in this application. +The application also assumes that all the packets it processes are TCP/UDP packets and +always extracts source/destination port information from the packets. + +Tuple Packet Syntax +^^^^^^^^^^^^^^^^^^^ + +The application implements packet classification for the IPv4/IPv6 5-tuple syntax specifically. +The 5-tuple syntax consist of a source IP address, a destination IP address, +a source port, a destination port and a protocol identifier. +The fields in the 5-tuple syntax have the following formats: + +* **Source IP address and destination IP address** + : Each is either a 32-bit field (for IPv4), or a set of 4 32-bit fields (for IPv6) represented by a value and a mask length. + For example, an IPv4 range of 192.168.1.0 to 192.168.1.255 could be represented by a value = [192, 168, 1, 0] and a mask length = 24. + +* **Source port and destination port** + : Each is a 16-bit field, represented by a lower start and a higher end. + For example, a range of ports 0 to 8192 could be represented by lower = 0 and higher = 8192. + +* **Protocol identifier** + : An 8-bit field, represented by a value and a mask, that covers a range of values. + To verify that a value is in the range, use the following expression: "(VAL & mask) == value" + +The trick in how to represent a range with a mask and value is as follows. +A range can be enumerated in binary numbers with some bits that are never changed and some bits that are dynamically changed. +Set those bits that dynamically changed in mask and value with 0. +Set those bits that never changed in the mask with 1, in value with number expected. +For example, a range of 6 to 7 is enumerated as 0b110 and 0b111. +Bit 1-7 are bits never changed and bit 0 is the bit dynamically changed. +Therefore, set bit 0 in mask and value with 0, set bits 1-7 in mask with 1, and bits 1-7 in value with number 0b11. +So, mask is 0xfe, value is 0x6. + +.. note:: + + The library assumes that each field in the rule is in LSB or Little Endian order when creating the database. + It internally converts them to MSB or Big Endian order. + When performing a lookup, the library assumes the input is in MSB or Big Endian order. + +Access Rule Syntax +^^^^^^^^^^^^^^^^^^ + +In this sample application, each rule is a combination of the following: + +* 5-tuple field: This field has a format described in Section. + +* priority field: A weight to measure the priority of the rules. + The rule with the higher priority will ALWAYS be returned if the specific input has multiple matches in the rule database. + Rules with lower priority will NEVER be returned in any cases. + +* userdata field: A user-defined field that could be any value. + It can be the forwarding port number if the rule is a route table entry or it can be a pointer to a mapping address + if the rule is used for address mapping in the NAT application. + The key point is that it is a useful reserved field for user convenience. + +ACL and Route Rules +^^^^^^^^^^^^^^^^^^^ + +The application needs to acquire ACL and route rules before it runs. +Route rules are mandatory, while ACL rules are optional. +To simplify the complexity of the priority field for each rule, all ACL and route entries are assumed to be in the same file. +To read data from the specified file successfully, the application assumes the following: + +* Each rule occupies a single line. + +* Only the following four rule line types are valid in this application: + +* ACL rule line, which starts with a leading character '@' + +* Route rule line, which starts with a leading character 'R' + +* Comment line, which starts with a leading character '#' + +* Empty line, which consists of a space, form-feed ('\f'), newline ('\n'), + carriage return ('\r'), horizontal tab ('\t'), or vertical tab ('\v'). + +Other lines types are considered invalid. + +* Rules are organized in descending order of priority, + which means rules at the head of the file always have a higher priority than those further down in the file. + +* A typical IPv4 ACL rule line should have a format as shown below: + + +.. _figure_ipv4_acl_rule: + +.. figure:: img/ipv4_acl_rule.* + + A typical IPv4 ACL rule + + +IPv4 addresses are specified in CIDR format as specified in RFC 4632. +They consist of the dot notation for the address and a prefix length separated by '/'. +For example, 192.168.0.34/32, where the address is 192.168.0.34 and the prefix length is 32. + +Ports are specified as a range of 16-bit numbers in the format MIN:MAX, +where MIN and MAX are the inclusive minimum and maximum values of the range. +The range 0:65535 represents all possible ports in a range. +When MIN and MAX are the same value, a single port is represented, for example, 20:20. + +The protocol identifier is an 8-bit value and a mask separated by '/'. +For example: 6/0xfe matches protocol values 6 and 7. + +* Route rules start with a leading character 'R' and have the same format as ACL rules except an extra field at the tail + that indicates the forwarding port number. + +Rules File Example +^^^^^^^^^^^^^^^^^^ + +.. _figure_example_rules: + +.. figure:: img/example_rules.* + + Rules example + + +Each rule is explained as follows: + +* Rule 1 (the first line) tells the application to drop those packets with source IP address = [1.2.3.*], + destination IP address = [192.168.0.36], protocol = [6]/[7] + +* Rule 2 (the second line) is similar to Rule 1, except the source IP address is ignored. + It tells the application to forward packets with destination IP address = [192.168.0.36], + protocol = [6]/[7], destined to port 1. + +* Rule 3 (the third line) tells the application to forward all packets to port 0. + This is something like a default route entry. + +As described earlier, the application assume rules are listed in descending order of priority, +therefore Rule 1 has the highest priority, then Rule 2, and finally, +Rule 3 has the lowest priority. + +Consider the arrival of the following three packets: + +* Packet 1 has source IP address = [1.2.3.4], destination IP address = [192.168.0.36], and protocol = [6] + +* Packet 2 has source IP address = [1.2.4.4], destination IP address = [192.168.0.36], and protocol = [6] + +* Packet 3 has source IP address = [1.2.3.4], destination IP address = [192.168.0.36], and protocol = [8] + +Observe that: + +* Packet 1 matches all of the rules + +* Packet 2 matches Rule 2 and Rule 3 + +* Packet 3 only matches Rule 3 + +For priority reasons, Packet 1 matches Rule 1 and is dropped. +Packet 2 matches Rule 2 and is forwarded to port 1. +Packet 3 matches Rule 3 and is forwarded to port 0. + +For more details on the rule file format, +please refer to rule_ipv4.db and rule_ipv6.db files (inside /examples/l3fwd-acl/). + +Application Phases +^^^^^^^^^^^^^^^^^^ + +Once the application starts, it transitions through three phases: + +* **Initialization Phase** + - Perform the following tasks: + +* Parse command parameters. Check the validity of rule file(s) name(s), number of logical cores, receive and transmit queues. + Bind ports, queues and logical cores. Check ACL search options, and so on. + +* Call Environmental Abstraction Layer (EAL) and Poll Mode Driver (PMD) functions to initialize the environment and detect possible NICs. + The EAL creates several threads and sets affinity to a specific hardware thread CPU based on the configuration specified + by the command line arguments. + +* Read the rule files and format the rules into the representation that the ACL library can recognize. + Call the ACL library function to add the rules into the database and compile them as a trie of pattern sets. + Note that application maintains a separate AC contexts for IPv4 and IPv6 rules. + +* **Runtime Phase** + - Process the incoming packets from a port. Packets are processed in three steps: + + * Retrieval: Gets a packet from the receive queue. Each logical core may process several queues for different ports. + This depends on the configuration specified by command line arguments. + + * Lookup: Checks that the packet type is supported (IPv4/IPv6) and performs a 5-tuple lookup over corresponding AC context. + If an ACL rule is matched, the packets will be dropped and return back to step 1. + If a route rule is matched, it indicates the packet is not in the ACL list and should be forwarded. + If there is no matches for the packet, then the packet is dropped. + + * Forwarding: Forwards the packet to the corresponding port. + +* **Final Phase** - Perform the following tasks: + + Calls the EAL, PMD driver and ACL library to free resource, then quits. Compiling the Application ------------------------- @@ -93,14 +347,18 @@ The application has a number of command line options:: ./l3fwd [EAL options] -- -p PORTMASK [-P] [-E] + [-A] [-L] --config(port,queue,lcore)[,(port,queue,lcore)] + --rule_ipv4 FILENAME + --rule_ipv6 FILENAME [--eth-dest=X,MM:MM:MM:MM:MM:MM] [--enable-jumbo [--max-pkt-len PKTLEN]] [--no-numa] [--hash-entry-num] [--ipv6] [--parse-ptype] + --scalar Where, @@ -111,10 +369,18 @@ Where, * ``-E:`` Optional, enable exact match. +* ``-A:`` Optional, enable access control list match. + * ``-L:`` Optional, enable longest prefix match. * ``--config (port,queue,lcore)[,(port,queue,lcore)]:`` Determines which queues from which ports are mapped to which cores. +* ``--rule_ipv4 FILENAME:`` Specifies the IPv4 hash-based, LPM, ACL and route rules file + +* ``--rule_ipv6 FILENAME:`` Specifies the IPv6 hash-based, LPM, ACL and route rules file + +* ``--scalar:`` Use a scalar function to perform ACL rule lookup + * ``--eth-dest=X,MM:MM:MM:MM:MM:MM:`` Optional, ethernet destination for port X. * ``--enable-jumbo:`` Optional, enables jumbo frames. @@ -137,7 +403,7 @@ To enable L3 forwarding between two ports, assuming that both ports are in the s .. code-block:: console - ./build/l3fwd -l 1,2 -n 4 -- -p 0x3 --config="(0,0,1),(1,0,2)" + ./build/l3fwd -l 1,2 -n 4 -- -p 0x3 --config="(0,0,1),(1,0,2) --rule_ipv4="./rule_ipv4.db" -- rule_ipv6="./rule_ipv6.db"" In this command: @@ -159,6 +425,12 @@ In this command: | | | | | +----------+-----------+-----------+-------------------------------------+ +* The --rule_ipv4 option specifies the reading of IPv4 rules sets from the ./ rule_ipv4.db file. + +* The --rule_ipv6 option specifies the reading of IPv6 rules sets from the ./ rule_ipv6.db file. + +* The --scalar option specifies the performing of ACL rule lookup with a scalar function. + Refer to the *DPDK Getting Started Guide* for general information on running applications and the Environment Abstraction Layer (EAL) options. @@ -171,6 +443,22 @@ The following sections provide some explanation of the sample application code. the initialization and run-time paths are very similar to those of the :doc:`l2_forward_real_virtual`. The following sections describe aspects that are specific to the L3 Forwarding sample application. +Parse Rules from File +~~~~~~~~~~~~~~~~~~~~~ + +As described earlier, Hash, LPM and ACL route rules are assumed to be saved in a file. +For ACL both ACL and route rules are assumed to be saved in the same file. +The application parses the rules from the file and adds them to the database by calling the respective library function. +It ignores empty and comment lines, and parses and validates the rules it reads. +If errors are detected, the application exits with messages to identify the errors encountered. + +The application needs to consider the userdata and priority fields for ACL. +The ACL rules save the index to the specific rules in the userdata field, +while route rules save the forwarding port number. +In order to differentiate the two types of rules, ACL rules add a signature in the userdata field. +As for the priority field, the application assumes rules are organized in descending order of priority. +Therefore, the code only decreases the priority number with each rule it parses. + Hash Initialization ~~~~~~~~~~~~~~~~~~~ @@ -194,7 +482,7 @@ for the convenience to execute hash performance test on 4M/8M/16M flows. .. code-block:: c - #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) + #if (-E option used) static void setup_hash(int socketid) @@ -228,7 +516,7 @@ The LPM object is created and loaded with the pre-configured entries read from a .. code-block:: c - #if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM) + #if (-L option used) static void setup_lpm(int socketid) @@ -358,3 +646,23 @@ for LPM-based lookups is done by the get_ipv4_dst_port() function below: return (uint8_t) ((rte_lpm_lookup(ipv4_l3fwd_lookup_struct, rte_be_to_cpu_32(ipv4_hdr->dst_addr), &next_hop) == 0)? next_hop : portid); } + +Setting Up the ACL Context +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +For each supported AC rule format (IPv4 5-tuple, IPv6 6-tuple) application creates a separate context handler +from the ACL library for each CPU socket on the board and adds parsed rules into that context. + +Note, that for each supported rule type, +application needs to calculate the expected offset of the fields from the start of the packet. +That's why only packets with fixed IPv4/ IPv6 header are supported. +That allows to perform ACL classify straight over incoming packet buffer - +no extra protocol field retrieval need to be performed. + +Subsequently, the application checks whether NUMA is enabled. +If it is, the application records the socket IDs of the CPU cores involved in the task. + +Finally, the application creates contexts handler from the ACL library, +adds rules parsed from the file into the database and build an ACL trie. +It is important to note that the application creates an independent copy of each database for each socket CPU +involved in the task to reduce the time for remote memory access. diff --git a/doc/guides/sample_app_ug/l3_forward_access_ctrl.rst b/doc/guides/sample_app_ug/l3_forward_access_ctrl.rst deleted file mode 100644 index a6aa4fb..0000000 --- a/doc/guides/sample_app_ug/l3_forward_access_ctrl.rst +++ /dev/null @@ -1,385 +0,0 @@ -.. BSD LICENSE - Copyright(c) 2010-2014 Intel Corporation. All rights reserved. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - * Neither the name of Intel Corporation nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -L3 Forwarding with Access Control Sample Application -==================================================== - -The L3 Forwarding with Access Control application is a simple example of packet processing using the DPDK. -The application performs a security check on received packets. -Packets that are in the Access Control List (ACL), which is loaded during initialization, are dropped. -Others are forwarded to the correct port. - -Overview --------- - -The application demonstrates the use of the ACL library in the DPDK to implement access control -and packet L3 forwarding. -The application loads two types of rules at initialization: - -* Route information rules, which are used for L3 forwarding - -* Access Control List (ACL) rules that blacklist (or block) packets with a specific characteristic - -When packets are received from a port, -the application extracts the necessary information from the TCP/IP header of the received packet and -performs a lookup in the rule database to figure out whether the packets should be dropped (in the ACL range) -or forwarded to desired ports. -The initialization and run-time paths are similar to those of the :doc:`l3_forward`. -However, there are significant differences in the two applications. -For example, the original L3 forwarding application uses either LPM or -an exact match algorithm to perform forwarding port lookup, -while this application uses the ACL library to perform both ACL and route entry lookup. -The following sections provide more detail. - -Classification for both IPv4 and IPv6 packets is supported in this application. -The application also assumes that all the packets it processes are TCP/UDP packets and -always extracts source/destination port information from the packets. - -Tuple Packet Syntax -~~~~~~~~~~~~~~~~~~~ - -The application implements packet classification for the IPv4/IPv6 5-tuple syntax specifically. -The 5-tuple syntax consist of a source IP address, a destination IP address, -a source port, a destination port and a protocol identifier. -The fields in the 5-tuple syntax have the following formats: - -* **Source IP address and destination IP address** - : Each is either a 32-bit field (for IPv4), or a set of 4 32-bit fields (for IPv6) represented by a value and a mask length. - For example, an IPv4 range of 192.168.1.0 to 192.168.1.255 could be represented by a value = [192, 168, 1, 0] and a mask length = 24. - -* **Source port and destination port** - : Each is a 16-bit field, represented by a lower start and a higher end. - For example, a range of ports 0 to 8192 could be represented by lower = 0 and higher = 8192. - -* **Protocol identifier** - : An 8-bit field, represented by a value and a mask, that covers a range of values. - To verify that a value is in the range, use the following expression: "(VAL & mask) == value" - -The trick in how to represent a range with a mask and value is as follows. -A range can be enumerated in binary numbers with some bits that are never changed and some bits that are dynamically changed. -Set those bits that dynamically changed in mask and value with 0. -Set those bits that never changed in the mask with 1, in value with number expected. -For example, a range of 6 to 7 is enumerated as 0b110 and 0b111. -Bit 1-7 are bits never changed and bit 0 is the bit dynamically changed. -Therefore, set bit 0 in mask and value with 0, set bits 1-7 in mask with 1, and bits 1-7 in value with number 0b11. -So, mask is 0xfe, value is 0x6. - -.. note:: - - The library assumes that each field in the rule is in LSB or Little Endian order when creating the database. - It internally converts them to MSB or Big Endian order. - When performing a lookup, the library assumes the input is in MSB or Big Endian order. - -Access Rule Syntax -~~~~~~~~~~~~~~~~~~ - -In this sample application, each rule is a combination of the following: - -* 5-tuple field: This field has a format described in Section. - -* priority field: A weight to measure the priority of the rules. - The rule with the higher priority will ALWAYS be returned if the specific input has multiple matches in the rule database. - Rules with lower priority will NEVER be returned in any cases. - -* userdata field: A user-defined field that could be any value. - It can be the forwarding port number if the rule is a route table entry or it can be a pointer to a mapping address - if the rule is used for address mapping in the NAT application. - The key point is that it is a useful reserved field for user convenience. - -ACL and Route Rules -~~~~~~~~~~~~~~~~~~~ - -The application needs to acquire ACL and route rules before it runs. -Route rules are mandatory, while ACL rules are optional. -To simplify the complexity of the priority field for each rule, all ACL and route entries are assumed to be in the same file. -To read data from the specified file successfully, the application assumes the following: - -* Each rule occupies a single line. - -* Only the following four rule line types are valid in this application: - -* ACL rule line, which starts with a leading character '@' - -* Route rule line, which starts with a leading character 'R' - -* Comment line, which starts with a leading character '#' - -* Empty line, which consists of a space, form-feed ('\f'), newline ('\n'), - carriage return ('\r'), horizontal tab ('\t'), or vertical tab ('\v'). - -Other lines types are considered invalid. - -* Rules are organized in descending order of priority, - which means rules at the head of the file always have a higher priority than those further down in the file. - -* A typical IPv4 ACL rule line should have a format as shown below: - - -.. _figure_ipv4_acl_rule: - -.. figure:: img/ipv4_acl_rule.* - - A typical IPv4 ACL rule - - -IPv4 addresses are specified in CIDR format as specified in RFC 4632. -They consist of the dot notation for the address and a prefix length separated by '/'. -For example, 192.168.0.34/32, where the address is 192.168.0.34 and the prefix length is 32. - -Ports are specified as a range of 16-bit numbers in the format MIN:MAX, -where MIN and MAX are the inclusive minimum and maximum values of the range. -The range 0:65535 represents all possible ports in a range. -When MIN and MAX are the same value, a single port is represented, for example, 20:20. - -The protocol identifier is an 8-bit value and a mask separated by '/'. -For example: 6/0xfe matches protocol values 6 and 7. - -* Route rules start with a leading character 'R' and have the same format as ACL rules except an extra field at the tail - that indicates the forwarding port number. - -Rules File Example -~~~~~~~~~~~~~~~~~~ - -.. _figure_example_rules: - -.. figure:: img/example_rules.* - - Rules example - - -Each rule is explained as follows: - -* Rule 1 (the first line) tells the application to drop those packets with source IP address = [1.2.3.*], - destination IP address = [192.168.0.36], protocol = [6]/[7] - -* Rule 2 (the second line) is similar to Rule 1, except the source IP address is ignored. - It tells the application to forward packets with destination IP address = [192.168.0.36], - protocol = [6]/[7], destined to port 1. - -* Rule 3 (the third line) tells the application to forward all packets to port 0. - This is something like a default route entry. - -As described earlier, the application assume rules are listed in descending order of priority, -therefore Rule 1 has the highest priority, then Rule 2, and finally, -Rule 3 has the lowest priority. - -Consider the arrival of the following three packets: - -* Packet 1 has source IP address = [1.2.3.4], destination IP address = [192.168.0.36], and protocol = [6] - -* Packet 2 has source IP address = [1.2.4.4], destination IP address = [192.168.0.36], and protocol = [6] - -* Packet 3 has source IP address = [1.2.3.4], destination IP address = [192.168.0.36], and protocol = [8] - -Observe that: - -* Packet 1 matches all of the rules - -* Packet 2 matches Rule 2 and Rule 3 - -* Packet 3 only matches Rule 3 - -For priority reasons, Packet 1 matches Rule 1 and is dropped. -Packet 2 matches Rule 2 and is forwarded to port 1. -Packet 3 matches Rule 3 and is forwarded to port 0. - -For more details on the rule file format, -please refer to rule_ipv4.db and rule_ipv6.db files (inside /examples/l3fwd-acl/). - -Application Phases -~~~~~~~~~~~~~~~~~~ - -Once the application starts, it transitions through three phases: - -* **Initialization Phase** - - Perform the following tasks: - -* Parse command parameters. Check the validity of rule file(s) name(s), number of logical cores, receive and transmit queues. - Bind ports, queues and logical cores. Check ACL search options, and so on. - -* Call Environmental Abstraction Layer (EAL) and Poll Mode Driver (PMD) functions to initialize the environment and detect possible NICs. - The EAL creates several threads and sets affinity to a specific hardware thread CPU based on the configuration specified - by the command line arguments. - -* Read the rule files and format the rules into the representation that the ACL library can recognize. - Call the ACL library function to add the rules into the database and compile them as a trie of pattern sets. - Note that application maintains a separate AC contexts for IPv4 and IPv6 rules. - -* **Runtime Phase** - - Process the incoming packets from a port. Packets are processed in three steps: - - * Retrieval: Gets a packet from the receive queue. Each logical core may process several queues for different ports. - This depends on the configuration specified by command line arguments. - - * Lookup: Checks that the packet type is supported (IPv4/IPv6) and performs a 5-tuple lookup over corresponding AC context. - If an ACL rule is matched, the packets will be dropped and return back to step 1. - If a route rule is matched, it indicates the packet is not in the ACL list and should be forwarded. - If there is no matches for the packet, then the packet is dropped. - - * Forwarding: Forwards the packet to the corresponding port. - -* **Final Phase** - Perform the following tasks: - - Calls the EAL, PMD driver and ACL library to free resource, then quits. - -Compiling the Application -------------------------- - -To compile the application: - -#. Go to the sample application directory: - - .. code-block:: console - - export RTE_SDK=/path/to/rte_sdk - cd ${RTE_SDK}/examples/l3fwd-acl - -#. Set the target (a default target is used if not specified). For example: - - .. code-block:: console - - export RTE_TARGET=x86_64-native-linuxapp-gcc - - See the *DPDK IPL Getting Started Guide* for possible RTE_TARGET values. - -#. Build the application: - - .. code-block:: console - - make - -Running the Application ------------------------ - -The application has a number of command line options: - -.. code-block:: console - - ./build/l3fwd-acl [EAL options] -- -p PORTMASK [-P] --config(port,queue,lcore)[,(port,queue,lcore)] --rule_ipv4 FILENAME rule_ipv6 FILENAME [--scalar] [--enable-jumbo [--max-pkt-len PKTLEN]] [--no-numa] - - -where, - -* -p PORTMASK: Hexadecimal bitmask of ports to configure - -* -P: Sets all ports to promiscuous mode so that packets are accepted regardless of the packet's Ethernet MAC destination address. - Without this option, only packets with the Ethernet MAC destination address set to the Ethernet address of the port are accepted. - -* --config (port,queue,lcore)[,(port,queue,lcore)]: determines which queues from which ports are mapped to which cores - -* --rule_ipv4 FILENAME: Specifies the IPv4 ACL and route rules file - -* --rule_ipv6 FILENAME: Specifies the IPv6 ACL and route rules file - -* --scalar: Use a scalar function to perform rule lookup - -* --enable-jumbo: optional, enables jumbo frames - -* --max-pkt-len: optional, maximum packet length in decimal (64-9600) - -* --no-numa: optional, disables numa awareness - -For example, consider a dual processor socket platform with 8 physical cores, where cores 0-7 and 16-23 appear on socket 0, -while cores 8-15 and 24-31 appear on socket 1. - -To enable L3 forwarding between two ports, assuming that both ports are in the same socket, using two cores, cores 1 and 2, -(which are in the same socket too), use the following command: - -.. code-block:: console - - ./build/l3fwd-acl -l 1,2 -n 4 -- -p 0x3 --config="(0,0,1),(1,0,2)" --rule_ipv4="./rule_ipv4.db" -- rule_ipv6="./rule_ipv6.db" --scalar - -In this command: - -* The -l option enables cores 1, 2 - -* The -p option enables ports 0 and 1 - -* The --config option enables one queue on each port and maps each (port,queue) pair to a specific core. - The following table shows the mapping in this example: - - +----------+------------+-----------+-------------------------------------+ - | **Port** | **Queue** | **lcore** | **Description** | - | | | | | - +==========+============+===========+=====================================+ - | 0 | 0 | 1 | Map queue 0 from port 0 to lcore 1. | - | | | | | - +----------+------------+-----------+-------------------------------------+ - | 1 | 0 | 2 | Map queue 0 from port 1 to lcore 2. | - | | | | | - +----------+------------+-----------+-------------------------------------+ - -* The --rule_ipv4 option specifies the reading of IPv4 rules sets from the ./ rule_ipv4.db file. - -* The --rule_ipv6 option specifies the reading of IPv6 rules sets from the ./ rule_ipv6.db file. - -* The --scalar option specifies the performing of rule lookup with a scalar function. - -Explanation ------------ - -The following sections provide some explanation of the sample application code. -The aspects of port, device and CPU configuration are similar to those of the :doc:`l3_forward`. -The following sections describe aspects that are specific to L3 forwarding with access control. - -Parse Rules from File -~~~~~~~~~~~~~~~~~~~~~ - -As described earlier, both ACL and route rules are assumed to be saved in the same file. -The application parses the rules from the file and adds them to the database by calling the ACL library function. -It ignores empty and comment lines, and parses and validates the rules it reads. -If errors are detected, the application exits with messages to identify the errors encountered. - -The application needs to consider the userdata and priority fields. -The ACL rules save the index to the specific rules in the userdata field, -while route rules save the forwarding port number. -In order to differentiate the two types of rules, ACL rules add a signature in the userdata field. -As for the priority field, the application assumes rules are organized in descending order of priority. -Therefore, the code only decreases the priority number with each rule it parses. - -Setting Up the ACL Context -~~~~~~~~~~~~~~~~~~~~~~~~~~ - -For each supported AC rule format (IPv4 5-tuple, IPv6 6-tuple) application creates a separate context handler -from the ACL library for each CPU socket on the board and adds parsed rules into that context. - -Note, that for each supported rule type, -application needs to calculate the expected offset of the fields from the start of the packet. -That's why only packets with fixed IPv4/ IPv6 header are supported. -That allows to perform ACL classify straight over incoming packet buffer - -no extra protocol field retrieval need to be performed. - -Subsequently, the application checks whether NUMA is enabled. -If it is, the application records the socket IDs of the CPU cores involved in the task. - -Finally, the application creates contexts handler from the ACL library, -adds rules parsed from the file into the database and build an ACL trie. -It is important to note that the application creates an independent copy of each database for each socket CPU -involved in the task to reduce the time for remote memory access. -- 2.7.4