Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH 1/7] spp_nfv: change type of port_id to uint16_t
@ 2017-12-06  8:18 ogawa.yasufumi
  2017-12-06  8:18 ` [spp] [PATCH 2/7] spp_vm: " ogawa.yasufumi
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: ogawa.yasufumi @ 2017-12-06  8:18 UTC (permalink / raw)
  To: spp; +Cc: ferruh.yigit, ogawa.yasufumi, gerald.rogers, sy.jong.choi

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

In SPP, type of port_id is int while it is changed from uint8_t to
uint16_t in DPDK 17.11. It causes compile errors for incompatible
pointer type.

In addition, SPP expects negative value of port_id if it is
unassigned or invalid case. It is also a problem because comparing
uint16_t with negative value is not allowed.

This update is to change type of port_id and its validation. PORT_RESET
used for unassigned ports is changed from -99 to UINT16_MAX to avoid
negative value.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/nfv/nfv.c       | 14 +++++++-------
 src/shared/common.h | 11 ++++++-----
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c
index fc9ad1e..4bd9f6d 100644
--- a/src/nfv/nfv.c
+++ b/src/nfv/nfv.c
@@ -120,10 +120,10 @@ forward(void)
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
 		struct rte_mbuf *bufs[MAX_PKT_BURST];
 
-		if (ports_fwd_array[i].in_port_id < 0)
+		if (ports_fwd_array[i].in_port_id == PORT_RESET)
 			continue;
 
-		if (ports_fwd_array[i].out_port_id < 0)
+		if (ports_fwd_array[i].out_port_id == PORT_RESET)
 			continue;
 
 		/* if status active, i count is in port*/
@@ -223,7 +223,7 @@ forward_array_reset(void)
 
 	/* initialize port forward array*/
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-		if (ports_fwd_array[i].in_port_id > -1) {
+		if (ports_fwd_array[i].in_port_id != PORT_RESET) {
 			ports_fwd_array[i].out_port_id = PORT_RESET;
 			RTE_LOG(INFO, APP, "Port ID %d\n", i);
 			RTE_LOG(INFO, APP, "out_port_id %d\n",
@@ -242,7 +242,7 @@ print_active_ports(char *str)
 
 	/* every elements value*/
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-		if (ports_fwd_array[i].in_port_id < 0)
+		if (ports_fwd_array[i].in_port_id == PORT_RESET)
 			continue;
 
 		RTE_LOG(INFO, APP, "Port ID %d\n", i);
@@ -250,7 +250,7 @@ print_active_ports(char *str)
 			ports_fwd_array[i].in_port_id);
 
 		sprintf(str + strlen(str), "port id: %d,", i);
-		if (ports_fwd_array[i].in_port_id >= 0)
+		if (ports_fwd_array[i].in_port_id != PORT_RESET)
 			sprintf(str + strlen(str), "on,");
 		else
 			sprintf(str + strlen(str), "off,");
@@ -309,7 +309,7 @@ forward_array_remove(int port_id)
 	forward_array_init_one(port_id);
 
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-		if (ports_fwd_array[i].in_port_id < 0)
+		if (ports_fwd_array[i].in_port_id == PORT_RESET)
 			continue;
 
 		if (ports_fwd_array[i].out_port_id == port_id) {
@@ -439,7 +439,7 @@ add_vhost_pmd(int index)
 		.rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN }
 	};
 	struct rte_mempool *mp;
-	uint8_t vhost_port_id;
+	uint16_t vhost_port_id;
 	int nr_queues = 1;
 	const char *name;
 	char devargs[64];
diff --git a/src/shared/common.h b/src/shared/common.h
index 6ae4ac9..27138bd 100644
--- a/src/shared/common.h
+++ b/src/shared/common.h
@@ -41,6 +41,7 @@
 #include <string.h>
 #include <sys/socket.h>
 #include <unistd.h>
+#include <limits.h>
 
 #include <rte_branch_prediction.h>
 #include <rte_common.h>
@@ -57,7 +58,7 @@
 #define MAX_CLIENT  99
 #define MSG_SIZE    1000
 #define SOCK_RESET  -1
-#define PORT_RESET  -99
+#define PORT_RESET  UINT16_MAX
 
 /*
  * When doing reads from the NIC or the client queues,
@@ -128,10 +129,10 @@ struct port_map {
 };
 
 struct port {
-	int in_port_id;
-	int out_port_id;
-	uint16_t (*rx_func)(uint8_t, uint16_t, struct rte_mbuf **, uint16_t);
-	uint16_t (*tx_func)(uint8_t, uint16_t, struct rte_mbuf **, uint16_t);
+	uint16_t in_port_id;
+	uint16_t out_port_id;
+	uint16_t (*rx_func)(uint16_t, uint16_t, struct rte_mbuf **, uint16_t);
+	uint16_t (*tx_func)(uint16_t, uint16_t, struct rte_mbuf **, uint16_t);
 };
 
 /* define common names for structures shared between server and client */
-- 
2.13.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-12-07 18:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-06  8:18 [spp] [PATCH 1/7] spp_nfv: change type of port_id to uint16_t ogawa.yasufumi
2017-12-06  8:18 ` [spp] [PATCH 2/7] spp_vm: " ogawa.yasufumi
2017-12-06  8:18 ` [spp] [PATCH 3/7] spp_primary: change type of ports_id " ogawa.yasufumi
2017-12-06  8:18 ` [spp] [PATCH 4/7] spp_vm: " ogawa.yasufumi
2017-12-06  8:18 ` [spp] [PATCH 5/7] spp/shared: " ogawa.yasufumi
2017-12-06  8:18 ` [spp] [PATCH 6/7] spp: change type of counter " ogawa.yasufumi
2017-12-06  8:18 ` [spp] [PATCH 7/7] spp/shared: refactor printing port status ogawa.yasufumi
2017-12-07 18:08 ` [spp] [PATCH 1/7] spp_nfv: change type of port_id to uint16_t Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).