diff options
-rwxr-xr-x | bin/ryu-manager | 9 | ||||
-rw-r--r-- | ryu/app/rest.py | 14 | ||||
-rw-r--r-- | ryu/app/simple_isolation.py | 21 | ||||
-rw-r--r-- | ryu/app/simple_switch.py | 14 | ||||
-rw-r--r-- | ryu/controller/controller.py | 6 | ||||
-rw-r--r-- | ryu/controller/event.py | 5 | ||||
-rw-r--r-- | ryu/controller/handler.py | 34 | ||||
-rw-r--r-- | ryu/controller/network.py | 2 | ||||
-rw-r--r-- | ryu/exception.py | 4 | ||||
-rw-r--r-- | ryu/log.py | 20 | ||||
-rw-r--r-- | ryu/utils.py | 6 |
11 files changed, 68 insertions, 67 deletions
diff --git a/bin/ryu-manager b/bin/ryu-manager index 61df86c6..ef8355b1 100755 --- a/bin/ryu-manager +++ b/bin/ryu-manager @@ -24,9 +24,8 @@ from gevent import monkey monkey.patch_all() from ryu import log -log.earlyInitLog(logging.DEBUG) +log.early_init_log(logging.DEBUG) -from ryu import flags from ryu import utils from ryu.app import wsapi from ryu.base.app_manager import AppManager @@ -46,10 +45,10 @@ gflags.DEFINE_multistring('app_lists', def main(): utils.find_flagfile() - args = FLAGS(sys.argv) - log.initLog() + _args = FLAGS(sys.argv) + log.init_log() - nw = network.network() + nw = network.Network() dpset_ = dpset.create_dpset() app_mgr = AppManager() diff --git a/ryu/app/rest.py b/ryu/app/rest.py index 2d9a81b3..61f255fd 100644 --- a/ryu/app/rest.py +++ b/ryu/app/rest.py @@ -16,7 +16,9 @@ import json from ryu.exception import NetworkNotFound, NetworkAlreadyExist from ryu.exception import PortNotFound, PortAlreadyExist -from ryu.app.wsapi import * +from ryu.app.wsapi import WSPathComponent +from ryu.app.wsapi import WSPathExtractResult +from ryu.app.wsapi import wsapi # REST API @@ -62,7 +64,7 @@ class WSPathNetwork(WSPathComponent): def __str__(self): return "{network-id}" - def extract(self, pc, data): + def extract(self, pc, _data): if pc == None: return WSPathExtractResult(error="End of requested URI") @@ -75,7 +77,7 @@ class WSPathPort(WSPathComponent): def __str__(self): return "{dpid}_{port-id}" - def extract(self, pc, data): + def extract(self, pc, _data): if pc == None: return WSPathExtractResult(error="End of requested URI") @@ -91,13 +93,13 @@ class WSPathPort(WSPathComponent): class restapi: - def __init__(self, *args, **kwargs): + def __init__(self, *_args, **kwargs): self.ws = wsapi() self.api = self.ws.get_version("1.0") self.nw = kwargs['network'] self.register() - def list_networks_handler(self, request, data): + def list_networks_handler(self, request, _data): request.setHeader("Content-Type", 'application/json') return json.dumps(self.nw.list_networks()) @@ -111,7 +113,7 @@ class restapi: return "" - def update_network_handler(self, request, data): + def update_network_handler(self, _request, data): network_id = data['{network-id}'] self.nw.update_network(network_id) return "" diff --git a/ryu/app/simple_isolation.py b/ryu/app/simple_isolation.py index 43e945c1..891e2497 100644 --- a/ryu/app/simple_isolation.py +++ b/ryu/app/simple_isolation.py @@ -22,8 +22,8 @@ from ryu.exception import PortUnknown from ryu.controller import event from ryu.controller import mac_to_network from ryu.controller import mac_to_port -from ryu.controller.handler import main_dispatcher -from ryu.controller.handler import config_dispatcher +from ryu.controller.handler import MAIN_DISPATCHER +from ryu.controller.handler import CONFIG_DISPATCHER from ryu.controller.handler import set_ev_cls from ryu.lib.mac import haddr_to_str @@ -31,21 +31,22 @@ LOG = logging.getLogger('ryu.app.simple_isolation') class SimpleIsolation(object): - def __init__(self, *args, **kwargs): + def __init__(self, *_args, **kwargs): self.nw = kwargs['network'] self.mac2port = mac_to_port.MacToPortTable() self.mac2net = mac_to_network.MacToNetwork(self.nw) - @set_ev_cls(event.EventOFPSwitchFeatures, config_dispatcher) + @set_ev_cls(event.EventOFPSwitchFeatures, CONFIG_DISPATCHER) def switch_features_handler(self, ev): self.mac2port.dpid_add(ev.msg.datapath_id) self.nw.add_datapath(ev.msg) @set_ev_cls(event.EventOFPBarrierReply) - def barrier_reply_handler(ev): + def barrier_reply_handler(self, ev): LOG.debug('barrier reply ev %s msg %s', ev, ev.msg) - def _modflow_and_send_packet(self, msg, src, dst, actions): + @staticmethod + def _modflow_and_send_packet(msg, src, dst, actions): datapath = msg.datapath # @@ -105,13 +106,13 @@ class SimpleIsolation(object): else: self._flood_to_nw_id(msg, src, dst, dst_nw_id) - @set_ev_cls(event.EventOFPPacketIn, main_dispatcher) + @set_ev_cls(event.EventOFPPacketIn, MAIN_DISPATCHER) def packet_in_handler(self, ev): # LOG.debug('packet in ev %s msg %s', ev, ev.msg) msg = ev.msg datapath = msg.datapath - dst, src, eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0) + dst, src, _eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0) try: port_nw_id = self.nw.get_network(datapath.id, msg.in_port) @@ -230,13 +231,13 @@ class SimpleIsolation(object): # drop packets? assert port_nw_id == NW_ID_UNKNOWN - @set_ev_cls(event.EventOFPPortStatus, main_dispatcher) + @set_ev_cls(event.EventOFPPortStatus, MAIN_DISPATCHER) def port_status_handler(self, ev): msg = ev.msg datapath = msg.datapath datapath.send_delete_all_flows() datapath.send_barrier() - @set_ev_cls(event.EventOFPBarrierReply, main_dispatcher) + @set_ev_cls(event.EventOFPBarrierReply, MAIN_DISPATCHER) def barrier_replay_handler(self, ev): pass diff --git a/ryu/app/simple_switch.py b/ryu/app/simple_switch.py index 78daeac5..02d2e5a1 100644 --- a/ryu/app/simple_switch.py +++ b/ryu/app/simple_switch.py @@ -17,7 +17,7 @@ import struct from ryu.controller import event from ryu.controller import mac_to_port -from ryu.controller.handler import main_dispatcher +from ryu.controller.handler import MAIN_DISPATCHER from ryu.controller.handler import set_ev_cls from ryu.lib.mac import haddr_to_str @@ -33,16 +33,16 @@ LOG = logging.getLogger('ryu.app.simple_switch') class SimpleSwitch(object): - def __init__(self, *args, **kwargs): + def __init__(self, *_args, **_kwargs): self.mac2port = mac_to_port.MacToPortTable() - @set_ev_cls(event.EventOFPPacketIn, main_dispatcher) - def packetInHandler(self, ev): + @set_ev_cls(event.EventOFPPacketIn, MAIN_DISPATCHER) + def _packet_in_handler(self, ev): msg = ev.msg datapath = msg.datapath ofproto = datapath.ofproto - dst, src, eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0) + dst, src, _eth_type = struct.unpack_from('!6s6sH', buffer(msg.data), 0) dpid = datapath.id self.mac2port.dpid_add(dpid) @@ -75,8 +75,8 @@ class SimpleSwitch(object): datapath.send_packet_out(msg.buffer_id, msg.in_port, actions) - @set_ev_cls(event.EventOFPPortStatus, main_dispatcher) - def portStatusHandler(self, ev): + @set_ev_cls(event.EventOFPPortStatus, MAIN_DISPATCHER) + def _port_status_handler(self, ev): msg = ev.msg reason = msg.reason port_no = msg.port_no diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py index 2832c5df..0882c497 100644 --- a/ryu/controller/controller.py +++ b/ryu/controller/controller.py @@ -50,7 +50,7 @@ class OpenFlowController(object): def server_loop(self): server = StreamServer((FLAGS.ofp_listen_host, FLAGS.ofp_tcp_listen_port), - DatapathConnectionFactory) + datapath_connection_factory) #LOG.debug('loop') server.serve_forever() @@ -84,7 +84,7 @@ class Datapath(object): # weakref: qv_q.aux refers to aux = self # self.ev_q.aux == weakref.ref(self) self.ev_q = dispatcher.EventQueue(handler.QUEUE_NAME_OFP_MSG, - handler.handshake_dispatcher, + handler.HANDSHAKE_DISPATCHER, weakref.ref(self)) self.version_sent = None @@ -206,7 +206,7 @@ class Datapath(object): self.send_msg(barrier_request) -def DatapathConnectionFactory(socket, address): +def datapath_connection_factory(socket, address): LOG.debug('connected socket:%s address:%s', socket, address) datapath = Datapath(socket, address) diff --git a/ryu/controller/event.py b/ryu/controller/event.py index 54d135d9..0f185716 100644 --- a/ryu/controller/event.py +++ b/ryu/controller/event.py @@ -23,6 +23,7 @@ class EventBase(object): class EventOFPMsgBase(EventBase): def __init__(self, msg): + super(EventOFPMsgBase, self).__init__() self.msg = msg @@ -57,10 +58,10 @@ def _create_ofp_msg_ev_class(msg_cls): def _create_ofp_msg_ev_from_module(modname): - (f, s, t) = modname.rpartition('.') + (f, _s, _t) = modname.rpartition('.') mod = __import__(modname, fromlist=[f]) print mod - for k, cls in mod.__dict__.items(): + for _k, cls in mod.__dict__.items(): if not inspect.isclass(cls): continue if 'cls_msg_type' not in cls.__dict__: diff --git a/ryu/controller/handler.py b/ryu/controller/handler.py index 49e11d83..7c32ab73 100644 --- a/ryu/controller/handler.py +++ b/ryu/controller/handler.py @@ -16,22 +16,20 @@ import copy import inspect import logging -import struct from ryu.controller import event from ryu.controller import dispatcher -from ryu.lib.mac import haddr_to_bin LOG = logging.getLogger('ryu.controller.handler') QUEUE_NAME_OFP_MSG = 'ofp_msg' DISPATCHER_NAME_OFP_HANDSHAKE = 'ofp_handshake' -handshake_dispatcher = dispatcher.EventDispatcher( +HANDSHAKE_DISPATCHER = dispatcher.EventDispatcher( DISPATCHER_NAME_OFP_HANDSHAKE) DISPATCHER_NAME_OFP_CONFIG = 'ofp_config' -config_dispatcher = dispatcher.EventDispatcher(DISPATCHER_NAME_OFP_CONFIG) +CONFIG_DISPATCHER = dispatcher.EventDispatcher(DISPATCHER_NAME_OFP_CONFIG) DISPATCHER_NAME_OFP_MAIN = 'ofp_main' -main_dispatcher = dispatcher.EventDispatcher(DISPATCHER_NAME_OFP_MAIN) +MAIN_DISPATCHER = dispatcher.EventDispatcher(DISPATCHER_NAME_OFP_MAIN) DISPATCHER_NAME_OFP_DEAD = 'ofp_dead' DEAD_DISPATCHER = dispatcher.EventDispatcher(DISPATCHER_NAME_OFP_DEAD) @@ -73,8 +71,8 @@ def register_cls(dispatchers=None): dispatchers = _listify(dispatchers) def _register_cls_method(cls): - for k, f in inspect.getmembers(cls, inspect.isfunction): - # LOG.debug('cls %s k %s f %s', cls, k, f) + for _k, f in inspect.getmembers(cls, inspect.isfunction): + # LOG.debug('cls %s k %s f %s', cls, _k, f) if not _is_ev_handler(f): continue @@ -91,8 +89,8 @@ def register_cls(dispatchers=None): def register_instance(i, dispatchers=None): dispatchers = _listify(dispatchers) - for k, m in inspect.getmembers(i, inspect.ismethod): - # LOG.debug('instance %s k %s m %s', i, k, m) + for _k, m in inspect.getmembers(i, inspect.ismethod): + # LOG.debug('instance %s k %s m %s', i, _k, m) if not _is_ev_handler(m): continue @@ -100,11 +98,11 @@ def register_instance(i, dispatchers=None): # LOG.debug("_dispatchers %s", _dispatchers) for d in _dispatchers: # LOG.debug('register dispatcher %s ev %s k %s m %s', - # d.name, m.ev_cls, k, m) + # d.name, m.ev_cls, _k, m) d.register_handler(m.ev_cls, m) -@register_cls([handshake_dispatcher, config_dispatcher, main_dispatcher]) +@register_cls([HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER]) class EchoHandler(object): @staticmethod @set_ev_cls(event.EventOFPEchoRequest) @@ -126,7 +124,7 @@ class EchoHandler(object): pass -@register_cls([handshake_dispatcher, config_dispatcher, main_dispatcher]) +@register_cls([HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER]) class ErrorMsgHandler(object): @staticmethod @set_ev_cls(event.EventOFPErrorMsg) @@ -137,7 +135,7 @@ class ErrorMsgHandler(object): msg.datapath.is_active = False -@register_cls(handshake_dispatcher) +@register_cls(HANDSHAKE_DISPATCHER) class HandShakeHandler(object): @staticmethod @set_ev_cls(event.EventOFPHello) @@ -166,10 +164,10 @@ class HandShakeHandler(object): # now move on to config state LOG.debug('move onto config mode') - datapath.ev_q.set_dispatcher(config_dispatcher) + datapath.ev_q.set_dispatcher(CONFIG_DISPATCHER) -@register_cls(config_dispatcher) +@register_cls(CONFIG_DISPATCHER) class ConfigHandler(object): @staticmethod @set_ev_cls(event.EventOFPSwitchFeatures) @@ -210,15 +208,15 @@ class ConfigHandler(object): # move on to main state LOG.debug('move onto main mode') - ev.msg.datapath.ev_q.set_dispatcher(main_dispatcher) + ev.msg.datapath.ev_q.set_dispatcher(MAIN_DISPATCHER) -@register_cls(main_dispatcher) +@register_cls(MAIN_DISPATCHER) class MainHandler(object): @staticmethod @set_ev_cls(event.EventOFPFlowRemoved) def flow_removed_handler(ev): - msg = ev.msg + pass @staticmethod @set_ev_cls(event.EventOFPPortStatus) diff --git a/ryu/controller/network.py b/ryu/controller/network.py index db8c8960..6aacd826 100644 --- a/ryu/controller/network.py +++ b/ryu/controller/network.py @@ -22,7 +22,7 @@ from ryu.app.rest_nw_id import NW_ID_UNKNOWN LOG = logging.getLogger('ryu.controller.network') -class network(object): +class Network(object): def __init__(self, nw_id_unknown=NW_ID_UNKNOWN): self.nw_id_unknown = nw_id_unknown self.networks = {} diff --git a/ryu/exception.py b/ryu/exception.py index 4ced457d..f226960f 100644 --- a/ryu/exception.py +++ b/ryu/exception.py @@ -24,7 +24,7 @@ class RyuException(Exception): try: msg = msg % kwargs - except Exception as e: + except Exception: msg = self.message super(RyuException, self).__init__(msg) @@ -34,7 +34,7 @@ class OFPUnknownVersion(RyuException): message = 'unknown version %(version)x' -class OFPMalformedMessage: +class OFPMalformedMessage(RyuException): message = 'malformed message' @@ -32,15 +32,15 @@ gflags.DEFINE_string('log_file', None, 'log file name') gflags.DEFINE_string('log_file_mode', '0644', 'default log file permission') -_early_log_handler = None +_EARLY_LOG_HANDLER = None -def earlyInitLog(level=None): - global _early_log_handler - _early_log_handler = logging.StreamHandler(sys.stderr) +def early_init_log(level=None): + global _EARLY_LOG_HANDLER + _EARLY_LOG_HANDLER = logging.StreamHandler(sys.stderr) log = logging.getLogger() - log.addHandler(_early_log_handler) + log.addHandler(_EARLY_LOG_HANDLER) if level is not None: log.setLevel(level) @@ -54,15 +54,15 @@ def _get_log_file(): return None -def initLog(): - global _early_log_handler +def init_log(): + global _EARLY_LOG_HANDLER log = logging.getLogger() if FLAGS.use_stderr: log.addHandler(logging.StreamHandler(sys.stderr)) - if _early_log_handler is not None: - log.removeHandler(_early_log_handler) - _early_log_handler = None + if _EARLY_LOG_HANDLER is not None: + log.removeHandler(_EARLY_LOG_HANDLER) + _EARLY_LOG_HANDLER = None if FLAGS.use_syslog: syslog = logging.handlers.SysLogHandler(address='/dev/log') diff --git a/ryu/utils.py b/ryu/utils.py index eea30f4a..5ab365bb 100644 --- a/ryu/utils.py +++ b/ryu/utils.py @@ -22,7 +22,7 @@ LOG = logging.getLogger('ryu.utils') def import_module(modname): - (f, s, t) = modname.rpartition('.') + (f, _s, _t) = modname.rpartition('.') mod = __import__(modname, fromlist=[f]) return mod @@ -31,7 +31,7 @@ def import_object(modname): try: return import_module(modname) except ImportError: - (from_mod, sep, target) = modname.rpartition('.') + (from_mod, _sep, target) = modname.rpartition('.') mod = import_module(from_mod) return getattr(mod, target) @@ -45,7 +45,7 @@ def find_flagfile(default_path=RYU_DEFAULT_FLAG_FILE): script_dir = os.path.dirname(inspect.stack()[-1][1]) - for filename in RYU_DEFAULT_FLAG_FILE: + for filename in default_path: if not os.path.abspath(filename): if os.path.exists(filename): # try relative to current path |