pythonnetwork-programmingopenflowryu

Ryu/OpenFlow how to map in_port number to physical port


For the uninitiated - I am asking a Python/SDN question. It is a programming question.

There isn't much literature on this and I didn't see it in the specification. I have built a Ryu controller based on the documentation and have it all working, but I have a rather simple problem:

How do you map the in_port numbers to actual port numbers? In my case, it is saying I have an in_port of 5. However, it's actually coming in to physical port 1/1/2 on my Dell 4112F-ON. There doesn't seem to be any correlation between the two.

If I want to control traffic on a per port basis, how do I know from which physical port the traffic came?

Edit: I know how to convert to a MAC address, but I haven't figured out a clean way to programatically determine the port # from the MAC address.


Solution

  • I discovered that in Ryu, the name of the physical port is inside the dpset data structure which is part of ryu.controller. In dpset there is an attribute called port_state which is a dictionary of type {: }. You can extract the data with the following code:

        port_list = []
    
        for port, port_info in simple_switch.dpset.port_state[dpid].items():
            port_list.append(
                {"hw_addr": port_info.hw_addr, "name": port_info.name.decode("utf-8"), "openflow_port": port})
    

    where simpleswitch in my case was an instance of Ryu's REST controller from here. However, you don't need to rest to get the data - it is part of the data maintained with the controller in dpset.