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);
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;
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:
}
}
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);
}
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());
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());
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 {
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 {
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;
}
}
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;
}
}
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(
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(
(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(
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(
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));
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());
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
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));
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();
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;
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);
}
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) {
}
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();
}
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();
*/
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;
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);
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;
}
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();
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;
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.
}
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));
+ }
}