Fix for ADVA ols with TAPI

Change-Id: I91d0002dc67697d394f6a97ed7f97089054f4837
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceDescriptionDiscovery.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceDescriptionDiscovery.java
index c106202..ab0a986 100644
--- a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceDescriptionDiscovery.java
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceDescriptionDiscovery.java
@@ -22,20 +22,18 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import org.onlab.packet.ChassisId;
+import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.Device;
-import org.onosproject.net.PortNumber;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.OchSignal;
+import org.onosproject.net.OduSignalType;
+import org.onosproject.net.PortNumber;
 import org.onosproject.net.device.DefaultDeviceDescription;
 import org.onosproject.net.device.DeviceDescription;
 import org.onosproject.net.device.DeviceDescriptionDiscovery;
 import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.PortDescription;
 import org.onosproject.net.driver.AbstractHandlerBehaviour;
-import org.onosproject.net.OchSignal;
-import org.onosproject.net.OduSignalType;
-import org.onosproject.net.GridType;
-import org.onosproject.net.ChannelSpacing;
-import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.protocol.rest.RestSBController;
 import org.slf4j.Logger;
 
@@ -46,24 +44,16 @@
 import java.util.List;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.CONTEXT;
 import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.LAYER_PROTOCOL_NAME;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.AVAILABLE_SPECTRUM;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.ADJUSTMENT_GRANULARITY;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.BASE_FREQUENCY;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.FREQUENCY_CONSTRAINT;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.GRID_TYPE;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.LOWER_FREQUENCY;
 import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.MC_POOL;
+import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC;
 import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.PHOTONIC_LAYER_QUALIFIER_NMC;
 import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.PHOTONIC_MEDIA;
 import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.SERVICE_INTERFACE_POINT;
 import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.SUPPORTED_LAYER_PROTOCOL_QUALIFIER;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.UPPER_FREQUENCY;
 import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.UUID;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.toMbpsFromHz;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.getChannelSpacing;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.getSlotGranularity;
+import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.getOchSignal;
 import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
 import static org.slf4j.LoggerFactory.getLogger;
 
