From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by dpdk.space (Postfix) with ESMTP id 91D22A0679
	for <public@inbox.dpdk.org>; Tue,  2 Apr 2019 22:39:23 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 641ED1B12A;
	Tue,  2 Apr 2019 22:39:16 +0200 (CEST)
Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com
 [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id E27471B11C
 for <dev@dpdk.org>; Tue,  2 Apr 2019 22:39:12 +0200 (CEST)
Received: by mail-pf1-f195.google.com with SMTP id 10so6953756pfo.5
 for <dev@dpdk.org>; Tue, 02 Apr 2019 13:39:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20150623.gappssmtp.com; s=20150623;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=HJtX5V5FJIwTW/kG6PNsptsquwc233N/A/cg4MNE6CA=;
 b=Y+wYFipTnpm0G2rn2njITnaxZKmSwltIW9nATFXrE256gcPDRGF9+jUVgqJacvla+N
 gjCy7Y9HmW9LvpuZkm9TcSdf9UH4yyVM/ZS8eBFjF0StuLZ8nm/LqLy4RBRxU46DMSGd
 pBO8c0NaGGNYzyCi5lYBmGdAx3m6Gqrc3OmpdXgQYOriMRpMqvkQOR9sjOTC7igbGcYd
 zCbsInWJEt/Epb2r3mYqqkdPE1hrEmr1ydFKL+4kW5hSITbvvZzrdelQQKR9i9U6QPVE
 PsLsJoUNzs2k1Nu12YrJDLEJDnViBuumru9d/HauL0dohtwPBaM7GJgrGmoVqliP6Sby
 eGbg==
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=HJtX5V5FJIwTW/kG6PNsptsquwc233N/A/cg4MNE6CA=;
 b=A7GaKRqvZ5JzvsxeMnQACZHpYDPG5Xw6LSaVC499GoudWCa5+MbGsV7f2Izo7ZQurM
 zZx1vIvS2gaXZJLOmgnjUuALWER/vBgwEO68vfaor5xmVl3Lx2n8GPAz3+qyj9qrcljN
 PIctf7mT74JbC+6W0n6kKG0+ku5kyBHvX6NR78g8Ofsiqu1ID0lAAw44rnRIP0NN+QsF
 4JSEc8REMbqUud0X0k3eNKtEa4v4xIQSoy+vEN0zrIhm8hfJkumkFonUMAXYzbP97EmY
 y2+NOOvd9sGOwjR4XxYNEyY6MOEoMzKB4946p1fGIXVnfVEfp7LBayAJKAKjwFN2KvdS
 mY1Q==
X-Gm-Message-State: APjAAAXimgNR2LxsKLC3F1t5okB/SPA/w6wB2WD0jzsy62L9LQkvgNfE
 FUXk8coImsojW21dL6RPxAwVOADA+qKPkA==
X-Google-Smtp-Source: APXvYqwN3Fz+Z2PRKAqVd9g7MtgEJwthiuH2BW1B24tgxCu6UbCiqFtJ3F9CflUA6BFEkH4jZubjog==
X-Received: by 2002:aa7:9193:: with SMTP id x19mr62292766pfa.108.1554237551676; 
 Tue, 02 Apr 2019 13:39:11 -0700 (PDT)
Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com.
 [204.195.22.127])
 by smtp.gmail.com with ESMTPSA id t64sm34191748pfa.86.2019.04.02.13.39.10
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Tue, 02 Apr 2019 13:39:10 -0700 (PDT)
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Date: Tue,  2 Apr 2019 13:39:05 -0700
Message-Id: <20190402203907.28679-2-stephen@networkplumber.org>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20190402203907.28679-1-stephen@networkplumber.org>
References: <20180618213557.15209-2-stephen@networkplumber.org>
 <20190402203907.28679-1-stephen@networkplumber.org>
Subject: [dpdk-dev] [PATCH v4 1/3] app/testpmd: add ability to set Tx IP and
	UDP parameters
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <20190402203905.ej3wyARhUk_L8zsxYsttv3Dn9lXMZR1X7Bs3g8i6vjg@z>

Use RFC 2544 standard values for Tx only test as default IP
address and port.  But let the user override those values on command line.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v4 - update documentation to be more precise
     support new tx-multi-flow addresses

 app/test-pmd/parameters.c             | 49 +++++++++++++++++++++++++++
 app/test-pmd/testpmd.h                |  6 ++++
 app/test-pmd/txonly.c                 | 22 +++++++-----
 doc/guides/testpmd_app_ug/run_app.rst | 12 ++++++-
 4 files changed, 79 insertions(+), 10 deletions(-)

diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c
index 7b6b60905dce..8b523a5c66ed 100644
--- a/app/test-pmd/parameters.c
+++ b/app/test-pmd/parameters.c
@@ -19,6 +19,7 @@
 #include <stdint.h>
 #include <unistd.h>
 #include <inttypes.h>
+#include <arpa/inet.h>
 
 #include <rte_common.h>
 #include <rte_byteorder.h>
@@ -65,6 +66,7 @@ usage(char* progname)
 #ifdef RTE_LIBRTE_CMDLINE
 	       "--eth-peers-configfile= | "
 	       "--eth-peer=X,M:M:M:M:M:M | "
+	       "--tx-ip=SRC,DST | --tx-udp=PORT | "
 #endif
 	       "--pkt-filter-mode= |"
 	       "--rss-ip | --rss-udp | "
@@ -645,6 +647,8 @@ launch_args_parse(int argc, char** argv)
 		{ "mlockall",			0, 0, 0 },
 		{ "no-mlockall",		0, 0, 0 },
 		{ "mp-alloc",			1, 0, 0 },
+		{ "tx-ip",			1, 0, 0 },
+		{ "tx-udp",			1, 0, 0 },
 		{ "noisy-tx-sw-buffer-size",	1, 0, 0 },
 		{ "noisy-tx-sw-buffer-flushtime", 1, 0, 0 },
 		{ "noisy-lkup-memory",		1, 0, 0 },
@@ -743,6 +747,51 @@ launch_args_parse(int argc, char** argv)
 				nb_peer_eth_addrs++;
 			}
 #endif
