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:
parent
32f644fbe9
commit
e5e4b84425
@ -31,8 +31,6 @@ from ryu import utils
|
||||
from ryu.app import wsapi
|
||||
from ryu.base.app_manager import AppManager
|
||||
from ryu.controller import controller
|
||||
from ryu.controller import dpset
|
||||
from ryu.controller import network
|
||||
|
||||
|
||||
FLAGS = gflags.FLAGS
|
||||
@ -49,17 +47,9 @@ def main():
|
||||
_args = FLAGS(sys.argv)
|
||||
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.load_apps(FLAGS.app_lists)
|
||||
contexts = app_mgr.create_contexts()
|
||||
contexts.update(kwargs)
|
||||
app_mgr.instantiate_apps(**contexts)
|
||||
|
||||
services = []
|
||||
|
@ -15,15 +15,16 @@
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
from ryu.base import app_manager
|
||||
from ryu.controller import ofp_event
|
||||
from ryu.controller.handler import MAIN_DISPATCHER
|
||||
from ryu.controller.handler import set_ev_cls
|
||||
from ryu.ofproto import nx_match
|
||||
|
||||
|
||||
class Cbench(object):
|
||||
def __init__(self, *_args, **kwargs):
|
||||
pass
|
||||
class Cbench(app_manager.RyuApp):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Cbench, self).__init__(*args, **kwargs)
|
||||
|
||||
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
|
||||
def packet_in_handler(self, ev):
|
||||
|
@ -18,6 +18,7 @@
|
||||
import gflags
|
||||
import logging
|
||||
|
||||
from ryu.base import app_manager
|
||||
from ryu.controller import dispatcher
|
||||
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')
|
||||
|
||||
|
||||
class EventDumper(object):
|
||||
def __init__(self, *_args, **_kwargs):
|
||||
super(EventDumper, self).__init__()
|
||||
class EventDumper(app_manager.RyuApp):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(EventDumper, self).__init__(*args, **kwargs)
|
||||
# EventDispatcher can be created and cloned before us.
|
||||
# So register it explicitly
|
||||
for ev_q in dispatcher.EventQueue.all_instances():
|
||||
|
@ -21,6 +21,8 @@ from ryu.app.wsapi import WSPathComponent
|
||||
from ryu.app.wsapi import WSPathExtractResult
|
||||
from ryu.app.wsapi import WSPathStaticString
|
||||
from ryu.app.wsapi import wsapi
|
||||
from ryu.base import app_manager
|
||||
from ryu.controller import network
|
||||
|
||||
# REST API
|
||||
|
||||
@ -93,9 +95,13 @@ class WSPathPort(WSPathComponent):
|
||||
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.api = self.ws.get_version("1.0")
|
||||
self.nw = kwargs['network']
|
||||
|
@ -18,10 +18,13 @@ import logging
|
||||
import struct
|
||||
|
||||
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 PortUnknown
|
||||
from ryu.controller import dpset
|
||||
from ryu.controller import mac_to_network
|
||||
from ryu.controller import mac_to_port
|
||||
from ryu.controller import network
|
||||
from ryu.controller import ofp_event
|
||||
from ryu.controller.handler import MAIN_DISPATCHER
|
||||
from ryu.controller.handler import CONFIG_DISPATCHER
|
||||
@ -34,9 +37,14 @@ from ryu.lib import mac
|
||||
LOG = logging.getLogger('ryu.app.simple_isolation')
|
||||
|
||||
|
||||
class SimpleIsolation(object):
|
||||
def __init__(self, *_args, **kwargs):
|
||||
super(SimpleIsolation, self).__init__()
|
||||
class SimpleIsolation(app_manager.RyuApp):
|
||||
_CONTEXTS = {
|
||||
'network': network.Network,
|
||||
'dpset': dpset.DPSet,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SimpleIsolation, self).__init__(*args, **kwargs)
|
||||
self.nw = kwargs['network']
|
||||
self.dpset = kwargs['dpset']
|
||||
self.mac2port = mac_to_port.MacToPortTable()
|
||||
|
@ -16,6 +16,7 @@
|
||||
import logging
|
||||
import struct
|
||||
|
||||
from ryu.base import app_manager
|
||||
from ryu.controller import mac_to_port
|
||||
from ryu.controller import ofp_event
|
||||
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
|
||||
|
||||
|
||||
class SimpleSwitch(object):
|
||||
def __init__(self, *_args, **_kwargs):
|
||||
super(SimpleSwitch, self).__init__()
|
||||
self.mac2port = mac_to_port.MacToPortTable()
|
||||
class SimpleSwitch(app_manager.RyuApp):
|
||||
_CONTEXETS = {
|
||||
'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)
|
||||
def _packet_in_handler(self, ev):
|
||||
|
Loading…
Reference in New Issue
Block a user