summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2014-03-24 11:26:05 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-03-25 19:42:48 +0900
commit6212f37e2e373d04e7ab6f5c218a27ffcfd5fc50 (patch)
tree970a06741f639f47996e2f83571a8d47a76fee8b
parentb2ce73e16b8e26403e773fa555005d52d6ffb48e (diff)
ofproto: get rid of fragile and slow glob'ing modules
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/ofproto/__init__.py41
1 files changed, 4 insertions, 37 deletions
diff --git a/ryu/ofproto/__init__.py b/ryu/ofproto/__init__.py
index 57f19397..ee148033 100644
--- a/ryu/ofproto/__init__.py
+++ b/ryu/ofproto/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
+# Copyright (C) 2013,2014 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");
@@ -18,51 +18,18 @@ import glob
import inspect
import os.path
-from ryu import utils
-
-
-_OFPROTO_DIR = os.path.dirname(__file__)
-
-_OFPROTO_PARSER_FILE_NAMES = glob.glob(os.path.join(
- _OFPROTO_DIR, 'ofproto_v[0-9]*_[0-9]*_parser.py*'))
-_OFPROTO_PARSER_FILE_NAMES = [os.path.basename(name)
- for name in _OFPROTO_PARSER_FILE_NAMES]
-
-
-_OFPROTO_MODULES = {}
-for parser_file_name in _OFPROTO_PARSER_FILE_NAMES:
- # drop tailing '.py*'
- parser_mod_name = __name__ + '.' + \
- '.'.join(parser_file_name.split('.')[:-1])
- consts_mod_name = parser_mod_name[:-7] # drop trailing '_parser'
- try:
- parser_mod = utils.import_module(parser_mod_name)
- consts_mod = utils.import_module(consts_mod_name)
- except:
- continue
-
- if consts_mod.OFP_VERSION not in _OFPROTO_MODULES:
- _OFPROTO_MODULES[consts_mod.OFP_VERSION] = (consts_mod, parser_mod)
+from ryu.ofproto import ofproto_protocol
def get_ofp_modules():
"""get modules pair for the constants and parser of OF-wire of
a given OF version.
"""
- return _OFPROTO_MODULES
+ return ofproto_protocol._versions
def get_ofp_module(ofp_version):
"""get modules pair for the constants and parser of OF-wire of
a given OF version.
"""
- return _OFPROTO_MODULES[ofp_version]
-
-
-def get_ofp_cls(ofp_version, name):
- """get class for name of a given OF version"""
- (_consts_mod, parser_mod) = get_ofp_module(ofp_version)
- for i in inspect.getmembers(parser_mod, inspect.isclass):
- if i[0] == name:
- return i[1]
- return None
+ return get_ofp_modules()[ofp_version]