Change the type of some leafs to uint32 31/4531/1
authorRobert Varga <rovarga@cisco.com>
Tue, 21 Jan 2014 19:20:28 +0000 (20:20 +0100)
committerRobert Varga <rovarga@cisco.com>
Tue, 21 Jan 2014 21:55:53 +0000 (22:55 +0100)
These were four-byte entities, which are specified to be "32-bit
integers" in their specification.

Change-Id: Ibfaa7317e8034645311a6f0dddd53d6809f11f15
Signed-off-by: Robert Varga <rovarga@cisco.com>
bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParser.java
bgp/linkstate/src/main/yang/bgp-linkstate.yang
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/LinkstateTopologyBuilder.java
bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/UriBuilder.java
util/src/main/java/org/opendaylight/protocol/util/ByteArray.java

index 13dcb493a686512d615bb0c885867635b402c655..413beb6917299f07c44b7deed7fa96cce87c9379 100644 (file)
@@ -74,6 +74,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
+import com.google.common.primitives.UnsignedInteger;
 
 public final class LinkstateNlriParser implements NlriParser {
        private static final Logger LOG = LoggerFactory.getLogger(LinkstateNlriParser.class);
@@ -118,8 +119,8 @@ public final class LinkstateNlriParser implements NlriParser {
                        LOG.trace("Parsing Link Descriptor: {}", Arrays.toString(value));
                        switch (type) {
                        case TlvCode.LINK_LR_IDENTIFIERS:
-                               builder.setLinkLocalIdentifier(ByteArray.subByte(value, 0, 4));
-                               builder.setLinkRemoteIdentifier(ByteArray.subByte(value, 4, 4));
+                               builder.setLinkLocalIdentifier(ByteArray.bytesToUint32(ByteArray.subByte(value, 0, 4)).longValue());
+                               builder.setLinkRemoteIdentifier(ByteArray.bytesToUint32(ByteArray.subByte(value, 4, 4)).longValue());
                                LOG.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
                                                builder.getLinkRemoteIdentifier());
                                break;
@@ -176,11 +177,11 @@ public final class LinkstateNlriParser implements NlriParser {
                                LOG.debug("Parsed {}", asnumber);
                                break;
                        case TlvCode.BGP_LS_ID:
-                               bgpId = new DomainIdentifier(value);
+                               bgpId = new DomainIdentifier(UnsignedInteger.fromIntBits(ByteArray.bytesToInt(value)).longValue());
                                LOG.debug("Parsed {}", bgpId);
                                break;
                        case TlvCode.AREA_ID:
-                               ai = new AreaIdentifier(value);
+                               ai = new AreaIdentifier(UnsignedInteger.fromIntBits(ByteArray.bytesToInt(value)).longValue());
                                LOG.debug("Parsed area identifier {}", ai);
                                break;
                        case TlvCode.IGP_ROUTER_ID:
@@ -216,13 +217,13 @@ public final class LinkstateNlriParser implements NlriParser {
                        }
                }
                if (value.length == 4) {
-                       return new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(ByteArray.subByte(value, 0, 4)).build()).build();
+                       return new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(ByteArray.bytesToUint32(value).longValue()).build()).build();
                }
                if (value.length == 8) {
                        final byte[] o = ByteArray.subByte(value, 0, 4);
-                       final OspfInterfaceIdentifier a = new OspfInterfaceIdentifier(ByteArray.subByte(value, 4, 4));
+                       final OspfInterfaceIdentifier a = new OspfInterfaceIdentifier(ByteArray.bytesToUint32(ByteArray.subByte(value, 4, 4)).longValue());
                        return new OspfPseudonodeCaseBuilder().setOspfPseudonode(
-                                       new OspfPseudonodeBuilder().setOspfRouterId(o).setLanInterface(a).build()).build();
+                                       new OspfPseudonodeBuilder().setOspfRouterId(ByteArray.bytesToUint32(o).longValue()).setLanInterface(a).build()).build();
                }
                throw new BGPParsingException("Router Id of invalid length " + value.length);
        }
