Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH 0/5] Add exit command support for spp_nfv and spp_vm
@ 2018-10-25  5:19 ogawa.yasufumi
  2018-10-25  5:19 ` [spp] [PATCH 1/5] spp_nfv: chage to return msg of exit command ogawa.yasufumi
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-25  5:19 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Hi,

SPP controller does not support `exit` command after it is changed to
request via `spp-ctl` because REST APIs for `exit` command is not
implemented. This series of patches is to add `exit' command for spp_nfv
and spp_vm. Spp_primary and spp_vf is also needed to add this support,
and updated in the next patches.

Thanks,
Yasufumi

Yasufumi Ogawa (5):
  spp_nfv: chage to return msg of exit command
  spp-ctl: add exit cmd support for spp_nfv
  spp_vm: chage to return msg of exit command
  controller: update sec exit cmd to call REST API
  docs: add DELETE method for exiting spp_nfv

 docs/guides/spp-ctl/api-reference.rst | 43 +++++++++++++++++++++++++++++++++++
 src/controller/commands/sec.py        | 10 +++++++-
 src/nfv/nfv.c                         | 10 ++++----
 src/spp-ctl/spp_ctl.py                |  9 ++++++++
 src/spp-ctl/spp_proc.py               |  4 ++++
 src/spp-ctl/spp_webapi.py             |  5 ++++
 src/vm/main.c                         | 12 ++++++----
 7 files changed, 83 insertions(+), 10 deletions(-)

-- 
2.7.4

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

* [spp] [PATCH 1/5] spp_nfv: chage to return msg of exit command
  2018-10-25  5:19 [spp] [PATCH 0/5] Add exit command support for spp_nfv and spp_vm ogawa.yasufumi
@ 2018-10-25  5:19 ` ogawa.yasufumi
  2018-10-25  5:19 ` [spp] [PATCH 2/5] spp-ctl: add exit cmd support for spp_nfv ogawa.yasufumi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-25  5:19 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

This patch is to fix error of receiving data of NfvProc in spp-ctl.
Spp_nfv returns no message after exit command while spp-ctl expects
to get any of message as a result. To fix, change to return empty
message.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/nfv/nfv.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c
index 05290ed..84d3df4 100644
--- a/src/nfv/nfv.c
+++ b/src/nfv/nfv.c
@@ -926,6 +926,7 @@ main(int argc, char *argv[])
 	int connected = 0;
 	char str[MSG_SIZE];
 	unsigned int i;
+	int flg_exit;  // used as res of parse_command() to exit if -1
 	int ret;
 
 	ret = rte_eal_init(argc, argv);
@@ -1000,13 +1001,14 @@ main(int argc, char *argv[])
 
 		RTE_LOG(DEBUG, APP, "Received string: %s\n", str);
 
-		ret = parse_command(str);
-		if (ret < 0)  /* terminate process if exit is called */
-			break;
+		flg_exit = parse_command(str);
 
 		/*Send the message back to client*/
 		ret = do_send(&connected, &sock, str);
-		if (ret < 0)
+
+		if (flg_exit < 0)  /* terminate process if exit is called */
+			break;
+		else if (ret < 0)
 			continue;
 	}
 
-- 
2.7.4

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

