Adding annotations for jitter, delay, loss, availability, flapping

Change-Id: I04943c27f7e9e2c7b50f574838f2d6e53f5ceef6
diff --git a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
index 2e92c53..f1d4fb7 100644
--- a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
+++ b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
@@ -9,6 +9,7 @@
  *
  * 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.
@@ -211,6 +212,36 @@
     public static final String LAYER = "layer";
 
     /**
+     * Annotation key for jitter.
+     * The value of this key is expected to be jitter in seconds
+     */
+    public static final String JITTER = "jitter";
+
+    /**
+     * Annotation key for delay.
+     * The value of this key is expected to be delay in seconds
+     */
+    public static final String DELAY = "delay";
+
+    /**
+     * Annotation key for loss.
+     * The value of this key is expected to be loss in percentage.
+     */
+    public static final String LOSS = "loss";
+
+    /**
+     * Annotation key for availability.
+     * The value of this key is expected to be availability as a percentage
+     */
+    public static final String AVAILABILITY = "availability";
+
+    /**
+     * Annotation key for flapping.
+     * The value of this key is expected to be a subjective percentage for flapping
+     */
+    public static final String FLAPPING = "flapping";
+
+    /**
      * Returns the value annotated object for the specified annotation key.
      * The annotated value is expected to be String that can be parsed as double.
      * If parsing fails, the returned value will be {@value #DEFAULT_VALUE}.
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java
index 5d27284..ff4edb0 100644
--- a/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicLinkConfig.java
@@ -41,6 +41,11 @@
     public static final String METRIC = "metric";
     public static final String LATENCY = "latency";
     public static final String BANDWIDTH = "bandwidth";
+    public static final String JITTER = "jitter";
+    public static final String DELAY = "delay";
+    public static final String LOSS = "loss";
+    public static final String AVAILABILITY = "availability";
+    public static final String FLAPPING = "flapping";
     public static final String IS_DURABLE = "durable";
     public static final String IS_BIDIRECTIONAL = "bidirectional";
 
@@ -49,9 +54,12 @@
         // Validate type/devices
         type();
 
-        return hasOnlyFields(ALLOWED, TYPE, METRIC, LATENCY, BANDWIDTH, IS_DURABLE, IS_BIDIRECTIONAL) &&
+        return hasOnlyFields(ALLOWED, TYPE, METRIC, LATENCY, BANDWIDTH, JITTER, DELAY, LOSS, AVAILABILITY, FLAPPING,
+                IS_DURABLE, IS_BIDIRECTIONAL) &&
                 isBoolean(ALLOWED, OPTIONAL) && isNumber(METRIC, OPTIONAL) &&
-                isNumber(LATENCY, OPTIONAL) && isNumber(BANDWIDTH, OPTIONAL) &&
+                isNumber(LATENCY, OPTIONAL) && isNumber(BANDWIDTH, OPTIONAL) && isDecimal(JITTER, OPTIONAL) &&
+                isDecimal(DELAY, OPTIONAL) && isDecimal(LOSS, OPTIONAL) && isDecimal(AVAILABILITY, OPTIONAL) &&
+                isDecimal(FLAPPING, OPTIONAL) &&
                 isBoolean(IS_BIDIRECTIONAL, OPTIONAL);
     }
 
@@ -204,6 +212,101 @@
     }
 
     /**
+     * Returns link jitter in terms of seconds.
+     *
+     * @return link jitter valuer; -1 if not set
+     */
+    public double jitter() {
+        return get(JITTER, -1.0);
+    }
+
+    /**
+     * Sets the link jitter.
+     *
+     * @param jitter new jitter value; null to clear
+     * @return self
+     */
+    public BasicLinkConfig jitter(Double jitter) {
+        return (BasicLinkConfig) setOrClear(JITTER, jitter);
+    }
+
+    /**
+     * Returns link delay in terms of seconds.
+     *
+     * @return link delay value; -1 if not set
+     */
+    public double delay() {
+        return get(DELAY, -1.0);
+    }
+
+    /**
+     * Sets the link delay.
+     *
+     * @param delay new delay value; null to clear
+     * @return self
+     */
+    public BasicLinkConfig delay(Double delay) {
+        return (BasicLinkConfig) setOrClear(DELAY, delay);
+    }
+
+    /**
+     * Returns link loss in terms of Percentage.
+     *
+     * @return link loss value; -1 if not set
+     */
+    public double loss() {
+        return get(LOSS, -1.0);
+    }
+
+    /**
+     * Sets the link loss.
+     *
+     * @param loss new loss value; null to clear
+     * @return self
+     */
+    public BasicLinkConfig loss(Double loss) {
+        return (BasicLinkConfig) setOrClear(LOSS, loss);
+    }
+
+    /**
+     * Returns link availability in terms of percentage.
+     *
+     * @return link availability value; -1 if not set
+     */
+    public double availability() {
+        return get(AVAILABILITY, -1.0);
+    }
+
+    /**
+     * Sets the link availability.
+     *
+     * @param availability new availability value; null to clear
+     * @return self
+     */
+    public BasicLinkConfig availability(Double availability) {
+        return (BasicLinkConfig) setOrClear(AVAILABILITY, availability);
+    }
+
+    /**
+     * Returns link flapping in terms of percentage.
+     *
+     * @return link flapping value; -1 if not set
+     */
+    public double flapping() {
+        return get(FLAPPING, -1.0);
+    }
+
+    /**
+     * Sets the link flapping.
+     *
+     * @param flapping new flapping value; null to clear
+     * @return self
+     */
+    public BasicLinkConfig flapping(Double flapping) {
+        return (BasicLinkConfig) setOrClear(FLAPPING, flapping);
+    }
+
+    /**
      * Create a {@link BasicLinkConfig} instance.
      * <p>
      * Note: created instance needs to be initialized by #init(..) before using.
diff --git a/core/api/src/test/java/org/onosproject/net/config/basics/BasicLinkConfigTest.java b/core/api/src/test/java/org/onosproject/net/config/basics/BasicLinkConfigTest.java
index adef8f1..94f0fa3 100644
--- a/core/api/src/test/java/org/onosproject/net/config/basics/BasicLinkConfigTest.java
+++ b/core/api/src/test/java/org/onosproject/net/config/basics/BasicLinkConfigTest.java
@@ -36,6 +36,11 @@
 public class BasicLinkConfigTest {
     private static final long BANDWIDTH = 11;
     private static final double METRIC = 3.0;
+    private static final double JITTER = 3.0;
+    private static final double DELAY = 3.0;
+    private static final double LOSS = 3.0;
+    private static final double AVAILABILITY = 3.0;
+    private static final double FLAPPING = 3.0;
     private static final Duration LATENCY =  Duration.ofNanos(5555);
 
     /**
@@ -54,6 +59,11 @@
 
 
         config.bandwidth(BANDWIDTH)
+                .jitter(JITTER)
+                .delay(DELAY)
+                .loss(LOSS)
+                .availability(AVAILABILITY)
+                .flapping(FLAPPING)
                 .isDurable(FALSE)
                 .metric(METRIC)
                 .type(Link.Type.DIRECT)
@@ -61,6 +71,11 @@
                 .isBidirectional(FALSE);
 
         assertThat(config.bandwidth(), is(BANDWIDTH));
+        assertThat(config.jitter(), is(JITTER));
+        assertThat(config.delay(), is(DELAY));
+        assertThat(config.loss(), is(LOSS));
+        assertThat(config.availability(), is(AVAILABILITY));
+        assertThat(config.flapping(), is(FLAPPING));
         assertThat(config.isDurable(), is(FALSE));
         assertThat(config.metric(), is(METRIC));
         assertThat(config.type(), is(Link.Type.DIRECT));
diff --git a/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java b/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java
index cbc046f..47cbdc6 100644
--- a/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java
+++ b/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java
@@ -38,6 +38,11 @@
 public final class BasicLinkOperator implements ConfigOperator {
 
     private static final long DEF_BANDWIDTH = -1L;
+    private static final double DEF_JITTER = -1.0;
+    private static final double DEF_DELAY = -1.0;
+    private static final double DEF_LOSS = -1.0;
+    private static final double DEF_AVAILABILITY = -1.0;
+    private static final double DEF_FLAPPING = -1.0;
     private static final double DEF_METRIC = -1;
     private static final Duration DEF_DURATION = Duration.ofNanos(-1L);
     private static final Logger log = getLogger(BasicLinkOperator.class);
@@ -93,6 +98,21 @@
         if (cfg.isDurable() != null) {
             b.set(AnnotationKeys.DURABLE, String.valueOf(cfg.isDurable()));
         }
+        if (cfg.jitter() != DEF_JITTER) {
+            b.set(AnnotationKeys.JITTER, String.valueOf(cfg.jitter()));
+        }
+        if (cfg.delay() != DEF_DELAY) {
+            b.set(AnnotationKeys.DELAY, String.valueOf(cfg.delay()));
+        }
+        if (cfg.loss() != DEF_LOSS) {
+            b.set(AnnotationKeys.LOSS, String.valueOf(cfg.loss()));
+        }
+        if (cfg.availability() != DEF_AVAILABILITY) {
+            b.set(AnnotationKeys.AVAILABILITY, String.valueOf(cfg.availability()));
+        }
+        if (cfg.flapping() != DEF_FLAPPING) {
+            b.set(AnnotationKeys.FLAPPING, String.valueOf(cfg.flapping()));
+        }
         return b.build();
     }