@@ -429,17 +430,17 @@ public final class LinkstateNlriParser implements NlriParser {
                if (descriptors.getAsNumber() != null) {
                        buffer.writeShort(TlvCode.AS_NUMBER);
                        buffer.writeShort(length);
-                       buffer.writeBytes(ByteArray.longToBytes(descriptors.getAsNumber().getValue(), length));
+                       buffer.writeBytes(ByteArray.uint32ToBytes(descriptors.getAsNumber().getValue()));
                }
                if (descriptors.getDomainId() != null) {
                        buffer.writeShort(TlvCode.BGP_LS_ID);
                        buffer.writeShort(length);
-                       buffer.writeBytes(descriptors.getDomainId().getValue());
+                       buffer.writeBytes(ByteArray.uint32ToBytes(descriptors.getDomainId().getValue()));
                }
                if (descriptors.getAreaId() != null) {
                        buffer.writeShort(TlvCode.AREA_ID);
                        buffer.writeShort(length);
-                       buffer.writeBytes(descriptors.getAreaId().getValue());
+                       buffer.writeBytes(ByteArray.uint32ToBytes(descriptors.getAreaId().getValue()));
                }
                if (descriptors.getCRouterIdentifier() != null) {
                        final byte[] value = serializeRouterId(descriptors.getCRouterIdentifier());
@@ -461,24 +462,22 @@ public final class LinkstateNlriParser implements NlriParser {
                        ByteArray.copyWhole(isis.getIsIsRouterIdentifier().getIsoSystemId().getValue(), bytes, 0);
                        bytes[6] = UnsignedBytes.checkedCast((isis.getPsn() != null) ? isis.getPsn() : 0);
                } else if (routerId instanceof OspfNodeCase) {
-                       bytes = ((OspfNodeCase) routerId).getOspfNode().getOspfRouterId();
+                       bytes = ByteArray.uint32ToBytes(((OspfNodeCase) routerId).getOspfNode().getOspfRouterId());
                } else if (routerId instanceof OspfPseudonodeCase) {
                        final OspfPseudonode node = ((OspfPseudonodeCase) routerId).getOspfPseudonode();
-                       bytes = new byte[node.getOspfRouterId().length + node.getLanInterface().getValue().length];
-                       ByteArray.copyWhole(node.getOspfRouterId(), bytes, 0);
-                       ByteArray.copyWhole(node.getLanInterface().getValue(), bytes, node.getOspfRouterId().length);
+                       bytes = new byte[2 * Integer.SIZE / Byte.SIZE];
+                       ByteArray.copyWhole(ByteArray.uint32ToBytes(node.getOspfRouterId()), bytes, 0);
+                       ByteArray.copyWhole(ByteArray.uint32ToBytes(node.getLanInterface().getValue()), bytes, Integer.SIZE / Byte.SIZE);
                }
                return bytes;
        }
 
        private static void serializeLinkDescriptors(final ByteBuf buffer, final LinkDescriptors descriptors) {
                if (descriptors.getLinkLocalIdentifier() != null && descriptors.getLinkRemoteIdentifier() != null) {
-                       final byte[] localId = descriptors.getLinkLocalIdentifier();
-                       final byte[] remoteId = descriptors.getLinkRemoteIdentifier();
                        buffer.writeShort(TlvCode.LINK_LR_IDENTIFIERS);
-                       buffer.writeShort(localId.length + remoteId.length);
-                       buffer.writeBytes(localId);
-                       buffer.writeBytes(remoteId);
+                       buffer.writeShort(8);
+                       buffer.writeInt(UnsignedInteger.valueOf(descriptors.getLinkLocalIdentifier()).intValue());
+                       buffer.writeInt(UnsignedInteger.valueOf(descriptors.getLinkRemoteIdentifier()).intValue());
                }
                if (descriptors.getIpv4InterfaceAddress() != null) {
                        final byte[] ipv4Address = Ipv4Util.bytesForAddress(descriptors.getIpv4InterfaceAddress());
index 26587992773b59a9334471827efd0cbaecde6747..86e3f5a24d45e0d9dbd2773aaf29a6e041871c14 100644 (file)
@@ -125,16 +125,12 @@ module bgp-linkstate {
 
        typedef domain-identifier {
                reference "https://tools.ietf.org/html/draft-ietf-idr-ls-distribution-03#section-3.2.1.4";
-               type binary {
-                       length "4";
-               }
+               type uint32;
        }
 
        typedef area-identifier {
                reference "https://tools.ietf.org/html/draft-ietf-idr-ls-distribution-03#section-3.2.1.4";
-               type binary {
-                       length "4";
-               }
+               type uint32;
        }
 
        typedef ipv4-interface-identifier {
@@ -149,9 +145,7 @@ module bgp-linkstate {
 
        typedef ospf-interface-identifier {
                reference "https://tools.ietf.org/html/draft-ietf-idr-ls-distribution-03#section-3.2.1.4";
-               type binary {
-                       length "4";
-               }
+               type uint32;
        }
 
        typedef topology-identifier {
@@ -186,9 +180,7 @@ module bgp-linkstate {
        grouping ospf-router-identifier {
                reference "https://tools.ietf.org/html/draft-ietf-idr-ls-distribution-03#section-3.2.1.4";
                leaf ospf-router-id {
-                       type binary {
-                               length "4";
-                       }
+                       type uint32;
                        mandatory true;
                }
        }
@@ -251,14 +243,10 @@ module bgp-linkstate {
        grouping link-lr-identifiers {
                reference "http://tools.ietf.org/html/rfc5307";
                leaf link-local-identifier {
-                       type binary {
-                               length "4";
-                       }
+                       type uint32;
                }
                leaf link-remote-identifier {
-                       type binary {
-                               length "4";
-                       }
+                       type uint32;
                }
        }
 
index 1ed914fab8bfe007fc8ca63e1a341b290a44354e..015a91c2506705cfd3cfdae700b56469b0599f09 100644 (file)
@@ -87,7 +87,7 @@ public class LinkstateNlriParserTest {
 
                final LocalNodeDescriptors nodeD = dest.getLocalNodeDescriptors();
                assertEquals(new AsNumber(72L), nodeD.getAsNumber());
-               assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), nodeD.getDomainId());
+               assertEquals(new DomainIdentifier(0x28282828L), nodeD.getDomainId());
                assertEquals(
                                new IsisNodeCaseBuilder().setIsisNode(
                                                new IsisNodeBuilder().setIsoSystemId(
@@ -120,7 +120,7 @@ public class LinkstateNlriParserTest {
 
                final LocalNodeDescriptors local = dest.getLocalNodeDescriptors();
                assertEquals(new AsNumber(72L), local.getAsNumber());
-               assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), local.getDomainId());
+               assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
                assertEquals(
                                new IsisNodeCaseBuilder().setIsisNode(
                                                new IsisNodeBuilder().setIsoSystemId(
@@ -128,7 +128,7 @@ public class LinkstateNlriParserTest {
                                                                                (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
                final RemoteNodeDescriptors remote = dest.getRemoteNodeDescriptors();
                assertEquals(new AsNumber(72L), remote.getAsNumber());
-               assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), remote.getDomainId());
+               assertEquals(new DomainIdentifier(0x28282828L), remote.getDomainId());
                assertEquals(
                                new IsisNodeCaseBuilder().setIsisNode(
                                                new IsisNodeBuilder().setIsoSystemId(
@@ -162,7 +162,7 @@ public class LinkstateNlriParserTest {
 
                final LocalNodeDescriptors local = dest.getLocalNodeDescriptors();
                assertEquals(new AsNumber(72L), local.getAsNumber());
-               assertEquals(new DomainIdentifier(new byte[] { (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28 }), local.getDomainId());
+               assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
                assertEquals(
                                new IsisNodeCaseBuilder().setIsisNode(
                                                new IsisNodeBuilder().setIsoSystemId(
index 04b30078aba015188d46bee9d09250f4d02d7d4f..682e6da6b3cfee051f37fef204152723ab19ac8d 100644 (file)
@@ -856,12 +856,10 @@ public class BGPParserTest {
                final List<Segments> asPath = Lists.newArrayList();
 
                final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
-                               new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
-                               new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+                               new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
 
                final RemoteNodeDescriptorsBuilder rndBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
-                               new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
-                               new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+                               new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
 
                final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
                clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
@@ -877,30 +875,30 @@ public class BGPParserTest {
                final List<CLinkstateDestination> linkstates = Lists.newArrayList();
                clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
                                new OspfPseudonodeCaseBuilder().setOspfPseudonode(
-                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
-                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+                                               new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(
+                                                               new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
                clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
-                               new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
+                               new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
                clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
                                new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
                linkstates.add(clBuilder.build());
 
                clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
                                new OspfPseudonodeCaseBuilder().setOspfPseudonode(
-                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
-                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+                                               new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(
+                                                               new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
                clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
-                               new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+                               new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
                clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
                                new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
                linkstates.add(clBuilder.build());
 
                clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
-                               new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+                               new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
                clBuilder.setRemoteNodeDescriptors(rndBuilder.setCRouterIdentifier(
                                new OspfPseudonodeCaseBuilder().setOspfPseudonode(
-                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
-                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+                                               new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(
+                                                               new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
                clBuilder.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
                                new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
                linkstates.add(clBuilder.build());
@@ -971,7 +969,7 @@ public class BGPParserTest {
                04 <- next hop length
                19 19 19 01 - nexthop (25.25.25.1)
                00 <- reserved
-               
+
                00 01 <- NLRI type (1 - nodeNLRI)
                00 31 <- NLRI length (49)
                03 <- ProtocolID - OSPF
@@ -1060,8 +1058,8 @@ public class BGPParserTest {
                                new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
 
                final LocalNodeDescriptorsBuilder lndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(
-                               new DomainIdentifier(new byte[] { (byte) 0x19, (byte) 0x19, (byte) 0x19, (byte) 0x01 })).setAreaId(
-                               new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+                               new DomainIdentifier(0x19191901L)).setAreaId(
+                                               new AreaIdentifier(0L));
 
                final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
                clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
@@ -1071,16 +1069,16 @@ public class BGPParserTest {
                final List<CLinkstateDestination> linkstates = Lists.newArrayList();
                clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
                                new OspfPseudonodeCaseBuilder().setOspfPseudonode(
-                                               new OspfPseudonodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).setLanInterface(
-                                                               new OspfInterfaceIdentifier(new byte[] { 0x0b, 0x0b, 0x0b, 0x03 })).build()).build()).build());
+                                               new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(
+                                                               new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
                linkstates.add(clBuilder.build());
 
                clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
-                               new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 3, 3, 3, 4 }).build()).build()).build());
+                               new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
                linkstates.add(clBuilder.build());
 
                clBuilder.setLocalNodeDescriptors(lndBuilder.setCRouterIdentifier(
-                               new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(new byte[] { 1, 1, 1, 2 }).build()).build()).build());
+                               new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
                linkstates.add(clBuilder.build());
 
                final PathAttributes1Builder lsBuilder = new PathAttributes1Builder();
index 9cd3fa0d16169e46074f3a62e6fb3a09e8c193ca..13718a5b53d5b9ed8509038a998a06b22d98eb83 100644 (file)
@@ -15,7 +15,6 @@ import java.util.List;
 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
 import org.opendaylight.protocol.bgp.rib.RibReference;
-import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.DomainName;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
@@ -102,7 +101,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Lists;
-import com.google.common.primitives.UnsignedInteger;
 
 public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
        private static final Logger LOG = LoggerFactory.getLogger(LinkstateTopologyBuilder.class);
@@ -121,9 +119,9 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
        }
 
        private TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier,
-                       final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final byte[] bs) {
+                       final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
                return new TpId(new UriBuilder(base, "tp").add("mt", topologyIdentifier).add("ipv4", ipv4InterfaceIdentifier).add("ipv6",
-                               ipv6InterfaceIdentifier).add("id", bs).toString());
+                               ipv6InterfaceIdentifier).add("id", id).toString());
        }
 
        private TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
@@ -147,10 +145,9 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
        }
 
        private TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
-                       final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final byte[] bs) {
+                       final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final Long id) {
                // Order of preference: Unnumbered first, then IP
-               if (bs != null) {
-                       final long id = UnsignedInteger.fromIntBits(ByteArray.bytesToInt(bs)).longValue();
+               if (id != null) {
                        LOG.debug("Unnumbered termination point type: {}", id);
                        return new UnnumberedBuilder().setUnnumberedId(id).build();
                }
@@ -416,7 +413,7 @@ public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<Link
                        final OspfPseudonode pn = ((OspfPseudonodeCase) ri).getOspfPseudonode();
 
                        ab.setRouterType(new PseudonodeBuilder().setPseudonode(Boolean.TRUE).build());
-                       ab.setDrInterfaceId(UnsignedInteger.fromIntBits(ByteArray.bytesToInt(pn.getLanInterface().getValue())).longValue());
+                       ab.setDrInterfaceId(pn.getLanInterface().getValue());
                } else if (ri instanceof OspfNodeCase) {
                        final OspfNode in = ((OspfNodeCase) ri).getOspfNode();
 
index 6d7912bb368cd96851ccf464e5512b7e0cc43361..6e363760d7a46405ac913481a1b0316cd1090fac 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.bgpcep.bgp.topology.provider;
 
-import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeIdentifier;
 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.linkstate.route.object.type.LinkCase;
@@ -23,7 +22,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.primitives.UnsignedBytes;
-import com.google.common.primitives.UnsignedInteger;
 
 final class UriBuilder {
        private static final Logger LOG = LoggerFactory.getLogger(UriBuilder.class);
@@ -71,12 +69,8 @@ final class UriBuilder {
                if (ld.getMultiTopologyId() != null) {
                        add("mt", ld.getMultiTopologyId().getValue());
                }
-               if (ld.getLinkLocalIdentifier() != null) {
-                       add("local-id", UnsignedInteger.fromIntBits(ByteArray.bytesToInt(ld.getLinkLocalIdentifier())));
-               }
-               if (ld.getLinkRemoteIdentifier() != null) {
-                       add("remote-id", UnsignedInteger.fromIntBits(ByteArray.bytesToInt(ld.getLinkRemoteIdentifier())));
-               }
+               add("local-id", ld.getLinkLocalIdentifier());
+               add("remote-id", ld.getLinkRemoteIdentifier());
                return this;
        }
 
@@ -103,10 +97,10 @@ final class UriBuilder {
                        final IsisPseudonode r = ((IsisPseudonodeCase)routerIdentifier).getIsisPseudonode();
                        return isoId(r.getIsIsRouterIdentifier().getIsoSystemId().getValue()) + '.' + r.getPsn();
                } else if (routerIdentifier instanceof OspfNodeCase) {
-                       return ByteArray.bytesToHexString(((OspfNodeCase)routerIdentifier).getOspfNode().getOspfRouterId());
+                       return ((OspfNodeCase)routerIdentifier).getOspfNode().getOspfRouterId().toString();
                } else if (routerIdentifier instanceof OspfPseudonodeCase) {
                        final OspfPseudonode r = ((OspfPseudonodeCase)routerIdentifier).getOspfPseudonode();
-                       return ByteArray.bytesToHexString(r.getOspfRouterId()) + ':' + ByteArray.bytesToHexString(r.getLanInterface().getValue());
+                       return r.getOspfRouterId().toString() + ':' + r.getLanInterface().getValue();
                } else {
                        LOG.warn("Unhandled router identifier type {}, fallback to toString()", routerIdentifier.getImplementedInterface());
                        return routerIdentifier.toString();
@@ -118,10 +112,10 @@ final class UriBuilder {
                        add(prefix + "as", node.getAsNumber().getValue());
                }
                if (node.getDomainId() != null) {
-                       add(prefix + "domain", ByteArray.bytesToHexString(node.getDomainId().getValue()));
+                       add(prefix + "domain", node.getDomainId().getValue());
                }
                if (node.getAreaId() != null) {
-                       add(prefix + "area", ByteArray.bytesToHexString(node.getAreaId().getValue()));
+                       add(prefix + "area", node.getAreaId().getValue());
                }
                add(prefix + "router", formatRouterIdentifier(node.getCRouterIdentifier()));
                return this;
index d756ad5d08c8d45c6e07e495676adadae8257ef2..139ca517d7c988b675a9b6749820c45f61bc70ce 100644 (file)
@@ -18,6 +18,9 @@ import java.util.BitSet;
 
 import org.apache.commons.codec.binary.Hex;
 
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.UnsignedInteger;
+
 /**
  * 
  * Util class for methods working with byte array.
@@ -476,4 +479,17 @@ public final class ByteArray {
                }
                return Arrays.copyOf(bytes, i + 1);
        }
+
+       public static UnsignedInteger bytesToUint32(final byte[] bytes) {
+               Preconditions.checkArgument(bytes.length == Integer.SIZE / Byte.SIZE);
+               return UnsignedInteger.fromIntBits(bytesToInt(bytes));
+       }
+
+       public static byte[] uint32ToBytes(final UnsignedInteger uint) {
+               return intToBytes(uint.intValue());
+       }
+
+       public static byte[] uint32ToBytes(final long uint) {
+               return uint32ToBytes(UnsignedInteger.valueOf(uint));
+       }
 }