use of org.onosproject.net.intent.constraint.LatencyConstraint in project onos by opennetworkinglab.
the class LinkCollectionIntentTest method testConstructorWithConstraints.
/**
* Tests constructor with constraints.
*/
@Test
public void testConstructorWithConstraints() {
final HashSet<Link> links1 = new HashSet<>();
final LinkedList<Constraint> constraints = new LinkedList<>();
links1.add(link("src", 1, "dst", 2));
constraints.add(new LatencyConstraint(Duration.ofMillis(100)));
final LinkCollectionIntent collectionIntent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).links(links1).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(ingress))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(egress))).constraints(constraints).priority(8888).build();
final Set<Link> createdLinks = collectionIntent.links();
assertThat(createdLinks, hasSize(1));
assertThat(collectionIntent.isInstallable(), is(false));
assertThat(collectionIntent.treatment(), is(treatment));
assertThat(collectionIntent.selector(), is(selector));
assertThat(collectionIntent.ingressPoints(), is(ImmutableSet.of(ingress)));
assertThat(collectionIntent.egressPoints(), is(ImmutableSet.of(egress)));
final List<Constraint> createdConstraints = collectionIntent.constraints();
assertThat(createdConstraints, hasSize(1));
assertThat(createdConstraints.get(0), instanceOf(LatencyConstraint.class));
}
use of org.onosproject.net.intent.constraint.LatencyConstraint in project onos by opennetworkinglab.
the class ConstraintCodecTest method latencyConstraint.
/**
* Tests latency constraint.
*/
@Test
public void latencyConstraint() {
Constraint constraint = getConstraint("LatencyConstraint.json");
assertThat(constraint, instanceOf(LatencyConstraint.class));
LatencyConstraint latencyConstraint = (LatencyConstraint) constraint;
assertThat(latencyConstraint.latency().toMillis(), is(111L));
}
use of org.onosproject.net.intent.constraint.LatencyConstraint in project onos by opennetworkinglab.
the class IntentCodecTest method intentWithTreatmentSelectorAndConstraints.
/**
* Tests the encoding of an intent with treatment, selector and constraints
* specified.
*/
@Test
public void intentWithTreatmentSelectorAndConstraints() {
ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1);
ConnectPoint egress = NetTestTools.connectPoint("egress", 2);
DeviceId did1 = did("device1");
DeviceId did2 = did("device2");
DeviceId did3 = did("device3");
Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
final TrafficSelector selector = DefaultTrafficSelector.builder().matchIPProtocol((byte) 3).matchMplsLabel(MplsLabel.mplsLabel(4)).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).matchEthDst(MacAddress.BROADCAST).matchIPDst(IpPrefix.valueOf("1.2.3.4/24")).build();
final TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(44)).setOutput(PortNumber.CONTROLLER).setEthDst(MacAddress.BROADCAST).build();
final List<Constraint> constraints = ImmutableList.of(new BandwidthConstraint(Bandwidth.bps(1.0)), new AnnotationConstraint("key", 33.0), new AsymmetricPathConstraint(), new LatencyConstraint(Duration.ofSeconds(2)), new ObstacleConstraint(did1, did2), new WaypointConstraint(did3));
final PointToPointIntent intent = PointToPointIntent.builder().appId(appId).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).constraints(constraints).build();
final JsonCodec<PointToPointIntent> intentCodec = context.codec(PointToPointIntent.class);
assertThat(intentCodec, notNullValue());
final ObjectNode intentJson = intentCodec.encode(intent, context);
assertThat(intentJson, matchesIntent(intent));
}
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;
}
use of org.onosproject.net.intent.constraint.LatencyConstraint in project onos by opennetworkinglab.
the class EncodeConstraintCodecHelper method encode.
/**
* Encodes the constraint in JSON.
*
* @return JSON node
*/
public ObjectNode encode() {
final ObjectNode result;
if (constraint instanceof BandwidthConstraint) {
result = encodeBandwidthConstraint();
} else if (constraint instanceof LinkTypeConstraint) {
result = encodeLinkTypeConstraint();
} else if (constraint instanceof AnnotationConstraint) {
result = encodeAnnotationConstraint();
} else if (constraint instanceof LatencyConstraint) {
result = encodeLatencyConstraint();
} else if (constraint instanceof ObstacleConstraint) {
result = encodeObstacleConstraint();
} else if (constraint instanceof WaypointConstraint) {
result = encodeWaypointConstraint();
} else if (constraint instanceof MeteredConstraint) {
result = encodeMeteredConstraint();
} else if (constraint instanceof TierConstraint) {
result = encodeTierConstraint();
} else {
result = context.mapper().createObjectNode();
}
result.put(ConstraintCodec.TYPE, constraint.getClass().getSimpleName());
return result;
}
Aggregations