Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH 0/3] Update for Python 3 support
@ 2018-05-15  1:20 ogawa.yasufumi
  2018-05-15  1:20 ` [spp] [PATCH 1/3] controller: change importing for python3 ogawa.yasufumi
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: ogawa.yasufumi @ 2018-05-15  1:20 UTC (permalink / raw)
  To: ferruh.yigit, spp; +Cc: Yasufumi Ogawa

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

Hi,

This seriese of patches is for adding Python3 support for SPP
controller. It is still keeping compatibility with Python 2.

Second patch is for explicitly encode or decode for socket messages.
It is because default encoding is changed to utf-8 in Python 3 and
should be encoded/decoded for running on both of Python 2 and 3.

Thanks,
Yasufumi


Yasufumi Ogawa (3):
  controller: change importing for python3
  controller: fix encoding for socket
  docs: add description for python 3 support

 docs/guides/setup/getting_started.rst | 17 ++++++++++++--
 src/controller/conn_thread.py         | 19 ++++++++-------
 src/controller/shell.py               | 34 ++++++++++++++-------------
 src/controller/spp.py                 | 21 +++++++++--------
 src/controller/spp_common.py          |  2 +-
 src/controller/topo.py                |  4 ++--
 src/spp.py                            |  1 +
 7 files changed, 59 insertions(+), 39 deletions(-)

-- 
2.17.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [spp] [PATCH 1/3] controller: change importing for python3
  2018-05-15  1:20 [spp] [PATCH 0/3] Update for Python 3 support ogawa.yasufumi
@ 2018-05-15  1:20 ` ogawa.yasufumi
  2018-05-15  1:20 ` [spp] [PATCH 2/3] controller: fix encoding for socket ogawa.yasufumi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: ogawa.yasufumi @ 2018-05-15  1:20 UTC (permalink / raw)
  To: ferruh.yigit, spp; +Cc: Yasufumi Ogawa

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

This is the first patch for updating to python3. To keep backward
compatibility with python2, it uses future module.

To comply with python3, it uses absolute_import module in __future__
and changes importing modules with path info. Some of module name, for
instance Queue or SocketServer, are also changed to the names of
python3's.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/conn_thread.py |  8 +++++---
 src/controller/shell.py       | 28 +++++++++++++++-------------
 src/controller/spp.py         | 21 +++++++++++----------
 src/controller/spp_common.py  |  2 +-
 src/controller/topo.py        |  4 ++--
 src/spp.py                    |  1 +
 6 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/src/controller/conn_thread.py b/src/controller/conn_thread.py
index 6325843..8b2f8cd 100644
--- a/src/controller/conn_thread.py
+++ b/src/controller/conn_thread.py
@@ -3,11 +3,13 @@
 # Copyright(c) 2015-2016 Intel Corporation
 # Copyright(c) 2017-2018 Nippon Telegraph and Telephone Corporation
 
-from Queue import Queue
+from __future__ import absolute_import
+
+from queue import Queue
 import select
 import socket
-import spp_common
-from spp_common import logger
+from . import spp_common
+from .spp_common import logger
 import threading
 import traceback
 
diff --git a/src/controller/shell.py b/src/controller/shell.py
index e0d13ca..b04cc62 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -3,16 +3,18 @@
 # Copyright(c) 2015-2016 Intel Corporation
 # Copyright(c) 2017-2018 Nippon Telegraph and Telephone Corporation
 
+from __future__ import absolute_import
+
 import cmd
 import json
 import os
-from Queue import Empty
+from queue import Empty
 import re
-from shell_lib import common
-import spp_common
-from spp_common import logger
+from .shell_lib import common
+from . import spp_common
+from .spp_common import logger
 import subprocess
-import topo
+from . import topo
 
 
 class Shell(cmd.Cmd, object):
@@ -88,11 +90,11 @@ class Shell(cmd.Cmd, object):
     def print_status(self):
         """Display information about connected clients"""
 
-        print ("Soft Patch Panel Status :")
-        print ("primary: %d" % spp_common.PRIMARY)  # it is 1 if PRIMA == True
-        print ("secondary count: %d" % len(spp_common.SECONDARY_LIST))
+        print("Soft Patch Panel Status :")
+        print("primary: %d" % spp_common.PRIMARY)  # it is 1 if PRIMA == True
+        print("secondary count: %d" % len(spp_common.SECONDARY_LIST))
         for i in spp_common.SECONDARY_LIST:
-            print ("Connected secondary id: %d" % i)
+            print("Connected secondary id: %d" % i)
 
     def print_sec_status(self, msg):
         """Parse and print message from SPP secondary
@@ -143,11 +145,11 @@ class Shell(cmd.Cmd, object):
         if spp_common.PRIMARY:
             spp_common.MAIN2PRIMARY.put(command)
             recv = spp_common.PRIMARY2MAIN.get(True)
-            print (recv)
+            print(recv)
             return self.CMD_OK, recv
         else:
             recv = "primary not started"
-            print (recv)
+            print(recv)
             return self.CMD_NOTREADY, recv
 
     def command_secondary(self, sec_id, command):
@@ -332,8 +334,8 @@ class Shell(cmd.Cmd, object):
                 print(message)
                 self.response(self.CMD_ERROR, message)
         else:
-            print (cmds[0])
-            print ("first %s" % cmds[1])
+            print(cmds[0])
+            print("first %s" % cmds[1])
             self.response(self.CMD_ERROR, "invalid format")
 
     def complete_sec(self, text, line, begidx, endidx):
diff --git a/src/controller/spp.py b/src/controller/spp.py
index 757a1d4..62e9b60 100644
--- a/src/controller/spp.py
+++ b/src/controller/spp.py
@@ -3,22 +3,23 @@
 # Copyright(c) 2015-2016 Intel Corporation
 # Copyright(c) 2017-2018 Nippon Telegraph and Telephone Corporation
 
-from __future__ import print_function
+from __future__ import absolute_import
+# from __future__ import print_function
 
 import argparse
-from conn_thread import AcceptThread
-from conn_thread import PrimaryThread
-from shell import Shell
+from .conn_thread import AcceptThread
+from .conn_thread import PrimaryThread
+from .shell import Shell
 import socket
-import SocketServer
-import spp_common
-from spp_common import logger
+import socketserver
+from . import spp_common
+from .spp_common import logger
 import sys
 import threading
 import traceback
 
 
-class CmdRequestHandler(SocketServer.BaseRequestHandler):
+class CmdRequestHandler(socketserver.BaseRequestHandler):
     """Request handler for getting message from remote entities"""
 
     CMD = None  # contains a instance of Shell class
@@ -88,9 +89,9 @@ def main(argv):
     shell = Shell()
 
     # Run request handler as a TCP server thread
-    SocketServer.ThreadingTCPServer.allow_reuse_address = True
+    socketserver.ThreadingTCPServer.allow_reuse_address = True
     CmdRequestHandler.CMD = shell
-    command_server = SocketServer.ThreadingTCPServer(
+    command_server = socketserver.ThreadingTCPServer(
         (host, management_port), CmdRequestHandler)
 
     t = threading.Thread(target=command_server.serve_forever)
diff --git a/src/controller/spp_common.py b/src/controller/spp_common.py
index c507d55..6d5d83b 100644
--- a/src/controller/spp_common.py
+++ b/src/controller/spp_common.py
@@ -5,7 +5,7 @@
 
 import logging
 import os
-from Queue import Queue
+from queue import Queue
 
 # Setup logger object
 logger = logging.getLogger(__name__)
diff --git a/src/controller/topo.py b/src/controller/topo.py
index a09a873..c6347a4 100644
--- a/src/controller/topo.py
+++ b/src/controller/topo.py
@@ -4,8 +4,8 @@
 
 import os
 import re
-import spp_common
-from spp_common import logger
+from . import spp_common
+from .spp_common import logger
 import subprocess
 import traceback
 import uuid
diff --git a/src/spp.py b/src/spp.py
index f52e063..105dba8 100755
--- a/src/spp.py
+++ b/src/spp.py
@@ -3,6 +3,7 @@
 # Copyright(c) 2015-2016 Intel Corporation
 # Copyright(c) 2017-2018 Nippon Telegraph and Telephone Corporation
 
+from __future__ import absolute_import
 from controller import spp
 import sys
 
-- 
2.17.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [spp] [PATCH 2/3] controller: fix encoding for socket
  2018-05-15  1:20 [spp] [PATCH 0/3] Update for Python 3 support ogawa.yasufumi
  2018-05-15  1:20 ` [spp] [PATCH 1/3] controller: change importing for python3 ogawa.yasufumi
