Merge changes I0f764a60,I5f7eff95
authorRobert Varga <rovarga@cisco.com>
Mon, 18 Aug 2014 12:09:12 +0000 (12:09 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 18 Aug 2014 12:09:12 +0000 (12:09 +0000)
* changes:
  Fixed PCE's remote and local address
  Bug-1516: Introduce PCC mock.

bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAdjRIBsInTest.java
util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java
util/src/main/java/org/opendaylight/protocol/util/PCEPHexDumpParser.java
util/src/test/java/org/opendaylight/protocol/util/IPAddressesAndPrefixesTest.java

index dbf27d185fe2310d2ab38225ec4600a1bfdaa8ba..b107038443c292892118af2df7ff3b8f25f6315f 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.protocol.bgp.linkstate;
 
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.Lists;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
@@ -36,6 +39,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NlriType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.LinkstateRoute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.LinkstateRouteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.LinkCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.NodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.PrefixCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.node._case.NodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.prefix._case.AdvertisingNodeDescriptorsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.isis.lan.identifier.IsIsRouterIdentifierBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestination;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.CLinkstateDestinationBuilder;
@@ -45,6 +55,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptorsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.OriginBuilder;
@@ -100,7 +111,7 @@ public class LinkstateAdjRIBsInTest extends AbstractDataBrokerTest {
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
         final InstanceIdentifier<Rib> iid = InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test-rib"))).toInstance();
         final KeyedInstanceIdentifier<Tables, TablesKey> key = iid.child(LocRib.class).child(Tables.class, new TablesKey(LinkstateAddressFamily.class,
-                LinkstateSubsequentAddressFamily.class));
+            LinkstateSubsequentAddressFamily.class));
 
         Mockito.doAnswer(new Answer<Void>() {
             @SuppressWarnings("unchecked")
@@ -140,7 +151,7 @@ public class LinkstateAdjRIBsInTest extends AbstractDataBrokerTest {
             }
         }).when(this.adjRibTx).setUptodate(Matchers.<InstanceIdentifier<Tables>>any(), Mockito.anyBoolean());
 
-        Mockito.doReturn(bgpComparator).when(this.adjRibTx).comparator();
+        Mockito.doReturn(this.bgpComparator).when(this.adjRibTx).comparator();
 
         Mockito.doReturn(iid).when(this.rib).getInstanceIdentifier();
         Mockito.doReturn("test").when(this.peer).toString();
@@ -157,13 +168,13 @@ public class LinkstateAdjRIBsInTest extends AbstractDataBrokerTest {
     public void testAddPrefix() {
         this.dBuilder.setNlriType(NlriType.Ipv4Prefix);
         this.dBuilder.setPrefixDescriptors(new PrefixDescriptorsBuilder().setIpReachabilityInformation(
-                new IpPrefix(new Ipv4Prefix("12.34.35.55/32"))).build());
+            new IpPrefix(new Ipv4Prefix("12.34.35.55/32"))).build());
         this.destinations.add(this.dBuilder.build());
         this.builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
-                new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
-                        new DestinationLinkstateBuilder().setCLinkstateDestination(this.destinations).build()).build()).build());
+            new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                new DestinationLinkstateBuilder().setCLinkstateDestination(this.destinations).build()).build()).build());
 
-        PathAttributesBuilder pa = new PathAttributesBuilder();
+        final PathAttributesBuilder pa = new PathAttributesBuilder();
         pa.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
 
         this.lrib.addRoutes(this.adjRibTx, this.peer, this.builder.build(), pa.build());
@@ -176,13 +187,13 @@ public class LinkstateAdjRIBsInTest extends AbstractDataBrokerTest {
     public void testAddNode() {
         this.dBuilder.setNlriType(NlriType.Node);
         this.dBuilder.setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder().setCRouterIdentifier(
-                new IsisPseudonodeCaseBuilder().setIsisPseudonode(
-                        new IsisPseudonodeBuilder().setIsIsRouterIdentifier(
-                                new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 1, 2, 3, 4, 5, 6 })).build()).build()).build()).build());
+            new IsisPseudonodeCaseBuilder().setIsisPseudonode(
+                new IsisPseudonodeBuilder().setIsIsRouterIdentifier(
+                    new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 1, 2, 3, 4, 5, 6 })).build()).build()).build()).build());
         this.destinations.add(this.dBuilder.build());
         this.builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