@@ -77,9 +67,7 @@
         implements DeviceDescriptionDiscovery {
 
     private static final Logger log = getLogger(TapiDeviceDescriptionDiscovery.class);
-    private static final String SIP_REQUEST_DATA_API = "/data/context/";
-    private static PortNumber nPort = PortNumber.portNumber(1);
-    private static final Object N_PORT_LOCK = new Object();
+    private static final String SIP_REQUEST_DATA_API = "/restconf/data/tapi-common:context";
 
     /**
      * Get the deviceId for which the methods apply.
@@ -98,9 +86,10 @@
         Device device = deviceService.getDevice(deviceId);
 
         if (device == null) {
+            //TODO need to obtain from the device.
             return new DefaultDeviceDescription(deviceId.uri(),
                     Device.Type.OLS,
-                    "tapi-swagger",
+                    "Tapi",
                     "0",
                     "2.1",
                     "Unknown",
@@ -125,6 +114,10 @@
         try {
             InputStream inputStream = controller.get(deviceId, SIP_REQUEST_DATA_API, MediaType.APPLICATION_JSON_TYPE);
             JsonNode jsonNode = new ObjectMapper().readTree(inputStream);
+            if (jsonNode == null) {
+                log.error("Can't discover port details at {}", SIP_REQUEST_DATA_API);
+                return ImmutableList.of();
+            }
             return parseTapiPorts(jsonNode);
         } catch (IOException e) {
             log.error("Exception discoverPortDetails() {}", did(), e);
@@ -134,39 +127,28 @@
 
     protected List<PortDescription> parseTapiPorts(JsonNode tapiContext) {
         List<PortDescription> ports = Lists.newArrayList();
-        int counter = 0;
-
-        /**
+        /*
          This annotations are used to store persistent mapping information between TAPI SIP's uuid
          and ONOS device portNumbers. This is needed to be publicly available at least within ODTN app
          when connectivity services will be sent to OLS Controller.
-         **/
+         */
         DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
-
-        JsonNode sips = tapiContext.get(SERVICE_INTERFACE_POINT);
-        Iterator<JsonNode> iter = sips.iterator();
+        Iterator<JsonNode> iter = tapiContext.get(CONTEXT).get(SERVICE_INTERFACE_POINT).iterator();
         while (iter.hasNext()) {
             JsonNode sipAttributes = iter.next();
             if (checkValidEndpoint(sipAttributes)) {
                 String uuid = sipAttributes.get(UUID).textValue();
+                PortNumber portNumber = PortNumber.portNumber(uuid.split("-")[0]);
+                annotations.set(UUID, uuid);
+
                 JsonNode mcPool = sipAttributes.get(MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC).get(MC_POOL);
+                // We get the first OCH signal as reported by the device.
+                OchSignal ochSignal = getOchSignal(mcPool).iterator().next();
+                //add och port
+                ports.add(ochPortDescription(portNumber, true, OduSignalType.ODU4,
+                        false, ochSignal, annotations.build()));
 
-                /*We create a sample OChSignal in the first position of the 50GHz DWDM Grid,
-                this should be replace for a OChSignal construct which has undefined spectrum.
-                OchSignal ochSignal = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ,
-                        0, 1);*/
 
-                OchSignal ochSignal = getOchSignal(mcPool);
-                synchronized (N_PORT_LOCK) {
-                    //annotations(portNumber-uuid)
-                    annotations.set(UUID, uuid);
-
-                    //add och port
-                    ports.add(ochPortDescription(nPort, true, OduSignalType.ODU4,
-                            false, ochSignal, annotations.build()));
-
-                    nPort = PortNumber.portNumber(counter++);
-                }
             } else {
                 log.error("SIP {} is not valid", sipAttributes);
             }
@@ -183,52 +165,11 @@
      * [PHOTONIC_LAYER_QUALIFIER_NMC, PHOTONIC_LAYER_QUALIFIER_NMCA, PHOTONIC_LAYER_QUALIFIER_OTSI...]
      **/
     private boolean checkValidEndpoint(JsonNode sipAttributes) {
-        return (sipAttributes.get(LAYER_PROTOCOL_NAME).toString().contains(PHOTONIC_MEDIA) &&
+        return sipAttributes.has(LAYER_PROTOCOL_NAME) &&
+                sipAttributes.get(LAYER_PROTOCOL_NAME).toString().contains(PHOTONIC_MEDIA) &&
+                sipAttributes.has(SUPPORTED_LAYER_PROTOCOL_QUALIFIER) &&
                 sipAttributes.get(SUPPORTED_LAYER_PROTOCOL_QUALIFIER).toString()
-                        .contains(PHOTONIC_LAYER_QUALIFIER_NMC));
-    }
-
-    /**
-     * If SIP info match our criteria, SIP component shall includes mc-pool information which must be obtained in order
-     * to complete the OchSignal info. with the TAPI SIP information included in spectrum-supported, spectrum-available
-     * and spectrum-occupied tapi objects.
-     **/
-    private OchSignal getOchSignal(JsonNode mcPool) {
-        long availableUpperFrec = 0;
-        long availableLowerFrec = 0;
-        String availableAdjustmentGranularity = "";
-        String availableGridType = "";
-        JsonNode availableSpectrum = mcPool.get(AVAILABLE_SPECTRUM);
-
-        /**At this time only the latest availableSpectrum is used**/
-        Iterator<JsonNode> iterAvailable = availableSpectrum.iterator();
-        while (iterAvailable.hasNext()) {
-            JsonNode availableSpec = iterAvailable.next();
-            availableUpperFrec = availableSpec.get(UPPER_FREQUENCY).asLong();
-            availableLowerFrec = availableSpec.get(LOWER_FREQUENCY).asLong();
-            availableAdjustmentGranularity = availableSpec.get(FREQUENCY_CONSTRAINT)
-                    .get(ADJUSTMENT_GRANULARITY).textValue();
-            availableGridType = availableSpec.get(FREQUENCY_CONSTRAINT).get(GRID_TYPE).textValue();
-        }
-
-        int spacingMult = 0;
-        int slotGranularity = 1;
-        ChannelSpacing chSpacing = getChannelSpacing(availableAdjustmentGranularity);
-        long spacingFrequency = chSpacing.frequency().asHz();
-        long centralFrequency = (availableUpperFrec - (availableUpperFrec - availableLowerFrec) / 2);
-
-        GridType gridType = GridType.valueOf(availableGridType);
-        if (gridType == GridType.DWDM) {
-            spacingMult = (int) ((centralFrequency - BASE_FREQUENCY) / toMbpsFromHz(spacingFrequency));
-        } else if (gridType == GridType.CWDM) {
-            log.warn("GridType CWDM. Not implemented");
-        } else if (gridType == GridType.FLEX) {
-            log.warn("GridType FLEX. Not implemented");
-            slotGranularity = getSlotGranularity(chSpacing);
-        } else {
-            log.warn("Unknown GridType");
-        }
-        return new OchSignal(gridType, chSpacing, spacingMult, slotGranularity);
+                        .contains(PHOTONIC_LAYER_QUALIFIER_NMC);
     }
 
 }
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceHelper.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceHelper.java
index d4e9c06..dee318c 100644
--- a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceHelper.java
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceHelper.java
@@ -17,17 +17,31 @@
  */
 package org.onosproject.drivers.odtn.tapi;
 
+import com.fasterxml.jackson.databind.JsonNode;
 import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.GridType;
+import org.onosproject.net.OchSignal;
+import org.slf4j.Logger;
+
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.stream.IntStream;
+
+import static org.slf4j.LoggerFactory.getLogger;
 
 /**
  * Tapi 2.1 OLS device related helpers.
  */
 public final class TapiDeviceHelper {
 
+    private static final Logger log = getLogger(TapiDeviceHelper.class);
+
     public static final String SERVICE_INTERFACE_POINT = "service-interface-point";
+    public static final String CONTEXT = "tapi-common:context";
     public static final String UUID = "uuid";
     public static final String MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC =
-            "media-channel-service-interface-point-spec";
+            "tapi-photonic-media:media-channel-service-interface-point-spec";
     public static final String MC_POOL = "mc-pool";
     public static final String LAYER_PROTOCOL_NAME = "layer-protocol-name";
     public static final String PHOTONIC_MEDIA = "PHOTONIC_MEDIA";
@@ -38,7 +52,6 @@
     public static final String ADJUSTMENT_GRANULARITY = "adjustment-granularity";
     public static final String UPPER_FREQUENCY = "upper-frequency";
     public static final String LOWER_FREQUENCY = "lower-frequency";
-    public static final String AVAILABLE_SPECTRUM = "available-spectrum";
     public static final long BASE_FREQUENCY = 193100000;   //Working in Mhz
     public static final String TAPI_CONNECTIVITY_CONNECTIVITY_SERVICE = "tapi-connectivity:connectivity-service";
     public static final String END_POINT = "end-point";
@@ -50,6 +63,8 @@
     public static final String TAPI_PHOTONIC_MEDIA_PHOTONIC_LAYER_QUALIFIER_NMC =
             "tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_NMC";
     public static final String SERVICE_INTERFACE_POINT_UUID = "service-interface-point-uuid";
+    public static final String AVAILABLE_SPECTRUM = "available-spectrum";
+    protected static final String SUPPORTABLE_SPECTRUM = "supportable-spectrum";
 
     private TapiDeviceHelper(){}
 
@@ -105,4 +120,57 @@
     public static long toMbpsFromHz(long speed) {
         return speed / 1000000;
     }
+
+    /**
+     * If SIP info match our criteria, SIP component shall includes mc-pool information which must be obtained in order
+     * to complete the OchSignal info. with the TAPI SIP information included in spectrum-supported, spectrum-available
+     * and spectrum-occupied tapi objects.
+     *
+     * @param mcPool the MC_POOL json node
+     * @return the set of OCH signals given the port's information
+     **/
+    protected static Set<OchSignal> getOchSignal(JsonNode mcPool) {
+
+        Set<OchSignal> lambdas = new LinkedHashSet<>();
+        long availableUpperFrec = 0;
+        long availableLowerFrec = 0;
+        String availableAdjustmentGranularity = "";
+        String availableGridType = "";
+        JsonNode availableSpectrum = mcPool.get(AVAILABLE_SPECTRUM);
+
+        if (availableSpectrum == null) {
+            availableSpectrum = mcPool.get(SUPPORTABLE_SPECTRUM);
+        }
+
+        Iterator<JsonNode> iterAvailable = availableSpectrum.iterator();
+        while (iterAvailable.hasNext()) {
+            JsonNode availableSpec = iterAvailable.next();
+            availableUpperFrec = availableSpec.get(UPPER_FREQUENCY).asLong();
+            availableLowerFrec = availableSpec.get(LOWER_FREQUENCY).asLong();
+            log.info("availableUpperFrec {}, availableLowerFrec {}", availableUpperFrec,
+                    availableLowerFrec);
+            availableAdjustmentGranularity = availableSpec.get(FREQUENCY_CONSTRAINT)
+                    .get(ADJUSTMENT_GRANULARITY).textValue();
+            availableGridType = availableSpec.get(FREQUENCY_CONSTRAINT).get(GRID_TYPE).textValue();
+
+            int slotGranularity;
+            ChannelSpacing chSpacing = getChannelSpacing(availableAdjustmentGranularity);
+            double spacingFrequency = chSpacing.frequency().asGHz();
+            int lambdaCount = (int) ((availableUpperFrec - availableLowerFrec) / spacingFrequency);
+            GridType gridType = GridType.valueOf(availableGridType);
+            if (gridType == GridType.DWDM) {
+                slotGranularity = getSlotGranularity(chSpacing);
+                int finalSlotGranularity = slotGranularity;
+                IntStream.range(0, lambdaCount).forEach(x -> lambdas.add(new OchSignal(GridType.DWDM, chSpacing,
+                        x - (lambdaCount / 2), finalSlotGranularity)));
+            } else if (gridType == GridType.CWDM) {
+                log.warn("GridType CWDM. Not implemented");
+            } else if (gridType == GridType.FLEX) {
+                log.warn("GridType FLEX. Not implemented");
+            } else {
+                log.warn("Unknown GridType");
+            }
+        }
+        return lambdas;
+    }
 }
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceLambdaQuery.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceLambdaQuery.java
index fa46b87..5f0f52e 100644
--- a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceLambdaQuery.java
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiDeviceLambdaQuery.java
@@ -17,46 +17,30 @@
  */
 package org.onosproject.drivers.odtn.tapi;
 
-import com.google.common.collect.ImmutableSet;
-import org.onosproject.net.Port;
-import org.onosproject.net.Device;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.ChannelSpacing;
-import org.onosproject.net.GridType;
-import org.onosproject.net.OchSignal;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.behaviour.LambdaQuery;
-import org.onosproject.net.driver.AbstractHandlerBehaviour;
-import org.onosproject.protocol.rest.RestSBController;
-
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.OchSignal;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.behaviour.LambdaQuery;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.protocol.rest.RestSBController;
 import org.slf4j.Logger;
 
+import javax.ws.rs.core.MediaType;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.Set;
 
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.AVAILABLE_SPECTRUM;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.ADJUSTMENT_GRANULARITY;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.BASE_FREQUENCY;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.FREQUENCY_CONSTRAINT;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.GRID_TYPE;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.LOWER_FREQUENCY;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.MC_POOL;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.UPPER_FREQUENCY;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.UUID;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.toMbpsFromHz;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.getChannelSpacing;
-import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.getSlotGranularity;
-
-import static org.slf4j.LoggerFactory.getLogger;
 import static com.google.common.base.Preconditions.checkNotNull;
-import org.onosproject.net.device.DeviceService;
-import javax.ws.rs.core.MediaType;
+import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.MC_POOL;
+import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC;
+import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.UUID;
+import static org.slf4j.LoggerFactory.getLogger;
 
 
 
@@ -67,7 +51,7 @@
         implements LambdaQuery {
 
     private static final Logger log = getLogger(TapiDeviceLambdaQuery.class);
-    private static final String SIP_REQUEST_DATA_API = "/data/context/service-interface-point=";
+    private static final String SIP_REQUEST_DATA_API = "/restconf/data/tapi-common:context/service-interface-point=";
 
     /**
      * Get the deviceId for which the methods apply.
@@ -103,9 +87,7 @@
             JsonNode mcPool = sipAttributes.get(MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC).get(MC_POOL);
 
             //This creates a hashset of OChSignals representing the spectrum availability at the target port.
-            Set<OchSignal> lambdas = getOchSignal(mcPool);
-            log.debug("Lambdas: {}", lambdas.toString());
-            return lambdas;
+            return TapiDeviceHelper.getOchSignal(mcPool);
 
         } catch (IOException e) {
             log.error("Exception discoverPortDetails() {}", did(), e);
@@ -113,51 +95,5 @@
         }
     }
 
-    /**
-     * If SIP info match our criteria, SIP component shall includes mc-pool information which must be obtained in order
-     * to complete the OchSignal info. with the TAPI SIP information included in spectrum-supported, spectrum-available
-     * and spectrum-occupied tapi objects.
-     **/
-    private Set<OchSignal> getOchSignal(JsonNode mcPool) {
-
-        Set<OchSignal> lambdas = new LinkedHashSet<>();
-        long availableUpperFrec = 0;
-        long availableLowerFrec = 0;
-        String availableAdjustmentGranularity = "";
-        String availableGridType = "";
-        JsonNode availableSpectrum = mcPool.get(AVAILABLE_SPECTRUM);
-
-        /**At this time only the latest availableSpectrum is used**/
-        Iterator<JsonNode> iterAvailable = availableSpectrum.iterator();
-        while (iterAvailable.hasNext()) {
-            JsonNode availableSpec = iterAvailable.next();
-            availableUpperFrec = availableSpec.get(UPPER_FREQUENCY).asLong();
-            availableLowerFrec = availableSpec.get(LOWER_FREQUENCY).asLong();
-            availableAdjustmentGranularity = availableSpec.get(FREQUENCY_CONSTRAINT)
-                    .get(ADJUSTMENT_GRANULARITY).textValue();
-            availableGridType = availableSpec.get(FREQUENCY_CONSTRAINT).get(GRID_TYPE).textValue();
-
-            int spacingMult = 0;
-            int slotGranularity = 1;
-            ChannelSpacing chSpacing = getChannelSpacing(availableAdjustmentGranularity);
-            long spacingFrequency = chSpacing.frequency().asHz();
-            long centralFrequency = (availableUpperFrec - (availableUpperFrec - availableLowerFrec) / 2);
-
-            GridType gridType = GridType.valueOf(availableGridType);
-            if (gridType == GridType.DWDM) {
-                spacingMult = (int) ((centralFrequency - BASE_FREQUENCY) / toMbpsFromHz(spacingFrequency));
-                OchSignal ochSignal = new OchSignal(gridType, chSpacing, spacingMult, slotGranularity);
-                lambdas.add(ochSignal);
-            } else if (gridType == GridType.CWDM) {
-                log.warn("GridType CWDM. Not implemented");
-            } else if (gridType == GridType.FLEX) {
-                log.warn("GridType FLEX. Not implemented");
-                slotGranularity = getSlotGranularity(chSpacing);
-            } else {
-                log.warn("Unknown GridType");
-            }
-        }
-        return lambdas;
-    }
 
 }
\ No newline at end of file
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiFlowRuleProgrammable.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiFlowRuleProgrammable.java
index c0bea12..d415738 100644
--- a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiFlowRuleProgrammable.java
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/tapi/TapiFlowRuleProgrammable.java
@@ -21,8 +21,6 @@
 import com.fasterxml.jackson.core.JsonFactory;
 import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectReader;
 import com.google.common.collect.ImmutableList;
 import org.apache.http.HttpStatus;
 import org.onosproject.drivers.odtn.impl.DeviceConnection;
@@ -45,13 +43,13 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onosproject.drivers.odtn.tapi.TapiDeviceHelper.END_POINT;
@@ -82,42 +80,50 @@
     private static final String CONN_REQ_REMOVE_DATA_API = "/restconf/data/tapi-common:context/" +
             "tapi-connectivity:connectivity-context/connectivity-service=";
     private static final String CONN_REQ_GET_API = "/restconf/data/tapi-common:context/" +
-            "tapi-connectivity:connectivity-context/";
+            "tapi-connectivity:connectivity-context/connectivity-service/";
 
 
     @Override
     public Collection<FlowEntry> getFlowEntries() {
         DeviceId deviceId = did();
-        RestSBController controller = checkNotNull(handler().get(RestSBController.class));
-        ObjectMapper om = new ObjectMapper();
-        final ObjectReader reader = om.reader();
-        // all waveserver responses contain data node, which contains the requested data
-        InputStream response = controller.get(deviceId, CONN_REQ_GET_API, MediaType.APPLICATION_JSON_TYPE);
-        JsonNode jsonNode = null;
-        try {
-            jsonNode = reader.readTree(response);
-            if (jsonNode == null) {
-                log.error("JsonNode is null for response {}", response);
-                return ImmutableList.of();
-            }
-            Set<String> uuids = parseTapiGetConnectivityRequest(jsonNode);
-            DeviceConnectionCache cache = getConnectionCache();
-            if (cache.get(deviceId) == null) {
-                return ImmutableList.of();
-            }
-            List<FlowEntry> entries = new ArrayList<>();
-            uuids.forEach(uuid -> {
-                FlowRule rule = cache.get(deviceId, uuid);
-                if (rule != null) {
-                    entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
-                } else {
-                    log.info("Non existing rule for uuid {}", uuid);
-                }
+        //TODO this is a blocking call on ADVA OLS, right now using cache.
+//        RestSBController controller = checkNotNull(handler().get(RestSBController.class));
+//        ObjectMapper om = new ObjectMapper();
+//        final ObjectReader reader = om.reader();
+//        InputStream response = controller.get(deviceId, CONN_REQ_GET_API, MediaType.APPLICATION_JSON_TYPE);
+//        JsonNode jsonNode = null;
+//        try {
+//            jsonNode = reader.readTree(response);
+//            if (jsonNode == null) {
+//                log.debug("JsonNode is null for response {}", response);
+//                return ImmutableList.of();
+//            }
+//            Set<String> uuids = parseTapiGetConnectivityRequest(jsonNode);
+//            DeviceConnectionCache cache = getConnectionCache();
+//            if (cache.get(deviceId) == null) {
+//                return ImmutableList.of();
+//            }
+//            List<FlowEntry> entries = new ArrayList<>();
+//            uuids.forEach(uuid -> {
+//                FlowRule rule = cache.get(deviceId, uuid);
+//                if (rule != null) {
+//                    entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
+//                } else {
+//                    log.info("Non existing rule for uuid {}", uuid);
+//                }
+//            });
+//            return entries;
+//        } catch (IOException e) {
+//            return ImmutableList.of();
+//        }
+        List<FlowEntry> entries = new ArrayList<>();
+        Set<FlowRule> rules = getConnectionCache().get(deviceId);
+        if (rules != null) {
+            rules.forEach(rule -> {
+                entries.add(new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED, 0, 0, 0));
             });
-            return entries;
-        } catch (IOException e) {
-            return ImmutableList.of();
         }
+        return entries;
     }
 
     @Override
@@ -129,18 +135,25 @@
             String uuid = createUuid();
             ByteArrayOutputStream applyConnectivityRequest = createConnectivityRequest(uuid, flowRule);
             if (applyConnectivityRequest.size() != 0) {
-                int result = controller.post(deviceId, CONN_REQ_POST_API,
+                CompletableFuture<Integer>  flowInstallation =
+                        CompletableFuture.supplyAsync(() -> controller.post(deviceId, CONN_REQ_POST_API,
                         new ByteArrayInputStream(applyConnectivityRequest.toByteArray()),
-                        MediaType.APPLICATION_JSON_TYPE);
+                        MediaType.APPLICATION_JSON_TYPE));
+                flowInstallation.thenApply(result -> {
+                    if (result == HttpStatus.SC_CREATED) {
+                        getConnectionCache().add(deviceId, uuid, flowRule);
+                        added.add(flowRule);
+                    } else {
+                       log.error("Can't add flow {}, result {}", flowRule, result);
+                    }
+                    return result;
+                });
                 // TODO retrieve the UUID from the location and store with that identifier
                 // at the moment is implied that the sent one is the same used by the TAPI server.
-                if (result == HttpStatus.SC_CREATED) {
-                    getConnectionCache().add(deviceId, uuid, flowRule);
-                    added.add(flowRule);
-                }
             }
         });
-        return added.build();
+        //TODO workaround for blocking call on ADVA OLS should return added
+        return rules;
     }
 
     @Override
