[RFC] app/testpmd: add generic swap forwarding engine

Message ID 47cf5b417fb3c74c04e5a020dba700c5d748383d.1586958002.git.jackmin@mellanox.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series [RFC] app/testpmd: add generic swap forwarding engine |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation fail Compilation issues

Commit Message

Xiaoyu Min April 15, 2020, 1:48 p.m. UTC
  This RFC propose a generic `swap` forwarding engine, which could be seen
as an extension of existing `macswap` but provide more flexibility.

With this generic `swap` forwarding engine, we can `swap` the source and
destination of L2/L3 address as well as the source and destination port
of L4 according to the user inputs.

This will be very helpful for developer/tester in some test scenarios.
For example, connection tracking functinality in OVS, which needs to
swap UDP ports in addition to L2/L3 addresses in order to complete one
connection.

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
 app/test-pmd/parameters.c                   |  2 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 ++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
  

Comments

Iremonger, Bernard April 21, 2020, 3:47 p.m. UTC | #1
Hi Xiaoyu,

> -----Original Message-----
> From: Xiaoyu Min <jackmin@mellanox.com>
> Sent: Wednesday, April 15, 2020 2:49 PM
> To: thomas@monjalon.net; asafp@mellanox.com; Lu, Wenzhuo
> <wenzhuo.lu@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>; Iremonger,
> Bernard <bernard.iremonger@intel.com>; Mcnamara, John
> <john.mcnamara@intel.com>; Kovacevic, Marko
> <marko.kovacevic@intel.com>
> Cc: dev@dpdk.org
> Subject: [RFC] app/testpmd: add generic swap forwarding engine
> 
> This RFC propose a generic `swap` forwarding engine, which could be seen as
> an extension of existing `macswap` but provide more flexibility.
> 
> With this generic `swap` forwarding engine, we can `swap` the source and
> destination of L2/L3 address as well as the source and destination port of L4
> according to the user inputs.
> 
> This will be very helpful for developer/tester in some test scenarios.
> For example, connection tracking functinality in OVS, which needs to swap
> UDP ports in addition to L2/L3 addresses in order to complete one
> connection.
> 
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---
>  app/test-pmd/parameters.c                   |  2 ++
>  doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 ++++++++++++++-
>  2 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index
> 404dba2b20..5c9aecd6cb 100644
> --- a/app/test-pmd/parameters.c
> +++ b/app/test-pmd/parameters.c
> @@ -147,6 +147,8 @@ usage(char* progname)
>  	       "is default).\n");
>  	printf("  --forward-mode=N: set forwarding mode (N: %s).\n",
>  	       list_pkt_forwarding_modes());
> +	printf("  --forward-mode=swap[:TYPE[,TYPE]]: set forwarding mode
> to swap "
> +	       "(TYPE: auto (default) or mac or ip or tp).\n");
>  	printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
>  	printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
>  	printf("  --rxq=N: set the number of RX queues per port to N.\n");
> diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> index dcee5de455..27f0600493 100644
> --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> @@ -298,7 +298,7 @@ set fwd
>  Set the packet forwarding mode::
> 
>     testpmd> set fwd (io|mac|macswap|flowgen| \
> -                     rxonly|txonly|csum|icmpecho|noisy) (""|retry)
> +                     rxonly|txonly|csum|icmpecho|noisy|swap) (""|retry)
> 
>  ``retry`` can be specified for forwarding engines except ``rx_only``.
> 
> @@ -336,6 +336,19 @@ The available information categories are:
>    Simulate more realistic behavior of a guest machine engaged in receiving
>    and sending packets performing Virtual Network Function (VNF).
> 
> +* ``swap[:TYPE[,TYPE]*]``: Generic swap forwarding mode.
> +
> +  Swap the source and destination address or/and source and destination
> port of packet according to ``TYPE`` before forwarding them.
> +  ``TYPE`` could be:
> +
> +  - ``auto``: swaps all supported fields (L2 to L4) if available, default.
> +
> +  - ``mac``: swaps the source address and destination address of Ethernet, as
> same as ``macswap``.
> +
> +  - ``ip``: swaps the source address and destination address of IP (v4 and v6).
> +
> +  - ``tp``: swaps the source port and destination port of transport layer (TCP
> and UDP).
> +
>  Example::
> 
>     testpmd> set fwd rxonly
> --
> 2.26.0

