ryu is a distributed NOS, that is, multiple ryu instances work
together. They need to share some information (e.g. set of ports in a
logically L2 network) by using some kinda storage, KVS, database, NFS,
or something else.

This adds the simple memcached server feature to ryu so that you can
develop and test ryu without setting up Memcached.

Several NoSQL implementations support Memcached protocol so you can
switch to one of these real NoSQL implementations.

Signed-off-by: FUJITA Tomonori <[email protected]>
---
 bin/ryu-manager           |    6 +++++
 ryu/app/fake_memcached.py |   49 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 0 deletions(-)
 create mode 100644 ryu/app/fake_memcached.py

diff --git a/bin/ryu-manager b/bin/ryu-manager
index ef8355b..b36b698 100755
--- a/bin/ryu-manager
+++ b/bin/ryu-manager
@@ -28,6 +28,7 @@ log.early_init_log(logging.DEBUG)
 
 from ryu import utils
 from ryu.app import wsapi
+from ryu.app import fake_memcached
 from ryu.base.app_manager import AppManager
 from ryu.controller import controller
 from ryu.controller import dpset
@@ -65,6 +66,11 @@ def main():
     thr = gevent.spawn_later(0, ws)
     services.append(thr)
 
+    # fake memcached server
+    mc = fake_memcached.FakeMemcached()
+    thr = gevent.spawn_later(0, mc)
+    services.append(thr)
+
     gevent.joinall(services)
 
 if __name__ == "__main__":
diff --git a/ryu/app/fake_memcached.py b/ryu/app/fake_memcached.py
new file mode 100644
index 0000000..020817e
--- /dev/null
+++ b/ryu/app/fake_memcached.py
@@ -0,0 +1,49 @@
+from gevent.server import StreamServer
+
+MSG_ERROR = "ERROR\r\n"
+MSG_END = "END\r\n"
+MSG_STORED = "STORED\r\n"
+
+table = {}
+
+class FakeMemcached:
+    def __call__(self):
+        server = StreamServer(('', 11211), self.application)
+        server.serve_forever()
+
+    def application(self, socket, address):
+        fileobj = socket.makefile()
+        get_op = 0
+        while True:
+            line = fileobj.readline()
+            if not line:
+                break
+            if get_op == 0:            
+                line = line.split()
+                if line[0] == "set":
+                    if len(line) == 5:
+                        get_op = 1
+                        key = line[1]
+                        flags = line[2]
+                        expire = line[3]
+                        length = line[4]
+                    else:
+                        fileobj.write(MSG_ERROR)
+                        fileobj.flush()
+                elif line[0] == "get":
+                    if line[1] in table:
+                        fileobj.write("VALUE " + table[line[1]] + MSG_END)
+                        fileobj.flush()
+                    else:
+                        fileobj.write(MSG_END)
+                        fileobj.flush()
+                else:
+                    fileobj.write(MSG_ERROR)
+                    fileobj.flush()
+            else:
+                get_op = 0
+                table[key] = key + " " + flags + " " + length + "\r\n" + line
+                fileobj.write(MSG_STORED)
+                fileobj.flush()
+            
+        
-- 
1.7.4.4


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to