package org.opendaylight.controller.samples.differentiatedforwarding.internal;

import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import org.apache.felix.service.command.Descriptor;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.samples.differentiatedforwarding.ITunnelObserver;
import org.opendaylight.controller.samples.differentiatedforwarding.Tunnel;
import org.osgi.framework.ServiceRegistration;

public class TenantTunnelObserverCLI {
    @SuppressWarnings("rawtypes")
    private ServiceRegistration sr = null;

    public void init() {
    }

    public void destroy() {
    }

    public void start() {
        final Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put("osgi.command.scope", "odpcontroller");
        props.put("osgi.command.function", new String[] { "getTunnelsMap", "loadTunnelEndPoints" });
        this.sr = ServiceHelper.registerGlobalServiceWReg(TenantTunnelObserverCLI.class, this, props);
    }

    public void stop() {
        if (this.sr != null) {
            this.sr.unregister();
            this.sr = null;
        }
    }

    @Descriptor("Retrieves Tunnels Map. This returns just those tunnels with a tunnel key (e.g. Tenants Tunnels)")
    public void getTunnelsMap(
            @Descriptor("Container") String containerName) {
        System.out.println("TenantTunnelObserver.getTunnelsMap");

        ITunnelObserver tunnelObserver = (ITunnelObserver) ServiceHelper.getInstance(ITunnelObserver.class, containerName, this);
        if(tunnelObserver == null){
            System.err.println("TenantTunnelObserverCLI - getTunnelsMap: TenantTunnelObserver is not available");
            return;
        }
        HashMap<String, List<Tunnel>> tunnelsMap = tunnelObserver.getTunnelsMap();
        System.out.println(tunnelsMap);
    }

    @Descriptor("Load Tunnel EndPoints. ")
    public void loadTunnelEndPoints(
            @Descriptor("Container") String containerName) {
        System.out.println("TenantTunnelObserver.loadTunnelEndPoints");

        ITunnelObserver tunnelObserver = (ITunnelObserver) ServiceHelper.getInstance(ITunnelObserver.class, containerName, this);
        if(tunnelObserver == null){
            System.err.println("TenantTunnelObserverCLI - loadTunnels: TenantTunnelObserver is not available");
            return;
        }
        tunnelObserver.loadTunnelEndPoints();
        System.out.println("LoadTunnelEndPoint finished");
    }

}

@@ -178,16 +178,38 @@
 il.List;
+%0Aimport java.util.Set;
 %0A%0Aimport
@@ -475,16 +475,100 @@
 Tunnel;%0A
+import org.opendaylight.controller.samples.differentiatedforwarding.TunnelEndPoint;%0A
 import o
@@ -1053,16 +1053,38 @@
 dPoints%22
+, %22getTunnelEndPoints%22
  %7D);%0A   
@@ -1988,24 +1988,24 @@
 nnelsMap();%0A
-
         Syst
@@ -2031,32 +2031,767 @@
 elsMap);%0A    %7D%0A%0A
+    @Descriptor(%22Retrieves Tunnels Map. This returns just those tunnels with a tunnel key (e.g. Tenants Tunnels)%22)%0A    public void getTunnelEndPoints(%0A            @Descriptor(%22Container%22) String containerName) %7B%0A        System.out.println(%22TenantTunnelObserver.getTunnelEndPoints%22);%0A%0A        ITunnelObserver tunnelObserver = (ITunnelObserver) ServiceHelper.getInstance(ITunnelObserver.class, containerName, this);%0A        if(tunnelObserver == null)%7B%0A            System.err.println(%22TenantTunnelObserverCLI - getTunnelEndPoints: TenantTunnelObserver is not available%22);%0A            return;%0A        %7D%0A        HashMap%3CString, Set%3CTunnelEndPoint%3E%3E tepsMap = tunnelObserver.getTunnelEndPoints();%0A        System.out.println(tepsMap);%0A    %7D%0A%0A
     @Descriptor(

Add getTEPs OSGI method