This patch is giving the following checkpatch errors:

root@silpixa00399470:~/dpdk-next-net# /root/dpdk-next-net/devtools/checkpatches.sh /home/bairemon/patches_20_05_patchwork/RFC-app-testpmd-add-generic-swap-forwarding-engine
.patch

### [dpdk-dev] [RFC] app/testpmd: add generic swap forwarding engine

ERROR:TRAILING_WHITESPACE: trailing whitespace
#97: FILE: doc/guides/testpmd_app_ug/testpmd_funcs.rst:340:
+ $

ERROR:TRAILING_WHITESPACE: trailing whitespace
#102: FILE: doc/guides/testpmd_app_ug/testpmd_funcs.rst:345:
+ $

ERROR:TRAILING_WHITESPACE: trailing whitespace
#104: FILE: doc/guides/testpmd_app_ug/testpmd_funcs.rst:347:
+ $

ERROR:TRAILING_WHITESPACE: trailing whitespace
#106: FILE: doc/guides/testpmd_app_ug/testpmd_funcs.rst:349:
+ $

total: 4 errors, 0 warnings, 35 lines checked


This seems to be just a documentation patch.
I don't see any code to implement the new forwarding feature.

Regards,

Bernard.
  
Ferruh Yigit April 21, 2020, 8:56 p.m. UTC | #2
On 4/15/2020 2:48 PM, Xiaoyu Min wrote:
> This RFC propose a generic `swap` forwarding engine, which could be seen
> as an extension of existing `macswap` but provide more flexibility.
> 
> With this generic `swap` forwarding engine, we can `swap` the source and
> destination of L2/L3 address as well as the source and destination port
> of L4 according to the user inputs.
> 
> This will be very helpful for developer/tester in some test scenarios.
> For example, connection tracking functinality in OVS, which needs to
> swap UDP ports in addition to L2/L3 addresses in order to complete one
> connection.

Why not, if this will be an additional forwarding engine, I am OK with it. It
increases the testpmd capabilities.

> 
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---
>  app/test-pmd/parameters.c                   |  2 ++
>  doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 ++++++++++++++-
>  2 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
> index 404dba2b20..5c9aecd6cb 100644
> --- a/app/test-pmd/parameters.c
> +++ b/app/test-pmd/parameters.c
> @@ -147,6 +147,8 @@ usage(char* progname)
>  	       "is default).\n");
>  	printf("  --forward-mode=N: set forwarding mode (N: %s).\n",
>  	       list_pkt_forwarding_modes());
> +	printf("  --forward-mode=swap[:TYPE[,TYPE]]: set forwarding mode to swap "
> +	       "(TYPE: auto (default) or mac or ip or tp).\n");
>  	printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
>  	printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
>  	printf("  --rxq=N: set the number of RX queues per port to N.\n");
> diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> index dcee5de455..27f0600493 100644
> --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> @@ -298,7 +298,7 @@ set fwd
>  Set the packet forwarding mode::
>  
>     testpmd> set fwd (io|mac|macswap|flowgen| \
> -                     rxonly|txonly|csum|icmpecho|noisy) (""|retry)
> +                     rxonly|txonly|csum|icmpecho|noisy|swap) (""|retry)
>  
>  ``retry`` can be specified for forwarding engines except ``rx_only``.
>  
> @@ -336,6 +336,19 @@ The available information categories are:
>    Simulate more realistic behavior of a guest machine engaged in receiving
>    and sending packets performing Virtual Network Function (VNF).
>  
> +* ``swap[:TYPE[,TYPE]*]``: Generic swap forwarding mode.
> + 
> +  Swap the source and destination address or/and source and destination port of packet according to ``TYPE`` before forwarding them.
> +  ``TYPE`` could be:
> +
> +  - ``auto``: swaps all supported fields (L2 to L4) if available, default.
> + 
> +  - ``mac``: swaps the source address and destination address of Ethernet, as same as ``macswap``.
> + 
> +  - ``ip``: swaps the source address and destination address of IP (v4 and v6).
> + 
> +  - ``tp``: swaps the source port and destination port of transport layer (TCP and UDP).
> +
>  Example::
>  
>     testpmd> set fwd rxonly
>
  
