diff options
-rw-r--r-- | ryu/app/simple_isolation.py | 10 | ||||
-rw-r--r-- | ryu/app/simple_switch.py | 6 | ||||
-rw-r--r-- | ryu/controller/controller.py | 4 | ||||
-rw-r--r-- | ryu/controller/event.py | 58 | ||||
-rw-r--r-- | ryu/controller/handler.py | 22 | ||||
-rw-r--r-- | ryu/controller/ofp_event.py | 74 |
6 files changed, 95 insertions, 79 deletions
diff --git a/ryu/app/simple_isolation.py b/ryu/app/simple_isolation.py index 891e2497..ac9e3161 100644 --- a/ryu/app/simple_isolation.py +++ b/ryu/app/simple_isolation.py @@ -19,9 +19,9 @@ import struct from ryu.app.rest_nw_id import NW_ID_UNKNOWN, NW_ID_EXTERNAL from ryu.exception import MacAddressDuplicated 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 import ofp_event from ryu.controller.handler import MAIN_DISPATCHER from ryu.controller.handler import CONFIG_DISPATCHER from ryu.controller.handler import set_ev_cls @@ -36,12 +36,12 @@ class SimpleIsolation(object): self.mac2port = mac_to_port.MacToPortTable() self.mac2net = mac_to_network.MacToNetwork(self.nw) - @set_ev_cls(event.EventOFPSwitchFeatures, CONFIG_DISPATCHER) + @set_ev_cls(ofp_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) + @set_ev_cls(ofp_event.EventOFPBarrierReply) def barrier_reply_handler(self, ev): LOG.debug('barrier reply ev %s msg %s', ev, ev.msg) @@ -106,7 +106,7 @@ 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(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER) def packet_in_handler(self, ev): # LOG.debug('packet in ev %s msg %s', ev, ev.msg) msg = ev.msg @@ -238,6 +238,6 @@ class SimpleIsolation(object): datapath.send_delete_all_flows() datapath.send_barrier() - @set_ev_cls(event.EventOFPBarrierReply, MAIN_DISPATCHER) + @set_ev_cls(ofp_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 02d2e5a1..4d3a21ba 100644 --- a/ryu/app/simple_switch.py +++ b/ryu/app/simple_switch.py @@ -15,8 +15,8 @@ import logging import struct -from ryu.controller import event from ryu.controller import mac_to_port +from ryu.controller import ofp_event from ryu.controller.handler import MAIN_DISPATCHER from ryu.controller.handler import set_ev_cls from ryu.lib.mac import haddr_to_str @@ -36,7 +36,7 @@ class SimpleSwitch(object): def __init__(self, *_args, **_kwargs): self.mac2port = mac_to_port.MacToPortTable() - @set_ev_cls(event.EventOFPPacketIn, MAIN_DISPATCHER) + @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER) def _packet_in_handler(self, ev): msg = ev.msg datapath = msg.datapath @@ -75,7 +75,7 @@ class SimpleSwitch(object): datapath.send_packet_out(msg.buffer_id, msg.in_port, actions) - @set_ev_cls(event.EventOFPPortStatus, MAIN_DISPATCHER) + @set_ev_cls(ofp_event.EventOFPPortStatus, MAIN_DISPATCHER) def _port_status_handler(self, ev): msg = ev.msg reason = msg.reason diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py index 0882c497..7d77bd4f 100644 --- a/ryu/controller/controller.py +++ b/ryu/controller/controller.py @@ -27,8 +27,8 @@ from ryu.ofproto import ofproto_v1_0 from ryu.ofproto import ofproto_v1_0_parser from ryu.controller import dispatcher -from ryu.controller import event from ryu.controller import handler +from ryu.controller import ofp_event LOG = logging.getLogger('ryu.controller.controller') @@ -165,7 +165,7 @@ class Datapath(object): while self.is_active: msg = self.recv_q.get() #LOG.debug('_event_loop ev %s cls %s', msg, msg.__class__) - self.ev_q.queue(event.ofp_msg_to_ev(msg)) + self.ev_q.queue(ofp_event.ofp_msg_to_ev(msg)) def send_ev(self, ev): #LOG.debug('send_ev %s', ev) diff --git a/ryu/controller/event.py b/ryu/controller/event.py index 0f185716..e831c076 100644 --- a/ryu/controller/event.py +++ b/ryu/controller/event.py @@ -13,65 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import inspect - class EventBase(object): # Nothing yet pass - - -class EventOFPMsgBase(EventBase): - def __init__(self, msg): - super(EventOFPMsgBase, self).__init__() - self.msg = msg - - -# -# Create event type corresponding to OFP Msg -# - -_OFP_MSG_EVENTS = {} - - -def _ofp_msg_name_to_ev_name(msg_name): - return 'Event' + msg_name - - -def ofp_msg_to_ev(msg): - name = _ofp_msg_name_to_ev_name(msg.__class__.__name__) - return _OFP_MSG_EVENTS[name](msg) - - -def _create_ofp_msg_ev_class(msg_cls): - name = _ofp_msg_name_to_ev_name(msg_cls.__name__) - # print 'creating event %s' % name - - if name in _OFP_MSG_EVENTS: - return - - cls = type(name, (EventOFPMsgBase,), - dict(__init__=lambda self, msg: - super(self.__class__, self).__init__(msg))) - globals()[name] = cls - _OFP_MSG_EVENTS[name] = cls - - -def _create_ofp_msg_ev_from_module(modname): - (f, _s, _t) = modname.rpartition('.') - mod = __import__(modname, fromlist=[f]) - print mod - for _k, cls in mod.__dict__.items(): - if not inspect.isclass(cls): - continue - if 'cls_msg_type' not in cls.__dict__: - continue - _create_ofp_msg_ev_class(cls) - - -# TODO:XXX -_PARSER_MODULE_LIST = ['ryu.ofproto.ofproto_v1_0_parser'] - -for m in _PARSER_MODULE_LIST: - # print 'loading module %s' % m - _create_ofp_msg_ev_from_module(m) diff --git a/ryu/controller/handler.py b/ryu/controller/handler.py index 7c32ab73..5d754cbb 100644 --- a/ryu/controller/handler.py +++ b/ryu/controller/handler.py @@ -17,8 +17,8 @@ import copy import inspect import logging -from ryu.controller import event from ryu.controller import dispatcher +from ryu.controller import ofp_event LOG = logging.getLogger('ryu.controller.handler') @@ -105,7 +105,7 @@ def register_instance(i, dispatchers=None): @register_cls([HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER]) class EchoHandler(object): @staticmethod - @set_ev_cls(event.EventOFPEchoRequest) + @set_ev_cls(ofp_event.EventOFPEchoRequest) def echo_request_handler(ev): msg = ev.msg # LOG.debug('echo request msg %s %s', msg, str(msg.data)) @@ -116,7 +116,7 @@ class EchoHandler(object): datapath.send_msg(echo_reply) @staticmethod - @set_ev_cls(event.EventOFPEchoReply) + @set_ev_cls(ofp_event.EventOFPEchoReply) def echo_reply_handler(ev): # do nothing # msg = ev.msg @@ -127,7 +127,7 @@ class EchoHandler(object): @register_cls([HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER]) class ErrorMsgHandler(object): @staticmethod - @set_ev_cls(event.EventOFPErrorMsg) + @set_ev_cls(ofp_event.EventOFPErrorMsg) def error_msg_handler(ev): msg = ev.msg LOG.debug('error msg ev %s type 0x%x code 0x%x %s', @@ -138,7 +138,7 @@ class ErrorMsgHandler(object): @register_cls(HANDSHAKE_DISPATCHER) class HandShakeHandler(object): @staticmethod - @set_ev_cls(event.EventOFPHello) + @set_ev_cls(ofp_event.EventOFPHello) def hello_handler(ev): LOG.debug('hello ev %s', ev) msg = ev.msg @@ -170,7 +170,7 @@ class HandShakeHandler(object): @register_cls(CONFIG_DISPATCHER) class ConfigHandler(object): @staticmethod - @set_ev_cls(event.EventOFPSwitchFeatures) + @set_ev_cls(ofp_event.EventOFPSwitchFeatures) def switch_features_handler(ev): msg = ev.msg datapath = msg.datapath @@ -194,15 +194,15 @@ class ConfigHandler(object): datapath.send_barrier() - # The above OFPC_DELETE request may trigger flow removed event. + # The above OFPC_DELETE request may trigger flow removed ofp_event. # Just ignore them. @staticmethod - @set_ev_cls(event.EventOFPFlowRemoved) + @set_ev_cls(ofp_event.EventOFPFlowRemoved) def flow_removed_handler(ev): LOG.debug("flow removed ev %s msg %s", ev, ev.msg) @staticmethod - @set_ev_cls(event.EventOFPBarrierReply) + @set_ev_cls(ofp_event.EventOFPBarrierReply) def barrier_reply_handler(ev): LOG.debug('barrier reply ev %s msg %s', ev, ev.msg) @@ -214,12 +214,12 @@ class ConfigHandler(object): @register_cls(MAIN_DISPATCHER) class MainHandler(object): @staticmethod - @set_ev_cls(event.EventOFPFlowRemoved) + @set_ev_cls(ofp_event.EventOFPFlowRemoved) def flow_removed_handler(ev): pass @staticmethod - @set_ev_cls(event.EventOFPPortStatus) + @set_ev_cls(ofp_event.EventOFPPortStatus) def port_status_handler(ev): msg = ev.msg LOG.debug('port status %s', msg.reason) diff --git a/ryu/controller/ofp_event.py b/ryu/controller/ofp_event.py new file mode 100644 index 00000000..312848ec --- /dev/null +++ b/ryu/controller/ofp_event.py @@ -0,0 +1,74 @@ +# Copyright (C) 2011 Nippon Telegraph and Telephone Corporation. +# Copyright (C) 2011 Isaku Yamahata <yamahata at valinux co jp> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import inspect + +from . import event + + +class EventOFPMsgBase(event.EventBase): + def __init__(self, msg): + super(EventOFPMsgBase, self).__init__() + self.msg = msg + + +# +# Create ofp_event type corresponding to OFP Msg +# + +_OFP_MSG_EVENTS = {} + + +def _ofp_msg_name_to_ev_name(msg_name): + return 'Event' + msg_name + + +def ofp_msg_to_ev(msg): + name = _ofp_msg_name_to_ev_name(msg.__class__.__name__) + return _OFP_MSG_EVENTS[name](msg) + + +def _create_ofp_msg_ev_class(msg_cls): + name = _ofp_msg_name_to_ev_name(msg_cls.__name__) + # print 'creating ofp_event %s' % name + + if name in _OFP_MSG_EVENTS: + return + + cls = type(name, (EventOFPMsgBase,), + dict(__init__=lambda self, msg: + super(self.__class__, self).__init__(msg))) + globals()[name] = cls + _OFP_MSG_EVENTS[name] = cls + + +def _create_ofp_msg_ev_from_module(modname): + (f, _s, _t) = modname.rpartition('.') + mod = __import__(modname, fromlist=[f]) + print mod + for _k, cls in mod.__dict__.items(): + if not inspect.isclass(cls): + continue + if 'cls_msg_type' not in cls.__dict__: + continue + _create_ofp_msg_ev_class(cls) + + +# TODO:XXX +_PARSER_MODULE_LIST = ['ryu.ofproto.ofproto_v1_0_parser'] + +for m in _PARSER_MODULE_LIST: + # print 'loading module %s' % m + _create_ofp_msg_ev_from_module(m) |