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

Revision history [back]

click to hide/show revision 1
initial version

I got to know this . I retrieved topology information as well ! . There are few steps , Databroker, Instance identifier of topology, read ! If some one wants help , let me know ..

Imports : I got to know this . I retrieved topology information as well copied all imports here ! . There are few steps , Databroker, you may delete unwanted ..

import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.ReadTransaction; import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Future;

Inside your class .. Instance identifier of topology, :

public static final InstanceIdentifier<topology> TOPO_IID = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(new TopologyId("flow:1")));

private RpcRegistration<pathservice> pathService; private DataBroker dataService;

@Override
public void onSessionInitiated(ProviderContext session) {
    LOG.info("PathProvider Session Initiated");
this.dataService = session.getSALService(DataBroker.class);
    pathService = session.addRpcImplementation(PathService.class, this);

}

RPC method :

@Override
public Future<RpcResult<NodesOutput>> nodes() {


    List<Node> nodes=null;
    ReadTransaction tx = dataService.newReadOnlyTransaction();

    List<String> results = new ArrayList<String>();

    try {
        nodes = tx.read(LogicalDatastoreType.OPERATIONAL, TOPO_IID)
                .checkedGet()
                .get().getNode();
    } catch (ReadFailedException e) {
        LOG.error("Failed to read !
If some one wants help , let me know ..

node config from datastore", e); throw new IllegalStateException(e); } results = new ArrayList<String>(); for (Node node : nodes) { LOG.info("Node: {}", node); results.add(node.getNodeId().getValue()); } NodesOutputBuilder NodeBuilder = new NodesOutputBuilder(); NodeBuilder.setListnode("Nodes are "+results); return RpcResultBuilder.success(NodeBuilder.build()).buildFuture(); }

Imports : I copied all imports here ! you may delete unwanted ..

import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.ReadTransaction; import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Future;

Inside your class .. Instance identifier :

public static final InstanceIdentifier<topology> TOPO_IID = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(new TopologyId("flow:1")));

private RpcRegistration<pathservice> pathService; private DataBroker dataService;

@Override
public void onSessionInitiated(ProviderContext session) {
    LOG.info("PathProvider Session Initiated");
this.dataService = session.getSALService(DataBroker.class);
    pathService = session.addRpcImplementation(PathService.class, this);

}

RPC method :

@Override
public Future<RpcResult<NodesOutput>> nodes() {


    List<Node> nodes=null;
    ReadTransaction tx = dataService.newReadOnlyTransaction();

    List<String> results = new ArrayList<String>();

    try {
        nodes = tx.read(LogicalDatastoreType.OPERATIONAL, TOPO_IID)
                .checkedGet()
                .get().getNode();
    } catch (ReadFailedException e) {
        LOG.error("Failed to read node config from datastore", e);
        throw new IllegalStateException(e);
    }

    results = new ArrayList<String>();
     for (Node node : nodes) {
        LOG.info("Node: {}", node);
        results.add(node.getNodeId().getValue());
    }

    NodesOutputBuilder NodeBuilder = new NodesOutputBuilder();
    NodeBuilder.setListnode("Nodes are  "+results);
    return RpcResultBuilder.success(NodeBuilder.build()).buildFuture();

}