@ 2018-05-15  1:20 ` ogawa.yasufumi
  2018-05-15  1:20 ` [spp] [PATCH 3/3] docs: add description for python 3 support ogawa.yasufumi
  2018-05-23 20:11 ` [spp] [PATCH v2 0/3] Update for Python " ogawa.yasufumi
  3 siblings, 0 replies; 9+ messages in thread
From: ogawa.yasufumi @ 2018-05-15  1:20 UTC (permalink / raw)
  To: ferruh.yigit, spp; +Cc: Yasufumi Ogawa

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

For python3, it is required to treat str and bytes explicitly for
sending and receiving messages via socket.

SPP controller has several socket interfaces between primary and
secondary processes. It means that messages must be encoded before
sending or decoded after receiving vise versa.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/conn_thread.py | 11 ++++++-----
 src/controller/shell.py       |  6 +++---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/controller/conn_thread.py b/src/controller/conn_thread.py
index 8b2f8cd..2ec4e2a 100644
--- a/src/controller/conn_thread.py
+++ b/src/controller/conn_thread.py
@@ -56,7 +56,7 @@ class ConnectionThread(threading.Thread):
                 # 1024 stands for bytes of data to be received
                 data = self.conn.recv(1024)
                 if data:
-                    msg = "%s" % data
+                    msg = "%s" % data.decode('utf-8')
                     spp_common.SEC2MAIN[self.client_id].put(msg)
                 else:
                     spp_common.SEC2MAIN[self.client_id].put(
@@ -96,7 +96,7 @@ class AcceptThread(threading.Thread):
         """Get client_id from client"""
 
         try:
-            conn.send("_get_client_id")
+            conn.send(b'_get_client_id')
         except KeyError:
             return -1
 
@@ -106,7 +106,7 @@ class AcceptThread(threading.Thread):
 
         if logger is not None:
             logger.debug("data: %s" % data)
-        client_id = int(data.strip('\0'))
+        client_id = int(data.decode('utf-8').strip('\0'))
 
         if client_id < 0 or client_id > spp_common.MAX_SECONDARY:
             logger.debug("Failed to get client_id: %d" % client_id)
@@ -139,7 +139,8 @@ class AcceptThread(threading.Thread):
         if free_client_id < 0:
             return -1
 
-        conn.send("_set_client_id %u" % free_client_id)
+        msg = "_set_client_id %u" % free_client_id
+        conn.send(msg.encode('utf-8'))
         data = conn.recv(1024)
 
         return free_client_id
@@ -240,7 +241,7 @@ class PrimaryThread(threading.Thread):
                     data = conn.recv(1024)
                     if data:
                         spp_common.PRIMARY2MAIN.put(
-                            "recv:%s:{%s}" % (str(addr), data))
+                            "recv:%s:{%s}" % (str(addr), data.decode('utf-8')))
                     else:
                         spp_common.PRIMARY2MAIN.put("closing:" + str(addr))
                         conn.close()
diff --git a/src/controller/shell.py b/src/controller/shell.py
index b04cc62..137c42b 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -143,7 +143,7 @@ class Shell(cmd.Cmd, object):
         """Send command to primary process"""
 
         if spp_common.PRIMARY:
-            spp_common.MAIN2PRIMARY.put(command)
+            spp_common.MAIN2PRIMARY.put(command.encode('utf-8'))
             recv = spp_common.PRIMARY2MAIN.get(True)
             print(recv)
             return self.CMD_OK, recv
@@ -156,7 +156,7 @@ class Shell(cmd.Cmd, object):
         """Send command to secondary process with sec_id"""
 
         if sec_id in spp_common.SECONDARY_LIST:
-            spp_common.MAIN2SEC[sec_id].put(command)
+            spp_common.MAIN2SEC[sec_id].put(command.encode('utf-8'))
             recv = spp_common.SEC2MAIN[sec_id].get(True)
             if command == 'status':
                 self.print_sec_status(recv)
@@ -234,7 +234,7 @@ class Shell(cmd.Cmd, object):
 
         if (rcmd == spp_common.REMOTE_COMMAND):
             param = result + '\n' + message
-            spp_common.RCMD_RESULT_QUEUE.put(param)
+            spp_common.RCMD_RESULT_QUEUE.put(param.encode('utf-8'))
         else:
             if logger is not None:
                 logger.debug("unknown remote command = %s" % rcmd)
-- 
2.17.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [spp] [PATCH 3/3] docs: add description for python 3 support
  2018-05-15  1:20 [spp] [PATCH 0/3] Update for Python 3 support ogawa.yasufumi
  2018-05-15  1:20 ` [spp] [PATCH 1/3] controller: change importing for python3 ogawa.yasufumi
  2018-05-15  1:20 ` [spp] [PATCH 2/3] controller: fix encoding for socket ogawa.yasufumi
@ 2018-05-15  1:20 ` ogawa.yasufumi
  2018-05-23 20:11 ` [spp] [PATCH v2 0/3] Update for Python " ogawa.yasufumi
  3 siblings, 0 replies; 9+ messages in thread
From: ogawa.yasufumi @ 2018-05-15  1:20 UTC (permalink / raw)
  To: ferruh.yigit, spp; +Cc: Yasufumi Ogawa

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

Add description to explain that SPP controller supports Python 3 while
keeping compatibility for Python 2.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 docs/guides/setup/getting_started.rst | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/docs/guides/setup/getting_started.rst b/docs/guides/setup/getting_started.rst
index 04df517..75dc68d 100644
--- a/docs/guides/setup/getting_started.rst
+++ b/docs/guides/setup/getting_started.rst
@@ -120,6 +120,9 @@ Refer to `DPDK documentation
 For Linux, see `Getting Started Guide for Linux
 <http://www.dpdk.org/doc/guides/linux_gsg/index.html>`_ .
 
