-->

Information about Switches and Ports from OpenFlow

2019-08-04 11:50发布

问题:

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)