Search in sources :

Example 1 with WaypointConstraint

use of org.onosproject.net.intent.constraint.WaypointConstraint in project onos by opennetworkinglab.

the class EncodeConstraintCodecHelper method encodeWaypointConstraint.

/**
 * Encodes a waypoint constraint.
 *
 * @return JSON ObjectNode representing the constraint
 */
private ObjectNode encodeWaypointConstraint() {
    checkNotNull(constraint, "Waypoint constraint cannot be null");
    final WaypointConstraint waypointConstraint = (WaypointConstraint) constraint;
    final ObjectNode result = context.mapper().createObjectNode();
    final ArrayNode jsonWaypoints = result.putArray("waypoints");
    for (DeviceId did : waypointConstraint.waypoints()) {
        jsonWaypoints.add(did.toString());
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) DeviceId(org.onosproject.net.DeviceId) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with WaypointConstraint

use of org.onosproject.net.intent.constraint.WaypointConstraint in project onos by opennetworkinglab.

the class ConstraintCodecTest method waypointConstraint.

/**
 * Tests waypoint constaint.
 */
@Test
public void waypointConstraint() {
    Constraint constraint = getConstraint("WaypointConstraint.json");
    assertThat(constraint, instanceOf(WaypointConstraint.class));
    WaypointConstraint waypointConstraint = (WaypointConstraint) constraint;
    assertThat(waypointConstraint.waypoints(), hasItem(did("devA")));
    assertThat(waypointConstraint.waypoints(), hasItem(did("devB")));
    assertThat(waypointConstraint.waypoints(), hasItem(did("devC")));
}
Also used : WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) MeteredConstraint(org.onosproject.net.intent.constraint.MeteredConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) Test(org.junit.Test)

Example 3 with WaypointConstraint

use of org.onosproject.net.intent.constraint.WaypointConstraint 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));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) DeviceId(org.onosproject.net.DeviceId) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Lambda(org.onosproject.net.Lambda) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 4 with WaypointConstraint

use of org.onosproject.net.intent.constraint.WaypointConstraint in project onos by opennetworkinglab.

the class DecodeConstraintCodecHelper method decodeWaypointConstraint.

/**
 * Decodes a waypoint constraint.
 *
 * @return waypoint constraint object.
 */
private Constraint decodeWaypointConstraint() {
    JsonNode waypoints = nullIsIllegal(json.get(ConstraintCodec.WAYPOINTS), ConstraintCodec.WAYPOINTS + ConstraintCodec.MISSING_MEMBER_MESSAGE);
    if (waypoints.size() < 1) {
        throw new IllegalArgumentException("obstacles array in obstacles constraint must have at least one value");
    }
    ArrayList<DeviceId> waypointEntries = new ArrayList<>(waypoints.size());
    IntStream.range(0, waypoints.size()).forEach(index -> waypointEntries.add(DeviceId.deviceId(waypoints.get(index).asText())));
    return new WaypointConstraint(waypointEntries.toArray(new DeviceId[waypoints.size()]));
}
Also used : DeviceId(org.onosproject.net.DeviceId) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 5 with WaypointConstraint

use of org.onosproject.net.intent.constraint.WaypointConstraint 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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) TierConstraint(org.onosproject.net.intent.constraint.TierConstraint) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) MeteredConstraint(org.onosproject.net.intent.constraint.MeteredConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint)

Aggregations

WaypointConstraint (org.onosproject.net.intent.constraint.WaypointConstraint)6 DeviceId (org.onosproject.net.DeviceId)4 AnnotationConstraint (org.onosproject.net.intent.constraint.AnnotationConstraint)4 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)4 LatencyConstraint (org.onosproject.net.intent.constraint.LatencyConstraint)4 ObstacleConstraint (org.onosproject.net.intent.constraint.ObstacleConstraint)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Constraint (org.onosproject.net.intent.Constraint)3 LinkTypeConstraint (org.onosproject.net.intent.constraint.LinkTypeConstraint)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Test (org.junit.Test)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 AsymmetricPathConstraint (org.onosproject.net.intent.constraint.AsymmetricPathConstraint)2 MeteredConstraint (org.onosproject.net.intent.constraint.MeteredConstraint)2 TierConstraint (org.onosproject.net.intent.constraint.TierConstraint)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)1 Lambda (org.onosproject.net.Lambda)1 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)1