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

0

How to get the Ip Address of a host node?

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

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": "10.0.2.1",
    "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
1

answered 2017-10-10 10:13:24 -0800

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))
                        .addAugmentation(AddressCapableNodeConnector.class, 
                            new AddressCapableNodeConnectorBuilder()
                            .setAddresses(Arrays.asList(new AddressesBuilder()
                                .setIp(ip).build())).build()).build();

Whereas I wanted to get hostNode objects, which is what l2switch uses to store its addresses:

org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.
network.topology.topology.NodeBuilder nb = 
     new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.
         network.topology.topology.NodeBuilder();

    nb.setNodeId(MDSalAccessUtils.makeNewNodeId("garbl"))
      .addAugmentation(HostNode.class,
              new HostNodeBuilder().setAddresses(Arrays.asList(
                      new AddressesBuilder().setIp(ip)
                      .build())).build());

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) {
    removedLink(oldLink);
    newLink(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

Follow
1 follower

Stats

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

Seen: 62 times

Last updated: Oct 10