[GEANT] Command device-interfaces added.
Change-Id: If70eedc5e8e0d83bc4d31c556fbf8382cbe97cec
diff --git a/core/api/src/main/java/org/onosproject/net/behaviour/InterfaceConfig.java b/core/api/src/main/java/org/onosproject/net/behaviour/InterfaceConfig.java
index 443450d..22c2d8a 100644
--- a/core/api/src/main/java/org/onosproject/net/behaviour/InterfaceConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/behaviour/InterfaceConfig.java
@@ -17,6 +17,7 @@
import org.onlab.packet.VlanId;
import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DeviceInterfaceDescription;
import org.onosproject.net.driver.HandlerBehaviour;
import java.util.List;
@@ -28,6 +29,7 @@
/**
* Adds an access interface to a VLAN.
+ *
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanId the VLAN ID
@@ -37,6 +39,7 @@
/**
* Removes an access interface to a VLAN.
+ *
* @param deviceId the device ID
* @param intf the name of the interface
* @return the result of operation
@@ -45,6 +48,7 @@
/**
* Adds a trunk interface for VLANs.
+ *
* @param deviceId the device ID
* @param intf the name of the interface
* @param vlanIds the VLAN IDs
@@ -54,6 +58,7 @@
/**
* Removes trunk mode configuration from an interface.
+ *
* @param deviceId the device ID
* @param intf the name of the interface
* @return the result of operation
@@ -61,6 +66,14 @@
boolean removeTrunkInterface(DeviceId deviceId, String intf);
/**
+ * Provides the interfaces configured on a device.
+ *
+ * @param deviceId the device ID
+ * @return the list of the configured interfaces
+ */
+ List<DeviceInterfaceDescription> getInterfaces(DeviceId deviceId);
+
+ /**
* TODO Addition of more methods to make the behavior symmetrical.
* Methods getInterfacesForVlan, getVlansForInterface, getTrunkforInterface,
* getInterfacesForTrunk should be added to complete the behavior.
diff --git a/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceInterfaceDescription.java b/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceInterfaceDescription.java
new file mode 100644
index 0000000..695f130
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceInterfaceDescription.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2016-present 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.net.device;
+
+import com.google.common.collect.Lists;
+import org.onlab.packet.VlanId;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Basic implementation of description of a legacy device interface.
+ */
+public class DefaultDeviceInterfaceDescription implements
+ DeviceInterfaceDescription {
+ private String name;
+ private Mode mode;
+ private List<VlanId> vlans;
+ private boolean isRateLimited;
+ private short rateLimit;
+
+ /**
+ * Device interface description object constructor.
+ *
+ * @param name the name of the interface
+ * @param mode the operation mode of the interface
+ * @param vlans the vlan-id of the interface (none, one or multiple can be
+ * specified based on if mode is normal, access or trunk).
+ * @param isRateLimited bandwidth limit application indication
+ * @param rateLimit percentage of bandwidth limit
+ */
+ public DefaultDeviceInterfaceDescription(String name,
+ Mode mode,
+ List<VlanId> vlans,
+ boolean isRateLimited,
+ short rateLimit) {
+ this.name = name;
+ this.mode = (mode != null ? mode : Mode.NORMAL);
+ this.vlans = (vlans != null ? vlans : Lists.newArrayList());
+ this.isRateLimited = isRateLimited;
+ this.rateLimit = rateLimit;
+ }
+
+ /**
+ * Returns the name of the interface.
+ *
+ * @return name of the interface
+ */
+ @Override
+ public String name() {
+ return this.name;
+ }
+
+ /**
+ * Returns the operation mode of the interface.
+ *
+ * @return operation mode of the interface
+ */
+ @Override
+ public Mode mode() {
+ return this.mode;
+ }
+
+ /**
+ * Returns the VLAN-IDs configured for the interface. No VLAN-ID should be
+ * returned for NORMAL mode, 1 VLAN-ID for access mode and 1 or more
+ * VLAN-IDs for trunking mode.
+ *
+ * @return VLAN-ID(s) configured for the interface.
+ */
+ @Override
+ public List<VlanId> vlans() {
+ return vlans;
+ }
+
+ /**
+ * Indicates whether a rate limit has been set on the interface.
+ *
+ * @return indication whether interface is rate limited or not
+ */
+ @Override
+ public boolean isRateLimited() {
+ return isRateLimited;
+ }
+
+ /**
+ * Returns the rate limit set on the interface bandwidth.
+ *
+ * @return the rate limit set on the interface bandwidth
+ */
+ @Override
+ public short rateLimit() {
+ return rateLimit;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof DefaultDeviceInterfaceDescription)) {
+ return false;
+ }
+
+ DefaultDeviceInterfaceDescription otherInterface =
+ (DefaultDeviceInterfaceDescription) other;
+
+ return Objects.equals(name, otherInterface.name) &&
+ Objects.equals(mode, otherInterface.mode) &&
+ Objects.equals(vlans, otherInterface.vlans) &&
+ Objects.equals(isRateLimited, otherInterface.isRateLimited) &&
+ Objects.equals(rateLimit, otherInterface.rateLimit);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, mode, vlans, isRateLimited, rateLimit);
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/device/DeviceInterfaceDescription.java b/core/api/src/main/java/org/onosproject/net/device/DeviceInterfaceDescription.java
new file mode 100644
index 0000000..6b14c37
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/device/DeviceInterfaceDescription.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2016-present 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.net.device;
+
+import org.onlab.packet.VlanId;
+
+import java.util.List;
+
+/**
+ * The description of an interface used for legacy devices.
+ */
+public interface DeviceInterfaceDescription {
+ /**
+ * Represents the type of operation of the interface.
+ */
+ enum Mode {
+ /**
+ * Normal mode of interface operation.
+ */
+ NORMAL,
+ /**
+ * Access mode to a VLAN for interface.
+ */
+ ACCESS,
+ /**
+ * Trunk mode for a set of VLANs for interface.
+ */
+ TRUNK
+ }
+
+ /**
+ * Returns the name of the interface.
+ *
+ * @return name of the interface
+ */
+ String name();
+
+ /**
+ * Returns the operation mode of the interface.
+ *
+ * @return operation mode of the interface
+ */
+ Mode mode();
+
+ /**
+ * Returns the VLAN-IDs configured for the interface. No VLAN-ID should be
+ * returned for NORMAL mode, 1 VLAN-ID for access mode and 1 or more
+ * VLAN-IDs for trunking mode.
+ *
+ * @return VLAN-ID(s) configured for the interface.
+ */
+ List<VlanId> vlans();
+
+ /**
+ * Indicates whether a rate limit has been set on the interface.
+ *
+ * @return indication whether interface is rate limited or not
+ */
+ boolean isRateLimited();
+
+ /**
+ * Returns the rate limit set on the interface bandwidth.
+ *
+ * @return the rate limit set on the interface bandwidth
+ */
+ short rateLimit();
+}