* [spp] [PATCH 2/5] spp-ctl: add exit cmd support for spp_nfv
  2018-10-25  5:19 [spp] [PATCH 0/5] Add exit command support for spp_nfv and spp_vm ogawa.yasufumi
  2018-10-25  5:19 ` [spp] [PATCH 1/5] spp_nfv: chage to return msg of exit command ogawa.yasufumi
@ 2018-10-25  5:19 ` ogawa.yasufumi
  2018-10-25  5:19 ` [spp] [PATCH 3/5] spp_vm: chage to return msg of exit command ogawa.yasufumi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-25  5:19 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Spp-ctl does not support exit spp_nfv and spp_vm, but it is required
using from `spp.py`. This update is to add a REST API for exiting the
process. It also add `do_exit()` method into spp-ctl to send `exit`
command to spp_nfv.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/spp-ctl/spp_ctl.py    | 9 +++++++++
 src/spp-ctl/spp_proc.py   | 4 ++++
 src/spp-ctl/spp_webapi.py | 5 +++++
 3 files changed, 18 insertions(+)

diff --git a/src/spp-ctl/spp_ctl.py b/src/spp-ctl/spp_ctl.py
index 80a78b6..81a2fe0 100644
--- a/src/spp-ctl/spp_ctl.py
+++ b/src/spp-ctl/spp_ctl.py
@@ -141,6 +141,15 @@ class Controller(object):
             procs.append(p)
         return procs
 
+    def do_exit(self, sec_type, sec_id):
+        target_key = None
+        for k, proc in self.procs.items():
+            if proc.type == sec_type and proc.id == sec_id:
+                target_key = k
+                break
+        if target_key is not None:
+            del self.procs[target_key]
+
 
 def main():
     parser = argparse.ArgumentParser(description="SPP Controller")
diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index 3b01e3f..aa928f2 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -168,6 +168,10 @@ class NfvProc(SppProc):
     def stop(self):
         return "stop"
 
+    @exec_command
+    def do_exit(self):
+        return "exit"
+
 
 class PrimaryProc(SppProc):
 
diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
index b2fbe3b..8332cab 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -310,6 +310,7 @@ class V1NFVHandler(BaseHandler):
 
     def set_route(self):
         self.route('/<sec_id:int>', 'GET', callback=self.nfv_get)
+        self.route('/<sec_id:int>', 'DELETE', callback=self.nfv_exit)
         self.route('/<sec_id:int>/forward', 'PUT',
                    callback=self.nfv_forward)
         self.route('/<sec_id:int>/ports', 'PUT',
@@ -377,6 +378,10 @@ class V1NFVHandler(BaseHandler):
     def nfv_patch_del(self, proc):
         proc.patch_reset()
 
+    def nfv_exit(self, proc):
+        self.ctrl.do_exit(proc.type, proc.id)
+        proc.do_exit()
+
 
 class V1PrimaryHandler(BaseHandler):
 
-- 
2.7.4

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

* [spp] [PATCH 3/5] spp_vm: chage to return msg of exit command
  2018-10-25  5:19 [spp] [PATCH 0/5] Add exit command support for spp_nfv and spp_vm ogawa.yasufumi
  2018-10-25  5:19 ` [spp] [PATCH 1/5] spp_nfv: chage to return msg of exit command ogawa.yasufumi
  2018-10-25  5:19 ` [spp] [PATCH 2/5] spp-ctl: add exit cmd support for spp_nfv ogawa.yasufumi
@ 2018-10-25  5:19 ` ogawa.yasufumi
  2018-10-25  5:19 ` [spp] [PATCH 4/5] controller: update sec exit cmd to call REST API ogawa.yasufumi
  2018-10-25  5:19 ` [spp] [PATCH 5/5] docs: add DELETE method for exiting spp_nfv ogawa.yasufumi
  4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-25  5:19 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

This patch is to fix error of receiving data of NfvProc in spp-ctl
as previous commit for spp_nfv.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/vm/main.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/vm/main.c b/src/vm/main.c
index 1d7d83a..050af3f 100644
--- a/src/vm/main.c
+++ b/src/vm/main.c
@@ -609,6 +609,7 @@ main(int argc, char *argv[])
 	int connected = 0;
 	char str[MSG_SIZE];
 	int ret;
+	int flg_exit;  // used as res of parse_command() to exit if -1
 	int i;
 
 	/* initialise the system */
@@ -651,13 +652,14 @@ main(int argc, char *argv[])
 
 		RTE_LOG(DEBUG, APP, "Received string: %s\n", str);
 
-		ret = parse_command(str);
-		if (ret < 0)  /* terminate process if exit is called */
-			break;
+		flg_exit = parse_command(str);
 
-		/*Send the message back to client*/
+		/* Send the message back to client */
 		ret = do_send(&connected, &sock, str);
-		if (ret < 0)
+
+		if (flg_exit < 0)  /* terminate process if exit is called */
+			break;
+		else if (ret < 0)
 			continue;
 	}
 
-- 
2.7.4

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

* [spp] [PATCH 4/5] controller: update sec exit cmd to call REST API
  2018-10-25  5:19 [spp] [PATCH 0/5] Add exit command support for spp_nfv and spp_vm ogawa.yasufumi
                   ` (2 preceding siblings ...)
  2018-10-25  5:19 ` [spp] [PATCH 3/5] spp_vm: chage to return msg of exit command ogawa.yasufumi
