From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5AA0BA317C for ; Thu, 17 Oct 2019 14:58:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 508E71E976; Thu, 17 Oct 2019 14:58:06 +0200 (CEST) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by dpdk.org (Postfix) with ESMTP id 824741E976 for ; Thu, 17 Oct 2019 14:58:05 +0200 (CEST) Received: by mail-pf1-f176.google.com with SMTP id q21so1602777pfn.11 for ; Thu, 17 Oct 2019 05:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=55+72Bx926FEv+UJJAaqwI3epN1ZUe1ih5P6M7TEIUY=; b=C44HKAISQEibWSBeVmecjxAKGhIKEHIlLgutO1C1NYI2q5KxWaP/KDkF3SNKZA8Y3z LCe+00yiRuZ168AskaDlBwbrRcS3+lxaqX2sxSYwBXQ3ti15FCImMcuZxTYVR1UKajAx 1vV9f/MrXFwie2LSInBZdipOGIAmA/kCq6Y5uKj3rQLCPpgvV9LklM2lqRyOWbjl98Gq QZYtoUVxjoAriH+ysckV/pep11vXdK0Z1tGTLvLTK5XLznNg+gzPg8kS2p6TfNUbDlE9 uRPHiWwfO29z+FzIk+iCpiWpifsawT7Een4y65QHL0WzUYqSOfzjZYsAF+myk2OEpiLL th5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=55+72Bx926FEv+UJJAaqwI3epN1ZUe1ih5P6M7TEIUY=; b=TRr37tSi/q228ZfjvzhGnySMw8EBDYqJ3wirBC/jL0PNi7nv3gRaK6+SidYIoDXrr9 AJVUfq1bcBPsE21xV6LUPKHJ1mFpDenQ1djSEzRrO2RZILvAaz+OishdAK7edDvrSs1P 3YlYaAxI64sfR4WVAZ6SYGG15a8eyLi4Ihs4dj3dmjUleO1TacPXNHJxPoaUhBZlf+ds gGFmBwFURkpCNyB4s+oejiooi1rSkfzWpmxsoETR/vxn+PGJboDF6shTVdWhOw0KHNAD uMVH7pLPR96IxWQJNBrLXBxSqan9nzO5ErtDyjIOnd6NrfuBiLEr6Z4vBj6EbeW6k+Cc yZfw== X-Gm-Message-State: APjAAAVt2oWjvKvneYA0A1IR0UtE861NEC+3PzzXa+IebAb3wPjS3rnB pBEOAa8V8Jzv6Y9TrK7dGoxLkWpskzM= X-Google-Smtp-Source: APXvYqxjCXdYNq6JhtcyQVweaPF7vsOYQlXSrXcTsyArfEYZXK4Y5h/Qtu4oZxXeXJkBTgFoZ4LNAg== X-Received: by 2002:a17:90b:316:: with SMTP id ay22mr4077992pjb.6.1571317084632; Thu, 17 Oct 2019 05:58:04 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id x139sm4494294pgx.92.2019.10.17.05.58.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Oct 2019 05:58:04 -0700 (PDT) From: yasufum.o@gmail.com To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Thu, 17 Oct 2019 21:58:00 +0900 Message-Id: <20191017125800.29197-1-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [spp] [PATCH] spp-ctl: add APIs for pri for managing ports 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: , Errors-To: spp-bounces@dpdk.org Sender: "spp" From: Yasufumi Ogawa 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 --- 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