/** * Convert a colon-separated hex string to byte array. * * @param values colon-separated hex string to be converted, * e.g. "0f:ca:fe:de:ad:be:ef" * @return converted byte array * @throws NumberFormatException if input hex string cannot be parsed */ public static byte[] fromHexString(final String values) { return fromHexString(values, ":"); }
@Override public Criterion decodeCriterion(ObjectNode json) { JsonNode oduSignalId = nullIsIllegal(json.get(CriterionCodec.ODU_SIGNAL_ID), CriterionCodec.TRIBUTARY_PORT_NUMBER + MISSING_MEMBER_MESSAGE); int tributaryPortNumber = nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_PORT_NUMBER), CriterionCodec.TRIBUTARY_PORT_NUMBER + MISSING_MEMBER_MESSAGE).asInt(); int tributarySlotLen = nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_SLOT_LEN), CriterionCodec.TRIBUTARY_SLOT_LEN + MISSING_MEMBER_MESSAGE).asInt(); byte[] tributarySlotBitmap = HexString.fromHexString( nullIsIllegal(oduSignalId.get(CriterionCodec.TRIBUTARY_SLOT_BITMAP), CriterionCodec.TRIBUTARY_SLOT_BITMAP + MISSING_MEMBER_MESSAGE).asText()); return Criteria.matchOduSignalId( OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap)); } }
/** * Decodes a Layer 1 instruction. * * @return instruction object decoded from the JSON * @throws IllegalArgumentException if the JSON is invalid */ private Instruction decodeL1() { String subType = nullIsIllegal(json.get(InstructionCodec.SUBTYPE), InstructionCodec.SUBTYPE + InstructionCodec.ERROR_MESSAGE).asText(); if (subType.equals(L1ModificationInstruction.L1SubType.ODU_SIGID.name())) { int tributaryPortNumber = nullIsIllegal(json.get(InstructionCodec.TRIBUTARY_PORT_NUMBER), InstructionCodec.TRIBUTARY_PORT_NUMBER + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); int tributarySlotLen = nullIsIllegal(json.get(InstructionCodec.TRIBUTARY_SLOT_LEN), InstructionCodec.TRIBUTARY_SLOT_LEN + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt(); byte[] tributarySlotBitmap = null; tributarySlotBitmap = HexString.fromHexString( nullIsIllegal(json.get(InstructionCodec.TRIBUTARY_SLOT_BITMAP), InstructionCodec.TRIBUTARY_SLOT_BITMAP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText()); return Instructions.modL1OduSignalId(OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap)); } throw new IllegalArgumentException("L1 Instruction subtype " + subType + " is not supported"); }
CriterionCodec.PI_MATCH_FIELD_ID + MISSING_MEMBER_MESSAGE).asText()), HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_VALUE), CriterionCodec.PI_MATCH_VALUE + MISSING_MEMBER_MESSAGE).asText(), null)); CriterionCodec.PI_MATCH_FIELD_ID + MISSING_MEMBER_MESSAGE).asText()), HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_VALUE), CriterionCodec.PI_MATCH_VALUE + MISSING_MEMBER_MESSAGE).asText(), null), CriterionCodec.PI_MATCH_FIELD_ID + MISSING_MEMBER_MESSAGE).asText()), HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_VALUE), CriterionCodec.PI_MATCH_VALUE + MISSING_MEMBER_MESSAGE).asText(), null), HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_MASK), CriterionCodec.PI_MATCH_MASK + MISSING_MEMBER_MESSAGE).asText(), null)); CriterionCodec.PI_MATCH_FIELD_ID + MISSING_MEMBER_MESSAGE).asText()), HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_LOW_VALUE), CriterionCodec.PI_MATCH_LOW_VALUE + MISSING_MEMBER_MESSAGE).asText(), null), HexString.fromHexString(nullIsIllegal(node.get(CriterionCodec.PI_MATCH_HIGH_VALUE), CriterionCodec.PI_MATCH_HIGH_VALUE + MISSING_MEMBER_MESSAGE).asText(), null)
throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x"); GroupKey groupKey = new DefaultGroupKey(HexString.fromHexString( groupKeyStr.split("0x")[1], ""));
piActionParam = new PiActionParam(piActionParamId, ImmutableByteSequence.copyFrom( HexString.fromHexString(param.getValue(), null))); builder.withParameter(piActionParam);