List of usage examples for io.netty.buffer ByteBufUtil hexDump
public static String hexDump(byte[] array)
From source file:org.opendaylight.protocol.bmp.impl.BmpByteToMessageDecoder.java
License:Open Source License
@Override protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws BmpDeserializationException { if (in.isReadable()) { LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); out.add(this.registry.parseMessage(in)); } else {/*from w ww . j av a 2 s . c o m*/ LOG.trace("No more content in incoming buffer."); } }
From source file:org.opendaylight.protocol.bmp.spi.parser.AbstractBmpMessageParser.java
License:Open Source License
@Override public final void serializeMessage(final Notification message, final ByteBuf buffer) { Preconditions.checkArgument(message != null, "BMP message is mandatory."); final ByteBuf bodyBuffer = Unpooled.buffer(); serializeMessageBody(message, bodyBuffer); formatMessage(bodyBuffer, buffer);//from w w w . j a v a2 s . c om LOG.trace("Serialized BMP message: {}", ByteBufUtil.hexDump(buffer)); }
From source file:org.opendaylight.protocol.bmp.spi.parser.AbstractBmpMessageWithTlvParser.java
License:Open Source License
protected final void parseTlvs(final T builder, final ByteBuf bytes) throws BmpDeserializationException { Preconditions.checkArgument(bytes != null, "Array of bytes is mandatory. Can't be null."); if (!bytes.isReadable()) { return;//from w w w .j a v a 2s . c om } while (bytes.isReadable()) { final int type = bytes.readUnsignedShort(); final int length = bytes.readUnsignedShort(); if (length > bytes.readableBytes()) { throw new BmpDeserializationException("Wrong length specified. Passed: " + length + "; Expected: <= " + bytes.readableBytes() + "."); } final ByteBuf tlvBytes = bytes.readSlice(length); LOG.trace("Parsing BMP TLV : {}", ByteBufUtil.hexDump(tlvBytes)); final Tlv tlv = this.tlvRegistry.parseTlv(type, tlvBytes); if (tlv != null) { LOG.trace("Parsed BMP TLV {}.", tlv); addTlv(builder, tlv); } } }
From source file:org.opendaylight.protocol.bmp.spi.parser.AbstractBmpMessageWithTlvParser.java
License:Open Source License
protected final void serializeTlv(final Tlv tlv, final ByteBuf buffer) { Preconditions.checkNotNull(tlv, "BMP TLV is mandatory."); LOG.trace("Serializing BMP TLV {}", tlv); this.tlvRegistry.serializeTlv(tlv, buffer); LOG.trace("Serialized BMP TLV : {}.", ByteBufUtil.hexDump(buffer)); }
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 www .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), 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 w w w.jav a 2 s. c om*/ 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()); }//from w w w . ja v a 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.PCEPByteToMessageDecoder.java
License:Open Source License
@Override protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) { if (!in.isReadable()) { LOG.debug("No more content in incoming buffer."); return;/*from w ww .j av a 2 s.co m*/ } in.markReaderIndex(); LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in)); final List<Message> errors = new ArrayList<>(); try { out.add(parse(in, errors)); } catch (final PCEPDeserializerException e) { LOG.debug("Failed to decode protocol message", e); } in.discardReadBytes(); if (!errors.isEmpty()) { // We have a bunch of messages, send them out for (final Object e : errors) { ctx.channel().writeAndFlush(e).addListener(new ChannelFutureListener() { @Override public void operationComplete(final ChannelFuture f) { if (!f.isSuccess()) { LOG.warn("Failed to send message {} to socket {}", e, ctx.channel(), f.cause()); } else { LOG.trace("Message {} sent to socket {}", e, ctx.channel()); } } }); } } }
From source file:org.opendaylight.protocol.pcep.impl.PCEPMessageToByteEncoder.java
License:Open Source License
@Override protected void encode(final ChannelHandlerContext ctx, final Message msg, final ByteBuf out) { Preconditions.checkNotNull(msg);/*from w ww . j a v a 2 s. c o m*/ this.registry.serializeMessage(msg, out); if (LOG.isTraceEnabled()) { LOG.trace("Encoded : {}", ByteBufUtil.hexDump(out)); } }
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 w ww.j a v a 2s . c om } 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); }