use of org.onosproject.net.intent.constraint.AnnotationConstraint in project onos by opennetworkinglab.
the class EncodeConstraintCodecHelper method encodeAnnotationConstraint.
/**
* Encodes a annotation constraint.
*
* @return JSON ObjectNode representing the constraint
*/
private ObjectNode encodeAnnotationConstraint() {
checkNotNull(constraint, "Annotation constraint cannot be null");
final AnnotationConstraint annotationConstraint = (AnnotationConstraint) constraint;
return context.mapper().createObjectNode().put("key", annotationConstraint.key()).put("threshold", annotationConstraint.threshold());
}
use of org.onosproject.net.intent.constraint.AnnotationConstraint in project onos by opennetworkinglab.
the class ConstraintCodecTest method annotationConstraint.
/**
* Tests annotation constraint.
*/
@Test
public void annotationConstraint() {
Constraint constraint = getConstraint("AnnotationConstraint.json");
assertThat(constraint, instanceOf(AnnotationConstraint.class));
AnnotationConstraint annotationConstraint = (AnnotationConstraint) constraint;
assertThat(annotationConstraint.key(), is("key"));
assertThat(annotationConstraint.threshold(), is(123.0D));
}
use of org.onosproject.net.intent.constraint.AnnotationConstraint 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.AnnotationConstraint 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