Signed-off-by: Isaku Yamahata <[email protected]>
---
 ryu/lib/of_config/api.py |   85 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100644 ryu/lib/of_config/api.py

diff --git a/ryu/lib/of_config/api.py b/ryu/lib/of_config/api.py
new file mode 100644
index 0000000..6de06a3
--- /dev/null
+++ b/ryu/lib/of_config/api.py
@@ -0,0 +1,85 @@
+# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2013 Isaku Yamahata <yamahata at private email ne jp>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from ryu.lib.of_config import events as ofc_events
+from ryu.lib.of_config import manager as ofc_manager
+
+
+class OFConfigSessionAPI(object):
+    def __init__(self, app, *conn_args, **conn_kwargs):
+        super(OFConfigSessionAPI, self).__init__()
+        self._app = app
+        self._session_id = None
+        self._conn_args = conn_args
+        self._conn_kwargs = conn_kwargs
+
+    def __del__(self):
+        self.close_session()
+
+    def __enter__(self):
+        self.connect()
+        return self
+
+    def __exit__(self):
+        self.close_session()
+        return False
+
+    def connect(self):
+        if self._session_id:
+            return
+        conn_req = ofc_events.EventOFConfigRequestConnect(
+            ofc_manager.OFConfigManager.__name__,
+            self._conn_args, self._conn_kwargs)
+        reply = self._app.send_request(conn_req)
+        self._session_id = reply()
+
+    def close_session(self):
+        if not self._session_id:
+            return
+        req = ofc_events.EventOFConfigRequestCloseSession(
+            ofc_manager.OFConfigManager.__name__, self._session_id)
+        reply = self._app.send_request(req)
+        reply()
+        self._session_id = None
+
+    def _send_req(self, method, **kwargs):
+        assert self._session_id
+        req = ofc_events.EventOFConfigRequest(
+            ofc_manager.OFConfigManager.__name__,
+            method, self._session_id, kwargs)
+        reply = self._app.send_request(req)
+        return reply()
+
+    def server_capabilities(self):
+        return self._send_req('server_capabilities')
+
+    def client_capabilities(self):
+        return self._send_req('client_capabilities')
+
+    def get(self, filter=None):
+        return self._send_req('get', filter=filter)
+
+    def get_config(self, source, filter=None):
+        return self._send_req('get_config', source=source, filter=filter)
+
+    def edit_config(self, target, config, default_operation=None,
+                    test_option=None, error_option=None):
+        return self._send_req(
+            'edit_config', target=target, config=config,
+            default_operation=default_operation, test_option=test_option,
+            error_option=error_option)
+
+    # TODO: more netconf operations
-- 
1.7.10.4


------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to