Information about Switches and Ports from OpenFlow (RYU Controller)

本秂侑毒 提交于 2020-01-25 01:08:10

问题


I am attempting to get some information from OpenFlow for my OpenFlow Application on RYU.

The information that I want to get is given below.

For each SWITCH,I want

        - DPID
        - STATE   (ACTIVE/INACTIVE)

For each PORT, I want

         - DPID
         - PORT_NUMBER
         - STATE
         - PORT_STATE

Port state - Tracks Port Status message from OF. 1 - ACTIVE. 0 - INACTIVE.OpenFlow 1.0 has 2 types of port status from memory, one concerning whether the port has link and the other concerning whether the port is administratively up. I believe this port status tracks the second type - i.e. port status should be 1 if the port is administratively up even if it doesn't have a link.

Which messages should I listen to to get the above information.Also I tried getting information about ofp_event.EventOFPStateChange.

I tried looking at http://ryu.readthedocs.org/en/latest/genindex.html I couldn't find the information related to ofp_event.EventOFPStateChange.

Any help to point me in the right direction would be highly appreciated.


回答1:


You can use the following code. I am using it to identify all switches connected to it. I needed only the DPIDs and out ports. But you can use 'ev.link' for other information. Hope this helps. `

class OF13(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]

_CONTEXTS = {
    'dpset': dpset.DPSet,
}

def __init__(self, *args, **kwargs):
    super(OF13, self).__init__(*args, **kwargs)
    self.dpset = kwargs['dpset']     

def _get_hwaddr(self, dpid, port_no):
    return self.dpset.get_port(dpid, port_no).hw_addr

@handler.set_ev_cls(event.EventLinkAdd)
def link_add(self, ev):
    print ev.link.src, ev.link.dst
    print self._get_hwaddr(ev.link.src.dpid, ev.link.src.port_no)        


来源:https://stackoverflow.com/questions/23838784/information-about-switches-and-ports-from-openflow-ryu-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!