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


How to get the Ip Address of a host node?

asked 2017-10-10 07:04:45 -0700

VincentJahjah gravatar image

I have tried with no avail to make my controller automatically detect which ip addresses are linked to which host nodes.

More precisely, I want to create a Map object associating NodeConnector(s) (or TerminationPoint) to IpAddress(es) of the host nodes at the other end of the Link.

I have installed l2switch and know that it is actively learning the ip address of host nodes, as when I query network-topology, I obtain juicy information:

"node-id": "host:06:03:09:94:c4:e7",
"termination-point": [
    "tp-id": "host:06:03:09:94:c4:e7"
"host-tracker-service:attachment-points": [
    "tp-id": "openflow:7:5",
    "corresponding-tp": "host:06:03:09:94:c4:e7",
    "active": true
"host-tracker-service:addresses": [
    "id": 5,
    "ip": "",
    "first-seen": 1507640107999,
    "last-seen": 1507640107999,
    "mac": "06:03:09:94:c4:e7"

So there is clearly a way to access the information. I know that either l2switch's AddressTracker, or HostTracker, or both are responsible for providing this information.

I'm just not clear on how best to access it inside the Java code (which classes these informations are mapped to, etc.).

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-10-10 10:13:24 -0700

VincentJahjah gravatar image

Answering my own question.

My problem stemmed from using the wrong "side" of the yang model. Here is code from my reverse-engineering test, showing what I was trying to "get" from the dataBroker:

NodeConnector nc =  new NodeConnectorBuilder().setId(new NodeConnectorId(ncIdStr))
                            new AddressCapableNodeConnectorBuilder()
                            .setAddresses(Arrays.asList(new AddressesBuilder()

Whereas I wanted to get hostNode objects, which is what l2switch uses to store its addresses:
network.topology.topology.NodeBuilder nb = 

              new HostNodeBuilder().setAddresses(Arrays.asList(
                      new AddressesBuilder().setIp(ip)

Here's what I do to get the addresses (the process begins on 'link' notification events, which are themselves generated by DataTreeModification events):

public void newLink(Link link) {
    // openflow switch nodes have ids that begin with "openflow:".
    // Host nodes (aka service nodes) have ids that begin with the mac address of the node.
    Optional<HostNode> host = Optional.absent();
    NodeConnectorId altNc = null;
    if (!link.getSource().getSourceTp().getValue().contains("openflow:")) {
        host = MDSalAccessUtils.sourceHostNode(link, dataBroker);
        altNc = new NodeConnectorId(link.getDestination().getDestTp().getValue());
    } else if (!link.getDestination().getDestTp().getValue().contains("openflow:")) {
        host = MDSalAccessUtils.destHostNode(link, dataBroker);
        altNc = new NodeConnectorId(link.getSource().getSourceTp().getValue());
    if (host.isPresent()) {
        for (Addresses addresses : host.get().getAddresses()) {
            realNodeAddresses.put(altNc, addresses.getIp());

public void updatedLink(Link oldLink, Link newLink) {

public void removedLink(Link link) {
    realNodeAddresses.remove(new NodeConnectorId( link.getDestination().getDestTp().getValue() ) );
    realNodeAddresses.remove(new NodeConnectorId( link.getSource().getSourceTp().getValue() ) );

MDSalAccessUtils is a custom utility class. The method used here is a simple read from databroker using a NetworkTopology --- Topology "flow:1" --- Node "nodeId" path.

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-10-10 07:04:45 -0700

Seen: 13 times

Last updated: Oct 10