Alan,
I've checked this on simple application:
"""
from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.dpset import DPSet
from ryu.controller.handler import MAIN_DISPATCHER, set_ev_cls
from ryu.ofproto import ofproto_v1_3
class MyApp(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
_CONTEXTS = {'dpset': DPSet}
def __init__(self, *args, **kwargs):
super(MyApp, self).__init__(*args, **kwargs)
self.dpset = kwargs['dpset']
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def on_packetin(self, ev):
switches = self.dpset.get_all()
mac_addresses = [(s[0],
s[1].ports[ofproto_v1_3.OFPP_LOCAL].hw_addr)
for s in switches]
print("mac_addresses {}".format(mac_addresses))
"""
First I've started mn like this: `mn --topo=linear,2 --controller=remote`
Then I started `ryu-manager myapp --verbose`, and called `pingall` in mn.
On packetin i received:
>> EVENT ofp_event->MyApp EventOFPPacketIn
>> mac_addresses [(1, '3e:a1:63:df:fa:4e'), (2, '8e:8e:51:8f:df:47')]
Hope it helps.
If it still doesn't work check for correct switch registration by dpset -
there must be following lines in output (with --verbose flag set):
>> EVENT ofp_event->dpset EventOFPStateChange
>> DPSET: register datapath <ryu.controller.controller.Datapath object at
0x7ff879a68550>
Nick
пт, 16 сент. 2016 г. в 18:07, Alan Wang <[email protected]>:
> Hi,
>
> Thanks for your reply.
>
> I tried your code and simulate it with mininet.
>
> But it returns empty list.
>
> How to solve the problem?
>
> Thanks,
>
> Alan
>
> 2016-09-16 21:46 GMT+08:00 Nick Sedelnikov <[email protected]>:
>
>> Hi,
>>
>> To know all registered switches try:
>> """
>> from ryu.controller.dpset import DPSet
>>
>> class MyApp(app_manager.RyuApp):
>> # ...
>>
>> _CONTEXTS = {'dpset': DPSet}
>>
>> def __init__(self, *args, **kwargs):
>> super(MyApp, self).__init__(*args, **kwargs)
>> # ...
>> self.dpset = kwargs['dpset']
>> # ...
>> """
>> Then fetch switches:
>> >> switches = self.dpset.get_all()
>> >> mac_addresses = [(s[0], s[1].ports[OFPP_LOCAL].hw_addr) for s in
>> switches]
>> It will return tuple(dpid, mac_address), like this:
>> [(1, '0a:74:ba:ce:11:47'), (2, '32:5b:11:d9:72:4f')]
>>
>>
>>
>> пт, 16 сент. 2016 г. в 15:25, Alan Wang <[email protected]>:
>>
>>> Hi All,
>>>
>>> I want to know the mac address of all switches from controller. How to
>>> get the mac
>>>
>>> address of switch?
>>>
>>> Thanks,
>>>
>>> Alan
>>>
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> Ryu-devel mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/ryu-devel
>>>
>>
>
------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel