Fix: Set default state as ADDED for newly added mapping by router
Change-Id: I34eda7f5b229efe273d4a4e61e72082f8f123a2c
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 a46ce3c..fb59b7f 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
@@ -80,7 +80,7 @@
* @param type store type
* @param mapping the mapping to add
*/
- void storeMapping(Type type, Mapping mapping);
+ void storeMapping(Type type, MappingEntry mapping);
/**
* Marks a mapping for deletion. Actual deletion will occur when the
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 d84032f..8465e45 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
@@ -191,7 +191,7 @@
}
@Override
- public void storeMapping(Type type, Mapping mapping) {
+ public void storeMapping(Type type, MappingEntry mapping) {
getStore(type).put(mapping.id(), mapping);
}
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 8b02868..0eca4bb 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
@@ -26,6 +26,7 @@
import org.onosproject.mapping.DefaultMappingEntry;
import org.onosproject.mapping.Mapping;
import org.onosproject.mapping.MappingEntry;
+import org.onosproject.mapping.MappingEntry.MappingEntryState;
import org.onosproject.mapping.MappingEvent;
import org.onosproject.mapping.MappingId;
import org.onosproject.mapping.MappingStore;
@@ -213,14 +214,15 @@
}
@Override
- public void storeMapping(Type type, Mapping mapping) {
+ public void storeMapping(Type type, MappingEntry mapping) {
List<StoredMappingEntry> entries =
getMappingEntriesInternal(type, mapping.deviceId(), mapping.id());
synchronized (entries) {
if (!entries.contains(mapping)) {
- StoredMappingEntry entry = new DefaultMappingEntry(mapping);
+ StoredMappingEntry entry =
+ new DefaultMappingEntry(mapping, mapping.state());
entries.add(entry);
}
}
@@ -252,7 +254,7 @@
for (StoredMappingEntry stored : entries) {
if (stored.equals(entry)) {
if (stored.state() == PENDING_ADD) {
- stored.setState(MappingEntry.MappingEntryState.ADDED);
+ stored.setState(MappingEntryState.ADDED);
return new MappingEvent(MAPPING_ADDED, entry);
}
return new MappingEvent(MAPPING_UPDATED, entry);
diff --git a/apps/mappingmanagement/mgr/src/test/java/org/onosproject/mapping/impl/DistributedMappingStoreTest.java b/apps/mappingmanagement/mgr/src/test/java/org/onosproject/mapping/impl/DistributedMappingStoreTest.java
index 9246f6d..e8cb335 100644
--- a/apps/mappingmanagement/mgr/src/test/java/org/onosproject/mapping/impl/DistributedMappingStoreTest.java
+++ b/apps/mappingmanagement/mgr/src/test/java/org/onosproject/mapping/impl/DistributedMappingStoreTest.java
@@ -22,10 +22,12 @@
import org.onlab.packet.ChassisId;
import org.onlab.packet.IpPrefix;
import org.onosproject.mapping.DefaultMapping;
+import org.onosproject.mapping.DefaultMappingEntry;
import org.onosproject.mapping.DefaultMappingKey;
import org.onosproject.mapping.DefaultMappingTreatment;
import org.onosproject.mapping.DefaultMappingValue;
import org.onosproject.mapping.Mapping;
+import org.onosproject.mapping.MappingEntry;
import org.onosproject.mapping.MappingKey;
import org.onosproject.mapping.MappingTreatment;
import org.onosproject.mapping.MappingValue;
@@ -59,8 +61,8 @@
private static final String IP_ADDRESS = "1.2.3.4/24";
private DistributedMappingStore mappingStore;
- private Mapping mapping1;
- private Mapping mapping2;
+ private MappingEntry mapping1;
+ private MappingEntry mapping2;
private Device device1;
private Device device2;
@@ -103,20 +105,23 @@
"foo.inc", "0", "0", "0", null,
DefaultAnnotations.builder().build());
- mapping1 = DefaultMapping.builder()
+ Mapping originalMapping1 = DefaultMapping.builder()
.forDevice(DEVICE_ID_1)
.withId(1000L)
.withKey(key)
.withValue(value)
.build();
- mapping2 = DefaultMapping.builder()
+ Mapping originalMapping2 = DefaultMapping.builder()
.forDevice(DEVICE_ID_2)
.withId(2000L)
.withKey(key)
.withValue(value)
.build();
+ mapping1 = new DefaultMappingEntry(originalMapping1);
+ mapping2 = new DefaultMappingEntry(originalMapping2);
+
mappingStore.activate();
}