*/
package org.opendaylight.protocol.pcep.impl.subobject;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Prefix;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import java.util.BitSet;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
import org.opendaylight.protocol.pcep.spi.RROSubobjectUtil;
+import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
public static final int TYPE = 1;
private static final int PREFIX_F_LENGTH = 1;
- private static final int FLAGS_F_LENGTH = 1;
+ private static final int FLAGS_SIZE = 8;
private static final int PREFIX4_F_OFFSET = 0 + Ipv4Util.IP4_LENGTH;
- private static final int CONTENT4_LENGTH = Ipv4Util.IP4_LENGTH + PREFIX_F_LENGTH + FLAGS_F_LENGTH;
+ private static final int CONTENT4_LENGTH = Ipv4Util.IP4_LENGTH + PREFIX_F_LENGTH + FLAGS_SIZE / Byte.SIZE;
private static final int LPA_F_OFFSET = 7;
private static final int LPIU_F_OFFSET = 6;
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.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 BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_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());
if (prefix.getIpv6Prefix() != null) {
new RROIpv6PrefixSubobjectParser().serializeSubobject(subobject, buffer);
} else {
- final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
- if (subobject.isProtectionAvailable() != null) {
- flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
- }
- if (subobject.isProtectionInUse() != null) {
- flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
- }
+ final BitArray flags = new BitArray(FLAGS_SIZE);
+ flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
+ flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
final ByteBuf body = Unpooled.buffer(CONTENT4_LENGTH);
Preconditions.checkArgument(prefix.getIpv4Prefix() != null, "Ipv4Prefix is mandatory.");
writeIpv4Prefix(prefix.getIpv4Prefix(), body);
- writeBitSet(flags, FLAGS_F_LENGTH, body);
+ flags.toByteBuf(body);
RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
}