xref: /dpdk/doc/guides/sample_app_ug/ipsec_secgw.rst (revision 6b8f212d3a0f30847bb6948d45e6aae57749ac56)
1..  SPDX-License-Identifier: BSD-3-Clause
2    Copyright(c) 2016-2017 Intel Corporation.
3    Copyright (C) 2020 Marvell International Ltd.
4
5IPsec Security Gateway Sample Application
6=========================================
7
8The IPsec Security Gateway application is an example of a "real world"
9application using DPDK cryptodev framework.
10
11Overview
12--------
13
14The application demonstrates the implementation of a Security Gateway
15(not IPsec compliant, see the Constraints section below) using DPDK based on RFC4301,
16RFC4303, RFC3602 and RFC2404.
17
18Internet Key Exchange (IKE) is not implemented, so only manual setting of
19Security Policies and Security Associations is supported.
20
21The Security Policies (SP) are implemented as ACL rules, the Security
22Associations (SA) are stored in a table and the routing is implemented
23using LPM.
24
25The application classifies the ports as *Protected* and *Unprotected*.
26Thus, traffic received on an Unprotected or Protected port is consider
27Inbound or Outbound respectively.
28
29The application also supports complete IPsec protocol offload to hardware
30(Look aside crypto accelerator or using ethernet device). It also support
31inline ipsec processing by the supported ethernet device during transmission.
32These modes can be selected during the SA creation configuration.
33
34In case of complete protocol offload, the processing of headers(ESP and outer
35IP header) is done by the hardware and the application does not need to
36add/remove them during outbound/inbound processing.
37
38For inline offloaded outbound traffic, the application will not do the LPM
39lookup for routing, as the port on which the packet has to be forwarded will be
40part of the SA. Security parameters will be configured on that port only, and
41sending the packet on other ports could result in unencrypted packets being
42sent out.
43
44The Path for IPsec Inbound traffic is:
45
46*  Read packets from the port.
47*  Classify packets between IPv4 and ESP.
48*  Perform Inbound SA lookup for ESP packets based on their SPI.
49*  Perform Verification/Decryption (Not needed in case of inline ipsec).
50*  Remove ESP and outer IP header (Not needed in case of protocol offload).
51*  Inbound SP check using ACL of decrypted packets and any other IPv4 packets.
52*  Routing.
53*  Write packet to port.
54
55The Path for the IPsec Outbound traffic is:
56
57*  Read packets from the port.
58*  Perform Outbound SP check using ACL of all IPv4 traffic.
59*  Perform Outbound SA lookup for packets that need IPsec protection.
60*  Add ESP and outer IP header (Not needed in case protocol offload).
61*  Perform Encryption/Digest (Not needed in case of inline ipsec).
62*  Routing.
63*  Write packet to port.
64
65The application supports two modes of operation: poll mode and event mode.
66
67* In the poll mode a core receives packets from statically configured list
68  of eth ports and eth ports' queues.
69
70* In the event mode a core receives packets as events. After packet processing
71  is done core submits them back as events to an event device. This enables
72  multicore scaling and HW assisted scheduling by making use of the event device
73  capabilities. The event mode configuration is predefined. All packets reaching
74  given eth port will arrive at the same event queue. All event queues are mapped
75  to all event ports. This allows all cores to receive traffic from all ports.
76  Since the underlying event device might have varying capabilities, the worker
77  threads can be drafted differently to maximize performance. For example, if an
78  event device - eth device pair has Tx internal port, then application can call
79  rte_event_eth_tx_adapter_enqueue() instead of regular rte_event_enqueue_burst().
80  So a thread which assumes that the device pair has internal port will not be the
81  right solution for another pair. The infrastructure added for the event mode aims
82  to help application to have multiple worker threads by maximizing performance from
83  every type of event device without affecting existing paths/use cases. The worker
84  to be used will be determined by the operating conditions and the underlying device
85  capabilities.
86  **Currently the application provides non-burst, internal port worker threads.**
87  It also provides infrastructure for non-internal port
88  however does not define any worker threads.
89
90  Event mode also supports event vectorization. The event devices, ethernet device
91  pairs which support the capability ``RTE_EVENT_ETH_RX_ADAPTER_CAP_EVENT_VECTOR`` can
92  aggregate packets based on flow characteristics and generate a ``rte_event``
93  containing ``rte_event_vector``.
94  The aggregation size and timeout can be given using command line options vector-size
95  (default vector-size is 16) and vector-tmo (default vector-tmo is 102400ns).
96  By default event vectorization is disabled and it can be enabled using event-vector
97  option.
98  For the event devices, crypto device pairs which support the capability
99  ``RTE_EVENT_CRYPTO_ADAPTER_CAP_EVENT_VECTOR`` vector aggregation
100  could also be enable using event-vector option.
101
102Additionally the event mode introduces two submodes of processing packets:
103
104* Driver submode: This submode has bare minimum changes in the application to support
105  IPsec. There are no lookups, no routing done in the application. And for inline
106  protocol use case, the worker thread resembles l2fwd worker thread as the IPsec
107  processing is done entirely in HW. This mode can be used to benchmark the raw
108  performance of the HW. The driver submode is selected with --single-sa option
109  (used also by poll mode). When --single-sa option is used in conjunction with event
110  mode then index passed to --single-sa is ignored.
111
112* App submode: This submode has all the features currently implemented with the
113  application (non librte_ipsec path). All the lookups, routing follows existing
114  methods and report numbers that can be compared against regular poll mode
115  benchmark numbers.
116
117Constraints
118-----------
119
120*  No IPv6 options headers.
121*  No AH mode.
122*  Supported algorithms: AES-CBC, AES-CTR, AES-GCM, 3DES-CBC, DES-CBC,
123   HMAC-SHA1, HMAC-SHA256, AES-GMAC, AES_CTR, AES_XCBC_MAC, AES_CCM,
124   CHACHA20_POLY1305 and NULL.
125*  Each SA must be handle by a unique lcore (*1 RX queue per port*).
126
127Compiling the Application
128-------------------------
129
130To compile the sample application see :doc:`compiling`.
131
132The application is located in the ``ipsec-secgw`` sub-directory.
133
134
135Running the Application
136-----------------------
137
138The application has a number of command line options::
139
140
141   ./<build_dir>/examples/dpdk-ipsec-secgw [EAL options] --
142                        -p PORTMASK -P -u PORTMASK -j FRAMESIZE
143                        -l -w REPLAY_WINDOW_SIZE -e -a
144                        -c SAD_CACHE_SIZE
145                        -t STATISTICS_INTERVAL
146                        -s NUMBER_OF_MBUFS_IN_PACKET_POOL
147                        -f CONFIG_FILE_PATH
148                        --config (port,queue,lcore)[,(port,queue,lcore)]
149                        --single-sa SAIDX
150                        --cryptodev_mask MASK
151                        --transfer-mode MODE
152                        --event-schedule-type TYPE
153                        --rxoffload MASK
154                        --txoffload MASK
155                        --reassemble NUM
156                        --mtu MTU
157                        --frag-ttl FRAG_TTL_NS
158                        --desc-nb NUMBER_OF_DESC
159
160Where:
161
162*   ``-p PORTMASK``: Hexadecimal bitmask of ports to configure.
163
164*   ``-P``: *optional*. Sets all ports to promiscuous mode so that packets are
165    accepted regardless of the packet's Ethernet MAC destination address.
166    Without this option, only packets with the Ethernet MAC destination address
167    set to the Ethernet address of the port are accepted (default is enabled).
168
169*   ``-u PORTMASK``: hexadecimal bitmask of unprotected ports
170
171*   ``-j FRAMESIZE``: *optional*. data buffer size (in bytes),
172    in other words maximum data size for one segment.
173    Packets with length bigger then FRAMESIZE still can be received,
174    but will be segmented.
175    Default value: RTE_MBUF_DEFAULT_BUF_SIZE (2176)
176    Minimum value: RTE_MBUF_DEFAULT_BUF_SIZE (2176)
177    Maximum value: UINT16_MAX (65535).
178
179*   ``-l``: enables code-path that uses librte_ipsec.
180
181*   ``-w REPLAY_WINDOW_SIZE``: specifies the IPsec sequence number replay window
182    size for each Security Association (available only with librte_ipsec
183    code path).
184
185*   ``-e``: enables Security Association extended sequence number processing
186    (available only with librte_ipsec code path).
187
188*   ``-a``: enables Security Association sequence number atomic behavior
189    (available only with librte_ipsec code path).
190
191*   ``-c``: specifies the SAD cache size. Stores the most recent SA in a per
192    lcore cache. Cache represents flat array containing SA's indexed by SPI.
193    Zero value disables cache.
194    Default value: 128.
195
196*   ``-t``: specifies the statistics screen update interval in seconds. If set
197    to zero or omitted statistics screen is disabled.
198    Default value: 0.
199
200*   ``-s``: sets number of mbufs in packet pool, if not provided number of mbufs
201    will be calculated based on number of cores, eth ports and crypto queues.
202
203*   ``-f CONFIG_FILE_PATH``: the full path of text-based file containing all
204    configuration items for running the application (See Configuration file
205    syntax section below). ``-f CONFIG_FILE_PATH`` **must** be specified.
206    **ONLY** the UNIX format configuration file is accepted.
207
208*   ``--config (port,queue,lcore)[,(port,queue,lcore)]``: in poll mode determines
209    which queues from which ports are mapped to which cores. In event mode this
210    option is not used as packets are dynamically scheduled to cores by HW.
211
212*   ``--single-sa SAIDX``: in poll mode use a single SA for outbound traffic,
213    bypassing the SP on both Inbound and Outbound. This option is meant for
214    debugging/performance purposes. In event mode selects driver submode, SA index
215    value is ignored.
216
217*   ``--cryptodev_mask MASK``: hexadecimal bitmask of the crypto devices
218    to configure.
219
220*   ``--transfer-mode MODE``: sets operating mode of the application
221    "poll"  : packet transfer via polling (default)
222    "event" : Packet transfer via event device
223
224*   ``--event-schedule-type TYPE``: queue schedule type, applies only when
225    --transfer-mode is set to event.
226    "ordered"  : Ordered (default)
227    "atomic"   : Atomic
228    "parallel" : Parallel
229    When --event-schedule-type is set as RTE_SCHED_TYPE_ORDERED/ATOMIC, event
230    device will ensure the ordering. Ordering will be lost when tried in PARALLEL.
231
232*   ``--rxoffload MASK``: RX HW offload capabilities to enable/use on this port
233    (bitmask of RTE_ETH_RX_OFFLOAD_* values). It is an optional parameter and
234    allows user to disable some of the RX HW offload capabilities.
235    By default all HW RX offloads are enabled.
236
237*   ``--txoffload MASK``: TX HW offload capabilities to enable/use on this port
238    (bitmask of RTE_ETH_TX_OFFLOAD_* values). It is an optional parameter and
239    allows user to disable some of the TX HW offload capabilities.
240    By default all HW TX offloads are enabled.
241
242*   ``--reassemble NUM``: max number of entries in reassemble fragment table.
243    Zero value disables reassembly functionality.
244    Default value: 0.
245
246*   ``--mtu MTU``: MTU value (in bytes) on all attached ethernet ports.
247    Outgoing packets with length bigger then MTU will be fragmented.
248    Incoming packets with length bigger then MTU will be discarded.
249    Default value: 1500.
250
251*   ``--frag-ttl FRAG_TTL_NS``: fragment lifetime (in nanoseconds).
252    If packet is not reassembled within this time, received fragments
253    will be discarded. Fragment lifetime should be decreased when
254    there is a high fragmented traffic loss in high bandwidth networks.
255    Should be lower for low number of reassembly buckets.
256    Valid values: from 1 ns to 10 s. Default value: 10000000 (10 s).
257
258*   ``--per-port-pool``: Enable per ethdev port pktmbuf pool.
259     By default one packet mbuf pool per socket is created and configured
260     via Rx queue setup.
261
262*   ``--vector-pool-sz``: Number of buffers in vector pool.
263    By default, vector pool size depeneds on packet pool size
264    and size of each vector.
265
266*   ``--desc-nb NUMBER_OF_DESC``: Number of descriptors per queue pair.
267    Default value: 2048.
268
269The mapping of lcores to port/queues is similar to other l3fwd applications.
270
271For example, given the following command line to run application in poll mode::
272
273    ./<build_dir>/examples/dpdk-ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048       \
274           --vdev "crypto_null" -- -p 0xf -P -u 0x3             \
275           --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)"       \
276           -f /path/to/config_file --transfer-mode poll         \
277
278where each option means:
279
280*   The ``-l`` option enables cores 20 and 21.
281
282*   The ``-n`` option sets memory 4 channels.
283
284*   The ``--socket-mem`` to use 2GB on socket 1.
285
286*   The ``--vdev "crypto_null"`` option creates virtual NULL cryptodev PMD.
287
288*   The ``-p`` option enables ports (detected) 0, 1, 2 and 3.
289
290*   The ``-P`` option enables promiscuous mode.
291
292*   The ``-u`` option sets ports 0 and 1 as unprotected, leaving 2 and 3 as protected.
293
294*   The ``--config`` option enables one queue per port with the following mapping:
295
296    +----------+-----------+-----------+---------------------------------------+
297    | **Port** | **Queue** | **lcore** | **Description**                       |
298    |          |           |           |                                       |
299    +----------+-----------+-----------+---------------------------------------+
300    | 0        | 0         | 20        | Map queue 0 from port 0 to lcore 20.  |
301    |          |           |           |                                       |
302    +----------+-----------+-----------+---------------------------------------+
303    | 1        | 0         | 20        | Map queue 0 from port 1 to lcore 20.  |
304    |          |           |           |                                       |
305    +----------+-----------+-----------+---------------------------------------+
306    | 2        | 0         | 21        | Map queue 0 from port 2 to lcore 21.  |
307    |          |           |           |                                       |
308    +----------+-----------+-----------+---------------------------------------+
309    | 3        | 0         | 21        | Map queue 0 from port 3 to lcore 21.  |
310    |          |           |           |                                       |
311    +----------+-----------+-----------+---------------------------------------+
312
313*   The ``-f /path/to/config_file`` option enables the application read and
314    parse the configuration file specified, and configures the application
315    with a given set of SP, SA and Routing entries accordingly. The syntax of
316    the configuration file will be explained below in more detail. Please
317    **note** the parser only accepts UNIX format text file. Other formats
318    such as DOS/MAC format will cause a parse error.
319
320*   The ``--transfer-mode`` option selects poll mode for processing packets.
321
322Similarly for example, given the following command line to run application in
323event app mode::
324
325    ./<build_dir>/examples/dpdk-ipsec-secgw -c 0x3 -- -P -p 0x3 -u 0x1       \
326           -f /path/to/config_file --transfer-mode event \
327           --event-schedule-type parallel --event-vector --vector-size 32    \
328           --vector-tmo 102400                           \
329
330where each option means:
331
332*   The ``-c`` option selects cores 0 and 1 to run on.
333
334*   The ``-P`` option enables promiscuous mode.
335
336*   The ``-p`` option enables ports (detected) 0 and 1.
337
338*   The ``-u`` option sets ports 0 as unprotected, leaving 1 as protected.
339
340*   The ``-f /path/to/config_file`` option has the same behavior as in poll
341    mode example.
342
343*   The ``--transfer-mode`` option selects event mode for processing packets.
344
345*   The ``--event-schedule-type`` option selects parallel ordering of event queues.
346
347*   The ``--event-vector`` option enables event vectorization.
348
349*   The ``--vector-size`` option specifies max vector size.
350
351*   The ``--vector-tmo`` option specifies max timeout in nanoseconds for vectorization.
352
353
354Refer to the *DPDK Getting Started Guide* for general information on running
355applications and the Environment Abstraction Layer (EAL) options.
356
357The application would do a best effort to "map" crypto devices to cores, with
358hardware devices having priority. Basically, hardware devices if present would
359be assigned to a core before software ones.
360This means that if the application is using a single core and both hardware
361and software crypto devices are detected, hardware devices will be used.
362
363A way to achieve the case where you want to force the use of virtual crypto
364devices is to only use the Ethernet devices needed (via the allow flag)
365and therefore implicitly blocking all hardware crypto devices.
366
367For example, something like the following command line:
368
369.. code-block:: console
370
371    ./<build_dir>/examples/dpdk-ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048 \
372            -a 81:00.0 -a 81:00.1 -a 81:00.2 -a 81:00.3 \
373            --vdev "crypto_aesni_mb" --vdev "crypto_null" \
374	    -- \
375            -p 0xf -P -u 0x3 --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)" \
376            -f sample.cfg
377
378
379Configurations
380--------------
381
382The following sections provide the syntax of configurations to initialize
383your SP, SA, Routing, Flow and Neighbour tables.
384Configurations shall be specified in the configuration file to be passed to
385the application. The file is then parsed by the application. The successful
386parsing will result in the appropriate rules being applied to the tables
387accordingly.
388
389
390Configuration File Syntax
391~~~~~~~~~~~~~~~~~~~~~~~~~
392
393As mention in the overview, the Security Policies are ACL rules.
394The application parsers the rules specified in the configuration file and
395passes them to the ACL table, and replicates them per socket in use.
396
397Following are the configuration file syntax.
398
399General rule syntax
400^^^^^^^^^^^^^^^^^^^
401
402The parse treats one line in the configuration file as one configuration
403item (unless the line concatenation symbol exists). Every configuration
404item shall follow the syntax of either SP, SA, Routing, Flow or Neighbour
405rules specified below.
406
407The configuration parser supports the following special symbols:
408
409 * Comment symbol **#**. Any character from this symbol to the end of
410   line is treated as comment and will not be parsed.
411
412 * Line concatenation symbol **\\**. This symbol shall be placed in the end
413   of the line to be concatenated to the line below. Multiple lines'
414   concatenation is supported.
415
416
417SP rule syntax
418^^^^^^^^^^^^^^
419
420The SP rule syntax is shown as follows:
421
422.. code-block:: console
423
424    sp <ip_ver> <dir> esp <action> <priority> <src_ip> <dst_ip>
425    <proto> <sport> <dport>
426
427
428where each options means:
429
430``<ip_ver>``
431
432 * IP protocol version
433
434 * Optional: No
435
436 * Available options:
437
438   * *ipv4*: IP protocol version 4
439   * *ipv6*: IP protocol version 6
440
441``<dir>``
442
443 * The traffic direction
444
445 * Optional: No
446
447 * Available options:
448
449   * *in*: inbound traffic
450   * *out*: outbound traffic
451
452``<action>``
453
454 * IPsec action
455
456 * Optional: No
457
458 * Available options:
459
460   * *protect <SA_idx>*: the specified traffic is protected by SA rule
461     with id SA_idx
462   * *bypass*: the specified traffic is bypassed
463   * *discard*: the specified traffic is discarded
464
465``<priority>``
466
467 * Rule priority
468
469 * Optional: Yes, default priority 0 will be used
470
471 * Syntax: *pri <id>*
472
473``<src_ip>``
474
475 * The source IP address and mask
476
477 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
478
479 * Syntax:
480
481   * *src X.X.X.X/Y* for IPv4
482   * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
483
484``<dst_ip>``
485
486 * The destination IP address and mask
487
488 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
489
490 * Syntax:
491
492   * *dst X.X.X.X/Y* for IPv4
493   * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
494
495``<proto>``
496
497 * The protocol start and end range
498
499 * Optional: yes, default range of 0 to 0 will be used
500
501 * Syntax: *proto X:Y*
502
503``<sport>``
504
505 * The source port start and end range
506
507 * Optional: yes, default range of 0 to 0 will be used
508
509 * Syntax: *sport X:Y*
510
511``<dport>``
512
513 * The destination port start and end range
514
515 * Optional: yes, default range of 0 to 0 will be used
516
517 * Syntax: *dport X:Y*
518
519Example SP rules:
520
521.. code-block:: console
522
523    sp ipv4 out esp protect 105 pri 1 dst 192.168.115.0/24 sport 0:65535 \
524    dport 0:65535
525
526    sp ipv6 in esp bypass pri 1 dst 0000:0000:0000:0000:5555:5555:\
527    0000:0000/96 sport 0:65535 dport 0:65535
528
529
530SA rule syntax
531^^^^^^^^^^^^^^
532
533The successfully parsed SA rules will be stored in an array table.
534
535The SA rule syntax is shown as follows:
536
537.. code-block:: console
538
539    sa <dir> <spi> <cipher_algo> <cipher_key> <auth_algo> <auth_key>
540    <mode> <src_ip> <dst_ip> <action_type> <port_id> <fallback>
541    <flow-direction> <port_id> <queue_id> <udp-encap> <reassembly_en>
542
543where each options means:
544
545``<dir>``
546
547 * The traffic direction
548
549 * Optional: No
550
551 * Available options:
552
553   * *in*: inbound traffic
554   * *out*: outbound traffic
555
556``<spi>``
557
558 * The SPI number
559
560 * Optional: No
561
562 * Syntax: unsigned integer number
563
564``<cipher_algo>``
565
566 * Cipher algorithm
567
568 * Optional: Yes, unless <aead_algo> is not used
569
570 * Available options:
571
572   * *null*: NULL algorithm
573   * *aes-128-cbc*: AES-CBC 128-bit algorithm
574   * *aes-192-cbc*: AES-CBC 192-bit algorithm
575   * *aes-256-cbc*: AES-CBC 256-bit algorithm
576   * *aes-128-ctr*: AES-CTR 128-bit algorithm
577   * *3des-cbc*: 3DES-CBC 192-bit algorithm
578   * *des-cbc*: DES-CBC 64-bit algorithm
579
580 * Syntax: *cipher_algo <your algorithm>*
581
582``<cipher_key>``
583
584 * Cipher key, NOT available when 'null' algorithm is used
585
586 * Optional: Yes, unless <aead_algo> is not used.
587   Must be followed by <cipher_algo> option
588
589 * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'.
590   The number of bytes should be as same as the specified cipher algorithm
591   key size.
592
593   For example: *cipher_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:
594   A1:B2:C3:D4*
595
596``<auth_algo>``
597
598 * Authentication algorithm
599
600 * Optional: Yes, unless <aead_algo> is not used
601
602 * Available options:
603
604    * *null*: NULL algorithm
605    * *sha1-hmac*: HMAC SHA1 algorithm
606    * *sha256-hmac*: HMAC SHA256 algorithm
607    * *aes-xcbc-mac*: AES XCBC MAC algorithm
608
609``<auth_key>``
610
611 * Authentication key, NOT available when 'null' or 'aes-128-gcm' algorithm
612   is used.
613
614 * Optional: Yes, unless <aead_algo> is not used.
615   Must be followed by <auth_algo> option
616
617 * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'.
618   The number of bytes should be as same as the specified authentication
619   algorithm key size.
620
621   For example: *auth_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:
622   A1:B2:C3:D4*
623
624``<aead_algo>``
625
626 * AEAD algorithm
627
628 * Optional: Yes, unless <cipher_algo> and <auth_algo> are not used
629
630 * Available options:
631
632   * *aes-128-gcm*: AES-GCM 128-bit algorithm
633   * *aes-192-gcm*: AES-GCM 192-bit algorithm
634   * *aes-256-gcm*: AES-GCM 256-bit algorithm
635
636 * Syntax: *cipher_algo <your algorithm>*
637
638``<aead_key>``
639
640 * Cipher key, NOT available when 'null' algorithm is used
641
642 * Optional: Yes, unless <cipher_algo> and <auth_algo> are not used.
643   Must be followed by <aead_algo> option
644
645 * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'.
646   Last 4 bytes of the provided key will be used as 'salt' and so, the
647   number of bytes should be same as the sum of specified AEAD algorithm
648   key size and salt size (4 bytes).
649
650   For example: *aead_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:
651   A1:B2:C3:D4:A1:B2:C3:D4*
652
653``<mode>``
654
655 * The operation mode
656
657 * Optional: No
658
659 * Available options:
660
661   * *ipv4-tunnel*: Tunnel mode for IPv4 packets
662   * *ipv6-tunnel*: Tunnel mode for IPv6 packets
663   * *transport*: transport mode
664
665 * Syntax: mode XXX
666
667``<src_ip>``
668
669 * The source IP address. This option is not available when
670   transport mode is used
671
672 * Optional: Yes, default address 0.0.0.0 will be used
673
674 * Syntax:
675
676   * *src X.X.X.X* for IPv4
677   * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX* for IPv6
678
679``<dst_ip>``
680
681 * The destination IP address. This option is not available when
682   transport mode is used
683
684 * Optional: Yes, default address 0.0.0.0 will be used
685
686 * Syntax:
687
688   * *dst X.X.X.X* for IPv4
689   * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX* for IPv6
690
691``<type>``
692
693 * Action type to specify the security action. This option specify
694   the SA to be performed with look aside protocol offload to HW
695   accelerator or protocol offload on ethernet device or inline
696   crypto processing on the ethernet device during transmission.
697
698 * Optional: Yes, default type *no-offload*
699
700 * Available options:
701
702   * *lookaside-protocol-offload*: look aside protocol offload to HW accelerator
703   * *inline-protocol-offload*: inline protocol offload on ethernet device
704   * *inline-crypto-offload*: inline crypto processing on ethernet device
705   * *no-offload*: no offloading to hardware
706
707 ``<port_id>``
708
709 * Port/device ID of the ethernet/crypto accelerator for which the SA is
710   configured. For *inline-crypto-offload* and *inline-protocol-offload*, this
711   port will be used for routing. The routing table will not be referred in
712   this case.
713
714 * Optional: No, if *type* is not *no-offload*
715
716 * Syntax:
717
718   * *port_id X* X is a valid device number in decimal
719
720 ``<fallback>``
721
722 * Action type for ingress IPsec packets that inline processor failed to
723   process. Only a combination of *inline-crypto-offload* as a primary
724   session and *lookaside-none* as a fall-back session is supported at the
725   moment.
726
727   If used in conjunction with IPsec window, its width needs be increased
728   due to different processing times of inline and lookaside modes which
729   results in packet reordering.
730
731 * Optional: Yes.
732
733 * Available options:
734
735   * *lookaside-none*: use automatically chosen cryptodev to process packets
736
737 * Syntax:
738
739   * *fallback lookaside-none*
740
741``<flow-direction>``
742
743 * Option for redirecting a specific inbound ipsec flow of a port to a specific
744   queue of that port.
745
746 * Optional: Yes.
747
748 * Available options:
749
750   * *port_id*: Port ID of the NIC for which the SA is configured.
751   * *queue_id*: Queue ID to which traffic should be redirected.
752
753 ``<udp-encap>``
754
755 * Option to enable IPsec UDP encapsulation for NAT Traversal.
756   Only *lookaside-protocol-offload* and *inline-crypto-offload* modes are
757   supported at the moment.
758
759 * Optional: Yes, it is disabled by default
760
761 * Syntax:
762
763   * *udp-encap*
764
765 ``<mss>``
766
767 * Maximum segment size for TSO offload, available for egress SAs only.
768   Currently only supports TCP/IP.
769
770 * Optional: Yes, TSO offload not set by default
771
772 * Syntax:
773
774   * *mss N* N is the segment size in bytes
775
776
777``<telemetry>``
778
779 * Option to enable per SA telemetry.
780   Currently only supported with IPsec library path.
781
782 * Optional: Yes, it is disabled by default
783
784 * Syntax:
785
786   * *telemetry*
787
788 ``<esn>``
789
790 * Enable ESN and set the initial ESN value.
791
792 * Optional: Yes, ESN not enabled by default
793
794 * Syntax:
795
796   * *esn N* N is the initial ESN value
797
798 ``<reassembly_en>``
799
800 * Option to enable HW reassembly per SA.
801
802 * Optional: Yes, it is disabled by default
803
804 * Syntax:
805
806   * *reassembly_en*
807
808Example SA rules:
809
810.. code-block:: console
811
812    sa out 5 cipher_algo null auth_algo null mode ipv4-tunnel \
813    src 172.16.1.5 dst 172.16.2.5
814
815    sa out 25 cipher_algo aes-128-cbc \
816    cipher_key c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3 \
817    auth_algo sha1-hmac \
818    auth_key c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3 \
819    mode ipv6-tunnel \
820    src 1111:1111:1111:1111:1111:1111:1111:5555 \
821    dst 2222:2222:2222:2222:2222:2222:2222:5555
822
823    sa in 105 aead_algo aes-128-gcm \
824    aead_key de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef \
825    mode ipv4-tunnel src 172.16.2.5 dst 172.16.1.5
826
827    sa out 5 cipher_algo aes-128-cbc cipher_key 0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0 \
828    auth_algo sha1-hmac auth_key 0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0 \
829    mode ipv4-tunnel src 172.16.1.5 dst 172.16.2.5 \
830    type lookaside-protocol-offload port_id 4
831
832    sa in 35 aead_algo aes-128-gcm \
833    aead_key de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef \
834    mode ipv4-tunnel src 172.16.2.5 dst 172.16.1.5 \
835    type inline-crypto-offload port_id 0
836
837    sa in 117 cipher_algo null auth_algo null mode ipv4-tunnel src 172.16.2.7 \
838    dst 172.16.1.7 flow-direction 0 2
839
840Routing rule syntax
841^^^^^^^^^^^^^^^^^^^
842
843The Routing rule syntax is shown as follows:
844
845.. code-block:: console
846
847    rt <ip_ver> <src_ip> <dst_ip> <port>
848
849
850where each options means:
851
852``<ip_ver>``
853
854 * IP protocol version
855
856 * Optional: No
857
858 * Available options:
859
860   * *ipv4*: IP protocol version 4
861   * *ipv6*: IP protocol version 6
862
863``<src_ip>``
864
865 * The source IP address and mask
866
867 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
868
869 * Syntax:
870
871   * *src X.X.X.X/Y* for IPv4
872   * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
873
874``<dst_ip>``
875
876 * The destination IP address and mask
877
878 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
879
880 * Syntax:
881
882   * *dst X.X.X.X/Y* for IPv4
883   * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
884
885``<port>``
886
887 * The traffic output port id
888
889 * Optional: yes, default output port 0 will be used
890
891 * Syntax: *port X*
892
893Example SP rules:
894
895.. code-block:: console
896
897    rt ipv4 dst 172.16.1.5/32 port 0
898
899    rt ipv6 dst 1111:1111:1111:1111:1111:1111:1111:5555/116 port 0
900
901Flow rule syntax
902^^^^^^^^^^^^^^^^
903
904Flow rule enables the usage of hardware classification capabilities to match specific
905ingress traffic and redirect the packets to the specified queue. This feature is
906optional and relies on hardware ``rte_flow`` support.
907
908The flow rule syntax is shown as follows:
909
910.. code-block:: console
911
912    flow <mark> <eth> <ip_ver> <src_ip> <dst_ip> <port> <queue> \
913         <count> <security> <set_mark>
914
915where each options means:
916
917``<mark>``
918
919 * Set RTE_FLOW_ITEM_TYPE_MARK pattern item in the flow rule with the given
920   mark value. This option can be used to match an arbitrary integer value
921   which was set using the RTE_FLOW_ACTION_TYPE_MARK action (see ``<set_mark>``)
922   in a previously matched rule.
923
924 * Optional: Yes, this pattern is not set by default.
925
926 * Syntax: *mark X*
927
928``<eth>``
929
930 * Set RTE_FLOW_ITEM_TYPE_ETH pattern item. This matches all ethernet packets.
931
932 * Optional: Yes, this pattern is not set by default.
933
934 * Syntax: *eth*
935
936``<ip_ver>``
937
938 * IP protocol version
939
940 * Optional: Yes, this pattern is not set by default.
941
942 * Available options:
943
944   * *ipv4*: IP protocol version 4
945   * *ipv6*: IP protocol version 6
946
947``<src_ip>``
948
949 * The source IP address and mask
950
951 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
952
953 * Syntax:
954
955   * *src X.X.X.X/Y* for IPv4
956   * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
957
958``<dst_ip>``
959
960 * The destination IP address and mask
961
962 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
963
964 * Syntax:
965
966   * *dst X.X.X.X/Y* for IPv4
967   * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
968
969``<port>``
970
971 * The traffic input port id
972
973 * Optional: yes, default input port 0 will be used
974
975 * Syntax: *port X*
976
977``<queue>``
978
979 * The traffic input queue id
980
981 * Optional: yes, default input queue 0 will be used
982
983 * Syntax: *queue X*
984
985``<count>``
986
987 * Set RTE_FLOW_ACTION_TYPE_COUNT action.
988
989 * Optional: yes, this action is not set by default.
990
991 * Syntax: *count*
992
993``<security>``
994
995 * Set RTE_FLOW_ITEM_TYPE_ESP pattern and RTE_FLOW_ACTION_TYPE_SECURITY action.
996
997 * Optional: yes, this pattern and action are not set by default.
998
999 * Syntax: *security*
1000
1001``<set_mark>``
1002
1003 * Set RTE_FLOW_ACTION_TYPE_MARK action in the flow rule with the given mark
1004   value. This option can be used to set the given integer value(mark) to
1005   packets and set RTE_MBUF_F_RX_FDIR and RTE_MBUF_F_RX_FDIR_ID mbuf flags.
1006
1007 * Optional: yes, this action is not set by default.
1008
1009 * Syntax: *set_mark X*
1010
1011Example flow rules:
1012
1013.. code-block:: console
1014
1015    flow ipv4 dst 172.16.1.5/32 port 0 queue 0
1016
1017    flow ipv6 dst 1111:1111:1111:1111:1111:1111:1111:5555/116 port 1 queue 0
1018
1019    flow mark 123 ipv4 dst 192.168.0.0/16 port 0 queue 0 count
1020
1021    flow eth ipv4 dst 192.168.0.0/16 port 0 queue 0 count
1022
1023    flow ipv4 dst 192.168.0.0/16 port 0 queue 0 count
1024
1025    flow ipv4 dst 192.168.0.0/16 port 0 queue 0
1026
1027    flow port 0 security set_mark 123
1028
1029    flow ipv4 dst 1.1.0.0/16 port 0 count set_mark 123 security
1030
1031
1032Neighbour rule syntax
1033^^^^^^^^^^^^^^^^^^^^^
1034
1035The Neighbour rule syntax is shown as follows:
1036
1037.. code-block:: console
1038
1039    neigh <port> <dst_mac>
1040
1041
1042where each options means:
1043
1044``<port>``
1045
1046 * The output port id
1047
1048 * Optional: No
1049
1050 * Syntax: *port X*
1051
1052``<dst_mac>``
1053
1054 * The destination ethernet address to use for that port
1055
1056 * Optional: No
1057
1058 * Syntax:
1059
1060   * XX:XX:XX:XX:XX:XX
1061
1062Example Neighbour rules:
1063
1064.. code-block:: console
1065
1066    neigh port 0 DE:AD:BE:EF:01:02
1067
1068Test directory
1069--------------
1070
1071The test directory contains scripts for testing the various encryption
1072algorithms.
1073
1074The purpose of the scripts is to automate ipsec-secgw testing
1075using another system running linux as a DUT.
1076
1077The user must setup the following environment variables:
1078
1079*   ``SGW_PATH``: path to the ipsec-secgw binary to test.
1080
1081*   ``REMOTE_HOST``: IP address/hostname of the DUT.
1082
1083*   ``REMOTE_IFACE``: interface name for the test-port on the DUT.
1084
1085*   ``ETH_DEV``: ethernet device to be used on the SUT by DPDK ('-a <pci-id>')
1086
1087Also the user can optionally setup:
1088
1089*   ``SGW_LCORE``: lcore to run ipsec-secgw on (default value is 0)
1090
1091*   ``CRYPTO_DEV``: crypto device to be used ('-a <pci-id>'). If none specified
1092    appropriate vdevs will be created by the script
1093
1094Scripts can be used for multiple test scenarios. To check all available
1095options run:
1096
1097.. code-block:: console
1098
1099    /bin/bash run_test.sh -h
1100
1101Note that most of the tests require the appropriate crypto PMD/device to be
1102available.
1103
1104Server configuration
1105~~~~~~~~~~~~~~~~~~~~
1106
1107Two servers are required for the tests, SUT and DUT.
1108
1109Make sure the user from the SUT can ssh to the DUT without entering the password.
1110To enable this feature keys must be setup on the DUT.
1111
1112``ssh-keygen`` will make a private & public key pair on the SUT.
1113
1114``ssh-copy-id`` <user name>@<target host name> on the SUT will copy the public
1115key to the DUT. It will ask for credentials so that it can upload the public key.
1116
1117The SUT and DUT are connected through at least 2 NIC ports.
1118
1119One NIC port is expected to be managed by linux on both machines and will be
1120used as a control path.
1121
1122The second NIC port (test-port) should be bound to DPDK on the SUT, and should
1123be managed by linux on the DUT.
1124
1125The script starts ``ipsec-secgw`` with 2 NIC devices: ``test-port`` and
1126``tap vdev``.
1127
1128It then configures the local tap interface and the remote interface and IPsec
1129policies in the following way:
1130
1131Traffic going over the test-port in both directions has to be protected by IPsec.
1132
1133Traffic going over the TAP port in both directions does not have to be protected.
1134
1135i.e:
1136
1137DUT OS(NIC1)--(IPsec)-->(NIC1)ipsec-secgw(TAP)--(plain)-->(TAP)SUT OS
1138
1139SUT OS(TAP)--(plain)-->(TAP)psec-secgw(NIC1)--(IPsec)-->(NIC1)DUT OS
1140
1141It then tries to perform some data transfer using the scheme described above.
1142
1143Usage
1144~~~~~
1145
1146In the ipsec-secgw/test directory run
1147
1148/bin/bash run_test.sh <options> <ipsec_mode>
1149
1150Available options:
1151
1152*   ``-4`` Perform tests with use of IPv4. One or both [-46] options needs to be
1153    selected.
1154
1155*   ``-6`` Perform tests with use of IPv6. One or both [-46] options needs to be
1156    selected.
1157
1158*   ``-m`` Add IPSec tunnel mixed IP version tests - outer IP version different
1159    than inner. Inner IP version will match selected option [-46].
1160
1161*   ``-i`` Run tests in inline mode. Regular tests will not be invoked.
1162
1163*   ``-f`` Run tests for fallback mechanism. Regular tests will not be invoked.
1164
1165*   ``-l`` Run tests in legacy mode only. It cannot be used with options [-fsc].
1166    On default library mode is used.
1167
1168*   ``-s`` Run all tests with reassembly support. On default only tests for
1169    fallback mechanism use reassembly support.
1170
1171*   ``-c`` Run tests with use of cpu-crypto. For inline tests it will not be
1172    applied. On default lookaside-none is used.
1173
1174*   ``-p`` Perform packet validation tests. Option [-46] is not required.
1175
1176*   ``-h`` Show usage.
1177
1178If <ipsec_mode> is specified, only tests for that mode will be invoked. For the
1179list of available modes please refer to run_test.sh.
1180