use of org.onosproject.net.intent.constraint.PartialFailureConstraint 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;
}
use of org.onosproject.net.intent.constraint.PartialFailureConstraint in project onos by opennetworkinglab.
the class MultiPointToSinglePointIntentCompilerTest method testPartialFailureConstraintSuccess.
/**
* Tests if all expected links are present when a partial failure
* constraint is used and one ingress is not present.
*/
@Test
public void testPartialFailureConstraintSuccess() {
Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)), new FilteredConnectPoint(new ConnectPoint(DID_5, PORT_1)));
FilteredConnectPoint egress = new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_2));
final List<Constraint> constraints = Collections.singletonList(new PartialFailureConstraint());
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress, constraints);
String[] hops = { S3 };
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(null, new IntentTestsMocks.FixedMP2MPMockPathService(hops), null);
assertThat(compiler, is(notNullValue()));
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent, instanceOf(LinkCollectionIntent.class));
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
assertThat(linkIntent.links(), hasSize(2));
assertThat(linkIntent.links(), linksHasPath(S1, S3));
assertThat(linkIntent.links(), linksHasPath(S3, S4));
}
assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
use of org.onosproject.net.intent.constraint.PartialFailureConstraint in project onos by opennetworkinglab.
the class SinglePointToMultiPointIntentCompilerTest method testPartialFailureConstraintSuccess.
/**
* Tests if all expected links are present when a partial failure
* constraint is used and one ingress is not present.
*/
@Test
public void testPartialFailureConstraintSuccess() {
FilteredConnectPoint ingress = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1));
Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_4, PORT_2)), new FilteredConnectPoint(new ConnectPoint(DID_5, PORT_2)));
final List<Constraint> constraints = Collections.singletonList(new PartialFailureConstraint());
SinglePointToMultiPointIntent intent = makeIntent(ingress, egress, constraints);
String[] hops = { S3 };
SinglePointToMultiPointIntentCompiler compiler = makeCompiler(null, new IntentTestsMocks.FixedMP2MPMockPathService(hops), null);
assertThat(compiler, is(notNullValue()));
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent, instanceOf(LinkCollectionIntent.class));
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
assertThat(linkIntent.links(), hasSize(2));
assertThat(linkIntent.links(), linksHasPath(S1, S3));
assertThat(linkIntent.links(), linksHasPath(S3, S4));
}
assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
Aggregations