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


Is there any way to get the ports from a given node (switch)?

asked 2017-10-06 06:40:50 -0700

DanielRomero gravatar image


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.

The code that I'm using is Beryllium-SR3:

Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-10-06 07:11:27 -0700

VincentJahjah gravatar image

updated 2017-10-06 07:12:32 -0700

You mean, like this?

Node node = ...
List<NodeConnector> nodeConnectors = node.getNodeConnector();
for (NodeConnector nodeConnector : nodeConnectors) {

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");
edit flag offensive delete publish link more


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?

DanielRomero ( 2017-10-06 07:32:55 -0700 )edit

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:

VincentJahjah ( 2017-10-06 09:22:54 -0700 )edit

Hey Vincent, could you please paste that code on Pastebin again. It has expired. Thank you!

DanielRomero ( 2017-10-09 05:54:21 -0700 )edit

Oh, sorry. It didn't expire, it's just that if a link ends a comment on this site, the "/p" tag gets included in the link... Just remove the "/p" in the link, or copy it directly

VincentJahjah ( 2017-10-09 09:16:19 -0700 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-10-06 06:40:50 -0700

Seen: 20 times

Last updated: Oct 06