initial commit

Change-Id: Idddb494b6593de2188b5c837f3caa46c0e956573
diff --git a/src/main/java/org/opencord/sadis/AppWebApplication.java b/src/main/java/org/opencord/sadis/AppWebApplication.java
new file mode 100644
index 0000000..6bbbe48
--- /dev/null
+++ b/src/main/java/org/opencord/sadis/AppWebApplication.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.opencord.sadis;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * Subscriber And Device Infomration Service REST API web application.
+ */
+public class AppWebApplication extends AbstractWebApplication {
+    @Override
+    public Set<Class<?>> getClasses() {
+        return getClasses(AppWebResource.class);
+    }
+}
diff --git a/src/main/java/org/opencord/sadis/AppWebResource.java b/src/main/java/org/opencord/sadis/AppWebResource.java
new file mode 100644
index 0000000..581728c
--- /dev/null
+++ b/src/main/java/org/opencord/sadis/AppWebResource.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.rest.AbstractWebResource;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+//import static org.onlab.util.Tools.nullIsNotFound;
+
+/**
+ * Subscriber And Device Information Service web resource.
+ */
+@Path("sadis")
+public class AppWebResource extends AbstractWebResource {
+
+    /**
+     * Get subscriber object.
+     *
+     * @param id
+     *            ID of the subscriber
+     *
+     * @return 200 OK
+     */
+    @GET
+    @Path("/subscriber/{id}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response getSubscriber(@PathParam("id") String id) {
+        ObjectNode node = mapper().createObjectNode().put("hello", "world");
+        return ok(node).build();
+    }
+
+    /**
+     * Update subscriber object.
+     *
+     * @param id
+     *            ID of the subscriber
+     *
+     * @return 200 OK
+     */
+    @PUT
+    @Path("/subscriber/{id}")
+    @Consumes(MediaType.APPLICATION_JSON)
+    public Response putSubscriber(@PathParam("id") String id) {
+        return Response.ok().build();
+    }
+
+    /**
+     * Create subscriber object.
+     *
+     * @return 201 Created
+     */
+    @POST
+    @Path("/subscriber")
+    @Consumes(MediaType.APPLICATION_JSON)
+    public Response postSubscriber() {
+        try {
+            return Response.created(new URI("/subsciber/123")).build();
+        } catch (URISyntaxException e) {
+            return Response.serverError().build();
+        }
+    }
+
+    /**
+     * Delete subscriber object.
+     *
+     * @param id
+     *            ID of the subscriber
+     * @return 204 NoContent
+     */
+    @DELETE
+    @Path("/subscriber/{id}")
+    public Response deleteSubscriber(@PathParam("id") String id) {
+        return Response.noContent().build();
+    }
+}
diff --git a/src/main/java/org/opencord/sadis/SadisConfig.java b/src/main/java/org/opencord/sadis/SadisConfig.java
new file mode 100644
index 0000000..ab6128d
--- /dev/null
+++ b/src/main/java/org/opencord/sadis/SadisConfig.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onlab.packet.VlanId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.Config;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+
+/**
+ * Configuration options for the Subscriber And Device Information Service.
+ *
+ * <pre>
+ * "sadis" : {
+ *     "integration" : {
+ *         "url" : "http://{hostname}{:port}",
+ *         "cache" : {
+ *             "enable"   : true or false,
+ *             "maxsize"  : number of entries,
+ *             "entryttl" : duration, i.e. 10s or 1m
+ *         }
+ *     },
+ *     "entries" : [
+ *         {
+ *             "id"                 : "uniqueid",
+ *             "ctag"               : int,
+ *             "stag"               : int,
+ *             "nasportid"          : string,
+ *             "port"               : int,
+ *             "slot"               : int,
+ *             "hardwareidentifier" : string
+ *         }, ...
+ *     ]
+ * }
+ * </pre>
+ */
+public class SadisConfig extends Config<ApplicationId> {
+
+    private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    private static final String SADIS_INTEGRATION = "integration";
+    private static final String SADIS_CACHE = "cache";
+    private static final String SADIS_CACHE_ENABLED = "enabled";
+    private static final String SADIS_CACHE_SIZE = "maxsize";
+    private static final String SADIS_CACHE_TTL = "ttl";
+    private static final String SADIS_URL = "url";
+    private static final String SADIS_ENTRIES = "entries";
+    private static final String DEFAULT_CACHE_TTL = "PT0S";
+
+    /**
+     * Returns SADIS integration URL.
+     *
+     * @return configured URL or null
+     * @throws MalformedURLException
+     *             specified URL not valid
+     */
+    public URL getUrl() throws MalformedURLException {
+        final JsonNode integration = this.object.path(SADIS_INTEGRATION);
+        if (integration.isMissingNode()) {
+            return null;
+        }
+
+        final JsonNode url = integration.path(SADIS_URL);
+        if (url.isMissingNode()) {
+            return null;
+        }
+
+        return new URL(url.asText());
+    }
+
+    /**
+     * Returns configuration if cache should be used or not. Only used if
+     * integration URL is set.
+     *
+     * @return if cache should be used
+     */
+    public Boolean getCacheEnabled() {
+        final JsonNode integration = this.object.path(SADIS_INTEGRATION);
+        if (integration.isMissingNode()) {
+            return false;
+        }
+
+        final JsonNode cache = integration.path(SADIS_CACHE);
+        if (cache.isMissingNode()) {
+            return false;
+        }
+
+        return cache.path(SADIS_CACHE_ENABLED).asBoolean(false);
+    }
+
+    public int getCacheMaxSize() {
+        final JsonNode integration = this.object.path(SADIS_INTEGRATION);
+        if (integration.isMissingNode()) {
+            return -1;
+        }
+
+        final JsonNode cache = integration.path(SADIS_CACHE);
+        if (cache.isMissingNode()) {
+            return -1;
+        }
+
+        return cache.path(SADIS_CACHE_SIZE).asInt(-1);
+    }
+
+    public Duration getCacheTtl() {
+        final JsonNode integration = this.object.path(SADIS_INTEGRATION);
+        if (integration.isMissingNode()) {
+            return Duration.parse(DEFAULT_CACHE_TTL);
+        }
+
+        final JsonNode cache = integration.path(SADIS_CACHE);
+        if (cache.isMissingNode()) {
+            return Duration.parse(DEFAULT_CACHE_TTL);
+        }
+
+        return Duration.parse(cache.path(SADIS_CACHE_TTL).asText(DEFAULT_CACHE_TTL));
+    }
+
+    public List<SubscriberAndDeviceInformation> getEntries() {
+        List<SubscriberAndDeviceInformation> result = new ArrayList<SubscriberAndDeviceInformation>();
+        ObjectMapper mapper = new ObjectMapper();
+        SimpleModule module = new SimpleModule();
+        module.addDeserializer(VlanId.class, new VlanIdDeserializer());
+        mapper.registerModule(module);
+        final JsonNode entries = this.object.path(SADIS_ENTRIES);
+        entries.forEach(entry -> {
+            try {
+                result.add(mapper.readValue(entry.toString(), SubscriberAndDeviceInformation.class));
+            } catch (IOException e) {
+                log.warn("Unable to parse configuration entry, '{}', error: {}", entry.toString(), e.getMessage());
+            }
+        });
+
+        return result;
+    }
+
+    public class VlanIdDeserializer extends JsonDeserializer<VlanId> {
+        @Override
+        public VlanId deserialize(JsonParser jp, DeserializationContext ctxt)
+                throws IOException, JsonProcessingException {
+            ObjectCodec oc = jp.getCodec();
+            JsonNode node = oc.readTree(jp);
+            return VlanId.vlanId((short) node.asInt());
+        }
+    }
+}
diff --git a/src/main/java/org/opencord/sadis/SadisManager.java b/src/main/java/org/opencord/sadis/SadisManager.java
new file mode 100644
index 0000000..7d060c3
--- /dev/null
+++ b/src/main/java/org/opencord/sadis/SadisManager.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis;
+
+import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
+
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Subscriber And Device Information Service application component. Component
+ * that manages the integration of ONOS into a deployment providing a bridge
+ * between ONOS and deployment specific information about subscribers and access
+ * devices.
+ */
+@Service
+@Component(immediate = true)
+public class SadisManager extends SubscriberAndDeviceInformationAdapter {
+    private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+    private static final String SADIS_APP = "org.opencord.sadis";
+    private ApplicationId appId;
+    private final InternalConfigListener cfgListener = new InternalConfigListener();
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigRegistry cfgService;
+
+    @SuppressWarnings("rawtypes")
+    private final Set<ConfigFactory> factories = ImmutableSet
+            .of(new ConfigFactory<ApplicationId, SadisConfig>(APP_SUBJECT_FACTORY, SadisConfig.class, "sadis") {
+                @Override
+                public SadisConfig createConfig() {
+                    return new SadisConfig();
+                }
+            });
+
+    /**
+     * Initialize the SADIS ONOS application.
+     */
+    @Activate
+    protected void activate() {
+
+        this.appId = this.coreService.registerApplication(SADIS_APP);
+        this.cfgService.addListener(this.cfgListener);
+        this.factories.forEach(this.cfgService::registerConfigFactory);
+        this.updateConfig();
+
+        this.log.info("Started");
+    }
+
+    /**
+     * Cleans up resources utilized by the SADIS ONOS application.
+     */
+    @Deactivate
+    protected void deactivate() {
+        this.log.info("Stopped");
+    }
+
+    /**
+     * Validates the configuration and updates any operational settings that are
+     * affected by configuration changes.
+     */
+    private void updateConfig() {
+        final SadisConfig cfg = this.cfgService.getConfig(this.appId, SadisConfig.class);
+        if (cfg == null) {
+            this.log.warn("Subscriber And Device Information Service (SADIS) configuration not available");
+            return;
+        }
+        this.log.info("Cache Enabled:  {}", cfg.getCacheEnabled());
+        this.log.info("Cache Mac Size: {}", cfg.getCacheMaxSize());
+        this.log.info("Cache TTL:      {}", cfg.getCacheTtl().getSeconds());
+        this.log.info("Entries:        {}", cfg.getEntries());
+    }
+
+    /**
+     * Listener for SADIS configuration events.
+     */
+    private class InternalConfigListener implements NetworkConfigListener {
+
+        @Override
+        public void event(final NetworkConfigEvent event) {
+
+            if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
+                    || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)
+                    && event.configClass().equals(SadisConfig.class)) {
+                SadisManager.this.updateConfig();
+                SadisManager.this.log.info("Reconfigured");
+            }
+        }
+    }
+}
diff --git a/src/main/java/org/opencord/sadis/SubscriberAndDeviceInformation.java b/src/main/java/org/opencord/sadis/SubscriberAndDeviceInformation.java
new file mode 100644
index 0000000..72cbfa0
--- /dev/null
+++ b/src/main/java/org/opencord/sadis/SubscriberAndDeviceInformation.java
@@ -0,0 +1,216 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis;
+
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Represents a unit of information about a subscriber or access device.
+ */
+public class SubscriberAndDeviceInformation {
+
+    @JsonProperty(value = "id")
+    String id;
+
+    @JsonProperty(value = "sTag")
+    VlanId sTag;
+
+    @JsonProperty(value = "cTag")
+    VlanId cTag;
+
+    @JsonProperty(value = "nasPortId")
+    String nasPortId;
+
+    @JsonProperty(value = "port")
+    int port;
+
+    @JsonProperty(value = "slot")
+    int slot;
+
+    @JsonProperty(value = "hardwareIdentifier")
+    MacAddress hardwareIdentifier;
+
+    SubscriberAndDeviceInformation() {
+    }
+
+    public final String id() {
+        return this.id;
+    }
+
+    public final void setId(final String id) {
+        this.id = id;
+    }
+
+    public final VlanId sTag() {
+        return this.sTag;
+    }
+
+    public final void setSTag(final VlanId stag) {
+        this.sTag = stag;
+    }
+
+    public final VlanId cTag() {
+        return this.cTag;
+    }
+
+    public final void setCTag(final VlanId ctag) {
+        this.cTag = ctag;
+    }
+
+    public final String nasPortId() {
+        return this.nasPortId;
+    }
+
+    public final void setNasPortId(final String nasPortId) {
+        this.nasPortId = nasPortId;
+    }
+
+    public final int port() {
+        return this.port;
+    }
+
+    public final void setPort(final int port) {
+        this.port = port;
+    }
+
+    public final int slot() {
+        return this.slot;
+    }
+
+    public final void setSlot(final int slot) {
+        this.slot = slot;
+    }
+
+    public final MacAddress hardwareIdentifier() {
+        return this.hardwareIdentifier;
+    }
+
+    public final void setHardwareIdentifier(final MacAddress hardwareIdentifier) {
+        this.hardwareIdentifier = hardwareIdentifier;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (this.cTag == null ? 0 : this.cTag.hashCode());
+        result = prime * result + (this.hardwareIdentifier == null ? 0 : this.hardwareIdentifier.hashCode());
+        result = prime * result + (this.id == null ? 0 : this.id.hashCode());
+        result = prime * result + (this.nasPortId == null ? 0 : this.nasPortId.hashCode());
+        result = prime * result + this.port;
+        result = prime * result + (this.sTag == null ? 0 : this.sTag.hashCode());
+        result = prime * result + this.slot;
+        return result;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (this.getClass() != obj.getClass()) {
+            return false;
+        }
+        final SubscriberAndDeviceInformation other = (SubscriberAndDeviceInformation) obj;
+        if (this.cTag == null) {
+            if (other.cTag != null) {
+                return false;
+            }
+        } else if (!this.cTag.equals(other.cTag)) {
+            return false;
+        }
+        if (this.hardwareIdentifier == null) {
+            if (other.hardwareIdentifier != null) {
+                return false;
+            }
+        } else if (!this.hardwareIdentifier.equals(other.hardwareIdentifier)) {
+            return false;
+        }
+        if (this.id == null) {
+            if (other.id != null) {
+                return false;
+            }
+        } else if (!this.id.equals(other.id)) {
+            return false;
+        }
+        if (this.nasPortId == null) {
+            if (other.nasPortId != null) {
+                return false;
+            }
+        } else if (!this.nasPortId.equals(other.nasPortId)) {
+            return false;
+        }
+        if (this.port != other.port) {
+            return false;
+        }
+        if (this.sTag == null) {
+            if (other.sTag != null) {
+                return false;
+            }
+        } else if (!this.sTag.equals(other.sTag)) {
+            return false;
+        }
+        if (this.slot != other.slot) {
+            return false;
+        }
+        return true;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        final StringBuilder buf = new StringBuilder();
+        buf.append('[');
+        buf.append("id:");
+        buf.append(this.id);
+        buf.append(",cTag:");
+        buf.append(this.cTag);
+        buf.append(",sTag:");
+        buf.append(this.sTag);
+        buf.append(",nasPortId:");
+        buf.append(this.nasPortId);
+        buf.append(",port:");
+        buf.append(this.port);
+        buf.append(",slot:");
+        buf.append(this.slot);
+        buf.append(",hardwareIdentifier:");
+        buf.append(this.hardwareIdentifier);
+        buf.append(']');
+
+        return buf.toString();
+    }
+
+}
diff --git a/src/main/java/org/opencord/sadis/SubscriberAndDeviceInformationAdapter.java b/src/main/java/org/opencord/sadis/SubscriberAndDeviceInformationAdapter.java
new file mode 100644
index 0000000..c131704
--- /dev/null
+++ b/src/main/java/org/opencord/sadis/SubscriberAndDeviceInformationAdapter.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.concurrent.TimeUnit;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+
+public abstract class SubscriberAndDeviceInformationAdapter implements SubscriberAndDeviceInformationService {
+    private static final int DEFAULT_MAXIMUM_CACHE_SIZE = 0;
+    private static final long DEFAULT_TTL = 0;
+
+    private String url;
+    private Cache<String, SubscriberAndDeviceInformation> cache;
+    private int maxiumCacheSize = DEFAULT_MAXIMUM_CACHE_SIZE;
+    private long cacheEntryTtl = DEFAULT_TTL;
+
+    public SubscriberAndDeviceInformationAdapter() {
+        cache = CacheBuilder.newBuilder().maximumSize(maxiumCacheSize)
+                .expireAfterAccess(cacheEntryTtl, TimeUnit.SECONDS).build();
+    }
+
+    public void configure(String url, int maximumCacheSeize, long cacheEntryTtl) {
+        // Rebuild cache if needed
+        if (url != this.url || maximumCacheSeize != this.maxiumCacheSize || cacheEntryTtl != this.cacheEntryTtl) {
+            this.url = url;
+            this.maxiumCacheSize = maximumCacheSeize;
+            this.cacheEntryTtl = cacheEntryTtl;
+            Cache<String, SubscriberAndDeviceInformation> newCache = CacheBuilder.newBuilder()
+                    .maximumSize(maxiumCacheSize).expireAfterAccess(cacheEntryTtl, TimeUnit.SECONDS).build();
+            Cache<String, SubscriberAndDeviceInformation> oldCache = cache;
+
+            synchronized (this) {
+                cache = newCache;
+            }
+
+            oldCache.invalidateAll();
+            oldCache.cleanUp();
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.opencord.sadis.SubscriberAndDeviceInformationService#clearCache()
+     */
+    @Override
+    public void invalidateAll() {
+        cache.invalidateAll();
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.opencord.sadis.SubscriberAndDeviceInformationService#get(java.lang.
+     * String)
+     */
+    @Override
+    public SubscriberAndDeviceInformation get(String id) {
+        Cache<String, SubscriberAndDeviceInformation> local;
+        synchronized (this) {
+            local = cache;
+        }
+
+        SubscriberAndDeviceInformation info = local.getIfPresent(id);
+        if (info != null) {
+            return info;
+        }
+
+        /*
+         * Not in cache, if we have a URL configured we can attempt to get it
+         * from there.
+         */
+        if (this.url == null) {
+            return null;
+        }
+
+        // Augment URL with query parameters
+        StringBuilder buf = new StringBuilder(this.url);
+        if (buf.charAt(buf.length() - 1) != '/') {
+            buf.append('/');
+        }
+
+        buf.append(id);
+
+        try (InputStream io = new URL(buf.toString()).openStream()) {
+            ObjectMapper mapper = new ObjectMapper();
+            info = mapper.readValue(io, SubscriberAndDeviceInformation.class);
+            local.put(id, info);
+            return info;
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return null;
+    }
+}
diff --git a/src/main/java/org/opencord/sadis/SubscriberAndDeviceInformationService.java b/src/main/java/org/opencord/sadis/SubscriberAndDeviceInformationService.java
new file mode 100644
index 0000000..8754978
--- /dev/null
+++ b/src/main/java/org/opencord/sadis/SubscriberAndDeviceInformationService.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2015-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis;
+
+/**
+ * Subscriber And Device Information Service.
+ */
+public interface SubscriberAndDeviceInformationService {
+
+    /**
+     * Removes all cached entries.
+     */
+    public void invalidateAll();
+
+    /**
+     * Return the information associated with the given ID.
+     *
+     * @param id
+     *            key to information
+     * @return information associated with ID, if available, else null
+     */
+    public SubscriberAndDeviceInformation get(String id);
+}
diff --git a/src/main/java/org/opencord/sadis/cli/SubscriberGetCommand.java b/src/main/java/org/opencord/sadis/cli/SubscriberGetCommand.java
new file mode 100644
index 0000000..bc5e812
--- /dev/null
+++ b/src/main/java/org/opencord/sadis/cli/SubscriberGetCommand.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+
+/**
+ * Subscriber And Device Information Service CLI.
+ */
+@Command(scope = "onos", name = "sadis", description = "Subscriber And Device Information Service CLI command")
+public class SubscriberGetCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "ID", description = "subscriber ID", required = true, multiValued = false)
+    String id;
+
+    @Override
+    protected void execute() {
+        print("Hello %s", "World");
+    }
+
+}
diff --git a/src/main/java/org/opencord/sadis/cli/package-info.java b/src/main/java/org/opencord/sadis/cli/package-info.java
new file mode 100644
index 0000000..9eee64f
--- /dev/null
+++ b/src/main/java/org/opencord/sadis/cli/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Subscriber And Device Information Service CLI handlers.
+ */
+package org.opencord.sadis.cli;
diff --git a/src/main/java/org/opencord/sadis/package-info.java b/src/main/java/org/opencord/sadis/package-info.java
new file mode 100644
index 0000000..cef1f21
--- /dev/null
+++ b/src/main/java/org/opencord/sadis/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * The purpose of this service is to define an optional service that provides a bridge
+ * to the customer's infrastructure to query / cache subsciber/access information
+ * and make it available to other services / applications within the ONOS/CORD
+ * infrastructure.
+ */
+package org.opencord.sadis;
diff --git a/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/src/main/resources/OSGI-INF/blueprint/shell-config.xml
new file mode 100644
index 0000000..9c8f318
--- /dev/null
+++ b/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -0,0 +1,24 @@
+<!--
+  ~ Copyright 2017-present Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+        <command>
+            <action class="org.opencord.sadis.AppCommand"/>
+        </command>
+    </command-bundle>
+
+</blueprint>
diff --git a/src/main/resources/config.json b/src/main/resources/config.json
new file mode 100644
index 0000000..e01da23
--- /dev/null
+++ b/src/main/resources/config.json
@@ -0,0 +1,35 @@
+{
+	"integration":
+	{
+		"url": "http://localhost:8090",
+		"cache":
+		{
+			"enabled": true,
+			"maxsize": 50,
+			"ttl": "PT1m"
+		}
+	},
+
+	"entries":
+	[
+		{
+			"id": "1",
+			"cTag": 2,
+			"sTag": 2,
+			"nasPortId": "1/1/2",
+			"port": 125,
+			"slot": 3,
+			"hardwareIdentifier": "aa:bb:cc:dd:ee:ff"
+		},
+
+		{
+			"id": "2",
+			"cTag": 4,
+			"sTag": 4,
+			"nasPortId": "1/1/2",
+			"port": 129,
+			"slot": 4,
+			"hardwareIdentifier": "aa:bb:cc:dd:ee:ff"
+		}
+	]
+}
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..e27be50
--- /dev/null
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2017-present Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xmlns="http://java.sun.com/xml/ns/javaee"
+         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+         id="ONOS" version="2.5">
+    <display-name>Sample App REST API v1.0</display-name>
+
+    <security-constraint>
+        <web-resource-collection>
+            <web-resource-name>Secured</web-resource-name>
+            <url-pattern>/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>admin</role-name>
+        </auth-constraint>
+    </security-constraint>
+
+    <security-role>
+        <role-name>admin</role-name>
+    </security-role>
+
+    <login-config>
+        <auth-method>BASIC</auth-method>
+        <realm-name>karaf</realm-name>
+    </login-config>
+
+    <servlet>
+        <servlet-name>JAX-RS Service</servlet-name>
+        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+        <init-param>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>org.opencord.sadis.AppWebApplication</param-value>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>JAX-RS Service</servlet-name>
+        <url-pattern>/*</url-pattern>
+    </servlet-mapping>
+</web-app>
diff --git a/src/test/java/org/opencord/sadis/SadisManagerTest.java b/src/test/java/org/opencord/sadis/SadisManagerTest.java
new file mode 100644
index 0000000..cf0f2e6
--- /dev/null
+++ b/src/test/java/org/opencord/sadis/SadisManagerTest.java
@@ -0,0 +1,213 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.InputStream;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreServiceAdapter;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.config.ConfigApplyDelegate;
+import org.onosproject.net.config.NetworkConfigRegistryAdapter;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Set of tests of the SADIS ONOS application component.
+ */
+public class SadisManagerTest {
+
+    private SadisManager sadis;
+
+    @Before
+    public void setUp() throws Exception {
+        this.sadis = new SadisManager();
+        this.sadis.coreService = new MockCoreService();
+
+        final InputStream jsonStream = SadisManagerTest.class.getResourceAsStream("/config.json");
+
+        final ObjectMapper mapper = new ObjectMapper();
+        final JsonNode testConfig = mapper.readTree(jsonStream);
+        final ConfigApplyDelegate delegate = new MockConfigDelegate();
+
+        final SadisConfig config = new SadisConfig();
+        final ApplicationId subject = this.sadis.coreService.registerApplication("org.opencord.sadis");
+
+        config.init(subject, "sadis-test", testConfig, mapper, delegate);
+
+        this.sadis.cfgService = new MockNetworkConfigRegistry(config);
+        this.sadis.activate();
+    }
+
+    @After
+    public void tearDown() {
+        this.sadis.deactivate();
+    }
+
+    @Test
+    public void testConfiguration() {
+        SadisConfig config = sadis.cfgService.getConfig(null, SadisConfig.class);
+        assertEquals(true, config.getCacheEnabled());
+        assertEquals(50, config.getCacheMaxSize());
+        assertEquals(Duration.parse("PT1m"), config.getCacheTtl());
+        List<SubscriberAndDeviceInformation> entries = config.getEntries();
+        assertEquals(2, entries.size());
+        assertEquals(SubscriberAndDeviceInformationBuilder.build("1", (short) 2, (short) 2, "1/1/2", (short) 125,
+                (short) 3, "aa:bb:cc:dd:ee:ff"), entries.get(0));
+        assertEquals(SubscriberAndDeviceInformationBuilder.build("2", (short) 4, (short) 4, "1/1/2", (short) 129,
+                (short) 4, "aa:bb:cc:dd:ee:ff"), entries.get(1));
+
+    }
+
+    // Mocks live here
+
+    private static final class SubscriberAndDeviceInformationBuilder extends SubscriberAndDeviceInformation {
+
+        public static SubscriberAndDeviceInformation build(String id, short cTag, short sTag, String nasPortId,
+                short port, short slot, String mac) {
+            SubscriberAndDeviceInformation info = new SubscriberAndDeviceInformation();
+            info.setId(id);
+            info.setCTag(VlanId.vlanId(cTag));
+            info.setSTag(VlanId.vlanId(sTag));
+            info.setNasPortId(nasPortId);
+            info.setPort(port);
+            info.setSlot(slot);
+            info.setHardwareIdentifier(MacAddress.valueOf(mac));
+            return info;
+        }
+    }
+
+    /**
+     * Mocks an ONOS configuration delegate to allow JSON based configuration to
+     * be tested.
+     */
+    private static final class MockConfigDelegate implements ConfigApplyDelegate {
+        @Override
+        public void onApply(@SuppressWarnings("rawtypes") Config config) {
+            config.apply();
+        }
+    }
+
+    /**
+     * Mocks an instance of {@link ApplicationId} so that the application
+     * component under test can query and use its application ID.
+     */
+    private static final class MockApplicationId implements ApplicationId {
+
+        private final short id;
+        private final String name;
+
+        public MockApplicationId(short id, String name) {
+            this.id = id;
+            this.name = name;
+        }
+
+        @Override
+        public short id() {
+            return id;
+        }
+
+        @Override
+        public String name() {
+            return name;
+        }
+    }
+
+    /**
+     * Mocks the core services of ONOS so that the application under test can
+     * register and query application IDs.
+     */
+    private static final class MockCoreService extends CoreServiceAdapter {
+
+        private List<ApplicationId> idList = new ArrayList<ApplicationId>();
+        private Map<String, ApplicationId> idMap = new HashMap<String, ApplicationId>();
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see
+         * org.onosproject.core.CoreServiceAdapter#getAppId(java.lang.Short)
+         */
+        @Override
+        public ApplicationId getAppId(Short id) {
+            if (id >= idList.size()) {
+                return null;
+            }
+            return idList.get(id);
+        }
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see
+         * org.onosproject.core.CoreServiceAdapter#getAppId(java.lang.String)
+         */
+        @Override
+        public ApplicationId getAppId(String name) {
+            return idMap.get(name);
+        }
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see
+         * org.onosproject.core.CoreServiceAdapter#registerApplication(java.lang
+         * .String)
+         */
+        @Override
+        public ApplicationId registerApplication(String name) {
+            ApplicationId appId = idMap.get(name);
+            if (appId == null) {
+                appId = new MockApplicationId((short) idList.size(), name);
+                idList.add(appId);
+                idMap.put(name, appId);
+            }
+            return appId;
+        }
+
+    }
+
+    /**
+     * Mocks the ONOS network configuration registry so that the application
+     * under test can access a JSON defined configuration.
+     */
+    static final class MockNetworkConfigRegistry extends NetworkConfigRegistryAdapter {
+        private final SadisConfig config;
+
+        public MockNetworkConfigRegistry(final SadisConfig config) {
+            this.config = config;
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public <S, C extends Config<S>> C getConfig(final S subject, final Class<C> configClass) {
+            return (C) this.config;
+        }
+    }
+}