Xiaoyu Min April 22, 2020, 2:12 a.m. UTC | #3
On Tue, 20-04-21, 15:47, Iremonger, Bernard wrote:
> Hi Xiaoyu,
Hey Bernard,

> 
> > -----Original Message-----
> > From: Xiaoyu Min <jackmin@mellanox.com>
> > Sent: Wednesday, April 15, 2020 2:49 PM
> > To: thomas@monjalon.net; asafp@mellanox.com; Lu, Wenzhuo
> > <wenzhuo.lu@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>; Iremonger,
> > Bernard <bernard.iremonger@intel.com>; Mcnamara, John
> > <john.mcnamara@intel.com>; Kovacevic, Marko
> > <marko.kovacevic@intel.com>
> > Cc: dev@dpdk.org
> > Subject: [RFC] app/testpmd: add generic swap forwarding engine
> > 
> > This RFC propose a generic `swap` forwarding engine, which could be seen as
> > an extension of existing `macswap` but provide more flexibility.
> > 
> > With this generic `swap` forwarding engine, we can `swap` the source and
> > destination of L2/L3 address as well as the source and destination port of L4
> > according to the user inputs.
> > 
> > This will be very helpful for developer/tester in some test scenarios.
> > For example, connection tracking functinality in OVS, which needs to swap
> > UDP ports in addition to L2/L3 addresses in order to complete one
> > connection.
> > 
> > Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> > ---
> >  app/test-pmd/parameters.c                   |  2 ++
> >  doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 ++++++++++++++-
> >  2 files changed, 16 insertions(+), 1 deletion(-)
> > 
> > diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index
> > 404dba2b20..5c9aecd6cb 100644
> > --- a/app/test-pmd/parameters.c
> > +++ b/app/test-pmd/parameters.c
> > @@ -147,6 +147,8 @@ usage(char* progname)
> >  	       "is default).\n");
> >  	printf("  --forward-mode=N: set forwarding mode (N: %s).\n",
> >  	       list_pkt_forwarding_modes());
> > +	printf("  --forward-mode=swap[:TYPE[,TYPE]]: set forwarding mode
> > to swap "
> > +	       "(TYPE: auto (default) or mac or ip or tp).\n");
> >  	printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
> >  	printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
> >  	printf("  --rxq=N: set the number of RX queues per port to N.\n");
> > diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > index dcee5de455..27f0600493 100644
> > --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > @@ -298,7 +298,7 @@ set fwd
> >  Set the packet forwarding mode::
> > 
> >     testpmd> set fwd (io|mac|macswap|flowgen| \
> > -                     rxonly|txonly|csum|icmpecho|noisy) (""|retry)
> > +                     rxonly|txonly|csum|icmpecho|noisy|swap) (""|retry)
> > 
> >  ``retry`` can be specified for forwarding engines except ``rx_only``.
> > 
> > @@ -336,6 +336,19 @@ The available information categories are:
> >    Simulate more realistic behavior of a guest machine engaged in receiving
> >    and sending packets performing Virtual Network Function (VNF).
> > 
> > +* ``swap[:TYPE[,TYPE]*]``: Generic swap forwarding mode.
> > +
> > +  Swap the source and destination address or/and source and destination
> > port of packet according to ``TYPE`` before forwarding them.
> > +  ``TYPE`` could be:
> > +
> > +  - ``auto``: swaps all supported fields (L2 to L4) if available, default.
> > +
> > +  - ``mac``: swaps the source address and destination address of Ethernet, as
> > same as ``macswap``.
> > +
> > +  - ``ip``: swaps the source address and destination address of IP (v4 and v6).
> > +
> > +  - ``tp``: swaps the source port and destination port of transport layer (TCP
> > and UDP).
> > +
> >  Example::
> > 
> >     testpmd> set fwd rxonly
> > --
> > 2.26.0
> 
> This patch is giving the following checkpatch errors:
Sorry, I missed them. I'll fix this in PATCH.

