Soft Patch Panel
 help / color / mirror / Atom feed
From: x-fn-spp@sl.ntt-tx.co.jp
To: ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Cc: spp@dpdk.org
Subject: [spp] [PATCH v2 7/7] controller: add pcap command to SPP controller
Date: Fri,  8 Feb 2019 17:44:38 +0900	[thread overview]
Message-ID: <201902080844.x188icPt030839@imss04.silk.ntt-tx.co.jp> (raw)
In-Reply-To: <20190208084438.7952-1-x-fn-spp@sl.ntt-tx.co.jp>

From: Hideyuki Yamashita <yamashita.hideyuki@po.ntt-tx.co.jp>

This update is to 'pcap' command to Shell class for managing
spp_pcap from SPP CLI. Spp_pcap might have several instances, and
deciding which of ones is also similar to other secondary processes.
'pcap' command consists of an indicator and actual command. Here is
an example.

  spp > pcap 3; start

In this example, indicator 'pcap 3;' is before spp_pcap's command
'capture start'. The number in indicator is a secondary ID actually,
so you cannot assign the same ID of others.

You can refer the usage of 'pcap' command with 'help' command.

  spp > help pcap

Signed-off-by: Hideyuki Yamashita <yamashita.hideyuki@po.ntt-tx.co.jp>
Signed-off-by: Naoki Takada <takada.naoki@lab.ntt.co.jp>
---
 src/controller/shell.py | 87 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 84 insertions(+), 3 deletions(-)

diff --git a/src/controller/shell.py b/src/controller/shell.py
index f1381b7..a695833 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: BSD-3-Clause
-# Copyright(c) 2015-2016 Intel Corporation
+# Copyright(c) 2015-2019 Intel Corporation
 
 from __future__ import absolute_import
 
@@ -11,6 +11,7 @@ from .commands import server
 from .commands import topo
 from .commands import vf
 from .commands import mirror
+from .commands import pcap
 import os
 import re
 import readline
@@ -116,6 +117,10 @@ class Shell(cmd.Cmd, object):
             self.secondaries['mirror'][sec_id] = mirror.SppMirror(
                     self.spp_ctl_cli, sec_id)
 
+        self.spp_pcaps = {}
+        for sec_id in self.get_sec_ids('pcap'):
+            self.spp_pcaps[sec_id] = pcap.SppPcap(self.spp_ctl_cli, sec_id)
+
     # Called everytime after running command. `stop` is returned from `do_*`
     # method and SPP CLI is terminated if it is True. It means that only
     # `do_bye` and  `do_exit` return True.
@@ -149,7 +154,7 @@ class Shell(cmd.Cmd, object):
     def get_sec_ids(self, ptype):
         """Return a list of IDs of running secondary processes.
 
-        'ptype' is 'nfv', 'vf' or 'mirror'.
+        'ptype' is 'nfv', 'vf' or 'mirror' or 'pcap'.
         """
 
         ids = []
@@ -176,6 +181,7 @@ class Shell(cmd.Cmd, object):
                 sec_obj['nfv'] = []
                 sec_obj['vf'] = []
                 sec_obj['mirror'] = []
+                sec_obj['pcap'] = []
 
                 for proc_obj in proc_objs:
                     if proc_obj['type'] == 'primary':
@@ -192,7 +198,7 @@ class Shell(cmd.Cmd, object):
                 print('- secondary:')
                 print('  - processes:')
                 cnt = 1
-                for pt in ['nfv', 'vf', 'mirror']:
+                for pt in ['nfv', 'vf', 'mirror', 'pcap']:
                     for obj in sec_obj[pt]:
                         print('    %d: %s:%s' %
                               (cnt, obj['type'], obj['client-id']))
@@ -575,6 +581,81 @@ class Shell(cmd.Cmd, object):
                 return self.secondaries['mirror'][idx].complete(
                         self.get_sec_ids('mirror'), text, line, begidx, endidx)
 
