Removed obsolete methods from Ipv4/Ipv6Util. 23/12523/2
authorDana Kutenicsova <dkutenic@cisco.com>
Wed, 5 Nov 2014 14:50:35 +0000 (15:50 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Wed, 5 Nov 2014 15:23:12 +0000 (16:23 +0100)
Change-Id: I79a7d82840a989418dc9216b522b8d3fdc4d77cd
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
13 files changed:
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ExtendedCommunitiesAttributeParser.java
pcep/ietf-stateful02/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful02/Stateful02RSVPErrorSpecTlvParser.java
pcep/ietf-stateful02/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPTlvParserTest.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv4TlvParser.java
pcep/ietf-stateful07/src/main/java/org/opendaylight/protocol/pcep/ietf/stateful07/Stateful07LSPIdentifierIpv6TlvParser.java
pcep/ietf-stateful07/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPObjectParserTest.java
pcep/ietf-stateful07/src/test/java/org/opendaylight/protocol/pcep/ietf/PCEPTlvParserTest.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIpv4ObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsIpv6ObjectParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java
util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java
util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java
util/src/test/java/org/opendaylight/protocol/util/IPAddressesAndPrefixesTest.java

index 38b5f60aee910700c38e9087e4a52a3ad8a7c51a..c176f5993be13c31684e4ec5207b32e0015fb5a8 100644 (file)
@@ -155,14 +155,14 @@ public final class ExtendedCommunitiesAttributeParser implements AttributeParser
             } else {
                 c = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
                     new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
-                            Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH))).setLocalAdministrator(
+                            Ipv4Util.addressForByteBuf(buffer)).setLocalAdministrator(
                             ByteArray.readBytes(buffer, INET_LOCAL_ADMIN_LENGTH)).build()).build();
             }
             break;
         case INET_TYPE_NON_TRANS:
             c = new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
                 new Inet4SpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(
-                        Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH))).setLocalAdministrator(
+                        Ipv4Util.addressForByteBuf(buffer)).setLocalAdministrator(
                         ByteArray.readBytes(buffer, INET_LOCAL_ADMIN_LENGTH)).build()).build();
             break;
         case OPAQUE_TYPE_TRANS:
index 31e47fab39bb2c4f58375dd0d9d9cc33fdcbf5e5..dd8e26e19239c184c7e6171f755aaef120cdbdd0 100644 (file)
@@ -55,9 +55,9 @@ public final class Stateful02RSVPErrorSpecTlvParser implements TlvParser, TlvSer
         }
         final RsvpErrorBuilder builder = new RsvpErrorBuilder();
         if (buffer.readableBytes() == V4_RSVP_LENGTH) {
-            builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH))));
+            builder.setNode(new IpAddress(Ipv4Util.addressForByteBuf(buffer)));
         } else if (buffer.readableBytes() == V6_RSVP_LENGTH) {
-            builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH))));
+            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)));
@@ -75,7 +75,7 @@ public final class Stateful02RSVPErrorSpecTlvParser implements TlvParser, TlvSer
         final RsvpError rsvp = rsvpTlv.getRsvpError();
         final ByteBuf body = Unpooled.buffer();
         final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-        Flags f = rsvp.getFlags();
+        final Flags f = rsvp.getFlags();
         if (f.isInPlace() != null) {
             flags.set(IN_PLACE_FLAG_OFFSET, f.isInPlace());
         }
index 72e0a64629b22c7f5aeceb250146d7bab233b950..cfe3242ef9dcf3d94bc1035c6f9fe7d46dd9d079 100644 (file)
@@ -73,7 +73,7 @@ public class PCEPTlvParserTest {
     @Test
     public void testNodeIdentifier() throws PCEPDeserializerException {
         final Stateful02NodeIdentifierTlvParser parser = new Stateful02NodeIdentifierTlvParser();
-        NodeIdentifier tlv = new NodeIdentifierBuilder().setNodeId(
+        final NodeIdentifier tlv = new NodeIdentifierBuilder().setNodeId(
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.NodeIdentifier(ByteArray.subByte(
                         nodeIdentifierBytes, 4, 25))).build();
         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.subByte(nodeIdentifierBytes, 4, 25))));
