Ryu is going to support many tunnel technology. Its tunnel key range depends.
So make it configurable instead of hard coded value.

Signed-off-by: Isaku Yamahata <[email protected]>
---
 etc/quantum/plugins/ryu/ryu.ini           |    7 +++++++
 quantum/plugins/ryu/db/api.py             |   21 ++++++++++++---------
 quantum/plugins/ryu/ryu_quantum_plugin.py |    8 +++++++-
 3 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/etc/quantum/plugins/ryu/ryu.ini b/etc/quantum/plugins/ryu/ryu.ini
index 157afae..fe5dbe8 100644
--- a/etc/quantum/plugins/ryu/ryu.ini
+++ b/etc/quantum/plugins/ryu/ryu.ini
@@ -34,6 +34,13 @@ ovsdb_manager = ptcp:6632
 # ovsdb_ip = <host IP address of ovsdb>
 # ovsdb_physical_interface = eth0
 
+[TUNNEL]
+# the maximum tunnel key
+# VLAN: 4095, VXLAN/NVGRE: 24 bit, STT: 64 bit
+key_max = 4095
+# key_max = 0xffffff
+# key_max = 0xffffffffffffffff
+
 [AGENT]
 # Change to "sudo quantum-rootwrap" to limit commands that can be run
 # as root.
diff --git a/quantum/plugins/ryu/db/api.py b/quantum/plugins/ryu/db/api.py
index b64dbcf..9c4a423 100644
--- a/quantum/plugins/ryu/db/api.py
+++ b/quantum/plugins/ryu/db/api.py
@@ -106,15 +106,16 @@ def port_binding_all_list():
 
 
 _TUNNEL_KEY_MIN = 0
-_TUNNEL_KEY_MAX = 0xffffffff
+# the maximum value of tunnel key is configurable
+# because it depends on tunnel technology(VLAN, VXLAN, NVGRE, STT...)
 
 
-def _tunnel_key_last(session):
+def _tunnel_key_last(session, tunnel_key_max):
     try:
         return session.query(models.TunnelKeyLast).one()
     except exc.MultipleResultsFound:
         max_key = session.query(func.max(models.TunnelKeyLast.last_key))
-        if max_key > _TUNNEL_KEY_MAX:
+        if max_key > tunnel_key_max:
             max_key = _TUNNEL_KEY_MIN
 
         session.query(models.TunnelKeyLast).delete()
@@ -127,7 +128,7 @@ def _tunnel_key_last(session):
     return session.query(models.TunnelKeyLast).one()
 
 
-def _tunnel_key_allocate(session, last_key):
+def _tunnel_key_allocate(session, last_key, tunnel_key_max):
     """
     Try to find unused tunnel key in TunnelKey table starting
     from last_key + 1.
@@ -160,19 +161,21 @@ def _tunnel_key_allocate(session, last_key):
     new_key = new_key[0]  # the result is tuple.
 
     LOG.debug("last_key %s new_key %s", last_key, new_key)
-    if new_key > _TUNNEL_KEY_MAX:
+    if new_key > tunnel_key_max:
         LOG.debug("no key found")
         raise exc.NoResultFound
     return new_key
 
 
-def tunnel_key_allocate(network_id):
+def tunnel_key_allocate(network_id, tunnel_key_max):
     session = db.get_session()
-    last_key = _tunnel_key_last(session)
+    last_key = _tunnel_key_last(session, tunnel_key_max)
     try:
-        new_key = _tunnel_key_allocate(session, last_key.last_key)
+        new_key = _tunnel_key_allocate(session,
+                                       last_key.last_key, tunnel_key_max)
     except exc.NoResultFound:
-        new_key = _tunnel_key_allocate(session, _TUNNEL_KEY_MIN)
+        new_key = _tunnel_key_allocate(session,
+                                       _TUNNEL_KEY_MIN, tunnel_key_max)
 
     tunnel_key = models.TunnelKey(network_id, new_key)
     last_key.last_key = new_key
diff --git a/quantum/plugins/ryu/ryu_quantum_plugin.py 
b/quantum/plugins/ryu/ryu_quantum_plugin.py
index b952264..9a658b9 100644
--- a/quantum/plugins/ryu/ryu_quantum_plugin.py
+++ b/quantum/plugins/ryu/ryu_quantum_plugin.py
@@ -36,10 +36,16 @@ CONF_FILE = find_config_file({"plugin": "ryu"}, None, 
"ryu.ini")
 
 
 class OFPRyuDriver(ovs_quantum_plugin_base.OVSQuantumPluginDriverBase):
+    # VLAN:16 bit, VXLAN/NVGRE: 24 bit, STT: 64 bit
+    _TUNNEL_KEY_MAX_DEFAULT = 4095
+
     def __init__(self, config):
         super(OFPRyuDriver, self).__init__()
         ofp_con_host = config.get("OVS", "openflow-controller")
         ofp_api_host = config.get("OVS", "openflow-rest-api")
+        self.tunnel_key_max = self._TUNNEL_KEY_MAX_DEFAULT
+        if config.has_option("TUNNEL", "key_max"):
+            self.tunnel_key_max = int(config.get("TUNNEL", "key_max"), 0)
 
         if ofp_con_host is None or ofp_api_host is None:
             raise q_exc.Invalid("invalid configuration. check ryu.ini")
@@ -73,7 +79,7 @@ class 
OFPRyuDriver(ovs_quantum_plugin_base.OVSQuantumPluginDriverBase):
         ryu_db.tunnel_port_request_initialize()
 
     def create_network(self, net):
-        tunnel_key = ryu_db.tunnel_key_allocate(net.uuid)
+        tunnel_key = ryu_db.tunnel_key_allocate(net.uuid, self.tunnel_key_max)
         self.client.create_network(net.uuid)
         self.gt_client.create_tunnel_key(net.uuid, tunnel_key)
 
-- 
1.7.1.1


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to