BUG-2794 : refactored code to use BitArray 93/15793/8
authorLadislav Borak <lborak@cisco.com>
Mon, 2 Mar 2015 12:46:07 +0000 (13:46 +0100)
committerLadislav Borak <lborak@cisco.com>
Tue, 3 Mar 2015 08:13:02 +0000 (09:13 +0100)
Change-Id: I8906ec2b9671cd71916f0e3c4225199cf5963bdc
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
Signed-off-by: Ladislav Borak <lborak@cisco.com>
37 files changed:
bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSExtendedCommunitiesAttributeParser.java
bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSNlriParser.java
bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FSNlriParserTest.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/LinkAttributesParser.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/NodeAttributesParser.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/PrefixAttributesParser.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/SrLinkAttributesParser.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/SrNodeAttributesParser.java
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/attribute/sr/SrPrefixAttributesParser.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/pojo/SimpleAttributeRegistry.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CInitiated00LspObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CInitiated00SrpObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/initiated00/CInitiated00StatefulCapabilityTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LspObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07RSVPErrorSpecTlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07SrpObjectParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07StatefulCapabilityTlvParser.java
pcep/ietf-stateful07/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPObjectParserTest.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMonitoringObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPProcTimeObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestParameterObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROLabelSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROIpv4PrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROIpv6PrefixSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROLabelSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/RROUnnumberedInterfaceSubobjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrEroSubobjectParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrRroSubobjectParser.java
pcep/segment-routing/src/main/java/org/opendaylight/protocol/pcep/segment/routing/SrSubobjectParserUtil.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/AbstractMessageParser.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/LabelUtil.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/ObjectUtil.java

index d62d3f99c3dd270484708cb80f2840afa477d16d..613f6079429785aad003e2eb1d0a411a457e9100 100644 (file)
@@ -8,10 +8,10 @@
 package org.opendaylight.protocol.bgp.flowspec;
 
 import io.netty.buffer.ByteBuf;
-import java.util.BitSet;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.ExtendedCommunitiesAttributeParser;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.ReferenceCache;
@@ -58,7 +58,7 @@ public class FSExtendedCommunitiesAttributeParser extends ExtendedCommunitiesAtt
 
     private static final int RESERVED = 5;
 
-    private static final int FLAGS_SIZE = 1;
+    private static final int FLAGS_SIZE = 8;
 
     private static final int SAMPLE_BIT = 6;
 
@@ -80,7 +80,7 @@ public class FSExtendedCommunitiesAttributeParser extends ExtendedCommunitiesAtt
                 break;
             case TRAFFIC_ACTION_SUBTYPE:
                 buffer.skipBytes(RESERVED);
-                final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_SIZE));
+                final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
                 final boolean sample = flags.get(SAMPLE_BIT);
                 final boolean terminal = flags.get(TERMINAL_BIT);
                 c = new TrafficActionExtendedCommunityCaseBuilder().setTrafficActionExtendedCommunity(new TrafficActionExtendedCommunityBuilder().setSample(sample).setTerminalAction(terminal).build()).build();
@@ -117,14 +117,10 @@ public class FSExtendedCommunitiesAttributeParser extends ExtendedCommunitiesAtt
         else if (ex instanceof TrafficActionExtendedCommunityCase) {
             final TrafficActionExtendedCommunity trafficAction = ((TrafficActionExtendedCommunityCase) ex).getTrafficActionExtendedCommunity();
             buffer.writeZero(RESERVED);
-            final BitSet flags = new BitSet(FLAGS_SIZE);
-            if (trafficAction.isSample() != null) {
-                flags.set(SAMPLE_BIT, trafficAction.isSample());
-            }
-            if (trafficAction.isTerminalAction() != null) {
-                flags.set(TERMINAL_BIT, trafficAction.isTerminalAction());
-            }
-            ByteBufWriteUtil.writeBitSet(flags, FLAGS_SIZE, buffer);
+            final BitArray flags = new BitArray(FLAGS_SIZE);
+            flags.set(SAMPLE_BIT, trafficAction.isSample());
+            flags.set(TERMINAL_BIT, trafficAction.isTerminalAction());
+            flags.toByteBuf(buffer);
         }
         else if (ex instanceof RedirectExtendedCommunityCase) {
             final RedirectExtendedCommunity redirect = ((RedirectExtendedCommunityCase) ex).getRedirectExtendedCommunity();
index 4f5c372334b988394be89a2ed2148d3a366c16cf..3910e4364e0a860ca5eedb8d85a6d6fc11bdce43 100644 (file)
@@ -14,11 +14,11 @@ import com.google.common.primitives.UnsignedInts;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
-import java.util.BitSet;
 import java.util.List;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
@@ -101,21 +101,23 @@ public class FSNlriParser implements NlriParser, NlriSerializer {
      */
     private static final int LENGTH_MAGIC = 61440;
 
-    private static final int END_OF_LIST = 7;
-    private static final int AND_BIT = 6;
+    private static final int OPERAND_LENGTH = 8;
+
+    private static final int END_OF_LIST = 0;
+    private static final int AND_BIT = 1;
     private static final int LENGTH_BITMASK = 48;
     private static final int LENGTH_SHIFT = 4;
-    private static final int LESS_THAN = 2;
-    private static final int GREATER_THAN = 1;
-    private static final int EQUAL = 0;
+    private static final int LESS_THAN = 5;
+    private static final int GREATER_THAN = 6;
+    private static final int EQUAL = 7;
 
-    private static final int NOT = 1;
-    private static final int MATCH = 0;
+    private static final int NOT = 6;
+    private static final int MATCH = 7;
 
-    private static final int LAST_FRAGMENT = 7;
-    private static final int FIRST_FRAGMENT = 6;
-    private static final int IS_A_FRAGMENT = 5;
-    private static final int DONT_FRAGMENT = 4;
+    private static final int LAST_FRAGMENT = 4;
+    private static final int FIRST_FRAGMENT = 5;
+    private static final int IS_A_FRAGMENT = 6;
+    private static final int DONT_FRAGMENT = 7;
 
     private static final int MAX_NLRI_LENGTH = 4095;
     private static final int MAX_NLRI_LENGTH_ONE_BYTE = 240;
@@ -269,42 +271,24 @@ public class FSNlriParser implements NlriParser, NlriSerializer {
     }
 
     private static void serializeNumericOperand(final NumericOperand op, final int length, final ByteBuf buffer) {
-        final BitSet bs = new BitSet(Byte.SIZE);
-        if (op.isEndOfList() != null) {
-            bs.set(END_OF_LIST, op.isEndOfList());
-        }
-        if (op.isAndBit() != null) {
-            bs.set(AND_BIT, op.isAndBit());
-        }
-        if (op.isLessThan() != null) {
-            bs.set(LESS_THAN, op.isLessThan());
-        }
-        if (op.isGreaterThan() != null) {
-            bs.set(GREATER_THAN, op.isGreaterThan());
-        }
-        if (op.isEquals() != null) {
-            bs.set(EQUAL, op.isEquals());
-        }
+        final BitArray bs = new BitArray(OPERAND_LENGTH);
+        bs.set(END_OF_LIST, op.isEndOfList());
+        bs.set(AND_BIT, op.isAndBit());
+        bs.set(LESS_THAN, op.isLessThan());
+        bs.set(GREATER_THAN, op.isGreaterThan());
+        bs.set(EQUAL, op.isEquals());
         final byte len = (byte) (Integer.numberOfTrailingZeros(length) << LENGTH_SHIFT);
-        buffer.writeByte(bs.toByteArray()[0] | len);
+        buffer.writeByte(bs.toByte() | len);
     }
 
     private static void serializeBitmaskOperand(final BitmaskOperand op, final int length, final ByteBuf buffer) {
-        final BitSet bs = new BitSet(Byte.SIZE);
-        if (op.isEndOfList() != null) {
-            bs.set(END_OF_LIST, op.isEndOfList());
-        }
-        if (op.isAndBit() != null) {
-            bs.set(AND_BIT, op.isAndBit());
-        }
-        if (op.isMatch() != null) {
-            bs.set(MATCH, op.isMatch());
-        }
-        if (op.isNot() != null) {
-            bs.set(NOT, op.isNot());
-        }
+        final BitArray bs = new BitArray(OPERAND_LENGTH);
+        bs.set(END_OF_LIST, op.isEndOfList());
+        bs.set(AND_BIT, op.isAndBit());
+        bs.set(MATCH, op.isMatch());
+        bs.set(NOT, op.isNot());
         final byte len = (byte) (Integer.numberOfTrailingZeros(length) << LENGTH_SHIFT);
-        buffer.writeByte(bs.toByteArray()[0] | len);
+        buffer.writeByte(bs.toByte() | len);
     }
 
     @Override
@@ -562,12 +546,12 @@ public class FSNlriParser implements NlriParser, NlriSerializer {
     }
 
     private static NumericOperand parseNumeric(final byte op) {
-        final BitSet bs = BitSet.valueOf(new long[] {UnsignedBytes.toInt(op)});
+        final BitArray bs = BitArray.valueOf(op);
         return new NumericOperand(bs.get(AND_BIT), bs.get(END_OF_LIST), bs.get(EQUAL), bs.get(GREATER_THAN), bs.get(LESS_THAN));
     }
 
     private static BitmaskOperand parseBitmask(final byte op) {
-        final BitSet bs = BitSet.valueOf(new long[] {UnsignedBytes.toInt(op)});
+        final BitArray bs = BitArray.valueOf(op);
         return new BitmaskOperand(bs.get(AND_BIT), bs.get(END_OF_LIST), bs.get(MATCH), bs.get(NOT));
     }
 
@@ -577,24 +561,16 @@ public class FSNlriParser implements NlriParser, NlriSerializer {
     }
 
     private static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Fragment parseFragment(final byte fragment) {
-        final BitSet bs = BitSet.valueOf(new long[] {UnsignedBytes.toInt(fragment)});
+        final BitArray bs = BitArray.valueOf(fragment);
         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Fragment(bs.get(DONT_FRAGMENT), bs.get(FIRST_FRAGMENT), bs.get(IS_A_FRAGMENT), bs.get(LAST_FRAGMENT));
     }
 
     private static byte serializeFragment(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Fragment fragment) {
-        final BitSet bs = new BitSet(Byte.SIZE);
-        if (fragment.isDoNot() != null) {
-            bs.set(DONT_FRAGMENT, fragment.isDoNot());
-        }
-        if (fragment.isFirst() != null) {
-            bs.set(FIRST_FRAGMENT, fragment.isFirst());
-        }
-        if (fragment.isIsA() != null) {
-            bs.set(IS_A_FRAGMENT, fragment.isIsA());
-        }
-        if (fragment.isLast() != null) {
-            bs.set(LAST_FRAGMENT, fragment.isLast());
-        }
-        return bs.toByteArray()[0];
+        final BitArray bs = new BitArray(Byte.SIZE);
+        bs.set(DONT_FRAGMENT, fragment.isDoNot());
+        bs.set(FIRST_FRAGMENT, fragment.isFirst());
+        bs.set(IS_A_FRAGMENT, fragment.isIsA());
+        bs.set(LAST_FRAGMENT, fragment.isLast());
+        return bs.toByte();
     }
 }
index fb7e7e9c26cf2a909436b5c19146962b30a123ac..56f6390a25571f5aab372e8be185e20ba28b3c30 100644 (file)
@@ -95,7 +95,7 @@ public class FSNlriParserTest {
         0x09, 0x12, 04, 01, (byte)0x91, 0x56, (byte) 0xb1,
         0x0a, (byte)0x96, (byte) 0xde, (byte) 0xad,
         0x0b, (byte)0x86, 0x2a,
-        0x0c, (byte)0x81, (byte)0xf0};
+        0x0c, (byte)0x81, (byte)0x0f};
 
     @Test
     public void testParseLength() {
index e10b832b93da413e1b40bc0b63a35b506962b67b..04eb63de455df428769940a040c23458a7c03781 100644 (file)
@@ -15,11 +15,11 @@ import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.BitSet;
 import java.util.List;
 import java.util.Map.Entry;
 import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrLinkAttributesParser;
 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
@@ -58,8 +58,10 @@ public final class LinkAttributesParser {
     private static final int BANDWIDTH_LENGTH = 4;
 
     // MPLS protection mask bits
-    private static final int LDP_BIT = 7;
-    private static final int RSVP_BIT = 6;
+    private static final int FLAGS_SIZE = 8;
+
+    private static final int LDP_BIT = 0;
+    private static final int RSVP_BIT = 1;
 
     /* Link Attribute TLVs */
     private static final int REMOTE_IPV4_ROUTER_ID = 1030;
@@ -147,7 +149,7 @@ public final class LinkAttributesParser {
                 LOG.debug("Parsed Link Protection Type {}", lpt);
                 break;
             case MPLS_PROTOCOL:
-                final BitSet bits = BitSet.valueOf(ByteArray.readAllBytes(value));
+                final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE);
                 builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
                 LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
                 break;
@@ -255,14 +257,10 @@ public final class LinkAttributesParser {
     private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask, final ByteBuf byteAggregator ) {
         if (mplsProtocolMask != null) {
             final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer(1);
-            final BitSet mask = new BitSet(Byte.SIZE);
-            if (mplsProtocolMask.isLdp() != null) {
-                mask.set(LDP_BIT, mplsProtocolMask.isLdp());
-            }
-            if (mplsProtocolMask.isRsvpte() != null) {
-                mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
-            }
-            mplsProtocolMaskBuf.writeBytes(mask.toByteArray());
+            final BitArray mask = new BitArray(FLAGS_SIZE);
+            mask.set(LDP_BIT, mplsProtocolMask.isLdp());
+            mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
+            mask.toByteBuf(mplsProtocolMaskBuf);
             TlvUtil.writeTLV(MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
         }
     }
index 841cc46a6cd933c189b347f59f8b136da8bbd965..f2e15c671331efe5584e040f883fbf60c5291965 100644 (file)
@@ -14,11 +14,11 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
-import java.util.BitSet;
 import java.util.List;
 import java.util.Map.Entry;
 import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrNodeAttributesParser;
 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
@@ -47,11 +47,13 @@ public final class NodeAttributesParser {
         throw new UnsupportedOperationException();
     }
 
+    private static final int FLAGS_SIZE = 8;
+
     // node flag bits
-    private static final int OVERLOAD_BIT = 7;
-    private static final int ATTACHED_BIT = 6;
-    private static final int EXTERNAL_BIT = 5;
-    private static final int ABBR_BIT = 4;
+    private static final int OVERLOAD_BIT = 0;
+    private static final int ATTACHED_BIT = 1;
+    private static final int EXTERNAL_BIT = 2;
+    private static final int ABBR_BIT = 3;
 
     /* Node Attribute TLVs */
     private static final int NODE_FLAG_BITS = 1024;
@@ -87,7 +89,7 @@ public final class NodeAttributesParser {
                 }
                 break;
             case NODE_FLAG_BITS:
-                final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
+                final BitArray flags = BitArray.valueOf(value, FLAGS_SIZE);
                 builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT)));
                 LOG.debug("Parsed Overload bit: {}, attached bit: {}, external bit: {}, area border router: {}.",
                     flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT));
