On Thu, 8 Mar 2012 09:55:57 +0900
FUJITA Tomonori <[email protected]> wrote:

> 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

On the top of the above patch, I like to convert the simple_isolation
stuff to use memcached in the following way.

We need an abstraction layer to hide storage protocols (memcached,
rdb, whatever) but I like to start with the straight conversion first.

In addition, we need to think about the data structures of the simple
isolation. The current data structures is not ideal for simple storage
like KVS. But again, I like to start with the straight conversion.

=
>From c9e795088bd3fbe5aced90cb39315785fd3b4e45 Mon Sep 17 00:00:00 2001
From: FUJITA Tomonori <[email protected]>
Date: Wed, 7 Mar 2012 19:21:36 -0800
Subject: [PATCH] convert MacToNetwork to use memcached

Signed-off-by: FUJITA Tomonori <[email protected]>
---
 ryu/controller/mac_to_network.py |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/ryu/controller/mac_to_network.py b/ryu/controller/mac_to_network.py
index bc18929..4bfe8dc 100644
--- a/ryu/controller/mac_to_network.py
+++ b/ryu/controller/mac_to_network.py
@@ -14,6 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import logging
+import memcache
 
 from ryu.exception import MacAddressDuplicated
 from ryu.lib.mac import haddr_to_str
@@ -24,20 +25,24 @@ LOG = logging.getLogger('ryu.controller.mac_to_network')
 class MacToNetwork(object):
     def __init__(self, nw):
         self.mac_to_net = {}
-        self.dpid = {}
-        self.nw = nw
 
     def get_network(self, mac, default=None):
-        return self.mac_to_net.get(mac, default)
+        mc = memcache.Client(['127.0.0.1:11211'])
+        net = mc.get(mac)
+        if net:
+            return net
+        else:
+            default
 
     def add_mac(self, mac, nw_id, nw_id_external=None):
-        _nw_id = self.mac_to_net.get(mac)
+        mc = memcache.Client(['127.0.0.1:11211'])
+        _nw_id = mc.get(mac)
         if _nw_id == nw_id:
             return
 
         # allow changing from nw_id_external to known nw id
         if _nw_id is None or _nw_id == nw_id_external:
-            self.mac_to_net[mac] = nw_id
+            mc.set(mac, new_id)
             LOG.debug('overwrite nw_id: mac %s nw old %s new %s',
                       haddr_to_str(mac), _nw_id, nw_id)
             return
@@ -53,4 +58,5 @@ class MacToNetwork(object):
         raise MacAddressDuplicated(mac=mac)
 
     def del_mac(self, mac):
-        del self.mac_to_net[mac]
+        mc = memcache.Client(['127.0.0.1:11211'])
+        mc.delete(mac)
-- 
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