+			if (!strcmp(lgopts[opt_idx].name, "tx-ip")) {
+				struct in_addr in;
+				char *end;
+
+				end = strchr(optarg, ',');
+				if (end == optarg || !end)
+					rte_exit(EXIT_FAILURE,
+						 "Invalid tx-ip: %s", optarg);
+
+				*end++ = 0;
+				if (inet_aton(optarg, &in) == 0)
+					rte_exit(EXIT_FAILURE,
+						 "Invalid source IP address: %s\n", optarg);
+				tx_ip_src_addr = rte_be_to_cpu_32(in.s_addr);
+
+				if (inet_aton(end, &in) == 0)
+					rte_exit(EXIT_FAILURE,
+						 "Invalid destination IP address: %s\n", optarg);
+				tx_ip_dst_addr = rte_be_to_cpu_32(in.s_addr);
+			}
+			if (!strcmp(lgopts[opt_idx].name, "tx-udp")) {
+				char *end = NULL;
+
+				errno = 0;
+				n = strtoul(optarg, &end, 10);
+				if (errno != 0 || end == optarg || n > UINT16_MAX ||
+				    !(*end == '\0' || *end == ','))
+					rte_exit(EXIT_FAILURE,
+						 "Invalid UDP port: %s\n", optarg);
+				tx_udp_src_port = n;
+				if (*end == ',') {
+					char *dst = end + 1;
+
+					n = strtoul(dst, &end, 10);
+					if (errno != 0 || end == dst ||
+					    n > UINT16_MAX || *end)
+						rte_exit(EXIT_FAILURE,
+							 "Invalid destination UDP port: %s\n",
+							 dst);
+					tx_udp_dst_port = n;
+				} else {
+					tx_udp_dst_port = n;
+				}
+
+			}
 			if (!strcmp(lgopts[opt_idx].name, "nb-ports")) {
 				n = atoi(optarg);
 				if (n > 0 && n <= nb_ports)
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index a45988ebc524..18d2c1ef1eaf 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -443,6 +443,12 @@ extern int8_t tx_pthresh;
 extern int8_t tx_hthresh;
 extern int8_t tx_wthresh;
 
+extern uint16_t tx_udp_src_port;
+extern uint16_t tx_udp_dst_port;
+
+extern uint32_t tx_ip_src_addr;
+extern uint32_t tx_ip_dst_addr;
+
 extern struct fwd_config cur_fwd_config;
 extern struct fwd_engine *cur_fwd_eng;
 extern uint32_t retry_enabled;
diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index def52a0487ea..ed5e715ea648 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -40,11 +40,13 @@
 
 #include "testpmd.h"
 
-#define UDP_SRC_PORT 1024
-#define UDP_DST_PORT 1024
+/* use RFC863 Discard Protocol */
+uint16_t tx_udp_src_port = 9;
+uint16_t tx_udp_dst_port = 9;
 
-#define IP_SRC_ADDR ((192U << 24) | (168 << 16) | (0 << 8) | 1)
-#define IP_DST_ADDR ((192U << 24) | (168 << 16) | (0 << 8) | 2)
+/* use RFC5735 / RFC2544 reserved network test addresses */
+uint32_t tx_ip_src_addr = (192U << 24) | (18 << 16) | (0 << 8) | 1;
+uint32_t tx_ip_dst_addr = (192U << 24) | (18 << 16) | (0 << 8) | 2;
 
 #define IP_DEFTTL  64   /* from RFC 1340. */
 #define IP_VERSION 0x40
@@ -105,8 +107,8 @@ setup_pkt_udp_ip_headers(struct ipv4_hdr *ip_hdr,
 	 * Initialize UDP header.
 	 */
 	pkt_len = (uint16_t) (pkt_data_len + sizeof(struct udp_hdr));
-	udp_hdr->src_port = rte_cpu_to_be_16(UDP_SRC_PORT);
-	udp_hdr->dst_port = rte_cpu_to_be_16(UDP_DST_PORT);
+	udp_hdr->src_port = rte_cpu_to_be_16(tx_udp_src_port);
+	udp_hdr->dst_port = rte_cpu_to_be_16(tx_udp_dst_port);
 	udp_hdr->dgram_len      = RTE_CPU_TO_BE_16(pkt_len);
 	udp_hdr->dgram_cksum    = 0; /* No UDP checksum. */
 
@@ -121,8 +123,8 @@ setup_pkt_udp_ip_headers(struct ipv4_hdr *ip_hdr,
 	ip_hdr->next_proto_id = IPPROTO_UDP;
 	ip_hdr->packet_id = 0;
 	ip_hdr->total_length   = RTE_CPU_TO_BE_16(pkt_len);
-	ip_hdr->src_addr = rte_cpu_to_be_32(IP_SRC_ADDR);
-	ip_hdr->dst_addr = rte_cpu_to_be_32(IP_DST_ADDR);
+	ip_hdr->src_addr = rte_cpu_to_be_32(tx_ip_src_addr);
+	ip_hdr->dst_addr = rte_cpu_to_be_32(tx_ip_dst_addr);
 
 	/*
 	 * Compute IP header checksum.
@@ -253,7 +255,9 @@ pkt_burst_transmit(struct fwd_stream *fs)
 			 * packet generator for developer's quick performance
 			 * regression test.
 			 */
-			addr = (IP_DST_ADDR | (ip_var++ << 8)) + rte_lcore_id();
+			addr = (tx_ip_dst_addr | (ip_var++ << 8))
+				+ rte_lcore_id();
+
 			ip_hdr->src_addr = rte_cpu_to_be_32(addr);
 		}
 		copy_buf_to_pkt(&pkt_udp_hdr, sizeof(pkt_udp_hdr), pkt,
diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst
index b717b8c7b742..a72f94923210 100644
--- a/doc/guides/testpmd_app_ug/run_app.rst
+++ b/doc/guides/testpmd_app_ug/run_app.rst
@@ -121,12 +121,22 @@ The commandline options are:
        XX:XX:XX:XX:XX:02
        ...
 
-
 *   ``--eth-peer=N,XX:XX:XX:XX:XX:XX``
 
     Set the MAC address ``XX:XX:XX:XX:XX:XX`` of the peer port N,
     where 0 <= N < ``CONFIG_RTE_MAX_ETHPORTS`` from the configuration file.
 
+*   ``--tx-ip=SRC,DST``
+    Set the source and destination IP address used when doing transmit only test.
+    The defaults address values are source 192.18.0.1 and
+    destination 192.18.0.2. These are special purpose addresses
+    reserved for benchmakring (RFC 2544).
+
+*   ``--tx-udp=SRC[,DST]``
+    Set the source and destination UDP port number for transmit test only test.
+    The default port is the port 9 which is defined for the discard protocol
+    (RFC 863).
+
 *   ``--pkt-filter-mode=mode``
 
     Set Flow Director mode where mode is either ``none`` (the default), ``signature`` or ``perfect``.
-- 
2.17.1