@@ -189,20 +191,12 @@ public final class NodeAttributesParser {
     private static void serializeNodeFlagBits(final NodeFlagBits nodeFlagBits, final ByteBuf byteAggregator) {
         if (nodeFlagBits != null) {
             final ByteBuf nodeFlagBuf = Unpooled.buffer(1);
-            final BitSet flags = new BitSet(Byte.SIZE);
-            if (nodeFlagBits.isOverload() != null) {
-                flags.set(OVERLOAD_BIT, nodeFlagBits.isOverload());
-            }
-            if (nodeFlagBits.isAttached() != null) {
-                flags.set(ATTACHED_BIT, nodeFlagBits.isAttached());
-            }
-            if (nodeFlagBits.isExternal() != null) {
-                flags.set(EXTERNAL_BIT, nodeFlagBits.isExternal());
-            }
-            if (nodeFlagBits.isAbr() != null) {
-                flags.set(ABBR_BIT, nodeFlagBits.isAbr());
-            }
-            nodeFlagBuf.writeBytes(flags.toByteArray());
+            final BitArray flags = new BitArray(FLAGS_SIZE);
+            flags.set(OVERLOAD_BIT, nodeFlagBits.isOverload());
+            flags.set(ATTACHED_BIT, nodeFlagBits.isAttached());
+            flags.set(EXTERNAL_BIT, nodeFlagBits.isExternal());
+            flags.set(ABBR_BIT, nodeFlagBits.isAbr());
+            flags.toByteBuf(nodeFlagBuf);
             TlvUtil.writeTLV(NODE_FLAG_BITS, nodeFlagBuf, byteAggregator);
         }
     }
index 34045a441e9644cbd7a5809d3a9bebcedabd2c02..2297c9483a544debadc9d464cc491039ef113a50 100644 (file)
@@ -13,11 +13,11 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
-import java.util.BitSet;
 import java.util.List;
 import java.util.Map.Entry;
 import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrPrefixAttributesParser;
 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
@@ -47,7 +47,9 @@ public final class PrefixAttributesParser {
 
     private static final int ROUTE_TAG_LENGTH = 4;
     private static final int EXTENDED_ROUTE_TAG_LENGTH = 8;
-    private static final int UP_DOWN_BIT = 7;
+
+    private static final int FLAGS_SIZE = 8;
+    private static final int UP_DOWN_BIT = 0;
 
     /* Prefix Attribute TLVs */
     private static final int IGP_FLAGS = 1152;
@@ -76,7 +78,7 @@ public final class PrefixAttributesParser {
             LOG.trace("Prefix attribute TLV {}", key);
             switch (key) {
             case IGP_FLAGS:
-                final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
+                final BitArray flags = BitArray.valueOf(value, FLAGS_SIZE);
                 final boolean upDownBit = flags.get(UP_DOWN_BIT);
                 builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit)).build());
                 LOG.debug("Parsed IGP flag (up/down bit) : {}", upDownBit);
@@ -141,12 +143,9 @@ public final class PrefixAttributesParser {
     static void serializePrefixAttributes(final PrefixAttributesCase prefixAttributesCase, final ByteBuf byteAggregator) {
         final PrefixAttributes prefixAtrributes = prefixAttributesCase.getPrefixAttributes();
         if (prefixAtrributes.getIgpBits() != null) {
-            final BitSet igpBit = new BitSet();
-            final Boolean bit = prefixAtrributes.getIgpBits().getUpDown().isUpDown();
-            if (bit != null) {
-                igpBit.set(UP_DOWN_BIT, bit);
-            }
-            TlvUtil.writeTLV(IGP_FLAGS, Unpooled.wrappedBuffer(igpBit.toByteArray()), byteAggregator);
+            final BitArray igpBit = new BitArray(FLAGS_SIZE);
+            igpBit.set(UP_DOWN_BIT, prefixAtrributes.getIgpBits().getUpDown().isUpDown());
+            TlvUtil.writeTLV(IGP_FLAGS, Unpooled.wrappedBuffer(igpBit.array()), byteAggregator);
         }
         if (prefixAtrributes.getRouteTags() != null) {
             final ByteBuf routeTagsBuf = Unpooled.buffer();
index 5b010432b31b2e4822d99c2618d66d48f1f344b5..18845e5d4ba8ad9c1152c3cc551280353954dc70 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.protocol.bgp.linkstate.attribute.sr;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import java.util.BitSet;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.SrAdjId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.link.state.SrAdjIdBuilder;
@@ -25,12 +25,12 @@ public final class SrLinkAttributesParser {
     private static final int ISO_SYSTEM_ID_SIZE = 6;
 
     /* Adj-SID flags */
-    private static final int ADDRESS_FAMILY_FLAG = 7;
-    private static final int BACKUP_FLAG = 6;
-    private static final int VALUE_FLAG = 5;
-    private static final int LOCAL_FLAG = 4;
-    private static final int SET_FLAG = 3;
-    private static final int FLAGS_SIZE = 1;
+    private static final int ADDRESS_FAMILY_FLAG = 0;
+    private static final int BACKUP_FLAG = 1;
+    private static final int VALUE_FLAG = 2;
+    private static final int LOCAL_FLAG = 3;
+    private static final int SET_FLAG = 4;
+    private static final int FLAGS_SIZE = 8;
 
     private SrLinkAttributesParser() {
         throw new UnsupportedOperationException();
@@ -41,7 +41,7 @@ public final class SrLinkAttributesParser {
             return new SrAdjIdBuilder().build();
         }
         final SrAdjIdBuilder srAdjIdBuilder = new SrAdjIdBuilder();
-        final BitSet flags = BitSet.valueOf(ByteArray.readBytes(buffer, FLAGS_SIZE));
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
         srAdjIdBuilder.setFlags(new AdjacencyFlags(flags.get(ADDRESS_FAMILY_FLAG), flags.get(BACKUP_FLAG), flags.get(LOCAL_FLAG), flags.get(SET_FLAG), flags.get(VALUE_FLAG)));
         srAdjIdBuilder.setWeight(new Weight(buffer.readUnsignedByte()));
         srAdjIdBuilder.setSid(new SidLabel(ByteArray.readAllBytes(buffer)));
@@ -51,23 +51,13 @@ public final class SrLinkAttributesParser {
     public static ByteBuf serializeAdjacencySegmentIdentifier(final SrAdjId srAdjId) {
         final ByteBuf value = Unpooled.buffer();
         final AdjacencyFlags srAdjIdFlags = srAdjId.getFlags();
-        final BitSet flags = new BitSet(FLAGS_SIZE);
-        if (srAdjIdFlags.isAddressFamily() != null) {
-            flags.set(ADDRESS_FAMILY_FLAG, srAdjIdFlags.isAddressFamily());
-        }
-        if (srAdjIdFlags.isBackup() != null) {
-            flags.set(BACKUP_FLAG, srAdjIdFlags.isBackup());
-        }
-        if (srAdjIdFlags.isValue() != null) {
-            flags.set(VALUE_FLAG, srAdjIdFlags.isValue());
-        }
-        if (srAdjIdFlags.isLocal() != null) {
-            flags.set(LOCAL_FLAG, srAdjIdFlags.isLocal());
-        }
-        if (srAdjIdFlags.isSetFlag() != null) {
-            flags.set(SET_FLAG, srAdjIdFlags.isSetFlag());
-        }
-        value.writeBytes(flags.toByteArray());
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(ADDRESS_FAMILY_FLAG, srAdjIdFlags.isAddressFamily());
+        flags.set(BACKUP_FLAG, srAdjIdFlags.isBackup());
+        flags.set(VALUE_FLAG, srAdjIdFlags.isValue());
+        flags.set(LOCAL_FLAG, srAdjIdFlags.isLocal());
+        flags.set(SET_FLAG, srAdjIdFlags.isSetFlag());
+        flags.toByteBuf(value);
         value.writeByte(srAdjId.getWeight().getValue());
         value.writeBytes(srAdjId.getSid().getValue());
         return value;
@@ -78,7 +68,7 @@ public final class SrLinkAttributesParser {
             return new SrLanAdjIdBuilder().build();
         }
         final SrLanAdjIdBuilder srLanAdjIdBuilder = new SrLanAdjIdBuilder();
-        final BitSet flags = BitSet.valueOf(ByteArray.readBytes(buffer, FLAGS_SIZE));
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
         srLanAdjIdBuilder.setFlags(new AdjacencyFlags(flags.get(ADDRESS_FAMILY_FLAG), flags.get(BACKUP_FLAG), flags.get(LOCAL_FLAG), flags.get(SET_FLAG), flags.get(VALUE_FLAG)));
         srLanAdjIdBuilder.setWeight(new Weight(buffer.readUnsignedByte()));
         srLanAdjIdBuilder.setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(buffer, ISO_SYSTEM_ID_SIZE)));
@@ -89,23 +79,13 @@ public final class SrLinkAttributesParser {
     public static ByteBuf serializeLanAdjacencySegmentIdentifier(final SrLanAdjId srLanAdjId) {
         final ByteBuf value = Unpooled.buffer();
         final AdjacencyFlags srAdjIdFlags = srLanAdjId.getFlags();
-        final BitSet flags = new BitSet(FLAGS_SIZE);
-        if (srAdjIdFlags.isAddressFamily() != null) {
-            flags.set(ADDRESS_FAMILY_FLAG, srAdjIdFlags.isAddressFamily());
-        }
-        if (srAdjIdFlags.isBackup() != null) {
-            flags.set(BACKUP_FLAG, srAdjIdFlags.isBackup());
-        }
-        if (srAdjIdFlags.isValue() != null) {
-            flags.set(VALUE_FLAG, srAdjIdFlags.isValue());
-        }
-        if (srAdjIdFlags.isLocal() != null) {
-            flags.set(LOCAL_FLAG, srAdjIdFlags.isLocal());
-        }
-        if (srAdjIdFlags.isSetFlag() != null) {
-            flags.set(SET_FLAG, srAdjIdFlags.isSetFlag());
-        }
-        value.writeBytes(flags.toByteArray());
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(ADDRESS_FAMILY_FLAG, srAdjIdFlags.isAddressFamily());
+        flags.set(BACKUP_FLAG, srAdjIdFlags.isBackup());
+        flags.set(VALUE_FLAG, srAdjIdFlags.isValue());
+        flags.set(LOCAL_FLAG, srAdjIdFlags.isLocal());
+        flags.set(SET_FLAG, srAdjIdFlags.isSetFlag());
+        flags.toByteBuf(value);
         value.writeByte(srLanAdjId.getWeight().getValue());
         value.writeBytes(srLanAdjId.getIsoSystemId().getValue());
         value.writeBytes(srLanAdjId.getSid().getValue());
index d776aaadf90ee5456249628ff05141b1473e77ee..f9da528897931c4516273734db03d64a4bd270f1 100644 (file)
@@ -10,9 +10,9 @@ package org.opendaylight.protocol.bgp.linkstate.attribute.sr;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.util.ArrayList;
-import java.util.BitSet;
 import java.util.List;
 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
@@ -61,15 +61,15 @@ public final class SrNodeAttributesParser {
         throw new UnsupportedOperationException();
     }
 
-    private static final int FLAGS_SIZE = 1;
+    private static final int FLAGS_SIZE = 8;
 
     /* SR Capabilities flags */
-    private static final int IPV4 = 7;
-    private static final int IPV6 = 6;
+    private static final int IPV4 = 0;
+    private static final int IPV6 = 1;
 
     /* SID Label flags */
-    private static final int AFI = 7;
-    private static final int MIRROR = 6;
+    private static final int AFI = 0;
+    private static final int MIRROR = 1;
 
     /* SID Label Tlv types */
     private static final int SID_TLV_TYPE = 1;
@@ -150,7 +150,7 @@ public final class SrNodeAttributesParser {
 
     public static SrSidLabel parseSidLabelBinding(final ByteBuf buffer) {
         final SrSidLabelBuilder builder = new SrSidLabelBuilder();
-        final BitSet flags = BitSet.valueOf(ByteArray.readBytes(buffer, FLAGS_SIZE));
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
         builder.setSidLabelFlags(new SidLabelFlags(flags.get(AFI), flags.get(MIRROR)));
         builder.setWeight(new Weight(buffer.readUnsignedByte()));
         builder.setValueRange(buffer.readUnsignedShort());
@@ -223,14 +223,10 @@ public final class SrNodeAttributesParser {
 
     public static void serializeSidLabelBinding(final SrSidLabel binding, final ByteBuf buffer) {
         final SidLabelFlags flags = binding.getSidLabelFlags();
-        final BitSet bs = new BitSet(FLAGS_SIZE);
-        if (flags.isAddressFamily() != null) {
-            bs.set(AFI, flags.isAddressFamily());
-        }
-        if (flags.isMirrorContext() != null) {
-            bs.set(MIRROR, flags.isMirrorContext());
-        }
-        buffer.writeBytes(bs.toByteArray());
+        final BitArray bs = new BitArray(FLAGS_SIZE);
+        bs.set(AFI, flags.isAddressFamily());
+        bs.set(MIRROR, flags.isMirrorContext());
+        bs.toByteBuf(buffer);
         buffer.writeByte(binding.getWeight().getValue());
         buffer.writeShort(binding.getValueRange());
         final IpPrefix prefix = binding.getFecPrefix();
@@ -246,7 +242,7 @@ public final class SrNodeAttributesParser {
 
     public static SrCapabilities parseSrCapabilities(final ByteBuf buffer) {
         final SrCapabilitiesBuilder builder = new SrCapabilitiesBuilder();
-        final BitSet flags = BitSet.valueOf(ByteArray.readBytes(buffer, FLAGS_SIZE));
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
         builder.setFlags(new Flags(flags.get(IPV4), flags.get(IPV6)));
         builder.setValueRange((long)buffer.readUnsignedMedium());
         buffer.skipBytes(2);
@@ -256,14 +252,10 @@ public final class SrNodeAttributesParser {
 
     public static void serializeSrCapabilities(final SrCapabilities caps, final ByteBuf buffer) {
         final Flags flags = caps.getFlags();
-        final BitSet bs = new BitSet(FLAGS_SIZE);
-        if (flags.isIpv4() != null) {
-            bs.set(IPV4, flags.isIpv4());
-        }
-        if (flags.isIpv6() != null) {
-            bs.set(IPV6, flags.isIpv6());
-        }
-        buffer.writeBytes(bs.toByteArray());
+        final BitArray bs = new BitArray(FLAGS_SIZE);
+        bs.set(IPV4, flags.isIpv4());
+        bs.set(IPV6, flags.isIpv6());
+        bs.toByteBuf(buffer);
         buffer.writeMedium(caps.getValueRange().intValue());
         buffer.writeByte(SID_TLV_TYPE);
         final byte[] sid = caps.getSid().getValue();
index 1614cc129b14ae0a970b509bbd67cadca3ec6b8d..a28db5df0d218a073dd04623902483624224e8b0 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.protocol.bgp.linkstate.attribute.sr;
 
 import io.netty.buffer.ByteBuf;
-import java.util.BitSet;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.SrPrefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.prefix.state.SrPrefixBuilder;
@@ -18,22 +18,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segm
 
 public final class SrPrefixAttributesParser {
 
-    private static final int FLAGS_SIZE = 1;
+    private static final int FLAGS_SIZE = 8;
 
     private SrPrefixAttributesParser() {
         throw new UnsupportedOperationException();
     }
 
     /* Flags */
-    private static final int RE_ADVERTISEMENT = 7;
-    private static final int NODE_SID = 6;
-    private static final int NO_PHP = 5;
-    private static final int EXPLICIT_NULL = 4;
-    private static final int VALUE = 3;
-    private static final int LOCAL = 2;
+    private static final int RE_ADVERTISEMENT = 0;
+    private static final int NODE_SID = 1;
+    private static final int NO_PHP = 2;
+    private static final int EXPLICIT_NULL = 3;
+    private static final int VALUE = 4;
+    private static final int LOCAL = 5;
 
     public static SrPrefix parseSrPrefix(final ByteBuf buffer) {
-        final BitSet flags = BitSet.valueOf(ByteArray.readBytes(buffer, FLAGS_SIZE));
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
         final SrPrefixBuilder builder = new SrPrefixBuilder();
         builder.setFlags(new Flags(flags.get(EXPLICIT_NULL), flags.get(LOCAL), flags.get(NO_PHP), flags.get(NODE_SID), flags.get(RE_ADVERTISEMENT), flags.get(VALUE)));
         builder.setAlgorithm(Algorithm.forValue(buffer.readUnsignedByte()));
@@ -43,26 +43,14 @@ public final class SrPrefixAttributesParser {
 
     public static void serializeSrPrefix(final SrPrefix srPrefix, final ByteBuf buffer) {
         final Flags flags = srPrefix.getFlags();
-        final BitSet bs = new BitSet(FLAGS_SIZE);
-        if (flags.isReadvertisement() != null) {
-            bs.set(RE_ADVERTISEMENT, flags.isReadvertisement());
-        }
-        if (flags.isNodeSid() != null) {
-            bs.set(NODE_SID, flags.isNodeSid());
-        }
-        if (flags.isNoPhp() != null) {
-            bs.set(NO_PHP, flags.isNoPhp());
-        }
-        if (flags.isExplicitNull() != null) {
-            bs.set(EXPLICIT_NULL, flags.isExplicitNull());
-        }
-        if (flags.isValue() != null) {
-            bs.set(VALUE, flags.isValue());
-        }
-        if (flags.isLocal() != null) {
-            bs.set(LOCAL, flags.isLocal());
-        }
-        buffer.writeBytes(bs.toByteArray());
+        final BitArray bs = new BitArray(FLAGS_SIZE);
+        bs.set(RE_ADVERTISEMENT, flags.isReadvertisement());
+        bs.set(NODE_SID, flags.isNodeSid());
+        bs.set(NO_PHP, flags.isNoPhp());
+        bs.set(EXPLICIT_NULL, flags.isExplicitNull());
+        bs.set(VALUE, flags.isValue());
+        bs.set(LOCAL, flags.isLocal());
+        bs.toByteBuf(buffer);
         buffer.writeByte(srPrefix.getAlgorithm().getIntValue());
         buffer.writeBytes(srPrefix.getSid().getValue());
     }
index ad5304664568a95bcd870fd3e62c08a28e650e6f..f6c4c669cacdce0b920ec33e877be61341ae271d 100644 (file)
@@ -22,7 +22,7 @@ import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
 import org.opendaylight.protocol.concepts.AbstractRegistration;
 import org.opendaylight.protocol.concepts.HandlerRegistry;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.Values;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
@@ -76,16 +76,16 @@ final class SimpleAttributeRegistry implements AttributeRegistry {
     }
 
     private void addAttribute(final ByteBuf buffer, final Map<Integer, RawAttribute> attributes) throws BGPDocumentedException {
-        final boolean[] flags = ByteArray.parseBits(buffer.readByte());
+        final BitArray flags = BitArray.valueOf(buffer.readByte());
         final int type = buffer.readUnsignedByte();
-        final int len = (flags[EXTENDED_LENGTH_BIT]) ? buffer.readUnsignedShort() : buffer.readUnsignedByte();
+        final int len = (flags.get(EXTENDED_LENGTH_BIT)) ? buffer.readUnsignedShort() : buffer.readUnsignedByte();
         if (!attributes.containsKey(type)) {
             final AttributeParser parser = this.handlers.getParser(type);
             if (parser == null) {
-                if (!flags[OPTIONAL_BIT]) {
+                if (!flags.get(OPTIONAL_BIT)) {
                     throw new BGPDocumentedException("Well known attribute not recognized.", BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED);
                 }
-                if (flags[TRANSITIVE_BIT]) {
+                if (flags.get(TRANSITIVE_BIT)) {
                     // FIXME: transitive attributes need to be preserved
                     LOG.warn("Losing unrecognized transitive attribute {}. Some data might be missing from the output.", type);
                 } else {
index cbdb9815b24ca90a2c86c340c82978cb7078c3ee..bd55317c29db3aa22e2898ab1093447b47370c2f 100644 (file)
@@ -13,13 +13,12 @@ import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import java.util.BitSet;
 import org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07LspObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Lsp1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Lsp1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.OperationalStatus;
@@ -35,7 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
  */
 public class CInitiated00LspObjectParser extends Stateful07LspObjectParser {
 
-    private static final int CREATE_FLAG_OFFSET = 8;
+    private static final int CREATE_FLAG_OFFSET = 4;
 
     public CInitiated00LspObjectParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
         super(tlvReg, viTlvReg);
@@ -48,17 +47,17 @@ public class CInitiated00LspObjectParser extends Stateful07LspObjectParser {
         builder.setIgnore(header.isIgnore());
         builder.setProcessingRule(header.isProcessingRule());
         final int[] plspIdRaw = new int[] { bytes.readUnsignedByte(), bytes.readUnsignedByte(), bytes.getUnsignedByte(2), };
-        builder.setPlspId(new PlspId((long) ((plspIdRaw[0] << TWELVE_BITS_SHIFT) | (plspIdRaw[1] << FOUR_BITS_SHIFT) | (plspIdRaw[2] >> FOUR_BITS_SHIFT))));
-        final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(bytes, 2));
-        builder.setDelegate(flags.get(DELEGATE_FLAG_OFFSET));
-        builder.setSync(flags.get(SYNC_FLAG_OFFSET));
-        builder.setRemove(flags.get(REMOVE_FLAG_OFFSET));
-        builder.setAdministrative(flags.get(ADMINISTRATIVE_FLAG_OFFSET));
+        builder.setPlspId(new PlspId((long) ((plspIdRaw[0] << FLAGS_SIZE) | (plspIdRaw[1] << FOUR_BITS_SHIFT) | (plspIdRaw[2] >> FOUR_BITS_SHIFT))));
+        final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
+        builder.setDelegate(flags.get(DELEGATE));
+        builder.setSync(flags.get(SYNC));
+        builder.setRemove(flags.get(REMOVE));
+        builder.setAdministrative(flags.get(ADMINISTRATIVE));
         builder.addAugmentation(Lsp1.class, new Lsp1Builder().setCreate(flags.get(CREATE_FLAG_OFFSET)).build());
         short s = 0;
-        s |= flags.get(OPERATIONAL_OFFSET + 2) ? 1 : 0;
-        s |= (flags.get(OPERATIONAL_OFFSET + 1) ? 1 : 0) << 1;
-        s |= (flags.get(OPERATIONAL_OFFSET) ? 1 : 0) << 2;
+        s |= flags.get(OPERATIONAL + 2) ? 1 : 0;
+        s |= (flags.get(OPERATIONAL + 1) ? 1 : 0) << 1;
+        s |= (flags.get(OPERATIONAL) ? 1 : 0) << 2;
         builder.setOperational(OperationalStatus.forValue(s));
         final TlvsBuilder b = new TlvsBuilder();
         parseTlvs(b, bytes.slice());
@@ -73,20 +72,12 @@ public class CInitiated00LspObjectParser extends Stateful07LspObjectParser {
         final ByteBuf body = Unpooled.buffer();
         Preconditions.checkArgument(specObj.getPlspId() != null, "PLSP-ID not present");
         writeMedium(specObj.getPlspId().getValue().intValue() << FOUR_BITS_SHIFT, body);
-        final BitSet flags = new BitSet(2 * Byte.SIZE);
-        if (specObj.isDelegate() != null) {
-            flags.set(DELEGATE_FLAG_OFFSET, specObj.isDelegate());
-        }
-        if (specObj.isRemove() != null) {
-            flags.set(REMOVE_FLAG_OFFSET, specObj.isRemove());
-        }
-        if (specObj.isSync() != null) {
-            flags.set(SYNC_FLAG_OFFSET, specObj.isSync());
-        }
-        if (specObj.isAdministrative() != null) {
-            flags.set(ADMINISTRATIVE_FLAG_OFFSET, specObj.isAdministrative());
-        }
-        if (specObj.getAugmentation(Lsp1.class) != null && specObj.getAugmentation(Lsp1.class).isCreate() != null) {
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(DELEGATE, specObj.isDelegate());
+        flags.set(REMOVE, specObj.isRemove());
+        flags.set(SYNC, specObj.isSync());
+        flags.set(ADMINISTRATIVE, specObj.isAdministrative());
+        if (specObj.getAugmentation(Lsp1.class) != null) {
             flags.set(CREATE_FLAG_OFFSET, specObj.getAugmentation(Lsp1.class).isCreate());
         }
         byte op = 0;
@@ -94,7 +85,9 @@ public class CInitiated00LspObjectParser extends Stateful07LspObjectParser {
             op = UnsignedBytes.checkedCast(specObj.getOperational().getIntValue());
             op = (byte) (op << FOUR_BITS_SHIFT);
         }
-        body.writeByte(ByteArray.bitSetToBytes(flags, 2)[1] | op);
+        final byte[] res = flags.array();
+        res[res.length -1] = (byte) (res[res.length -1] | op);
+        body.writeByte(res[res.length -1]);
         serializeTlvs(specObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index f0bca39e42eab9abd739799a3b0f9f86f29b98bb..42c726fa9363ce406baeb5039a13c05ee3e0d09f 100644 (file)
@@ -7,19 +7,17 @@
  */
 package org.opendaylight.protocol.pcep.ietf.initiated00;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 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.ietf.stateful07.Stateful07SrpObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Srp1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SrpIdNumber;
@@ -50,7 +48,7 @@ public class CInitiated00SrpObjectParser extends Stateful07SrpObjectParser {
         final SrpBuilder builder = new SrpBuilder();
         builder.setIgnore(header.isIgnore());
         builder.setProcessingRule(header.isProcessingRule());
-        final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(bytes, FLAGS_SIZE));
+        final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
         builder.addAugmentation(Srp1.class, new Srp1Builder().setRemove(flags.get(REMOVE_FLAG)).build());
         builder.setOperationId(new SrpIdNumber(bytes.readUnsignedInt()));
         final TlvsBuilder tlvsBuilder = new TlvsBuilder();
@@ -64,11 +62,11 @@ public class CInitiated00SrpObjectParser extends Stateful07SrpObjectParser {
         Preconditions.checkArgument(object instanceof Srp, "Wrong instance of PCEPObject. Passed %s. Needed SrpObject.", object.getClass());
         final Srp srp = (Srp) object;
         final ByteBuf body = Unpooled.buffer();
-        final BitSet flags = new BitSet(FLAGS_SIZE * Byte.SIZE);
-        if (srp.getAugmentation(Srp1.class) != null && srp.getAugmentation(Srp1.class).isRemove()) {
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        if (srp.getAugmentation(Srp1.class) != null) {
             flags.set(REMOVE_FLAG, srp.getAugmentation(Srp1.class).isRemove());
         }
-        writeBitSet(flags, FLAGS_SIZE, body);
+        flags.toByteBuf(body);
         Preconditions.checkArgument(srp.getOperationId() != null, "OperationId is mandatory.");
         writeUnsignedInt(srp.getOperationId().getValue(), body);
         serializeTlvs(srp.getTlvs(), body);
index 27ce9f9bd3c9529eee0a635ba0a5898a1498b5d2..493b9e7bd3a5854d4cd691d369d57b458bf17c1b 100644 (file)
@@ -7,16 +7,13 @@
  */
 package org.opendaylight.protocol.pcep.ietf.initiated00;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
-
 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.ietf.stateful07.Stateful07StatefulCapabilityTlvParser;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvUtil;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1Builder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.Stateful;
@@ -35,15 +32,13 @@ public final class CInitiated00StatefulCapabilityTlvParser extends Stateful07Sta
         if (buffer == null) {
             return null;
         }
-        if (buffer.readableBytes() < FLAGS_F_LENGTH) {
+        if (buffer.readableBytes() < FLAGS_F_LENGTH / Byte.SIZE) {
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >= "
-                    + FLAGS_F_LENGTH + ".");
+                    + FLAGS_F_LENGTH / Byte.SIZE + ".");
         }
-        final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
-
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_F_LENGTH);
         final StatefulBuilder sb = new StatefulBuilder();
         sb.setLspUpdateCapability(flags.get(U_FLAG_OFFSET));
-
         if (flags.get(I_FLAG_OFFSET)) {
             sb.addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build());
         }
@@ -54,16 +49,12 @@ public final class CInitiated00StatefulCapabilityTlvParser extends Stateful07Sta
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
         Preconditions.checkArgument(tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
         final Stateful sct = (Stateful) tlv;
-        final ByteBuf body = Unpooled.buffer();
-        final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
+        final BitArray flags = new BitArray(FLAGS_F_LENGTH);
         final Stateful1 sfi = sct.getAugmentation(Stateful1.class);
         if (sfi != null) {
             flags.set(I_FLAG_OFFSET, sfi.isInitiation());
         }
-        if (sct.isLspUpdateCapability() != null) {
-            flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
-        }
-        writeBitSet(flags, FLAGS_F_LENGTH, body);
-        TlvUtil.formatTlv(TYPE, body, buffer);
+        flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
+        TlvUtil.formatTlv(TYPE, Unpooled.wrappedBuffer(flags.array()), buffer);
     }
 }
index c4a3ab56382f5cd3783cce9abf4603045409d1bf..824659286faa66fc6957ea5a7f9e6f72442e3ffb 100644 (file)
@@ -13,14 +13,13 @@ import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import java.util.BitSet;
 import java.util.List;
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.OperationalStatus;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PlspId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.error.code.tlv.LspErrorCode;
@@ -46,26 +45,17 @@ public class Stateful07LspObjectParser extends AbstractObjectWithTlvsParser<Tlvs
 
     public static final int TYPE = 1;
 
-    /*
-     * offset of TLVs offset of other fields are not defined as constants
-     * because of non-standard mapping of bits
-     */
-    protected static final int TLVS_OFFSET = 4;
-
     /*
      * 12b extended to 16b so first 4b are restricted (belongs to LSP ID)
      */
-    protected static final int DELEGATE_FLAG_OFFSET = 15;
-    protected static final int SYNC_FLAG_OFFSET = 14;
-    protected static final int REMOVE_FLAG_OFFSET = 13;
-    protected static final int ADMINISTRATIVE_FLAG_OFFSET = 12;
-    protected static final int OPERATIONAL_OFFSET = 9;
+    protected static final int DELEGATE = 11;
+    protected static final int SYNC = 10;
+    protected static final int REMOVE = 9;
+    protected static final int ADMINISTRATIVE = 8;
+    protected static final int OPERATIONAL = 5;
 
     protected static final int FOUR_BITS_SHIFT = 4;
-    protected static final int TWELVE_BITS_SHIFT = 12;
-    protected static final int BODY_LENGTH = 4;
-    protected static final int FLAGS_INDEX = 3;
-    protected static final int OP_VALUE_BITS_OFFSET = 7;
+    protected static final int FLAGS_SIZE = 12;
 
     public Stateful07LspObjectParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
         super(tlvReg, viTlvReg);
@@ -78,16 +68,16 @@ public class Stateful07LspObjectParser extends AbstractObjectWithTlvsParser<Tlvs
         builder.setIgnore(header.isIgnore());
         builder.setProcessingRule(header.isProcessingRule());
         final int[] plspIdRaw = new int[] { bytes.readUnsignedByte(), bytes.readUnsignedByte(), bytes.getUnsignedByte(2), };
-        builder.setPlspId(new PlspId((long) ((plspIdRaw[0] << TWELVE_BITS_SHIFT) | (plspIdRaw[1] << FOUR_BITS_SHIFT) | (plspIdRaw[2] >> FOUR_BITS_SHIFT))));
-        final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(bytes, 2));
-        builder.setDelegate(flags.get(DELEGATE_FLAG_OFFSET));
-        builder.setSync(flags.get(SYNC_FLAG_OFFSET));
-        builder.setRemove(flags.get(REMOVE_FLAG_OFFSET));
-        builder.setAdministrative(flags.get(ADMINISTRATIVE_FLAG_OFFSET));
+        builder.setPlspId(new PlspId((long) ((plspIdRaw[0] << FLAGS_SIZE) | (plspIdRaw[1] << FOUR_BITS_SHIFT) | (plspIdRaw[2] >> FOUR_BITS_SHIFT))));
+        final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
+        builder.setDelegate(flags.get(DELEGATE));
+        builder.setSync(flags.get(SYNC));
+        builder.setRemove(flags.get(REMOVE));
+        builder.setAdministrative(flags.get(ADMINISTRATIVE));
         short s = 0;
-        s |= flags.get(OPERATIONAL_OFFSET + 2) ? 1 : 0;
-        s |= (flags.get(OPERATIONAL_OFFSET + 1) ? 1 : 0) << 1;
-        s |= (flags.get(OPERATIONAL_OFFSET) ? 1 : 0) << 2;
+        s |= flags.get(OPERATIONAL + 2) ? 1 : 0;
+        s |= (flags.get(OPERATIONAL + 1) ? 1 : 0) << 1;
+        s |= (flags.get(OPERATIONAL) ? 1 : 0) << 2;
         builder.setOperational(OperationalStatus.forValue(s));
         final TlvsBuilder b = new TlvsBuilder();
         parseTlvs(b, bytes.slice());
@@ -117,25 +107,19 @@ public class Stateful07LspObjectParser extends AbstractObjectWithTlvsParser<Tlvs
         final ByteBuf body = Unpooled.buffer();
         Preconditions.checkArgument(specObj.getPlspId() != null, "PLSP-ID not present");
         writeMedium(specObj.getPlspId().getValue().intValue() << FOUR_BITS_SHIFT, body);
-        final BitSet flags = new BitSet(2 * Byte.SIZE);
-        if (specObj.isDelegate() != null) {
-            flags.set(DELEGATE_FLAG_OFFSET, specObj.isDelegate());
-        }
-        if (specObj.isRemove() != null) {
-            flags.set(REMOVE_FLAG_OFFSET, specObj.isRemove());
-        }
-        if (specObj.isSync() != null) {
-            flags.set(SYNC_FLAG_OFFSET, specObj.isSync());
-        }
-        if (specObj.isAdministrative() != null) {
-            flags.set(ADMINISTRATIVE_FLAG_OFFSET, specObj.isAdministrative());
-        }
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(DELEGATE, specObj.isDelegate());
+        flags.set(REMOVE, specObj.isRemove());
+        flags.set(SYNC, specObj.isSync());
+        flags.set(ADMINISTRATIVE, specObj.isAdministrative());
         byte op = 0;
         if (specObj.getOperational() != null) {
             op = UnsignedBytes.checkedCast(specObj.getOperational().getIntValue());
             op = (byte) (op << FOUR_BITS_SHIFT);
         }
-        body.writeByte(ByteArray.bitSetToBytes(flags, 2)[1] | op);
+        final byte[] res = flags.array();
+        res[res.length -1] = (byte) (res[res.length -1] | op);
+        body.writeByte(res[res.length -1]);
         serializeTlvs(specObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
     }
index 908ba1f2dfcb3418a27e29e177c1ecaaeb0a687d..4ec2d5f9f4dd48b1cf90ba1dc447b0f2bae33fe1 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
@@ -18,11 +17,11 @@ import com.google.common.base.Charsets;
 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.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
 import org.opendaylight.protocol.pcep.spi.TlvUtil;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
@@ -49,7 +48,7 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
 
     public static final int TYPE = 21;
 
-    private static final int FLAGS_F_LENGTH = 1;
+    private static final int FLAGS_SIZE = 8;
     private static final int HEADER_LENGTH = 4;
 
     private static final int RSVP_ERROR_CLASS_NUM = 6;
@@ -59,8 +58,8 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
     private static final int USER_ERROR_CLASS_NUM = 194;
     private static final int USER_ERROR_CLASS_TYPE = 1;
 
-    private static final int IN_PLACE_FLAG_OFFSET = 7;
-    private static final int NOT_GUILTY_FLAGS_OFFSET = 6;
+    private static final int IN_PLACE = 7;
+    private static final int NOT_GUILTY = 6;
 
     @Override
     public RsvpErrorSpec parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
@@ -128,8 +127,8 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
         } else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) {
             builder.setNode(new IpAddress(Ipv6Util.addressForByteBuf(buffer)));
         }
-        final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
-        builder.setFlags(new Flags(flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET)));
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
+        builder.setFlags(new Flags(flags.get(IN_PLACE), flags.get(NOT_GUILTY)));
         final short errorCode = buffer.readUnsignedByte();
         builder.setCode(errorCode);
         final int errorValue = buffer.readUnsignedShort();
@@ -138,9 +137,9 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
     }
 
     private void serializeRsvp(final RsvpError rsvp, final ByteBuf body) {
-        final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-        flags.set(IN_PLACE_FLAG_OFFSET, rsvp.getFlags().isInPlace());
-        flags.set(NOT_GUILTY_FLAGS_OFFSET, rsvp.getFlags().isNotGuilty());
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(IN_PLACE, rsvp.getFlags().isInPlace());
+        flags.set(NOT_GUILTY, rsvp.getFlags().isNotGuilty());
         final IpAddress node = rsvp.getNode();
         Preconditions.checkArgument(node != null, "Node is mandatory.");
         final ByteBuf rsvpObjBuf = Unpooled.buffer();
@@ -152,7 +151,7 @@ public final class Stateful07RSVPErrorSpecTlvParser implements TlvParser, TlvSer
             type = RSVP_IPV6_ERROR_CLASS_TYPE;
             writeIpv6Address(node.getIpv6Address(), rsvpObjBuf);
         }
-        writeBitSet(flags, FLAGS_F_LENGTH, rsvpObjBuf);
+        flags.toByteBuf(rsvpObjBuf);
         Preconditions.checkArgument(rsvp.getCode() != null, "Code is mandatory.");
         writeUnsignedByte(rsvp.getCode(), rsvpObjBuf);
         Preconditions.checkArgument(rsvp.getValue() != null, "Value is mandatory.");
index 32856744f3ba5e4a9bd261ba8b7915a9ebf08d16..184271776c8d6674c4deae87ef77a1ffd0a2bb19 100644 (file)
@@ -39,13 +39,11 @@ public class Stateful07SrpObjectParser extends AbstractObjectWithTlvsParser<Tlvs
 
     public static final int TYPE = 1;
 
-    protected static final int FLAGS_SIZE = 4;
+    protected static final int FLAGS_SIZE = 32;
 
     protected static final int SRP_ID_SIZE = 4;
 
-    protected static final int TLVS_OFFSET = FLAGS_SIZE + SRP_ID_SIZE;
-
-    protected static final int MIN_SIZE = FLAGS_SIZE + SRP_ID_SIZE;
+    protected static final int MIN_SIZE = FLAGS_SIZE / Byte.SIZE + SRP_ID_SIZE;
 
     protected Stateful07SrpObjectParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
         super(tlvReg, viTlvReg);
@@ -61,7 +59,7 @@ public class Stateful07SrpObjectParser extends AbstractObjectWithTlvsParser<Tlvs
         final SrpBuilder builder = new SrpBuilder();
         builder.setIgnore(header.isIgnore());
         builder.setProcessingRule(header.isProcessingRule());
-        bytes.skipBytes(FLAGS_SIZE);
+        bytes.skipBytes(FLAGS_SIZE / Byte.SIZE);
         builder.setOperationId(new SrpIdNumber(bytes.readUnsignedInt()));
         final TlvsBuilder tlvsBuilder = new TlvsBuilder();
         parseTlvs(tlvsBuilder, bytes.slice());
@@ -84,7 +82,7 @@ public class Stateful07SrpObjectParser extends AbstractObjectWithTlvsParser<Tlvs
         Preconditions.checkArgument(object instanceof Srp, "Wrong instance of PCEPObject. Passed %s . Needed SrpObject.", object.getClass());
         final Srp srp = (Srp) object;
         final ByteBuf body = Unpooled.buffer();
-        body.writerIndex(body.writerIndex() + FLAGS_SIZE);
+        body.writeZero(FLAGS_SIZE / Byte.SIZE);
         final SrpIdNumber srpId = srp.getOperationId();
         Preconditions.checkArgument(srpId != null, "SrpId is mandatory.");
         writeUnsignedInt(srpId.getValue(), body);
index ecddf39e2423674fc1a978fcfbe52dffd0a0e545..ba863fbedc55f6cb3ec282d3daec33683a30201e 100644 (file)
@@ -7,17 +7,14 @@
  */
 package org.opendaylight.protocol.pcep.ietf.stateful07;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
-
 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.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
 import org.opendaylight.protocol.pcep.spi.TlvUtil;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.Stateful;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
@@ -29,7 +26,7 @@ public class Stateful07StatefulCapabilityTlvParser implements TlvParser, TlvSeri
 
     public static final int TYPE = 16;
 
-    protected static final int FLAGS_F_LENGTH = 4;
+    protected static final int FLAGS_F_LENGTH = 32;
 
     protected static final int U_FLAG_OFFSET = 31;
 
@@ -38,12 +35,11 @@ public class Stateful07StatefulCapabilityTlvParser implements TlvParser, TlvSeri
         if (buffer == null) {
             return null;
         }
-        if (buffer.readableBytes() < FLAGS_F_LENGTH) {
+        if (buffer.readableBytes() < FLAGS_F_LENGTH / Byte.SIZE) {
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >= "
-                    + FLAGS_F_LENGTH + ".");
+                    + FLAGS_F_LENGTH / Byte.SIZE + ".");
         }
-        final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, FLAGS_F_LENGTH));
-
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_F_LENGTH);
         final StatefulBuilder sb = new StatefulBuilder();
         sb.setLspUpdateCapability(flags.get(U_FLAG_OFFSET));
         return sb.build();
@@ -53,12 +49,8 @@ public class Stateful07StatefulCapabilityTlvParser implements TlvParser, TlvSeri
     public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
         Preconditions.checkArgument(tlv instanceof Stateful, "StatefulCapabilityTlv is mandatory.");
         final Stateful sct = (Stateful) tlv;
-        final ByteBuf body = Unpooled.buffer();
-        final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-        if (sct.isLspUpdateCapability() != null) {
-            flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
-        }
-        writeBitSet(flags, FLAGS_F_LENGTH, body);
-        TlvUtil.formatTlv(TYPE, body, buffer);
+        final BitArray flags = new BitArray(FLAGS_F_LENGTH);
+        flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
+        TlvUtil.formatTlv(TYPE, Unpooled.wrappedBuffer(flags.array()), buffer);
     }
 }
index ce4d9f56d64ec450f87834dadabfddc22fa1b695..0abe24da5b76af4b394060306c37216c4905fc86 100644 (file)
@@ -230,7 +230,7 @@ public class PCEPObjectParserTest {
             /* pst-tlv */
             0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0 };
         final CInitiated00SrpObjectParser parser = new CInitiated00SrpObjectParser(this.tlvRegistry, this.viTlvRegistry);
-        SrpBuilder builder = new SrpBuilder();
+        final SrpBuilder builder = new SrpBuilder();
         builder.setProcessingRule(false);
         builder.setIgnore(false);
         builder.setOperationId(new SrpIdNumber(1L));
index 020a0afe4ec6ddf7aaeb7bc23be1162452b6648f..6975d56d771d76f5a4ca8d557d33f3f07ec618d3 100644 (file)
@@ -7,21 +7,19 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import java.util.BitSet;
 import java.util.List;
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
@@ -43,7 +41,7 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
     /*
      * lengths of fields in bytes
      */
-    private static final int FLAGS_F_LENGTH = 1;
+    private static final int FLAGS_SIZE = 8;
 
     /*
      * offsets of flags inside flags field in bits
@@ -69,7 +67,7 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
         builder.setSetupPriority(bytes.readUnsignedByte());
         builder.setHoldPriority(bytes.readUnsignedByte());
 
-        final BitSet flags = ByteArray.bytesToBitSet(new byte[] { bytes.readByte() });
+        final BitArray flags = BitArray.valueOf(bytes.readByte());
         builder.setLocalProtectionDesired(flags.get(L_FLAG_OFFSET));
         final TlvsBuilder tbuilder = new TlvsBuilder();
         bytes.skipBytes(RESERVED);
@@ -88,11 +86,9 @@ public class PCEPLspaObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
         writeAttributeFilter(lspaObj.getIncludeAll(), body);
         writeUnsignedByte(lspaObj.getSetupPriority(), body);
         writeUnsignedByte(lspaObj.getHoldPriority(), body);
-        final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-        if (lspaObj.isLocalProtectionDesired() != null) {
-            flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
-        }
-        writeBitSet(flags, FLAGS_F_LENGTH, body);
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(L_FLAG_OFFSET, lspaObj.isLocalProtectionDesired());
+        flags.toByteBuf(body);
         body.writeZero(RESERVED);
         serializeTlvs(lspaObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
index 1e418afd20bbd72940f79378b57a616ee05a4e61..33bd86b612b6b874a179726be774eb3c1c0615de 100644 (file)
@@ -7,18 +7,17 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
 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.ObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
@@ -38,7 +37,7 @@ public class PCEPMetricObjectParser implements ObjectParser, ObjectSerializer {
     /*
      * lengths of fields in bytes
      */
-    private static final int FLAGS_F_LENGTH = 1;
+    private static final int FLAGS_SIZE = 8;
     private static final int METRIC_VALUE_F_LENGTH = 4;
 
     /*
@@ -62,8 +61,7 @@ public class PCEPMetricObjectParser implements ObjectParser, ObjectSerializer {
                     + ".");
         }
         bytes.skipBytes(RESERVED);
-        final byte[] flagBytes = { bytes.readByte() };
-        final BitSet flags = ByteArray.bytesToBitSet(flagBytes);
+        final BitArray flags = BitArray.valueOf(bytes.readByte());
         final MetricBuilder builder = new MetricBuilder();
         builder.setIgnore(header.isIgnore());
         builder.setProcessingRule(header.isProcessingRule());
@@ -80,14 +78,10 @@ public class PCEPMetricObjectParser implements ObjectParser, ObjectSerializer {
         final Metric mObj = (Metric) object;
         final ByteBuf body = Unpooled.buffer(SIZE);
         body.writeZero(RESERVED);
-        final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-        if (mObj.isComputed() != null) {
-            flags.set(C_FLAG_OFFSET, mObj.isComputed());
-        }
-        if (mObj.isBound() != null) {
-            flags.set(B_FLAG_OFFSET, mObj.isBound());
-        }
-        writeBitSet(flags, FLAGS_F_LENGTH, body);
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(C_FLAG_OFFSET, mObj.isComputed());
+        flags.set(B_FLAG_OFFSET, mObj.isBound());
+        flags.toByteBuf(body);
         Preconditions.checkArgument(mObj.getMetricType() != null, "MetricType is mandatory.");
         writeUnsignedByte(mObj.getMetricType(), body);
         writeFloat32(mObj.getValue(), body);
index efd734ed03d06ba7e13b3e12de527ab0d128f6da..487f6622a990966c7d9997e4cba00aaef3d3a2b8 100644 (file)
@@ -11,14 +11,13 @@ package org.opendaylight.protocol.pcep.impl.object;
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import java.util.BitSet;
 import java.util.List;
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
@@ -39,7 +38,7 @@ public class PCEPMonitoringObjectParser extends AbstractObjectWithTlvsParser<Tlv
 
     public static final int TYPE = 1;
 
-    private static final int FLAGS = 3;
+    private static final int FLAGS_SIZE = 24;
     private static final int RESERVED = 1;
     private static final int L_FLAG_POS = 23;
     private static final int G_FLAG_POS = 22;
@@ -56,7 +55,7 @@ public class PCEPMonitoringObjectParser extends AbstractObjectWithTlvsParser<Tlv
         Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         final MonitoringBuilder builder = new MonitoringBuilder();
         buffer.readBytes(RESERVED);
-        final BitSet flagBits = ByteArray.bytesToBitSet(buffer.readBytes(FLAGS).array());
+        final BitArray flagBits = BitArray.valueOf(buffer, FLAGS_SIZE);
         final Flags flags = new Flags(flagBits.get(G_FLAG_POS), flagBits.get(I_FLAG_POS), flagBits.get(L_FLAG_POS),
                 flagBits.get(C_FLAG_POS), flagBits.get(P_FLAG_POS));
         builder.setFlags(flags);
@@ -74,13 +73,13 @@ public class PCEPMonitoringObjectParser extends AbstractObjectWithTlvsParser<Tlv
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(RESERVED);
         final Flags flags = monitoring.getFlags();
-        final BitSet flagBits = new BitSet(FLAGS);
+        final BitArray flagBits = new BitArray(FLAGS_SIZE);
         flagBits.set(I_FLAG_POS, flags.isIncomplete());
         flagBits.set(C_FLAG_POS, flags.isOverload());
         flagBits.set(P_FLAG_POS, flags.isProcessingTime());
         flagBits.set(G_FLAG_POS, flags.isGeneral());
         flagBits.set(L_FLAG_POS, flags.isLiveness());
-        ByteBufWriteUtil.writeBitSet(flagBits, FLAGS, body);
+        flagBits.toByteBuf(body);
         ByteBufWriteUtil.writeUnsignedInt(monitoring.getMonitoringId(), body);
         serializeTlvs(monitoring.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
index 8b87007a33a0f3bcebe75bbece86896a95c8cfa9..8df98be321c4ed0e1d07d35c8027a24bf6be0ba8 100644 (file)
@@ -7,20 +7,18 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
 
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import java.util.BitSet;
 import java.util.List;
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
@@ -43,7 +41,7 @@ public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<TlvsBui
     /*
      * lengths of fields in bytes
      */
-    private static final int FLAGS_F_LENGTH = 2;
+    private static final int FLAGS_SIZE = 16;
     private static final int RESERVED_F_LENGTH = 1;
 
     /*
@@ -63,8 +61,7 @@ public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<TlvsBui
         builder.setProcessingRule(header.isProcessingRule());
 
         builder.setNatureOfIssue(bytes.readUnsignedByte());
-        final byte[] flagsByte = ByteArray.readBytes(bytes, FLAGS_F_LENGTH);
-        final BitSet flags = ByteArray.bytesToBitSet(flagsByte);
+        final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
         builder.setUnsatisfiedConstraints(flags.get(C_FLAG_OFFSET));
         bytes.skipBytes(RESERVED_F_LENGTH);
         final TlvsBuilder tlvsBuilder = new TlvsBuilder();
@@ -87,11 +84,9 @@ public class PCEPNoPathObjectParser extends AbstractObjectWithTlvsParser<TlvsBui
         final ByteBuf body = Unpooled.buffer();
         Preconditions.checkArgument(nPObj.getNatureOfIssue() != null, "NatureOfIssue is mandatory.");
         writeUnsignedByte(nPObj.getNatureOfIssue(), body);
-        final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-        if (nPObj.isUnsatisfiedConstraints() != null) {
-            flags.set(C_FLAG_OFFSET, nPObj.isUnsatisfiedConstraints());
-        }
-        writeBitSet(flags, FLAGS_F_LENGTH, body);
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(C_FLAG_OFFSET, nPObj.isUnsatisfiedConstraints());
+        flags.toByteBuf(body);
         body.writeZero(RESERVED_F_LENGTH);
         serializeTlvs(nPObj.getTlvs(), body);
         ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
index a9b6e0af06b5351d36d4a07f964bf95a48b6f609..65678023d1454f94c37b98dd50de77227c9180da 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.pcep.impl.object;
 
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.INT_BYTES_LENGTH;
@@ -13,12 +12,11 @@ import static org.opendaylight.protocol.util.ByteBufWriteUtil.INT_BYTES_LENGTH;
 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.ObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
@@ -36,7 +34,7 @@ public class PCEPProcTimeObjectParser implements ObjectParser, ObjectSerializer
     public static final int TYPE = 1;
 
     private static final int RESERVED = 2;
-    private static final int FLAGS = RESERVED;
+    private static final int FLAGS = 16;
     private static final int COUNT_FIELDS = 5;
     private static final int BODY_SIZE = RESERVED + FLAGS + COUNT_FIELDS * INT_BYTES_LENGTH;
     private static final int E_FLAG_POSITION = 15;
@@ -47,9 +45,9 @@ public class PCEPProcTimeObjectParser implements ObjectParser, ObjectSerializer
         final ProcTime procTime = (ProcTime) object;
         final ByteBuf body = Unpooled.buffer(BODY_SIZE);
         body.writeZero(RESERVED);
-        final BitSet flagBits = new BitSet(FLAGS * Byte.SIZE);
+        final BitArray flagBits = new BitArray(FLAGS);
         flagBits.set(E_FLAG_POSITION, procTime.isEstimated());
-        ByteBufWriteUtil.writeBitSet(flagBits, FLAGS, body);
+        flagBits.toByteBuf(body);
         ByteBufWriteUtil.writeUnsignedInt(procTime.getCurrentProcTime(), body);
         ByteBufWriteUtil.writeUnsignedInt(procTime.getMinProcTime(), body);
         ByteBufWriteUtil.writeUnsignedInt(procTime.getMaxProcTime(), body);
@@ -62,8 +60,8 @@ public class PCEPProcTimeObjectParser implements ObjectParser, ObjectSerializer
     public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException {
         Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
         final ProcTimeBuilder builder = new ProcTimeBuilder();
-        buffer.readBytes(RESERVED);
-        final BitSet flagBits = ByteArray.bytesToBitSet(buffer.readBytes(FLAGS).array());
+        buffer.skipBytes(RESERVED);
+        final BitArray flagBits = BitArray.valueOf(buffer, FLAGS);
         builder.setEstimated(flagBits.get(E_FLAG_POSITION));
         builder.setCurrentProcTime(buffer.readUnsignedInt());
         builder.setMinProcTime(buffer.readUnsignedInt());
index 83c0544ca06462b3df8e84bc760f6ecc91b30492..b9fc394d8dc438ffd910b462d7ceae9f3bdbbf1e 100644 (file)
@@ -8,21 +8,19 @@
 
 package org.opendaylight.protocol.pcep.impl.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import java.util.BitSet;
 import java.util.List;
 import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
@@ -47,7 +45,7 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectWithTlvsPars
     /*
      * lengths of fields in bytes
      */
-    private static final int FLAGS_PRI_MF_LENGTH = 4;
+    private static final int FLAGS_SIZE = 32;
 
     /*
      * lengths of subfields inside multi-field in bits
@@ -99,7 +97,7 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectWithTlvsPars
     @Override
     public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
         Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
-        final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(bytes, FLAGS_PRI_MF_LENGTH));
+        final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
 
         final RpBuilder builder = new RpBuilder();
         builder.setIgnore(header.isIgnore());
@@ -143,42 +141,23 @@ public class PCEPRequestParameterObjectParser extends AbstractObjectWithTlvsPars
         Preconditions.checkArgument(object instanceof Rp, "Wrong instance of PCEPObject. Passed %s. Needed RPObject.", object.getClass());
         final ByteBuf body = Unpooled.buffer();
         final Rp rpObj = (Rp) object;
-        final BitSet flags = new BitSet(FLAGS_PRI_MF_LENGTH * Byte.SIZE);
-        if (rpObj.isReoptimization() != null) {
-            flags.set(R_FLAG_OFFSET, rpObj.isReoptimization());
-        }
-        if (rpObj.isBiDirectional() != null) {
-            flags.set(B_FLAG_OFFSET, rpObj.isBiDirectional());
-        }
-        if (rpObj.isLoose() != null) {
-            flags.set(O_FLAG_OFFSET, rpObj.isLoose());
-        }
-        if (rpObj.isMakeBeforeBreak() != null) {
-            flags.set(M_FLAG_OFFSET, rpObj.isMakeBeforeBreak());
-        }
-        if (rpObj.isOrder() != null) {
-            flags.set(D_FLAG_OFFSET, rpObj.isOrder());
-        }
-        if (rpObj.isPathKey() != null) {
-            flags.set(P_FLAG_OFFSET, rpObj.isPathKey());
-        }
-        if (rpObj.isSupplyOf() != null) {
-            flags.set(S_FLAG_OFFSET, rpObj.isSupplyOf());
-        }
-        if (rpObj.isFragmentation() != null) {
-            flags.set(F_FLAG_OFFSET, rpObj.isFragmentation());
-        }
-        if (rpObj.isP2mp() != null) {
-            flags.set(N_FLAG_OFFSET, rpObj.isP2mp());
-        }
-        if (rpObj.isEroCompression() != null) {
-            flags.set(E_FLAG_OFFSET, rpObj.isEroCompression());
-        }
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(R_FLAG_OFFSET, rpObj.isReoptimization());
+        flags.set(B_FLAG_OFFSET, rpObj.isBiDirectional());
+        flags.set(O_FLAG_OFFSET, rpObj.isLoose());
+        flags.set(M_FLAG_OFFSET, rpObj.isMakeBeforeBreak());
+        flags.set(D_FLAG_OFFSET, rpObj.isOrder());
+        flags.set(P_FLAG_OFFSET, rpObj.isPathKey());
+        flags.set(S_FLAG_OFFSET, rpObj.isSupplyOf());
+        flags.set(F_FLAG_OFFSET, rpObj.isFragmentation());
+        flags.set(N_FLAG_OFFSET, rpObj.isP2mp());
+        flags.set(E_FLAG_OFFSET, rpObj.isEroCompression());
+        final byte[] res = flags.array();
         if (rpObj.getPriority() != null) {
-            final byte[] p = { 0, 0, 0, UnsignedBytes.checkedCast(rpObj.getPriority().shortValue())};
-            flags.or(ByteArray.bytesToBitSet(p));
+            final byte p = UnsignedBytes.checkedCast(rpObj.getPriority().shortValue());
+            res[res.length -1] = (byte) (res[res.length -1] | p);
         }
-        writeBitSet(flags, FLAGS_PRI_MF_LENGTH, body);
+        body.writeBytes(res);
         Preconditions.checkArgument(rpObj.getRequestId() != null, "RequestId is mandatory");
         writeUnsignedInt(rpObj.getRequestId().getValue(), body);
         serializeTlvs(rpObj.getTlvs(), body);
index 7c246339bd29ea94574aa8d55b9cd0fdcc61b66f..2512d00c57ef5d1a8bab2bff002a24702f4e1ec5 100644 (file)
@@ -7,20 +7,18 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import java.util.BitSet;
 import java.util.List;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
@@ -39,7 +37,7 @@ public class PCEPSvecObjectParser implements ObjectParser, ObjectSerializer {
     /*
      * field lengths in bytes
      */
-    private static final int FLAGS_F_LENGTH = 3;
+    private static final int FLAGS_SIZE = 24;
 
     /*
      * fields offsets in bytes
@@ -56,7 +54,7 @@ public class PCEPSvecObjectParser implements ObjectParser, ObjectSerializer {
     /*
      * min size in bytes
      */
-    private static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET;
+    private static final int MIN_SIZE = FLAGS_SIZE / Byte.SIZE + FLAGS_F_OFFSET;
 
     @Override
     public Svec parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
@@ -66,7 +64,7 @@ public class PCEPSvecObjectParser implements ObjectParser, ObjectSerializer {
                     + MIN_SIZE + ".");
         }
         bytes.skipBytes(FLAGS_F_OFFSET);
-        final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readBytes(bytes, FLAGS_F_LENGTH));
+        final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
         final List<RequestId> requestIDs = Lists.newArrayList();
 
         while (bytes.isReadable()) {
@@ -93,17 +91,11 @@ public class PCEPSvecObjectParser implements ObjectParser, ObjectSerializer {
         final Svec svecObj = (Svec) object;
         final ByteBuf body = Unpooled.buffer();
         body.writeZero(FLAGS_F_OFFSET);
-        final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-        if (svecObj.isLinkDiverse() != null) {
-            flags.set(L_FLAG_OFFSET, svecObj.isLinkDiverse());
-        }
-        if (svecObj.isNodeDiverse() != null) {
-            flags.set(N_FLAG_OFFSET, svecObj.isNodeDiverse());
-        }
-        if (svecObj.isSrlgDiverse() != null) {
-            flags.set(S_FLAG_OFFSET, svecObj.isSrlgDiverse());
-        }
-        writeBitSet(flags, FLAGS_F_LENGTH, body);
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(L_FLAG_OFFSET, svecObj.isLinkDiverse());
+        flags.set(N_FLAG_OFFSET, svecObj.isNodeDiverse());
+        flags.set(S_FLAG_OFFSET, svecObj.isSrlgDiverse());
+        flags.toByteBuf(body);
 
         final List<RequestId> requestIDs = svecObj.getRequestsIds();
         assert !(requestIDs.isEmpty()) : "Empty Svec Object - no request ids.";
index f6344ec633a7a336b232cf3de167af1a02543d88..b772daf5dabcb4650df19b999112a8dd01729169 100644 (file)
@@ -10,13 +10,12 @@ package org.opendaylight.protocol.pcep.impl.subobject;
 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.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
 import org.opendaylight.protocol.pcep.spi.LabelRegistry;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.LabelCase;
@@ -29,13 +28,11 @@ public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobject
 
     public static final int TYPE = 3;
 
-    private static final int RES_F_LENGTH = 1;
+    private static final int FLAGS_SIZE = 8;
 
     private static final int C_TYPE_F_LENGTH = 1;
 
-    private static final int RES_F_OFFSET = 0;
-
-    private static final int C_TYPE_F_OFFSET = RES_F_OFFSET + RES_F_LENGTH;
+    private static final int C_TYPE_F_OFFSET = FLAGS_SIZE / Byte.SIZE;
 
     private static final int HEADER_LENGTH = C_TYPE_F_OFFSET + C_TYPE_F_LENGTH;
 
@@ -54,7 +51,7 @@ public class EROLabelSubobjectParser implements EROSubobjectParser, EROSubobject
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
                     + HEADER_LENGTH + ".");
         }
-        final BitSet reserved = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, RES_F_LENGTH));
+        final BitArray reserved = BitArray.valueOf(buffer, FLAGS_SIZE);
         final short cType = buffer.readUnsignedByte();
 
         final LabelType labelType = this.registry.parseLabel(cType, buffer.slice());
index 0e0788cf08b4234f584ef96a2cf7dc8b4c1fd189..85ecd63e0831569a6e30f7d38224e460612153a4 100644 (file)
@@ -7,17 +7,16 @@
  */
 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;
@@ -36,11 +35,11 @@ public class RROIpv4PrefixSubobjectParser implements RROSubobjectParser, RROSubo
     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;
@@ -56,7 +55,7 @@ public class RROIpv4PrefixSubobjectParser implements RROSubobjectParser, RROSubo
         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());
@@ -72,17 +71,13 @@ public class RROIpv4PrefixSubobjectParser implements RROSubobjectParser, RROSubo
         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);
         }
     }
index edd17c9683bd35a9b38309eff59171f4d94a83b4..b39d22f1f7e485fd0555b6991acc56b7bfbb5bdb 100644 (file)
@@ -7,17 +7,16 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Prefix;
 
 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.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
@@ -36,11 +35,11 @@ public class RROIpv6PrefixSubobjectParser implements RROSubobjectParser, RROSubo
     public static final int TYPE = 2;
 
     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 PREFIX_F_OFFSET = Ipv6Util.IPV6_LENGTH;
 
-    private static final int CONTENT_LENGTH = Ipv6Util.IPV6_LENGTH + PREFIX_F_LENGTH + FLAGS_F_LENGTH;
+    private static final int CONTENT_LENGTH = Ipv6Util.IPV6_LENGTH + PREFIX_F_LENGTH + FLAGS_SIZE / Byte.SIZE;
 
     private static final int LPA_F_OFFSET = 7;
     private static final int LPIU_F_OFFSET = 6;
@@ -56,7 +55,7 @@ public class RROIpv6PrefixSubobjectParser implements RROSubobjectParser, RROSubo
         final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(buffer,
                 Ipv6Util.IPV6_LENGTH), length)));
         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()).build());
@@ -68,17 +67,13 @@ public class RROIpv6PrefixSubobjectParser implements RROSubobjectParser, RROSubo
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
         final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
         final IpPrefix prefix = specObj.getIpPrefix();
-        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(CONTENT_LENGTH);
         Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
         writeIpv6Prefix(prefix.getIpv6Prefix(), body);
-        writeBitSet(flags, FLAGS_F_LENGTH, body);
+        flags.toByteBuf(body);
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
     }
 }
index 2187fe5cc33da7b0892ae51c7b2040c6fdf589ee..b7da1446b7590a51082447659d7816a459c556bf 100644 (file)
@@ -10,13 +10,12 @@ package org.opendaylight.protocol.pcep.impl.subobject;
 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.LabelRegistry;
 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.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
@@ -29,13 +28,11 @@ public class RROLabelSubobjectParser implements RROSubobjectParser, RROSubobject
 
     public static final int TYPE = 3;
 
-    public static final int RES_F_LENGTH = 1;
+    public static final int FLAGS_SIZE = 8;
 
     public static final int C_TYPE_F_LENGTH = 1;
 
-    public static final int RES_F_OFFSET = 0;
-
-    public static final int C_TYPE_F_OFFSET = RES_F_OFFSET + RES_F_LENGTH;
+    public static final int C_TYPE_F_OFFSET = FLAGS_SIZE / Byte.SIZE;
 
     public static final int HEADER_LENGTH = C_TYPE_F_OFFSET + C_TYPE_F_LENGTH;
 
@@ -55,7 +52,7 @@ public class RROLabelSubobjectParser implements RROSubobjectParser, RROSubobject
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >"
                     + HEADER_LENGTH + ".");
         }
