@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) .ingressPoint(ingress) .egressPoint(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)); }
@Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() .escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); } IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; }
IntentCodec extends JsonCodec<Intent> { @Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() .escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); } IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; } }
IntentCodec extends JsonCodec<Intent> { @Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() .escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); } IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; }  }
IntentCodec extends JsonCodec<Intent> { @Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() .escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); } IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; }  @Override ObjectNode encode(Intent intent, CodecContext context); @Override Intent decode(ObjectNode json, CodecContext context); static void intentAttributes(ObjectNode json, CodecContext context,
                                    Intent.Builder builder); }
IntentCodec extends JsonCodec<Intent> { @Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper() .escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); } IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; }  @Override ObjectNode encode(Intent intent, CodecContext context); @Override Intent decode(ObjectNode json, CodecContext context); static void intentAttributes(ObjectNode json, CodecContext context,
                                    Intent.Builder builder);  }