Sho SHIMIZU

Aggregate definition of annotation key for latency into a single file

Change-Id: Id0b9089ec60e6f144ff42c40d0e1b19b280c4271
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onlab.onos.net;
17 +
18 +/**
19 + * Collection of keys for annotation.
20 + * Definitions of annotation keys needs to be here to avoid scattering.
21 + */
22 +public final class AnnotationKeys {
23 +
24 + // Prohibit instantiation
25 + private AnnotationKeys() {}
26 +
27 + /**
28 + * Annotation key for latency.
29 + */
30 + public static final String LATENCY = "latency";
31 +}
...@@ -25,14 +25,13 @@ import java.time.Duration; ...@@ -25,14 +25,13 @@ import java.time.Duration;
25 import java.time.temporal.ChronoUnit; 25 import java.time.temporal.ChronoUnit;
26 import java.util.Objects; 26 import java.util.Objects;
27 27
28 +import static org.onlab.onos.net.AnnotationKeys.LATENCY;
29 +
28 /** 30 /**
29 * Constraint that evaluates the latency through a path. 31 * Constraint that evaluates the latency through a path.
30 */ 32 */
31 public class LatencyConstraint implements Constraint { 33 public class LatencyConstraint implements Constraint {
32 34
33 - // TODO: formalize the key for latency all over the codes.
34 - private static final String LATENCY_KEY = "latency";
35 -
36 private final Duration latency; 35 private final Duration latency;
37 36
38 /** 37 /**
...@@ -49,7 +48,7 @@ public class LatencyConstraint implements Constraint { ...@@ -49,7 +48,7 @@ public class LatencyConstraint implements Constraint {
49 48
50 @Override 49 @Override
51 public double cost(Link link, LinkResourceService resourceService) { 50 public double cost(Link link, LinkResourceService resourceService) {
52 - String value = link.annotations().value(LATENCY_KEY); 51 + String value = link.annotations().value(LATENCY);
53 52
54 double latencyInMicroSec; 53 double latencyInMicroSec;
55 try { 54 try {
......
...@@ -37,6 +37,7 @@ import static org.easymock.EasyMock.createMock; ...@@ -37,6 +37,7 @@ import static org.easymock.EasyMock.createMock;
37 import static org.hamcrest.Matchers.closeTo; 37 import static org.hamcrest.Matchers.closeTo;
38 import static org.hamcrest.Matchers.is; 38 import static org.hamcrest.Matchers.is;
39 import static org.junit.Assert.assertThat; 39 import static org.junit.Assert.assertThat;
40 +import static org.onlab.onos.net.AnnotationKeys.LATENCY;
40 import static org.onlab.onos.net.DefaultLinkTest.cp; 41 import static org.onlab.onos.net.DefaultLinkTest.cp;
41 import static org.onlab.onos.net.DeviceId.deviceId; 42 import static org.onlab.onos.net.DeviceId.deviceId;
42 import static org.onlab.onos.net.Link.Type.DIRECT; 43 import static org.onlab.onos.net.Link.Type.DIRECT;
...@@ -51,7 +52,6 @@ public class LatencyConstraintTest { ...@@ -51,7 +52,6 @@ public class LatencyConstraintTest {
51 private static final PortNumber PN3 = PortNumber.portNumber(3); 52 private static final PortNumber PN3 = PortNumber.portNumber(3);
52 private static final PortNumber PN4 = PortNumber.portNumber(4); 53 private static final PortNumber PN4 = PortNumber.portNumber(4);
53 private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); 54 private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo");
54 - private static final String LATENCY_KEY = "latency";
55 private static final String LATENCY1 = "3.0"; 55 private static final String LATENCY1 = "3.0";
56 private static final String LATENCY2 = "4.0"; 56 private static final String LATENCY2 = "4.0";
57 57
...@@ -66,8 +66,8 @@ public class LatencyConstraintTest { ...@@ -66,8 +66,8 @@ public class LatencyConstraintTest {
66 public void setUp() { 66 public void setUp() {
67 linkResourceService = createMock(LinkResourceService.class); 67 linkResourceService = createMock(LinkResourceService.class);
68 68
69 - Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY_KEY, LATENCY1).build(); 69 + Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build();
70 - Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY_KEY, LATENCY2).build(); 70 + Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build();
71 71
72 link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT, annotations1); 72 link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT, annotations1);
73 link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT, annotations2); 73 link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT, annotations2);
......