-        final BitSet reserved = ByteArray.bytesToBitSet(ByteArray.readBytes(buffer, RES_F_LENGTH));
+        final BitArray reserved = BitArray.valueOf(buffer, FLAGS_SIZE);
 
         final short cType = buffer.readUnsignedByte();
 
index 07306296077dfdfa6cddfbbe81bb1e9a671c52a5..18b5471fb4bda171d3b4bf6be756f61754d9b125 100644 (file)
@@ -7,18 +7,16 @@
  */
 package org.opendaylight.protocol.pcep.impl.subobject;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
 
 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.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.Subobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject;
@@ -33,7 +31,7 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser
 
     public static final int TYPE = 4;
 
-    private static final int FLAGS_F_LENGTH = 1;
+    private static final int FLAGS_SIZE = 8;
     private static final int RESERVED = 1;
 
     private static final int CONTENT_LENGTH = 10;
@@ -49,7 +47,7 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser
                     + CONTENT_LENGTH + ".");
         }
         final SubobjectBuilder builder = new SubobjectBuilder();
-        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));
         final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
@@ -64,15 +62,11 @@ public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser
     public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
         Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase, "Unknown subobject instance. Passed %s. Needed UnnumberedCase.", subobject.getSubobjectType().getClass());
         final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
