-1

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.

Grant Curell
  • 1,321
  • 2
  • 16
  • 32
  • This appears to be a networking question, not a programming question. You can ask questions about business networks on [sf]. – Ron Maupin Mar 30 '20 at 23:30
  • It is not a networking question. It is a Python question about how to program a Ryu controller to output the physical port of a switch. It’s SDN so at this point it sounds like minor semantics lol – Grant Curell Mar 31 '20 at 03:06

1 Answers1

0

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.

Grant Curell
  • 1,321
  • 2
  • 16
  • 32