> 
> root@silpixa00399470:~/dpdk-next-net# /root/dpdk-next-net/devtools/checkpatches.sh /home/bairemon/patches_20_05_patchwork/RFC-app-testpmd-add-generic-swap-forwarding-engine
> .patch
> 
> ### [dpdk-dev] [RFC] app/testpmd: add generic swap forwarding engine
> 
> ERROR:TRAILING_WHITESPACE: trailing whitespace
> #97: FILE: doc/guides/testpmd_app_ug/testpmd_funcs.rst:340:
> + $
> 
> ERROR:TRAILING_WHITESPACE: trailing whitespace
> #102: FILE: doc/guides/testpmd_app_ug/testpmd_funcs.rst:345:
> + $
> 
> ERROR:TRAILING_WHITESPACE: trailing whitespace
> #104: FILE: doc/guides/testpmd_app_ug/testpmd_funcs.rst:347:
> + $
> 
> ERROR:TRAILING_WHITESPACE: trailing whitespace
> #106: FILE: doc/guides/testpmd_app_ug/testpmd_funcs.rst:349:
> + $
> 
> total: 4 errors, 0 warnings, 35 lines checked
> 
> 
> This seems to be just a documentation patch.
> I don't see any code to implement the new forwarding feature.
Yes, it's RFC so I just update the related documentation to describe the idea.
The complete code implementation will be a comming PATCH if community is OK
with this RFC.

> 
> Regards,
> 
> Bernard.
> 
>
  
Xiaoyu Min April 22, 2020, 2:15 a.m. UTC | #4
On Tue, 20-04-21, 21:56, Ferruh Yigit wrote:
> On 4/15/2020 2:48 PM, Xiaoyu Min wrote:
> > This RFC propose a generic `swap` forwarding engine, which could be seen
> > as an extension of existing `macswap` but provide more flexibility.
> > 
> > With this generic `swap` forwarding engine, we can `swap` the source and
> > destination of L2/L3 address as well as the source and destination port
> > of L4 according to the user inputs.
> > 
> > This will be very helpful for developer/tester in some test scenarios.
> > For example, connection tracking functinality in OVS, which needs to
> > swap UDP ports in addition to L2/L3 addresses in order to complete one
> > connection.
> 
> Why not, if this will be an additional forwarding engine, I am OK with it. It
> increases the testpmd capabilities.
Yes, it increases the capabilities.

> 
> > 
> > Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> > ---
> >  app/test-pmd/parameters.c                   |  2 ++
> >  doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 ++++++++++++++-
> >  2 files changed, 16 insertions(+), 1 deletion(-)
> > 
> > diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
> > index 404dba2b20..5c9aecd6cb 100644
> > --- a/app/test-pmd/parameters.c
> > +++ b/app/test-pmd/parameters.c
> > @@ -147,6 +147,8 @@ usage(char* progname)
> >  	       "is default).\n");
> >  	printf("  --forward-mode=N: set forwarding mode (N: %s).\n",
> >  	       list_pkt_forwarding_modes());
> > +	printf("  --forward-mode=swap[:TYPE[,TYPE]]: set forwarding mode to swap "
> > +	       "(TYPE: auto (default) or mac or ip or tp).\n");
> >  	printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
> >  	printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
> >  	printf("  --rxq=N: set the number of RX queues per port to N.\n");
> > diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > index dcee5de455..27f0600493 100644
> > --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > @@ -298,7 +298,7 @@ set fwd
> >  Set the packet forwarding mode::
> >  
> >     testpmd> set fwd (io|mac|macswap|flowgen| \
> > -                     rxonly|txonly|csum|icmpecho|noisy) (""|retry)
> > +                     rxonly|txonly|csum|icmpecho|noisy|swap) (""|retry)
> >  
> >  ``retry`` can be specified for forwarding engines except ``rx_only``.
> >  
> > @@ -336,6 +336,19 @@ The available information categories are:
> >    Simulate more realistic behavior of a guest machine engaged in receiving
> >    and sending packets performing Virtual Network Function (VNF).
> >  
> > +* ``swap[:TYPE[,TYPE]*]``: Generic swap forwarding mode.
> > + 
> > +  Swap the source and destination address or/and source and destination port of packet according to ``TYPE`` before forwarding them.
> > +  ``TYPE`` could be:
> > +
> > +  - ``auto``: swaps all supported fields (L2 to L4) if available, default.
> > + 
> > +  - ``mac``: swaps the source address and destination address of Ethernet, as same as ``macswap``.
> > + 
> > +  - ``ip``: swaps the source address and destination address of IP (v4 and v6).
> > + 
> > +  - ``tp``: swaps the source port and destination port of transport layer (TCP and UDP).
> > +
> >  Example::
> >  
> >     testpmd> set fwd rxonly
> > 
>
  
Kevin Traynor April 22, 2020, 9:26 a.m. UTC | #5
On 15/04/2020 14:48, Xiaoyu Min wrote:
> This RFC propose a generic `swap` forwarding engine, which could be seen
> as an extension of existing `macswap` but provide more flexibility.
> 
> With this generic `swap` forwarding engine, we can `swap` the source and
> destination of L2/L3 address as well as the source and destination port
> of L4 according to the user inputs.
> 
> This will be very helpful for developer/tester in some test scenarios.
> For example, connection tracking functinality in OVS, which needs to
> swap UDP ports in addition to L2/L3 addresses in order to complete one
> connection.
> 
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---
>  app/test-pmd/parameters.c                   |  2 ++
>  doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 ++++++++++++++-
>  2 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
> index 404dba2b20..5c9aecd6cb 100644
> --- a/app/test-pmd/parameters.c
> +++ b/app/test-pmd/parameters.c
> @@ -147,6 +147,8 @@ usage(char* progname)
>  	       "is default).\n");
>  	printf("  --forward-mode=N: set forwarding mode (N: %s).\n",
>  	       list_pkt_forwarding_modes());
> +	printf("  --forward-mode=swap[:TYPE[,TYPE]]: set forwarding mode to swap "
> +	       "(TYPE: auto (default) or mac or ip or tp).\n");
>  	printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
>  	printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
>  	printf("  --rxq=N: set the number of RX queues per port to N.\n");
> diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> index dcee5de455..27f0600493 100644
> --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> @@ -298,7 +298,7 @@ set fwd
>  Set the packet forwarding mode::
>  
>     testpmd> set fwd (io|mac|macswap|flowgen| \
> -                     rxonly|txonly|csum|icmpecho|noisy) (""|retry)
> +                     rxonly|txonly|csum|icmpecho|noisy|swap) (""|retry)
>  
>  ``retry`` can be specified for forwarding engines except ``rx_only``.
>  
> @@ -336,6 +336,19 @@ The available information categories are:
>    Simulate more realistic behavior of a guest machine engaged in receiving
>    and sending packets performing Virtual Network Function (VNF).
>  
> +* ``swap[:TYPE[,TYPE]*]``: Generic swap forwarding mode.
> + 
> +  Swap the source and destination address or/and source and destination port of packet according to ``TYPE`` before forwarding them.
> +  ``TYPE`` could be:
> +
> +  - ``auto``: swaps all supported fields (L2 to L4) if available, default.

It's not an intuitive name and doesn't seem like it's really needed.
Selecting multiple items below is more explicit IMHO.

> + 
> +  - ``mac``: swaps the source address and destination address of Ethernet, as same as ``macswap``.
> + 
> +  - ``ip``: swaps the source address and destination address of IP (v4 and v6).
> + 
> +  - ``tp``: swaps the source port and destination port of transport layer (TCP and UDP).

I think 'port' would be clearer.

> +
>  Example::
>  
>     testpmd> set fwd rxonly
>
  
