Ask Your Question
0

How to read data from Operational Data Store?

asked 2016-01-25 01:11:43 -0700

karthik330 gravatar image

updated 2016-01-25 01:12:08 -0700

I need to read the data from Operational Data Store.For example if i give mac , i should get ip of the relavant mac. I know we can get the mac, ip details from UI itself.But i wants to do experiment on reading data from Operational Data Store.How to use DataBroker service for this? Thanks in Advance

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-02-25 04:39:08 -0700

karthik330 gravatar image

updated 2016-02-25 21:05:01 -0700

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);
    }


    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();

}
edit flag offensive delete publish link more

Comments

Could you please paste the steps

saisujithreddy ( 2016-02-25 16:49:35 -0700 )edit

Plz check my updated answer

karthik330 ( 2016-02-25 20:55:40 -0700 )edit

Thank for the code. I am trying to use it but I do not know how implement NodesOutput, pathservice, Topology.

migueldmh ( 2016-04-28 07:08:54 -0700 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Follow
1 follower

Stats

Asked: 2016-01-25 01:11:43 -0700

Seen: 481 times

Last updated: Feb 25 '16