diff mbox

[2/2] enhance odp_pktio to set/get mtu

Message ID 1415729700-23420-2-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Nov. 11, 2014, 6:15 p.m. UTC
Add new option -t or --mtu to set up new mtu value.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 example/packet/odp_pktio.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index 2cf3f0d..04cfa5f 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -69,6 +69,7 @@  typedef struct {
 	char **if_names;	/**< Array of pointers to interface names */
 	int mode;		/**< Packet IO mode */
 	odp_buffer_pool_t pool;	/**< Buffer pool for packet IO */
+	unsigned int mtu;	/**< Pktio dev MTU */
 } appl_args_t;
 
 /**
@@ -78,6 +79,7 @@  typedef struct {
 	char *pktio_dev;	/**< Interface name to use */
 	odp_buffer_pool_t pool;	/**< Buffer pool for packet IO */
 	int mode;		/**< Thread mode */
+	unsigned int mtu;	/**< Pktio dev MTU */
 } thread_args_t;
 
 /**
@@ -120,6 +122,7 @@  static void *pktio_queue_thread(void *arg)
 	int ret;
 	unsigned long pkt_cnt = 0;
 	unsigned long err_cnt = 0;
+	unsigned int mtu = 0;
 
 	thr = odp_thread_id();
 	thr_args = arg;
@@ -141,6 +144,21 @@  static void *pktio_queue_thread(void *arg)
 		return NULL;
 	}
 
+	/* Change mtu if requested */
+	if (thr_args->mtu) {
+		ret = odp_pktio_set_mtu(pktio, thr_args->mtu);
+		if (ret != 0)
+			ODP_ERR("setting MTU to %d failed\n",
+				thr_args->mtu);
+	}
+
+	ret = odp_pktio_mtu(pktio, &mtu);
+	if (!ret)
+		printf("PKTIO: %d, dev %s, MTU: %d\n",
+		       pktio, thr_args->pktio_dev, mtu);
+	else
+		ODP_ERR("odp_pktio_mtu: unable to get mtu\n");
+
 	/*
 	 * Create and set the default INPUT queue associated with the 'pktio'
 	 * resource
@@ -229,6 +247,8 @@  static void *pktio_ifburst_thread(void *arg)
 	unsigned long pkt_cnt = 0;
 	unsigned long err_cnt = 0;
 	unsigned long tmp = 0;
+	unsigned int mtu = 0;
+	int ret;
 
 	thr = odp_thread_id();
 	thr_args = arg;
@@ -250,6 +270,21 @@  static void *pktio_ifburst_thread(void *arg)
 		return NULL;
 	}
 
+	/* Change mtu if requested */
+	if (thr_args->mtu) {
+		ret = odp_pktio_set_mtu(pktio, thr_args->mtu);
+		if (ret != 0)
+			ODP_ERR("setting MTU to %d failed\n",
+				thr_args->mtu);
+	}
+
+	ret = odp_pktio_mtu(pktio, &mtu);
+	if (!ret)
+		printf("PKTIO: %d, dev %s, MTU: %d\n",
+		       pktio, thr_args->pktio_dev, mtu);
+	else
+		ODP_ERR("odp_pktio_mtu: unable to get mtu\n");
+
 	printf("  [%02i] created pktio:%02i, burst mode\n",
 	       thr, pktio);
 
@@ -384,6 +419,7 @@  int main(int argc, char *argv[])
 		args->thread[i].pktio_dev = args->appl.if_names[if_idx];
 		args->thread[i].pool = pool;
 		args->thread[i].mode = args->appl.mode;
+		args->thread[i].mtu = args->appl.mtu;
 
 		if (args->appl.mode == APPL_MODE_PKT_BURST)
 			thr_run_func = pktio_ifburst_thread;
@@ -492,14 +528,16 @@  static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
 		{"count", required_argument, NULL, 'c'},
 		{"interface", required_argument, NULL, 'i'},	/* return 'i' */
 		{"mode", required_argument, NULL, 'm'},		/* return 'm' */
+		{"mtu", required_argument, NULL, 't'},		/* return 't' */
 		{"help", no_argument, NULL, 'h'},		/* return 'h' */
 		{NULL, 0, NULL, 0}
 	};
 
 	appl_args->mode = -1; /* Invalid, must be changed by parsing */
+	appl_args->mtu = 0;
 
 	while (1) {
-		opt = getopt_long(argc, argv, "+c:i:m:h",
+		opt = getopt_long(argc, argv, "+c:i:m:t:h",
 				  longopts, &long_index);
 
 		if (opt == -1)
@@ -559,6 +597,9 @@  static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
 			else
 				appl_args->mode = APPL_MODE_PKT_QUEUE;
 			break;
+		case 't':
+			appl_args->mtu = atoi(optarg);
+			break;
 
 		case 'h':
 			usage(argv[0]);
@@ -629,6 +670,7 @@  static void usage(char *progname)
 	       "  -i, --interface Eth interfaces (comma-separated, no spaces)\n"
 	       "  -m, --mode      0: Burst send&receive packets (no queues)\n"
 	       "                  1: Send&receive packets through ODP queues.\n"
+	       "  -t, --mtu       MTU\n"
 	       "\n"
 	       "Optional OPTIONS\n"
 	       "  -c, --count <number> Core count.\n"