Augment provider service to query mapping value from protocol layer
Change-Id: Ib6f03102ea2b720968117f032293e09c11cbf619
diff --git a/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingProviderService.java b/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingProviderService.java
index 6cbd478..4ff6e29 100644
--- a/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingProviderService.java
+++ b/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingProviderService.java
@@ -30,4 +30,12 @@
* @param type indicates that where this map entry should be stored
*/
void mappingAdded(MappingEntry mappingEntry, MappingStore.Type type);
+
+ /**
+ * Signals that a new mapping query has been issued.
+ *
+ * @param mappingKey a mapping key that is used for query a mapping value
+ * @return a mapping value associated with a given mapping key
+ */
+ MappingValue mappingQueried(MappingKey mappingKey);
}
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 e2d6109..a46ce3c 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
@@ -48,6 +48,14 @@
int getMappingCount(Type type);
/**
+ * Obtains all mapping entries from the specified store.
+ *
+ * @param type store type
+ * @return the mapping entries
+ */
+ Iterable<MappingEntry> getAllMappingEntries(Type type);
+
+ /**
* Obtains the stored mapping from the specified store.
*
* @param type store type
diff --git a/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingProviderServiceAdapter.java b/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingProviderServiceAdapter.java
index b5a4311..a5e35af 100644
--- a/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingProviderServiceAdapter.java
+++ b/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingProviderServiceAdapter.java
@@ -28,4 +28,9 @@
public void mappingAdded(MappingEntry mappingEntry, MappingStore.Type type) {
}
+
+ @Override
+ public MappingValue mappingQueried(MappingKey mappingKey) {
+ return null;
+ }
}
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 55208ce..d84032f 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
@@ -166,6 +166,15 @@
}
@Override
+ public Iterable<MappingEntry> getAllMappingEntries(Type type) {
+
+ Map<MappingId, Mapping> storeMap = getStoreMap(type);
+ return ImmutableList.copyOf(storeMap.values().stream()
+ .map(DefaultMappingEntry::new)
+ .collect(Collectors.toList()));
+ }
+
+ @Override
public MappingEntry getMappingEntry(Type type, Mapping mapping) {
return new DefaultMappingEntry(getStoreMap(type).get(mapping.id()));
diff --git a/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/MappingManager.java b/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/MappingManager.java
index 289bb2a..4f0ed79 100644
--- a/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/MappingManager.java
+++ b/apps/mappingmanagement/mgr/src/main/java/org/onosproject/mapping/impl/MappingManager.java
@@ -27,6 +27,7 @@
import org.onosproject.mapping.MappingAdminService;
import org.onosproject.mapping.MappingEntry;
import org.onosproject.mapping.MappingEvent;
+import org.onosproject.mapping.MappingKey;
import org.onosproject.mapping.MappingListener;
import org.onosproject.mapping.MappingProvider;
import org.onosproject.mapping.MappingProviderRegistry;
@@ -35,6 +36,7 @@
import org.onosproject.mapping.MappingStore;
import org.onosproject.mapping.MappingStore.Type;
import org.onosproject.mapping.MappingStoreDelegate;
+import org.onosproject.mapping.MappingValue;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceService;
@@ -134,6 +136,21 @@
}
/**
+ * Obtains a mapping value associated a mapping key.
+ *
+ * @param mappingKey a given mapping key
+ * @return a mapping value
+ */
+ private MappingValue getMappingValueByMappingKey(MappingKey mappingKey) {
+ for (MappingEntry entry : store.getAllMappingEntries(Type.MAP_DATABASE)) {
+ if (entry.key().equals(mappingKey)) {
+ return entry.value();
+ }
+ }
+ return null;
+ }
+
+ /**
* Store delegate.
*/
private class InternalStoreDelegate implements MappingStoreDelegate {
@@ -163,5 +180,10 @@
public void mappingAdded(MappingEntry mappingEntry, Type type) {
storeMappingEntry(type, mappingEntry);
}
+
+ @Override
+ public MappingValue mappingQueried(MappingKey mappingKey) {
+ return getMappingValueByMappingKey(mappingKey);
+ }
}
}
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
index c349423..8b02868 100644
--- 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
@@ -16,6 +16,7 @@
package org.onosproject.mapping.impl;
import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -87,22 +88,8 @@
public int getMappingCount(Type type) {
int sum = 0;
- ConcurrentMap<DeviceId, ConcurrentMap<MappingId,
- List<StoredMappingEntry>>> store = Maps.newConcurrentMap();
-
- switch (type) {
- case MAP_DATABASE:
- store = mapDbStore;
- break;
- case MAP_CACHE:
- store = mapCacheStore;
- break;
- default:
- log.error(UNRECOGNIZED_STORE_MSG, type);
- break;
- }
-
- for (ConcurrentMap<MappingId, List<StoredMappingEntry>> mapDb : store.values()) {
+ for (ConcurrentMap<MappingId, List<StoredMappingEntry>> mapDb :
+ getMappingStore(type).values()) {
for (List<StoredMappingEntry> mes : mapDb.values()) {
sum += mes.size();
}
@@ -111,6 +98,21 @@
return sum;
}
+ @Override
+ public Iterable<MappingEntry> getAllMappingEntries(Type type) {
+
+ List<MappingEntry> entries = Lists.newArrayList();
+
+ for (ConcurrentMap<MappingId, List<StoredMappingEntry>> mapDb :
+ getMappingStore(type).values()) {
+ for (List<StoredMappingEntry> mes : mapDb.values()) {
+ entries.addAll(mes);
+ }
+ }
+
+ return entries;
+ }
+
/**
* Obtains the mapping store for specified device and store type.
*