use of org.onosproject.net.intent.constraint.LatencyConstraint in project onos by opennetworkinglab.
the class ConnectivityIntentCommand method buildConstraints.
/**
* Builds the constraint list for this command based on the command line
* parameters.
*
* @return List of constraint objects describing the constraints requested
*/
protected List<Constraint> buildConstraints() {
final List<Constraint> constraints = new LinkedList<>();
// Check for a bandwidth specification
if (!isNullOrEmpty(bandwidthString)) {
Bandwidth bandwidth;
try {
bandwidth = Bandwidth.bps(Long.parseLong(bandwidthString));
// when the string can't be parsed as long, then try to parse as double
} catch (NumberFormatException e) {
bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
}
constraints.add(new BandwidthConstraint(bandwidth));
}
// Check for partial failure specification
if (partial) {
constraints.add(new PartialFailureConstraint());
}
// Check for encapsulation specification
if (!isNullOrEmpty(encapsulationString)) {
final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
constraints.add(new EncapsulationConstraint(encapType));
}
// Check for hashed path selection
if (hashedPathSelection) {
constraints.add(new HashedPathSelectionConstraint());
}
// Check for domain processing
if (domains) {
constraints.add(DomainConstraint.domain());
}
// Check for a latency specification
if (!isNullOrEmpty(latConstraint)) {
try {
long lat = Long.parseLong(latConstraint);
constraints.add(new LatencyConstraint(Duration.of(lat, ChronoUnit.NANOS)));
} catch (NumberFormatException e) {
double lat = Double.parseDouble(latConstraint);
constraints.add(new LatencyConstraint(Duration.of((long) lat, ChronoUnit.NANOS)));
}
}
return constraints;
}
Aggregations