+DPDK
+~~~~
+
 First, download and compile DPDK in any directory.
 Compiling DPDK takes a few minutes.
 
@@ -132,6 +135,9 @@ Compiling DPDK takes a few minutes.
     $ export RTE_TARGET=x86_64-native-linuxapp-gcc  # depends on your env
     $ make install T=$RTE_TARGET
 
+SPP
+~~~
+
 Then, download and compile SPP in any directory.
 
 .. code-block:: console
@@ -142,6 +148,13 @@ Then, download and compile SPP in any directory.
     $ make  # Confirm that $RTE_SDK and $RTE_TARGET are set
 
 
+Python 2 or 3 ?
+~~~~~~~~~~~~~~~
+
+You need to install Python for using usertools of DPDK or SPP controller.
+DPDK and SPP support both of Python2 and 3.
+
+
 Binding Network Ports to DPDK
 -----------------------------
 
@@ -238,8 +251,8 @@ cannot find it by using ``ifconfig`` or ``ip``.
     ....
 
 
-Run DPDK Sample Application
----------------------------
+Confirm DPDK is setup properly
+------------------------------
 
 You had better to run DPDK sample application before SPP
 as checking DPDK is setup properly.
-- 
2.17.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [spp] [PATCH v2 0/3] Update for Python 3 support
  2018-05-15  1:20 [spp] [PATCH 0/3] Update for Python 3 support ogawa.yasufumi
                   ` (2 preceding siblings ...)
  2018-05-15  1:20 ` [spp] [PATCH 3/3] docs: add description for python 3 support ogawa.yasufumi
