List of usage examples for io.netty.buffer ByteBuf readUnsignedInt
public abstract long readUnsignedInt();
From source file:org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser.java
License:Open Source License
protected final void parseTlvs(final T builder, final ByteBuf bytes) throws PCEPDeserializerException { Preconditions.checkArgument(bytes != null, "Array of bytes is mandatory. Can't be null."); if (!bytes.isReadable()) { return;/*from ww w . j a v a 2 s.c o m*/ } final List<VendorInformationTlv> viTlvs = Lists.newArrayList(); while (bytes.isReadable()) { final int type = bytes.readUnsignedShort(); final int length = bytes.readUnsignedShort(); if (length > bytes.readableBytes()) { throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= " + bytes.readableBytes() + "."); } final ByteBuf tlvBytes = bytes.readSlice(length); LOG.trace("Parsing PCEP TLV : {}", ByteBufUtil.hexDump(tlvBytes)); if (VendorInformationUtil.isVendorInformationTlv(type)) { final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(tlvBytes.readUnsignedInt()); final Optional<VendorInformationTlv> viTlv = this.viTlvReg .parseVendorInformationTlv(enterpriseNumber, tlvBytes); if (viTlv.isPresent()) { LOG.trace("Parsed VENDOR-INFORMATION TLV {}.", viTlv.get()); viTlvs.add(viTlv.get()); } } else { final Tlv tlv = this.tlvReg.parseTlv(type, tlvBytes); if (tlv != null) { LOG.trace("Parsed PCEP TLV {}.", tlv); addTlv(builder, tlv); } } bytes.skipBytes(TlvUtil.getPadding(TlvUtil.HEADER_SIZE + length, TlvUtil.PADDED_TO)); } addVendorInformationTlvs(builder, viTlvs); }
From source file:org.opendaylight.protocol.rsvp.parser.impl.subobject.label.Type1LabelParser.java
License:Open Source License
@Override public LabelType parseLabel(final ByteBuf buffer) throws RSVPParsingException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() != LABEL_LENGTH) { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + LABEL_LENGTH + "."); }/*www . java2s. c om*/ return new Type1LabelCaseBuilder() .setType1Label(new Type1LabelBuilder().setType1Label(buffer.readUnsignedInt()).build()).build(); }
From source file:org.opendaylight.protocol.rsvp.parser.impl.subobject.label.WavebandSwitchingLabelParser.java
License:Open Source License
@Override public final LabelType parseLabel(final ByteBuf buffer) throws RSVPParsingException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + "."); }/*from w w w. j a v a 2s . co m*/ final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder(); builder.setWavebandId(buffer.readUnsignedInt()); builder.setStartLabel(buffer.readUnsignedInt()); builder.setEndLabel(buffer.readUnsignedInt()); return new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(builder.build()).build(); }
From source file:org.opendaylight.protocol.rsvp.parser.impl.subobject.rro.RROUnnumberedInterfaceSubobjectParser.java
License:Open Source License
@Override public SubobjectContainer parseSubobject(final ByteBuf buffer) throws RSVPParsingException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + "."); }/*from w w w .j a va 2 s. c om*/ final SubobjectContainerBuilder builder = new SubobjectContainerBuilder(); final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); builder.setProtectionAvailable(flags.get(LPA_F_OFFSET)); builder.setProtectionInUse(flags.get(LPIU_F_OFFSET)); final UnnumberedBuilder ubuilder = new UnnumberedBuilder(); buffer.skipBytes(RESERVED); ubuilder.setRouterId(buffer.readUnsignedInt()); ubuilder.setInterfaceId(buffer.readUnsignedInt()); builder.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(ubuilder.build()).build()); return builder.build(); }
From source file:org.opendaylight.protocol.rsvp.parser.impl.subobject.xro.XROSRLGSubobjectParser.java
License:Open Source License
@Override public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws RSVPParsingException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + "."); }//from w w w. ja v a 2 s. c o m final SubobjectContainerBuilder builder = new SubobjectContainerBuilder(); builder.setMandatory(mandatory); builder.setSubobjectType(new SrlgCaseBuilder() .setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(buffer.readUnsignedInt())).build()).build()); buffer.readByte(); builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte())); return builder.build(); }
From source file:org.opendaylight.protocol.rsvp.parser.impl.te.FastRerouteObjectParser.java
License:Open Source License
@Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) { final BasicFastRerouteObjectBuilder builder = new BasicFastRerouteObjectBuilder(); builder.setSetupPriority(byteBuf.readUnsignedByte()); builder.setHoldPriority(byteBuf.readUnsignedByte()); builder.setHopLimit(byteBuf.readUnsignedByte()); builder.setFlags(FastRerouteFlags.forValue(byteBuf.readUnsignedByte())); final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH); builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))); builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); builder.setIncludeAll(new AttributeFilter(byteBuf.readUnsignedInt())); return builder.build(); }
From source file:org.opendaylight.protocol.rsvp.parser.impl.te.FlowSpecObjectParser.java
License:Open Source License
@Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException { final FlowSpecObjectBuilder builder = new FlowSpecObjectBuilder(); //skip version number, reserved, overall length byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH); builder.setServiceHeader(ServiceNumber.forValue(byteBuf.readUnsignedByte())); //skip reserved byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH); //skip Length of controlled-load data byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH); //skip parameter ID 127 and 127 flags byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH); final TspecObjectBuilder tBuilder = new TspecObjectBuilder(); tBuilder.setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); tBuilder.setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); tBuilder.setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); tBuilder.setMinimumPolicedUnit(byteBuf.readUnsignedInt()); tBuilder.setMaximumPacketSize(byteBuf.readUnsignedInt()); builder.setTspecObject(tBuilder.build()); if (builder.getServiceHeader().getIntValue() == 2) { //skip parameter ID 130, flags, lenght byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH); builder.setRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); builder.setSlackTerm(byteBuf.readUnsignedInt()); }/*from w w w. j a v a 2 s. c om*/ return builder.build(); }
From source file:org.opendaylight.protocol.rsvp.parser.impl.te.InformationalFastRerouteObjectParser.java
License:Open Source License
@Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException { final LegacyFastRerouteObjectBuilder builder = new LegacyFastRerouteObjectBuilder(); builder.setSetupPriority(byteBuf.readUnsignedByte()); builder.setHoldPriority(byteBuf.readUnsignedByte()); builder.setHopLimit(byteBuf.readUnsignedByte()); //skip reserved byteBuf.skipBytes(ByteBufWriteUtil.ONE_BYTE_LENGTH); final ByteBuf v = byteBuf.readSlice(METRIC_VALUE_F_LENGTH); builder.setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))); builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); return builder.build(); }
From source file:org.opendaylight.protocol.rsvp.parser.impl.te.SenderTspecObjectParser.java
License:Open Source License
@Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException { final TspecObjectBuilder builder = new TspecObjectBuilder(); //skip version number, reserved, Overall length byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH); //skip Service header, reserved, Length of service byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH); //skip Parameter ID, Parameter 127 flags, Parameter 127 length byteBuf.skipBytes(ByteBufWriteUtil.INT_BYTES_LENGTH); builder.setTokenBucketRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); builder.setTokenBucketSize(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); builder.setPeakDataRate(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH))); builder.setMinimumPolicedUnit(byteBuf.readUnsignedInt()); builder.setMaximumPacketSize(byteBuf.readUnsignedInt()); return builder.build(); }
From source file:org.opendaylight.protocol.rsvp.parser.impl.te.SessionAttributeLspRaObjectParser.java
License:Open Source License
@Override protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException { final SessionAttributeObjectWithResourcesAffinitiesBuilder builder = new SessionAttributeObjectWithResourcesAffinitiesBuilder(); builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt())); builder.setIncludeAll(new AttributeFilter(byteBuf.readUnsignedInt())); builder.setSetupPriority(byteBuf.readUnsignedByte()); builder.setHoldPriority(byteBuf.readUnsignedByte()); final BitArray bs = BitArray.valueOf(byteBuf.readByte()); builder.setLocalProtectionDesired(bs.get(SessionAttributeLspObjectParser.LOCAL_PROTECTION)); builder.setLabelRecordingDesired(bs.get(SessionAttributeLspObjectParser.LABEL_RECORDING)); builder.setSeStyleDesired(bs.get(SessionAttributeLspObjectParser.SE_STYLE)); final short nameLenght = byteBuf.readUnsignedByte(); final ByteBuf auxBuf = byteBuf.readSlice(nameLenght); final String name = new String(ByteArray.readAllBytes(auxBuf), StandardCharsets.US_ASCII); builder.setSessionName(name);/*from w ww .j a va2s .com*/ return builder.build(); }