List of usage examples for io.netty.buffer ByteBuf slice
public abstract ByteBuf slice();
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser.java
License:Open Source License
@Override public Of parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException { Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final OfBuilder builder = new OfBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); builder.setCode(new OfId(bytes.readUnsignedShort())); bytes.readBytes(RESERVED);/* w w w .ja va2 s .c o m*/ final TlvsBuilder tlvsBuilder = new TlvsBuilder(); parseTlvs(tlvsBuilder, bytes.slice()); builder.setTlvs(tlvsBuilder.build()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser.java
License:Open Source License
@Override public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException { Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final int versionValue = ByteArray.copyBitsRange(bytes.readByte(), VERSION_SF_OFFSET, VERSION_SF_LENGTH); final OpenBuilder builder = new OpenBuilder(); builder.setVersion(new ProtocolVersion((short) versionValue)); builder.setProcessingRule(header.isProcessingRule()); builder.setIgnore(header.isIgnore()); final short keepalive = bytes.readUnsignedByte(); builder.setKeepalive(keepalive);//from w ww . j a va2 s . c o m final short deadTimer = bytes.readUnsignedByte(); if (keepalive == 0) { builder.setDeadTimer((short) 0); } else { builder.setDeadTimer(deadTimer); } builder.setSessionId(bytes.readUnsignedByte()); final TlvsBuilder tbuilder = new TlvsBuilder(); parseTlvs(tbuilder, bytes.slice()); builder.setTlvs(tbuilder.build()); final Open obj = builder.build(); if (versionValue != PCEP_VERSION) { // TODO: Should we move this check into the negotiator LOG.debug("Unsupported PCEP version {}", versionValue); return new UnknownObject(PCEPErrors.PCEP_VERSION_NOT_SUPPORTED, obj); } return obj; }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser.java
License:Open Source License
@Override public Rro parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException { Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final RroBuilder builder = new RroBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); builder.setSubobject(parseSubobjects(bytes.slice())); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser.java
License:Open Source License
@Override public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException { Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE); final RpBuilder builder = new RpBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); short priority = 0; priority |= flags.get(PRI_SF_OFFSET + 2) ? 1 : 0; priority |= (flags.get(PRI_SF_OFFSET + 1) ? 1 : 0) << 1; priority |= (flags.get(PRI_SF_OFFSET) ? 1 : 0) << 2; if (priority != 0) { builder.setPriority(priority);//from www . j av a 2 s . com } builder.setFragmentation(flags.get(F_FLAG_OFFSET)); builder.setP2mp(flags.get(N_FLAG_OFFSET)); builder.setEroCompression(flags.get(E_FLAG_OFFSET)); builder.setMakeBeforeBreak(flags.get(M_FLAG_OFFSET)); builder.setOrder(flags.get(D_FLAG_OFFSET)); builder.setPathKey(flags.get(P_FLAG_OFFSET)); builder.setSupplyOf(flags.get(S_FLAG_OFFSET)); builder.setLoose(flags.get(O_FLAG_OFFSET)); builder.setBiDirectional(flags.get(B_FLAG_OFFSET)); builder.setReoptimization(flags.get(R_FLAG_OFFSET)); builder.setRequestId(new RequestId(bytes.readUnsignedInt())); final TlvsBuilder tlvsBuilder = new TlvsBuilder(); parseTlvs(tlvsBuilder, bytes.slice()); builder.setTlvs(tlvsBuilder.build()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPByteToMessageDecoder.java
License:Open Source License
private Message parse(final ByteBuf buffer, final List<Message> errors) throws PCEPDeserializerException { buffer.skipBytes(1);//from w w w. j a v a 2 s.co m final int type = buffer.readUnsignedByte(); final int msgLength = buffer.readUnsignedShort(); final int actualLength = buffer.readableBytes(); final ByteBuf msgBody = buffer.slice(); if (actualLength != msgLength - PCEPMessageConstants.COMMON_HEADER_LENGTH) { throw new PCEPDeserializerException("Body size " + actualLength + " does not match header size " + (msgLength - PCEPMessageConstants.COMMON_HEADER_LENGTH)); } buffer.skipBytes(actualLength); return this.registry.parseMessage(type, msgBody, errors); }
From source file:org.opendaylight.protocol.pcep.impl.subobject.EROLabelSubobjectParser.java
License:Open Source License
@Override public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() < HEADER_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" + HEADER_LENGTH + "."); }/* w ww. j a v a 2 s . c o m*/ final BitArray reserved = BitArray.valueOf(buffer, FLAGS_SIZE); final short cType = buffer.readUnsignedByte(); final LabelType labelType = this.registry.parseLabel(cType, buffer.slice()); if (labelType == null) { throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType); } final LabelBuilder builder = new LabelBuilder(); builder.setUniDirectional(reserved.get(U_FLAG_OFFSET)); builder.setLabelType(labelType); return new SubobjectBuilder().setLoose(loose) .setSubobjectType(new LabelCaseBuilder().setLabel(builder.build()).build()).build(); }
From source file:org.opendaylight.protocol.pcep.impl.subobject.RROLabelSubobjectParser.java
License:Open Source License
@Override public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() < HEADER_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >" + HEADER_LENGTH + "."); }// w ww.j a v a 2 s.c o m final BitArray reserved = BitArray.valueOf(buffer, FLAGS_SIZE); final short cType = buffer.readUnsignedByte(); final LabelType labelType = this.registry.parseLabel(cType, buffer.slice()); if (labelType == null) { throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType); } final LabelBuilder builder = new LabelBuilder(); builder.setUniDirectional(reserved.get(U_FLAG_OFFSET)); builder.setGlobal(reserved.get(G_FLAG_OFFSET)); builder.setLabelType(labelType); return new SubobjectBuilder().setSubobjectType(new LabelCaseBuilder().setLabel(builder.build()).build()) .build(); }
From source file:org.opendaylight.protocol.pcep.impl.tlv.AbstractVendorInformationTlvParser.java
License:Open Source License
@Override public final VendorInformationTlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException { if (buffer == null) { return null; }//from w w w . j a v a2 s .c o m final VendorInformationTlvBuilder viTlvBuider = new VendorInformationTlvBuilder(); viTlvBuider.setEnterpriseNumber(getEnterpriseNumber()); if (buffer.isReadable()) { final EnterpriseSpecificInformation esInformation = parseEnterpriseSpecificInformation(buffer.slice()); if (esInformation != null) { viTlvBuider.setEnterpriseSpecificInformation(esInformation); } } return viTlvBuider.build(); }
From source file:org.opendaylight.protocol.pcep.impl.tlv.AbstractVendorSpecificTlvParser.java
License:Open Source License
@Override public VsTlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException { if (buffer == null) { return null; }/*from ww w . java 2s . c o m*/ final VsTlvBuilder vsTlvBuider = new VsTlvBuilder(); final long en = buffer.readUnsignedInt(); if (en == getEnterpriseNumber()) { vsTlvBuider.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber())); VendorPayload vendorPayload = null; if (buffer.isReadable()) { final ByteBuf payloadBytes = buffer.slice(); vendorPayload = parseVendorPayload(payloadBytes); if (vendorPayload != null) { vsTlvBuider.setVendorPayload(vendorPayload); } } } return vsTlvBuider.build(); }
From source file:org.opendaylight.protocol.pcep.pcecc.PceccLabelObjectParser.java
License:Open Source License
@Override public Label parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException { Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (bytes.readableBytes() < MIN_SIZE) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: >=" + MIN_SIZE + "."); }/*from w w w. j a v a2 s . c om*/ final LabelBuilder builder = new LabelBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); bytes.skipBytes(RESERVED + SKIP_BYTE); byte outLabel = bytes.readByte(); if ((byte) (outLabel & OUT_LABEL_BYTE) == OUT_LABEL_BYTE) { builder.setOutLabel(true); } else { builder.setOutLabel(false); } ByteBuf lableBuff = bytes.readBytes((LABEL_SIZE + RESERVED_LABEL) / Byte.SIZE); builder.setLabelNum(new LabelNumber(lableBuff.readUnsignedInt() >> RESERVED_LABEL)); final TlvsBuilder tlvsBuilder = new TlvsBuilder(); ByteBuf tlvBytes = bytes.slice(); parseTlvs(tlvsBuilder, tlvBytes); builder.setTlvs(tlvsBuilder.build()); return builder.build(); }