-        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(CONTENT_LENGTH);
-        writeBitSet(flags, FLAGS_F_LENGTH, body);
+        flags.toByteBuf(body);
         body.writeZero(RESERVED);
         Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
         writeUnsignedInt(specObj.getRouterId(), body);
index 84ad0f116e05c866bc74208ffb90630662208f37..f8822f8efb60a1fdbfdf62e7acbba3914a19e6b5 100644 (file)
@@ -10,13 +10,11 @@ package org.opendaylight.protocol.pcep.impl.tlv;
 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.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
 import org.opendaylight.protocol.pcep.spi.TlvUtil;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.ByteBufWriteUtil;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags;
 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.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVector;
@@ -29,7 +27,7 @@ public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
 
     public static final int TYPE = 1;
 
-    private static final int FLAGS_F_LENGTH = 4;
+    private static final int FLAGS_SIZE = 32;
 
     private static final int REACHABLITY_PROBLEM = 24;
     private static final int NO_GCO_SOLUTION = 25;
@@ -45,11 +43,11 @@ public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
         if (buffer == null) {
             return null;
         }
-        if (buffer.readableBytes() != FLAGS_F_LENGTH) {
+        if (buffer.readableBytes() != FLAGS_SIZE / Byte.SIZE) {
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: >="
-                    + FLAGS_F_LENGTH + ".");
+                    + FLAGS_SIZE / Byte.SIZE + ".");
         }
