@Override public ObjectNode encode(TenantId tenantId, CodecContext context) { checkNotNull(tenantId, NULL_TENANT_MSG); ObjectNode result = context.mapper().createObjectNode() .put(TENANT_ID, tenantId.id()); return result; }
@Override public ObjectNode encode(Annotations annotations, CodecContext context) { ObjectNode result = context.mapper().createObjectNode(); Set<String> keys = new TreeSet<>(annotations.keys()); for (String key : keys) { result.put(key, annotations.value(key)); } return result; }
@Override public ObjectNode encode(PiPipelineModel pipeline, CodecContext context) { ObjectNode result = context.mapper().createObjectNode(); ArrayNode actions = result.putArray(ACTIONS); pipeline.tables() .stream() .flatMap(piTableModel -> piTableModel.actions().stream()) .distinct() .map(action -> context.encode(action, PiActionModel.class)) .forEach(actions::add); ArrayNode tables = result.putArray(TABLES); pipeline.tables().stream() .map(table -> context.encode(table, PiTableModel.class)) .forEach(tables::add); return result; } }
@Override public ObjectNode encode(NextObjective nextObjective, CodecContext context) { checkNotNull(nextObjective, NOT_NULL_MESSAGE); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class); // encode common properties ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(nextObjective, context); // encode id result.put(ID, nextObjective.id()); // encode type result.put(TYPE, nextObjective.type().toString()); // encode operation result.put(OPERATION, nextObjective.op().toString()); // encode treatments ArrayNode treatments = context.mapper().createArrayNode(); nextObjective.next().forEach(t -> { ObjectNode treatmentJson = trafficTreatmentCodec.encode(t, context); treatments.add(treatmentJson); }); result.set(TREATMENTS, treatments); // encode meta if (nextObjective.meta() != null) { ObjectNode trafficSelectorNode = trafficSelectorCodec.encode(nextObjective.meta(), context); result.set(META, trafficSelectorNode); } return result; }
@Override public ObjectNode encode(ExtensionTreatment extensionTreatment, CodecContext context) { checkNotNull(extensionTreatment, "Extension treatment cannot be null"); ExtensionTreatmentType type = extensionTreatment.type(); ObjectNode root = context.mapper().createObjectNode();
@Override public ObjectNode encode(FilteredConnectPoint entity, CodecContext context) { ObjectNode node = context.mapper().createObjectNode(); node.set(CONNECT_POINT, context.encode(entity.connectPoint(), ConnectPoint.class)); node.set(TRAFFIC_SELECTOR, context.encode(entity.trafficSelector(), TrafficSelector.class)); return node; }
/** * Encodes a latency constraint. * * @return JSON ObjectNode representing the constraint */ private ObjectNode encodeLatencyConstraint() { checkNotNull(constraint, "Duration constraint cannot be null"); final LatencyConstraint latencyConstraint = (LatencyConstraint) constraint; return context.mapper().createObjectNode() .put("latencyMillis", latencyConstraint.latency().toMillis()); }
@Override public ObjectNode encode(FilteringObjective filteringObjective, CodecContext context) { checkNotNull(filteringObjective, NOT_NULL_MESSAGE); result.put(ID, filteringObjective.id()); result.put(TYPE, filteringObjective.type().toString()); ArrayNode conditions = context.mapper().createArrayNode(); filteringObjective.conditions().forEach(c -> { ObjectNode criterionJson = criterionCodec.encode(c, context);
@Override public ObjectNode encode(TransportEndpointDescription entity, CodecContext context) { ObjectNode node = context.mapper().createObjectNode(); node.put(ENABLED, entity.isEnabled()); node.set(OUTPUT, context.encode(entity.output(), FilteredConnectPoint.class)); return node; } }
@Override public ObjectNode encode(MastershipRole mastershipRole, CodecContext context) { checkNotNull(mastershipRole, "MastershipRole cannot be null"); ObjectNode result = context.mapper().createObjectNode() .put(ROLE, mastershipRole.name()); return result; }
@Override public ObjectNode encode(PiActionParamModel param, CodecContext context) { ObjectNode result = context.mapper().createObjectNode(); result.put(NAME, param.id().toString()); result.put(BIT_WIDTH, param.bitWidth()); return result; } }
/** * Encodes a bandwidth constraint. * * @return JSON ObjectNode representing the constraint */ private ObjectNode encodeBandwidthConstraint() { checkNotNull(constraint, "Bandwidth constraint cannot be null"); final BandwidthConstraint bandwidthConstraint = (BandwidthConstraint) constraint; return context.mapper().createObjectNode() .put("bandwidth", bandwidthConstraint.bandwidth().bps()); }
@Override public ObjectNode encode(PiMatchFieldModel matchFieldModel, CodecContext context) { ObjectNode result = context.mapper().createObjectNode(); result.put(MATCH_TYPE, matchFieldModel.matchType().toString()); result.put(BIT_WIDTH, matchFieldModel.bitWidth()); result.put(FIELD, matchFieldModel.id().toString()); return result; } }
@Override public ObjectNode encode(OfdpaMatchVlanVid vlanId, CodecContext context) { checkNotNull(vlanId, "Vlan ID cannot be null"); ObjectNode root = context.mapper().createObjectNode() .put(VLAN_ID, vlanId.vlanId().id()); return root; }
private ObjectNode parsePiMatchExact(PiExactFieldMatch exactFieldMatch) { ObjectNode matchExactNode = context.mapper().createObjectNode(); matchExactNode.put(CriterionCodec.PI_MATCH_FIELD_ID, exactFieldMatch.fieldId().id()); matchExactNode.put(CriterionCodec.PI_MATCH_TYPE, PiMatchType.EXACT.name().toLowerCase()); matchExactNode.put(CriterionCodec.PI_MATCH_VALUE, HexString.toHexString(exactFieldMatch.value().asArray(), null)); return matchExactNode; }
@Override public ObjectNode encode(NiciraMatchNshSi niciraMatchNshSi, CodecContext context) { checkNotNull(niciraMatchNshSi, "Nicira Match Nsh Si cannot be null"); ObjectNode root = context.mapper().createObjectNode() .put(NSH_SERVICE_INDEX, niciraMatchNshSi.nshSi().serviceIndex()); return root; }
private ObjectNode parsePiMatchLpm(PiLpmFieldMatch lpmFieldMatch) { ObjectNode matchLpmNode = context.mapper().createObjectNode(); matchLpmNode.put(CriterionCodec.PI_MATCH_FIELD_ID, lpmFieldMatch.fieldId().id()); matchLpmNode.put(CriterionCodec.PI_MATCH_TYPE, PiMatchType.LPM.name().toLowerCase()); matchLpmNode.put(CriterionCodec.PI_MATCH_VALUE, HexString.toHexString(lpmFieldMatch.value().asArray(), null)); matchLpmNode.put(CriterionCodec.PI_MATCH_PREFIX, lpmFieldMatch.prefixLength()); return matchLpmNode; }
@Override public ObjectNode encode(ApplicationId appId, CodecContext context) { checkNotNull(appId, "ApplicationId cannot be null"); ObjectNode result = context.mapper().createObjectNode() .put("id", appId.id()) .put("name", appId.name()); return result; }
private ObjectNode parsePiMatchTernary(PiTernaryFieldMatch ternaryFieldMatch) { ObjectNode matchTernaryNode = context.mapper().createObjectNode(); matchTernaryNode.put(CriterionCodec.PI_MATCH_FIELD_ID, ternaryFieldMatch.fieldId().id()); matchTernaryNode.put(CriterionCodec.PI_MATCH_TYPE, PiMatchType.TERNARY.name().toLowerCase()); matchTernaryNode.put(CriterionCodec.PI_MATCH_VALUE, HexString.toHexString(ternaryFieldMatch.value().asArray(), null)); matchTernaryNode.put(CriterionCodec.PI_MATCH_MASK, HexString.toHexString(ternaryFieldMatch.mask().asArray(), null)); return matchTernaryNode; }
@Override public ObjectNode encode(NiciraSetNshSpi niciraSetNshSpi, CodecContext context) { checkNotNull(niciraSetNshSpi, "Nicira Set Nsh Spi cannot be null"); ObjectNode root = context.mapper().createObjectNode() .put(NSH_PATH_ID, niciraSetNshSpi.nshSpi().servicePathId()); return root; }