Added events for the Interface subsytem
Change-Id: I9adcc2caa2a98625173c9b9c6d15bbd1a0706eaa
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/InterfaceConfig.java b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/InterfaceConfig.java
index 5246f31..3c41291 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/InterfaceConfig.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/InterfaceConfig.java
@@ -31,6 +31,9 @@
import java.util.Iterator;
import java.util.Set;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Configuration for interfaces.
*/
@@ -41,7 +44,9 @@
public static final String MAC = "mac";
public static final String VLAN = "vlan";
- public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
+ private static final String CONFIG_VALUE_ERROR = "Error parsing config value";
+ private static final String INTF_NULL_ERROR = "Interface cannot be null";
+ private static final String INTF_NAME_ERROR = "Interface must have a valid name";
/**
* Retrieves all interfaces configured on this port.
@@ -78,6 +83,12 @@
* @param intf interface to add
*/
public void addInterface(Interface intf) {
+ checkNotNull(intf, INTF_NULL_ERROR);
+ checkArgument(!intf.name().equals(Interface.NO_INTERFACE_NAME), INTF_NAME_ERROR);
+
+ // Remove old interface with this name if it exists
+ removeInterface(intf.name());
+
ObjectNode intfNode = array.addObject();
intfNode.put(NAME, intf.name());
@@ -101,6 +112,9 @@
* @param name name of the interface to remove
*/
public void removeInterface(String name) {
+ checkNotNull(name, INTF_NULL_ERROR);
+ checkArgument(!name.equals(Interface.NO_INTERFACE_NAME), INTF_NAME_ERROR);
+
Iterator<JsonNode> it = array.iterator();
while (it.hasNext()) {
JsonNode node = it.next();
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
new file mode 100644
index 0000000..1bbf665
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceEvent.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2015 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.incubator.net.intf;
+
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Describes an interface event.
+ */
+public class InterfaceEvent extends AbstractEvent<InterfaceEvent.Type, Interface> {
+
+ public enum Type {
+ /**
+ * Indicates a new interface has been added.
+ */
+ INTERFACE_ADDED,
+
+ /**
+ * Indicates an interface has been updated.
+ */
+ INTERFACE_UPDATED,
+
+ /**
+ * Indicates an interface has been removed.
+ */
+ INTERFACE_REMOVED
+ }
+
+ /**
+ * Creates an interface event with type and subject.
+ *
+ * @param type event type
+ * @param subject subject interface
+ */
+ public InterfaceEvent(Type type, Interface subject) {
+ super(type, subject);
+ }
+
+ /**
+ * Creates an interface event with type, subject and time.
+ *
+ * @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);
+ }
+
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceListener.java b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceListener.java
new file mode 100644
index 0000000..2fd045d
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceListener.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2015 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.incubator.net.intf;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Listener for interface events.
+ */
+public interface InterfaceListener extends EventListener<InterfaceEvent> {
+}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceService.java
index b164df9..38cfdc5 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceService.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceService.java
@@ -19,6 +19,7 @@
import com.google.common.annotations.Beta;
import org.onlab.packet.IpAddress;
import org.onlab.packet.VlanId;
+import org.onosproject.event.ListenerService;
import org.onosproject.net.ConnectPoint;
import java.util.Set;
@@ -27,7 +28,8 @@
* Service for interacting with interfaces.
*/
@Beta
-public interface InterfaceService {
+public interface InterfaceService
+ extends ListenerService<InterfaceEvent, InterfaceListener> {
/**
* Returns the set of all interfaces in the system.