@ 2018-05-23 20:11 ` ogawa.yasufumi
  2018-05-23 20:11   ` [spp] [PATCH v2 1/3] controller: change importing for python3 ogawa.yasufumi
                     ` (3 more replies)
  3 siblings, 4 replies; 9+ messages in thread
From: ogawa.yasufumi @ 2018-05-23 20:11 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: spp, Yasufumi Ogawa

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

Hi,

This patch set is for adding Python 3 support. This update is needed
to follow the previous patches of license update bacause it changes the
top of files and it affects codes importing modules. The difference
from v1 is only the number of line for the importing.

Thanks,
Yasufumi


Yasufumi Ogawa (3):
  controller: change importing for python3
  controller: fix encoding for socket
  docs: add description for python 3 support

 docs/guides/setup/getting_started.rst | 17 ++++++++++++--
 src/controller/conn_thread.py         | 19 ++++++++-------
 src/controller/shell.py               | 34 ++++++++++++++-------------
 src/controller/spp.py                 | 21 +++++++++--------
 src/controller/spp_common.py          |  2 +-
 src/controller/topo.py                |  4 ++--
 src/spp.py                            |  1 +
 7 files changed, 59 insertions(+), 39 deletions(-)

-- 
2.17.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [spp] [PATCH v2 1/3] controller: change importing for python3
  2018-05-23 20:11 ` [spp] [PATCH v2 0/3] Update for Python " ogawa.yasufumi
@ 2018-05-23 20:11   ` ogawa.yasufumi
  2018-05-23 20:11   ` [spp] [PATCH v2 2/3] controller: fix encoding for socket ogawa.yasufumi
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: ogawa.yasufumi @ 2018-05-23 20:11 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: spp, Yasufumi Ogawa

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

This is the first patch for updating to python3. To keep backward
compatibility with python2, it uses future module.

To comply with python3, it uses absolute_import module in __future__
and changes importing modules with path info. Some of module name, for
instance Queue or SocketServer, are also changed to the names of
python3's.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/conn_thread.py |  8 +++++---
 src/controller/shell.py       | 28 +++++++++++++++-------------
 src/controller/spp.py         | 21 +++++++++++----------
 src/controller/spp_common.py  |  2 +-
 src/controller/topo.py        |  4 ++--
 src/spp.py                    |  1 +
 6 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/src/controller/conn_thread.py b/src/controller/conn_thread.py
index e42b0e8..bffdcee 100644
--- a/src/controller/conn_thread.py
+++ b/src/controller/conn_thread.py
@@ -2,11 +2,13 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2015-2016 Intel Corporation
 
-from Queue import Queue
+from __future__ import absolute_import
+
+from queue import Queue
 import select
 import socket
-import spp_common
-from spp_common import logger
+from . import spp_common
+from .spp_common import logger
 import threading
 import traceback
 
diff --git a/src/controller/shell.py b/src/controller/shell.py
index eac6aec..6bd9cb0 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -2,16 +2,18 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2015-2016 Intel Corporation
 
+from __future__ import absolute_import
+
 import cmd
 import json
 import os
-from Queue import Empty
+from queue import Empty
 import re
-from shell_lib import common
-import spp_common
-from spp_common import logger
+from .shell_lib import common
+from . import spp_common
+from .spp_common import logger
 import subprocess
-import topo
+from . import topo
 
 
 class Shell(cmd.Cmd, object):
@@ -87,11 +89,11 @@ class Shell(cmd.Cmd, object):
     def print_status(self):
         """Display information about connected clients"""
 
-        print ("Soft Patch Panel Status :")
-        print ("primary: %d" % spp_common.PRIMARY)  # it is 1 if PRIMA == True
-        print ("secondary count: %d" % len(spp_common.SECONDARY_LIST))
+        print("Soft Patch Panel Status :")
+        print("primary: %d" % spp_common.PRIMARY)  # it is 1 if PRIMA == True
+        print("secondary count: %d" % len(spp_common.SECONDARY_LIST))
         for i in spp_common.SECONDARY_LIST:
