Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Thomas Vachuska
2014-11-11 16:51:50 -0800
Browse Files
Options
Browse Files
Download
Plain Diff
Committed by
Gerrit Code Review
2014-11-11 16:51:50 -0800
Commit
591cf2776b1ba893d11c531b0b66860d98f2f7ca
591cf277
2 parents
36fa36dd
97a64cd7
Merge "Refactor: move method to get annotated double value"
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
29 deletions
core/api/src/main/java/org/onlab/onos/net/AnnotationKeys.java
core/api/src/main/java/org/onlab/onos/net/intent/constraint/AnnotationConstraint.java
core/api/src/main/java/org/onlab/onos/net/intent/constraint/LatencyConstraint.java
core/api/src/main/java/org/onlab/onos/net/AnnotationKeys.java
View file @
591cf27
...
...
@@ -28,4 +28,23 @@ public final class AnnotationKeys {
* Annotation key for latency.
*/
public
static
final
String
LATENCY
=
"latency"
;
/**
* 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 1.0.
*
* @param annotated annotated object whose annotated value is obtained
* @param key key of annotation
* @return double value of annotated object for the specified key
*/
public
static
double
getAnnotatedValue
(
Annotated
annotated
,
String
key
)
{
double
value
;
try
{
value
=
Double
.
parseDouble
(
annotated
.
annotations
().
value
(
key
));
}
catch
(
NumberFormatException
e
)
{
value
=
1.0
;
}
return
value
;
}
}
...
...
core/api/src/main/java/org/onlab/onos/net/intent/constraint/AnnotationConstraint.java
View file @
591cf27
...
...
@@ -21,6 +21,8 @@ import org.onlab.onos.net.resource.LinkResourceService;
import
java.util.Objects
;
import
static
org
.
onlab
.
onos
.
net
.
AnnotationKeys
.
getAnnotatedValue
;
/**
* Constraint that evaluates an arbitrary link annotated value is under the specified threshold.
*/
...
...
@@ -65,25 +67,6 @@ public class AnnotationConstraint extends BooleanConstraint {
return
value
<=
threshold
;
}
/**
* Returns the annotated value of the specified link. The annotated value
* is expected to be String that can be parsed as double. If parsing fails,
* the returned value will be 1.0.
*
* @param link link whose annotated value is obtained
* @param key key of link annotation
* @return double value of link annotation for the specified key
*/
private
double
getAnnotatedValue
(
Link
link
,
String
key
)
{
double
value
;
try
{
value
=
Double
.
parseDouble
(
link
.
annotations
().
value
(
key
));
}
catch
(
NumberFormatException
e
)
{
value
=
1.0
;
}
return
value
;
}
@Override
public
double
cost
(
Link
link
,
LinkResourceService
resourceService
)
{
if
(
isValid
(
link
,
resourceService
))
{
...
...
core/api/src/main/java/org/onlab/onos/net/intent/constraint/LatencyConstraint.java
View file @
591cf27
...
...
@@ -26,6 +26,7 @@ import java.time.temporal.ChronoUnit;
import
java.util.Objects
;
import
static
org
.
onlab
.
onos
.
net
.
AnnotationKeys
.
LATENCY
;
import
static
org
.
onlab
.
onos
.
net
.
AnnotationKeys
.
getAnnotatedValue
;
/**
* Constraint that evaluates the latency through a path.
...
...
@@ -48,16 +49,7 @@ public class LatencyConstraint implements Constraint {
@Override
public
double
cost
(
Link
link
,
LinkResourceService
resourceService
)
{
String
value
=
link
.
annotations
().
value
(
LATENCY
);
double
latencyInMicroSec
;
try
{
latencyInMicroSec
=
Double
.
parseDouble
(
value
);
}
catch
(
NumberFormatException
e
)
{
latencyInMicroSec
=
1.0
;
}
return
latencyInMicroSec
;
return
getAnnotatedValue
(
link
,
LATENCY
);
}
@Override
...
...
Please
register
or
login
to post a comment