-        final BitSet flags = ByteArray.bytesToBitSet(ByteArray.readAllBytes(buffer));
+        final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
         return new NoPathVectorBuilder().setFlags(
                 new Flags(flags.get(CHAIN_UNAVAILABLE), flags.get(NO_GCO_MIGRATION_PATH), flags.get(NO_GCO_SOLUTION), flags.get(REACHABLITY_PROBLEM), flags.get(PATH_KEY), flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC))).build();
     }
@@ -59,33 +57,17 @@ public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
         Preconditions.checkArgument(tlv instanceof NoPathVector, "NoPathVectorTlv is mandatory.");
         final NoPathVector noPath = (NoPathVector) tlv;
         final ByteBuf body = Unpooled.buffer();
-        final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-        Flags f = noPath.getFlags();
-        if (f.isP2mpUnreachable() != null) {
-            flags.set(REACHABLITY_PROBLEM, f.isP2mpUnreachable());
-        }
-        if (f.isNoGcoSolution() != null) {
-            flags.set(NO_GCO_SOLUTION, f.isNoGcoSolution());
-        }
-        if (f.isNoGcoMigration() != null) {
-            flags.set(NO_GCO_MIGRATION_PATH, f.isNoGcoMigration());
-        }
-        if (f.isPathKey() != null) {
-            flags.set(PATH_KEY, f.isPathKey());
-        }
-        if (f.isChainUnavailable() != null) {
-            flags.set(CHAIN_UNAVAILABLE, f.isChainUnavailable());
-        }
-        if (f.isUnknownSource() != null) {
-            flags.set(UNKNOWN_SRC, f.isUnknownSource());
-        }
-        if (f.isUnknownDestination() != null) {
-            flags.set(UNKNOWN_DEST, f.isUnknownDestination());
-        }
-        if (f.isPceUnavailable() != null) {
-            flags.set(PCE_UNAVAILABLE, f.isPceUnavailable());
-        }
-        ByteBufWriteUtil.writeBitSet(flags, FLAGS_F_LENGTH, body);
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        final Flags f = noPath.getFlags();
+        flags.set(REACHABLITY_PROBLEM, f.isP2mpUnreachable());
+        flags.set(NO_GCO_SOLUTION, f.isNoGcoSolution());
+        flags.set(NO_GCO_MIGRATION_PATH, f.isNoGcoMigration());
+        flags.set(PATH_KEY, f.isPathKey());
+        flags.set(CHAIN_UNAVAILABLE, f.isChainUnavailable());
+        flags.set(UNKNOWN_SRC, f.isUnknownSource());
+        flags.set(UNKNOWN_DEST, f.isUnknownDestination());
+        flags.set(PCE_UNAVAILABLE, f.isPceUnavailable());
+        flags.toByteBuf(body);
         TlvUtil.formatTlv(TYPE, body, buffer);
     }
 }
index c124e7e649953ec90ad326bbd4ea1dfb42424af8..717d865d0d072079b8c263dcb22988b292306573 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.pcep.segment.routing;
 
 import static org.opendaylight.protocol.pcep.segment.routing.SrSubobjectParserUtil.BITSET_LENGTH;
@@ -13,11 +12,11 @@ import static org.opendaylight.protocol.pcep.segment.routing.SrSubobjectParserUt
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
-import java.util.BitSet;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrEroSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.add.lsp.input.arguments.ero.subobject.subobject.type.SrEroTypeBuilder;
@@ -45,19 +44,14 @@ public class SrEroSubobjectParser implements EROSubobjectParser, EROSubobjectSer
         if (srEroSubobject.isMFlag() != null && srEroSubobject.isMFlag() && srEroSubobject.getSid() != null) {
             builder.setSid(srEroSubobject.getSid() << MPLS_LABEL_OFFSET);
         }
-
-        final BitSet bits = new BitSet(BITSET_LENGTH);
-        if (srEroSubobject.isMFlag() != null) {
-            bits.set(M_FLAG_POSITION, srEroSubobject.isMFlag());
-        }
-        if (srEroSubobject.isCFlags() != null) {
-            bits.set(C_FLAG_POSITION, srEroSubobject.isCFlags());
-        }
+        final BitArray bits = new BitArray(BITSET_LENGTH);
+        bits.set(M_FLAG_POSITION, srEroSubobject.isMFlag());
+        bits.set(C_FLAG_POSITION, srEroSubobject.isCFlags());
         if (srEroSubobject.getSid() == null) {
-            bits.set(S_FLAG_POSITION);
+            bits.set(S_FLAG_POSITION, Boolean.TRUE);
         }
         if (srEroSubobject.getNai() == null) {
-            bits.set(F_FLAG_POSITION);
+            bits.set(F_FLAG_POSITION, Boolean.TRUE);
         }
         final ByteBuf body = SrSubobjectParserUtil.serializeSrSubobject(builder.build(), bits);
         EROSubobjectUtil.formatSubobject(TYPE, subobject.isLoose(), body, buffer);