Xiaoyu Min April 22, 2020, 1:43 p.m. UTC | #6
On Wed, 20-04-22, 10:26, Kevin Traynor wrote:
> On 15/04/2020 14:48, Xiaoyu Min wrote:
> > This RFC propose a generic `swap` forwarding engine, which could be seen
> > as an extension of existing `macswap` but provide more flexibility.
> > 
> > With this generic `swap` forwarding engine, we can `swap` the source and
> > destination of L2/L3 address as well as the source and destination port
> > of L4 according to the user inputs.
> > 
> > This will be very helpful for developer/tester in some test scenarios.
> > For example, connection tracking functinality in OVS, which needs to
> > swap UDP ports in addition to L2/L3 addresses in order to complete one
> > connection.
> > 
> > Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> > ---
> >  app/test-pmd/parameters.c                   |  2 ++
> >  doc/guides/testpmd_app_ug/testpmd_funcs.rst | 15 ++++++++++++++-
> >  2 files changed, 16 insertions(+), 1 deletion(-)
> > 
> > diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
> > index 404dba2b20..5c9aecd6cb 100644
> > --- a/app/test-pmd/parameters.c
> > +++ b/app/test-pmd/parameters.c
> > @@ -147,6 +147,8 @@ usage(char* progname)
> >  	       "is default).\n");
> >  	printf("  --forward-mode=N: set forwarding mode (N: %s).\n",
> >  	       list_pkt_forwarding_modes());
> > +	printf("  --forward-mode=swap[:TYPE[,TYPE]]: set forwarding mode to swap "
> > +	       "(TYPE: auto (default) or mac or ip or tp).\n");
> >  	printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
> >  	printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
> >  	printf("  --rxq=N: set the number of RX queues per port to N.\n");
> > diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > index dcee5de455..27f0600493 100644
> > --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> > @@ -298,7 +298,7 @@ set fwd
> >  Set the packet forwarding mode::
> >  
> >     testpmd> set fwd (io|mac|macswap|flowgen| \
> > -                     rxonly|txonly|csum|icmpecho|noisy) (""|retry)
> > +                     rxonly|txonly|csum|icmpecho|noisy|swap) (""|retry)
> >  
> >  ``retry`` can be specified for forwarding engines except ``rx_only``.
> >  
> > @@ -336,6 +336,19 @@ The available information categories are:
> >    Simulate more realistic behavior of a guest machine engaged in receiving
> >    and sending packets performing Virtual Network Function (VNF).
> >  
> > +* ``swap[:TYPE[,TYPE]*]``: Generic swap forwarding mode.
> > + 
> > +  Swap the source and destination address or/and source and destination port of packet according to ``TYPE`` before forwarding them.
> > +  ``TYPE`` could be:
> > +
> > +  - ``auto``: swaps all supported fields (L2 to L4) if available, default.
> 
> It's not an intuitive name and doesn't seem like it's really needed.
> Selecting multiple items below is more explicit IMHO.
Yes, it's not really needed. I'll remove it.

> 
> > + 
> > +  - ``mac``: swaps the source address and destination address of Ethernet, as same as ``macswap``.
> > + 
> > +  - ``ip``: swaps the source address and destination address of IP (v4 and v6).
> > + 
> > +  - ``tp``: swaps the source port and destination port of transport layer (TCP and UDP).
> 
> I think 'port' would be clearer.
Yes, it's more clearer. I'll change it to 'port'.
Thank you.

> 
> > +
> >  Example::
> >  
> >     testpmd> set fwd rxonly
> > 
>
  

Patch

diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 404dba2b20..5c9aecd6cb 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -147,6 +147,8 @@  usage(char* progname)
 	       "is default).\n");
 	printf("  --forward-mode=N: set forwarding mode (N: %s).\n",
 	       list_pkt_forwarding_modes());
+	printf("  --forward-mode=swap[:TYPE[,TYPE]]: set forwarding mode to swap "
+	       "(TYPE: auto (default) or mac or ip or tp).\n");
 	printf("  --rss-ip: set RSS functions to IPv4/IPv6 only .\n");
 	printf("  --rss-udp: set RSS functions to IPv4/IPv6 + UDP.\n");
 	printf("  --rxq=N: set the number of RX queues per port to N.\n");
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index dcee5de455..27f0600493 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -298,7 +298,7 @@  set fwd
 Set the packet forwarding mode::
 
    testpmd> set fwd (io|mac|macswap|flowgen| \
-                     rxonly|txonly|csum|icmpecho|noisy) (""|retry)
+                     rxonly|txonly|csum|icmpecho|noisy|swap) (""|retry)
 
 ``retry`` can be specified for forwarding engines except ``rx_only``.
 
@@ -336,6 +336,19 @@  The available information categories are:
   Simulate more realistic behavior of a guest machine engaged in receiving
   and sending packets performing Virtual Network Function (VNF).
 
+* ``swap[:TYPE[,TYPE]*]``: Generic swap forwarding mode.
+ 
+  Swap the source and destination address or/and source and destination port of packet according to ``TYPE`` before forwarding them.
+  ``TYPE`` could be:
+
+  - ``auto``: swaps all supported fields (L2 to L4) if available, default.
+ 
+  - ``mac``: swaps the source address and destination address of Ethernet, as same as ``macswap``.
+ 
+  - ``ip``: swaps the source address and destination address of IP (v4 and v6).
+ 
+  - ``tp``: swaps the source port and destination port of transport layer (TCP and UDP).
+
 Example::
 
    testpmd> set fwd rxonly