List of usage examples for io.netty.buffer ByteBuf getUnsignedByte
public abstract short getUnsignedByte(int index);
From source file:org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactory.java
License:Open Source License
/** * @param version// w w w. ja va 2s .c o m * @return */ public static CodeKeyMaker createMatchEntriesKeyMaker(short version) { return new AbstractCodeKeyMaker(version) { @Override public MessageCodeKey make(ByteBuf input) { int oxmClass = input.getUnsignedShort(input.readerIndex()); int oxmField = input .getUnsignedByte(input.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1; MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(getVersion(), oxmClass, oxmField); if (oxmClass == EncodeConstants.EXPERIMENTER_VALUE) { long expId = input.getUnsignedInt(input.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES + 2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES); key.setExperimenterId(expId); return key; } key.setExperimenterId(null); return key; } }; }
From source file:org.opendaylight.openflowjava.util.ByteBufUtils.java
License:Open Source License
/** * Converts ByteBuf into String//from w ww . jav a2 s .c om * @param bb input ByteBuf * @return String */ public static String byteBufToHexString(final ByteBuf bb) { StringBuilder sb = new StringBuilder(); for (int i = bb.readerIndex(); i < (bb.readerIndex() + bb.readableBytes()); i++) { sb.append(String.format(" %02x", bb.getUnsignedByte(i))); } return sb.toString().trim(); }
From source file:org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspObjectParser.java
License:Open Source License
@Override public Lsp 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 LspBuilder builder = new LspBuilder(); builder.setIgnore(header.isIgnore()); builder.setProcessingRule(header.isProcessingRule()); final int[] plspIdRaw = new int[] { bytes.readUnsignedByte(), bytes.readUnsignedByte(), bytes.getUnsignedByte(2), }; builder.setPlspId(new PlspId((long) ((plspIdRaw[0] << FLAGS_SIZE) | (plspIdRaw[1] << FOUR_BITS_SHIFT) | (plspIdRaw[2] >> FOUR_BITS_SHIFT)))); parseFlags(builder, bytes);/*from ww w .j a va2 s. co m*/ final TlvsBuilder b = new TlvsBuilder(); parseTlvs(b, bytes.slice()); builder.setTlvs(b.build()); return builder.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()); }// w w w . jav 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), 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.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()); }//from www .ja va2 s . com 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.subobject.EROIpv4PrefixSubobjectParser.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."); final SubobjectBuilder builder = new SubobjectBuilder(); builder.setLoose(loose);/*from w w w . ja v a 2 s .co m*/ 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()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.subobject.EROIpv6PrefixSubobjectParser.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."); final SubobjectBuilder builder = new SubobjectBuilder(); builder.setLoose(loose);//from w w w . ja v a2 s. c o m if (buffer.readableBytes() != CONTENT_LENGTH) { throw new PCEPDeserializerException( "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); } final int length = buffer.getUnsignedByte(PREFIX_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()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.subobject.RROIpv4PrefixSubobjectParser.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() != CONTENT4_LENGTH) { throw new PCEPDeserializerException( "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); }/*from w w w . ja v a 2 s. c o m*/ final SubobjectBuilder builder = new SubobjectBuilder(); final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefix prefix = new IpPrefixBuilder() .setIpPrefix(new IpPrefix( Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH), length))) .build(); buffer.skipBytes(PREFIX_F_LENGTH); final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); builder.setProtectionAvailable(flags.get(LPA_F_OFFSET)); builder.setProtectionInUse(flags.get(LPIU_F_OFFSET)); builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix).build()); return builder.build(); }
From source file:org.opendaylight.protocol.pcep.impl.subobject.RROIpv6PrefixSubobjectParser.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."); final SubobjectBuilder builder = new SubobjectBuilder(); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new PCEPDeserializerException( "Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); }//from w w w. j av a 2 s . c o m final int length = buffer.getUnsignedByte(PREFIX_F_OFFSET); final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix( new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH), length))); buffer.skipBytes(PREFIX_F_LENGTH); final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); builder.setProtectionAvailable(flags.get(LPA_F_OFFSET)); builder.setProtectionInUse(flags.get(LPIU_F_OFFSET)); builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build()); return builder.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. ja v a2 s . co m 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(); }