-                new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
-                        new DestinationLinkstateBuilder().setCLinkstateDestination(this.destinations).build()).build()).build());
+            new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                new DestinationLinkstateBuilder().setCLinkstateDestination(this.destinations).build()).build()).build());
 
         final PathAttributesBuilder pa = new PathAttributesBuilder();
         pa.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
@@ -197,15 +208,15 @@ public class LinkstateAdjRIBsInTest extends AbstractDataBrokerTest {
     public void testAddRemoveLink() {
         this.dBuilder.setNlriType(NlriType.Link);
         this.dBuilder.setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder().setCRouterIdentifier(
-                new IsisPseudonodeCaseBuilder().setIsisPseudonode(
-                        new IsisPseudonodeBuilder().setIsIsRouterIdentifier(
-                                new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 1, 2, 3, 4, 5, 6 })).build()).build()).build()).build());
+            new IsisPseudonodeCaseBuilder().setIsisPseudonode(
+                new IsisPseudonodeBuilder().setIsIsRouterIdentifier(
+                    new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 1, 2, 3, 4, 5, 6 })).build()).build()).build()).build());
         this.dBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
-                new Ipv4InterfaceIdentifier(new Ipv4Address("127.0.0.1"))).build());
+            new Ipv4InterfaceIdentifier(new Ipv4Address("127.0.0.1"))).build());
         this.destinations.add(this.dBuilder.build());
         this.builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
-                new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
-                        new DestinationLinkstateBuilder().setCLinkstateDestination(this.destinations).build()).build()).build());
+            new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                new DestinationLinkstateBuilder().setCLinkstateDestination(this.destinations).build()).build()).build());
 
         final PathAttributesBuilder pa = new PathAttributesBuilder();
         pa.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
@@ -219,11 +230,53 @@ public class LinkstateAdjRIBsInTest extends AbstractDataBrokerTest {
         builder.setAfi(LinkstateAddressFamily.class);
         builder.setSafi(LinkstateSubsequentAddressFamily.class);
         builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
-                        new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
-                                this.destinations).build()).build()).build());
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
+                    this.destinations).build()).build()).build());
         this.lrib.removeRoutes(this.adjRibTx, this.peer, builder.build());
 
         Mockito.verify(this.adjRibTx, Mockito.times(1)).withdraw(Mockito.<RouteEncoder>any(), Mockito.any(), Matchers.<InstanceIdentifier<Route>>any());
     }
+
+    @Test
+    public void testAddAdvertisement() {
+        final PrefixCaseBuilder pcb = new PrefixCaseBuilder();
+        pcb.setAdvertisingNodeDescriptors(new AdvertisingNodeDescriptorsBuilder().build());
+        pcb.setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1"))).build();
+        LinkstateRoute data = new LinkstateRouteBuilder().setObjectType(pcb.build()).build();
+        final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
+        this.lrib.addAdvertisement(mpBuilder, data);
+        final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mpBuilder.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
+        assertEquals(NlriType.Ipv4Prefix, dests.get(0).getNlriType());
+
+        final NodeCaseBuilder ncb = new NodeCaseBuilder();
+        ncb.setNodeDescriptors(new NodeDescriptorsBuilder().build());
+        data = new LinkstateRouteBuilder().setObjectType(ncb.build()).build();
+        this.lrib.addAdvertisement(mpBuilder, data);
+        assertEquals(2, dests.size());
+        assertEquals(NlriType.Node, dests.get(1).getNlriType());
+
+        final LinkCaseBuilder lcb = new LinkCaseBuilder();
+        lcb.setLocalNodeDescriptors(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.link._case.LocalNodeDescriptorsBuilder().build());
+        lcb.setRemoteNodeDescriptors(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.link._case.RemoteNodeDescriptorsBuilder().build());
+        lcb.setLinkDescriptors(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.link._case.LinkDescriptorsBuilder().build());
+        data = new LinkstateRouteBuilder().setObjectType(lcb.build()).build();
+        this.lrib.addAdvertisement(mpBuilder, data);
+        assertEquals(3, dests.size());
+        assertEquals(NlriType.Link, dests.get(2).getNlriType());
+    }
+
+    @Test
+    public void testAddWithdrawal() {
+        this.dBuilder.setNlriType(NlriType.Node);
+        final MpUnreachNlriBuilder paBuilder = new MpUnreachNlriBuilder().setWithdrawnRoutes(
+            new WithdrawnRoutesBuilder().setDestinationType(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+                    new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
+                        Lists.newArrayList(this.dBuilder.build())).build()).build()).build());
+
+        final MpUnreachNlriBuilder mpUBuilder = new MpUnreachNlriBuilder();
+        this.lrib.addWithdrawal(mpUBuilder, this.dBuilder.build());
+        assertEquals(paBuilder.build(), mpUBuilder.build());
+    }
 }
