Allow to specify time when creates a mapping event instance
Change-Id: Id4d9583a8d43d8a6e0913393d35a222b9688b0d2
diff --git a/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/DefaultMapping.java b/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/DefaultMapping.java
index a6836f8..42415ff 100644
--- a/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/DefaultMapping.java
+++ b/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/DefaultMapping.java
@@ -122,6 +122,18 @@
.toString();
}
+ /**
+ * Returns a default mapping builder.
+ *
+ * @return builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
+ * Default mapping builder.
+ */
public static final class Builder implements Mapping.Builder {
private MappingId id;
diff --git a/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/DefaultMappingEntry.java b/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/DefaultMappingEntry.java
index cbdce56..626cee2 100644
--- a/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/DefaultMappingEntry.java
+++ b/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/DefaultMappingEntry.java
@@ -40,6 +40,15 @@
this.state = state;
}
+ /**
+ * Creates a mapping entry specified with the mapping.
+ *
+ * @param mapping mapping
+ */
+ public DefaultMappingEntry(Mapping mapping) {
+ this(mapping, MappingEntryState.PENDING_ADD);
+ }
+
@Override
public MappingEntryState state() {
return state;
diff --git a/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingEvent.java b/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingEvent.java
index 4b03d13..8d23085 100644
--- a/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingEvent.java
+++ b/apps/mappingmanagement/api/src/main/java/org/onosproject/mapping/MappingEvent.java
@@ -22,6 +22,9 @@
*/
public class MappingEvent extends AbstractEvent<MappingEvent.Type, Mapping> {
+ /**
+ * Type of mapping events.
+ */
public enum Type {
/**
@@ -54,10 +57,28 @@
/**
* Signifies that a request to remove flow rule has been added to the store.
*/
- MAPPING_REMOVE_REQUESTED,
+ MAPPING_REMOVE_REQUESTED
}
+ /**
+ * Creates an event of a given type and for the specified mapping and the
+ * current time.
+ *
+ * @param type mapping event type
+ * @param mapping event mapping subject
+ */
public MappingEvent(Type type, Mapping mapping) {
super(type, mapping);
}
+
+ /**
+ * Creates an event of a given type and for the specified mapping and time.
+ *
+ * @param type mapping event type
+ * @param mapping event mapping subject
+ * @param time occurrence time
+ */
+ public MappingEvent(Type type, Mapping mapping, long time) {
+ super(type, mapping, time);
+ }
}
diff --git a/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/DefaultMappingEntryTest.java b/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/DefaultMappingEntryTest.java
index 47aadbe..f3cbde4 100644
--- a/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/DefaultMappingEntryTest.java
+++ b/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/DefaultMappingEntryTest.java
@@ -32,6 +32,10 @@
private static final MappingValue MAPPING_VALUE =
new MappingTestMocks.MockMappingValue();
+ private final MappingEntry entry1 = makeMappingEntry(1);
+ private final MappingEntry sameAsEntry1 = makeMappingEntry(1);
+ private final MappingEntry entry2 = makeMappingEntry(2);
+
/**
* Creates a new mapping entry from an unique value.
*
@@ -50,10 +54,6 @@
return new DefaultMappingEntry(mapping, MappingEntry.MappingEntryState.ADDED);
}
- final MappingEntry entry1 = makeMappingEntry(1);
- final MappingEntry sameAsEntry1 = makeMappingEntry(1);
- final MappingEntry entry2 = makeMappingEntry(2);
-
/**
* Tests the equals, hashCode and toString methods using Guava EqualsTester.
*/
diff --git a/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingEventTest.java b/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingEventTest.java
index 2da8863..7e21085 100644
--- a/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingEventTest.java
+++ b/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingEventTest.java
@@ -77,6 +77,18 @@
}
/**
+ * Tests the constructor where a time is passed in.
+ */
+ @Test
+ public void testTimeConstructor() {
+ final long time = 123L;
+ final Mapping mapping = mockMapping(1, DEVICE_ID_1);
+ final MappingEvent event =
+ new MappingEvent(MappingEvent.Type.MAPPING_REMOVE_REQUESTED, mapping, time);
+ validateEvent(event, MappingEvent.Type.MAPPING_REMOVE_REQUESTED, mapping, time);
+ }
+
+ /**
* Tests creation of a MappingEvent.
*/
@Test
diff --git a/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingTestMocks.java b/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingTestMocks.java
index 364a9b0..f45b197 100644
--- a/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingTestMocks.java
+++ b/apps/mappingmanagement/api/src/test/java/org/onosproject/mapping/MappingTestMocks.java
@@ -20,9 +20,11 @@
import org.onosproject.mapping.actions.MappingActions;
import org.onosproject.mapping.addresses.MappingAddress;
import org.onosproject.mapping.addresses.MappingAddresses;
+import org.onosproject.net.DeviceId;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
/**
* Commons mocks used by the mapping management tasks.
@@ -58,4 +60,66 @@
return Collections.emptyList();
}
}
+
+ private static final MockMappingKey MAPPING_KEY = new MockMappingKey();
+ private static final MockMappingValue MAPPING_VALUE = new MockMappingValue();
+
+ /**
+ * Mock mapping class used for satisfying API requirements.
+ */
+ public static class MockMapping implements Mapping {
+
+ static int nextId = 0;
+
+ int id;
+ long timestamp;
+
+ public MockMapping() {
+ this.id = nextId++;
+ this.timestamp = System.currentTimeMillis();
+ }
+
+ @Override
+ public MappingId id() {
+ return MappingId.valueOf(id);
+ }
+
+ @Override
+ public short appId() {
+ return 0;
+ }
+
+ @Override
+ public DeviceId deviceId() {
+ return DeviceId.deviceId("lisp:" + id);
+ }
+
+ @Override
+ public MappingKey key() {
+ return MAPPING_KEY;
+ }
+
+ @Override
+ public MappingValue value() {
+ return MAPPING_VALUE;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final MockMapping other = (MockMapping) obj;
+ return Objects.equals(this.timestamp, other.timestamp) &&
+ this.id == other.id;
+ }
+ }
}