From: x-fn-spp-ml@ntt-tx.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH v2 15/17] cli: add support of rte_flow in nfv
Date: Wed, 19 Feb 2020 20:49:45 +0900 [thread overview]
Message-ID: <20200219114947.14134-16-x-fn-spp-ml@ntt-tx.co.jp> (raw)
In-Reply-To: <20200218063720.6597-1-x-fn-spp-ml@ntt-tx.co.jp>
From: Hideyuki Yamashita <yamashita.hideyuki@ntt-tx.co.jp>
This patch implements support of multi-queue in nfv command.
- nfv; status
- nfv; port
Signed-off-by: Hideyuki Yamashita <yamashita.hideyuki@ntt-tx.co.jp>
Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
src/cli/commands/nfv.py | 245 +++++++++++++++++++++++++++++-----------
1 file changed, 179 insertions(+), 66 deletions(-)
diff --git a/src/cli/commands/nfv.py b/src/cli/commands/nfv.py
index 6349823..0feb4ac 100644
--- a/src/cli/commands/nfv.py
+++ b/src/cli/commands/nfv.py
@@ -260,49 +260,123 @@ class SppNfv(object):
def _compl_patch(self, sub_tokens):
"""Complete `patch` command."""
- # Patch command consists of three tokens max, for instance,
- # `nfv 1; patch phy:0 ring:1`.
- if len(sub_tokens) < 4:
- res = []
-
- if self.use_cache is False:
- self.ports, self.patches = self._get_ports_and_patches()
+ res = []
+ candidates = []
+ # index 0 is "port", so from 1
+ index = 1
+
+ # compl_phase "src_res_uid" : candidate is src RES_UID or reset
+ # compl_phase "src_nq" : candidate is nq
+ # compl_phase "src_q_no" : candidate is queue no
+ # compl_phase "dst_res_uid" : candidate is dst RES_UID
+ # compl_phase "dst_nq" : candidate is nq
+ # compl_phase "dst_q_no" : candidate is queue no
+ # compl_phase None : candidate is None
+ compl_phase = "src_res_uid"
+
+ if self.use_cache is False:
+ self.ports, self.patches = self._get_ports_and_patches()
+
+ # Get patched ports of src and dst to be used for completion.
+ src_ports = []
+ dst_ports = []
+ for pt in self.patches:
+ src_ports.append(pt['src'])
+ dst_ports.append(pt['dst'])
+
+ while index < len(sub_tokens):
+ if compl_phase == "src_nq" or compl_phase == "dst_nq":
+ if sub_tokens[index - 1] == "reset":
+ candidates = []
+ compl_phase = None
+ continue
+
+ queue_no_list = []
+ for port in self.ports:
+ split_port = port.split()
+ if len(split_port) != 3:
+ continue
+ if sub_tokens[index - 1] != split_port[0]:
+ continue
+ queue_no_list.append(split_port[2])
+
+ if len(queue_no_list) == 0:
+ if compl_phase == "src_nq":
+ compl_phase = "dst_res_uid"
+ elif compl_phase == "dst_nq":
+ compl_phase = None
+
+ if compl_phase == "src_res_uid":
+ candidates = []
+ for port in self.ports:
+ if port in src_ports:
+ continue
+ if port in candidates:
+ continue
+ candidates.append(port.split()[0])
+
+ # If some of ports are patched, `reset` should be included
+ if len(self.patches) != 0:
+ candidates.append("reset")
+
+ compl_phase = "src_nq"
+
+ elif compl_phase == "src_nq":
+ candidates = ["nq"]
+ compl_phase = "src_q_no"
+
+ elif compl_phase == "src_q_no":
+ candidates = []
+ for queue_no in queue_no_list:
+ res_uid = "{0} nq {1}".format(
+ sub_tokens[index - 2], queue_no)
+ if res_uid in src_ports:
+ continue
+ candidates.append(queue_no)
+ compl_phase = "dst_res_uid"
+
+ elif compl_phase == "dst_res_uid":
+ candidates = []
+ for port in self.ports:
+ if port in dst_ports:
+ continue
+ if port in candidates:
+ continue
+ candidates.append(port.split()[0])
+
+ compl_phase = "dst_nq"
+
+ elif compl_phase == "dst_nq":
+ candidates = ["nq"]
+ compl_phase = "dst_q_no"
+
+ elif compl_phase == "dst_q_no":
+ candidates = []
+ for queue_no in queue_no_list:
+ res_uid = "{0} nq {1}".format(
+ sub_tokens[index - 2], queue_no)
+ if res_uid in dst_ports:
+ continue
+ candidates.append(queue_no)
+ compl_phase = None
- # Get patched ports of src and dst to be used for completion.
- src_ports = []
- dst_ports = []
- for pt in self.patches:
- src_ports.append(pt['src'])
- dst_ports.append(pt['dst'])
-
- # Remove patched ports from candidates.
- target_idx = len(sub_tokens) - 1 # target is src or dst
- tmp_ports = self.ports[:] # candidates
- if target_idx == 1: # find src port
- # If some of ports are patched, `reset` should be included.
- if self.patches != []:
- tmp_ports.append('reset')
- for pt in src_ports:
- tmp_ports.remove(pt) # remove patched ports
- else: # find dst port
- # If `reset` is given, no need to show dst ports.
- if sub_tokens[target_idx - 1] == 'reset':
- tmp_ports = []
+ else:
+ candidates = []
+ compl_phase = None
+
+ index += 1
+
+ last_index = len(sub_tokens) - 1
+ for candidate in candidates:
+ if candidate.startswith(sub_tokens[last_index]):
+ # Completion does not work correctly if `:` is included in
+ # tokens. Required to create keyword only after `:`.
+ if ':' in sub_tokens[last_index]: # 'ring:' or 'ring:0'
+ res.append(candidate.split(':')[1]) # add only after `:`
else:
- for pt in dst_ports:
- tmp_ports.remove(pt)
-
- # Return candidates.
- for kw in tmp_ports:
- if kw.startswith(sub_tokens[target_idx]):
- # Completion does not work correctly if `:` is included in
- # tokens. Required to create keyword only after `:`.
- if ':' in sub_tokens[target_idx]: # 'ring:' or 'ring:0'
- res.append(kw.split(':')[1]) # add only after `:`
- else:
- res.append(kw)
+ res.append(candidate)
- return res
+ return res
def _run_status(self):
"""Run `status` command."""
@@ -407,34 +481,73 @@ class SppNfv(object):
def _run_patch(self, params):
"""Run `patch` command."""
+ params_index = 0
+ req_params = {}
+ flg_reset = False
+ flg_mq = False
+
if len(params) == 0:
- print('Params are required!')
- elif params[0] == 'reset':
- res = self.spp_ctl_cli.delete('nfvs/%d/patches' % self.sec_id)
- if res is not None:
- error_codes = self.spp_ctl_cli.rest_common_error_codes
- if res.status_code == 204:
- print('Clear all of patches.')
- elif res.status_code in error_codes:
- pass
- else:
- print('Error: unknown response.')
+ print('Error: Params are required!')
+ return
+
+ while params_index < len(params):
+ if params_index == 0 and params[0] == "reset":
+ flg_reset = True
+ break
+
+ elif params_index == 0:
+ req_params["src"] = params[params_index]
+
+ if params_index + 2 < len(params):
+ if params[params_index + 1] == "nq":
+ params_index += 2
+ req_params["src"] += "nq" + params[params_index]
+ flg_mq = True
+
+ elif ((params_index == 1 and flg_mq is False) or
+ (params_index == 3 and flg_mq is True)):
+ req_params["dst"] = params[params_index]
+
+ if params_index + 2 < len(params):
+ if params[params_index + 1] == "nq":
+ params_index += 2
+ req_params["dst"] += "nq" + params[params_index]
+
+ params_index += 1
+
+ if flg_reset is False:
+ if "src" not in req_params:
+ print("Error: Src port is required!")
+ return
+
+ if "dst" not in req_params:
+ print("Error: Dst port is required!")
+ return
+
+ url = "nfvs/{0}/patches".format(self.sec_id)
+ if flg_reset:
+ res = self.spp_ctl_cli.delete(url)
else:
- if len(params) < 2:
- print('Dst port is required!')
- else:
- req_params = {'src': params[0], 'dst': params[1]}
- res = self.spp_ctl_cli.put(
- 'nfvs/%d/patches' % self.sec_id, req_params)
- if res is not None:
- error_codes = self.spp_ctl_cli.rest_common_error_codes
- if res.status_code == 204:
- print('Patch ports (%s -> %s).' % (
- params[0], params[1]))
- elif res.status_code in error_codes:
- pass
- else:
- print('Error: unknown response.')
+ res = self.spp_ctl_cli.put(url, req_params)
+
+ if res is None:
+ return
+
+ error_codes = self.spp_ctl_cli.rest_common_error_codes
+ if res.status_code in error_codes:
+ pass
+ elif res.status_code != 204:
+ print('Error: unknown response.')
+ return
+
+ if flg_reset:
+ print("Clear all of patches.")
+ else:
+ src = (req_params["src"].replace("nq", " nq ")
+ if "nq" in req_params["src"] else req_params["src"])
+ dst = (req_params["dst"].replace("nq", " nq ")
+ if "nq" in req_params["dst"] else req_params["dst"])
+ print("Patch ports ({0} -> {1}).".format(src, dst))
def _run_exit(self):
"""Run `exit` command."""
--
2.17.1
next prev parent reply other threads:[~2020-02-19 11:50 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-18 6:37 [spp] [PATCH 00/17] Adding Hardware offload capability x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 01/17] shared: add support of multi-queue x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 02/17] spp_vf: " x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 03/17] spp_mirror: " x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 04/17] spp_pcap: " x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 05/17] spp_primary: " x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 06/17] spp_primary: add support of rte_flow x-fn-spp-ml
2020-02-19 2:24 ` Yasufumi Ogawa
2020-02-19 11:57 ` [spp] (x-fn-spp-ml 118) " Hideyuki Yamashita
2020-02-18 6:37 ` [spp] [PATCH 07/17] spp_primary: add common function " x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 08/17] spp_primary: add attribute " x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 09/17] spp_primary: add patterns " x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 10/17] spp_primary: add actions " x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 11/17] bin: add parameter for hardrare offload x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 12/17] cli: add support of hardware offload x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 13/17] cli: add support of rte_flow in vf x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 14/17] cli: add support of rte_flow in mirror x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 15/17] cli: add support of rte_flow in nfv x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 16/17] spp-ctl: add APIs for flow rules x-fn-spp-ml
2020-02-18 6:37 ` [spp] [PATCH 17/17] spp_nfv: add support of multi-queue x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 00/17] Adding Hardware offload capability x-fn-spp-ml
2020-02-21 8:17 ` Yasufumi Ogawa
2020-02-25 5:49 ` [spp] (x-fn-spp-ml 177) " Hideyuki Yamashita
2020-02-19 11:49 ` [spp] [PATCH v2 01/17] shared: add support of multi-queue x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 02/17] spp_vf: " x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 03/17] spp_mirror: " x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 04/17] spp_pcap: " x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 05/17] spp_primary: " x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 06/17] spp_primary: add support of rte_flow x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 07/17] spp_primary: add common function " x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 08/17] spp_primary: add attribute " x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 09/17] spp_primary: add patterns " x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 10/17] spp_primary: add actions " x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 11/17] bin: add parameter for hardrare offload x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 12/17] cli: add support of hardware offload x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 13/17] cli: add support of rte_flow in vf x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 14/17] cli: add support of rte_flow in mirror x-fn-spp-ml
2020-02-19 11:49 ` x-fn-spp-ml [this message]
2020-02-19 11:49 ` [spp] [PATCH v2 16/17] spp-ctl: add APIs for flow rules x-fn-spp-ml
2020-02-19 11:49 ` [spp] [PATCH v2 17/17] spp_nfv: add support of multi-queue x-fn-spp-ml
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=20200219114947.14134-16-x-fn-spp-ml@ntt-tx.co.jp \
--to=x-fn-spp-ml@ntt-tx.co.jp \
--cc=ferruh.yigit@intel.com \
--cc=spp@dpdk.org \
--cc=yasufum.o@gmail.com \
/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).