changes for getting the previous subject of the modified interface.
Change-Id: I7dffe0598dee92dfb8a458cb01b819df7e6a5e57
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceEvent.java b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceEvent.java
index 4e6e81c..540a79d 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceEvent.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceEvent.java
@@ -17,12 +17,16 @@
package org.onosproject.incubator.net.intf;
import org.onosproject.event.AbstractEvent;
+import org.joda.time.LocalDateTime;
+import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Describes an interface event.
*/
public class InterfaceEvent extends AbstractEvent<InterfaceEvent.Type, Interface> {
+ private final Interface prevSubject;
+
public enum Type {
/**
* Indicates a new interface has been added.
@@ -47,18 +51,64 @@
* @param subject subject interface
*/
public InterfaceEvent(Type type, Interface subject) {
- super(type, subject);
+ this(type, subject, null);
}
/**
- * Creates an interface event with type, subject and time.
+ * Creates an interface event with type, subject and time of event.
*
* @param type event type
* @param subject subject interface
* @param time time of event
*/
public InterfaceEvent(Type type, Interface subject, long time) {
- super(type, subject, time);
+ this(type, subject, null, time);
}
+ /**
+ * Creates an interface event with type, subject and previous subject.
+ *
+ * @param type event type
+ * @param subject subject interface
+ * @param subject previous interface subject
+ */
+ public InterfaceEvent(Type type, Interface subject, Interface prevSubject) {
+ super(type, subject);
+ this.prevSubject = prevSubject;
+ }
+
+ /**
+ * Creates an interface event with type, subject, previous subject and time.
+ *
+ * @param type event type
+ * @param subject subject interface
+ * @param subject previous interface subject
+ * @param time time of event
+ */
+ public InterfaceEvent(Type type, Interface subject, Interface prevSubject, long time) {
+ super(type, subject, time);
+ this.prevSubject = prevSubject;
+ }
+
+ /**
+ * Returns the previous interface subject.
+ *
+ * @return previous subject of interface or null if the event is not interface specific.
+ */
+ public Interface prevSubject() {
+ return prevSubject;
+ }
+
+ @Override
+ public String toString() {
+ if (prevSubject == null) {
+ return super.toString();
+ }
+ return toStringHelper(this)
+ .add("time", new LocalDateTime(time()))
+ .add("type", type())
+ .add("subject", subject())
+ .add("prevSubject", prevSubject)
+ .toString();
+ }
}
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/InterfaceManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/InterfaceManager.java
index c31ab92..2b4ecbf 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/InterfaceManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/intf/impl/InterfaceManager.java
@@ -171,7 +171,7 @@
if (oldIntf.isPresent()) {
old.remove(oldIntf.get());
if (!oldIntf.get().equals(intf)) {
- process(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_UPDATED, intf));
+ process(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_UPDATED, intf, oldIntf.get()));
}
} else {
process(new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf));