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

Revision history [back]

click to hide/show revision 1
initial version

I would do it in the following way:

public void onEthernetPacketReceived(EthernetPacketReceived packetReceived) {
    long timeReceivedInMs = System.currentTimeMillis();

    if (packetReceived == null || packetReceived.getPacketChain() == null) {

    RawPacket rawPacket = null;
    EthernetPacket ethernetPacket = null;
    for (PacketChain packetChain : packetReceived.getPacketChain()) {
        if (packetChain.getPacket() instanceof RawPacket) {
            rawPacket = (RawPacket) packetChain.getPacket();
        } else if (packetChain.getPacket() instanceof EthernetPacket) {
            ethernetPacket = (EthernetPacket) packetChain.getPacket();
    if (rawPacket == null || ethernetPacket == null) {
    NodeConnectorRef ref = rawPacket.getIngress();
    try {
        NodeConnector nodeConnector = (NodeConnector) dataBroker.newReadOnlyTransaction()
                .read(LogicalDatastoreType.OPERATIONAL, ref.getValue()).get();
        NodeConnectorId nodeConnectorId = nodeConnector.getId();
        if (nodeConnectorId.getValue().contains("openflow:")) {
            NodeId nodeId = new NodeId("openflow:" + nodeConnectorId.getValue().split(":")[1]);
    } catch (InterruptedException | ExecutionException e) {

RawPacket should always be involved in a packet-in event, so you should have access to the ingress port. Each port is unique, and their IDs are usually defined as "'openflow:' + nodeNumber + ':' + portNumber", in the case of a flow capable node. If you have a flow capable node, then you have access to the node ID. It's probably only a matter of doing a map, like Map{NodeId, FlowCapableNode}.

There's probably a way to get the ID from the reference without doing a datastore read (with "getValue()" and analyzing the format) but I haven't tried.