@@ -86,7 +86,7 @@ public class PCEPTlvParserTest {
     public void testRSVPError4SpecTlv() throws PCEPDeserializerException {
         final Stateful02RSVPErrorSpecTlvParser parser = new Stateful02RSVPErrorSpecTlvParser();
         final RsvpErrorBuilder builder = new RsvpErrorBuilder();
-        builder.setNode(new IpAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
+        builder.setNode(new IpAddress(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))));
         builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
         builder.setCode((short) 146);
         builder.setValue(5634);
@@ -101,9 +101,9 @@ public class PCEPTlvParserTest {
     public void testRSVPError6SpecTlv() throws PCEPDeserializerException {
         final Stateful02RSVPErrorSpecTlvParser parser = new Stateful02RSVPErrorSpecTlvParser();
         final RsvpErrorBuilder builder = new RsvpErrorBuilder();
-        builder.setNode(new IpAddress(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+        builder.setNode(new IpAddress(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
             (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a,
-            (byte) 0xbc, (byte) 0xde, (byte) 0xf0 })));
+            (byte) 0xbc, (byte) 0xde, (byte) 0xf0 }))));
         builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
         builder.setCode((short) 213);
         builder.setValue(50649);
index c6df883afe22f5e7a3acca6587d40ae505b353ed..d15d4a8c63d558a4199d2f3f1e656b9ebb20d9b2 100644 (file)
@@ -18,7 +18,6 @@ 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.Ipv4Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
@@ -53,12 +52,11 @@ public final class Stateful07LSPIdentifierIpv4TlvParser implements TlvParser, Tl
             throw new IllegalArgumentException("Length " + buffer.readableBytes() + " does not match LSP Identifiers Ipv4 tlv length.");
         }
         final Ipv4Builder builder = new Ipv4Builder();
-        builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH)));
+        builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(buffer));
         final LspId lspId = new LspId((long) buffer.readUnsignedShort());
         final TunnelId tunnelId = new TunnelId(buffer.readUnsignedShort());
-        builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer,
-                EX_TUNNEL_ID4_F_LENGTH))));
-        builder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH)));
+        builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForByteBuf(buffer)));
+        builder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(buffer));
         final AddressFamily afi = new Ipv4CaseBuilder().setIpv4(builder.build()).build();
         return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
     }
index 8c44ccd0839a71b04c639aa17e8c89e1679a3d5c..d625d2fab9dd4105db0ff1132de9fb54a64fe10f 100644 (file)
@@ -18,7 +18,6 @@ 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.Ipv6Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
@@ -39,8 +38,6 @@ public final class Stateful07LSPIdentifierIpv6TlvParser implements TlvParser, Tl
 
     public static final int TYPE = 19;
 
-    private static final int EX_TUNNEL_ID6_F_LENGTH = 16;
-
     private static final int V6_LENGTH = 52;
 
     @Override
@@ -52,12 +49,11 @@ public final class Stateful07LSPIdentifierIpv6TlvParser implements TlvParser, Tl
             throw new IllegalArgumentException("Length " + buffer.readableBytes() + " does not match LSP Identifiers Ipv6 tlv length.");
         }
         final Ipv6Builder builder = new Ipv6Builder();
-        builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH)));
+        builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForByteBuf(buffer));
         final LspId lspId = new LspId((long) buffer.readUnsignedShort());
         final TunnelId tunnelId = new TunnelId(buffer.readUnsignedShort());