-            print ("Connected secondary id: %d" % i)
+            print("Connected secondary id: %d" % i)
 
     def print_sec_status(self, msg):
         """Parse and print message from SPP secondary
@@ -142,11 +144,11 @@ class Shell(cmd.Cmd, object):
         if spp_common.PRIMARY:
             spp_common.MAIN2PRIMARY.put(command)
             recv = spp_common.PRIMARY2MAIN.get(True)
-            print (recv)
+            print(recv)
             return self.CMD_OK, recv
         else:
             recv = "primary not started"
-            print (recv)
+            print(recv)
             return self.CMD_NOTREADY, recv
 
     def command_secondary(self, sec_id, command):
@@ -331,8 +333,8 @@ class Shell(cmd.Cmd, object):
                 print(message)
                 self.response(self.CMD_ERROR, message)
         else:
-            print (cmds[0])
-            print ("first %s" % cmds[1])
+            print(cmds[0])
+            print("first %s" % cmds[1])
             self.response(self.CMD_ERROR, "invalid format")
 
     def complete_sec(self, text, line, begidx, endidx):
diff --git a/src/controller/spp.py b/src/controller/spp.py
index 9c13d59..57604de 100644
--- a/src/controller/spp.py
+++ b/src/controller/spp.py
@@ -2,22 +2,23 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2015-2016 Intel Corporation
 
-from __future__ import print_function
+from __future__ import absolute_import
+# from __future__ import print_function
 
 import argparse
-from conn_thread import AcceptThread
-from conn_thread import PrimaryThread
-from shell import Shell
+from .conn_thread import AcceptThread
+from .conn_thread import PrimaryThread
+from .shell import Shell
 import socket
-import SocketServer
-import spp_common
-from spp_common import logger
+import socketserver
+from . import spp_common
+from .spp_common import logger
 import sys
 import threading
 import traceback
 
 
-class CmdRequestHandler(SocketServer.BaseRequestHandler):
+class CmdRequestHandler(socketserver.BaseRequestHandler):
     """Request handler for getting message from remote entities"""
 
     CMD = None  # contains a instance of Shell class
@@ -87,9 +88,9 @@ def main(argv):
     shell = Shell()
 
     # Run request handler as a TCP server thread
-    SocketServer.ThreadingTCPServer.allow_reuse_address = True
+    socketserver.ThreadingTCPServer.allow_reuse_address = True
     CmdRequestHandler.CMD = shell
-    command_server = SocketServer.ThreadingTCPServer(
+    command_server = socketserver.ThreadingTCPServer(
         (host, management_port), CmdRequestHandler)
 
     t = threading.Thread(target=command_server.serve_forever)
diff --git a/src/controller/spp_common.py b/src/controller/spp_common.py
index d89461b..80fab76 100644
--- a/src/controller/spp_common.py
+++ b/src/controller/spp_common.py
@@ -4,7 +4,7 @@
 
 import logging
 import os
-from Queue import Queue
+from queue import Queue
 
 # Setup logger object
 logger = logging.getLogger(__name__)
diff --git a/src/controller/topo.py b/src/controller/topo.py
index a09a873..c6347a4 100644
--- a/src/controller/topo.py
+++ b/src/controller/topo.py
@@ -4,8 +4,8 @@
 
 import os
 import re
-import spp_common
-from spp_common import logger
+from . import spp_common
+from .spp_common import logger
 import subprocess
 import traceback
 import uuid
diff --git a/src/spp.py b/src/spp.py
index 5c63924..62606e7 100755
--- a/src/spp.py
+++ b/src/spp.py
@@ -2,6 +2,7 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2015-2016 Intel Corporation
 
+from __future__ import absolute_import
 from controller import spp
 import sys
 
-- 
2.17.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [spp] [PATCH v2 2/3] controller: fix encoding for socket
  2018-05-23 20:11 ` [spp] [PATCH v2 0/3] Update for Python " ogawa.yasufumi
  2018-05-23 20:11   ` [spp] [PATCH v2 1/3] controller: change importing for python3 ogawa.yasufumi
@ 2018-05-23 20:11   ` ogawa.yasufumi
  2018-05-23 20:11   ` [spp] [PATCH v2 3/3] docs: add description for python 3 support ogawa.yasufumi
  2018-05-24 13:18   ` [spp] [PATCH v2 0/3] Update for Python " Ferruh Yigit
  3 siblings, 0 replies; 9+ messages in thread
From: ogawa.yasufumi @ 2018-05-23 20:11 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: spp, Yasufumi Ogawa

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

For python3, it is required to treat str and bytes explicitly for
sending and receiving messages via socket.

SPP controller has several socket interfaces between primary and
secondary processes. It means that messages must be encoded before
sending or decoded after receiving vise versa.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/conn_thread.py | 11 ++++++-----
 src/controller/shell.py       |  6 +++---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/controller/conn_thread.py b/src/controller/conn_thread.py
index bffdcee..e524e84 100644
--- a/src/controller/conn_thread.py
+++ b/src/controller/conn_thread.py
@@ -55,7 +55,7 @@ class ConnectionThread(threading.Thread):
                 # 1024 stands for bytes of data to be received
                 data = self.conn.recv(1024)
                 if data:
-                    msg = "%s" % data
+                    msg = "%s" % data.decode('utf-8')
                     spp_common.SEC2MAIN[self.client_id].put(msg)
                 else:
                     spp_common.SEC2MAIN[self.client_id].put(
@@ -95,7 +95,7 @@ class AcceptThread(threading.Thread):
         """Get client_id from client"""
 
         try:
-            conn.send("_get_client_id")
+            conn.send(b'_get_client_id')
         except KeyError:
             return -1
 
@@ -105,7 +105,7 @@ class AcceptThread(threading.Thread):
 
         if logger is not None:
             logger.debug("data: %s" % data)
-        client_id = int(data.strip('\0'))
+        client_id = int(data.decode('utf-8').strip('\0'))
 
         if client_id < 0 or client_id > spp_common.MAX_SECONDARY:
             logger.debug("Failed to get client_id: %d" % client_id)
@@ -138,7 +138,8 @@ class AcceptThread(threading.Thread):
         if free_client_id < 0:
             return -1
 
-        conn.send("_set_client_id %u" % free_client_id)
+        msg = "_set_client_id %u" % free_client_id
+        conn.send(msg.encode('utf-8'))
         data = conn.recv(1024)
 
         return free_client_id
@@ -239,7 +240,7 @@ class PrimaryThread(threading.Thread):
                     data = conn.recv(1024)
                     if data:
                         spp_common.PRIMARY2MAIN.put(
-                            "recv:%s:{%s}" % (str(addr), data))
+                            "recv:%s:{%s}" % (str(addr), data.decode('utf-8')))
                     else:
                         spp_common.PRIMARY2MAIN.put("closing:" + str(addr))
                         conn.close()
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 6bd9cb0..dc6eb34 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -142,7 +142,7 @@ class Shell(cmd.Cmd, object):
         """Send command to primary process"""
 
         if spp_common.PRIMARY:
-            spp_common.MAIN2PRIMARY.put(command)
+            spp_common.MAIN2PRIMARY.put(command.encode('utf-8'))
             recv = spp_common.PRIMARY2MAIN.get(True)
             print(recv)
             return self.CMD_OK, recv
@@ -155,7 +155,7 @@ class Shell(cmd.Cmd, object):
         """Send command to secondary process with sec_id"""
 
         if sec_id in spp_common.SECONDARY_LIST:
-            spp_common.MAIN2SEC[sec_id].put(command)
+            spp_common.MAIN2SEC[sec_id].put(command.encode('utf-8'))
             recv = spp_common.SEC2MAIN[sec_id].get(True)
             if command == 'status':
                 self.print_sec_status(recv)
@@ -233,7 +233,7 @@ class Shell(cmd.Cmd, object):
 
         if (rcmd == spp_common.REMOTE_COMMAND):
             param = result + '\n' + message
-            spp_common.RCMD_RESULT_QUEUE.put(param)
+            spp_common.RCMD_RESULT_QUEUE.put(param.encode('utf-8'))
         else:
             if logger is not None:
                 logger.debug("unknown remote command = %s" % rcmd)
-- 
2.17.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [spp] [PATCH v2 3/3] docs: add description for python 3 support
  2018-05-23 20:11 ` [spp] [PATCH v2 0/3] Update for Python " ogawa.yasufumi
  2018-05-23 20:11   ` [spp] [PATCH v2 1/3] controller: change importing for python3 ogawa.yasufumi
  2018-05-23 20:11   ` [spp] [PATCH v2 2/3] controller: fix encoding for socket ogawa.yasufumi
@ 2018-05-23 20:11   ` ogawa.yasufumi
  2018-05-24 13:18   ` [spp] [PATCH v2 0/3] Update for Python " Ferruh Yigit
  3 siblings, 0 replies; 9+ messages in thread
From: ogawa.yasufumi @ 2018-05-23 20:11 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: spp, Yasufumi Ogawa

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

Add description to explain that SPP controller supports Python 3 while
keeping compatibility for Python 2.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 docs/guides/setup/getting_started.rst | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/docs/guides/setup/getting_started.rst b/docs/guides/setup/getting_started.rst
index 04df517..75dc68d 100644
--- a/docs/guides/setup/getting_started.rst
+++ b/docs/guides/setup/getting_started.rst
@@ -120,6 +120,9 @@ Refer to `DPDK documentation
 For Linux, see `Getting Started Guide for Linux
 <http://www.dpdk.org/doc/guides/linux_gsg/index.html>`_ .
 
+DPDK
+~~~~
+
 First, download and compile DPDK in any directory.
 Compiling DPDK takes a few minutes.
 
@@ -132,6 +135,9 @@ Compiling DPDK takes a few minutes.
     $ export RTE_TARGET=x86_64-native-linuxapp-gcc  # depends on your env
     $ make install T=$RTE_TARGET
 
+SPP
+~~~
+
 Then, download and compile SPP in any directory.
 
 .. code-block:: console
@@ -142,6 +148,13 @@ Then, download and compile SPP in any directory.
     $ make  # Confirm that $RTE_SDK and $RTE_TARGET are set
 
 
+Python 2 or 3 ?
+~~~~~~~~~~~~~~~
+
+You need to install Python for using usertools of DPDK or SPP controller.
+DPDK and SPP support both of Python2 and 3.
+
+
 Binding Network Ports to DPDK
 -----------------------------
 
@@ -238,8 +251,8 @@ cannot find it by using ``ifconfig`` or ``ip``.
     ....
 
 
-Run DPDK Sample Application
----------------------------
+Confirm DPDK is setup properly
+------------------------------
 
 You had better to run DPDK sample application before SPP
 as checking DPDK is setup properly.
-- 
2.17.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [spp] [PATCH v2 0/3] Update for Python 3 support
  2018-05-23 20:11 ` [spp] [PATCH v2 0/3] Update for Python " ogawa.yasufumi
                     ` (2 preceding siblings ...)
  2018-05-23 20:11   ` [spp] [PATCH v2 3/3] docs: add description for python 3 support ogawa.yasufumi
@ 2018-05-24 13:18   ` Ferruh Yigit
  3 siblings, 0 replies; 9+ messages in thread
From: Ferruh Yigit @ 2018-05-24 13:18 UTC (permalink / raw)
  To: ogawa.yasufumi; +Cc: spp

On 5/23/2018 9:11 PM, ogawa.yasufumi@lab.ntt.co.jp wrote:
> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> 
> Hi,
> 
> This patch set is for adding Python 3 support. This update is needed
> to follow the previous patches of license update bacause it changes the
> top of files and it affects codes importing modules. The difference
> from v1 is only the number of line for the importing.
> 
> Thanks,
> Yasufumi
> 
> 
> Yasufumi Ogawa (3):
>   controller: change importing for python3
>   controller: fix encoding for socket
>   docs: add description for python 3 support

Series applied to dpdk-next-net/master, thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-05-24 13:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-15  1:20 [spp] [PATCH 0/3] Update for Python 3 support ogawa.yasufumi
2018-05-15  1:20 ` [spp] [PATCH 1/3] controller: change importing for python3 ogawa.yasufumi
2018-05-15  1:20 ` [spp] [PATCH 2/3] controller: fix encoding for socket ogawa.yasufumi
2018-05-15  1:20 ` [spp] [PATCH 3/3] docs: add description for python 3 support ogawa.yasufumi
2018-05-23 20:11 ` [spp] [PATCH v2 0/3] Update for Python " ogawa.yasufumi
2018-05-23 20:11   ` [spp] [PATCH v2 1/3] controller: change importing for python3 ogawa.yasufumi
2018-05-23 20:11   ` [spp] [PATCH v2 2/3] controller: fix encoding for socket ogawa.yasufumi
2018-05-23 20:11   ` [spp] [PATCH v2 3/3] docs: add description for python 3 support ogawa.yasufumi
2018-05-24 13:18   ` [spp] [PATCH v2 0/3] Update for Python " Ferruh Yigit

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).