index cc35b22f8538956aab25e55871059711a7592442..86968fb4e2d4fd2059c3d8cb451cc85c67565c47 100644 (file)
@@ -12,16 +12,13 @@ import com.google.common.collect.Lists;
 import com.google.common.net.InetAddresses;
 import com.google.common.primitives.Bytes;
 import com.google.common.primitives.UnsignedBytes;
-
 import io.netty.buffer.ByteBuf;
-
 import java.net.Inet6Address;
 import java.net.InetAddress;
 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.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
 
@@ -29,6 +26,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
  * Util class for creating generated Ipv6Address.
  */
 public final class Ipv6Util {
+
     private Ipv6Util() {
     }
 
@@ -82,10 +80,10 @@ public final class Ipv6Util {
     }
 
     /**
-     * Converts Ipv6Prefix to byte array.
+     * Converts Ipv6Prefix to byte array. Prefix length at the end.
      *
      * @param prefix Ipv6Prefix to be converted
-     * @return byte array
+     * @return byte array with prefix length at the end
      */
     public static byte[] bytesForPrefix(final Ipv6Prefix prefix) {
         final String p = prefix.getValue();
@@ -137,7 +135,6 @@ public final class Ipv6Util {
         if (bytes.length == 0) {
             return Collections.emptyList();
         }
-
         final List<Ipv6Prefix> list = Lists.newArrayList();
         int byteOffset = 0;
         while (byteOffset < bytes.length) {
index dd20b7ae6ecbac676546983da64a902190253067..7b6218edf6fd888ce221c13285899d3264a19a87 100644 (file)
@@ -46,8 +46,6 @@ public final class PCEPHexDumpParser {
         Preconditions.checkNotNull(is);
         try (InputStreamReader isr = new InputStreamReader(is)) {
             return parseMessages(CharStreams.toString(isr));
-        } finally {
-            is.close();
         }
     }
 
index b7106749d7aaf54c310664d1fff4e2d7092a6aca..5866c6c48d7b626ecd774a4dd8309a71d095e872 100644 (file)
@@ -13,6 +13,8 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
 import com.google.common.collect.Lists;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import java.net.UnknownHostException;
 import java.util.List;
 import org.junit.Test;
@@ -54,6 +56,18 @@ public class IPAddressesAndPrefixesTest {
         assertArrayEquals(new byte[] { (byte) 255, (byte) 255, 0, 0, 16 }, Ipv4Util.bytesForPrefix(new Ipv4Prefix("255.255.0.0/16")));
     }
 
+    @Test
+    public void testBytesForPrefix4Begin() {
+        byte[] bytes = new byte[] { 123, 122, 4, 5 };
+        assertEquals(new Ipv4Prefix("123.122.4.5/8"), Ipv4Util.prefixForBytes(bytes, 8));
+        assertArrayEquals(new byte[] { 8, 102 }, Ipv4Util.bytesForPrefixBegin(new Ipv4Prefix("102.0.0.0/8")));
+
+        bytes = new byte[] { (byte) 255, (byte) 255, 0, 0 };
+        assertEquals(new Ipv4Prefix("255.255.0.0/16"), Ipv4Util.prefixForBytes(bytes, 16));
+
+        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 };
@@ -80,12 +94,10 @@ public class IPAddressesAndPrefixesTest {
     }
 
     @Test
-    public void testPrefixList4ForBytes() {
-        final byte[] bytes = new byte[] { 22, (byte) 172, (byte) 168, 3, 8, 12, 32, (byte) 192, (byte) 168, 35, 100 };
-        final List<Ipv4Prefix> prefs = Ipv4Util.prefixListForBytes(bytes);
-        assertEquals(
-                Lists.newArrayList(new Ipv4Prefix("172.168.3.0/22"), new Ipv4Prefix("12.0.0.0/8"), new Ipv4Prefix("192.168.35.100/32")),
-                prefs);
+    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 } );
+        assertEquals(new Ipv4Address("123.122.4.5"), Ipv4Util.addressForByteBuf(bb));
+        assertEquals(new Ipv6Address("2001::1"), Ipv6Util.addressForByteBuf(bb));
     }
 
     @Test
@@ -103,6 +115,28 @@ public class IPAddressesAndPrefixesTest {
             0x00, 0x00, 0x40 }, Ipv6Util.bytesForPrefix(new Ipv6Prefix("2001:db8:1:2::/64")));
     }
 