-        builder.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(ByteArray.readBytes(buffer,
-                EX_TUNNEL_ID6_F_LENGTH))));
-        builder.setIpv6TunnelEndpointAddress(Ipv6Util.addressForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH)));
+        builder.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForByteBuf(buffer)));
+        builder.setIpv6TunnelEndpointAddress(Ipv6Util.addressForByteBuf(buffer));
         final AddressFamily afi = new Ipv6CaseBuilder().setIpv6(builder.build()).build();
         return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
     }
index 2165b21c6e5e984ee854d1c96ea476530d2e2a6b..ddd650acd43a4b22f51e80809975bde933ddb388 100644 (file)
@@ -99,7 +99,7 @@ public class PCEPObjectParserTest {
                 Tlvs1.class, statBuilder.build()).build());
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
     }
@@ -150,14 +150,14 @@ public class PCEPObjectParserTest {
         final SymbolicPathName tlv2 = new SymbolicPathNameBuilder().setPathName(
                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName("Med".getBytes())).build();
         final Ipv4Builder afi = new Ipv4Builder();
-        afi.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }));
-        afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
-            (byte) 0x78 })));
-        afi.setIpv4TunnelEndpointAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }));
+        afi.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
+        afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
+            (byte) 0x78 }))));
+        afi.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
         final LspIdentifiers tlv3 = new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(afi.build()).build()).setLspId(
             new LspId(65535L)).setTunnelId(new TunnelId(4660)).build();
         final RsvpErrorBuilder rsvpBuilder = new RsvpErrorBuilder();
-        rsvpBuilder.setNode(new IpAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
+        rsvpBuilder.setNode(new IpAddress(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))));
         rsvpBuilder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
         rsvpBuilder.setCode((short) 146);
         rsvpBuilder.setValue(5634);
@@ -198,7 +198,7 @@ public class PCEPObjectParserTest {
         assertEquals(tlv, ((Lspa) o).getTlvs().getAugmentation(Tlvs2.class).getSymbolicPathName());
         // assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), ByteArray.cutBytes(result,
         // 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
     }
@@ -217,7 +217,7 @@ public class PCEPObjectParserTest {
         builder.setTlvs(new TlvsBuilder().build());
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4)));
-        ByteBuf buf = Unpooled.buffer();
+        final ByteBuf buf = Unpooled.buffer();
         parser.serializeObject(builder.build(), buf);
         assertArrayEquals(result.array(),ByteArray.getAllBytes(buf));
     }
index 7550e1e391bc4dd36373b8dbd07f09390d9bded8..6e0dd6b66bad4ad47cdd3d04b6eb81f2db42f18b 100644 (file)
@@ -104,10 +104,10 @@ public class PCEPTlvParserTest {
     public void testLspIdentifiers4Tlv() throws PCEPDeserializerException {
         final Stateful07LSPIdentifierIpv4TlvParser parser = new Stateful07LSPIdentifierIpv4TlvParser();
         final Ipv4Builder afi = new Ipv4Builder();
-        afi.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }));
-        afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
-            (byte) 0x78 })));
-        afi.setIpv4TunnelEndpointAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }));
+        afi.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
+        afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
+            (byte) 0x78 }))));
+        afi.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
         final LspIdentifiers tlv = new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(afi.build()).build()).setLspId(
             new LspId(65535L)).setTunnelId(new TunnelId(4660)).build();
         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(lspIdentifiers4Bytes, 4))));
@@ -120,15 +120,15 @@ public class PCEPTlvParserTest {
     public void testLspIdentifiers6Tlv() throws PCEPDeserializerException {
         final Stateful07LSPIdentifierIpv6TlvParser parser = new Stateful07LSPIdentifierIpv6TlvParser();
         final Ipv6Builder afi = new Ipv6Builder();
-        afi.setIpv6TunnelSenderAddress(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+        afi.setIpv6TunnelSenderAddress(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
             (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A,
-            (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 }));
-        afi.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
+            (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 })));
+        afi.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
             (byte) 0x78, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67,
