- modify flow's duration time for testing master: $ ryu-manager --ofp_controller_role 'master' --ofp_tcp_listen_port \ 6633 --app_lists ryu.app.simple_switch
slave: $ ryu-manager --ofp_controller_role 'slave' --ofp_tcp_listen_port \ 6634 --app_lists ryu.app.simple_switch Signed-off-by: OHMURA Kei <ohmura....@lab.ntt.co.jp> --- bin/ryu-manager | 1 + ryu/app/simple_switch.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/ryu-manager b/bin/ryu-manager index cee0b41..8e9791e 100755 --- a/bin/ryu-manager +++ b/bin/ryu-manager @@ -30,6 +30,7 @@ log.early_init_log(logging.DEBUG) from ryu import version from ryu import utils from ryu.app import wsgi +from ryu.app import simple_switch from ryu.base.app_manager import AppManager from ryu.controller import controller from ryu.tests.integrated import tester diff --git a/ryu/app/simple_switch.py b/ryu/app/simple_switch.py index 571fceb..08e9e31 100644 --- a/ryu/app/simple_switch.py +++ b/ryu/app/simple_switch.py @@ -15,18 +15,25 @@ import logging import struct +import gflags from ryu.base import app_manager -from ryu.controller import mac_to_port from ryu.controller import ofp_event +from ryu.controller import dpset from ryu.controller.handler import MAIN_DISPATCHER from ryu.controller.handler import set_ev_cls from ryu.ofproto import ofproto_v1_0 from ryu.lib.mac import haddr_to_str +from ryu.app.multiple_controllers_zk import MultipleControllers LOG = logging.getLogger('ryu.app.simple_switch') +FLAGS = gflags.FLAGS +gflags.DEFINE_string('ofp_controller_role', '', 'role of a controller') + +ZHOST = '127.0.0.1:2181' # TODO: XXX + # TODO: we should split the handler into two parts, protocol # independent and dependant parts. @@ -37,10 +44,15 @@ LOG = logging.getLogger('ryu.app.simple_switch') class SimpleSwitch(app_manager.RyuApp): OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION] + _CONTEXTS = { + 'dpset': dpset.DPSet, + } def __init__(self, *args, **kwargs): super(SimpleSwitch, self).__init__(*args, **kwargs) self.mac_to_port = {} + self.mc = MultipleControllers(FLAGS.ofp_controller_role, + ZHOST) def add_flow(self, datapath, in_port, dst, actions): ofproto = datapath.ofproto @@ -55,7 +67,7 @@ class SimpleSwitch(app_manager.RyuApp): mod = datapath.ofproto_parser.OFPFlowMod( datapath=datapath, match=match, cookie=0, - command=ofproto.OFPFC_ADD, idle_timeout=0, hard_timeout=0, + command=ofproto.OFPFC_ADD, idle_timeout=5, hard_timeout=5, priority=ofproto.OFP_DEFAULT_PRIORITY, flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions) datapath.send_msg(mod) @@ -108,3 +120,8 @@ class SimpleSwitch(app_manager.RyuApp): LOG.info("port modified %s", port_no) else: LOG.info("Illeagal port state %s %s", port_no, reason) + + @set_ev_cls(dpset.EventDP, dpset.DPSET_EV_DISPATCHER) + def handle_datapath(self, ev): + if ev.enter: + self.mc.handle_datapath(ev) -- 1.7.9.5 ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Ryu-devel mailing list Ryu-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ryu-devel