+    @Test
+    public void testBytesForPrefix6Begin() {
+        final byte[] bytes = new byte[] { 0x20, 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02 };
+        assertEquals(new Ipv6Prefix("2001:db8:1:2::/64"), Ipv6Util.prefixForBytes(bytes, 64));
+        assertArrayEquals(new byte[] { 0x40, 0x20, (byte) 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02 }, Ipv6Util.bytesForPrefixBegin(new Ipv6Prefix("2001:db8:1:2::/64")));
+    }
+
+    @Test
+    public void testPrefixLength() {
+        assertEquals(8, Ipv4Util.getPrefixLengthBytes("2001:db8:1:2::/64"));
+        assertEquals(3, Ipv4Util.getPrefixLengthBytes("172.168.3.0/22"));
+    }
+
+    @Test
+    public void testPrefixList4ForBytes() {
+        final byte[] bytes = new byte[] { 22, (byte) 172, (byte) 168, 3, 8, 12, 32, (byte) 192, (byte) 168, 35, 100 };
+        final List<Ipv4Prefix> prefs = Ipv4Util.prefixListForBytes(bytes);
+        assertEquals(
+            Lists.newArrayList(new Ipv4Prefix("172.168.3.0/22"), new Ipv4Prefix("12.0.0.0/8"), new Ipv4Prefix("192.168.35.100/32")),
+            prefs);
+    }
+
     @Test
     public void testPrefixList6ForBytes() {
         final byte[] bytes = new byte[] { 0x40, 0x20, 0x01, 0x0d, (byte) 0xb8, 0x00, 0x01, 0x00, 0x02, 0x40, 0x20, 0x01, 0x0d, (byte) 0xb8,
@@ -110,10 +144,4 @@ public class IPAddressesAndPrefixesTest {
         final List<Ipv6Prefix> prefs = Ipv6Util.prefixListForBytes(bytes);
         assertEquals(prefs, Lists.newArrayList(new Ipv6Prefix("2001:db8:1:2::/64"), new Ipv6Prefix("2001:db8:1:1::/64")));
     }
-
-    @Test
-    public void testPrefixLength() {
-        assertEquals(22, Ipv4Util.getPrefixLength(new IpPrefix(new Ipv4Prefix("172.168.3.0/22"))));
-        assertEquals(64, Ipv4Util.getPrefixLength(new IpPrefix(new Ipv6Prefix("2001:db8:1:2::/64"))));
-    }
 }