Hi,

If you want to detect links between switches,
use events that ryu/topology/switches.py provides.
ryu/topology/switches.py provides events for adding and deleting switch or port 
or link.
Please see topology/event.py about the type of events.

An EventLinkAdd event occurs on each direction when you connect switches.
For example when you connect Switch-A and Switch-B, two EventLinkAdd events 
occur.
One of the two events is for Link(src=A, dest=B) event
and another is for Link(src=B, dest=A) event.
Those events can be caught in an event handler which process EventLinkAdd event.
Please see ryu/topology/dumper.py about
how to implement the event handler that catch EventLinkAdd events.


(2013/08/26 20:20), Christoph Brass wrote:
> Hi,
>
> I ask you for some help relating to the topology-modul of
> Ryu. I wrote a simple app, which is supposed to give me
> the complete topology of the network (a connected mininet
> network), by listing all switches and links. The problem
> is, that i have to use a trick to get all of the links, by
> specifing, that the number of links is complete if it
> corresponds to the number of switches+1. This works
> because every links is recorded twice, as it has two
> directions and i'm using a tree-topology. My example
> program is attached below and started with  PYTHONPATH=.
> ./bin/ryu-manager --observe-links ryu/app/topotester.py
> The rest_topology.py app just works fine for me and gives
> me all the links by first reqeust, which is what I hope to
> realize with my application.
>
> Kind regards, Chris
>
>
> from ryu.base import app_manager
>
> 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.topology import switches
> from ryu.topology.switches import get_switch, get_link
>
>
>
> class topotester(app_manager.RyuApp):
>       _CONTEXTS = {
>
>           'switches': switches.Switches
>       }
>
>
>       def __init__(self, *args, **kwargs):
>           super(topotester, self).__init__(*args, **kwargs)
>
>       self.switches = kwargs['switches']
>
>           self.topology_unknown = True
>           self.number_of_switches = 0
>           self.number_of_links = 0
>
>
>       def list_switches(self):
>           dpid = None
>
>           switch_list = get_switch(self.switches, dpid)
>           for switch in switch_list:
>               print switch.to_dict()
>
>           print "DEBUG: Number of Switches:",
> len(switch_list)
>           if self.topology_unknown:
>               self.number_of_switches = len(switch_list)
>
>       def list_links(self):
>           dpid = None
>           links = get_link(self.switches, dpid)
>           for link in links:
>               print link.to_dict()
>           print "DEBUG: Number of Links:", len(links)
>           self.number_of_links = len(links)
>
>
>       @set_ev_cls(ofp_event.EventOFPPacketIn,
> MAIN_DISPATCHER)
>       def packet_in_handler(self, ev):
>           msg = ev.msg
>           dp = msg.datapath
>           ofp = dp.ofproto
>           ofp_parser = dp.ofproto_parser
>
>
>           if self.topology_unknown==True:
>
>               print "Switches:"
>               self.list_switches()
>
>               print
> "---------------------------------------------------"
>
>               print "Links:"
>               self.list_links()
>               print
> "---------------------------------------------------"
>               if self.number_of_links ==
> self.number_of_switches+1:
>                   self.topology_unknown=False
>
>
>
> ------------------------------------------------------------------------------
> Introducing Performance Central, a new site from SourceForge and
> AppDynamics. Performance Central is your source for news, insights,
> analysis and resources for efficient Application Performance Management.
> Visit us today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
> _______________________________________________
> Ryu-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>

-- 


------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to