summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/services/protocols/bgp/api/base.py4
-rw-r--r--ryu/services/protocols/bgp/base.py12
-rw-r--r--ryu/services/protocols/bgp/core_managers/__init__.py9
-rw-r--r--ryu/services/protocols/bgp/info_base/base.py4
-rw-r--r--ryu/services/protocols/bgp/operator/commands/show/rib.py4
-rw-r--r--ryu/services/protocols/bgp/operator/commands/show/route_formatter_mixin.py7
-rw-r--r--ryu/services/protocols/bgp/operator/commands/show/vrf.py6
-rw-r--r--ryu/services/protocols/bgp/utils/circlist.py4
-rw-r--r--ryu/services/protocols/bgp/utils/internable.py35
9 files changed, 48 insertions, 37 deletions
diff --git a/ryu/services/protocols/bgp/api/base.py b/ryu/services/protocols/bgp/api/base.py
index 489e318e..33a4d8b8 100644
--- a/ryu/services/protocols/bgp/api/base.py
+++ b/ryu/services/protocols/bgp/api/base.py
@@ -18,6 +18,8 @@
This API can be used by various services like RPC, CLI, IoC, etc.
"""
+from __future__ import absolute_import
+
import inspect
import logging
import traceback
@@ -208,7 +210,7 @@ def call(symbol, **kwargs):
LOG.info("API method %s called with args: %s", symbol, str(kwargs))
# TODO(PH, JK) improve the way api function modules are loaded
- import all # noqa
+ from . import all # noqa
if not is_call_registered(symbol):
message = 'Did not find any method registered by symbol %s' % symbol
raise MethodNotFound(message)
diff --git a/ryu/services/protocols/bgp/base.py b/ryu/services/protocols/bgp/base.py
index a8ef6214..5e4cc254 100644
--- a/ryu/services/protocols/bgp/base.py
+++ b/ryu/services/protocols/bgp/base.py
@@ -15,12 +15,16 @@
"""
Defines some base class related to managing green threads.
"""
+from __future__ import absolute_import
+
import abc
+from collections import OrderedDict
import logging
import socket
import time
import traceback
import weakref
+
import netaddr
from ryu.lib import hub
@@ -38,12 +42,6 @@ from ryu.services.protocols.bgp.utils.evtlet import LoopingCall
# Logger instance for this module.
LOG = logging.getLogger('bgpspeaker.base')
-
-try:
- from collections import OrderedDict
-except ImportError:
- from ordereddict import OrderedDict
-
# Pointer to active/available OrderedDict.
OrderedDict = OrderedDict
@@ -456,7 +454,7 @@ class Sink(object):
self.index = Sink.next_index()
# Event used to signal enqueing.
- from utils.evtlet import EventletIOFactory
+ from .utils.evtlet import EventletIOFactory
self.outgoing_msg_event = EventletIOFactory.create_custom_event()
self.messages_queued = 0
diff --git a/ryu/services/protocols/bgp/core_managers/__init__.py b/ryu/services/protocols/bgp/core_managers/__init__.py
index 883de2d2..8b76bdc6 100644
--- a/ryu/services/protocols/bgp/core_managers/__init__.py
+++ b/ryu/services/protocols/bgp/core_managers/__init__.py
@@ -13,10 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import absolute_import
-from configuration_manager import ConfigurationManager
-from import_map_manager import ImportMapManager
-from peer_manager import PeerManager
-from table_manager import TableCoreManager
+from .configuration_manager import ConfigurationManager
+from .import_map_manager import ImportMapManager
+from .peer_manager import PeerManager
+from .table_manager import TableCoreManager
__all__ = ['ImportMapManager', 'TableCoreManager', 'PeerManager',
'ConfigurationManager']
diff --git a/ryu/services/protocols/bgp/info_base/base.py b/ryu/services/protocols/bgp/info_base/base.py
index 7ec54ce0..da1a480c 100644
--- a/ryu/services/protocols/bgp/info_base/base.py
+++ b/ryu/services/protocols/bgp/info_base/base.py
@@ -226,6 +226,10 @@ class NonVrfPathProcessingMixin(object):
because they are processed at VRF level, so different logic applies.
"""
+ def __init__(self):
+ self._core_service = None # not assigned yet
+ self._known_path_list = []
+
def _best_path_lost(self):
self._best_path = None
diff --git a/ryu/services/protocols/bgp/operator/commands/show/rib.py b/ryu/services/protocols/bgp/operator/commands/show/rib.py
index 440234ce..27d5b73c 100644
--- a/ryu/services/protocols/bgp/operator/commands/show/rib.py
+++ b/ryu/services/protocols/bgp/operator/commands/show/rib.py
@@ -1,4 +1,6 @@
-from route_formatter_mixin import RouteFormatterMixin
+from __future__ import absolute_import
+
+from .route_formatter_mixin import RouteFormatterMixin
from ryu.services.protocols.bgp.operator.command import Command
from ryu.services.protocols.bgp.operator.command import CommandsResponse
diff --git a/ryu/services/protocols/bgp/operator/commands/show/route_formatter_mixin.py b/ryu/services/protocols/bgp/operator/commands/show/route_formatter_mixin.py
index c20c97c9..e29c7c7f 100644
--- a/ryu/services/protocols/bgp/operator/commands/show/route_formatter_mixin.py
+++ b/ryu/services/protocols/bgp/operator/commands/show/route_formatter_mixin.py
@@ -17,12 +17,7 @@ class RouteFormatterMixin(object):
@classmethod
def _format_family(cls, dest_list):
- if six.PY3:
- import io
- msg = io.StringIO()
- else:
- import StringIO
- msg = StringIO.StringIO()
+ msg = six.StringIO()
def _append_path_info(buff, path, is_best, show_prefix):
aspath = path.get('aspath')
diff --git a/ryu/services/protocols/bgp/operator/commands/show/vrf.py b/ryu/services/protocols/bgp/operator/commands/show/vrf.py
index b78a7cf5..8730665c 100644
--- a/ryu/services/protocols/bgp/operator/commands/show/vrf.py
+++ b/ryu/services/protocols/bgp/operator/commands/show/vrf.py
@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
import logging
import pprint
@@ -9,7 +11,7 @@ from ryu.services.protocols.bgp.operator.commands.responses import \
WrongParamResp
from ryu.services.protocols.bgp.operator.views.conf import ConfDetailView
from ryu.services.protocols.bgp.operator.views.conf import ConfDictView
-from route_formatter_mixin import RouteFormatterMixin
+from .route_formatter_mixin import RouteFormatterMixin
LOG = logging.getLogger('bgpspeaker.operator.commands.show.vrf')
@@ -77,6 +79,8 @@ class Routes(Command, RouteFormatterMixin):
class CountRoutesMixin(object):
+ api = None # not assigned yet
+
def _count_routes(self, vrf_name, vrf_rf):
return len(self.api.get_single_vrf_routes(vrf_name, vrf_rf))
diff --git a/ryu/services/protocols/bgp/utils/circlist.py b/ryu/services/protocols/bgp/utils/circlist.py
index d22ec215..4a04f4fb 100644
--- a/ryu/services/protocols/bgp/utils/circlist.py
+++ b/ryu/services/protocols/bgp/utils/circlist.py
@@ -13,7 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from six.moves import intern
+import six
+if six.PY3:
+ from sys import intern
class CircularListType(object):
diff --git a/ryu/services/protocols/bgp/utils/internable.py b/ryu/services/protocols/bgp/utils/internable.py
index 9f5e8d95..2029bf0d 100644
--- a/ryu/services/protocols/bgp/utils/internable.py
+++ b/ryu/services/protocols/bgp/utils/internable.py
@@ -14,9 +14,6 @@
# limitations under the License.
import weakref
-from six.moves import intern
-
-dict_name = intern('_internable_dict')
#
@@ -40,6 +37,12 @@ class Internable(object):
Internable to work.
"""
+ _internable_stats = None
+ _internable_dict = None
+
+ def __init__(self):
+ self._interned = False
+
class Stats(object):
def __init__(self):
@@ -55,17 +58,17 @@ class Internable(object):
return str(self.d)
@classmethod
- def _internable_init(kls):
+ def _internable_init(cls):
# Objects to be interned are held as keys in a dictionary that
# only holds weak references to keys. As a result, when the
# last reference to an interned object goes away, the object
# will be removed from the dictionary.
- kls._internable_dict = weakref.WeakKeyDictionary()
- kls._internable_stats = Internable.Stats()
+ cls._internable_dict = weakref.WeakKeyDictionary()
+ cls._internable_stats = Internable.Stats()
@classmethod
- def intern_stats(kls):
- return kls._internable_stats
+ def intern_stats(cls):
+ return cls._internable_stats
def intern(self):
"""Returns either itself or a canonical copy of itself."""
@@ -78,26 +81,26 @@ class Internable(object):
# Got to find or create an interned object identical to this
# one. Auto-initialize the class if need be.
#
- kls = self.__class__
+ cls = self.__class__
- if not hasattr(kls, dict_name):
- kls._internable_init()
+ if not cls._internable_dict:
+ cls._internable_init()
- obj = kls._internable_dict.get(self)
+ obj = cls._internable_dict.get(self)
if (obj):
# Found an interned copy.
- kls._internable_stats.incr('found')
+ cls._internable_stats.incr('found')
return obj
# Create an interned copy. Take care to only keep a weak
# reference to the object itself.
def object_collected(obj):
- kls._internable_stats.incr('collected')
+ cls._internable_stats.incr('collected')
# print("Object %s garbage collected" % obj)
pass
ref = weakref.ref(self, object_collected)
- kls._internable_dict[self] = ref
+ cls._internable_dict[self] = ref
self._interned = True
- kls._internable_stats.incr('inserted')
+ cls._internable_stats.incr('inserted')
return self