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] spp-ctl: add APIs for pri for managing ports
Date: Thu, 17 Oct 2019 21:58:00 +0900	[thread overview]
Message-ID: <20191017125800.29197-1-yasufum.o@gmail.com> (raw)

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

Add REST APIs for spp_primary for running `forward`, `stop` and
`patch` commands which are similar to spp_nfv. For example, forward
can be run with curl as below.

  $ curl -X PUT -H 'application/json' -d '{"action": "start"}' \
    http://127.0.0.1:7777/v1/primary/forward

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/spp-ctl/spp_proc.py   | 17 +++++++++++++
 src/spp-ctl/spp_webapi.py | 51 +++++++++++++++++++++++++++++++++++----
 2 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index 33bde43..35919fb 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -11,6 +11,7 @@ import spp_ctl
 
 LOG = logging.getLogger(__name__)
 
+# TODO(yasufum): Move following definitions to another file.
 ID_PRIMARY = 0
 TYPE_PRIMARY = "primary"
 TYPE_VF = "vf"
@@ -300,6 +301,22 @@ class PrimaryProc(SppProc):
     def port_del(self, port):
         return "del {port}".format(**locals())
 
+    @exec_command
+    def patch_add(self, src_port, dst_port):
+        return "patch {src_port} {dst_port}".format(**locals())
+
+    @exec_command
+    def patch_reset(self):
+        return "patch reset"
+
+    @exec_command
+    def forward(self):
+        return "forward"
+
+    @exec_command
+    def stop(self):
+        return "stop"
+
     @exec_command
     def do_launch_sec_proc(self, args):
         proc_name = args['proc_name']
diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
index 8451711..a21fd86 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -455,13 +455,20 @@ class V1PrimaryHandler(BaseHandler):
     def set_route(self):
         self.route('/status', 'GET', callback=self.get_status)
         self.route('/status', 'DELETE', callback=self.clear_status)
-        self.route('/ports', 'PUT',
-                   callback=self.primary_port)
-        self.route('/launch', 'PUT',
-                   callback=self.launch_sec_proc)
+        self.route('/forward', 'PUT', callback=self.nfv_forward)
+        self.route('/ports', 'PUT', callback=self.primary_port)
+        self.route('/patches', 'PUT', callback=self.nfv_patch_add)
+        self.route('/patches', 'DELETE', callback=self.nfv_patch_del)
+        self.route('/launch', 'PUT', callback=self.launch_sec_proc)
         self.route('/', 'DELETE', callback=self.pri_exit)
 
     def _get_proc(self):
+        """Get Primary object for requesting.
+
+        This method is call everytime received request via REST API
+        to confirm primary is alive.
+        """
+
         proc = self.ctrl.procs.get(spp_proc.ID_PRIMARY)
         if proc is None:
             raise bottle.HTTPError(404, "primary not found.")
@@ -483,7 +490,22 @@ class V1PrimaryHandler(BaseHandler):
         proc = self._get_proc()
         proc.clear()
 
-    # TODO(yasufum) change name and make it to shared method
+    # TODO(yasufum) change name `nfv` and make it to shared method
+    def _validate_nfv_forward(self, body):
+        if 'action' not in body:
+            raise KeyRequired('action')
+        if body['action'] not in ["start", "stop"]:
+            raise KeyInvalid('action', body['action'])
+
+    # TODO(yasufum) change name `nfv` and make it to shared method
+    def nfv_forward(self, body):
+        proc = self._get_proc()
+        if body['action'] == "start":
+            proc.forward()
+        else:
+            proc.stop()
+
+    # TODO(yasufum) change name `nfv` and make it to shared method
     def _validate_nfv_port(self, body):
         for key in ['action', 'port']:
             if key not in body:
@@ -501,6 +523,25 @@ class V1PrimaryHandler(BaseHandler):
         else:
             proc.port_del(body['port'])
 
+    # TODO(yasufum) change name `nfv` and make it to shared method
+    def _validate_nfv_patch(self, body):
+        for key in ['src', 'dst']:
+            if key not in body:
+                raise KeyRequired(key)
+        self._validate_port(body['src'])
+        self._validate_port(body['dst'])
+
+    # TODO(yasufum) change name `nfv` and make it to shared method
+    def nfv_patch_add(self, body):
+        proc = self._get_proc()
+        self._validate_nfv_patch(body)
+        proc.patch_add(body['src'], body['dst'])
+
+    # TODO(yasufum) change name `nfv` and make it to shared method
+    def nfv_patch_del(self):
+        proc = self._get_proc()
+        proc.patch_reset()
+
     def launch_sec_proc(self, body):  # the arg should be "body"
         for key in ['client_id', 'proc_name', 'eal', 'app']:
             if key not in body:
-- 
2.17.1


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

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20191017125800.29197-1-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).