public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, ObjectSerializer {
- private static final Logger logger = LoggerFactory.getLogger(AbstractEROWithSubobjectsParser.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractEROWithSubobjectsParser.class);
private static final int SUB_TYPE_FLAG_F_LENGTH = 1;
private static final int SUB_LENGTH_F_LENGTH = 1;
throw new IllegalArgumentException("Byte array is mandatory.");
}
- boolean loose_flag = false;
+ boolean loose = false;
int type;
byte[] soContentsBytes;
int length;
while (offset < bytes.length) {
- loose_flag = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
+ loose = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, SUB_LENGTH_F_LENGTH));
type = (bytes[offset + TYPE_FLAG_F_OFFSET] & 0xff) & ~(1 << 7);
soContentsBytes = new byte[length - SO_CONTENTS_OFFSET];
System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
- logger.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
- final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, loose_flag);
- logger.debug("Subobject was parsed. {}", sub);
+ LOG.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
+ final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, loose);
+ LOG.debug("Subobject was parsed. {}", sub);
subs.add(sub);
import com.google.common.base.Preconditions;
-public abstract class AbstractObjectWithTlvsParser<BUILDER> implements ObjectParser, ObjectSerializer {
+public abstract class AbstractObjectWithTlvsParser<T> implements ObjectParser, ObjectSerializer {
- private static final Logger logger = LoggerFactory.getLogger(AbstractObjectWithTlvsParser.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractObjectWithTlvsParser.class);
private static final int TLV_TYPE_F_LENGTH = 2;
private static final int TLV_LENGTH_F_LENGTH = 2;
this.tlvReg = Preconditions.checkNotNull(tlvReg);
}
- protected final void parseTlvs(final BUILDER builder, final byte[] bytes) throws PCEPDeserializerException {
+ protected final void parseTlvs(final T builder, final byte[] bytes) throws PCEPDeserializerException {
if (bytes == null) {
throw new IllegalArgumentException("Byte array is mandatory.");
}
final byte[] tlvBytes = ByteArray.subByte(bytes, byteOffset, length);
- logger.trace("Attempt to parse tlv from bytes: {}", ByteArray.bytesToHexString(tlvBytes));
+ LOG.trace("Attempt to parse tlv from bytes: {}", ByteArray.bytesToHexString(tlvBytes));
final Tlv tlv = this.tlvReg.getTlvParser(type).parseTlv(tlvBytes);
- logger.trace("Tlv was parsed. {}", tlv);
+ LOG.trace("Tlv was parsed. {}", tlv);
addTlv(builder, tlv);
int byteOffset = 0;
System.arraycopy(typeBytes, 0, bytes, byteOffset, TLV_TYPE_F_LENGTH);
- System.arraycopy(lengthBytes, 0, bytes, byteOffset += TLV_TYPE_F_LENGTH, TLV_LENGTH_F_LENGTH);
- System.arraycopy(valueBytes, 0, bytes, byteOffset += TLV_LENGTH_F_LENGTH, valueBytes.length);
+ byteOffset += TLV_TYPE_F_LENGTH;
+ System.arraycopy(lengthBytes, 0, bytes, byteOffset, TLV_LENGTH_F_LENGTH);
+ byteOffset += TLV_LENGTH_F_LENGTH;
+ System.arraycopy(valueBytes, 0, bytes, byteOffset, valueBytes.length);
return bytes;
}
- public abstract void addTlv(final BUILDER builder, final Tlv tlv);
+ public abstract void addTlv(final T builder, final Tlv tlv);
protected static int getPadding(final int length, final int padding) {
return (padding - (length % padding)) % padding;
public abstract class AbstractRROWithSubobjectsParser implements ObjectParser, ObjectSerializer {
- private static final Logger logger = LoggerFactory.getLogger(AbstractRROWithSubobjectsParser.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractRROWithSubobjectsParser.class);
private static final int SUB_TYPE_FLAG_F_LENGTH = 1;
private static final int SUB_LENGTH_F_LENGTH = 1;
soContentsBytes = new byte[length - SO_CONTENTS_OFFSET];
System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
- logger.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
+ LOG.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes);
- logger.debug("Subobject was parsed. {}", sub);
+ LOG.debug("Subobject was parsed. {}", sub);
subs.add(sub);
private static final int SET_PRIO_F_OFFSET = INC_ALL_F_OFFSET + INC_ALL_F_LENGTH;
private static final int HOLD_PRIO_F_OFFSET = SET_PRIO_F_OFFSET + SET_PRIO_F_LENGTH;
private static final int FLAGS_F_OFFSET = HOLD_PRIO_F_OFFSET + HOLD_PRIO_F_LENGTH;
- private static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1; // added reserved field of length 1B
+ private static final int TLVS_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH + 1;
public PCEPLspaObjectParser(final TlvHandlerRegistry tlvReg) {
super(tlvReg);
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder;
import com.google.common.collect.Lists;
+import com.google.common.primitives.UnsignedBytes;
public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
public static final int TYPE = 33;
- private static final int RESERVED = 2;
-
private static final int SUB_TYPE_FLAG_F_LENGTH = 1;
private static final int SUB_LENGTH_F_LENGTH = 1;
private static final int SUB_HEADER_LENGTH = SUB_TYPE_FLAG_F_LENGTH + SUB_LENGTH_F_LENGTH;
return subs;
}
- private final byte[] serializeSubobject(
+ private byte[] serializeSubobject(
final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> subobjects) {
final List<byte[]> result = Lists.newArrayList();
final XROSubobjectSerializer serializer = this.registry.getSubobjectSerializer(subobject.getSubobjectType());
- System.out.println(serializer);
-
final byte[] valueBytes = serializer.serializeSubobject(subobject);
final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isMandatory() ? 1 << 7
: 0));
- final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
+ final byte lengthBytes = UnsignedBytes.checkedCast(valueBytes.length);
bytes[0] = typeBytes;
bytes[1] = lengthBytes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
import com.google.common.base.Preconditions;
+import com.google.common.primitives.UnsignedBytes;
public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
}
final BitSet reserved = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, RES_F_OFFSET, RES_F_LENGTH));
- final short c_type = (short) (buffer[C_TYPE_F_OFFSET] & 0xFF);
+ final short cType = (short) UnsignedBytes.toInt(buffer[C_TYPE_F_OFFSET]);
- final LabelParser parser = this.registry.getLabelParser(c_type);
+ final LabelParser parser = this.registry.getLabelParser(cType);
if (parser == null) {
- throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + c_type);
+ throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
}
final LabelBuilder builder = new LabelBuilder();
builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
final BitSet reserved = new BitSet();
reserved.set(U_FLAG_OFFSET, label.isUniDirectional());
System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
- retBytes[C_TYPE_F_OFFSET] = (byte) serializer.getType();
+ retBytes[C_TYPE_F_OFFSET] = UnsignedBytes.checkedCast(serializer.getType());
return retBytes;
}
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeySubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
/**
- * Parser for {@link PathKeySubobject}
+ * Parser for {@link PathKey}
*/
public class EROPathKeySubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.LabelBuilder;
import com.google.common.base.Preconditions;
+import com.google.common.primitives.UnsignedBytes;
public class RROLabelSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
}
final BitSet reserved = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, RES_F_OFFSET, RES_F_LENGTH));
- final short c_type = (short) (buffer[C_TYPE_F_OFFSET] & 0xFF);
+ final short cType = (short) UnsignedBytes.toInt(buffer[C_TYPE_F_OFFSET]);
- final LabelParser parser = this.registry.getLabelParser(c_type);
+ final LabelParser parser = this.registry.getLabelParser(cType);
if (parser == null) {
- throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + c_type);
+ throw new PCEPDeserializerException("Unknown C-TYPE for ero label subobject. Passed: " + cType);
}
final LabelBuilder builder = new LabelBuilder();
builder.setUniDirectional(reserved.get(U_FLAG_OFFSET));
reserved.set(U_FLAG_OFFSET, label.isUniDirectional());
reserved.set(G_FLAG_OFFSET, label.isGlobal());
System.arraycopy(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH), 0, retBytes, RES_F_OFFSET, RES_F_LENGTH);
- retBytes[C_TYPE_F_OFFSET] = (byte) parser.getType();
+ retBytes[C_TYPE_F_OFFSET] = UnsignedBytes.checkedCast(parser.getType());
return retBytes;
}
import org.opendaylight.protocol.pcep.spi.TlvParser;
import org.opendaylight.protocol.pcep.spi.TlvSerializer;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.LspIdentifiers;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.LspIdentifiersBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
/**
- * Parser for {@link LspIdentifiersTlv}
+ * Parser for {@link LspIdentifiers}
*/
public class LSPIdentifierTlvParser implements TlvParser, TlvSerializer {