Add optional "name" parameter in interface configuration.
Interfaces can now be added and deleted by name. Interfaces without names
cannot be updated or deleted.
Change-Id: Icb2188b1c9abf3017724f751a93457920a53ba03
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 9f2d410..5246f31 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
@@ -28,6 +28,7 @@
import org.onosproject.net.config.Config;
import org.onosproject.net.host.InterfaceIpAddress;
+import java.util.Iterator;
import java.util.Set;
/**
@@ -35,6 +36,7 @@
*/
@Beta
public class InterfaceConfig extends Config<ConnectPoint> {
+ public static final String NAME = "name";
public static final String IPS = "ips";
public static final String MAC = "mac";
public static final String VLAN = "vlan";
@@ -52,6 +54,8 @@
try {
for (JsonNode intfNode : array) {
+ String name = intfNode.path(NAME).asText(null);
+
Set<InterfaceIpAddress> ips = getIps(intfNode);
String mac = intfNode.path(MAC).asText();
@@ -59,7 +63,7 @@
VlanId vlan = getVlan(intfNode);
- interfaces.add(new Interface(subject, ips, macAddr, vlan));
+ interfaces.add(new Interface(name, subject, ips, macAddr, vlan));
}
} catch (IllegalArgumentException e) {
throw new ConfigException(CONFIG_VALUE_ERROR, e);
@@ -76,6 +80,8 @@
public void addInterface(Interface intf) {
ObjectNode intfNode = array.addObject();
+ intfNode.put(NAME, intf.name());
+
if (intf.mac() != null) {
intfNode.put(MAC, intf.mac().toString());
}
@@ -92,12 +98,14 @@
/**
* Removes an interface from the config.
*
- * @param intf interface to remove
+ * @param name name of the interface to remove
*/
- public void removeInterface(Interface intf) {
- for (int i = 0; i < array.size(); i++) {
- if (intf.vlan().equals(getVlan(node))) {
- array.remove(i);
+ public void removeInterface(String name) {
+ Iterator<JsonNode> it = array.iterator();
+ while (it.hasNext()) {
+ JsonNode node = it.next();
+ if (node.path(NAME).asText().equals(name)) {
+ it.remove();
break;
}
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/intf/Interface.java b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/Interface.java
index b9d3ead..e210968 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/intf/Interface.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/Interface.java
@@ -30,11 +30,13 @@
/**
* An Interface maps network configuration information (such as addresses and
- * vlans) to a port in the network. This is considered a L2/L3 network
- * interface.
+ * vlans) to a port in the network.
*/
@Beta
public class Interface {
+ public static final String NO_INTERFACE_NAME = "";
+
+ private final String name;
private final ConnectPoint connectPoint;
private final Set<InterfaceIpAddress> ipAddresses;
private final MacAddress macAddress;
@@ -43,6 +45,25 @@
/**
* Creates new Interface with the provided configuration.
*
+ * @param name name of the interface
+ * @param connectPoint the connect point this interface maps to
+ * @param ipAddresses Set of IP addresses
+ * @param macAddress MAC address
+ * @param vlan VLAN ID
+ */
+ public Interface(String name, ConnectPoint connectPoint,
+ Set<InterfaceIpAddress> ipAddresses,
+ MacAddress macAddress, VlanId vlan) {
+ this.name = name == null ? NO_INTERFACE_NAME : name;
+ this.connectPoint = checkNotNull(connectPoint);
+ this.ipAddresses = ipAddresses == null ? Sets.newHashSet() : ipAddresses;
+ this.macAddress = macAddress == null ? MacAddress.NONE : macAddress;
+ this.vlan = vlan == null ? VlanId.NONE : vlan;
+ }
+
+ /**
+ * Creates new Interface with the provided configuration.
+ *
* @param connectPoint the connect point this interface maps to
* @param ipAddresses Set of IP addresses
* @param macAddress MAC address
@@ -51,10 +72,16 @@
public Interface(ConnectPoint connectPoint,
Set<InterfaceIpAddress> ipAddresses,
MacAddress macAddress, VlanId vlan) {
- this.connectPoint = checkNotNull(connectPoint);
- this.ipAddresses = ipAddresses == null ? Sets.newHashSet() : ipAddresses;
- this.macAddress = macAddress == null ? MacAddress.NONE : macAddress;
- this.vlan = vlan == null ? VlanId.NONE : vlan;
+ this(NO_INTERFACE_NAME, connectPoint, ipAddresses, macAddress, vlan);
+ }
+
+ /**
+ * Retrieves the name of the interface.
+ *
+ * @return name
+ */
+ public String name() {
+ return name;
}
/**
@@ -101,7 +128,8 @@
Interface otherInterface = (Interface) other;
- return Objects.equals(connectPoint, otherInterface.connectPoint) &&
+ return Objects.equals(name, otherInterface.name) &&
+ Objects.equals(connectPoint, otherInterface.connectPoint) &&
Objects.equals(ipAddresses, otherInterface.ipAddresses) &&
Objects.equals(macAddress, otherInterface.macAddress) &&
Objects.equals(vlan, otherInterface.vlan);
@@ -109,12 +137,13 @@
@Override
public int hashCode() {
- return Objects.hash(connectPoint, ipAddresses, macAddress, vlan);
+ return Objects.hash(connectPoint, name, ipAddresses, macAddress, vlan);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
+ .add("name", name)
.add("connectPoint", connectPoint)
.add("ipAddresses", ipAddresses)
.add("macAddress", macAddress)
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceAdminService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceAdminService.java
index 56d5aec..32d480d 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceAdminService.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/intf/InterfaceAdminService.java
@@ -16,13 +16,13 @@
package org.onosproject.incubator.net.intf;
-import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
/**
* Provides a means to modify the interfaces configuration.
*/
public interface InterfaceAdminService {
+
/**
* Adds a new interface configuration to the system.
*
@@ -34,7 +34,7 @@
* Removes an interface configuration from the system.
*
* @param connectPoint connect point of the interface
- * @param vlanId vlan id
+ * @param name name of the interface
*/
- void remove(ConnectPoint connectPoint, VlanId vlanId);
+ boolean remove(ConnectPoint connectPoint, String name);
}