List of usage examples for io.netty.buffer ByteBuf readUnsignedByte
public abstract short readUnsignedByte();
From source file:org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07RSVPErrorSpecTlvParser.java
License:Open Source License
private RsvpCase parseRsvp(final int classType, final ByteBuf buffer) { final RsvpErrorBuilder builder = new RsvpErrorBuilder(); if (classType == RSVP_IPV4_ERROR_CLASS_TYPE) { builder.setNode(new IpAddress(Ipv4Util.addressForByteBuf(buffer))); } else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) { builder.setNode(new IpAddress(Ipv6Util.addressForByteBuf(buffer))); }/*from w w w . j ava 2s .c o m*/ final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); builder.setFlags(new Flags(flags.get(IN_PLACE), flags.get(NOT_GUILTY))); final short errorCode = buffer.readUnsignedByte(); builder.setCode(errorCode); final int errorValue = buffer.readUnsignedShort(); builder.setValue(errorValue); return new RsvpCaseBuilder().setRsvpError(builder.build()).build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.AbstractEROWithSubobjectsParser.java
License:Open Source License
protected List<Subobject> parseSubobjects(final ByteBuf buffer) throws PCEPDeserializerException { // Explicit approval of empty ERO Preconditions.checkArgument(buffer != null, "Array of bytes is mandatory. Can't be null."); final List<Subobject> subs = new ArrayList<>(); while (buffer.isReadable()) { final boolean loose = ((buffer.getUnsignedByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false; final int type = (buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET); final int length = buffer.readUnsignedByte() - HEADER_LENGTH; if (length > buffer.readableBytes()) { throw new PCEPDeserializerException( "Wrong length specified. Passed: " + length + "; Expected: <= " + buffer.readableBytes()); }/*from w w w.ja va 2 s. c o m*/ LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer)); final Subobject sub = this.subobjReg.parseSubobject(type, buffer.readSlice(length), loose); if (sub == null) { LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type); } else { LOG.debug("Subobject was parsed. {}", sub); subs.add(sub); } } return subs; }
From source file:org.opendaylight.protocol.pcep.impl.object.AbstractRROWithSubobjectsParser.java
License:Open Source License
protected List<Subobject> parseSubobjects(final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final List<Subobject> subs = new ArrayList<>(); while (buffer.isReadable()) { final int type = buffer.readUnsignedByte(); final int length = buffer.readUnsignedByte() - HEADER_LENGTH; if (length > buffer.readableBytes()) { throw new PCEPDeserializerException( "Wrong length specified. Passed: " + length + "; Expected: <= " + buffer.readableBytes()); }//from ww w . ja v a 2 s.c o m LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer)); final Subobject sub = this.subobjReg.parseSubobject(type, buffer.readSlice(length)); if (sub == null) { LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type); } else { LOG.debug("Subobject was parsed. {}", sub); subs.add(sub); } } return subs; }
From source file:org.opendaylight.protocol.pcep.impl.object.AbstractXROWithSubobjectsParser.java
License:Open Source License
protected List<Subobject> parseSubobjects(final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final List<Subobject> subs = new ArrayList<>(); while (buffer.isReadable()) { final boolean mandatory = ((buffer.getUnsignedByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true : false; final int type = UnsignedBytes.checkedCast( (buffer.readUnsignedByte() & Values.BYTE_MAX_VALUE_BYTES) & ~(1 << Values.FIRST_BIT_OFFSET)); final int length = buffer.readUnsignedByte() - HEADER_LENGTH; if (length > buffer.readableBytes()) { throw new PCEPDeserializerException( "Wrong length specified. Passed: " + length + "; Expected: <= " + buffer.readableBytes()); }// w w w . j a va 2s . c o m LOG.debug("Attempt to parse subobject from bytes: {}", ByteBufUtil.hexDump(buffer)); final Subobject sub = this.subobjReg.parseSubobject(type, buffer.readSlice(length), mandatory); if (sub == null) { LOG.warn("Unknown subobject type: {}. Ignoring subobject.", type); } else { LOG.debug("Subobject was parsed. {}", sub); subs.add(sub); } } return subs; }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser.java
License:Open Source License
@Override public CClose 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 CCloseBuilder builder = new CCloseBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); bytes.skipBytes(FLAGS_F_LENGTH + RESERVED); builder.setReason(bytes.readUnsignedByte()); 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.PCEPErrorObjectParser.java
License:Open Source License
@Override public ErrorObject 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 ErrorObjectBuilder builder = new ErrorObjectBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); bytes.skipBytes(FLAGS_F_LENGTH + RESERVED); builder.setType(bytes.readUnsignedByte()); builder.setValue(bytes.readUnsignedByte()); parseTlvs(builder, bytes.slice());//www . ja va2 s . c om return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser.java
License:Open Source License
@Override public Gc 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 GcBuilder builder = new GcBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); builder.setMaxHop(bytes.readUnsignedByte()); builder.setMaxUtilization(bytes.readUnsignedByte()); builder.setMinUtilization(bytes.readUnsignedByte()); builder.setOverBookingFactor(bytes.readUnsignedByte()); 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.PCEPLoadBalancingObjectParser.java
License:Open Source License
@Override public LoadBalancing 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() != SIZE) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: " + SIZE + "."); }/*from w ww. j a va2s . c o m*/ final LoadBalancingBuilder builder = new LoadBalancingBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); bytes.skipBytes(RESERVED + FLAGS_F_LENGTH); builder.setMaxLsp(bytes.readUnsignedByte()); builder.setMinBandwidth(new Bandwidth(ByteArray.readAllBytes(bytes))); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser.java
License:Open Source License
@Override public Lspa 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 LspaBuilder builder = new LspaBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); builder.setExcludeAny(new AttributeFilter(bytes.readUnsignedInt())); builder.setIncludeAll(new AttributeFilter(bytes.readUnsignedInt())); builder.setIncludeAny(new AttributeFilter(bytes.readUnsignedInt())); builder.setSetupPriority(bytes.readUnsignedByte()); builder.setHoldPriority(bytes.readUnsignedByte()); final BitArray flags = BitArray.valueOf(bytes.readByte()); builder.setLocalProtectionDesired(flags.get(L_FLAG_OFFSET)); final TlvsBuilder tbuilder = new TlvsBuilder(); bytes.skipBytes(RESERVED);//from w w w .ja va 2s .c om parseTlvs(tbuilder, bytes.slice()); builder.setTlvs(tbuilder.build()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser.java
License:Open Source License
@Override public Metric 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() != SIZE) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: " + SIZE + "."); }/*from ww w . j av a2s . com*/ bytes.skipBytes(RESERVED); final BitArray flags = BitArray.valueOf(bytes.readByte()); final MetricBuilder builder = new MetricBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); builder.setBound(flags.get(B_FLAG_OFFSET)); builder.setComputed(flags.get(C_FLAG_OFFSET)); builder.setMetricType(bytes.readUnsignedByte()); builder.setValue(new Float32(ByteArray.readBytes(bytes, METRIC_VALUE_F_LENGTH))); return builder.build(); }