-            (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67 })));
-        afi.setIpv6TunnelEndpointAddress(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+            (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67 }))));
+        afi.setIpv6TunnelEndpointAddress(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
             (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A,
-            (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 }));
+            (byte) 0xBC, (byte) 0xDE, (byte) 0xF0 })));
         final LspIdentifiers tlv = new LspIdentifiersBuilder().setAddressFamily(new Ipv6CaseBuilder().setIpv6(afi.build()).build()).setLspId(
             new LspId(4660L)).setTunnelId(new TunnelId(65535)).build();
         assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(lspIdentifiers6Bytes, 4))));
@@ -141,7 +141,7 @@ public class PCEPTlvParserTest {
     public void testRSVPError4SpecTlv() throws PCEPDeserializerException {
         final Stateful07RSVPErrorSpecTlvParser parser = new Stateful07RSVPErrorSpecTlvParser();
         final RsvpErrorBuilder builder = new RsvpErrorBuilder();
-        builder.setNode(new IpAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
+        builder.setNode(new IpAddress(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))));
         builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
         builder.setCode((short) 146);
         builder.setValue(5634);
@@ -156,9 +156,9 @@ public class PCEPTlvParserTest {
     public void testRSVPError6SpecTlv() throws PCEPDeserializerException {
         final Stateful07RSVPErrorSpecTlvParser parser = new Stateful07RSVPErrorSpecTlvParser();
         final RsvpErrorBuilder builder = new RsvpErrorBuilder();
-        builder.setNode(new IpAddress(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+        builder.setNode(new IpAddress(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
             (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a,
-            (byte) 0xbc, (byte) 0xde, (byte) 0xf0 })));
+            (byte) 0xbc, (byte) 0xde, (byte) 0xf0 }))));
         builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
         builder.setCode((short) 213);
         builder.setValue(50649);
index 1185fdd38043231a0078d520204c78b8a2a846a2..04df6390aa3bf8462cb1e7c0f5e08f6f0a4ef4c4 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
 import org.opendaylight.protocol.pcep.spi.UnknownObject;
-import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.Ipv4Util;
 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;
@@ -57,8 +56,8 @@ public class PCEPEndPointsIpv4ObjectParser implements ObjectParser, ObjectSerial
         builder.setIgnore(header.isIgnore());
         builder.setProcessingRule(header.isProcessingRule());
         final Ipv4Builder b = new Ipv4Builder();
-        b.setSourceIpv4Address(Ipv4Util.addressForBytes(ByteArray.readBytes(bytes, Ipv4Util.IP4_LENGTH)));
-        b.setDestinationIpv4Address((Ipv4Util.addressForBytes(ByteArray.readBytes(bytes, Ipv4Util.IP4_LENGTH))));
+        b.setSourceIpv4Address(Ipv4Util.addressForByteBuf(bytes));
+        b.setDestinationIpv4Address((Ipv4Util.addressForByteBuf(bytes)));
         builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(b.build()).build());
         return builder.build();
     }
index 22adcd6e887a7cd18ce103031394a8f0c82f8609..f5267ce742bdc853f5c5b45a0f8189a341da158a 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
 import org.opendaylight.protocol.pcep.spi.UnknownObject;
-import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.Ipv6Util;
 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;
@@ -57,8 +56,8 @@ public class PCEPEndPointsIpv6ObjectParser implements ObjectParser, ObjectSerial
         builder.setIgnore(header.isIgnore());
         builder.setProcessingRule(header.isProcessingRule());
         final Ipv6Builder b = new Ipv6Builder();
-        b.setSourceIpv6Address(Ipv6Util.addressForBytes(ByteArray.readBytes(bytes, Ipv6Util.IPV6_LENGTH)));
-        b.setDestinationIpv6Address((Ipv6Util.addressForBytes(ByteArray.readBytes(bytes, Ipv6Util.IPV6_LENGTH))));
+        b.setSourceIpv6Address(Ipv6Util.addressForByteBuf(bytes));
+        b.setDestinationIpv6Address(Ipv6Util.addressForByteBuf(bytes));
         builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(b.build()).build());
         return builder.build();
     }
