use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class ConstraintCodecTest method linkTypeConstraint.
/**
* Tests link type constraint.
*/
@Test
public void linkTypeConstraint() {
Constraint constraint = getConstraint("LinkTypeConstraint.json");
assertThat(constraint, instanceOf(LinkTypeConstraint.class));
LinkTypeConstraint linkTypeConstraint = (LinkTypeConstraint) constraint;
assertThat(linkTypeConstraint.isInclusive(), is(false));
assertThat(linkTypeConstraint.types(), hasSize(2));
assertThat(linkTypeConstraint.types(), hasItem(Link.Type.OPTICAL));
assertThat(linkTypeConstraint.types(), hasItem(Link.Type.DIRECT));
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class ConstraintCodecTest method asymmetricPathConstraint.
/**
* Tests asymmetric path constraint.
*/
@Test
public void asymmetricPathConstraint() {
Constraint constraint = getConstraint("AsymmetricPathConstraint.json");
assertThat(constraint, instanceOf(AsymmetricPathConstraint.class));
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class ConstraintCodecTest method bandwidthConstraint.
/**
* Tests bandwidth constraint.
*/
@Test
public void bandwidthConstraint() {
Constraint constraint = getConstraint("BandwidthConstraint.json");
assertThat(constraint, instanceOf(BandwidthConstraint.class));
BandwidthConstraint bandwidthConstraint = (BandwidthConstraint) constraint;
assertThat(bandwidthConstraint.bandwidth().bps(), is(345.678D));
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class IntentJsonMatcher method matchLinkTypeConstraint.
/**
* Matches a link type constraint against a JSON representation of the
* constraint.
*
* @param linkTypeConstraint constraint object to match
* @param constraintJson JSON representation of the constraint
* @return true if the constraint and JSON match, false otherwise.
*/
private boolean matchLinkTypeConstraint(LinkTypeConstraint linkTypeConstraint, JsonNode constraintJson) {
final JsonNode inclusiveJson = constraintJson.get("inclusive");
final JsonNode typesJson = constraintJson.get("types");
if (typesJson.size() != linkTypeConstraint.types().size()) {
return false;
}
int foundType = 0;
for (Link.Type type : linkTypeConstraint.types()) {
for (int jsonIndex = 0; jsonIndex < typesJson.size(); jsonIndex++) {
if (type.name().equals(typesJson.get(jsonIndex).asText())) {
foundType++;
break;
}
}
}
return (inclusiveJson != null && inclusiveJson.asBoolean() == linkTypeConstraint.isInclusive()) && foundType == typesJson.size();
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class IntentJsonMatcher method matchWaypointConstraint.
/**
* Matches a waypoint constraint against a JSON representation of the
* constraint.
*
* @param waypointConstraint constraint object to match
* @param constraintJson JSON representation of the constraint
* @return true if the constraint and JSON match, false otherwise.
*/
private boolean matchWaypointConstraint(WaypointConstraint waypointConstraint, JsonNode constraintJson) {
final JsonNode waypointsJson = constraintJson.get("waypoints");
if (waypointsJson.size() != waypointConstraint.waypoints().size()) {
return false;
}
for (int waypointsIndex = 0; waypointsIndex < waypointsJson.size(); waypointsIndex++) {
boolean waypointFound = false;
final String waypointJson = waypointsJson.get(waypointsIndex).asText();
for (DeviceId waypoint : waypointConstraint.waypoints()) {
if (waypoint.toString().equals(waypointJson)) {
waypointFound = true;
}
}
if (!waypointFound) {
return false;
}
}
return true;
}
Aggregations