Notion of config operators:
Added operator for combining configuration info for Optical ports
from various sources. Also includes minor tweaks to OpticalPortConfig,
and javadoc fixes.
Change-Id: I754b2e29f560b473d1f791025f8b8b18c8d75a13
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/config/ConfigOperator.java b/incubator/api/src/main/java/org/onosproject/incubator/net/config/ConfigOperator.java
new file mode 100644
index 0000000..ab02e88
--- /dev/null
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/config/ConfigOperator.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2014-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.config;
+
+/**
+ * An interface signifying a class that implements network configuration
+ * information from multiple sources. There is a natural ordering to the
+ * precedence of information, depending on its source:
+ * <ol>
+ * <li>Intents (from applications), which override</li>
+ * <li>Configs (from the network configuration subsystem), which override</li>
+ * <li>Descriptions (from southbound)</li>
+ * </ol>
+ * i.e., for a field representing the same attribute, the value from a Config
+ * entity will be used over that from the Description.
+ */
+public interface ConfigOperator {
+}
\ No newline at end of file
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/OpticalPortConfig.java b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/OpticalPortConfig.java
index 3757e7c..e9aad7a 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/OpticalPortConfig.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/OpticalPortConfig.java
@@ -3,7 +3,6 @@
import java.util.Optional;
import org.onosproject.incubator.net.config.Config;
-import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Port;
@@ -19,9 +18,11 @@
// port name. "name" is the alphanumeric name of the port, but "port" refers
// to the port number used as a name string (i.e., for ports without
- // alphanumeric names). this should be linked to ConnectPoint.
+ // alphanumeric names).
public static final String NAME = "name";
public static final String PORT = "port";
+ public static final String STATIC_PORT = "staticPort";
+ public static final String STATIC_LAMBDA = "staticLambda";
/**
* Returns the Enum value representing the type of port.
@@ -38,14 +39,22 @@
/**
* Returns the port name associated with this port configuration. The Name
- * may either be an alphanumeric string, or a string representation of the
- * port number, falling back on the latter if the former doesn't exist.
+ * is an alphanumeric string.
*
* @return the name of this port, else, an empty string
*/
public String name() {
- String name = getStringValue(NAME);
- return name.isEmpty() ? getStringValue(PORT) : name;
+ return getStringValue(NAME);
+ }
+
+ /**
+ * Returns a stringified representation of the port number, configured in
+ * some port types without an alphanumeric name as the port name.
+ *
+ * @return A string representation of the port number
+ */
+ public String numberName() {
+ return getStringValue(PORT);
}
/**
@@ -56,7 +65,7 @@
* @return the name of this port, else, an empty string
*/
public String staticPort() {
- return getStringValue(AnnotationKeys.STATIC_PORT);
+ return getStringValue(STATIC_PORT);
}
private String getStringValue(String field) {
@@ -71,7 +80,7 @@
* @return an Optional that may contain a frequency value.
*/
public Optional<Long> staticLambda() {
- JsonNode sl = node.path(AnnotationKeys.STATIC_LAMBDA);
+ JsonNode sl = node.path(STATIC_LAMBDA);
if (sl.isMissingNode()) {
return Optional.empty();
}
@@ -121,7 +130,7 @@
* @return this OpticalPortConfig instance
*/
public OpticalPortConfig staticPort(String name) {
- return (OpticalPortConfig) setOrClear(AnnotationKeys.STATIC_PORT, name);
+ return (OpticalPortConfig) setOrClear(STATIC_PORT, name);
}
/**
@@ -132,7 +141,7 @@
* @return this OpticalPortConfig instance
*/
public OpticalPortConfig staticLambda(Long index) {
- return (OpticalPortConfig) setOrClear(AnnotationKeys.STATIC_LAMBDA, index);
+ return (OpticalPortConfig) setOrClear(STATIC_LAMBDA, index);
}
}
diff --git a/incubator/api/src/test/java/org/onosproject/incubator/net/config/basics/OpticalPortConfigTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/config/basics/OpticalPortConfigTest.java
index a30582e..9a9a8b3 100644
--- a/incubator/api/src/test/java/org/onosproject/incubator/net/config/basics/OpticalPortConfigTest.java
+++ b/incubator/api/src/test/java/org/onosproject/incubator/net/config/basics/OpticalPortConfigTest.java
@@ -5,6 +5,8 @@
import static org.onosproject.incubator.net.config.basics.OpticalPortConfig.TYPE;
import static org.onosproject.incubator.net.config.basics.OpticalPortConfig.NAME;
import static org.onosproject.incubator.net.config.basics.OpticalPortConfig.PORT;
+import static org.onosproject.incubator.net.config.basics.OpticalPortConfig.STATIC_LAMBDA;
+import static org.onosproject.incubator.net.config.basics.OpticalPortConfig.STATIC_PORT;
import java.io.IOException;
import java.util.Iterator;
@@ -14,7 +16,6 @@
import org.junit.Test;
import org.onosproject.incubator.net.config.Config;
import org.onosproject.incubator.net.config.ConfigApplyDelegate;
-import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
@@ -103,7 +104,8 @@
assertEquals(Port.Type.OMS, op0.type());
assertEquals(jn0.path(NAME).asText(), op0.name());
- assertEquals(jn1.path(PORT).asText(), op1.name());
+ assertEquals(jn1.path(PORT).asText(), op1.numberName());
+ assertEquals("", op1.name());
assertEquals("", op2.name());
}
@@ -116,8 +118,8 @@
Long sl = 1L;
// see config entity 2 in DEMOTREE
- op2.staticLambda(jn2.path("annotations").path(AnnotationKeys.STATIC_LAMBDA).asLong());
- op2.staticPort(jn2.path("annotations").path(AnnotationKeys.STATIC_PORT).asText());
+ op2.staticLambda(jn2.path("annotations").path(STATIC_LAMBDA).asLong());
+ op2.staticPort(jn2.path("annotations").path(STATIC_PORT).asText());
assertEquals(sl, op2.staticLambda().get());
assertFalse(op1.staticLambda().isPresent());