@ 2018-10-25  5:19 ` ogawa.yasufumi
  2018-10-25  5:19 ` [spp] [PATCH 5/5] docs: add DELETE method for exiting spp_nfv ogawa.yasufumi
  4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-25  5:19 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

To send `exit` command to spp_nfv or spp_vm, change to call REST API of
spp-ctl.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/commands/sec.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/controller/commands/sec.py b/src/controller/commands/sec.py
index 77cfe62..ec1da58 100644
--- a/src/controller/commands/sec.py
+++ b/src/controller/commands/sec.py
@@ -107,7 +107,15 @@ class SppSecondary(object):
                         print('Error: unknown response.')
 
         elif cmd == 'exit':
-            print('do nothing.')
+            res = self.spp_ctl_cli.delete('nfvs/%d' % sec_id)
+            if res is not None:
+                error_codes = self.spp_ctl_cli.rest_common_error_codes
+                if res.status_code == 204:
+                    print('Exit sec %d' % sec_id)
+                elif res.status_code in error_codes:
+                    pass
+                else:
+                    print('Error: unknown response.')
 
         else:
             print('Invalid command "%s".' % cmd)
-- 
2.7.4

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

* [spp] [PATCH 5/5] docs: add DELETE method for exiting spp_nfv
  2018-10-25  5:19 [spp] [PATCH 0/5] Add exit command support for spp_nfv and spp_vm ogawa.yasufumi
                   ` (3 preceding siblings ...)
  2018-10-25  5:19 ` [spp] [PATCH 4/5] controller: update sec exit cmd to call REST API ogawa.yasufumi
@ 2018-10-25  5:19 ` ogawa.yasufumi
  4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-25  5:19 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

To support `exit` of `sec` command of `spp.py`, add DELETE method. It
is called with client ID as following example.

  $ curl -X DELETE http://127.0.0.1:7777/v1/nfvs/1

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 docs/guides/spp-ctl/api-reference.rst | 43 +++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/docs/guides/spp-ctl/api-reference.rst b/docs/guides/spp-ctl/api-reference.rst
index 3ae90fd..f0661c8 100644
--- a/docs/guides/spp-ctl/api-reference.rst
+++ b/docs/guides/spp-ctl/api-reference.rst
@@ -582,6 +582,49 @@ Equivalent CLI command
     sec {client_id};patch reset
 
 
+DELETE /v1/nfvs/{client_id}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Terminate ``spp_nfv`` or ``spp_vm`` process.
+
+* Normal response codes: 204
+* Error response codes: 400, 404
+
+Request(path)
+^^^^^^^^^^^^^
+
+.. _table_spp_ctl_nfvs_delete:
+
+.. table:: Request parameter for terminating spp_nfv or spp_vm.
+
+    +-----------+---------+-------------------------------------+
+    | Name      | Type    | Description                         |
+    |           |         |                                     |
+    +===========+=========+=====================================+
+    | client_id | integer | client id.                          |
+    +-----------+---------+-------------------------------------+
+
+Request example
+^^^^^^^^^^^^^^^
+
+.. code-block:: console
+
+    curl -X DELETE -H 'application/json' \
+    http://127.0.0.1:7777/v1/nfvs/1
+
+Response example
+^^^^^^^^^^^^^^^^
+
+There is no body content for the response of a successful ``DELETE`` request.
+
+Equivalent CLI command
+^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: none
+
+    sec {client_id}; exit
+
+
 API for spp_vf
 --------------
 
-- 
2.7.4

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

end of thread, other threads:[~2018-10-25  5:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-25  5:19 [spp] [PATCH 0/5] Add exit command support for spp_nfv and spp_vm ogawa.yasufumi
2018-10-25  5:19 ` [spp] [PATCH 1/5] spp_nfv: chage to return msg of exit command ogawa.yasufumi
2018-10-25  5:19 ` [spp] [PATCH 2/5] spp-ctl: add exit cmd support for spp_nfv ogawa.yasufumi
2018-10-25  5:19 ` [spp] [PATCH 3/5] spp_vm: chage to return msg of exit command ogawa.yasufumi
2018-10-25  5:19 ` [spp] [PATCH 4/5] controller: update sec exit cmd to call REST API ogawa.yasufumi
2018-10-25  5:19 ` [spp] [PATCH 5/5] docs: add DELETE method for exiting spp_nfv ogawa.yasufumi

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).