final BitSet reserved = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, RES_F_LENGTH));
final short cType = (short) UnsignedBytes.toInt(buffer.readByte());
- //FIXME: switch to ByteBuf
- final LabelType labelType = this.registry.parseLabel(cType, ByteArray.readAllBytes(buffer));
+ final LabelType labelType = this.registry.parseLabel(cType, buffer.slice());
if (labelType == null) {
throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
}
*/
package org.opendaylight.protocol.pcep.impl.subobject;
+import io.netty.buffer.ByteBuf;
+
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
import org.opendaylight.protocol.pcep.spi.LabelUtil;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.generalized.label._case.GeneralizedLabelBuilder;
+import com.google.common.base.Preconditions;
+
/**
* Parser for {@link GeneralizedLabelCase}
*/
public static final int CTYPE = 2;
@Override
- public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0) {
- throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- }
-
- return new GeneralizedLabelCaseBuilder().setGeneralizedLabel(new GeneralizedLabelBuilder().setGeneralizedLabel(buffer).build()).build();
+ public LabelType parseLabel(final ByteBuf buffer) throws PCEPDeserializerException {
+ Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
+ return new GeneralizedLabelCaseBuilder().setGeneralizedLabel(new GeneralizedLabelBuilder().setGeneralizedLabel(ByteArray.readAllBytes(buffer)).build()).build();
}
@Override
final short cType = (short) UnsignedBytes.toInt(buffer.readByte());
- //FIXME: switch to ByteBuf
- final LabelType labelType = this.registry.parseLabel(cType, ByteArray.readAllBytes(buffer));
+ final LabelType labelType = this.registry.parseLabel(cType, buffer.slice());
if (labelType == null) {
throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
}
*/
package org.opendaylight.protocol.pcep.impl.subobject;
+import io.netty.buffer.ByteBuf;
+
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
import org.opendaylight.protocol.pcep.spi.LabelUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.Type1LabelCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.type1.label._case.Type1LabelBuilder;
-import com.google.common.primitives.UnsignedInts;
+import com.google.common.base.Preconditions;
/**
* Parser for {@link Type1LabelCase}
public static final int LABEL_LENGTH = 4;
@Override
- public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0) {
- throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- }
- if (buffer.length != LABEL_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: " + LABEL_LENGTH
+ public LabelType parseLabel(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() != LABEL_LENGTH) {
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + LABEL_LENGTH
+ ".");
}
return new Type1LabelCaseBuilder().setType1Label(
- new Type1LabelBuilder().setType1Label(UnsignedInts.toLong(ByteArray.bytesToInt(buffer))).build()).build();
+ new Type1LabelBuilder().setType1Label(buffer.readUnsignedInt()).build()).build();
}
@Override
*/
package org.opendaylight.protocol.pcep.impl.subobject;
+import io.netty.buffer.ByteBuf;
+
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelSerializer;
import org.opendaylight.protocol.pcep.spi.LabelUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.waveband.switching.label._case.WavebandSwitchingLabelBuilder;
+import com.google.common.base.Preconditions;
+
/**
* Parser for {@link WavebandSwitchingLabelCase}
*/
private static final int CONTENT_LENGTH = WAVEB_F_LENGTH + START_F_LENGTH + END_F_LENGTH;
@Override
- public LabelType parseLabel(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0) {
- throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- }
- if (buffer.length != CONTENT_LENGTH) {
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
+ public LabelType parseLabel(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() != CONTENT_LENGTH) {
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: "
+ CONTENT_LENGTH + ".");
}
final WavebandSwitchingLabelBuilder builder = new WavebandSwitchingLabelBuilder();
- int byteOffset = 0;
- builder.setWavebandId(ByteArray.bytesToLong(ByteArray.subByte(buffer, byteOffset, WAVEB_F_LENGTH)));
- byteOffset += WAVEB_F_LENGTH;
- builder.setStartLabel(ByteArray.bytesToLong(ByteArray.subByte(buffer, byteOffset, START_F_LENGTH)));
- byteOffset += START_F_LENGTH;
- builder.setEndLabel(ByteArray.bytesToLong(ByteArray.subByte(buffer, byteOffset, END_F_LENGTH)));
+ builder.setWavebandId(buffer.readUnsignedInt());
+ builder.setStartLabel(buffer.readUnsignedInt());
+ builder.setEndLabel(buffer.readUnsignedInt());
return new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(builder.build()).build();
}
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import io.netty.buffer.Unpooled;
import org.junit.Test;
import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelParser;
final GeneralizedLabelBuilder iBuilder = new GeneralizedLabelBuilder();
iBuilder.setGeneralizedLabel(ByteArray.cutBytes(generalizedLabelBytes, 2));
final GeneralizedLabelCaseBuilder builder = new GeneralizedLabelCaseBuilder().setGeneralizedLabel(iBuilder.build());
- assertEquals(builder.build(), parser.parseLabel(ByteArray.cutBytes(generalizedLabelBytes, 2)));
+ assertEquals(builder.build(), parser.parseLabel(Unpooled.wrappedBuffer(ByteArray.cutBytes(generalizedLabelBytes, 2))));
assertArrayEquals(generalizedLabelBytes, parser.serializeLabel(true, false, builder.build()));
}
iBuilder.setStartLabel(0x9999L);
iBuilder.setEndLabel(0x1111L);
final WavebandSwitchingLabelCaseBuilder builder = new WavebandSwitchingLabelCaseBuilder().setWavebandSwitchingLabel(iBuilder.build());
- assertEquals(builder.build(), parser.parseLabel(ByteArray.cutBytes(wavebandLabelBytes, 2)));
+ assertEquals(builder.build(), parser.parseLabel(Unpooled.wrappedBuffer(ByteArray.cutBytes(wavebandLabelBytes, 2))));
assertArrayEquals(wavebandLabelBytes, parser.serializeLabel(false, true, builder.build()));
}
final Type1LabelBuilder iBuilder = new Type1LabelBuilder();
iBuilder.setType1Label(0x120025ffL);
final Type1LabelCaseBuilder builder = new Type1LabelCaseBuilder().setType1Label(iBuilder.build());
- assertEquals(builder.build(), parser.parseLabel(ByteArray.cutBytes(typeOneLabelBytes, 2)));
+ assertEquals(builder.build(), parser.parseLabel(Unpooled.wrappedBuffer(ByteArray.cutBytes(typeOneLabelBytes, 2))));
assertArrayEquals(typeOneLabelBytes, parser.serializeLabel(true, true, builder.build()));
}
}
*/
package org.opendaylight.protocol.pcep.spi;
+import io.netty.buffer.ByteBuf;
+
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
public interface LabelParser {
- LabelType parseLabel(byte[] buffer) throws PCEPDeserializerException;
+ LabelType parseLabel(final ByteBuf buffer) throws PCEPDeserializerException;
}
*/
package org.opendaylight.protocol.pcep.spi;
+import io.netty.buffer.ByteBuf;
+
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
public interface LabelRegistry {
/**
* Finds parser for given label C-type in the registry. Delegates parsing to found parser.
* @param cType label type, key in parser registry
- * @param buffer label raw binary value to be parsed
+ * @param buffer label wrapped in ByteBuf
* @return null if the parser for this label could not be found
* @throws PCEPDeserializerException if the parsing did not succeed
*/
- LabelType parseLabel(final int cType, final byte[] buffer) throws PCEPDeserializerException;
+ LabelType parseLabel(final int cType, final ByteBuf buffer) throws PCEPDeserializerException;
/**
* Find serializer for given label. Delegates parsing to found serializer.
*/
package org.opendaylight.protocol.pcep.spi.pojo;
+import io.netty.buffer.ByteBuf;
+
import org.opendaylight.protocol.concepts.HandlerRegistry;
import org.opendaylight.protocol.pcep.spi.LabelParser;
import org.opendaylight.protocol.pcep.spi.LabelRegistry;
}
@Override
- public LabelType parseLabel(int cType, byte[] buffer) throws PCEPDeserializerException {
+ public LabelType parseLabel(final int cType, final ByteBuf buffer) throws PCEPDeserializerException {
Preconditions.checkArgument(cType >= 0 && cType <= Values.UNSIGNED_BYTE_MAX_VALUE);
final LabelParser parser = this.handlers.getParser(cType);
if (parser == null) {