Hi, On 2015年06月05日 15:49, 曾惠萍 wrote: > Thanks,do you know another way to get the switch object by switch dpid? > cuz i want to get the datapath and ofproto_parse
You can use DPSet application as follows. http://ryu.readthedocs.org/en/latest/api_ref.html#ryu.controller.dpset.DPSet e.g.) $ git diff diff --git a/ryu/app/simple_switch_13.py b/ryu/app/simple_switch_13.py index b9cbad0..173f1ee 100644 --- a/ryu/app/simple_switch_13.py +++ b/ryu/app/simple_switch_13.py @@ -21,13 +21,17 @@ from ryu.ofproto import ofproto_v1_3 from ryu.lib.packet import packet from ryu.lib.packet import ethernet +from ryu.controller import dpset + class SimpleSwitch13(app_manager.RyuApp): OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION] + _CONTEXTS = {'dpset': dpset.DPSet} def __init__(self, *args, **kwargs): super(SimpleSwitch13, self).__init__(*args, **kwargs) self.mac_to_port = {} + self.dpset = kwargs['dpset'] @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER) def switch_features_handler(self, ev): @@ -64,6 +68,8 @@ class SimpleSwitch13(app_manager.RyuApp): @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER) def _packet_in_handler(self, ev): + dp = self.dpset.get(1) + self.logger.info('dp: %s', dp) # If you hit this you might want to increase # the "miss_send_length" of your switch if ev.msg.msg_len < ev.msg.total_len: $ ryu-manager ryu.app.simple_switch_13 loading app ryu.app.simple_switch_13 loading app ryu.controller.ofp_handler instantiating app None of DPSet creating context dpset instantiating app ryu.app.simple_switch_13 of SimpleSwitch13 instantiating app ryu.controller.ofp_handler of OFPHandler dp: <ryu.controller.controller.Datapath object at 0x7f2c9923d7d0> packet in 1 00:00:00:00:00:01 ff:ff:ff:ff:ff:ff 1 dp: <ryu.controller.controller.Datapath object at 0x7f2c9923d7d0> packet in 1 00:00:00:00:00:02 00:00:00:00:00:01 2 dp: <ryu.controller.controller.Datapath object at 0x7f2c9923d7d0> packet in 1 00:00:00:00:00:01 00:00:00:00:00:02 1 Thanks, Iwase > > Thanks, > Ping > > > 2015-06-05 14:36 GMT+08:00 Yusuke Iwase <iwase.yusu...@gmail.com > <mailto:iwase.yusu...@gmail.com>>: > > Hi, > > On 2015年06月05日 14:37, 曾惠萍 wrote: > > Hello, Iwase, > > > > when i interrupt my program by press ctrl+c, and the error msg is as > follow: > > -------------------------Error > msg----------------------------------------- > > Traceback (most recent call last): > > File "./bin/ryu-manager", line 19, in <module> > > main() > > File "/usr/local/lib/python2.7/dist-packages/ryu/cmd/manager.py", > line 101, in main > > app_mgr.close() > > File > "/usr/local/lib/python2.7/dist-packages/ryu/base/app_manager.py", line 514, > in close > > close_all(self.applications) > > File > "/usr/local/lib/python2.7/dist-packages/ryu/base/app_manager.py", line 511, > in close_all > > self._close(app) > > File > "/usr/local/lib/python2.7/dist-packages/ryu/base/app_manager.py", line 495, > in _close > > close_method() > > File > "/usr/local/lib/python2.7/dist-packages/ryu/topology/switches.py", line 470, > in close > > hub.joinall(self.threads) > > File "/usr/local/lib/python2.7/dist-packages/ryu/lib/hub.py", line > 89, in joinall > > t.wait() > > File "/usr/lib/python2.7/dist-packages/eventlet/greenthread.py", line > 168, in wait > > return self._exit_event.wait() > > File "/usr/lib/python2.7/dist-packages/eventlet/event.py", line 116, > in wait > > return hubs.get_hub().switch() > > File "/usr/lib/python2.7/dist-packages/eventlet/hubs/hub.py", line > 187, in switch > > return self.greenlet.switch() > > File "/usr/lib/python2.7/dist-packages/eventlet/hubs/hub.py", line > 236, in run > > self.wait(sleep_time) > > File "/usr/lib/python2.7/dist-packages/eventlet/hubs/poll.py", line > 84, in wait > > presult = self.do_poll(seconds) > > File "/usr/lib/python2.7/dist-packages/eventlet/hubs/epolls.py", line > 61, in do_poll > > return self.poll.poll(seconds) > > -------------------------Error > msg----------------------------------------- > > what does the function t.wait() wait for? > > Sorry, I don't know a lot. > >From the source code, it seems to wait for joining lldp_loop and > link_loop threads, > the one sends LLDP packets periodically, the other one observes links > status. > > Thanks, > Iwase > > > > > Thanks, > > Ping > > > > 2015-06-03 14:34 GMT+08:00 Yusuke Iwase <iwase.yusu...@gmail.com > <mailto:iwase.yusu...@gmail.com> <mailto:iwase.yusu...@gmail.com > <mailto:iwase.yusu...@gmail.com>>>: > > > > Hi, > > > > On 2015年05月31日 23:57, 曾惠萍 wrote: > > > Hi, > > > > > > sometime my program is normally work, but sometime it hang up. > > > when i get switch object, sometime it 's hangup and later it show > error message. > > > > > > *command:* > > > PYTHON=. ./bin/ryu-manager --observe-links ryu/app/address.py > > > > > > *my program as follow:* > > > @handler.set_ev_cls(event.EventLinkAdd) > > > def link_add_handler(self, ev): > > > link = ev.link > > > self.logger.info <http://self.logger.info> > <http://self.logger.info> <http://self.logger.info>("link add: > %s",link.to_dict()) > > > linkarray = link.to_dict() > > > > > > src_sw = api.get_switch(self, link.src.dpid)[0] > > > dst_sw = api.get_switch(self, link.dst.dpid)[0] > > > src_dp = src_sw.dp > > > dst_dp = dst_sw.dp > > > src_parser = src_sw.dp.ofproto_parser > > > dst_parser = dst_sw.dp.ofproto_parser > > > > > > *error message:* > > > hub: uncaught exception: Traceback (most recent call last): > > > File "/usr/local/lib/python2.7/dist-packages/ryu/lib/hub.py", > line 52, in _launch > > > File > "/usr/local/lib/python2.7/dist-packages/ryu/controller/controller.py", line > 70, in __call__ > > > self.server_loop() > > > File > "/usr/local/lib/python2.7/dist-packages/ryu/controller/controller.py", line > 96, in server_loop > > > server.serve_forever() > > > File "/usr/local/lib/python2.7/dist-packages/ryu/lib/hub.py", > line 120, in serve_forever > > > File "/usr/lib/python2.7/dist-packages/eventlet/greenio.py", > line 179, in accept > > > File "/usr/lib/python2.7/dist-packages/eventlet/greenio.py", > line 56, in socket_accept > > > File "/usr/lib/python2.7/socket.py", line 202, in accept > > > error: [Errno 24] Too many open files > > > > This message shows that the number of open files per process > reached the limit, I think. > > Please check the limit of your system (eg. with "ulimit -n" > command). > > > > Thanks, > > Iwase > > > > > > > > > > > > > > i think get_switch function is the point. > > > but i don't know how to correct it. > > > > > > Thanks, > > > Ping > > > > > > > > > > > > > ------------------------------------------------------------------------------ > > > > > > > > > > > > _______________________________________________ > > > Ryu-devel mailing list > > > Ryu-devel@lists.sourceforge.net > <mailto:Ryu-devel@lists.sourceforge.net> > <mailto:Ryu-devel@lists.sourceforge.net > <mailto:Ryu-devel@lists.sourceforge.net>> > > > https://lists.sourceforge.net/lists/listinfo/ryu-devel > > > > > > > > > > > > > > ------------------------------------------------------------------------------ > > > > > > > > _______________________________________________ > > Ryu-devel mailing list > > Ryu-devel@lists.sourceforge.net <mailto:Ryu-devel@lists.sourceforge.net> > > https://lists.sourceforge.net/lists/listinfo/ryu-devel > > > > > > > ------------------------------------------------------------------------------ > > > > _______________________________________________ > Ryu-devel mailing list > Ryu-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/ryu-devel > ------------------------------------------------------------------------------ _______________________________________________ Ryu-devel mailing list Ryu-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ryu-devel