From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by dpdk.org (Postfix) with ESMTP id 53B3D5B30 for ; Fri, 5 Oct 2018 05:58:01 +0200 (CEST) Received: by valinux.co.jp (Postfix, from userid 1000) id EE4F9240CDC; Fri, 5 Oct 2018 12:57:58 +0900 (JST) From: oda@valinux.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Date: Fri, 5 Oct 2018 12:57:53 +0900 Message-Id: <20181005035757.23122-11-oda@valinux.co.jp> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181005035757.23122-1-oda@valinux.co.jp> References: <20180913082544.2D36.277DD91C@valinux.co.jp> <20181005035757.23122-1-oda@valinux.co.jp> Subject: [spp] [PATCH v4 10/14] spp-ctl: update parsing spp_nfv status X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Oct 2018 03:58:01 -0000 From: Yasufumi Ogawa Update for parsing the result of status of spp_nfv. Signed-off-by: Yasufumi Ogawa Signed-off-by: Itsuro Oda --- src/spp-ctl/spp_webapi.py | 66 +++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py index 435c4b7..ee47f2f 100644 --- a/src/spp-ctl/spp_webapi.py +++ b/src/spp-ctl/spp_webapi.py @@ -318,50 +318,40 @@ class V1NFVHandler(BaseHandler): self.route('//patches', 'DELETE', callback=self.nfv_patch_del) - def convert_nfv_info(self, data): + def convert_nfv_info(self, sec_id, data): nfv = {} - lines = data.splitlines() - if len(lines) < 3: + + # spp_nfv returns status info in two lines. First line is + # status of running or idling, and second is patch info. + # 'null' means that it has no dst port. + # "status: idling\nports: 'phy:0-phy:1,phy:1-null'\x00\x00.." + entries = data.split('\n') + if len(entries) != 2: return {} - p = re.compile("Client ID (\d+) (\w+)") - m = p.match(lines[0]) - if m: - nfv['client_id'] = int(m.group(1)) - nfv['status'] = m.group(2) - - ports = {} - outs = [] - for line in lines[2:]: - if not line.startswith("port_id"): - break - arg1, _, arg2, arg3 = line.split(",") - _, port_id = arg1.split(":") - if arg2 == "PHY": - port = "phy:" + port_id - else: - if_type, rest = arg2.split("(") - if_num = rest.rstrip(")") - if if_type == "RING": - port = "ring:" + if_num - elif if_type == "VHOST": - port = "vhost:" + if_num - else: - port = if_type + ":" + if_num - ports[port_id] = port - _, out_id = arg3.split(":") - if out_id != "none": - outs.append((port_id, out_id)) - nfv['ports'] = list(ports.values()) - patches = [] - if outs: - for src_id, dst_id in outs: - patches.append({"src": ports[src_id], "dst": ports[dst_id]}) - nfv['patches'] = patches + + nfv['client_id'] = int(sec_id) + nfv['status'] = entries[0].split()[1] + + patch_list = entries[1].split()[1].replace("'", '') + + ports = [] + nfv['patches'] = [] + + for port_cmb in patch_list.split(','): + p_src, p_dst = port_cmb.split('-') + if p_src != 'null' and p_dst != 'null': + nfv['patches'].append({'src': p_src, 'dst': p_dst}) + + for port in [p_src, p_dst]: + if port != 'null': + ports.append(port) + + nfv['ports'] = list(set(ports)) return nfv def nfv_get(self, proc): - return self.convert_nfv_info(proc.get_status()) + return self.convert_nfv_info(proc.id, proc.get_status()) def _validate_nfv_forward(self, body): if 'action' not in body: -- 2.17.1