+    def do_pcap(self, cmd):
+        """Send a command to spp_pcap.
+
+        spp_pcap is a secondary process for duplicating incoming
+        packets to be used as similar to TaaS in OpenStack. This
+        command has four sub commands.
+          * status
+          * start
+          * stop
+          * exit
+
+        Each of sub commands other than 'status' takes several parameters
+        for detailed operations. Notice that 'start' for launching a worker
+        is replaced with 'stop' for terminating. 'exit' for spp_pcap
+        terminating.
+
+        Examples:
+
+        # (1) show status of worker threads and resources
+        spp > pcap 1; status
+
+        # (2) launch capture thread
+        spp > pcap 1; start
+
+        # (3) terminate capture thread
+        spp > pcap 1; stop
+
+        # (4) terminate spp_pcap secondaryd
+        spp > pcap 1; exit
+        """
+
+        # remove unwanted spaces to avoid invalid command error
+        tmparg = self.clean_cmd(cmd)
+        cmds = tmparg.split(';')
+        if len(cmds) < 2:
+            print("Required an ID and ';' before the command.")
+        elif str.isdigit(cmds[0]):
+            self.spp_pcaps[int(cmds[0])].run(cmds[1])
+        else:
+            print('Invalid command: %s' % tmparg)
+
+    def complete_pcap(self, text, line, begidx, endidx):
+        """Completion for pcap command"""
+
+        line = self.clean_cmd(line)
+
+        tokens = line.split(';')
+        if len(tokens) == 1:
+            # Add SppPcap of sec_id if it is not exist
+            sec_ids = self.get_sec_ids('pcap')
+            for idx in sec_ids:
+                if self.spp_pcaps[idx] is None:
+                    self.spp_pcaps[idx] = pcap.SppPcap(self.spp_ctl_cli, idx)
+
+            if len(line.split()) == 1:
+                res = [str(i)+';' for i in sec_ids]
+            else:
+                if not (';' in line):
+                    res = [str(i)+';'
+                           for i in sec_ids
+                           if (str(i)+';').startswith(text)]
+            return res
+        elif len(tokens) == 2:
+            # Split tokens like as from 'pcap 1' to ['pcap', '1']
+            first_tokens = tokens[0].split(' ')
+            if len(first_tokens) == 2:
+                idx = int(first_tokens[1])
+
+                # Add SppPcap of sec_id if it is not exist
+                if self.spp_pcaps[idx] is None:
+                    self.spp_pcaps[idx] = pcap.SppPcap(self.spp_ctl_cli, idx)
+
+                return self.spp_pcaps[idx].complete(
+                        self.get_sec_ids('pcap'), text, line, begidx, endidx)
+
     def do_record(self, fname):
         """Save commands as a recipe file.
 
-- 
2.17.1

      parent reply	other threads:[~2019-02-08  8:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190208084438.7952-1-x-fn-spp@sl.ntt-tx.co.jp>
2019-02-08  8:44 ` [spp] [PATCH v2 1/7] spp_pcap: add command main x-fn-spp
2019-02-08  8:44 ` [spp] [PATCH v2 2/7] spp_pcap: add command decode x-fn-spp
2019-02-08  8:44 ` [spp] [PATCH v2 3/7] spp_pcap: add management function x-fn-spp
2019-02-08  8:44 ` [spp] [PATCH v2 4/7] spp_pcap: add spp_pcap main function x-fn-spp
2019-02-08  8:44 ` [spp] [PATCH v2 5/7] spp_pcap: add Makefile for spp_pcap x-fn-spp
2019-02-08  8:44 ` [spp] [PATCH v2 6/7] controller: add SppPcap class x-fn-spp
2019-02-08  8:44 ` x-fn-spp [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=201902080844.x188icPt030839@imss04.silk.ntt-tx.co.jp \
    --to=x-fn-spp@sl.ntt-tx.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=ogawa.yasufumi@lab.ntt.co.jp \
    --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).