index f5d277b7e0e3d49270a0c0cdd8927707d86209f2..dbcb54d79f401651999de25274132a3f48389593 100644 (file)
@@ -424,8 +424,8 @@ public class PCEPObjectParserTest {
         builder.setProcessingRule(true);
         builder.setIgnore(false);
         builder.setAddressFamily(new Ipv4CaseBuilder().setIpv4(
-                new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForBytes(srcIPBytes)).setDestinationIpv4Address(
-                        Ipv4Util.addressForBytes(destIPBytes)).build()).build());
+                new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv4Address(
+                        Ipv4Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
         final ByteBuf buf = Unpooled.buffer();
@@ -460,8 +460,8 @@ public class PCEPObjectParserTest {
         builder.setProcessingRule(true);
         builder.setIgnore(false);
         builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(
-                new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForBytes(srcIPBytes)).setDestinationIpv6Address(
-                        Ipv6Util.addressForBytes(destIPBytes)).build()).build());
+                new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(srcIPBytes))).setDestinationIpv6Address(
+                        Ipv6Util.addressForByteBuf(Unpooled.wrappedBuffer(destIPBytes))).build()).build());
 
         assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result.slice(4, result.readableBytes() - 4)));
         final ByteBuf buf = Unpooled.buffer();
index c75ba5d9c680746a01ec663c525b5a024f45bc82..1bbbc00e3fd2d3e31d22b8eaa30ca791a12e6aa8 100644 (file)
@@ -19,7 +19,6 @@ import java.net.UnknownHostException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 
@@ -49,16 +48,6 @@ public final class Ipv4Util {
         }
     }
 
-    /**
-     * Converts byte array to Ipv4Address.
-     *
-     * @param bytes to be converted to Ipv4Address
-     * @return Ipv4Address
-     */
-    public static Ipv4Address addressForBytes(final byte[] bytes) {
-        return new Ipv4Address(InetAddresses.toAddrString(getAddress(bytes)));
-    }
-
     /**
      * Reads from ByteBuf buffer and converts bytes to Ipv4Address.
      *
@@ -66,7 +55,7 @@ public final class Ipv4Util {
      * @return Ipv4Address
      */
     public static Ipv4Address addressForByteBuf(final ByteBuf buffer) {
-        return addressForBytes(ByteArray.readBytes(buffer, IP4_LENGTH));
+        return new Ipv4Address(InetAddresses.toAddrString(getAddress(ByteArray.readBytes(buffer, IP4_LENGTH))));
     }
 
     /**
@@ -87,23 +76,12 @@ public final class Ipv4Util {
      * @param prefix
      * @return
      */