@@ -70,11 +64,10 @@ public class SrEroSubobjectParser implements EROSubobjectParser, EROSubobjectSer
         if (buffer.readableBytes() <= SrSubobjectParserUtil.MINIMAL_LENGTH) {
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
         }
-
-        final BitSet flags = new BitSet(BITSET_LENGTH);
-        final SrSubobject srSubobject = SrSubobjectParserUtil.parseSrSubobject(buffer, new Function<BitSet, Void>() {
+        final BitArray flags = new BitArray(BITSET_LENGTH);
+        final SrSubobject srSubobject = SrSubobjectParserUtil.parseSrSubobject(buffer, new Function<BitArray, Void>() {
             @Override
-            public Void apply(final BitSet input) {
+            public Void apply(final BitArray input) {
                 flags.set(C_FLAG_POSITION, input.get(C_FLAG_POSITION));
                 flags.set(M_FLAG_POSITION, input.get(M_FLAG_POSITION));
                 return null;
@@ -86,7 +79,6 @@ public class SrEroSubobjectParser implements EROSubobjectParser, EROSubobjectSer
         if (srEroSubobjectBuilder.isMFlag() != null && srEroSubobjectBuilder.isMFlag() && srEroSubobjectBuilder.getSid() != null) {
             srEroSubobjectBuilder.setSid(srEroSubobjectBuilder.getSid() >> MPLS_LABEL_OFFSET);
         }
-
         final SubobjectBuilder subobjectBuilder = new SubobjectBuilder();
         subobjectBuilder.setLoose(loose);
         subobjectBuilder.setSubobjectType(srEroSubobjectBuilder.build());
index 8496698b50ffbdb8db134dc088d290f93f79eacf..eae3b391e28e00e61b5a505e4ce2325a3f966978 100644 (file)
@@ -14,11 +14,11 @@ import static org.opendaylight.protocol.pcep.segment.routing.SrSubobjectParserUt
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
-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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrRroSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.SrSubobject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev150112.add.lsp.input.arguments.rro.subobject.subobject.type.SrRroTypeBuilder;
@@ -39,12 +39,12 @@ public class SrRroSubobjectParser implements RROSubobjectParser, RROSubobjectSer
                         .getClass());
 
         final SrRroSubobject srRroSubobject = (SrRroSubobject) subobject.getSubobjectType();
-        final BitSet bits = new BitSet(BITSET_LENGTH);
+        final BitArray bits = new BitArray(BITSET_LENGTH);
         if (srRroSubobject.getSid() == null) {
-            bits.set(S_FLAG_POSITION);
+            bits.set(S_FLAG_POSITION, Boolean.TRUE);
         }
         if (srRroSubobject.getNai() == null) {
-            bits.set(F_FLAG_POSITION);
+            bits.set(F_FLAG_POSITION, Boolean.TRUE);
         }
         final ByteBuf body = SrSubobjectParserUtil.serializeSrSubobject(srRroSubobject, bits);
         RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
@@ -58,9 +58,9 @@ public class SrRroSubobjectParser implements RROSubobjectParser, RROSubobjectSer
             throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
         }
 
-        final SrSubobject srSubobject = SrSubobjectParserUtil.parseSrSubobject(buffer, new Function<BitSet, Void>() {
+        final SrSubobject srSubobject = SrSubobjectParserUtil.parseSrSubobject(buffer, new Function<BitArray, Void>() {
             @Override
-            public Void apply(final BitSet input) {
+            public Void apply(final BitArray input) {
                 return null;
             }
         }, F_FLAG_POSITION, S_FLAG_POSITION);
index da03eecaffb8660e4a6c119980676d65c9175ff7..df604152e332bffcc1c136f2dbf2439c5c8c79e0 100644 (file)
@@ -5,10 +5,8 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.pcep.segment.routing;
 
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedByte;
@@ -18,9 +16,8 @@ import com.google.common.base.Function;
 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.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
@@ -42,20 +39,18 @@ final class SrSubobjectParserUtil {
     public static final int MINIMAL_LENGTH = 4;
     public static final int BITSET_LENGTH = 8;
 
-    private static final int FLAGS_OFFSET = 1;
     private static final int SID_TYPE_BITS_OFFSET = 4;
 
     private SrSubobjectParserUtil() {
         throw new UnsupportedOperationException();
     }
 
-    public static ByteBuf serializeSrSubobject(final SrSubobject srSubobject, final BitSet bits) {
+    public static ByteBuf serializeSrSubobject(final SrSubobject srSubobject, final BitArray bits) {
         Preconditions.checkArgument(srSubobject.getNai() != null || srSubobject.getSid() != null,
                 "Both SID and NAI are absent in SR subobject.");
         final ByteBuf body = Unpooled.buffer(MINIMAL_LENGTH);
         writeUnsignedByte((short)(srSubobject.getSidType().getIntValue() << SID_TYPE_BITS_OFFSET), body);
-
-        writeBitSet(bits, FLAGS_OFFSET, body);
+        bits.toByteBuf(body);
 
         if (srSubobject.getSid() != null) {
             writeUnsignedInt(srSubobject.getSid(), body);
@@ -91,12 +86,12 @@ final class SrSubobjectParserUtil {
         return body;
     }
 
-    public static SrSubobject parseSrSubobject(final ByteBuf buffer, final Function<BitSet, Void> getFlags, final int fPosition, final int sPosition)
+    public static SrSubobject parseSrSubobject(final ByteBuf buffer, final Function<BitArray, Void> getFlags, final int fPosition, final int sPosition)
             throws PCEPDeserializerException {
         final int sidTypeByte = buffer.readByte() >> SID_TYPE_BITS_OFFSET;
         final SidType sidType = SidType.forValue(sidTypeByte);
 
-        final BitSet bitSet = ByteArray.bytesToBitSet(new byte[] { buffer.readByte() });
+        final BitArray bitSet = BitArray.valueOf(buffer.readByte());
         getFlags.apply(bitSet);
         final boolean f = bitSet.get(fPosition);
         final boolean s = bitSet.get(sPosition);
index 93d548cd056a47cdd76eaa097e532d0cd34c5289..e4929b2aa7488b813546f465b440c13310ee4546 100644 (file)
@@ -13,10 +13,10 @@ import com.google.common.primitives.UnsignedBytes;
 import io.netty.buffer.ByteBuf;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.BitSet;
 import java.util.Collections;
 import java.util.List;
 import javax.annotation.Nullable;
+import org.opendaylight.protocol.util.BitArray;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder;
@@ -37,17 +37,15 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer
     private static final int COMMON_OBJECT_HEADER_LENGTH = 4;
 
     private static final int OT_SF_LENGTH = 4;
-    private static final int FLAGS_SF_LENGTH = 4;
     /*
      * offsets of fields inside of multi-field in bits
      */
     private static final int OT_SF_OFFSET = 0;
-    private static final int FLAGS_SF_OFFSET = OT_SF_OFFSET + OT_SF_LENGTH;
     /*
      * flags offsets inside multi-filed
      */
-    private static final int P_FLAG_OFFSET = 6;
-    private static final int I_FLAG_OFFSET = 7;
+    private static final int PROCESSED = 6;
+    private static final int IGNORED = 7;
 
     private final ObjectRegistry registry;
     private final VendorInformationObjectRegistry viRegistry;
@@ -85,10 +83,8 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer
             final int objClass = bytes.readUnsignedByte();
 
             final byte flagsByte = bytes.readByte();
+            final BitArray flags = BitArray.valueOf(flagsByte);
             final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(flagsByte, OT_SF_OFFSET, OT_SF_LENGTH));
-            final byte[] flagsBytes = { ByteArray.copyBitsRange(flagsByte, FLAGS_SF_OFFSET, FLAGS_SF_LENGTH) };
-            final BitSet flags = ByteArray.bytesToBitSet(flagsBytes);
-
             final int objLength = bytes.readUnsignedShort();
 
             if (bytes.readableBytes() < objLength - COMMON_OBJECT_HEADER_LENGTH) {
@@ -98,7 +94,7 @@ public abstract class AbstractMessageParser implements MessageParser, MessageSer
             // copy bytes for deeper parsing
             final ByteBuf bytesToPass = bytes.readSlice(objLength - COMMON_OBJECT_HEADER_LENGTH);
 
-            final ObjectHeader header = new ObjectHeaderImpl(flags.get(P_FLAG_OFFSET), flags.get(I_FLAG_OFFSET));
+            final ObjectHeader header = new ObjectHeaderImpl(flags.get(PROCESSED), flags.get(IGNORED));
 
             if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) {
                 Preconditions.checkState(this.viRegistry != null);
index ec9a33a1e5a0052001c6b9f592e7fe704211e9c1..1144a8b22f059f738c71985d4912903d422c5dc2 100644 (file)
@@ -8,30 +8,24 @@
 package org.opendaylight.protocol.pcep.spi;
 
 import io.netty.buffer.ByteBuf;
-import java.util.BitSet;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 
 public final class LabelUtil {
 
-    private static final int RES_F_LENGTH = 1;
+    private static final int FLAGS_SIZE = 8;
 
-    private static final int U_FLAG_OFFSET = 0;
-
-    private static final int G_FLAG_OFFSET = 7;
+    private static final int UNIDIRECTIONAL = 0;
+    private static final int GLOBAL = 7;
 
     private LabelUtil() {
         throw new UnsupportedOperationException();
     }
 
     public static void formatLabel(final int type, final Boolean unidirectional, final Boolean global, final ByteBuf body, final ByteBuf buffer) {
-        final BitSet reserved = new BitSet(RES_F_LENGTH * Byte.SIZE);
-        if (unidirectional != null) {
-            reserved.set(U_FLAG_OFFSET, unidirectional);
-        }
-        if (global != null) {
-            reserved.set(G_FLAG_OFFSET, global);
-        }
-        buffer.writeBytes(ByteArray.bitSetToBytes(reserved, RES_F_LENGTH));
+        final BitArray reserved = new BitArray(FLAGS_SIZE);
+        reserved.set(UNIDIRECTIONAL, unidirectional);
+        reserved.set(GLOBAL, global);
+        reserved.toByteBuf(buffer);
         buffer.writeByte(type);
         buffer.writeBytes(body);
     }
index f96b9ad71447f3803e5aa17d8f8a26c78c5ab3c2..86f6779422b4e67c744cb0d25c9ad726f8ad6c2d 100644 (file)
@@ -8,19 +8,18 @@
 package org.opendaylight.protocol.pcep.spi;
 
 import io.netty.buffer.ByteBuf;
-import java.util.BitSet;
-import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.BitArray;
 
 public final class ObjectUtil {
 
     private static final int HEADER_SIZE = 4;
 
-    private static final int OT_SF_LENGTH = 4;
+    private static final int FLAGS_SIZE = 4;
     /*
      * flags offsets inside multi-field
      */
-    private static final int P_FLAG_OFFSET = 6;
-    private static final int I_FLAG_OFFSET = 7;
+    private static final int PROCESSED = 2;
+    private static final int IGNORED = 3;
 
     private ObjectUtil() {
         throw new UnsupportedOperationException();
@@ -29,15 +28,11 @@ public final class ObjectUtil {
     public static void formatSubobject(final int objectType, final int objectClass, final Boolean processingRule, final Boolean ignore,
         final ByteBuf body, final ByteBuf out) {
         out.writeByte(objectClass);
-        BitSet flags = new BitSet(Byte.SIZE);
-        if (ignore != null) {
-            flags.set(I_FLAG_OFFSET, ignore);
-        }
-        if (processingRule != null) {
-            flags.set(P_FLAG_OFFSET, processingRule);
-        }
-        byte[] flagB = ByteArray.bitSetToBytes(flags, 1);
-        int typeByte = objectType << OT_SF_LENGTH | flagB[0];
+        final BitArray flags = new BitArray(FLAGS_SIZE);
+        flags.set(IGNORED, ignore);
+        flags.set(PROCESSED, processingRule);
+        final byte flagB = flags.toByte();
+        final int typeByte = objectType << FLAGS_SIZE | flagB;
         out.writeByte(typeByte);
         out.writeShort(body.writerIndex() + HEADER_SIZE);
         out.writeBytes(body);