Sho SHIMIZU

Aggregate definition of annotation key for latency into a single file

Change-Id: Id0b9089ec60e6f144ff42c40d0e1b19b280c4271
/*
* Copyright 2014 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.onlab.onos.net;
/**
* Collection of keys for annotation.
* Definitions of annotation keys needs to be here to avoid scattering.
*/
public final class AnnotationKeys {
// Prohibit instantiation
private AnnotationKeys() {}
/**
* Annotation key for latency.
*/
public static final String LATENCY = "latency";
}
......@@ -25,14 +25,13 @@ import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Objects;
import static org.onlab.onos.net.AnnotationKeys.LATENCY;
/**
* Constraint that evaluates the latency through a path.
*/
public class LatencyConstraint implements Constraint {
// TODO: formalize the key for latency all over the codes.
private static final String LATENCY_KEY = "latency";
private final Duration latency;
/**
......@@ -49,7 +48,7 @@ public class LatencyConstraint implements Constraint {
@Override
public double cost(Link link, LinkResourceService resourceService) {
String value = link.annotations().value(LATENCY_KEY);
String value = link.annotations().value(LATENCY);
double latencyInMicroSec;
try {
......
......@@ -37,6 +37,7 @@ import static org.easymock.EasyMock.createMock;
import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.onlab.onos.net.AnnotationKeys.LATENCY;
import static org.onlab.onos.net.DefaultLinkTest.cp;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.Link.Type.DIRECT;
......@@ -51,7 +52,6 @@ public class LatencyConstraintTest {
private static final PortNumber PN3 = PortNumber.portNumber(3);
private static final PortNumber PN4 = PortNumber.portNumber(4);
private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo");
private static final String LATENCY_KEY = "latency";
private static final String LATENCY1 = "3.0";
private static final String LATENCY2 = "4.0";
......@@ -66,8 +66,8 @@ public class LatencyConstraintTest {
public void setUp() {
linkResourceService = createMock(LinkResourceService.class);
Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY_KEY, LATENCY1).build();
Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY_KEY, LATENCY2).build();
Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build();
Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build();
link1 = new DefaultLink(PROVIDER_ID, cp(DID1, PN1), cp(DID2, PN2), DIRECT, annotations1);
link2 = new DefaultLink(PROVIDER_ID, cp(DID2, PN3), cp(DID3, PN4), DIRECT, annotations2);
......