Soft Patch Panel
 help / color / mirror / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 2/2] spp_primary: fix bug of add and del port
Date: Thu, 17 Oct 2019 21:58:22 +0900	[thread overview]
Message-ID: <20191017125822.29309-3-yasufum.o@gmail.com> (raw)
In-Reply-To: <20191017125822.29309-1-yasufum.o@gmail.com>

From: Yasufumi Ogawa <yasufum.o@gmail.com>

Added port cannot be referred because `port_fwd_array` is updated
appropriately, and same issue for deleted port. This patch is to fix
this issue by updating `port_fwd_array` in add_port() and del_port().

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/cli/commands/pri.py | 40 ++++++++++++++++++++--------------------
 src/nfv/commands.h      |  4 ++++
 src/primary/main.c      | 13 +++++++++++++
 3 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/src/cli/commands/pri.py b/src/cli/commands/pri.py
index 021f322..32c632c 100644
--- a/src/cli/commands/pri.py
+++ b/src/cli/commands/pri.py
@@ -61,7 +61,7 @@ class SppPrimary(object):
                     # Print default error message
                     pass
                 else:
-                    print('Error: unknown response.')
+                    print('Error: unknown response from status.')
 
         elif subcmd == 'add':
             self._run_add(params)
@@ -87,7 +87,7 @@ class SppPrimary(object):
                 elif res.status_code in common_err_codes:
                     pass
                 else:
-                    print('Error: unknown response.')
+                    print('Error: unknown response for clear.')
 
         else:
             print('Invalid pri command!')
@@ -102,7 +102,7 @@ class SppPrimary(object):
             elif res.status_code in error_codes:
                 pass
             else:
-                print('Error: unknown response.')
+                print('Error: unknown response for exit.')
 
     def print_status(self, json_obj):
         """Parse SPP primary's status and print.
@@ -219,15 +219,15 @@ class SppPrimary(object):
     def _get_ports(self):
         """Get all of ports as a list."""
 
-        res = self.spp_ctl_cli.get('primary')
+        res = self.spp_ctl_cli.get('primary/status')
         if res is not None:
             error_codes = self.spp_ctl_cli.rest_common_error_codes
             if res.status_code == 200:
-                return res.json()['ports']
+                return res.json()['forwarder']['ports']
             elif res.status_code in error_codes:
                 pass
             else:
-                print('Error: unknown response.')
+                print('Error: unknown response for get_ports.')
 
     def _get_patches(self):
         """Get all of patched ports as a list of dicts.
@@ -237,15 +237,15 @@ class SppPrimary(object):
            {'src': 'ring:1', 'dst':'vhost:1'}, ...]
         """
 
-        res = self.spp_ctl_cli.get('primary')
+        res = self.spp_ctl_cli.get('primary/status')
         if res is not None:
             error_codes = self.spp_ctl_cli.rest_common_error_codes
             if res.status_code == 200:
-                return res.json()['patches']
+                return res.json()['forwarder']['patches']
             elif res.status_code in error_codes:
                 pass
             else:
-                print('Error: unknown response.')
+                print('Error: unknown response for get_patches.')
 
     def _get_ports_and_patches(self):
         """Get all of ports and patchs at once.
@@ -256,17 +256,17 @@ class SppPrimary(object):
           ports, patches = _get_ports_and_patches()
         """
 
-        res = self.spp_ctl_cli.get('primary')
+        res = self.spp_ctl_cli.get('primary/status')
         if res is not None:
             error_codes = self.spp_ctl_cli.rest_common_error_codes
             if res.status_code == 200:
-                ports = res.json()['ports']
-                patches = res.json()['patches']
+                ports = res.json()['forwarder']['ports']
+                patches = res.json()['forwarder']['patches']
                 return ports, patches
             elif res.status_code in error_codes:
                 pass
             else:
-                print('Error: unknown response.')
+                print('Error: unknown response 3.')
 
     def _get_patched_ports(self):
         """Get all of patched ports as a list.
@@ -547,7 +547,7 @@ class SppPrimary(object):
                 # Print default error message
                 pass
             else:
-                print('Error: unknown response.')
+                print('Error: unknown response for _get_sec_ids.')
         return sec_ids
 
     def _setup_opts_dict(self, opts_list):
@@ -590,7 +590,7 @@ class SppPrimary(object):
                 elif res.status_code in error_codes:
                     pass
                 else:
-                    print('Error: unknown response.')
+                    print('Error: unknown response for add.')
 
     def _run_del(self, params):
         """Run `del` command."""
@@ -617,7 +617,7 @@ class SppPrimary(object):
                     elif res.status_code in error_codes:
                         pass
                     else:
-                        print('Error: unknown response.')
+                        print('Error: unknown response for del.')
 
     def _run_forward_or_stop(self, cmd):
         """Run `forward` or `stop` command."""
@@ -641,7 +641,7 @@ class SppPrimary(object):
             elif res.status_code in error_codes:
                 pass
             else:
-                print('Error: unknown response.')
+                print('Error: unknown response for forward/stop.')
 
     def _run_patch(self, params):
         """Run `patch` command."""
@@ -657,7 +657,7 @@ class SppPrimary(object):
                 elif res.status_code in error_codes:
                     pass
                 else:
-                    print('Error: unknown response.')
+                    print('Error: unknown response for patch.')
         else:
             if len(params) < 2:
                 print('Dst port is required!')
@@ -673,7 +673,7 @@ class SppPrimary(object):
                     elif res.status_code in error_codes:
                         pass
                     else:
-                        print('Error: unknown response.')
+                        print('Error: unknown response for patch.')
 
     def _run_launch(self, params, wait_time):
         """Launch secondary process.
@@ -787,7 +787,7 @@ class SppPrimary(object):
             elif res.status_code in error_codes:
                 pass
             else:
-                print('Error: unknown response.')
+                print('Error: unknown response for launch.')
 
     @classmethod
     def help(cls):
diff --git a/src/nfv/commands.h b/src/nfv/commands.h
index 499bdd4..4a6a170 100644
--- a/src/nfv/commands.h
+++ b/src/nfv/commands.h
@@ -12,6 +12,10 @@
 
 #define RTE_LOGTYPE_SPP_NFV RTE_LOGTYPE_USER1
 
+/* TODO(yasufum): consider to rename find_port_id() to find_ethdev_id()
+ * defined in shared/port_manager.c
+ */
+
 static int
 do_del(char *p_type, int p_id)
 {
diff --git a/src/primary/main.c b/src/primary/main.c
index 9d216a0..dbae424 100644
--- a/src/primary/main.c
+++ b/src/primary/main.c
@@ -785,10 +785,12 @@ get_status_json(char *str)
  * Add a port to spp_primary. Port is given as a resource UID which is a
  * combination of port type and ID like as 'ring:0'.
  */
+/* TODO(yasufum) consider to merge do_add in nfv/commands.h */
 static int
 add_port(char *p_type, int p_id)
 {
 	uint16_t dev_id;
+	uint16_t port_id;
 	int res = 0;
 	uint16_t cnt = 0;
 
@@ -822,6 +824,13 @@ add_port(char *p_type, int p_id)
 	if (res < 0)
 		return -1;
 
+	port_id = (uint16_t) res;
+	port_map[port_id].id = p_id;
+	port_map[port_id].port_type = port_id_list[cnt].type;
+	port_map[port_id].stats = &ports->client_stats[p_id];
+
+	/* Update ports_fwd_array with port id */
+	ports_fwd_array[port_id].in_port_id = port_id;
 	return 0;
 }
 
@@ -850,6 +859,7 @@ find_ethdev_id(int p_id, enum port_type ptype)
 }
 
 /* Delete port. */
+/* TODO(yasufum) consider to merge do_del in nfv/commands.h */
 static int
 del_port(char *p_type, int p_id)
 {
@@ -884,6 +894,9 @@ del_port(char *p_type, int p_id)
 	port_id_list[dev_id].port_id = PORT_RESET;
 	port_id_list[dev_id].type = UNDEF;
 
+	forward_array_remove(dev_id);
+	port_map_init_one(dev_id);
+
 	return 0;
 }
 
-- 
2.17.1


      parent reply	other threads:[~2019-10-17 12:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 12:58 [spp] [PATCH 0/2] Update status command for forwarder thread yasufum.o
2019-10-17 12:58 ` [spp] [PATCH 1/2] spp_primary: add status " yasufum.o
2019-10-17 12:58 ` yasufum.o [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191017125822.29309-3-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).