LOG.debug("Parsed Metric: {}", metric);
break;
case TlvCode.FORWARDING_ADDRESS:
- IpAddress fwdAddress = null;
- switch (value.readableBytes()) {
- case Ipv4Util.IP4_LENGTH:
- fwdAddress = new IpAddress(Ipv4Util.addressForByteBuf(value));
- break;
- case Ipv6Util.IPV6_LENGTH:
- fwdAddress = new IpAddress(Ipv6Util.addressForByteBuf(value));
- break;
- default:
- LOG.debug("Ignoring unsupported forwarding address length {}", value.readableBytes());
- }
+ IpAddress fwdAddress = parseForwardingAddress(value);
builder.setOspfForwardingAddress(fwdAddress);
LOG.debug("Parsed FWD Address: {}", fwdAddress);
break;
return new PrefixAttributesCaseBuilder().setPrefixAttributes(builder.build()).build();
}
+ private static IpAddress parseForwardingAddress(final ByteBuf value) {
+ IpAddress fwdAddress = null;
+ switch (value.readableBytes()) {
+ case Ipv4Util.IP4_LENGTH:
+ fwdAddress = new IpAddress(Ipv4Util.addressForByteBuf(value));
+ break;
+ case Ipv6Util.IPV6_LENGTH:
+ fwdAddress = new IpAddress(Ipv6Util.addressForByteBuf(value));
+ break;
+ default:
+ LOG.debug("Ignoring unsupported forwarding address length {}", value.readableBytes());
+ }
+ return fwdAddress;
+ }
+
/**
* Serialize linkstate attributes.
*
if (linkAttributes.getLinkProtection() != null) {
writeTLV(TlvCode.LINK_PROTECTION_TYPE, Unpooled.copyShort(linkAttributes.getLinkProtection().getIntValue()), byteAggregator);
}
- MplsProtocolMask mplsProtocolMask = linkAttributes.getMplsProtocol();
- if (mplsProtocolMask != null) {
- final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer();
- final BitSet mask = new BitSet();
- if (mplsProtocolMask.isLdp() != null) {
- mask.set(LDP_BIT, mplsProtocolMask.isLdp());
- }
- if (mplsProtocolMask.isRsvpte() != null) {
- mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
- }
- mplsProtocolMaskBuf.writeBytes(mask.toByteArray());
- writeTLV(TlvCode.MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
- }
+ serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), byteAggregator);
if (linkAttributes.getMetric() != null) {
// size of metric can be 1,2 or 3 depending on the protocol
writeTLV(TlvCode.METRIC, Unpooled.copyMedium(linkAttributes.getMetric().getValue().intValue()), byteAggregator);
LOG.trace("Finished serializing Link Attributes");
}
+ private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask, final ByteBuf byteAggregator ) {
+ if (mplsProtocolMask != null) {
+ final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer();
+ final BitSet mask = new BitSet();
+ if (mplsProtocolMask.isLdp() != null) {
+ mask.set(LDP_BIT, mplsProtocolMask.isLdp());
+ }
+ if (mplsProtocolMask.isRsvpte() != null) {
+ mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
+ }
+ mplsProtocolMaskBuf.writeBytes(mask.toByteArray());
+ writeTLV(TlvCode.MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
+ }
+ }
+
private void serializeNodeAttributes(final NodeAttributesCase nodeAttributesCase, final ByteBuf byteAggregator) {
LOG.trace("Started serializing Node Attributes");
final NodeAttributes nodeAttributes = nodeAttributesCase.getNodeAttributes();
}
writeTLV(TlvCode.MULTI_TOPOLOGY_ID, mpIdBuf, byteAggregator);
}
- final NodeFlagBits nodeFlagBits = nodeAttributes.getNodeFlags();
+ serializeNodeFlagBits(nodeAttributes.getNodeFlags(), byteAggregator);
+ if (nodeAttributes.getDynamicHostname() != null) {
+ writeTLV(TlvCode.DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(nodeAttributes.getDynamicHostname().getBytes()), byteAggregator);
+ }
+ if (nodeAttributes.getIsisAreaId() != null) {
+ for (final IsisAreaIdentifier isisAreaIdentifier : nodeAttributes.getIsisAreaId()) {
+ writeTLV(TlvCode.ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator);
+ }
+ }
+ if (nodeAttributes.getIpv4RouterId() != null) {
+ writeTLV(TlvCode.LOCAL_IPV4_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(nodeAttributes.getIpv4RouterId().getValue()).getAddress()), byteAggregator);
+ }
+ if (nodeAttributes.getIpv6RouterId() != null) {
+ writeTLV(TlvCode.LOCAL_IPV6_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(nodeAttributes.getIpv6RouterId().getValue()).getAddress()), byteAggregator);
+ }
+ LOG.trace("Finished serializing Node Attributes");
+ }
+
+ private static void serializeNodeFlagBits(final NodeFlagBits nodeFlagBits, final ByteBuf byteAggregator) {
if (nodeFlagBits != null) {
final ByteBuf nodeFlagBuf = Unpooled.buffer();
final BitSet flags = new BitSet();
nodeFlagBuf.writeBytes(flags.toByteArray());
writeTLV(TlvCode.NODE_FLAG_BITS, nodeFlagBuf, byteAggregator);
}
- if (nodeAttributes.getDynamicHostname() != null) {
- writeTLV(TlvCode.DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(nodeAttributes.getDynamicHostname().getBytes()), byteAggregator);
- }
- if (nodeAttributes.getIsisAreaId() != null) {
- for (final IsisAreaIdentifier isisAreaIdentifier : nodeAttributes.getIsisAreaId()) {
- writeTLV(TlvCode.ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator);
- }
- }
- if (nodeAttributes.getIpv4RouterId() != null) {
- writeTLV(TlvCode.LOCAL_IPV4_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(nodeAttributes.getIpv4RouterId().getValue()).getAddress()), byteAggregator);
- }
- if (nodeAttributes.getIpv6RouterId() != null) {
- writeTLV(TlvCode.LOCAL_IPV6_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(nodeAttributes.getIpv6RouterId().getValue()).getAddress()), byteAggregator);
- }
- LOG.trace("Finished serializing Node Attributes");
}
private void serializePrefixAttributes(final PrefixAttributesCase prefixAttributesCase, final ByteBuf byteAggregator) {
final PrefixAttributes prefixAtrributes = prefixAttributesCase.getPrefixAttributes();
if (prefixAtrributes.getIgpBits() != null) {
- BitSet igpBit = new BitSet();
- Boolean bit = prefixAtrributes.getIgpBits().getUpDown().isUpDown();
+ final BitSet igpBit = new BitSet();
+ final Boolean bit = prefixAtrributes.getIgpBits().getUpDown().isUpDown();
if (bit != null) {
igpBit.set(UP_DOWN_BIT, bit);
}
if (prefixAtrributes.getPrefixMetric() != null) {
writeTLV(TlvCode.PREFIX_METRIC, Unpooled.copyInt(prefixAtrributes.getPrefixMetric().getValue().intValue()), byteAggregator);
}
- IpAddress forwardingAddress = prefixAtrributes.getOspfForwardingAddress();
+ serializeForwardingAddress(prefixAtrributes.getOspfForwardingAddress(), byteAggregator);
+ }
+
+ private static void serializeForwardingAddress(final IpAddress forwardingAddress, final ByteBuf byteAggregator) {
if (forwardingAddress != null) {
final ByteBuf ospfBuf = Unpooled.buffer();
if (forwardingAddress.getIpv4Address() != null) {
import com.google.common.collect.Lists;
import com.google.common.primitives.UnsignedBytes;
import com.google.common.primitives.UnsignedInteger;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
-
import java.math.BigInteger;
import java.util.List;
-
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
private static final int ROUTE_DISTINGUISHER_LENGTH = 8;
private static final int PROTOCOL_ID_LENGTH = 1;
private static final int IDENTIFIER_LENGTH = 8;
+ private static final int OSPF_PSEUDONODE_ROUTER_ID_LENGTH = 8;
private static final int OSPF_ROUTER_ID_LENGTH = 4;
private static final int ISO_SYSTEM_ID_LENGTH = 6;
private static final int PSN_LENGTH = 1;
builder.setLinkLocalIdentifier(value.readUnsignedInt());
builder.setLinkRemoteIdentifier(value.readUnsignedInt());
LOG.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
- builder.getLinkRemoteIdentifier());
+ builder.getLinkRemoteIdentifier());
break;
case TlvCode.IPV4_IFACE_ADDRESS:
final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
}
LOG.trace("Finished parsing Node descriptors.");
return (local) ? new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(
- routerId).build()
- : new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
+ routerId).build()
+ : new RemoteNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
}
private static CRouterIdentifier parseRouterId(final ByteBuf value) throws BGPParsingException {
if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH || (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH && value.getByte(ISO_SYSTEM_ID_LENGTH) == 0)) {
return new IsisNodeCaseBuilder().setIsisNode(
- new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build()).build();
+ new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build()).build();
}
if (value.readableBytes() == ISO_SYSTEM_ID_LENGTH + PSN_LENGTH) {
final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
- new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build();
+ new IsoSystemIdentifier(ByteArray.readBytes(value, ISO_SYSTEM_ID_LENGTH))).build();
return new IsisPseudonodeCaseBuilder().setIsisPseudonode(new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) value.readByte()).build()).build();
}
if (value.readableBytes() == OSPF_ROUTER_ID_LENGTH) {
return new OspfNodeCaseBuilder().setOspfNode(
- new OspfNodeBuilder().setOspfRouterId(value.readUnsignedInt()).build()).build();
+ new OspfNodeBuilder().setOspfRouterId(value.readUnsignedInt()).build()).build();
}
- if (value.readableBytes() == 8) {
+ if (value.readableBytes() == OSPF_PSEUDONODE_ROUTER_ID_LENGTH) {
return new OspfPseudonodeCaseBuilder().setOspfPseudonode(
- new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt()).setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()).build();
+ new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt()).setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()).build();
}
throw new BGPParsingException("Router Id of invalid length " + value.readableBytes());
}
nlri.skipBytes(locallength);
builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
final int restLength = length - (this.isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
- - TYPE_LENGTH - LENGTH_SIZE - locallength;
+ - TYPE_LENGTH - LENGTH_SIZE - locallength;
LOG.trace("Restlength {}", restLength);
ByteBuf rest = nlri.slice(nlri.readerIndex(), restLength);
switch (type) {
final List<CLinkstateDestination> dst = parseNlri(nlri);
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(
- dst).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(
+ dst).build()).build()).build());
}
@Override
final List<CLinkstateDestination> dst = parseNlri(nlri);
builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
- new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build()).build());
+ new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+ new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build()).build());
}
/**
private static void serializeLinkDescriptors(final LinkDescriptors descriptors, final ByteBuf buffer) {
if (descriptors.getLinkLocalIdentifier() != null && descriptors.getLinkRemoteIdentifier() != null) {
- LinkstateAttributeParser.writeTLV(TlvCode.LINK_LR_IDENTIFIERS, Unpooled.copyInt(descriptors.getLinkLocalIdentifier().intValue()), buffer);
+ final ByteBuf identifierBuf = Unpooled.buffer();
+ identifierBuf.writeInt(descriptors.getLinkLocalIdentifier().intValue());
+ identifierBuf.writeInt(descriptors.getLinkRemoteIdentifier().intValue());
+ LinkstateAttributeParser.writeTLV(TlvCode.LINK_LR_IDENTIFIERS, identifierBuf, buffer);
}
if (descriptors.getIpv4InterfaceAddress() != null) {
LinkstateAttributeParser.writeTLV(TlvCode.IPV4_IFACE_ADDRESS, Unpooled.wrappedBuffer(Ipv4Util.bytesForAddress(descriptors.getIpv4InterfaceAddress())), buffer);
}
if (descriptors.getOspfRouteType() != null) {
LinkstateAttributeParser.writeTLV(TlvCode.OSPF_ROUTE_TYPE,
- Unpooled.wrappedBuffer(new byte[] {UnsignedBytes.checkedCast(descriptors.getOspfRouteType().getIntValue()) }), buffer);
+ Unpooled.wrappedBuffer(new byte[] {UnsignedBytes.checkedCast(descriptors.getOspfRouteType().getIntValue()) }), buffer);
}
if (descriptors.getIpReachabilityInformation() != null) {
final IpPrefix prefix = descriptors.getIpReachabilityInformation();
final PathAttributes pathAttributes = (PathAttributes) attribute;
final PathAttributes1 pathAttributes1 = pathAttributes.getAugmentation(PathAttributes1.class);
final PathAttributes2 pathAttributes2 = pathAttributes.getAugmentation(PathAttributes2.class);
- if (pathAttributes1 == null && pathAttributes2 == null) {
- return;
- }
if (pathAttributes1 != null) {
final AdvertizedRoutes routes = (pathAttributes1.getMpReachNlri()).getAdvertizedRoutes();
if (routes != null &&
- routes.getDestinationType()
- instanceof
- 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) {
+ routes.getDestinationType()
+ instanceof
+ 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) {
final 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
linkstateCase = (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) routes.getDestinationType();
import static org.junit.Assert.assertTrue;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.Arrays;
-
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.util.ByteArray;
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.update.PathAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlriBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
public class LinkstateAttributeParserTest {
private static PathAttributesBuilder createBuilder(final NlriType type) {
return new PathAttributesBuilder().addAugmentation(
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1.class,
- new PathAttributes1Builder().setMpReachNlri(
- new MpReachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setAdvertizedRoutes(
- new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
- new DestinationLinkstateBuilder().setCLinkstateDestination(
- Lists.newArrayList(new CLinkstateDestinationBuilder().setNlriType(type).build())).build()).build()).build()).build()).build());
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1.class,
+ new PathAttributes1Builder().setMpReachNlri(
+ new MpReachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setAdvertizedRoutes(
+ new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+ new DestinationLinkstateBuilder().setCLinkstateDestination(
+ Lists.newArrayList(new CLinkstateDestinationBuilder().setNlriType(type).build())).build()).build()).build()).build()).build());
+ }
+
+ private static PathAttributesBuilder createUnreachBuilder(final NlriType type) {
+ return new PathAttributesBuilder().addAugmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2.class,
+ new PathAttributes2Builder().setMpUnreachNlri(
+ new MpUnreachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).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(new CLinkstateDestinationBuilder().setNlriType(type).build())).build()).build()).build()).build()).build());
}
@Test
//serialization
final ByteBuf buff = Unpooled.buffer();
this.parser.serializeAttribute(builder.build(), buff);
- buff.readerIndex(buff.readerIndex() + 3);
+ buff.skipBytes(3);
// there is unresolved TLV at the end, that needs to be cut off
assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length -5), ByteArray.getAllBytes(buff));
}
//serialization
final ByteBuf buff = Unpooled.buffer();
this.parser.serializeAttribute(builder.build(), buff);
- buff.readerIndex(buff.readerIndex() + 3);
+ buff.skipBytes(3);
// there is unresolved TLV at the end, that needs to be cut off
assertTrue(Arrays.equals(ByteArray.subByte(NODE_ATTR, 0, NODE_ATTR.length -5), ByteArray.getAllBytes(buff)) || Arrays.equals(NODE_ATTR_S, ByteArray.getAllBytes(buff)));
}
@Test
public void testPositiveV4Prefixes() throws BGPParsingException {
- final PathAttributesBuilder builder = createBuilder(NlriType.Ipv4Prefix);
+ final PathAttributesBuilder builder = createUnreachBuilder(NlriType.Ipv4Prefix);
this.parser.parseAttribute(Unpooled.copiedBuffer(P4_ATTR), builder);
final PathAttributes1 attrs = builder.getAugmentation(PathAttributes1.class);
//serialization
final ByteBuf buff = Unpooled.buffer();
this.parser.serializeAttribute(builder.build(), buff);
- buff.readerIndex(buff.readerIndex() + 3);
+ buff.skipBytes(3);
// there is unresolved TLV at the end, that needs to be cut off
assertArrayEquals(ByteArray.subByte(P4_ATTR, 0, P4_ATTR.length -5), ByteArray.getAllBytes(buff));
}
import static org.junit.Assert.assertNull;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.math.BigInteger;
import java.util.List;
-
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.util.ByteArray;
(byte) 0x00, (byte) 0x29, (byte) 0x29, (byte) 0x29, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x39, (byte) 0x05 };
- private final byte[] linkNlri = new byte[] { (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x53, (byte) 0x02, (byte) 0x00, (byte) 0x00,
+ private final byte[] linkNlri = new byte[] { (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x65, (byte) 0x02, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a,
(byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01,
(byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x18,
(byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01,
(byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x04,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14,
- (byte) 0xa0, (byte) 0x2a, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x28 };
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, 1, 2, 0, 8, 1, 2, 3, 4, 0x0a, 0x0b, 0x0c, 0x0d,
+ (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14,
+ (byte) 0xa0, (byte) 0x2a, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x28,
+ 1, 7, 0, 2, 0, 3};
private final byte[] prefixNlri = new byte[] { (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x39, (byte) 0x02, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00,
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedShort;
import com.google.common.base.Preconditions;
-import com.google.common.primitives.UnsignedBytes;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.BitSet;
public static final int TYPE = 21;
private static final int FLAGS_F_LENGTH = 1;
+ private static final int HEADER_LENGTH = 4;
private static final int RSVP_ERROR_CLASS_NUM = 6;
private static final int RSVP_IPV4_ERROR_CLASS_TYPE = 1;
if (buffer == null) {
return null;
}
- final int classNum = UnsignedBytes.toInt(buffer.readByte());
- final int classType = UnsignedBytes.toInt(buffer.readByte());
+ // throw away contents of length field
+ buffer.readUnsignedShort();
+ final int classNum = buffer.readUnsignedByte();
+ final int classType = buffer.readUnsignedByte();
ErrorType errorType = null;
if (classNum == RSVP_ERROR_CLASS_NUM) {
errorType = parseRsvp(classType, buffer.slice());
private UserCase parseUserError(final ByteBuf buffer) {
final UserErrorBuilder error = new UserErrorBuilder();
error.setEnterprise(new EnterpriseNumber(buffer.readUnsignedInt()));
- error.setSubOrg((short) UnsignedBytes.toInt(buffer.readByte()));
- final int errDescrLength = UnsignedBytes.toInt(buffer.readByte());
+ error.setSubOrg(buffer.readUnsignedByte());
+ final int errDescrLength = buffer.readUnsignedByte();
error.setValue(buffer.readUnsignedShort());
error.setDescription(ByteArray.bytesToHRString(ByteArray.readBytes(buffer, errDescrLength)));
// if we have any subobjects, place the implementation here
private void serializerUserError(final UserError ue, final ByteBuf body) {
byte[] desc = (ue.getDescription() == null) ? new byte[0] : ue.getDescription().getBytes();
- body.writeByte(USER_ERROR_CLASS_NUM);
- body.writeByte(USER_ERROR_CLASS_TYPE);
+ final ByteBuf userErrorBuf = Unpooled.buffer();
Preconditions.checkArgument(ue.getEnterprise() != null, "EnterpriseNumber is mandatory");
- writeUnsignedInt(ue.getEnterprise().getValue(), body);
- writeUnsignedByte(ue.getSubOrg(), body);
- body.writeByte(desc.length);
+ writeUnsignedInt(ue.getEnterprise().getValue(), userErrorBuf);
+ writeUnsignedByte(ue.getSubOrg(), userErrorBuf);
+ userErrorBuf.writeByte(desc.length);
Preconditions.checkArgument(ue.getValue() != null, "Value is mandatory.");
- writeUnsignedShort(ue.getValue(), body);
- body.writeBytes(desc);
+ writeUnsignedShort(ue.getValue(), userErrorBuf);
+ userErrorBuf.writeBytes(desc);
+ userErrorBuf.writeZero(TlvUtil.getPadding(desc.length, TlvUtil.PADDED_TO));
+ formatRSVPObject(USER_ERROR_CLASS_NUM, USER_ERROR_CLASS_TYPE, userErrorBuf, body);
}
private RsvpCase parseRsvp(final int classType, final ByteBuf buffer) {
final RsvpErrorBuilder builder = new RsvpErrorBuilder();
if (classType == RSVP_IPV4_ERROR_CLASS_TYPE) {
- builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH))));
+ builder.setNode(new IpAddress(Ipv4Util.addressForByteBuf(buffer)));
} else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) {
- 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)));
flags.set(NOT_GUILTY_FLAGS_OFFSET, rsvp.getFlags().isNotGuilty());
final IpAddress node = rsvp.getNode();
Preconditions.checkArgument(node != null, "Node is mandatory.");
+ final ByteBuf rsvpObjBuf = Unpooled.buffer();
+ int type = 0;
if (node.getIpv4Address() != null) {
- body.writeByte(RSVP_ERROR_CLASS_NUM);
- body.writeByte(RSVP_IPV4_ERROR_CLASS_TYPE);
- writeIpv4Address(node.getIpv4Address(), body);
+ type = RSVP_IPV4_ERROR_CLASS_TYPE;
+ writeIpv4Address(node.getIpv4Address(), rsvpObjBuf);
} else {
- body.writeByte(RSVP_ERROR_CLASS_NUM);
- body.writeByte(RSVP_IPV6_ERROR_CLASS_TYPE);
- writeIpv6Address(node.getIpv6Address(), body);
+ type = RSVP_IPV6_ERROR_CLASS_TYPE;
+ writeIpv6Address(node.getIpv6Address(), rsvpObjBuf);
}
- writeBitSet(flags, FLAGS_F_LENGTH, body);
+ writeBitSet(flags, FLAGS_F_LENGTH, rsvpObjBuf);
Preconditions.checkArgument(rsvp.getCode() != null, "Code is mandatory.");
- writeUnsignedByte(rsvp.getCode(), body);
+ writeUnsignedByte(rsvp.getCode(), rsvpObjBuf);
Preconditions.checkArgument(rsvp.getValue() != null, "Value is mandatory.");
- writeUnsignedShort(rsvp.getValue(), body);
+ writeUnsignedShort(rsvp.getValue(), rsvpObjBuf);
+ formatRSVPObject(RSVP_ERROR_CLASS_NUM, type, rsvpObjBuf, body);
+ }
+
+ private static void formatRSVPObject(final int objClass, final int type, final ByteBuf body, final ByteBuf out) {
+ out.writeShort(body.writerIndex() + HEADER_LENGTH);
+ out.writeByte(objClass);
+ out.writeByte(type);
+ out.writeBytes(body);
}
}
(byte) 0xFF, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x01, 0x23, 0x45, 0x67, 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56,
0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, 0x12, 0x34, 0x56, 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
(byte) 0xF0 };
- private static final byte[] rsvpErrorBytes = { 0x00, 0x15, 0x00, 0x0a, 0x06, 0x01, 0x12, 0x34, 0x56, 0x78, 0x02, (byte) 0x92, 0x16,
- 0x02, 0x00, 0x00 };
- private static final byte[] rsvpError6Bytes = { 0x00, 0x15, 0x00, 0x16, 0x06, 0x02, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc,
+ private static final byte[] rsvpErrorBytes = { 0x00, 0x15, 0x00, 0x0c, 0, 0x0c, 0x06, 0x01, 0x12, 0x34, 0x56, 0x78, 0x02, (byte) 0x92, 0x16,
+ 0x02 };
+ private static final byte[] rsvpError6Bytes = { 0x00, 0x15, 0x00, 0x18, 0, 0x18, 0x06, 0x02, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc,
(byte) 0xde, (byte) 0xf0, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, 0x02, (byte) 0xd5,
- (byte) 0xc5, (byte) 0xd9, 0x00, 0x00 };
- private static final byte[] userErrorBytes = { 0x00, 0x15, 0x00, 0x13, (byte) 0xc2, 0x01, 0x00, 0x00, 0x30, 0x39, 0x05, 0x09, 0x00,
- 0x26, 0x75, 0x73, 0x65, 0x72, 0x20, 0x64, 0x65, 0x73, 0x63, 0x00 };
+ (byte) 0xc5, (byte) 0xd9};
+ private static final byte[] userErrorBytes = { 0x00, 0x15, 0x00, 0x18, 0, 0x18, (byte) 0xc2, 0x01, 0x00, 0x00, 0x30, 0x39, 0x05, 0x09, 0x00,
+ 0x26, 0x75, 0x73, 0x65, 0x72, 0x20, 0x64, 0x65, 0x73, 0x63, 0, 0, 0 };
@Test
public void testStatefulTlv() throws PCEPDeserializerException {
public void testSymbolicNameTlv() throws PCEPDeserializerException {
final Stateful07LspSymbolicNameTlvParser parser = new Stateful07LspSymbolicNameTlvParser();
final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName("Med test of symbolic nameeee".getBytes())).build();
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName("Med test of symbolic nameeee".getBytes())).build();
assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(symbolicNameBytes, 4))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
(byte) 0x78 })));
afi.setIpv4TunnelEndpointAddress(Ipv4Util.addressForBytes(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();
+ new LspId(65535L)).setTunnelId(new TunnelId(4660)).build();
assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(lspIdentifiers4Bytes, 4))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
(byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xF0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A,
(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();
+ new LspId(4660L)).setTunnelId(new TunnelId(65535)).build();
assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(lspIdentifiers6Bytes, 4))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
package org.opendaylight.protocol.pcep.impl.message;
import com.google.common.base.Preconditions;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.ArrayList;
import java.util.List;
-
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
}
}
- if (errorObjects.isEmpty() && errorObjects.isEmpty()) {
+ if (errorObjects.isEmpty()) {
throw new PCEPDeserializerException("At least one PCEPErrorObject is mandatory.");
}
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.ArrayList;
import java.util.List;
-
import org.junit.Test;
import org.opendaylight.protocol.pcep.spi.MessageRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
public class PCEPParserTest {
assertTrue(out.get(0) instanceof Keepalive);
decoder.decode(null, Unpooled.wrappedBuffer(new byte[] { 0x20, 0x07, 0, 0x0C, 0x0F, 0x10, 0, 8, 0, 0, 0, 5 }), out);
assertTrue(out.get(1) instanceof Close);
+ decoder.decode(null, Unpooled.wrappedBuffer(new byte[] { 0x20, 06, 00, 0x18, 0x21,0x10, 00,0x0c, 00,00,00,00,00,00,00,01,0x0d,0x10,00,0x08,00,00,0x18,02 }), out);
+ assertTrue(out.get(2) instanceof Pcerr);
}
@Test
private static final Logger LOG = LoggerFactory.getLogger(AbstractObjectWithTlvsParser.class);
+ private static final int TLV_TYPE_F_LENGTH = 2;
+ private static final int TLV_LENGTH_F_LENGTH = 2;
+ private static final int TLV_HEADER_LENGTH = TLV_LENGTH_F_LENGTH + TLV_TYPE_F_LENGTH;
+
+ public static final int PADDED_TO = 4;
+
private final TlvRegistry tlvReg;
protected AbstractObjectWithTlvsParser(final TlvRegistry tlvReg) {
protected static final int HEADER_SIZE = 4;
- protected static final int PADDED_TO = 4;
+ public static final int PADDED_TO = 4;
private TlvUtil() {
}