Hi,
It might be this line.
https://github.com/karthik82/ryu/blob/master/ryu/topology/switches.py#L492
Because your app import ryu.topology.api, ryu.topology.switches is loaded
automatically.
(2014/05/21 12:10), Karthik Sharma wrote:
> Hi
>
> When I run my modified version of simple_switch.py I get the following
> output.
>
> loading app ryu/app/simple_switch.py
> loading app ryu.topology.switches
> loading app ryu.controller.ofp_handler
> loading app ryu.controller.ofp_handler
> instantiating app ryu.topology.switches of Switches
> instantiating app ryu.controller.ofp_handler of OFPHandler
> instantiating app ryu/app/simple_switch.py of SimpleSwitch
> switch Switch<dpid=516, Port<dpid=516, port_no=1, LIVE> Port<dpid=516,
> port_no=2, LIVE> >
> switch Switch<dpid=514, Port<dpid=514, port_no=1, LIVE> Port<dpid=514,
> port_no=2, LIVE> >
> switch Switch<dpid=513, Port<dpid=513, port_no=1, LIVE> Port<dpid=513,
> port_no=2, LIVE> >
> switch Switch<dpid=517, Port<dpid=517, port_no=1, LIVE> Port<dpid=517,
> port_no=2, LIVE> >
> switch Switch<dpid=515, Port<dpid=515, port_no=1, LIVE> Port<dpid=515,
> port_no=2, LIVE> >
> switch Switch<dpid=518, Port<dpid=518, port_no=1, LIVE> Port<dpid=518,
> port_no=2, LIVE> >
>
>
> Now my modified simple_switch application is given below.
>
>
> 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
> from ryu.controller.handler import CONFIG_DISPATCHER
> from ryu.controller.handler import set_ev_cls
> from ryu.ofproto import ofproto_v1_0
> from ryu.lib.mac import haddr_to_bin
> from ryu.lib.packet import packet
> from ryu.lib.packet import ethernet
> from bulbs.titan import Graph
> import ryu.topology.api
> from ryu.lib import stplib
> from ryu.lib import dpid as dpid_lib
>
> class _SwitchInfo(object):
> def __init__(self, datapath):
> self.datapath = datapath
> self.xids = {}
> self.barriers = {}
> self.results = {}
>
> class SimpleSwitch(app_manager.RyuApp):
> OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
>
> def __init__(self, *args, **kwargs):
> super(SimpleSwitch, self).__init__(*args, **kwargs)
> self.mac_to_port = {}
> self.do_once = 0
> self.switches = {}
>
> def add_flow(self, datapath, in_port, dst, actions):
> ofproto = datapath.ofproto
>
> match = datapath.ofproto_parser.OFPMatch(
> in_port=in_port, dl_dst=haddr_to_bin(dst))
>
> mod = datapath.ofproto_parser.OFPFlowMod(
> datapath=datapath, match=match, cookie=0,
> command=ofproto.OFPFC_ADD, idle_timeout=0, hard_timeout=0,
> priority=ofproto.OFP_DEFAULT_PRIORITY,
> flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
> datapath.send_msg(mod)
>
> @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
> def _packet_in_handler(self, ev):
> msg = ev.msg
> datapath = msg.datapath
> ofproto = datapath.ofproto
>
> pkt = packet.Packet(msg.data)
> eth = pkt.get_protocol(ethernet.ethernet)
>
> dst = eth.dst
> src = eth.src
>
> dpid = datapath.id
> self.mac_to_port.setdefault(dpid, {})
>
> #self.logger.info("packet in %s %s %s %s", dpid, src, dst,
> msg.in_port)
>
> # learn a mac address to avoid FLOOD next time.
> self.mac_to_port[dpid][src] = msg.in_port
>
> if dst in self.mac_to_port[dpid]:
> out_port = self.mac_to_port[dpid][dst]
> else:
> out_port = ofproto.OFPP_FLOOD
>
> actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
>
> # install a flow to avoid packet_in next time
> if out_port != ofproto.OFPP_FLOOD:
> self.add_flow(datapath, msg.in_port, dst, actions)
>
> out = datapath.ofproto_parser.OFPPacketOut(
> datapath=datapath, buffer_id=msg.buffer_id, in_port=msg.in_port,
> actions=actions)
> datapath.send_msg(out)
>
> @set_ev_cls(ofp_event.EventOFPPortStatus, MAIN_DISPATCHER)
> def _port_status_handler(self, ev):
> msg = ev.msg
> reason = msg.reason
> port_no = msg.desc.port_no
>
> ofproto = msg.datapath.ofproto
> if reason == ofproto.OFPPR_ADD:
> self.logger.info("port added %s", port_no)
> pass
> elif reason == ofproto.OFPPR_DELETE:
> self.logger.info("port deleted %s", port_no)
> pass
> elif reason == ofproto.OFPPR_MODIFY:
> self.logger.info("port modified %s", port_no)
> pass
> else:
> self.logger.info("Illeagal port state %s %s", port_no, reason)
>
> @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
> def _switch_features_handler(self, ev):
> datapath = ev.msg.datapath
> id = datapath.id
> assert isinstance(id, (int, long))
> old_info = self.switches.get(id, None)
> new_info = _SwitchInfo(datapath=datapath)
> self.logger.debug('add dpid %s datapath %s new_info %s old_info %s'
> %
> (id, datapath, new_info, old_info))
> self.switches[id] = new_info
>
> @set_ev_cls(stplib.EventPortStateChange, MAIN_DISPATCHER)
> def _port_state_change_handler(self, ev):
> dpid_str = dpid_lib.dpid_to_str(ev.dp.id)
> of_state = {stplib.PORT_STATE_DISABLE: 'DISABLE',
> stplib.PORT_STATE_BLOCK: 'BLOCK',
> stplib.PORT_STATE_LISTEN: 'LISTEN',
> stplib.PORT_STATE_LEARN: 'LEARN',
> stplib.PORT_STATE_FORWARD: 'FORWARD'}
> self.logger.debug("***[dpid=%s][port=%d] state=%s",
> dpid_str, ev.port_no, of_state[ev.port_state])
>
>
> My question is what part of the code is prompting the the messages given
> above.(switch Switch<dpid=516, Port<dpid=516, port_no=1, LIVE>
> Port<dpid=516, port_no=2, LIVE> >)
> I think I have found out the code for it
> https://github.com/karthik82/ryu/blob/master/ryu/topology/switches.py#L100
>
> But I can't seem to understand the control flow.
>
> Any help would be greatly appreciated.
>
> Regards,
> Karthik.
>
>
>
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
>
>
>
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel