Topology Service (Java version)
Usage of the Topology Service in a Java application
DNOS provides a gRPC based topology service that can be used in management applications to retrieve topology information. In this tutorial we will show you how can use that to print topology graph.
-
Follow the installation instructions here to prepare your setup ready.
- Clone the repository of the sample applications:
$ git clone https://github.com/dnosproject/dnos-apps-java.git
- Run a mininet emulation scenario as follows:
$ sudo mn --topo=linear,4 --controller=remote,ip=127.0.0.1
- Run the sampletopology app under dnos-apps-java as follows.
$ bazel run sampletopology:sampletopology_image
The above command creates an image of the application and run it in a docker container. You should be able to see it by running the following command:
$ docker ps
- After running the application, it prints the number of links and topology graph information as follows:
2019-02-22 01:46:06 INFO sampletopology:59 - Number of links:6 2019-02-22 01:46:06 INFO sampletopology:76 - of:0000000000000002:3 -->of:0000000000000003:2 2019-02-22 01:46:06 INFO sampletopology:76 - of:0000000000000003:3 -->of:0000000000000004:2 2019-02-22 01:46:06 INFO sampletopology:76 - of:0000000000000002:2 -->of:0000000000000001:2 2019-02-22 01:46:06 INFO sampletopology:76 - of:0000000000000004:2 -->of:0000000000000003:3 2019-02-22 01:46:06 INFO sampletopology:76 - of:0000000000000003:2 -->of:0000000000000002:3 2019-02-22 01:46:06 INFO sampletopology:76 - of:0000000000000001:2 -->of:0000000000000002:2
How does the sample topology service application work?
- First, we need to create a gRPC channel and TopologyService gRPC stub. We also use an external Conguration service which is part of dnos-services repository to initalize log4j.
ManagedChannel channel; String controllerIP; String grpcPort; ConfigService configService = new ConfigService(); configService.init(); controllerIP = configService.getConfig().getControllerIp(); grpcPort = configService.getConfig().getGrpcPort(); TopoServiceStub topologyServiceStub; channel = ManagedChannelBuilder .forAddress(controllerIP, Integer.parseInt(grpcPort)) .usePlaintext() .build(); topologyServiceStub = TopoServiceGrpc.newStub(channel);
- Second, we need to create an Empty request that should be sent as an argument when we call topology servcie functions (i.e. currentTopology and getGraph functions). CurrentTopology function returns high level information about topology such as number of links, the time that topology is created, number of clusters in the topology, etc (For more information, please take a look at Topology class in ONOS. getGraph function returns a graph of the network topology that includes topology edges and vertices.
Empty empty = Empty.newBuilder().build(); // Retrieves current topology information topologyServiceStub.currentTopology(empty, new StreamObserver<TopologyProto>() { @Override public void onNext(TopologyProto value) { log.info("Number of links:" + value.getLinkCount()); } @Override public void onError(Throwable t) {} @Override public void onCompleted() {} }); // Retrieves topology graph topologyServiceStub.getGraph(empty, new StreamObserver<TopologyGraphProto>() { @Override public void onNext(TopologyGraphProto value) { for(TopologyEdgeProto topologyEdgeProto: value.getEdgesList()) { log.info(topologyEdgeProto.getLink().getSrc().getDeviceId() + ":" + topologyEdgeProto.getLink().getSrc().getPortNumber() + " -->" + topologyEdgeProto.getLink().getDst().getDeviceId() + ":" + topologyEdgeProto.getLink().getDst().getPortNumber()); } } @Override public void onError(Throwable t) {} @Override public void onCompleted() {} });
- Previous
- Next