Ask is moving to Stack Overflow and Serverfault.com! Please use the "opendaylight" tag on either of these sites. This site is now in Read-Only mode

I'm modifying L2Switch to install reactive rules to a given node (in this case a switch). What I'd want to know is if there's any method to get the ports from a switch. This will help me to forward packets to one of these ports.

NodeConnectors are mapped to switch ports, so they are essentially the same.

Later versions of ODL use TerminationPoint instead of NodeConnector, but they are interchangeable (you can refer to a NodeConnector with a TerminationPoint's id, and vice versa).

You can even refer to OpenFlow's special ports in the following way (these ports exist for all switches, except for the optional ports which may not be supported by your openflow hardware):

// reserved ports (openflow 1.1+)
public final static NodeConnectorId INGRESS_PORT = new NodeConnectorId("0xfffffff8");
public final static NodeConnectorId TABLE_PORT = new NodeConnectorId("0xfffffff9");
public final static NodeConnectorId NORMAL_PORT = new NodeConnectorId("0xfffffffa"); // optional
public final static NodeConnectorId FLOOD_PORT = new NodeConnectorId("0xfffffffb"); // optional
public final static NodeConnectorId ALL_PORT = new NodeConnectorId("0xfffffffc");
public final static NodeConnectorId CONTROLLER_PORT = new NodeConnectorId("0xfffffffd");
public final static NodeConnectorId LOCAL_PORT = new NodeConnectorId("0xfffffffe");
public final static NodeConnectorId ANY_PORT = new NodeConnectorId("0xffffffff");

Comments

Wow! that's very useful. But for example, I know the NodeId of the switch that I want to know the NodeConnectors. The NodeId is "openflow:1". So how can I get the "Node"? I read that I should to read from DataBroker, isn't?

To get all nodes, you can query the class Nodes (which has a getNode() method returning a list of Node). There were some query examples in my answer to your previous question, one of which involved querying a node using an id, from DataBroker: https://pastebin.com/uMsjEHAb