List of usage examples for io.netty.buffer ByteBuf readUnsignedByte
public abstract short readUnsignedByte();
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser.java
License:Open Source License
@Override public NoPath 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 NoPathBuilder builder = new NoPathBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); builder.setNatureOfIssue(bytes.readUnsignedByte()); final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE); builder.setUnsatisfiedConstraints(flags.get(C_FLAG_OFFSET)); bytes.skipBytes(RESERVED_F_LENGTH);// w w w.j a va 2s . 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.PCEPNotificationObjectParser.java
License:Open Source License
@Override public CNotification 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 CNotificationBuilder builder = new CNotificationBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); bytes.skipBytes(NT_F_OFFSET);//w w w . ja v a2 s .c o m builder.setType(bytes.readUnsignedByte()); builder.setValue(bytes.readUnsignedByte()); parseTlvs(builder, bytes.slice()); 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 w w. ja v a2s.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.PCEPByteToMessageDecoder.java
License:Open Source License
private Message parse(final ByteBuf buffer, final List<Message> errors) throws PCEPDeserializerException { buffer.skipBytes(1);//ww w . j av a2 s. c o 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.EROExplicitExclusionRouteSubobjectParser.java
License:Open Source License
private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject> parseSubobject( final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject> subs = new ArrayList<>(); while (buffer.isReadable()) { final boolean mandatory = ((buffer.getByte(buffer.readerIndex()) & (1 << Values.FIRST_BIT_OFFSET)) != 0) ? true/* www .ja v a2s. c om*/ : 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()); } subs.add(this.registry.parseSubobject(type, buffer.readSlice(length), mandatory)); } return subs; }
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 + "."); }/*from ww w .j a v a2s . 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 ava2 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.subobject.XROIpv4PrefixSubobjectParser.java
License:Open Source License
@Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final SubobjectBuilder builder = new SubobjectBuilder(); builder.setMandatory(mandatory);/*w ww .j av a2 s . com*/ if (buffer.readableBytes() != CONTENT4_LENGTH) { throw new PCEPDeserializerException( "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); } final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET); final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix( new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH), length))); builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build()); buffer.skipBytes(PREFIX_F_LENGTH); builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte())); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.subobject.XROIpv6PrefixSubobjectParser.java
License:Open Source License
@Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final SubobjectBuilder builder = new SubobjectBuilder(); builder.setMandatory(mandatory);/*from w ww .j a va 2s . c om*/ if (buffer.readableBytes() != CONTENT6_LENGTH) { throw new PCEPDeserializerException( "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); } final int length = buffer.getUnsignedByte(PREFIX6_F_OFFSET); final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix( new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH), length))); builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build()); buffer.skipBytes(PREFIX_F_LENGTH); builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte())); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser.java
License:Open Source License
@Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + "."); }/*from w ww . ja v a2 s .c o m*/ final SubobjectBuilder builder = new SubobjectBuilder(); 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(); }