ryu/app: convert existing application to new style ryu application

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Isaku Yamahata 2012-05-29 18:26:58 +09:00 committed by FUJITA Tomonori
parent 32f644fbe9
commit e5e4b84425
6 changed files with 35 additions and 25 deletions

View File

@ -31,8 +31,6 @@ from ryu import utils
from ryu.app import wsapi from ryu.app import wsapi
from ryu.base.app_manager import AppManager from ryu.base.app_manager import AppManager
from ryu.controller import controller from ryu.controller import controller
from ryu.controller import dpset
from ryu.controller import network
FLAGS = gflags.FLAGS FLAGS = gflags.FLAGS
@ -49,17 +47,9 @@ def main():
_args = FLAGS(sys.argv) _args = FLAGS(sys.argv)
log.init_log() log.init_log()
# to make non-converted apps work. Once all of them converted,
# this will be removed.
kwargs = {
'network': network.Network(),
'dpset': dpset.DPSet(),
}
app_mgr = AppManager() app_mgr = AppManager()
app_mgr.load_apps(FLAGS.app_lists) app_mgr.load_apps(FLAGS.app_lists)
contexts = app_mgr.create_contexts() contexts = app_mgr.create_contexts()
contexts.update(kwargs)
app_mgr.instantiate_apps(**contexts) app_mgr.instantiate_apps(**contexts)
services = [] services = []

View File

@ -15,15 +15,16 @@
# limitations under the License. # limitations under the License.
from ryu.base import app_manager
from ryu.controller import ofp_event from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER from ryu.controller.handler import MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls from ryu.controller.handler import set_ev_cls
from ryu.ofproto import nx_match from ryu.ofproto import nx_match
class Cbench(object): class Cbench(app_manager.RyuApp):
def __init__(self, *_args, **kwargs): def __init__(self, *args, **kwargs):
pass super(Cbench, self).__init__(*args, **kwargs)
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER) @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def packet_in_handler(self, ev): def packet_in_handler(self, ev):

View File

@ -18,6 +18,7 @@
import gflags import gflags
import logging import logging
from ryu.base import app_manager
from ryu.controller import dispatcher from ryu.controller import dispatcher
from ryu.controller.handler import set_ev_cls from ryu.controller.handler import set_ev_cls
@ -30,9 +31,9 @@ gflags.DEFINE_multistring('dump_dispatcher', [],
'list of dispatcher name to dump event: default any') 'list of dispatcher name to dump event: default any')
class EventDumper(object): class EventDumper(app_manager.RyuApp):
def __init__(self, *_args, **_kwargs): def __init__(self, *args, **kwargs):
super(EventDumper, self).__init__() super(EventDumper, self).__init__(*args, **kwargs)
# EventDispatcher can be created and cloned before us. # EventDispatcher can be created and cloned before us.
# So register it explicitly # So register it explicitly
for ev_q in dispatcher.EventQueue.all_instances(): for ev_q in dispatcher.EventQueue.all_instances():

View File

@ -21,6 +21,8 @@ from ryu.app.wsapi import WSPathComponent
from ryu.app.wsapi import WSPathExtractResult from ryu.app.wsapi import WSPathExtractResult
from ryu.app.wsapi import WSPathStaticString from ryu.app.wsapi import WSPathStaticString
from ryu.app.wsapi import wsapi from ryu.app.wsapi import wsapi
from ryu.base import app_manager
from ryu.controller import network
# REST API # REST API
@ -93,9 +95,13 @@ class WSPathPort(WSPathComponent):
return WSPathExtractResult(value={'dpid': dpid, 'port': port}) return WSPathExtractResult(value={'dpid': dpid, 'port': port})
class restapi: class restapi(app_manager.RyuApp):
_CONTEXTS = {
'network': network.Network,
}
def __init__(self, *_args, **kwargs): def __init__(self, *args, **kwargs):
super(restapi, self).__init__(*args, **kwargs)
self.ws = wsapi() self.ws = wsapi()
self.api = self.ws.get_version("1.0") self.api = self.ws.get_version("1.0")
self.nw = kwargs['network'] self.nw = kwargs['network']

View File

@ -18,10 +18,13 @@ import logging
import struct import struct
from ryu.app.rest_nw_id import NW_ID_UNKNOWN, NW_ID_EXTERNAL from ryu.app.rest_nw_id import NW_ID_UNKNOWN, NW_ID_EXTERNAL
from ryu.base import app_manager
from ryu.exception import MacAddressDuplicated from ryu.exception import MacAddressDuplicated
from ryu.exception import PortUnknown from ryu.exception import PortUnknown
from ryu.controller import dpset
from ryu.controller import mac_to_network from ryu.controller import mac_to_network
from ryu.controller import mac_to_port from ryu.controller import mac_to_port
from ryu.controller import network
from ryu.controller import ofp_event from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER from ryu.controller.handler import MAIN_DISPATCHER
from ryu.controller.handler import CONFIG_DISPATCHER from ryu.controller.handler import CONFIG_DISPATCHER
@ -34,9 +37,14 @@ from ryu.lib import mac
LOG = logging.getLogger('ryu.app.simple_isolation') LOG = logging.getLogger('ryu.app.simple_isolation')
class SimpleIsolation(object): class SimpleIsolation(app_manager.RyuApp):
def __init__(self, *_args, **kwargs): _CONTEXTS = {
super(SimpleIsolation, self).__init__() 'network': network.Network,
'dpset': dpset.DPSet,
}
def __init__(self, *args, **kwargs):
super(SimpleIsolation, self).__init__(*args, **kwargs)
self.nw = kwargs['network'] self.nw = kwargs['network']
self.dpset = kwargs['dpset'] self.dpset = kwargs['dpset']
self.mac2port = mac_to_port.MacToPortTable() self.mac2port = mac_to_port.MacToPortTable()

View File

@ -16,6 +16,7 @@
import logging import logging
import struct import struct
from ryu.base import app_manager
from ryu.controller import mac_to_port from ryu.controller import mac_to_port
from ryu.controller import ofp_event from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER from ryu.controller.handler import MAIN_DISPATCHER
@ -34,10 +35,13 @@ LOG = logging.getLogger('ryu.app.simple_switch')
# TODO: we need to move the followings to something like db # TODO: we need to move the followings to something like db
class SimpleSwitch(object): class SimpleSwitch(app_manager.RyuApp):
def __init__(self, *_args, **_kwargs): _CONTEXETS = {
super(SimpleSwitch, self).__init__() 'mac2port': mac_to_port.MacToPortTable,
self.mac2port = mac_to_port.MacToPortTable() }
def __init__(self, *args, **kwargs):
super(SimpleSwitch, self).__init__(*args, **kwargs)
self.mac2port = kwargs['mac2port']
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER) @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def _packet_in_handler(self, ev): def _packet_in_handler(self, ev):