BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / routing / dijkstra_implementation / src / main / java / org / opendaylight / controller / routing / dijkstra_implementation / internal / DijkstraImplementationCLI.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.routing.dijkstra_implementation.internal;
9
10 import java.util.Dictionary;
11 import java.util.Hashtable;
12
13 import org.apache.felix.service.command.Descriptor;
14 import org.opendaylight.controller.sal.core.Node;
15 import org.opendaylight.controller.sal.core.Path;
16 import org.opendaylight.controller.sal.routing.IRouting;
17 import org.opendaylight.controller.sal.utils.ServiceHelper;
18 import org.osgi.framework.ServiceRegistration;
19
20 public class DijkstraImplementationCLI {
21     @SuppressWarnings("rawtypes")
22     private ServiceRegistration sr = null;
23
24     public void init() {
25     }
26
27     public void destroy() {
28     }
29
30     public void start() {
31         final Dictionary<String, Object> props = new Hashtable<String, Object>();
32         props.put("osgi.command.scope", "odpcontroller");
33         props.put("osgi.command.function", new String[] { "getRoute" });
34         this.sr = ServiceHelper.registerGlobalServiceWReg(DijkstraImplementationCLI.class, this, props);
35     }
36
37     public void stop() {
38         if (this.sr != null) {
39             this.sr.unregister();
40             this.sr = null;
41         }
42     }
43
44     @Descriptor("Retrieves a Route between two Nodes in the discovered Topology DB")
45     public void getRoute(
46             @Descriptor("Container on the context of which the routing service need to be looked up") String container,
47             @Descriptor("String representation of the Source Node, this need to be consumable from Node.fromString()") String srcNode,
48             @Descriptor("String representation of the Destination Node") String dstNode) {
49         final IRouting r = (IRouting) ServiceHelper.getInstance(IRouting.class, container, this);
50
51         if (r == null) {
52             System.out.println("Cannot find the routing instance on container:" + container);
53             return;
54         }
55
56         final Node src = Node.fromString(srcNode);
57         final Node dst = Node.fromString(dstNode);
58         final Path p = r.getRoute(src, dst);
59         if (p != null) {
60             System.out.println("Route between srcNode:" + src + " and dstNode:" + dst + " = " + p);
61         } else {
62             System.out.println("There is no route between srcNode:" + src + " and dstNode:" + dst);
63         }
64     }
65 }