-    public static int getPrefixLengthBytes(final String prefix) {
+    protected static int getPrefixLengthBytes(final String prefix) {
         final int bits = Ipv4Util.getPrefixLength(prefix);
-        if (bits % 8 != 0) {
-            return (bits / 8) + 1;
+        if (bits % Byte.SIZE != 0) {
+            return (bits / Byte.SIZE) + 1;
         }
-        return bits / 8;
-    }
-
-    /**
-     * Converts Ipv4Prefix to byte array of length equal to prefix length value.
-     *
-     * @param ipv4Prefix Ipv4Prefix to be converted
-     * @return byte array
-     */
-    public static byte[] bytesForPrefixByPrefixLength(final Ipv4Prefix ipv4Prefix) {
-        return ByteArray.subByte(bytesForPrefix(ipv4Prefix), 0,
-            getPrefixLengthBytes(ipv4Prefix.getValue()));
+        return bits / Byte.SIZE;
     }
 
     /**
@@ -174,29 +152,13 @@ public final class Ipv4Util {
         return list;
     }
 
-    /**
-     * Obtains prefix length from given prefix.
-     *
-     * @param prefix
-     * @return prefix length
-     */
-    public static int getPrefixLength(final IpPrefix prefix) {
-        String p = "";
-        if (prefix.getIpv4Prefix() != null) {
-            p = prefix.getIpv4Prefix().getValue();
-        } else {
-            p = prefix.getIpv6Prefix().getValue();
-        }
-        return getPrefixLength(p);
-    }
-
     /**
      * Obtains prefix length from given string prefix.
      *
      * @param prefixValue value of prefix
      * @return prefix length
      */
-    public static int getPrefixLength(final String prefixValue) {
+    protected static int getPrefixLength(final String prefixValue) {
         final int sep = prefixValue.indexOf('/');
         return Integer.parseInt(prefixValue.substring(sep + 1, prefixValue.length()));
     }
index e2eb54299f5af0a58ed4bf22dc0cb19a9605c0c3..a0267206bb9da5d5b721bdeb0cef5df15ca349cf 100644 (file)
@@ -48,16 +48,6 @@ public final class Ipv6Util {
         }
     }
 
-    /**
-     * Converts byte array to Ipv6Address.
-     *
-     * @param bytes to be converted to Ipv6Address
-     * @return Ipv6Address
-     */
-    public static Ipv6Address addressForBytes(final byte[] bytes) {
-        return new Ipv6Address(InetAddresses.toAddrString(getAddress(bytes)));
-    }
-
     /**
      * Reads from ByteBuf buffer and converts bytes to Ipv6Address.
      *
@@ -65,7 +55,7 @@ public final class Ipv6Util {
      * @return Ipv4Address
      */
     public static Ipv6Address addressForByteBuf(final ByteBuf buffer) {
-        return addressForBytes(ByteArray.readBytes(buffer, IPV6_LENGTH));
+        return new Ipv6Address(InetAddresses.toAddrString(getAddress((ByteArray.readBytes(buffer, IPV6_LENGTH)))));
     }
 
     /**
index c45108985d5c30feaf2aea67f28a5b93a8824db1..87a1ed18462bafc2d72c7c55136e62f4aeca7016 100644 (file)
@@ -79,31 +79,6 @@ public class IPAddressesAndPrefixesTest {
         assertArrayEquals(new byte[] { 16, (byte) 255, (byte) 255 }, Ipv4Util.bytesForPrefixBegin(new Ipv4Prefix("255.255.0.0/16")));
     }
 
-    @Test
-    public void testAddress4ForBytes() {
-        final byte[] bytes = new byte[] { (byte) 123, (byte) 122, (byte) 4, (byte) 5 };
-        assertEquals(new Ipv4Address("123.122.4.5"), Ipv4Util.addressForBytes(bytes));
-        try {
-            Ipv4Util.addressForBytes(new byte[] { 22, 44, 66, 18, 88, 33 });
-            fail();
-        } catch (final IllegalArgumentException e) {
-            assertEquals("Failed to construct IPv4 address", e.getMessage());
-        }
-    }
-
-    @Test
-    public void testAddress6ForBytes() {
-        final byte[] bytes = new byte[] { 0x20, (byte) 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-            0x01 };
-        assertEquals(new Ipv6Address("2001::1"), Ipv6Util.addressForBytes(bytes));
-        try {
-            Ipv6Util.addressForBytes(new byte[] { 22, 44, 66, 18, 88, 33 });
-            fail();
-        } catch (final IllegalArgumentException e) {
-            assertEquals("Failed to construct IPv6 address", e.getMessage());
-        }
-    }
-
     @Test
     public void testAddressForByteBuf() {
         final ByteBuf bb = Unpooled.wrappedBuffer(new byte[] { 123, 122, 4, 5, 0x20, (byte) 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } );