From ogawa.yasufumi at lab.ntt.co.jp Tue Oct 3 08:34:25 2017 From: ogawa.yasufumi at lab.ntt.co.jp (Yasufumi Ogawa) Date: Tue, 3 Oct 2017 15:34:25 +0900 Subject: [spp] [RFC] assign global unique port ID Message-ID: <093f4d79-1238-3be8-f242-062bca27a933@lab.ntt.co.jp> Hi, Gerald, Sy Jong, In spp, port ID is assigned as a number incrementally and the number of ID can be different from each sec processes. For instance, ring 0 is added to sec 1 at first while it is added to sec 2 after ring 1, ring 0 is referred as port 2 from sec 1 and port 3 from sec 2. spp > sec 1;status ... port id: 0,on,PHY,outport: -99 port id: 1,on,PHY,outport: -99 port id: 2,on,RING(0),outport: -99 # ring 0 is referred as port 2 spp > sec 2;status ... port id: 0,on,PHY,outport: -99 port id: 1,on,PHY,outport: -99 port id: 2,on,RING(1),outport: -99 port id: 3,on,RING(0),outport: -99 # ring 0 is referred as port 3 User always has to check the status any time patching to avoid mistake. However, it must be annoying and an error is possibly happened. I propose to assign global unique ID for port. In this update, port ID is referred as a combination of PMD type and its ID, not a number. For instance, (Before) spp> patch 0 2 (After) spp> patch phy:0 ring:0 # means to patch from phy 0 to ring 0 If you agree, I would like to send patches for update. Thanks, Yasufumi -- ------------------------------------------------- Yasufumi Ogawa NTT Network Service Systems Labs tel: 0422(59)5776 fax: 0422(59)5653 email: ogawa.yasufumi at lab.ntt.co.jp ------------------------------------------------- From ogawa.yasufumi at lab.ntt.co.jp Tue Oct 3 12:42:12 2017 From: ogawa.yasufumi at lab.ntt.co.jp (ogawa.yasufumi at lab.ntt.co.jp) Date: Tue, 3 Oct 2017 19:42:12 +0900 Subject: [spp] [PATCH 1/3] spp: fix bug of precmd Message-ID: <20171003104214.81003-1-ogawa.yasufumi@lab.ntt.co.jp> From: Yasufumi Ogawa In precmd function, command log is not recorded if it is 'playback' to avoid illegal action when the log is loaded. However, 'bye' should be also excluded from the log because spp.py is terminated immediately if the log is loaded. This change for adding a condition for command logging. Signed-off-by: Yasufumi Ogawa --- src/spp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/spp.py b/src/spp.py index 68b3a3f..4aa0c62 100755 --- a/src/spp.py +++ b/src/spp.py @@ -503,8 +503,9 @@ class Shell(cmd.Cmd): def precmd(self, line): line = line.lower() - if self.recorded_file and 'playback' not in line: - print(line, file=self.recorded_file) + if self.recorded_file: + if not (('playback' in line) or ('bye' in line)): + print(line, file=self.recorded_file) return line def close(self): -- 2.13.1 From ogawa.yasufumi at lab.ntt.co.jp Tue Oct 3 12:42:13 2017 From: ogawa.yasufumi at lab.ntt.co.jp (ogawa.yasufumi at lab.ntt.co.jp) Date: Tue, 3 Oct 2017 19:42:13 +0900 Subject: [spp] [PATCH 2/3] spp: add record file check In-Reply-To: <20171003104214.81003-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20171003104214.81003-1-ogawa.yasufumi@lab.ntt.co.jp> Message-ID: <20171003104214.81003-2-ogawa.yasufumi@lab.ntt.co.jp> From: Yasufumi Ogawa record and playback command should be given a record file name but there are no checking if it is given. This change adds checking for record file in do_record and do_playback methods. Signed-off-by: Yasufumi Ogawa --- src/spp.py | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/spp.py b/src/spp.py index 4aa0c62..4bbbb44 100755 --- a/src/spp.py +++ b/src/spp.py @@ -477,29 +477,35 @@ class Shell(cmd.Cmd): print ("first %s" % cmds[1]) self.response(CMD_ERROR, "invalid format") - def do_record(self, arg): + def do_record(self, fname): """Save future commands to filename: RECORD filename.cmd""" - self.recorded_file = open(arg, 'w') - self.response(CMD_OK, "record") + if fname == '': + print("Record file is required!") + else: + self.recorded_file = open(fname, 'w') + self.response(CMD_OK, "record") - def do_playback(self, arg): + def do_playback(self, fname): """Playback commands from a file: PLAYBACK filename.cmd""" - self.close() - try: - with open(arg) as recorded_file: - lines = [] - for line in recorded_file: - if line.strip().startswith("#"): - continue - lines.append(line) - self.cmdqueue.extend(lines) - self.response(CMD_OK, "playback") - except IOError: - message = "Error: File does not exist." - print(message) - self.response(CMD_NG, message) + if fname == '': + print("Record file is required!") + else: + self.close() + try: + with open(fname) as recorded_file: + lines = [] + for line in recorded_file: + if line.strip().startswith("#"): + continue + lines.append(line) + self.cmdqueue.extend(lines) + self.response(CMD_OK, "playback") + except IOError: + message = "Error: File does not exist." + print(message) + self.response(CMD_NG, message) def precmd(self, line): line = line.lower() -- 2.13.1 From ogawa.yasufumi at lab.ntt.co.jp Tue Oct 3 12:42:14 2017 From: ogawa.yasufumi at lab.ntt.co.jp (ogawa.yasufumi at lab.ntt.co.jp) Date: Tue, 3 Oct 2017 19:42:14 +0900 Subject: [spp] [PATCH 3/3] spp: change logger to optional In-Reply-To: <20171003104214.81003-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20171003104214.81003-1-ogawa.yasufumi@lab.ntt.co.jp> Message-ID: <20171003104214.81003-3-ogawa.yasufumi@lab.ntt.co.jp> From: Yasufumi Ogawa Logger in spp.py is used only for debugging and useless for users. Use of logger is selectable by comment/uncomment logger's setting defined after importing libraries. Signed-off-by: Yasufumi Ogawa --- src/spp.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/spp.py b/src/spp.py index 4bbbb44..ce8aff0 100755 --- a/src/spp.py +++ b/src/spp.py @@ -18,14 +18,17 @@ import readline import threading import json -from logging import getLogger,StreamHandler,Formatter,DEBUG -logger = getLogger(__name__) -handler = StreamHandler() -handler.setLevel(DEBUG) -formatter = Formatter('%(asctime)s - [%(name)s] - [%(levelname)s] - %(message)s') -handler.setFormatter(formatter) -logger.setLevel(DEBUG) -logger.addHandler(handler) +logger = None + +# Comment out to activate debug logging +#from logging import getLogger,StreamHandler,Formatter,DEBUG +#logger = getLogger(__name__) +#handler = StreamHandler() +#handler.setLevel(DEBUG) +#formatter = Formatter('%(asctime)s - [%(name)s] - [%(levelname)s] - %(message)s') +#handler.setFormatter(formatter) +#logger.setLevel(DEBUG) +#logger.addHandler(handler) CMD_OK = "OK" @@ -53,13 +56,16 @@ class CmdRequestHandler(SocketServer.BaseRequestHandler): CmdRequestHandler.CMD.onecmd(self.data) ret = RCMD_RESULT_QUEUE.get() if (ret is not None): - logger.debug("ret:%s" % ret) + if logger != None: + logger.debug("ret:%s" % ret) self.request.send(ret) else: - logger.debug("ret is none") + if logger != None: + logger.debug("ret is none") self.request.send("") else: - logger.debug("CMD is None") + if logger != None: + logger.debug("CMD is None") self.request.send("") @@ -340,6 +346,7 @@ def clean_sec_cmd(cmdstr): return res + class Shell(cmd.Cmd): """SPP command prompt""" @@ -433,7 +440,8 @@ class Shell(cmd.Cmd): param = result + '\n' + message RCMD_RESULT_QUEUE.put(param) else: - logger.debug("unknown remote command = %s" % rcmd) + if logger != None: + logger.debug("unknown remote command = %s" % rcmd) def do_status(self, _): """Display Soft Patch Panel Status""" @@ -488,7 +496,7 @@ class Shell(cmd.Cmd): def do_playback(self, fname): """Playback commands from a file: PLAYBACK filename.cmd""" - + if fname == '': print("Record file is required!") else: -- 2.13.1