[ONOS-6055] Define mapping store interface with skeleton impl codes
Change-Id: Icb2bf9e3985ed0316bd54fa300385060112c52fb
diff --git a/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingStore.java b/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingStore.java
index f5f4413..b93a3a9 100644
--- a/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingStore.java
+++ b/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingStore.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.mapping;
+import org.onosproject.net.DeviceId;
import org.onosproject.store.Store;
/**
@@ -37,4 +38,85 @@
*/
MAP_CACHE
}
+
+ /**
+ * Obtains the number of mapping in the specified store.
+ *
+ * @param type store type
+ * @return number of mapping
+ */
+ int getMappingCount(Type type);
+
+ /**
+ * Obtains the stored mapping from the specified store.
+ *
+ * @param type store type
+ * @param mapping the mapping to look for
+ * @return a mapping
+ */
+ MappingEntry getMappingEntry(Type type, Mapping mapping);
+
+ /**
+ * Obtains the mapping entries associated with a device from the
+ * specified store.
+ *
+ * @param type store type
+ * @param deviceId device identifier
+ * @return the mapping entries
+ */
+ Iterable<MappingEntry> getMappingEntries(Type type, DeviceId deviceId);
+
+ /**
+ * Marks a mapping for deletion. Actual deletion will occur when the
+ * provider indicates that the mapping has been removed.
+ *
+ * @param type store type
+ * @param mapping the mapping to delete
+ */
+ void deleteMapping(Type type, Mapping mapping);
+
+ /**
+ * Stores a new mapping or updates an existing entry from/to the
+ * specified store.
+ *
+ * @param type store type
+ * @param entry the mapping to add or update
+ * @return mapping_added event, or null if just an update
+ */
+ MappingEvent addOrUpdateMappingEntry(Type type, MappingEntry entry);
+
+ /**
+ * Removes an existing mapping from the specified store.
+ *
+ * @param type store type
+ * @param entry the mapping to remove
+ * @return mapping_removed event, or null if nothing removed
+ */
+ MappingEvent removeMappingEntry(Type type, MappingEntry entry);
+
+ /**
+ * Marks a mapping as PENDING_ADD during retry.
+ *
+ * Emits mapping_update event if the state is changed
+ *
+ * @param type store type
+ * @param entry the mapping that is retrying
+ * @return mapping_updated event, or null if nothing updated
+ */
+ MappingEvent pendingMappingEntry(Type type, MappingEntry entry);
+
+ /**
+ * Removes all mapping entries of given device from the specified store.
+ *
+ * @param type store type
+ * @param deviceId device identifier
+ */
+ default void purgeMappingEntry(Type type, DeviceId deviceId) {}
+
+ /**
+ * Removes all mapping entries from the specified store.
+ *
+ * @param type store type
+ */
+ void purgeMappingEntries(Type type);
}
diff --git a/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/DistributedMappingStore.java b/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/DistributedMappingStore.java
index 6e3f445..772337e 100644
--- a/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/DistributedMappingStore.java
+++ b/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/DistributedMappingStore.java
@@ -15,13 +15,43 @@
*/
package org.onosproject.mapping.impl;
+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.Service;
+import org.onosproject.mapping.Mapping;
+import org.onosproject.mapping.MappingEvent;
+import org.onosproject.mapping.MappingEntry;
import org.onosproject.mapping.MappingStore;
import org.onosproject.mapping.MappingStoreDelegate;
+import org.onosproject.net.DeviceId;
+import org.onosproject.store.AbstractStore;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+
+import static org.slf4j.LoggerFactory.getLogger;
/**
* Implementation of a distributed store for managing mapping information.
*/
-public class DistributedMappingStore implements MappingStore {
+@Component(immediate = true)
+@Service
+public class DistributedMappingStore
+ extends AbstractStore<MappingEvent, MappingStoreDelegate>
+ implements MappingStore {
+
+ private final Logger log = getLogger(getClass());
+
+ @Activate
+ public void activate(ComponentContext context) {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate(ComponentContext context) {
+ log.info("Stopped");
+ }
+
@Override
public void setDelegate(MappingStoreDelegate delegate) {
@@ -36,4 +66,44 @@
public boolean hasDelegate() {
return false;
}
+
+ @Override
+ public int getMappingCount(Type type) {
+ return 0;
+ }
+
+ @Override
+ public MappingEntry getMappingEntry(Type type, Mapping mapping) {
+ return null;
+ }
+
+ @Override
+ public Iterable<MappingEntry> getMappingEntries(Type type, DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public void deleteMapping(Type type, Mapping mapping) {
+
+ }
+
+ @Override
+ public MappingEvent addOrUpdateMappingEntry(Type type, MappingEntry entry) {
+ return null;
+ }
+
+ @Override
+ public MappingEvent removeMappingEntry(Type type, MappingEntry entry) {
+ return null;
+ }
+
+ @Override
+ public MappingEvent pendingMappingEntry(Type type, MappingEntry entry) {
+ return null;
+ }
+
+ @Override
+ public void purgeMappingEntries(Type type) {
+
+ }
}
diff --git a/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/SimpleMappingStore.java b/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/SimpleMappingStore.java
new file mode 100644
index 0000000..d82ff94
--- /dev/null
+++ b/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/SimpleMappingStore.java
@@ -0,0 +1,119 @@
+/*
+ * 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.onosproject.mapping.impl;
+
+import com.google.common.collect.Maps;
+
+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.Service;
+import org.apache.felix.scr.annotations.Modified;
+import org.onosproject.mapping.MappingEvent;
+import org.onosproject.mapping.Mapping;
+import org.onosproject.mapping.MappingId;
+import org.onosproject.mapping.MappingStore;
+import org.onosproject.mapping.MappingEntry;
+import org.onosproject.mapping.MappingStoreDelegate;
+import org.onosproject.net.DeviceId;
+import org.onosproject.store.AbstractStore;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+
+import java.util.List;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Manages inventory of mappings using trivial in-memory implementation.
+ */
+@Component(immediate = true)
+@Service
+public class SimpleMappingStore
+ extends AbstractStore<MappingEvent, MappingStoreDelegate>
+ implements MappingStore {
+
+ private final Logger log = getLogger(getClass());
+
+ private final ConcurrentMap<DeviceId, ConcurrentMap<MappingId, List<MappingEntry>>>
+ mapDbStore = Maps.newConcurrentMap();
+
+ private final ConcurrentMap<DeviceId, ConcurrentMap<MappingId, List<MappingEntry>>>
+ mapCacheStore = Maps.newConcurrentMap();
+
+ private final AtomicInteger localBatchIdGen = new AtomicInteger();
+
+ @Activate
+ public void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ mapDbStore.clear();
+ mapCacheStore.clear();
+ log.info("Stopped");
+ }
+
+ @Modified
+ public void modified(ComponentContext context) {
+
+ }
+
+ @Override
+ public int getMappingCount(Type type) {
+ return 0;
+ }
+
+ @Override
+ public MappingEntry getMappingEntry(Type type, Mapping mapping) {
+ return null;
+ }
+
+ @Override
+ public Iterable<MappingEntry> getMappingEntries(Type type, DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public void deleteMapping(Type type, Mapping mapping) {
+
+ }
+
+ @Override
+ public MappingEvent addOrUpdateMappingEntry(Type type, MappingEntry entry) {
+ return null;
+ }
+
+ @Override
+ public MappingEvent removeMappingEntry(Type type, MappingEntry entry) {
+ return null;
+ }
+
+ @Override
+ public MappingEvent pendingMappingEntry(Type type, MappingEntry entry) {
+ return null;
+ }
+
+ @Override
+ public void purgeMappingEntries(Type type) {
+
+ }
+}
+
+