@@ -155,14 +168,22 @@
                         flowRule.id(), deviceId);
                 return;
             }
-            int result = controller.delete(deviceId, CONN_REQ_REMOVE_DATA_API + conn.getId(),
-                    null, MediaType.APPLICATION_JSON_TYPE);
-            if (result == HttpStatus.SC_NO_CONTENT) {
-                getConnectionCache().remove(deviceId, flowRule);
-                removed.add(flowRule);
-            }
+            CompletableFuture<Integer>  flowInstallation =
+                    CompletableFuture.supplyAsync(() -> controller.delete(deviceId,
+                            CONN_REQ_REMOVE_DATA_API + conn.getId(),
+                            null, MediaType.APPLICATION_JSON_TYPE));
+            flowInstallation.thenApply(result -> {
+                if (result == HttpStatus.SC_NO_CONTENT) {
+                    getConnectionCache().remove(deviceId, flowRule);
+                    removed.add(flowRule);
+                } else {
+                    log.error("Can't remove flow {}, result {}", flowRule, result);
+                }
+                return result;
+            });
         });
-        return removed.build();
+        //TODO workaround for blocking call on ADVA OLS shoudl return removed
+        return rules;
     }
 
     /**
@@ -193,8 +214,8 @@
         if (tapiConnectivityReply.has(TAPI_CONNECTIVITY_CONNECTIVITY_SERVICE)) {
             tapiConnectivityReply.get(TAPI_CONNECTIVITY_CONNECTIVITY_SERVICE).elements()
                     .forEachRemaining(node -> uuids.add(node.get(TapiDeviceHelper.UUID).asText()));
-        } else {
-            log.warn("Cant retrieve connectivity UUID from {}", tapiConnectivityReply);
+        } else if (tapiConnectivityReply.size() != 0) {
+            log.warn("Can't retrieve connectivity UUID from {}", tapiConnectivityReply);
         }
         //This is only one uuid or empty in case of failures
         return uuids;
diff --git a/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java b/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java
index cd738cd..c89e59b 100644
--- a/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java
+++ b/providers/rest/device/src/main/java/org/onosproject/provider/rest/device/impl/RestDeviceProvider.java
@@ -581,6 +581,16 @@
         return false;
     }
 
+    private Runnable exceptionSafe(Runnable runnable) {
+        return () -> {
+            try {
+                runnable.run();
+            } catch (Exception e) {
+                log.error("Unhandled Exception", e);
+            }
+        };
+    }
+
     private class InternalNetworkConfigListener implements NetworkConfigListener {
         @Override
         public void event(NetworkConfigEvent event) {
@@ -601,7 +611,7 @@
                         event.type(), event.config().get().subject());
                 RestDeviceConfig cfg = (RestDeviceConfig) event.config().get();
                 RestSBDevice restSBDevice = toInactiveRestSBDevice(cfg);
-                bg.execute(() -> connectDevice(restSBDevice));
+                bg.execute(exceptionSafe(() -> connectDevice(restSBDevice)));
             }
         }