X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fimpl%2FPCEPMessageFactory.java;h=627b1673602c291a128cd1bf338f2ce4a8bfaae3;hb=3307057347e7e3f7a5089f56f4c29e0e24c1d5ae;hp=1bc18098700dd544dcfed15f98e7f9deb9e4cdaf;hpb=5e46c45d236f1eb8c075aabd41b3b6bd11b996cc;p=bgpcep.git diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java index 1bc1809870..627b167360 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java @@ -10,11 +10,13 @@ package org.opendaylight.protocol.pcep.impl; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import java.util.ArrayList; +import java.util.List; + import org.opendaylight.protocol.framework.DeserializerException; import org.opendaylight.protocol.framework.DocumentedException; import org.opendaylight.protocol.framework.ProtocolMessageFactory; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.PCEPDocumentedException; import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry; import org.opendaylight.protocol.pcep.spi.MessageSerializer; import org.opendaylight.protocol.util.ByteArray; @@ -77,17 +79,20 @@ public final class PCEPMessageFactory implements ProtocolMessageFactory + (msgLength - COMMON_HEADER_LENGTH)); } + final List errors = new ArrayList<>(); Message msg = null; try { - msg = this.registry.getMessageParser(type).parseMessage(msgBody); + msg = this.registry.getMessageParser(type).parseMessage(msgBody, errors); } catch (final PCEPDeserializerException e) { logger.debug("Unexpected deserializer problem", e); throw new DeserializerException(e.getMessage(), e); - } catch (final PCEPDocumentedException e) { - logger.debug("Documented deserializer problem", e); - throw new DocumentedException(e.getMessage(), e); } + + if (!errors.isEmpty()) { + // FIXME: we have a bunch of error messages, how can we send them back? + } + logger.debug("Message was parsed. {}", msg); return msg; } @@ -104,7 +109,9 @@ public final class PCEPMessageFactory implements ProtocolMessageFactory serializer.serializeMessage(msg, buf); - final byte[] msgBody = buf.array(); + final byte[] msgBody = new byte[buf.readableBytes()]; + + buf.getBytes(0, msgBody); final byte[] headerBytes = new byte[COMMON_HEADER_LENGTH]; @@ -115,13 +122,13 @@ public final class PCEPMessageFactory implements ProtocolMessageFactory headerBytes[TYPE_F_OFFSET] = (byte) serializer.getMessageType(); // msgLength - System.arraycopy(ByteArray.intToBytes(msgBody.length), Integer.SIZE / Byte.SIZE - LENGTH_F_LENGTH, headerBytes, LENGTH_F_OFFSET, - LENGTH_F_LENGTH); + System.arraycopy(ByteArray.intToBytes(msgBody.length + COMMON_HEADER_LENGTH), Integer.SIZE / Byte.SIZE - LENGTH_F_LENGTH, + headerBytes, LENGTH_F_OFFSET, LENGTH_F_LENGTH); final byte[] retBytes = new byte[headerBytes.length + msgBody.length]; ByteArray.copyWhole(headerBytes, retBytes, 0); - ByteArray.copyWhole(msgBody, retBytes, PCEPMessageHeader.COMMON_HEADER_LENGTH); + ByteArray.copyWhole(msgBody, retBytes, COMMON_HEADER_LENGTH); return retBytes; }