import java.util.ArrayList;
import java.util.List;
+import org.opendaylight.protocol.bgp.linkstate.attribute.LinkstateAttributeParser;
+import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkstateAddressFamily;
this.ianaLinkstateAttributeType = true;
}
- public BGPActivator(boolean ianaLinkstateAttributeType) {
+ public BGPActivator(final boolean ianaLinkstateAttributeType) {
super();
this.ianaLinkstateAttributeType = ianaLinkstateAttributeType;
}
new LinkstateNlriParser(true)));
regs.add(context.registerNlriSerializer(PathAttributes.class, new LinkstateNlriParser(false)));
- regs.add(context.registerAttributeSerializer(PathAttributes1.class, new LinkstateAttributeParser(ianaLinkstateAttributeType)));
- final LinkstateAttributeParser linkstateAttributeParser = new LinkstateAttributeParser(ianaLinkstateAttributeType);
+ regs.add(context.registerAttributeSerializer(PathAttributes1.class, new LinkstateAttributeParser(this.ianaLinkstateAttributeType)));
+ final LinkstateAttributeParser linkstateAttributeParser = new LinkstateAttributeParser(this.ianaLinkstateAttributeType);
regs.add(context.registerAttributeParser(linkstateAttributeParser.getType(), linkstateAttributeParser));
return regs;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.List;
+import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.rib.spi.AbstractAdjRIBs;
import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsTransaction;
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.linkstate;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-import com.google.common.net.InetAddresses;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
-import io.netty.buffer.Unpooled;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.BitSet;
-import java.util.List;
-import java.util.Map.Entry;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
-import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
-import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.Ipv4Util;
-import org.opendaylight.protocol.util.Ipv6Util;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.AdministrativeGroup;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.ExtendedRouteTag;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.IgpBits.UpDown;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4RouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6RouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.IsisAreaIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkProtectionType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.MplsProtocolMask;
-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.NodeFlagBits;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.RouteTag;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidth;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidthBuilder;
-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.prefix.state.IgpBitsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttribute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttributeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributesBuilder;
-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.message.rev130919.update.PathAttributes;
-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.PathAttributes2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IgpMetric;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgId;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Parser for Link State Path Attribute.
- *
- * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-04">BGP-LS draft</a>
- */
-public class LinkstateAttributeParser implements AttributeParser, AttributeSerializer {
-
- private static final int TYPE = 29;
-
- private static final int LEGACY_TYPE = 99;
-
- private static final Logger LOG = LoggerFactory.getLogger(LinkstateAttributeParser.class);
-
- private static final int ROUTE_TAG_LENGTH = 4;
-
- private static final int EXTENDED_ROUTE_TAG_LENGTH = 8;
-
- private static final int UNRESERVED_BW_COUNT = 8;
-
- private static final int BANDWIDTH_LENGTH = 4;
-
- // node flag bits
- private static final int OVERLOAD_BIT = 7;
- private static final int ATTACHED_BIT = 6;
- private static final int EXTERNAL_BIT = 5;
- private static final int ABBR_BIT = 4;
-
- // MPLS protection mask bits
- private static final int LDP_BIT = 7;
- private static final int RSVP_BIT = 6;
-
- private static final int UP_DOWN_BIT = 7;
-
- private final int type;
-
- public LinkstateAttributeParser(final boolean isIanaAssignedType) {
- if(isIanaAssignedType) {
- this.type = TYPE;
- } else {
- this.type = LEGACY_TYPE;
- }
- }
-
- public int getType() {
- return this.type;
- }
-
- private NlriType getNlriType(final PathAttributesBuilder pab) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1 mpr = pab.getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1.class);
- if (mpr != null && mpr.getMpReachNlri() != null) {
- final DestinationType dt = mpr.getMpReachNlri().getAdvertizedRoutes().getDestinationType();
- if (dt instanceof DestinationLinkstateCase) {
- for (final CLinkstateDestination d : ((DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) {
- return d.getNlriType();
- }
- }
- } else {
- LOG.debug("No MP_REACH attribute present");
- }
- final PathAttributes2 mpu = pab.getAugmentation(PathAttributes2.class);
- if (mpu != null && mpu.getMpUnreachNlri() != null) {
- final DestinationType dt = mpu.getMpUnreachNlri().getWithdrawnRoutes().getDestinationType();
- if (dt instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) {
- for (final CLinkstateDestination d : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) {
- return d.getNlriType();
- }
- }
- } else {
- LOG.debug("No MP_UNREACH attribute present");
- }
- return null;
- }
-
- @Override
- public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) throws BGPParsingException {
- final NlriType nlriType = getNlriType(builder);
- if (nlriType == null) {
- LOG.warn("No Linkstate NLRI found, not parsing Linkstate attribute");
- return;
- }
- final PathAttributes1 a = new PathAttributes1Builder().setLinkstatePathAttribute(parseLinkState(nlriType, buffer)).build();
- builder.addAugmentation(PathAttributes1.class, a);
- }
-
- private static LinkstatePathAttribute parseLinkState(final NlriType nlri, final ByteBuf buffer) throws BGPParsingException {
- /*
- * e.g. IS-IS Area Identifier TLV can occur multiple times
- */
- final Multimap<Integer, ByteBuf> map = HashMultimap.create();
- while (buffer.isReadable()) {
- final int type = buffer.readUnsignedShort();
- final int length = buffer.readUnsignedShort();
- final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
- map.put(type, value);
- buffer.skipBytes(length);
- }
- final LinkstatePathAttributeBuilder builder = new LinkstatePathAttributeBuilder();
-
- switch (nlri) {
- case Ipv4Prefix:
- case Ipv6Prefix:
- builder.setLinkStateAttribute(parsePrefixAttributes(map));
- return builder.build();
- case Link:
- builder.setLinkStateAttribute(parseLinkAttributes(map));
- return builder.build();
- case Node:
- builder.setLinkStateAttribute(parseNodeAttributes(map));
- return builder.build();
- default:
- throw new IllegalStateException("Unhandled NLRI type " + nlri);
- }
- }
-
- /**
- * Parse Link Attributes.
- *
- * @param attributes key is the tlv type and value is the value of the tlv
- * @return {@link LinkStateAttribute}
- */
- private static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes) {
- final LinkAttributesBuilder builder = new LinkAttributesBuilder();
- for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
- LOG.trace("Link attribute TLV {}", entry.getKey());
- final int key = entry.getKey();
- final ByteBuf value = entry.getValue();
- switch (key) {
- case TlvCode.LOCAL_IPV4_ROUTER_ID:
- final Ipv4RouterIdentifier lipv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
- builder.setLocalIpv4RouterId(lipv4);
- LOG.debug("Parsed IPv4 Router-ID of local node: {}", lipv4);
- break;
- case TlvCode.LOCAL_IPV6_ROUTER_ID:
- final Ipv6RouterIdentifier lipv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
- builder.setLocalIpv6RouterId(lipv6);
- LOG.debug("Parsed IPv6 Router-ID of local node: {}", lipv6);
- break;
- case TlvCode.REMOTE_IPV4_ROUTER_ID:
- final Ipv4RouterIdentifier ripv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
- builder.setRemoteIpv4RouterId(ripv4);
- LOG.debug("Parsed IPv4 Router-ID of remote node: {}", ripv4);
- break;
- case TlvCode.REMOTE_IPV6_ROUTER_ID:
- final Ipv6RouterIdentifier ripv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
- builder.setRemoteIpv6RouterId(ripv6);
- LOG.debug("Parsed IPv6 Router-ID of remote node: {}", ripv6);
- break;
- case TlvCode.ADMIN_GROUP:
- builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt()));
- LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
- break;
- case TlvCode.MAX_BANDWIDTH:
- builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
- LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
- break;
- case TlvCode.MAX_RESERVABLE_BANDWIDTH:
- builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
- LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
- break;
- case TlvCode.UNRESERVED_BANDWIDTH:
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidth> unreservedBandwidth = new ArrayList<>(UNRESERVED_BW_COUNT);
- for (int i = 0; i < UNRESERVED_BW_COUNT; i++) {
- final ByteBuf v = value.slice(value.readerIndex(), BANDWIDTH_LENGTH);
- unreservedBandwidth.add(new UnreservedBandwidthBuilder().setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))).setPriority((short) i).build());
- value.skipBytes(BANDWIDTH_LENGTH);
- }
- builder.setUnreservedBandwidth(unreservedBandwidth);
- LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
- break;
- case TlvCode.TE_METRIC:
- builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
- LOG.debug("Parsed Metric {}", builder.getTeMetric());
- break;
- case TlvCode.LINK_PROTECTION_TYPE:
- final int l = value.readShort();
- final LinkProtectionType lpt = LinkProtectionType.forValue(l);
- if (lpt == null) {
- LOG.warn("Link Protection Type not recognized: {}", l);
- break;
- }
- builder.setLinkProtection(lpt);
- LOG.debug("Parsed Link Protection Type {}", lpt);
- break;
- case TlvCode.MPLS_PROTOCOL:
- final BitSet bits = BitSet.valueOf(ByteArray.readAllBytes(value));
- builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
- LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
- break;
- case TlvCode.METRIC:
- // length can 3, 2 or 1
- builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
- LOG.debug("Parsed Metric {}", builder.getMetric());
- break;
- case TlvCode.SHARED_RISK_LINK_GROUP:
- final List<SrlgId> sharedRiskLinkGroups = new ArrayList<>();
- while (value.isReadable()) {
- sharedRiskLinkGroups.add(new SrlgId(value.readUnsignedInt()));
- }
- builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
- LOG.debug("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
- break;
- case TlvCode.LINK_OPAQUE:
- LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
- break;
- case TlvCode.LINK_NAME:
- final String name = new String(ByteArray.readAllBytes(value), Charsets.US_ASCII);
- builder.setLinkName(name);
- LOG.debug("Parsed Link Name : {}", name);
- break;
- default:
- LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
- }
- }
- LOG.trace("Finished parsing Link Attributes.");
- return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
- }
-
- /**
- * Parse Node Attributes.
- *
- * @param attributes key is the tlv type and value is the value of the tlv
- * @return {@link LinkStateAttribute}
- */
- private static LinkStateAttribute parseNodeAttributes(final Multimap<Integer, ByteBuf> attributes) {
- final List<TopologyIdentifier> topologyMembership = Lists.newArrayList();
- final List<IsisAreaIdentifier> areaMembership = Lists.newArrayList();
- final NodeAttributesBuilder builder = new NodeAttributesBuilder();
- for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
- final int key = entry.getKey();
- final ByteBuf value = entry.getValue();
- LOG.trace("Node attribute TLV {}", key);
- switch (key) {
- case TlvCode.MULTI_TOPOLOGY_ID:
- while (value.isReadable()) {
- final TopologyIdentifier topId = new TopologyIdentifier(value.readUnsignedShort() & LinkstateNlriParser.TOPOLOGY_ID_OFFSET);
- topologyMembership.add(topId);
- LOG.debug("Parsed Topology Identifier: {}", topId);
- }
- break;
- case TlvCode.NODE_FLAG_BITS:
- final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
- builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT)));
- LOG.debug("Parsed Overload bit: {}, attached bit: {}, external bit: {}, area border router: {}.",
- flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT));
- break;
- case TlvCode.NODE_OPAQUE:
- LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value));
- break;
- case TlvCode.DYNAMIC_HOSTNAME:
- builder.setDynamicHostname(new String(ByteArray.readAllBytes(value), Charsets.US_ASCII));
- LOG.debug("Parsed Node Name {}", builder.getDynamicHostname());
- break;
- case TlvCode.ISIS_AREA_IDENTIFIER:
- final IsisAreaIdentifier ai = new IsisAreaIdentifier(ByteArray.readAllBytes(value));
- areaMembership.add(ai);
- LOG.debug("Parsed AreaIdentifier {}", ai);
- break;
- case TlvCode.LOCAL_IPV4_ROUTER_ID:
- final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
- builder.setIpv4RouterId(ip4);
- LOG.debug("Parsed IPv4 Router Identifier {}", ip4);
- break;
- case TlvCode.LOCAL_IPV6_ROUTER_ID:
- final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
- builder.setIpv6RouterId(ip6);
- LOG.debug("Parsed IPv6 Router Identifier {}", ip6);
- break;
- default:
- LOG.warn("TLV {} is not a valid node attribute, ignoring it", key);
- }
- }
- LOG.trace("Finished parsing Node Attributes.");
- builder.setTopologyIdentifier(topologyMembership);
- builder.setIsisAreaId(areaMembership);
- return new NodeAttributesCaseBuilder().setNodeAttributes(builder.build()).build();
- }
-
- /**
- * Parse prefix attributes.
- *
- * @param attributes key is the tlv type and value are the value bytes of the tlv
- * @return {@link LinkStateAttribute}
- */
- private static LinkStateAttribute parsePrefixAttributes(final Multimap<Integer, ByteBuf> attributes) {
- final PrefixAttributesBuilder builder = new PrefixAttributesBuilder();
- final List<RouteTag> routeTags = Lists.newArrayList();
- final List<ExtendedRouteTag> exRouteTags = Lists.newArrayList();
- for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
- final int key = entry.getKey();
- final ByteBuf value = entry.getValue();
- LOG.trace("Prefix attribute TLV {}", key);
- switch (key) {
- case TlvCode.IGP_FLAGS:
- final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
- final boolean upDownBit = flags.get(UP_DOWN_BIT);
- builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit)).build());
- LOG.debug("Parsed IGP flag (up/down bit) : {}", upDownBit);
- break;
- case TlvCode.ROUTE_TAG:
- while (value.isReadable()) {
- final RouteTag routeTag = new RouteTag(ByteArray.readBytes(value, ROUTE_TAG_LENGTH));
- routeTags.add(routeTag);
- LOG.debug("Parsed Route Tag: {}", routeTag);
- }
- break;
- case TlvCode.EXTENDED_ROUTE_TAG:
- while (value.isReadable()) {
- final ExtendedRouteTag exRouteTag = new ExtendedRouteTag(ByteArray.readBytes(value, EXTENDED_ROUTE_TAG_LENGTH));
- exRouteTags.add(exRouteTag);
- LOG.debug("Parsed Extended Route Tag: {}", exRouteTag);
- }
- break;
- case TlvCode.PREFIX_METRIC:
- final IgpMetric metric = new IgpMetric(value.readUnsignedInt());
- builder.setPrefixMetric(metric);
- LOG.debug("Parsed Metric: {}", metric);
- break;
- case TlvCode.FORWARDING_ADDRESS:
- final IpAddress fwdAddress = parseForwardingAddress(value);
- builder.setOspfForwardingAddress(fwdAddress);
- LOG.debug("Parsed FWD Address: {}", fwdAddress);
- break;
- case TlvCode.PREFIX_OPAQUE:
- LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value));
- break;
- default:
- LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key);
- }
- }
- LOG.trace("Finished parsing Prefix Attributes.");
- builder.setRouteTags(routeTags);
- builder.setExtendedTags(exRouteTags);
- 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.
- *
- * @param attribute DataObject representing LinkstatePathAttribute
- * @param byteAggregator ByteBuf where all serialized data are aggregated
- */
-
- @Override
- public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
- Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
- final PathAttributes1 pathAttributes1 = ((PathAttributes) attribute).getAugmentation(PathAttributes1.class);
- if (pathAttributes1 == null) {
- return;
- }
- final LinkStateAttribute linkState = pathAttributes1.getLinkstatePathAttribute().getLinkStateAttribute();
- final ByteBuf lsBuffer = Unpooled.buffer();
- if (linkState instanceof LinkAttributesCase) {
- serializeLinkAttributes((LinkAttributesCase) linkState, lsBuffer);
- } else if (linkState instanceof NodeAttributesCase) {
- serializeNodeAttributes((NodeAttributesCase) linkState, lsBuffer);
- } else if (linkState instanceof PrefixAttributesCase) {
- serializePrefixAttributes((PrefixAttributesCase) linkState, lsBuffer);
- }
- AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, getType(), lsBuffer, byteAggregator);
- }
-
- private void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf byteAggregator) {
- final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes();
- LOG.trace("Started serializing Link Attributes");
- if (linkAttributes.getLocalIpv4RouterId() != null) {
- writeTLV(TlvCode.LOCAL_IPV4_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(linkAttributes.getLocalIpv4RouterId().getValue()).getAddress()), byteAggregator);
- }
- if (linkAttributes.getLocalIpv6RouterId() != null) {
- writeTLV(TlvCode.LOCAL_IPV6_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(linkAttributes.getLocalIpv6RouterId().getValue()).getAddress()), byteAggregator);
- }
- if (linkAttributes.getRemoteIpv4RouterId() != null) {
- writeTLV(TlvCode.REMOTE_IPV4_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(linkAttributes.getRemoteIpv4RouterId().getValue()).getAddress()), byteAggregator);
- }
- if (linkAttributes.getRemoteIpv6RouterId() != null) {
- writeTLV(TlvCode.REMOTE_IPV6_ROUTER_ID, Unpooled.wrappedBuffer(InetAddresses.forString(linkAttributes.getRemoteIpv6RouterId().getValue()).getAddress()), byteAggregator);
- }
- if (linkAttributes.getAdminGroup() != null) {
- writeTLV(TlvCode.ADMIN_GROUP, Unpooled.copyInt(linkAttributes.getAdminGroup().getValue().intValue()), byteAggregator);
- }
- if (linkAttributes.getMaxLinkBandwidth() != null) {
- writeTLV(TlvCode.MAX_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxLinkBandwidth().getValue()), byteAggregator);
- }
- if (linkAttributes.getMaxReservableBandwidth() != null) {
- writeTLV(TlvCode.MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxReservableBandwidth().getValue()), byteAggregator);
- }
- // this sub-TLV contains eight 32-bit IEEE floating point numbers
- final List<UnreservedBandwidth> ubList = linkAttributes.getUnreservedBandwidth();
- if (ubList != null && !ubList.isEmpty()) {
- final ByteBuf unreservedBandwithBuf = Unpooled.buffer();
- for (final UnreservedBandwidth unreservedBandwidth : ubList) {
- unreservedBandwithBuf.writeBytes(unreservedBandwidth.getBandwidth().getValue());
- }
- writeTLV(TlvCode.UNRESERVED_BANDWIDTH, unreservedBandwithBuf, byteAggregator);
- }
- if (linkAttributes.getTeMetric() != null) {
- writeTLV(TlvCode.TE_METRIC, Unpooled.copyLong(linkAttributes.getTeMetric().getValue().longValue()), byteAggregator);
- }
- if (linkAttributes.getLinkProtection() != null) {
- writeTLV(TlvCode.LINK_PROTECTION_TYPE, Unpooled.copyShort(linkAttributes.getLinkProtection().getIntValue()), 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);
- }
- final List<SrlgId> srlgList = linkAttributes.getSharedRiskLinkGroups();
- if (srlgList != null && !srlgList.isEmpty()) {
- final ByteBuf sharedRLGBuf = Unpooled.buffer();
- for (final SrlgId srlgId : srlgList) {
- sharedRLGBuf.writeInt(srlgId.getValue().intValue());
- }
- writeTLV(TlvCode.SHARED_RISK_LINK_GROUP, sharedRLGBuf, byteAggregator);
- }
- if (linkAttributes.getLinkName() != null) {
- writeTLV(TlvCode.LINK_NAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(linkAttributes.getLinkName())), 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();
- final List<TopologyIdentifier> topList = nodeAttributes.getTopologyIdentifier();
- if (topList != null && !topList.isEmpty()) {
- final ByteBuf mpIdBuf = Unpooled.buffer();
- for (final TopologyIdentifier topologyIdentifier : topList) {
- mpIdBuf.writeShort(topologyIdentifier.getValue());
- }
- writeTLV(TlvCode.MULTI_TOPOLOGY_ID, mpIdBuf, byteAggregator);
- }
- serializeNodeFlagBits(nodeAttributes.getNodeFlags(), byteAggregator);
- if (nodeAttributes.getDynamicHostname() != null) {
- writeTLV(TlvCode.DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(nodeAttributes.getDynamicHostname())), byteAggregator);
- }
- final List<IsisAreaIdentifier> isisList = nodeAttributes.getIsisAreaId();
- if (isisList != null && !isisList.isEmpty()) {
- for (final IsisAreaIdentifier isisAreaIdentifier : isisList) {
- 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();
- if (nodeFlagBits.isOverload() != null) {
- flags.set(OVERLOAD_BIT, nodeFlagBits.isOverload());
- }
- if (nodeFlagBits.isAttached() != null) {
- flags.set(ATTACHED_BIT, nodeFlagBits.isAttached());
- }
- if (nodeFlagBits.isExternal() != null) {
- flags.set(EXTERNAL_BIT, nodeFlagBits.isExternal());
- }
- if (nodeFlagBits.isAbr() != null) {
- flags.set(ABBR_BIT, nodeFlagBits.isAbr());
- }
- nodeFlagBuf.writeBytes(flags.toByteArray());
- writeTLV(TlvCode.NODE_FLAG_BITS, nodeFlagBuf, byteAggregator);
- }
- }
-
- private void serializePrefixAttributes(final PrefixAttributesCase prefixAttributesCase, final ByteBuf byteAggregator) {
- final PrefixAttributes prefixAtrributes = prefixAttributesCase.getPrefixAttributes();
- if (prefixAtrributes.getIgpBits() != null) {
- final BitSet igpBit = new BitSet();
- final Boolean bit = prefixAtrributes.getIgpBits().getUpDown().isUpDown();
- if (bit != null) {
- igpBit.set(UP_DOWN_BIT, bit);
- }
- writeTLV(TlvCode.IGP_FLAGS, Unpooled.wrappedBuffer(igpBit.toByteArray()), byteAggregator);
- }
- if (prefixAtrributes.getRouteTags() != null) {
- final ByteBuf routeTagsBuf = Unpooled.buffer();
- for (final RouteTag routeTag : prefixAtrributes.getRouteTags()) {
- routeTagsBuf.writeBytes(routeTag.getValue());
- }
- writeTLV(TlvCode.ROUTE_TAG, routeTagsBuf, byteAggregator);
- }
- final List<ExtendedRouteTag> routeTagList = prefixAtrributes.getExtendedTags();
- if (routeTagList != null && !routeTagList.isEmpty()) {
- final ByteBuf extendedBuf = Unpooled.buffer();
- for (final ExtendedRouteTag extendedRouteTag : routeTagList) {
- extendedBuf.writeBytes(extendedRouteTag.getValue());
- }
- writeTLV(TlvCode.EXTENDED_ROUTE_TAG, extendedBuf, byteAggregator);
- }
- if (prefixAtrributes.getPrefixMetric() != null) {
- writeTLV(TlvCode.PREFIX_METRIC, Unpooled.copyInt(prefixAtrributes.getPrefixMetric().getValue().intValue()), byteAggregator);
- }
- 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) {
- ospfBuf.writeBytes(Ipv4Util.bytesForAddress(forwardingAddress.getIpv4Address()));
- } else if (forwardingAddress.getIpv6Address() != null) {
- ospfBuf.writeBytes(Ipv6Util.bytesForAddress(forwardingAddress.getIpv6Address()));
- }
- writeTLV(TlvCode.FORWARDING_ADDRESS, ospfBuf, byteAggregator);
- }
- }
-
- /**
- * Util method for writing TLV header.
- * @param type TLV type
- * @param value TLV value
- * @param byteAggregator final ByteBuf where the tlv should be serialized
- */
- protected static void writeTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator){
- byteAggregator.writeShort(type);
- byteAggregator.writeShort(value.writerIndex());
- byteAggregator.writeBytes(value);
- value.readerIndex(0);
- LOG.debug("Serialized tlv type {} to: {}", type, ByteBufUtil.hexDump(value));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.linkstate;
-
-import com.google.common.base.Preconditions;
-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;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.protocol.util.Ipv4Util;
-import org.opendaylight.protocol.util.Ipv6Util;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.AreaIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.DomainIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Identifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6InterfaceIdentifier;
-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.NodeIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.OspfInterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.OspfRouteType;
-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.RouteDistinguisher;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.isis.lan.identifier.IsIsRouterIdentifier;
-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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.PrefixDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.PrefixDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
-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.CRouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisPseudonodeCase;
-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.OspfNodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
-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.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
-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.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
-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.MpUnreachNlri;
-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.AdvertizedRoutes;
-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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Parser and serializer for Linkstate NLRI.
- */
-public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
- private static final Logger LOG = LoggerFactory.getLogger(LinkstateNlriParser.class);
- 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;
-
- private static final int TYPE_LENGTH = 2;
- private static final int LENGTH_SIZE = 2;
-
- static final int TOPOLOGY_ID_OFFSET = 0x3fff;
-
- private final boolean isVpn;
-
- public LinkstateNlriParser(final boolean isVpn) {
- this.isVpn = isVpn;
- }
-
- private static NodeIdentifier parseLink(final CLinkstateDestinationBuilder builder, final ByteBuf buffer) throws BGPParsingException {
- final int type = buffer.readUnsignedShort();
- final int length = buffer.readUnsignedShort();
- final NodeIdentifier remote = null;
- if (type == TlvCode.REMOTE_NODE_DESCRIPTORS) {
- builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(buffer.slice(buffer.readerIndex(), length), false));
- buffer.skipBytes(length);
- }
- builder.setLinkDescriptors(parseLinkDescriptors(buffer.slice()));
- return remote;
- }
-
- private static LinkDescriptors parseLinkDescriptors(final ByteBuf buffer) throws BGPParsingException {
- final LinkDescriptorsBuilder builder = new LinkDescriptorsBuilder();
- while (buffer.isReadable()) {
- final int type = buffer.readUnsignedShort();
- final int length = buffer.readUnsignedShort();
- final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
- LOG.trace("Parsing Link Descriptor: {}", ByteBufUtil.hexDump(value));
- switch (type) {
- case TlvCode.LINK_LR_IDENTIFIERS:
- builder.setLinkLocalIdentifier(value.readUnsignedInt());
- builder.setLinkRemoteIdentifier(value.readUnsignedInt());
- LOG.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
- builder.getLinkRemoteIdentifier());
- break;
- case TlvCode.IPV4_IFACE_ADDRESS:
- final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
- builder.setIpv4InterfaceAddress(lipv4);
- LOG.debug("Parsed IPv4 interface address {}.", lipv4);
- break;
- case TlvCode.IPV4_NEIGHBOR_ADDRESS:
- final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
- builder.setIpv4NeighborAddress(ripv4);
- LOG.debug("Parsed IPv4 neighbor address {}.", ripv4);
- break;
- case TlvCode.IPV6_IFACE_ADDRESS:
- final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value));
- builder.setIpv6InterfaceAddress(lipv6);
- LOG.debug("Parsed IPv6 interface address {}.", lipv6);
- break;
- case TlvCode.IPV6_NEIGHBOR_ADDRESS:
- final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value));
- builder.setIpv6NeighborAddress(ripv6);
- LOG.debug("Parsed IPv6 neighbor address {}.", ripv6);
- break;
- case TlvCode.MULTI_TOPOLOGY_ID:
- final TopologyIdentifier topId = new TopologyIdentifier(value.readUnsignedShort() & LinkstateNlriParser.TOPOLOGY_ID_OFFSET);
- builder.setMultiTopologyId(topId);
- LOG.debug("Parsed topology identifier {}.", topId);
- break;
- default:
- throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
- }
- buffer.skipBytes(length);
- }
- LOG.trace("Finished parsing Link descriptors.");
- return builder.build();
- }
-
- private static NodeIdentifier parseNodeDescriptors(final ByteBuf buffer, final boolean local) throws BGPParsingException {
- AsNumber asnumber = null;
- DomainIdentifier bgpId = null;
- AreaIdentifier ai = null;
- CRouterIdentifier routerId = null;
- while (buffer.isReadable()) {
- final int type = buffer.readUnsignedShort();
- final int length = buffer.readUnsignedShort();
- final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
- LOG.trace("Parsing Node Descriptor: {}", ByteBufUtil.hexDump(value));
- switch (type) {
- case TlvCode.AS_NUMBER:
- asnumber = new AsNumber(value.readUnsignedInt());
- LOG.debug("Parsed {}", asnumber);
- break;
- case TlvCode.BGP_LS_ID:
- bgpId = new DomainIdentifier(value.readUnsignedInt());
- LOG.debug("Parsed {}", bgpId);
- break;
- case TlvCode.AREA_ID:
- ai = new AreaIdentifier(value.readUnsignedInt());
- LOG.debug("Parsed area identifier {}", ai);
- break;
- case TlvCode.IGP_ROUTER_ID:
- routerId = parseRouterId(value);
- LOG.debug("Parsed Router Identifier {}", routerId);
- break;
- default:
- throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
- }
- buffer.skipBytes(length);
- }
- 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();
- }
-
- 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();
- }
- 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();
- 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();
- }
- if (value.readableBytes() == OSPF_PSEUDONODE_ROUTER_ID_LENGTH) {
- return new OspfPseudonodeCaseBuilder().setOspfPseudonode(
- new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt()).setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()).build();
- }
- throw new BGPParsingException("Router Id of invalid length " + value.readableBytes());
- }
-
- private static PrefixDescriptors parsePrefixDescriptors(final ByteBuf buffer, final boolean ipv4) throws BGPParsingException {
- final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
- while (buffer.isReadable()) {
- final int type = buffer.readUnsignedShort();
- final int length = buffer.readUnsignedShort();
- final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
- LOG.trace("Parsing Prefix Descriptor: {}", ByteBufUtil.hexDump(value));
- switch (type) {
- case TlvCode.MULTI_TOPOLOGY_ID:
- final TopologyIdentifier topologyId = new TopologyIdentifier(value.readShort() & LinkstateNlriParser.TOPOLOGY_ID_OFFSET);
- builder.setMultiTopologyId(topologyId);
- LOG.trace("Parsed Topology Identifier: {}", topologyId);
- break;
- case TlvCode.OSPF_ROUTE_TYPE:
- final int rt = value.readByte();
- final OspfRouteType routeType = OspfRouteType.forValue(rt);
- if (routeType == null) {
- throw new BGPParsingException("Unknown OSPF Route Type: " + rt);
- }
- builder.setOspfRouteType(routeType);
- LOG.trace("Parser RouteType: {}", routeType);
- break;
- case TlvCode.IP_REACHABILITY:
- IpPrefix prefix = null;
- final int prefixLength = value.readByte();
- final int size = prefixLength / Byte.SIZE + ((prefixLength % Byte.SIZE == 0) ? 0 : 1);
- if (size != value.readableBytes()) {
- LOG.debug("Expected length {}, actual length {}.", size, value.readableBytes());
- throw new BGPParsingException("Illegal length of IP reachability TLV: " + (value.readableBytes()));
- }
- if (ipv4) {
- prefix = new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(value, size), prefixLength));
- } else {
- prefix = new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(value, size), prefixLength));
- }
- builder.setIpReachabilityInformation(prefix);
- LOG.trace("Parsed IP reachability info: {}", prefix);
- break;
- default:
- throw new BGPParsingException("Prefix Descriptor not recognized, type: " + type);
- }
- buffer.skipBytes(length);
- }
- LOG.debug("Finished parsing Prefix descriptors.");
- return builder.build();
- }
-
- /**
- * Parses common parts for Link State Nodes, Links and Prefixes, that includes protocol ID and identifier tlv.
- *
- * @param nlri as byte array
- * @return {@link CLinkstateDestination}
- * @throws BGPParsingException if parsing was unsuccessful
- */
- public static List<CLinkstateDestination> parseNlri(final ByteBuf nlri, final boolean isVpn) throws BGPParsingException {
- if (!nlri.isReadable()) {
- return null;
- }
- final List<CLinkstateDestination> dests = Lists.newArrayList();
-
- CLinkstateDestinationBuilder builder = null;
-
- while (nlri.isReadable()) {
- builder = new CLinkstateDestinationBuilder();
- final NlriType type = NlriType.forValue(nlri.readUnsignedShort());
- builder.setNlriType(type);
-
- // length means total length of the tlvs including route distinguisher not including the type field
- final int length = nlri.readUnsignedShort();
- RouteDistinguisher distinguisher = null;
- if (isVpn) {
- // this parses route distinguisher
- distinguisher = new RouteDistinguisher(BigInteger.valueOf(nlri.readLong()));
- builder.setDistinguisher(distinguisher);
- }
- // parse source protocol
- final ProtocolId sp = ProtocolId.forValue(nlri.readByte());
- builder.setProtocolId(sp);
-
- // parse identifier
- final Identifier identifier = new Identifier(BigInteger.valueOf(nlri.readLong()));
- builder.setIdentifier(identifier);
-
- // if we are dealing with linkstate nodes/links, parse local node descriptor
- NodeIdentifier localDescriptor = null;
- int locallength = 0;
- final int localtype = nlri.readUnsignedShort();
- locallength = nlri.readUnsignedShort();
- if (localtype == TlvCode.LOCAL_NODE_DESCRIPTORS) {
- localDescriptor = parseNodeDescriptors(nlri.slice(nlri.readerIndex(), locallength), true);
- }
- nlri.skipBytes(locallength);
- builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
- final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
- - TYPE_LENGTH - LENGTH_SIZE - locallength;
- LOG.trace("Restlength {}", restLength);
- final ByteBuf rest = nlri.slice(nlri.readerIndex(), restLength);
- switch (type) {
- case Link:
- parseLink(builder, rest);
- break;
- case Ipv4Prefix:
- builder.setPrefixDescriptors(parsePrefixDescriptors(rest, true));
- break;
- case Ipv6Prefix:
- builder.setPrefixDescriptors(parsePrefixDescriptors(rest, false));
- break;
- case Node:
- // node nlri is already parsed as it contains only the common fields for node and link nlri
- break;
- default:
- break;
- }
- nlri.skipBytes(restLength);
- dests.add(builder.build());
- }
- return dests;
- }
-
- @Override
- public void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
- if (!nlri.isReadable()) {
- return;
- }
- final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
-
- 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());
- }
-
- @Override
- public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder) throws BGPParsingException {
- if (!nlri.isReadable()) {
- return;
- }
- final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
-
- builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
- new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build()).build());
- }
-
- /**
- * Serializes Linkstate NLRI to byte array. We need this as NLRI serves as a key in upper layers.
- *
- * @param destination Linkstate NLRI to be serialized
- */
- public static void serializeNlri(final CLinkstateDestination destination, final ByteBuf buffer) {
- final ByteBuf nlriByteBuf = Unpooled.buffer();
- if (destination.getDistinguisher() != null) {
- nlriByteBuf.writeBytes(destination.getDistinguisher().getValue().toByteArray());
- }
- nlriByteBuf.writeByte(destination.getProtocolId().getIntValue());
- nlriByteBuf.writeLong(destination.getIdentifier().getValue().longValue());
-
- // serialize local node descriptors
- final ByteBuf ldescs = Unpooled.buffer();
- serializeNodeDescriptors(destination.getLocalNodeDescriptors(), ldescs);
- LinkstateAttributeParser.writeTLV(TlvCode.LOCAL_NODE_DESCRIPTORS, ldescs, nlriByteBuf);
-
- switch (destination.getNlriType()) {
- case Ipv4Prefix:
- case Ipv6Prefix:
- if (destination.getPrefixDescriptors() != null) {
- serializePrefixDescriptors(destination.getPrefixDescriptors(), nlriByteBuf);
- }
- break;
- case Link:
- final ByteBuf rdescs = Unpooled.buffer();
- serializeNodeDescriptors(destination.getRemoteNodeDescriptors(), rdescs);
- LinkstateAttributeParser.writeTLV(TlvCode.REMOTE_NODE_DESCRIPTORS, rdescs, nlriByteBuf);
- if (destination.getLinkDescriptors() != null) {
- serializeLinkDescriptors(destination.getLinkDescriptors(), nlriByteBuf);
- }
- break;
- case Node:
- break;
- default:
- LOG.warn("Unknown NLRI Type.");
- break;
- }
- LinkstateAttributeParser.writeTLV(destination.getNlriType().getIntValue(), nlriByteBuf, buffer);
- }
-
- private static void serializeNodeDescriptors(final NodeIdentifier descriptors, final ByteBuf buffer) {
- if (descriptors.getAsNumber() != null) {
- LinkstateAttributeParser.writeTLV(TlvCode.AS_NUMBER, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getAsNumber().getValue()).intValue()), buffer);
- }
- if (descriptors.getDomainId() != null) {
- LinkstateAttributeParser.writeTLV(TlvCode.BGP_LS_ID, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getDomainId().getValue()).intValue()), buffer);
- }
- if (descriptors.getAreaId() != null) {
- LinkstateAttributeParser.writeTLV(TlvCode.AREA_ID, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getAreaId().getValue()).intValue()), buffer);
- }
- if (descriptors.getCRouterIdentifier() != null) {
- final ByteBuf routerIdBuf = Unpooled.buffer();
- serializeRouterId(descriptors.getCRouterIdentifier(), routerIdBuf);
- LinkstateAttributeParser.writeTLV(TlvCode.IGP_ROUTER_ID, routerIdBuf, buffer);
- }
- }
-
- private static void serializeRouterId(final CRouterIdentifier routerId, final ByteBuf buffer) {
- if (routerId instanceof IsisNodeCase) {
- final IsisNode isis = ((IsisNodeCase) routerId).getIsisNode();
- buffer.writeBytes(isis.getIsoSystemId().getValue());
- } else if (routerId instanceof IsisPseudonodeCase) {
- final IsisPseudonode isis = ((IsisPseudonodeCase) routerId).getIsisPseudonode();
- buffer.writeBytes(isis.getIsIsRouterIdentifier().getIsoSystemId().getValue());
- buffer.writeByte(((isis.getPsn() != null) ? isis.getPsn() : 0));
- } else if (routerId instanceof OspfNodeCase) {
- buffer.writeInt(UnsignedInteger.valueOf(((OspfNodeCase) routerId).getOspfNode().getOspfRouterId()).intValue());
- } else if (routerId instanceof OspfPseudonodeCase) {
- final OspfPseudonode node = ((OspfPseudonodeCase) routerId).getOspfPseudonode();
- buffer.writeInt(UnsignedInteger.valueOf(node.getOspfRouterId()).intValue());
- buffer.writeInt(UnsignedInteger.valueOf(node.getLanInterface().getValue()).intValue());
- }
- }
-
- private static void serializeLinkDescriptors(final LinkDescriptors descriptors, final ByteBuf buffer) {
- if (descriptors.getLinkLocalIdentifier() != null && descriptors.getLinkRemoteIdentifier() != null) {
- 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.getIpv4NeighborAddress() != null) {
- LinkstateAttributeParser.writeTLV(TlvCode.IPV4_NEIGHBOR_ADDRESS, Unpooled.wrappedBuffer(Ipv4Util.bytesForAddress(descriptors.getIpv4NeighborAddress())), buffer);
- }
- if (descriptors.getIpv6InterfaceAddress() != null) {
- LinkstateAttributeParser.writeTLV(TlvCode.IPV6_IFACE_ADDRESS, Unpooled.wrappedBuffer(Ipv6Util.bytesForAddress(descriptors.getIpv6InterfaceAddress())), buffer);
- }
- if (descriptors.getIpv6NeighborAddress() != null) {
- LinkstateAttributeParser.writeTLV(TlvCode.IPV6_NEIGHBOR_ADDRESS, Unpooled.wrappedBuffer(Ipv6Util.bytesForAddress(descriptors.getIpv6NeighborAddress())), buffer);
- }
- if (descriptors.getMultiTopologyId() != null) {
- LinkstateAttributeParser.writeTLV(TlvCode.MULTI_TOPOLOGY_ID, Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
- }
- }
-
- private static void serializePrefixDescriptors(final PrefixDescriptors descriptors, final ByteBuf buffer) {
- if (descriptors.getMultiTopologyId() != null) {
- LinkstateAttributeParser.writeTLV(TlvCode.MULTI_TOPOLOGY_ID, Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
- }
- if (descriptors.getOspfRouteType() != null) {
- LinkstateAttributeParser.writeTLV(TlvCode.OSPF_ROUTE_TYPE,
- Unpooled.wrappedBuffer(new byte[] {UnsignedBytes.checkedCast(descriptors.getOspfRouteType().getIntValue()) }), buffer);
- }
- if (descriptors.getIpReachabilityInformation() != null) {
- final IpPrefix prefix = descriptors.getIpReachabilityInformation();
- byte[] prefixBytes = null;
- if (prefix.getIpv4Prefix() != null) {
- prefixBytes = Ipv4Util.bytesForPrefixBegin(prefix.getIpv4Prefix());
- } else if (prefix.getIpv6Prefix() != null) {
- prefixBytes = Ipv6Util.bytesForPrefixBegin(prefix.getIpv6Prefix());
- }
- LinkstateAttributeParser.writeTLV(TlvCode.IP_REACHABILITY, Unpooled.wrappedBuffer(prefixBytes), buffer);
- }
- }
-
- @Override
- public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
- Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
- final PathAttributes pathAttributes = (PathAttributes) attribute;
- final PathAttributes1 pathAttributes1 = pathAttributes.getAugmentation(PathAttributes1.class);
- final PathAttributes2 pathAttributes2 = pathAttributes.getAugmentation(PathAttributes2.class);
- 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) {
- 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();
-
- for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
- serializeNlri(cLinkstateDestination, byteAggregator);
- }
- }
- } else if (pathAttributes2 != null) {
- final MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri();
- if (mpUnreachNlri.getWithdrawnRoutes() != null && mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationLinkstateCase) {
- final DestinationLinkstateCase linkstateCase = (DestinationLinkstateCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
- for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
- serializeNlri(cLinkstateDestination, byteAggregator);
- }
- }
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.linkstate;
-
-final class TlvCode {
-
- private TlvCode() {
- throw new UnsupportedOperationException();
- }
-
- static final int LOCAL_NODE_DESCRIPTORS = 256;
-
- static final int REMOTE_NODE_DESCRIPTORS = 257;
-
- /* Link Descriptor TLVs */
-
- static final int LINK_LR_IDENTIFIERS = 258;
-
- static final int IPV4_IFACE_ADDRESS = 259;
-
- static final int IPV4_NEIGHBOR_ADDRESS = 260;
-
- static final int IPV6_IFACE_ADDRESS = 261;
-
- static final int IPV6_NEIGHBOR_ADDRESS = 262;
-
- /* Link Attribute TLVs */
-
- static final int LOCAL_IPV4_ROUTER_ID = 1028;
-
- static final int LOCAL_IPV6_ROUTER_ID = 1029;
-
- static final int REMOTE_IPV4_ROUTER_ID = 1030;
-
- static final int REMOTE_IPV6_ROUTER_ID = 1031;
-
- static final int ADMIN_GROUP = 1088;
-
- static final int MAX_BANDWIDTH = 1089;
-
- static final int MAX_RESERVABLE_BANDWIDTH = 1090;
-
- static final int UNRESERVED_BANDWIDTH = 1091;
-
- static final int TE_METRIC = 1092;
-
- static final int LINK_PROTECTION_TYPE = 1093;
-
- static final int MPLS_PROTOCOL = 1094;
-
- static final int METRIC = 1095;
-
- static final int SHARED_RISK_LINK_GROUP = 1096;
-
- static final int LINK_OPAQUE = 1097;
-
- static final int LINK_NAME = 1098;
-
- /* Prefix Descriptor TLVs */
-
- static final int MULTI_TOPOLOGY_ID = 263;
-
- static final int OSPF_ROUTE_TYPE = 264;
-
- static final int IP_REACHABILITY = 265;
-
- /* Prefix Attribute TLVs */
-
- static final int IGP_FLAGS = 1152;
-
- static final int ROUTE_TAG = 1153;
-
- static final int EXTENDED_ROUTE_TAG = 1154;
-
- static final int PREFIX_METRIC = 1155;
-
- static final int FORWARDING_ADDRESS = 1156;
-
- static final int PREFIX_OPAQUE = 1157;
-
- /* Node Descriptor TLVs */
-
- static final int AS_NUMBER = 512;
-
- static final int BGP_LS_ID = 513;
-
- static final int AREA_ID = 514;
-
- static final int IGP_ROUTER_ID = 515;
-
- /* Node Attribute TLVs */
-
- static final int NODE_FLAG_BITS = 1024;
-
- static final int NODE_OPAQUE = 1025;
-
- static final int DYNAMIC_HOSTNAME = 1026;
-
- static final int ISIS_AREA_IDENTIFIER = 1027;
-}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class TlvUtil {
+
+ private TlvUtil() {
+ throw new UnsupportedOperationException();
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(TlvUtil.class);
+
+ public static final int TOPOLOGY_ID_OFFSET = 0x3fff;
+
+ public static final int MULTI_TOPOLOGY_ID = 263;
+ public static final int LOCAL_IPV4_ROUTER_ID = 1028;
+ public static final int LOCAL_IPV6_ROUTER_ID = 1029;
+
+ /**
+ * Util method for writing TLV header.
+ * @param type TLV type
+ * @param value TLV value
+ * @param byteAggregator final ByteBuf where the tlv should be serialized
+ */
+ public static void writeTLV(final int type, final ByteBuf value, final ByteBuf byteAggregator){
+ byteAggregator.writeShort(type);
+ byteAggregator.writeShort(value.writerIndex());
+ byteAggregator.writeBytes(value);
+ value.readerIndex(0);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Serialized tlv type {} to: {}", type, ByteBufUtil.hexDump(value));
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.attribute;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.Multimap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map.Entry;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.AdministrativeGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4RouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6RouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.LinkProtectionType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.MplsProtocolMask;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class LinkAttributesParser {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LinkAttributesParser.class);
+
+ private static final int UNRESERVED_BW_COUNT = 8;
+
+ private static final int BANDWIDTH_LENGTH = 4;
+
+ // MPLS protection mask bits
+ private static final int LDP_BIT = 7;
+ private static final int RSVP_BIT = 6;
+
+ /* Link Attribute TLVs */
+ private static final int REMOTE_IPV4_ROUTER_ID = 1030;
+ private static final int REMOTE_IPV6_ROUTER_ID = 1031;
+ private static final int ADMIN_GROUP = 1088;
+ private static final int MAX_BANDWIDTH = 1089;
+ private static final int MAX_RESERVABLE_BANDWIDTH = 1090;
+ private static final int UNRESERVED_BANDWIDTH = 1091;
+ private static final int TE_METRIC = 1092;
+ private static final int LINK_PROTECTION_TYPE = 1093;
+ private static final int MPLS_PROTOCOL = 1094;
+ private static final int METRIC = 1095;
+ private static final int SHARED_RISK_LINK_GROUP = 1096;
+ private static final int LINK_OPAQUE = 1097;
+ private static final int LINK_NAME = 1098;
+
+ /**
+ * Parse Link Attributes.
+ *
+ * @param attributes key is the tlv type and value is the value of the tlv
+ * @return {@link LinkStateAttribute}
+ */
+ static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes) {
+ final LinkAttributesBuilder builder = new LinkAttributesBuilder();
+ for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
+ LOG.trace("Link attribute TLV {}", entry.getKey());
+ final int key = entry.getKey();
+ final ByteBuf value = entry.getValue();
+ switch (key) {
+ case TlvUtil.LOCAL_IPV4_ROUTER_ID:
+ final Ipv4RouterIdentifier lipv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
+ builder.setLocalIpv4RouterId(lipv4);
+ LOG.debug("Parsed IPv4 Router-ID of local node: {}", lipv4);
+ break;
+ case TlvUtil.LOCAL_IPV6_ROUTER_ID:
+ final Ipv6RouterIdentifier lipv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
+ builder.setLocalIpv6RouterId(lipv6);
+ LOG.debug("Parsed IPv6 Router-ID of local node: {}", lipv6);
+ break;
+ case REMOTE_IPV4_ROUTER_ID:
+ final Ipv4RouterIdentifier ripv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
+ builder.setRemoteIpv4RouterId(ripv4);
+ LOG.debug("Parsed IPv4 Router-ID of remote node: {}", ripv4);
+ break;
+ case REMOTE_IPV6_ROUTER_ID:
+ final Ipv6RouterIdentifier ripv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
+ builder.setRemoteIpv6RouterId(ripv6);
+ LOG.debug("Parsed IPv6 Router-ID of remote node: {}", ripv6);
+ break;
+ case ADMIN_GROUP:
+ builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt()));
+ LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
+ break;
+ case MAX_BANDWIDTH:
+ builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
+ LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
+ break;
+ case MAX_RESERVABLE_BANDWIDTH:
+ builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
+ LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
+ break;
+ case UNRESERVED_BANDWIDTH:
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.link.state.UnreservedBandwidth> unreservedBandwidth = new ArrayList<>(UNRESERVED_BW_COUNT);
+ for (int i = 0; i < UNRESERVED_BW_COUNT; i++) {
+ final ByteBuf v = value.slice(value.readerIndex(), BANDWIDTH_LENGTH);
+ unreservedBandwidth.add(new UnreservedBandwidthBuilder().setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))).setPriority((short) i).build());
+ value.skipBytes(BANDWIDTH_LENGTH);
+ }
+ builder.setUnreservedBandwidth(unreservedBandwidth);
+ LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
+ break;
+ case TE_METRIC:
+ builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
+ LOG.debug("Parsed Metric {}", builder.getTeMetric());
+ break;
+ case LINK_PROTECTION_TYPE:
+ final int l = value.readShort();
+ final LinkProtectionType lpt = LinkProtectionType.forValue(l);
+ if (lpt == null) {
+ LOG.warn("Link Protection Type not recognized: {}", l);
+ break;
+ }
+ builder.setLinkProtection(lpt);
+ LOG.debug("Parsed Link Protection Type {}", lpt);
+ break;
+ case MPLS_PROTOCOL:
+ final BitSet bits = BitSet.valueOf(ByteArray.readAllBytes(value));
+ builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
+ LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
+ break;
+ case METRIC:
+ // length can 3, 2 or 1
+ builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
+ LOG.debug("Parsed Metric {}", builder.getMetric());
+ break;
+ case SHARED_RISK_LINK_GROUP:
+ final List<SrlgId> sharedRiskLinkGroups = new ArrayList<>();
+ while (value.isReadable()) {
+ sharedRiskLinkGroups.add(new SrlgId(value.readUnsignedInt()));
+ }
+ builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
+ LOG.debug("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
+ break;
+ case LINK_OPAQUE:
+ LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
+ break;
+ case LINK_NAME:
+ final String name = new String(ByteArray.readAllBytes(value), Charsets.US_ASCII);
+ builder.setLinkName(name);
+ LOG.debug("Parsed Link Name : {}", name);
+ break;
+ default:
+ LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
+ }
+ }
+ LOG.trace("Finished parsing Link Attributes.");
+ return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
+ }
+
+ static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf byteAggregator) {
+ final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes();
+ LOG.trace("Started serializing Link Attributes");
+ if (linkAttributes.getLocalIpv4RouterId() != null) {
+ TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(linkAttributes.getLocalIpv4RouterId()), byteAggregator);
+ }
+ if (linkAttributes.getLocalIpv6RouterId() != null) {
+ TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(linkAttributes.getLocalIpv6RouterId()), byteAggregator);
+ }
+ if (linkAttributes.getRemoteIpv4RouterId() != null) {
+ TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(linkAttributes.getRemoteIpv4RouterId()), byteAggregator);
+ }
+ if (linkAttributes.getRemoteIpv6RouterId() != null) {
+ TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(linkAttributes.getRemoteIpv6RouterId()), byteAggregator);
+ }
+ if (linkAttributes.getAdminGroup() != null) {
+ TlvUtil.writeTLV(ADMIN_GROUP, Unpooled.copyInt(linkAttributes.getAdminGroup().getValue().intValue()), byteAggregator);
+ }
+ if (linkAttributes.getMaxLinkBandwidth() != null) {
+ TlvUtil.writeTLV(MAX_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxLinkBandwidth().getValue()), byteAggregator);
+ }
+ if (linkAttributes.getMaxReservableBandwidth() != null) {
+ TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(linkAttributes.getMaxReservableBandwidth().getValue()), byteAggregator);
+ }
+ // this sub-TLV contains eight 32-bit IEEE floating point numbers
+ final List<UnreservedBandwidth> ubList = linkAttributes.getUnreservedBandwidth();
+ if (ubList != null && !ubList.isEmpty()) {
+ final ByteBuf unreservedBandwithBuf = Unpooled.buffer();
+ for (final UnreservedBandwidth unreservedBandwidth : ubList) {
+ unreservedBandwithBuf.writeBytes(unreservedBandwidth.getBandwidth().getValue());
+ }
+ TlvUtil.writeTLV(UNRESERVED_BANDWIDTH, unreservedBandwithBuf, byteAggregator);
+ }
+ if (linkAttributes.getTeMetric() != null) {
+ TlvUtil.writeTLV(TE_METRIC, Unpooled.copyLong(linkAttributes.getTeMetric().getValue().longValue()), byteAggregator);
+ }
+ if (linkAttributes.getLinkProtection() != null) {
+ TlvUtil.writeTLV(LINK_PROTECTION_TYPE, Unpooled.copyShort(linkAttributes.getLinkProtection().getIntValue()), byteAggregator);
+ }
+ serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), byteAggregator);
+ if (linkAttributes.getMetric() != null) {
+ // size of metric can be 1,2 or 3 depending on the protocol
+ TlvUtil.writeTLV(METRIC, Unpooled.copyMedium(linkAttributes.getMetric().getValue().intValue()), byteAggregator);
+ }
+ final List<SrlgId> srlgList = linkAttributes.getSharedRiskLinkGroups();
+ if (srlgList != null && !srlgList.isEmpty()) {
+ final ByteBuf sharedRLGBuf = Unpooled.buffer();
+ for (final SrlgId srlgId : srlgList) {
+ sharedRLGBuf.writeInt(srlgId.getValue().intValue());
+ }
+ TlvUtil.writeTLV(SHARED_RISK_LINK_GROUP, sharedRLGBuf, byteAggregator);
+ }
+ if (linkAttributes.getLinkName() != null) {
+ TlvUtil.writeTLV(LINK_NAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(linkAttributes.getLinkName())), 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(1);
+ final BitSet mask = new BitSet(Byte.SIZE);
+ if (mplsProtocolMask.isLdp() != null) {
+ mask.set(LDP_BIT, mplsProtocolMask.isLdp());
+ }
+ if (mplsProtocolMask.isRsvpte() != null) {
+ mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
+ }
+ mplsProtocolMaskBuf.writeBytes(mask.toByteArray());
+ TlvUtil.writeTLV(MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.attribute;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeUtil;
+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.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1Builder;
+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.update.path.attributes.LinkstatePathAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.LinkstatePathAttributeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
+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.message.rev130919.update.PathAttributes;
+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.PathAttributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Parser for Link State Path Attribute.
+ *
+ * @see <a href="http://tools.ietf.org/html/draft-gredler-idr-ls-distribution-04">BGP-LS draft</a>
+ */
+public class LinkstateAttributeParser implements AttributeParser, AttributeSerializer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LinkstateAttributeParser.class);
+
+ private static final int TYPE = 29;
+
+ private static final int LEGACY_TYPE = 99;
+
+ private final int type;
+
+ public LinkstateAttributeParser(final boolean isIanaAssignedType) {
+ this.type = (isIanaAssignedType) ? TYPE : LEGACY_TYPE;
+ }
+
+ public int getType() {
+ return this.type;
+ }
+
+ @Override
+ public void parseAttribute(final ByteBuf buffer, final PathAttributesBuilder builder) throws BGPParsingException {
+ final NlriType nlriType = getNlriType(builder);
+ if (nlriType == null) {
+ LOG.warn("No Linkstate NLRI found, not parsing Linkstate attribute");
+ return;
+ }
+ final PathAttributes1 a = new PathAttributes1Builder().setLinkstatePathAttribute(parseLinkState(nlriType, buffer)).build();
+ builder.addAugmentation(PathAttributes1.class, a);
+ }
+
+ private NlriType getNlriType(final PathAttributesBuilder pab) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1 mpr = pab.getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1.class);
+ if (mpr != null && mpr.getMpReachNlri() != null) {
+ final DestinationType dt = mpr.getMpReachNlri().getAdvertizedRoutes().getDestinationType();
+ if (dt instanceof DestinationLinkstateCase) {
+ for (final CLinkstateDestination d : ((DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) {
+ return d.getNlriType();
+ }
+ }
+ }
+ final PathAttributes2 mpu = pab.getAugmentation(PathAttributes2.class);
+ if (mpu != null && mpu.getMpUnreachNlri() != null) {
+ final DestinationType dt = mpu.getMpUnreachNlri().getWithdrawnRoutes().getDestinationType();
+ if (dt instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) {
+ for (final CLinkstateDestination d : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) {
+ return d.getNlriType();
+ }
+ }
+ }
+ return null;
+ }
+
+ private static LinkstatePathAttribute parseLinkState(final NlriType nlri, final ByteBuf buffer) throws BGPParsingException {
+ /*
+ * e.g. IS-IS Area Identifier TLV can occur multiple times
+ */
+ final Multimap<Integer, ByteBuf> map = HashMultimap.create();
+ while (buffer.isReadable()) {
+ final int type = buffer.readUnsignedShort();
+ final int length = buffer.readUnsignedShort();
+ final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
+ map.put(type, value);
+ buffer.skipBytes(length);
+ }
+ final LinkstatePathAttributeBuilder builder = new LinkstatePathAttributeBuilder();
+
+ switch (nlri) {
+ case Ipv4Prefix:
+ case Ipv6Prefix:
+ builder.setLinkStateAttribute(PrefixAttributesParser.parsePrefixAttributes(map));
+ return builder.build();
+ case Link:
+ builder.setLinkStateAttribute(LinkAttributesParser.parseLinkAttributes(map));
+ return builder.build();
+ case Node:
+ builder.setLinkStateAttribute(NodeAttributesParser.parseNodeAttributes(map));
+ return builder.build();
+ default:
+ throw new IllegalStateException("Unhandled NLRI type " + nlri);
+ }
+ }
+
+ /**
+ * Serialize linkstate attributes.
+ *
+ * @param attribute DataObject representing LinkstatePathAttribute
+ * @param byteAggregator ByteBuf where all serialized data are aggregated
+ */
+
+ @Override
+ public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
+ final PathAttributes1 pathAttributes1 = ((PathAttributes) attribute).getAugmentation(PathAttributes1.class);
+ if (pathAttributes1 == null) {
+ return;
+ }
+ final LinkStateAttribute linkState = pathAttributes1.getLinkstatePathAttribute().getLinkStateAttribute();
+ final ByteBuf lsBuffer = Unpooled.buffer();
+ if (linkState instanceof LinkAttributesCase) {
+ LinkAttributesParser.serializeLinkAttributes((LinkAttributesCase) linkState, lsBuffer);
+ } else if (linkState instanceof NodeAttributesCase) {
+ NodeAttributesParser.serializeNodeAttributes((NodeAttributesCase) linkState, lsBuffer);
+ } else if (linkState instanceof PrefixAttributesCase) {
+ PrefixAttributesParser.serializePrefixAttributes((PrefixAttributesCase) linkState, lsBuffer);
+ }
+ AttributeUtil.formatAttribute(AttributeUtil.OPTIONAL, getType(), lsBuffer, byteAggregator);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.attribute;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.Multimap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map.Entry;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4RouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6RouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.IsisAreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeFlagBits;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributesBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class NodeAttributesParser {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NodeAttributesParser.class);
+
+ // node flag bits
+ private static final int OVERLOAD_BIT = 7;
+ private static final int ATTACHED_BIT = 6;
+ private static final int EXTERNAL_BIT = 5;
+ private static final int ABBR_BIT = 4;
+
+ /* Node Attribute TLVs */
+ private static final int NODE_FLAG_BITS = 1024;
+ private static final int NODE_OPAQUE = 1025;
+ private static final int DYNAMIC_HOSTNAME = 1026;
+ private static final int ISIS_AREA_IDENTIFIER = 1027;
+
+ /**
+ * Parse Node Attributes.
+ *
+ * @param attributes key is the tlv type and value is the value of the tlv
+ * @return {@link LinkStateAttribute}
+ */
+ static LinkStateAttribute parseNodeAttributes(final Multimap<Integer, ByteBuf> attributes) {
+ final List<TopologyIdentifier> topologyMembership = new ArrayList<>();
+ final List<IsisAreaIdentifier> areaMembership = new ArrayList<>();
+ final NodeAttributesBuilder builder = new NodeAttributesBuilder();
+ for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
+ final int key = entry.getKey();
+ final ByteBuf value = entry.getValue();
+ LOG.trace("Node attribute TLV {}", key);
+ switch (key) {
+ case TlvUtil.MULTI_TOPOLOGY_ID:
+ while (value.isReadable()) {
+ final TopologyIdentifier topId = new TopologyIdentifier(value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
+ topologyMembership.add(topId);
+ LOG.debug("Parsed Topology Identifier: {}", topId);
+ }
+ break;
+ case NODE_FLAG_BITS:
+ final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
+ builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT)));
+ LOG.debug("Parsed Overload bit: {}, attached bit: {}, external bit: {}, area border router: {}.",
+ flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT));
+ break;
+ case NODE_OPAQUE:
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value));
+ }
+ break;
+ case DYNAMIC_HOSTNAME:
+ builder.setDynamicHostname(new String(ByteArray.readAllBytes(value), Charsets.US_ASCII));
+ LOG.debug("Parsed Node Name {}", builder.getDynamicHostname());
+ break;
+ case ISIS_AREA_IDENTIFIER:
+ final IsisAreaIdentifier ai = new IsisAreaIdentifier(ByteArray.readAllBytes(value));
+ areaMembership.add(ai);
+ LOG.debug("Parsed AreaIdentifier {}", ai);
+ break;
+ case TlvUtil.LOCAL_IPV4_ROUTER_ID:
+ final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
+ builder.setIpv4RouterId(ip4);
+ LOG.debug("Parsed IPv4 Router Identifier {}", ip4);
+ break;
+ case TlvUtil.LOCAL_IPV6_ROUTER_ID:
+ final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
+ builder.setIpv6RouterId(ip6);
+ LOG.debug("Parsed IPv6 Router Identifier {}", ip6);
+ break;
+ default:
+ LOG.warn("TLV {} is not a valid node attribute, ignoring it", key);
+ }
+ }
+ LOG.trace("Finished parsing Node Attributes.");
+ builder.setTopologyIdentifier(topologyMembership);
+ builder.setIsisAreaId(areaMembership);
+ return new NodeAttributesCaseBuilder().setNodeAttributes(builder.build()).build();
+ }
+
+ static void serializeNodeAttributes(final NodeAttributesCase nodeAttributesCase, final ByteBuf byteAggregator) {
+ LOG.trace("Started serializing Node Attributes");
+ final NodeAttributes nodeAttributes = nodeAttributesCase.getNodeAttributes();
+ final List<TopologyIdentifier> topList = nodeAttributes.getTopologyIdentifier();
+ if (topList != null && !topList.isEmpty()) {
+ final ByteBuf mpIdBuf = Unpooled.buffer();
+ for (final TopologyIdentifier topologyIdentifier : topList) {
+ mpIdBuf.writeShort(topologyIdentifier.getValue());
+ }
+ TlvUtil.writeTLV(TlvUtil.MULTI_TOPOLOGY_ID, mpIdBuf, byteAggregator);
+ }
+ serializeNodeFlagBits(nodeAttributes.getNodeFlags(), byteAggregator);
+ if (nodeAttributes.getDynamicHostname() != null) {
+ TlvUtil.writeTLV(DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(Charsets.UTF_8.encode(nodeAttributes.getDynamicHostname())), byteAggregator);
+ }
+ final List<IsisAreaIdentifier> isisList = nodeAttributes.getIsisAreaId();
+ if (isisList != null && !isisList.isEmpty()) {
+ for (final IsisAreaIdentifier isisAreaIdentifier : isisList) {
+ TlvUtil.writeTLV(ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator);
+ }
+ }
+ if (nodeAttributes.getIpv4RouterId() != null) {
+ TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(nodeAttributes.getIpv4RouterId()), byteAggregator);
+ }
+ if (nodeAttributes.getIpv6RouterId() != null) {
+ TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(nodeAttributes.getIpv6RouterId()), 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(1);
+ final BitSet flags = new BitSet(Byte.SIZE);
+ if (nodeFlagBits.isOverload() != null) {
+ flags.set(OVERLOAD_BIT, nodeFlagBits.isOverload());
+ }
+ if (nodeFlagBits.isAttached() != null) {
+ flags.set(ATTACHED_BIT, nodeFlagBits.isAttached());
+ }
+ if (nodeFlagBits.isExternal() != null) {
+ flags.set(EXTERNAL_BIT, nodeFlagBits.isExternal());
+ }
+ if (nodeFlagBits.isAbr() != null) {
+ flags.set(ABBR_BIT, nodeFlagBits.isAbr());
+ }
+ nodeFlagBuf.writeBytes(flags.toByteArray());
+ TlvUtil.writeTLV(NODE_FLAG_BITS, nodeFlagBuf, byteAggregator);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.attribute;
+
+import com.google.common.collect.Multimap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map.Entry;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.ExtendedRouteTag;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.IgpBits.UpDown;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.RouteTag;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.prefix.state.IgpBitsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.LinkStateAttribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IgpMetric;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class PrefixAttributesParser {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PrefixAttributesParser.class);
+
+ private static final int ROUTE_TAG_LENGTH = 4;
+ private static final int EXTENDED_ROUTE_TAG_LENGTH = 8;
+ private static final int UP_DOWN_BIT = 7;
+
+ /* Prefix Attribute TLVs */
+ private static final int IGP_FLAGS = 1152;
+ private static final int ROUTE_TAG = 1153;
+ private static final int EXTENDED_ROUTE_TAG = 1154;
+ private static final int PREFIX_METRIC = 1155;
+ private static final int FORWARDING_ADDRESS = 1156;
+ private static final int PREFIX_OPAQUE = 1157;
+
+ /**
+ * Parse prefix attributes.
+ *
+ * @param attributes key is the tlv type and value are the value bytes of the tlv
+ * @return {@link LinkStateAttribute}
+ */
+ static LinkStateAttribute parsePrefixAttributes(final Multimap<Integer, ByteBuf> attributes) {
+ final PrefixAttributesBuilder builder = new PrefixAttributesBuilder();
+ final List<RouteTag> routeTags = new ArrayList<>();
+ final List<ExtendedRouteTag> exRouteTags = new ArrayList<>();
+ for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
+ final int key = entry.getKey();
+ final ByteBuf value = entry.getValue();
+ LOG.trace("Prefix attribute TLV {}", key);
+ switch (key) {
+ case IGP_FLAGS:
+ final BitSet flags = BitSet.valueOf(ByteArray.readAllBytes(value));
+ final boolean upDownBit = flags.get(UP_DOWN_BIT);
+ builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit)).build());
+ LOG.debug("Parsed IGP flag (up/down bit) : {}", upDownBit);
+ break;
+ case ROUTE_TAG:
+ while (value.isReadable()) {
+ final RouteTag routeTag = new RouteTag(ByteArray.readBytes(value, ROUTE_TAG_LENGTH));
+ routeTags.add(routeTag);
+ LOG.debug("Parsed Route Tag: {}", routeTag);
+ }
+ break;
+ case EXTENDED_ROUTE_TAG:
+ while (value.isReadable()) {
+ final ExtendedRouteTag exRouteTag = new ExtendedRouteTag(ByteArray.readBytes(value, EXTENDED_ROUTE_TAG_LENGTH));
+ exRouteTags.add(exRouteTag);
+ LOG.debug("Parsed Extended Route Tag: {}", exRouteTag);
+ }
+ break;
+ case PREFIX_METRIC:
+ final IgpMetric metric = new IgpMetric(value.readUnsignedInt());
+ builder.setPrefixMetric(metric);
+ LOG.debug("Parsed Metric: {}", metric);
+ break;
+ case FORWARDING_ADDRESS:
+ final IpAddress fwdAddress = parseForwardingAddress(value);
+ builder.setOspfForwardingAddress(fwdAddress);
+ LOG.debug("Parsed FWD Address: {}", fwdAddress);
+ break;
+ case PREFIX_OPAQUE:
+ LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value));
+ break;
+ default:
+ LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key);
+ }
+ }
+ LOG.trace("Finished parsing Prefix Attributes.");
+ builder.setRouteTags(routeTags);
+ builder.setExtendedTags(exRouteTags);
+ 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;
+ }
+
+ static void serializePrefixAttributes(final PrefixAttributesCase prefixAttributesCase, final ByteBuf byteAggregator) {
+ final PrefixAttributes prefixAtrributes = prefixAttributesCase.getPrefixAttributes();
+ if (prefixAtrributes.getIgpBits() != null) {
+ final BitSet igpBit = new BitSet();
+ final Boolean bit = prefixAtrributes.getIgpBits().getUpDown().isUpDown();
+ if (bit != null) {
+ igpBit.set(UP_DOWN_BIT, bit);
+ }
+ TlvUtil.writeTLV(IGP_FLAGS, Unpooled.wrappedBuffer(igpBit.toByteArray()), byteAggregator);
+ }
+ if (prefixAtrributes.getRouteTags() != null) {
+ final ByteBuf routeTagsBuf = Unpooled.buffer();
+ for (final RouteTag routeTag : prefixAtrributes.getRouteTags()) {
+ routeTagsBuf.writeBytes(routeTag.getValue());
+ }
+ TlvUtil.writeTLV(ROUTE_TAG, routeTagsBuf, byteAggregator);
+ }
+ final List<ExtendedRouteTag> routeTagList = prefixAtrributes.getExtendedTags();
+ if (routeTagList != null && !routeTagList.isEmpty()) {
+ final ByteBuf extendedBuf = Unpooled.buffer();
+ for (final ExtendedRouteTag extendedRouteTag : routeTagList) {
+ extendedBuf.writeBytes(extendedRouteTag.getValue());
+ }
+ TlvUtil.writeTLV(EXTENDED_ROUTE_TAG, extendedBuf, byteAggregator);
+ }
+ if (prefixAtrributes.getPrefixMetric() != null) {
+ TlvUtil.writeTLV(PREFIX_METRIC, Unpooled.copyInt(prefixAtrributes.getPrefixMetric().getValue().intValue()), byteAggregator);
+ }
+ 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) {
+ ospfBuf.writeBytes(Ipv4Util.bytesForAddress(forwardingAddress.getIpv4Address()));
+ } else if (forwardingAddress.getIpv6Address() != null) {
+ ospfBuf.writeBytes(Ipv6Util.bytesForAddress(forwardingAddress.getIpv6Address()));
+ }
+ TlvUtil.writeTLV(FORWARDING_ADDRESS, ospfBuf, byteAggregator);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.nlri;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class LinkNlriParser {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LinkNlriParser.class);
+
+ /* Link Descriptor TLVs */
+ private static final int LINK_LR_IDENTIFIERS = 258;
+ private static final int IPV4_IFACE_ADDRESS = 259;
+ private static final int IPV4_NEIGHBOR_ADDRESS = 260;
+ private static final int IPV6_IFACE_ADDRESS = 261;
+ private static final int IPV6_NEIGHBOR_ADDRESS = 262;
+
+ static LinkDescriptors parseLinkDescriptors(final ByteBuf buffer) throws BGPParsingException {
+ final LinkDescriptorsBuilder builder = new LinkDescriptorsBuilder();
+ while (buffer.isReadable()) {
+ final int type = buffer.readUnsignedShort();
+ final int length = buffer.readUnsignedShort();
+ final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
+ LOG.trace("Parsing Link Descriptor: {}", ByteBufUtil.hexDump(value));
+ switch (type) {
+ case LINK_LR_IDENTIFIERS:
+ builder.setLinkLocalIdentifier(value.readUnsignedInt());
+ builder.setLinkRemoteIdentifier(value.readUnsignedInt());
+ LOG.debug("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
+ builder.getLinkRemoteIdentifier());
+ break;
+ case IPV4_IFACE_ADDRESS:
+ final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
+ builder.setIpv4InterfaceAddress(lipv4);
+ LOG.debug("Parsed IPv4 interface address {}.", lipv4);
+ break;
+ case IPV4_NEIGHBOR_ADDRESS:
+ final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForByteBuf(value));
+ builder.setIpv4NeighborAddress(ripv4);
+ LOG.debug("Parsed IPv4 neighbor address {}.", ripv4);
+ break;
+ case IPV6_IFACE_ADDRESS:
+ final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value));
+ builder.setIpv6InterfaceAddress(lipv6);
+ LOG.debug("Parsed IPv6 interface address {}.", lipv6);
+ break;
+ case IPV6_NEIGHBOR_ADDRESS:
+ final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value));
+ builder.setIpv6NeighborAddress(ripv6);
+ LOG.debug("Parsed IPv6 neighbor address {}.", ripv6);
+ break;
+ case TlvUtil.MULTI_TOPOLOGY_ID:
+ final TopologyIdentifier topId = new TopologyIdentifier(value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
+ builder.setMultiTopologyId(topId);
+ LOG.debug("Parsed topology identifier {}.", topId);
+ break;
+ default:
+ throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
+ }
+ buffer.skipBytes(length);
+ }
+ LOG.trace("Finished parsing Link descriptors.");
+ return builder.build();
+ }
+
+ static void serializeLinkDescriptors(final LinkDescriptors descriptors, final ByteBuf buffer) {
+ if (descriptors.getLinkLocalIdentifier() != null && descriptors.getLinkRemoteIdentifier() != null) {
+ final ByteBuf identifierBuf = Unpooled.buffer();
+ identifierBuf.writeInt(descriptors.getLinkLocalIdentifier().intValue());
+ identifierBuf.writeInt(descriptors.getLinkRemoteIdentifier().intValue());
+ TlvUtil.writeTLV(LINK_LR_IDENTIFIERS, identifierBuf, buffer);
+ }
+ if (descriptors.getIpv4InterfaceAddress() != null) {
+ TlvUtil.writeTLV(IPV4_IFACE_ADDRESS, Ipv4Util.byteBufForAddress(descriptors.getIpv4InterfaceAddress()), buffer);
+ }
+ if (descriptors.getIpv4NeighborAddress() != null) {
+ TlvUtil.writeTLV(IPV4_NEIGHBOR_ADDRESS, Ipv4Util.byteBufForAddress(descriptors.getIpv4NeighborAddress()), buffer);
+ }
+ if (descriptors.getIpv6InterfaceAddress() != null) {
+ TlvUtil.writeTLV(IPV6_IFACE_ADDRESS, Ipv6Util.byteBufForAddress(descriptors.getIpv6InterfaceAddress()), buffer);
+ }
+ if (descriptors.getIpv6NeighborAddress() != null) {
+ TlvUtil.writeTLV(IPV6_NEIGHBOR_ADDRESS, Ipv6Util.byteBufForAddress(descriptors.getIpv6NeighborAddress()), buffer);
+ }
+ if (descriptors.getMultiTopologyId() != null) {
+ TlvUtil.writeTLV(TlvUtil.MULTI_TOPOLOGY_ID, Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.nlri;
+
+import com.google.common.base.Preconditions;
+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.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
+import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Identifier;
+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.NodeIdentifier;
+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.RouteDistinguisher;
+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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.LocalNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+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.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.PathAttributes2;
+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.MpUnreachNlri;
+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.AdvertizedRoutes;
+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;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Parser and serializer for Linkstate NLRI.
+ */
+public final class LinkstateNlriParser implements NlriParser, NlriSerializer {
+ private static final Logger LOG = LoggerFactory.getLogger(LinkstateNlriParser.class);
+ 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 TYPE_LENGTH = 2;
+ private static final int LENGTH_SIZE = 2;
+
+
+ private static final int LOCAL_NODE_DESCRIPTORS = 256;
+ private static final int REMOTE_NODE_DESCRIPTORS = 257;
+
+ private final boolean isVpn;
+
+ public LinkstateNlriParser(final boolean isVpn) {
+ this.isVpn = isVpn;
+ }
+
+ private static NodeIdentifier parseLink(final CLinkstateDestinationBuilder builder, final ByteBuf buffer) throws BGPParsingException {
+ final int type = buffer.readUnsignedShort();
+ final int length = buffer.readUnsignedShort();
+ final NodeIdentifier remote = null;
+ if (type == REMOTE_NODE_DESCRIPTORS) {
+ builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) NodeNlriParser.parseNodeDescriptors(buffer.slice(buffer.readerIndex(), length), false));
+ buffer.skipBytes(length);
+ }
+ builder.setLinkDescriptors(LinkNlriParser.parseLinkDescriptors(buffer.slice()));
+ return remote;
+ }
+
+ /**
+ * Parses common parts for Link State Nodes, Links and Prefixes, that includes protocol ID and identifier tlv.
+ *
+ * @param nlri as byte array
+ * @return {@link CLinkstateDestination}
+ * @throws BGPParsingException if parsing was unsuccessful
+ */
+ public static List<CLinkstateDestination> parseNlri(final ByteBuf nlri, final boolean isVpn) throws BGPParsingException {
+ if (!nlri.isReadable()) {
+ return null;
+ }
+ final List<CLinkstateDestination> dests = Lists.newArrayList();
+
+ CLinkstateDestinationBuilder builder = null;
+
+ while (nlri.isReadable()) {
+ builder = new CLinkstateDestinationBuilder();
+ final NlriType type = NlriType.forValue(nlri.readUnsignedShort());
+ builder.setNlriType(type);
+
+ // length means total length of the tlvs including route distinguisher not including the type field
+ final int length = nlri.readUnsignedShort();
+ RouteDistinguisher distinguisher = null;
+ if (isVpn) {
+ // this parses route distinguisher
+ distinguisher = new RouteDistinguisher(BigInteger.valueOf(nlri.readLong()));
+ builder.setDistinguisher(distinguisher);
+ }
+ // parse source protocol
+ final ProtocolId sp = ProtocolId.forValue(nlri.readByte());
+ builder.setProtocolId(sp);
+
+ // parse identifier
+ final Identifier identifier = new Identifier(BigInteger.valueOf(nlri.readLong()));
+ builder.setIdentifier(identifier);
+
+ // if we are dealing with linkstate nodes/links, parse local node descriptor
+ NodeIdentifier localDescriptor = null;
+ int locallength = 0;
+ final int localtype = nlri.readUnsignedShort();
+ locallength = nlri.readUnsignedShort();
+ if (localtype == LOCAL_NODE_DESCRIPTORS) {
+ localDescriptor = NodeNlriParser.parseNodeDescriptors(nlri.slice(nlri.readerIndex(), locallength), true);
+ }
+ nlri.skipBytes(locallength);
+ builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
+ final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
+ - TYPE_LENGTH - LENGTH_SIZE - locallength;
+ LOG.trace("Restlength {}", restLength);
+ final ByteBuf rest = nlri.slice(nlri.readerIndex(), restLength);
+ switch (type) {
+ case Link:
+ parseLink(builder, rest);
+ break;
+ case Ipv4Prefix:
+ builder.setPrefixDescriptors(PrefixNlriParser.parsePrefixDescriptors(rest, true));
+ break;
+ case Ipv6Prefix:
+ builder.setPrefixDescriptors(PrefixNlriParser.parsePrefixDescriptors(rest, false));
+ break;
+ case Node:
+ // node nlri is already parsed as it contains only the common fields for node and link nlri
+ break;
+ default:
+ break;
+ }
+ nlri.skipBytes(restLength);
+ dests.add(builder.build());
+ }
+ return dests;
+ }
+
+ @Override
+ public void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
+ if (!nlri.isReadable()) {
+ return;
+ }
+ final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
+
+ 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());
+ }
+
+ @Override
+ public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder) throws BGPParsingException {
+ if (!nlri.isReadable()) {
+ return;
+ }
+ final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
+
+ builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+ new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build()).build()).build());
+ }
+
+ /**
+ * Serializes Linkstate NLRI to byte array. We need this as NLRI serves as a key in upper layers.
+ *
+ * @param destination Linkstate NLRI to be serialized
+ */
+ public static void serializeNlri(final CLinkstateDestination destination, final ByteBuf buffer) {
+ final ByteBuf nlriByteBuf = Unpooled.buffer();
+ if (destination.getDistinguisher() != null) {
+ nlriByteBuf.writeBytes(destination.getDistinguisher().getValue().toByteArray());
+ }
+ nlriByteBuf.writeByte(destination.getProtocolId().getIntValue());
+ nlriByteBuf.writeLong(destination.getIdentifier().getValue().longValue());
+
+ // serialize local node descriptors
+ final ByteBuf ldescs = Unpooled.buffer();
+ NodeNlriParser.serializeNodeDescriptors(destination.getLocalNodeDescriptors(), ldescs);
+ TlvUtil.writeTLV(LOCAL_NODE_DESCRIPTORS, ldescs, nlriByteBuf);
+
+ switch (destination.getNlriType()) {
+ case Ipv4Prefix:
+ case Ipv6Prefix:
+ if (destination.getPrefixDescriptors() != null) {
+ PrefixNlriParser.serializePrefixDescriptors(destination.getPrefixDescriptors(), nlriByteBuf);
+ }
+ break;
+ case Link:
+ final ByteBuf rdescs = Unpooled.buffer();
+ NodeNlriParser.serializeNodeDescriptors(destination.getRemoteNodeDescriptors(), rdescs);
+ TlvUtil.writeTLV(REMOTE_NODE_DESCRIPTORS, rdescs, nlriByteBuf);
+ if (destination.getLinkDescriptors() != null) {
+ LinkNlriParser.serializeLinkDescriptors(destination.getLinkDescriptors(), nlriByteBuf);
+ }
+ break;
+ case Node:
+ break;
+ default:
+ LOG.warn("Unknown NLRI Type.");
+ break;
+ }
+ TlvUtil.writeTLV(destination.getNlriType().getIntValue(), nlriByteBuf, buffer);
+ }
+
+ @Override
+ public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ Preconditions.checkArgument(attribute instanceof PathAttributes, "Attribute parameter is not a PathAttribute object.");
+ final PathAttributes pathAttributes = (PathAttributes) attribute;
+ final PathAttributes1 pathAttributes1 = pathAttributes.getAugmentation(PathAttributes1.class);
+ final PathAttributes2 pathAttributes2 = pathAttributes.getAugmentation(PathAttributes2.class);
+ 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) {
+ 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();
+
+ for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
+ serializeNlri(cLinkstateDestination, byteAggregator);
+ }
+ }
+ } else if (pathAttributes2 != null) {
+ final MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri();
+ if (mpUnreachNlri.getWithdrawnRoutes() != null && mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationLinkstateCase) {
+ final DestinationLinkstateCase linkstateCase = (DestinationLinkstateCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
+ for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate().getCLinkstateDestination()) {
+ serializeNlri(cLinkstateDestination, byteAggregator);
+ }
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.nlri;
+
+import com.google.common.primitives.UnsignedInteger;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.AreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.DomainIdentifier;
+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.OspfInterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.isis.lan.identifier.IsIsRouterIdentifier;
+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.c.linkstate.destination.LocalNodeDescriptorsBuilder;
+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.CRouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisPseudonodeCase;
+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.OspfNodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
+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.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class NodeNlriParser {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NodeNlriParser.class);
+
+ 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;
+
+ /* Node Descriptor TLVs */
+ private static final int AS_NUMBER = 512;
+ private static final int BGP_LS_ID = 513;
+ private static final int AREA_ID = 514;
+ private static final int IGP_ROUTER_ID = 515;
+
+ static NodeIdentifier parseNodeDescriptors(final ByteBuf buffer, final boolean local) throws BGPParsingException {
+ AsNumber asnumber = null;
+ DomainIdentifier bgpId = null;
+ AreaIdentifier ai = null;
+ CRouterIdentifier routerId = null;
+ while (buffer.isReadable()) {
+ final int type = buffer.readUnsignedShort();
+ final int length = buffer.readUnsignedShort();
+ final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Parsing Node Descriptor: {}", ByteBufUtil.hexDump(value));
+ }
+ switch (type) {
+ case AS_NUMBER:
+ asnumber = new AsNumber(value.readUnsignedInt());
+ LOG.debug("Parsed {}", asnumber);
+ break;
+ case BGP_LS_ID:
+ bgpId = new DomainIdentifier(value.readUnsignedInt());
+ LOG.debug("Parsed {}", bgpId);
+ break;
+ case AREA_ID:
+ ai = new AreaIdentifier(value.readUnsignedInt());
+ LOG.debug("Parsed area identifier {}", ai);
+ break;
+ case IGP_ROUTER_ID:
+ routerId = parseRouterId(value);
+ LOG.debug("Parsed Router Identifier {}", routerId);
+ break;
+ default:
+ throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
+ }
+ buffer.skipBytes(length);
+ }
+ 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();
+ }
+
+ 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();
+ }
+ 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();
+ 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();
+ }
+ if (value.readableBytes() == OSPF_PSEUDONODE_ROUTER_ID_LENGTH) {
+ return new OspfPseudonodeCaseBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(value.readUnsignedInt()).setLanInterface(new OspfInterfaceIdentifier(value.readUnsignedInt())).build()).build();
+ }
+ throw new BGPParsingException("Router Id of invalid length " + value.readableBytes());
+ }
+
+ static void serializeNodeDescriptors(final NodeIdentifier descriptors, final ByteBuf buffer) {
+ if (descriptors.getAsNumber() != null) {
+ TlvUtil.writeTLV(AS_NUMBER, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getAsNumber().getValue()).intValue()), buffer);
+ }
+ if (descriptors.getDomainId() != null) {
+ TlvUtil.writeTLV(BGP_LS_ID, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getDomainId().getValue()).intValue()), buffer);
+ }
+ if (descriptors.getAreaId() != null) {
+ TlvUtil.writeTLV(AREA_ID, Unpooled.copyInt(UnsignedInteger.valueOf(descriptors.getAreaId().getValue()).intValue()), buffer);
+ }
+ if (descriptors.getCRouterIdentifier() != null) {
+ final ByteBuf routerIdBuf = Unpooled.buffer();
+ serializeRouterId(descriptors.getCRouterIdentifier(), routerIdBuf);
+ TlvUtil.writeTLV(IGP_ROUTER_ID, routerIdBuf, buffer);
+ }
+ }
+
+ private static void serializeRouterId(final CRouterIdentifier routerId, final ByteBuf buffer) {
+ if (routerId instanceof IsisNodeCase) {
+ final IsisNode isis = ((IsisNodeCase) routerId).getIsisNode();
+ buffer.writeBytes(isis.getIsoSystemId().getValue());
+ } else if (routerId instanceof IsisPseudonodeCase) {
+ final IsisPseudonode isis = ((IsisPseudonodeCase) routerId).getIsisPseudonode();
+ buffer.writeBytes(isis.getIsIsRouterIdentifier().getIsoSystemId().getValue());
+ buffer.writeByte(((isis.getPsn() != null) ? isis.getPsn() : 0));
+ } else if (routerId instanceof OspfNodeCase) {
+ buffer.writeInt(UnsignedInteger.valueOf(((OspfNodeCase) routerId).getOspfNode().getOspfRouterId()).intValue());
+ } else if (routerId instanceof OspfPseudonodeCase) {
+ final OspfPseudonode node = ((OspfPseudonodeCase) routerId).getOspfPseudonode();
+ buffer.writeInt(UnsignedInteger.valueOf(node.getOspfRouterId()).intValue());
+ buffer.writeInt(UnsignedInteger.valueOf(node.getLanInterface().getValue()).intValue());
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.linkstate.nlri;
+
+import com.google.common.primitives.UnsignedBytes;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.bgp.linkstate.TlvUtil;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.OspfRouteType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.PrefixDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.linkstate.destination.c.linkstate.destination.PrefixDescriptorsBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class PrefixNlriParser {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PrefixNlriParser.class);
+
+ /* Prefix Descriptor TLVs */
+ private static final int OSPF_ROUTE_TYPE = 264;
+ private static final int IP_REACHABILITY = 265;
+
+ static PrefixDescriptors parsePrefixDescriptors(final ByteBuf buffer, final boolean ipv4) throws BGPParsingException {
+ final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
+ while (buffer.isReadable()) {
+ final int type = buffer.readUnsignedShort();
+ final int length = buffer.readUnsignedShort();
+ final ByteBuf value = buffer.slice(buffer.readerIndex(), length);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Parsing Prefix Descriptor: {}", ByteBufUtil.hexDump(value));
+ }
+ switch (type) {
+ case TlvUtil.MULTI_TOPOLOGY_ID:
+ final TopologyIdentifier topologyId = new TopologyIdentifier(value.readShort() & TlvUtil.TOPOLOGY_ID_OFFSET);
+ builder.setMultiTopologyId(topologyId);
+ LOG.trace("Parsed Topology Identifier: {}", topologyId);
+ break;
+ case OSPF_ROUTE_TYPE:
+ final int rt = value.readByte();
+ final OspfRouteType routeType = OspfRouteType.forValue(rt);
+ if (routeType == null) {
+ throw new BGPParsingException("Unknown OSPF Route Type: " + rt);
+ }
+ builder.setOspfRouteType(routeType);
+ LOG.trace("Parser RouteType: {}", routeType);
+ break;
+ case IP_REACHABILITY:
+ IpPrefix prefix = null;
+ final int prefixLength = value.readByte();
+ final int size = prefixLength / Byte.SIZE + ((prefixLength % Byte.SIZE == 0) ? 0 : 1);
+ if (size != value.readableBytes()) {
+ LOG.debug("Expected length {}, actual length {}.", size, value.readableBytes());
+ throw new BGPParsingException("Illegal length of IP reachability TLV: " + (value.readableBytes()));
+ }
+ prefix = (ipv4) ? new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(value, size), prefixLength)):
+ new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(value, size), prefixLength));
+ builder.setIpReachabilityInformation(prefix);
+ LOG.trace("Parsed IP reachability info: {}", prefix);
+ break;
+ default:
+ throw new BGPParsingException("Prefix Descriptor not recognized, type: " + type);
+ }
+ buffer.skipBytes(length);
+ }
+ LOG.debug("Finished parsing Prefix descriptors.");
+ return builder.build();
+ }
+
+ static void serializePrefixDescriptors(final PrefixDescriptors descriptors, final ByteBuf buffer) {
+ if (descriptors.getMultiTopologyId() != null) {
+ TlvUtil.writeTLV(TlvUtil.MULTI_TOPOLOGY_ID, Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
+ }
+ if (descriptors.getOspfRouteType() != null) {
+ TlvUtil.writeTLV(OSPF_ROUTE_TYPE,
+ Unpooled.wrappedBuffer(new byte[] {UnsignedBytes.checkedCast(descriptors.getOspfRouteType().getIntValue()) }), buffer);
+ }
+ if (descriptors.getIpReachabilityInformation() != null) {
+ final IpPrefix prefix = descriptors.getIpReachabilityInformation();
+ byte[] prefixBytes = null;
+ if (prefix.getIpv4Prefix() != null) {
+ prefixBytes = Ipv4Util.bytesForPrefixBegin(prefix.getIpv4Prefix());
+ } else if (prefix.getIpv6Prefix() != null) {
+ prefixBytes = Ipv6Util.bytesForPrefixBegin(prefix.getIpv6Prefix());
+ }
+ TlvUtil.writeTLV(IP_REACHABILITY, Unpooled.wrappedBuffer(prefixBytes), buffer);
+ }
+ }
+}
public void setUp() {
MockitoAnnotations.initMocks(this);
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- final InstanceIdentifier<Rib> iid = InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test-rib"))).toInstance();
+ final InstanceIdentifier<Rib> iid = InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test-rib"))).build();
final KeyedInstanceIdentifier<Tables, TablesKey> key = iid.child(LocRib.class).child(Tables.class, new TablesKey(LinkstateAddressFamily.class,
LinkstateSubsequentAddressFamily.class));
import io.netty.buffer.Unpooled;
import java.util.Arrays;
import org.junit.Test;
+import org.opendaylight.protocol.bgp.linkstate.attribute.LinkstateAttributeParser;
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.LinkProtectionType;
import java.math.BigInteger;
import java.util.List;
import org.junit.Test;
+import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
-public class TlvCodeTest {
+public class TlvUtilTest {
@Test(expected=UnsupportedOperationException.class)
public void testPrivateConstructor() throws Throwable {
- final Constructor<TlvCode> c = TlvCode.class.getDeclaredConstructor();
+ final Constructor<TlvUtil> c = TlvUtil.class.getDeclaredConstructor();
c.setAccessible(true);
try {
c.newInstance();
- } catch (InvocationTargetException e) {
+ } catch (final InvocationTargetException e) {
throw e.getCause();
}
}
public RIBImpl(final RibId ribId, final AsNumber localAs, final Ipv4Address localBgpId, final RIBExtensionConsumerContext extensions,
final BGPDispatcher dispatcher, final ReconnectStrategyFactory tcpStrategyFactory,
final ReconnectStrategyFactory sessionStrategyFactory, final DataBroker dps, final List<BgpTableType> localTables) {
- super(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(ribId))).toInstance());
+ super(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(ribId))).build());
this.chain = dps.createTransactionChain(this);
this.localAs = Preconditions.checkNotNull(localAs);
this.comparator = new BGPObjectComparator(localAs);
private WriteTransaction trans;
- private final DefaultRibReference rib = new DefaultRibReference(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test"))).toInstance());
+ private final DefaultRibReference rib = new DefaultRibReference(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test"))).build());
private final RIBActivator act = new RIBActivator();
private static final Ipv4Prefix IPV4_PREFIX2 = new Ipv4Prefix("2.2.2.2/32");
- private static final InstanceIdentifier<Rib> RIB_IID = InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test-rib"))).toInstance();
+ private static final InstanceIdentifier<Rib> RIB_IID = InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test-rib"))).build();
private static final KeyedInstanceIdentifier<Tables, TablesKey> TABLES_IID = RIB_IID.child(LocRib.class).child(Tables.class, new TablesKey(Ipv4AddressFamily.class,
UnicastSubsequentAddressFamily.class));
this.chain = dataProvider.createTransactionChain(this);
final TopologyKey tk = new TopologyKey(Preconditions.checkNotNull(topologyId));
- this.topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, tk).toInstance();
+ this.topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, tk).build();
LOG.debug("Initiating topology builder from {} at {}", locRibReference, this.topology);
public final InstanceIdentifier<Tables> tableInstanceIdentifier(final Class<? extends AddressFamily> afi,
final Class<? extends SubsequentAddressFamily> safi) {
- return this.locRibReference.getInstanceIdentifier().builder().child(LocRib.class).child(Tables.class, new TablesKey(afi, safi)).toInstance();
+ return this.locRibReference.getInstanceIdentifier().builder().child(LocRib.class).child(Tables.class, new TablesKey(afi, safi)).build();
}
protected abstract void createObject(ReadWriteTransaction trans, InstanceIdentifier<T> id, T value);
public abstract class AbstractTopologyBuilderTest extends AbstractDataBrokerTest {
protected static final TopologyId TEST_TOPOLOGY_ID = new TopologyId("test-topo");
- protected static RibReference LOC_RIB_REF = new DefaultRibReference(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(new RibId("test-rib")))).toInstance());
+ protected static RibReference LOC_RIB_REF = new DefaultRibReference(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(new RibId("test-rib")))).build());
protected ListenerRegistration<DataChangeListener> reg;
protected void createEmptyTopology() {
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- wTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(NetworkTopology.class).toInstance(), new NetworkTopologyBuilder().setTopology(Collections.<Topology>emptyList()).build());
+ wTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(NetworkTopology.class).build(), new NetworkTopologyBuilder().setTopology(Collections.<Topology>emptyList()).build());
wTx.submit();
}
wTx.put(LogicalDatastoreType.OPERATIONAL, path, new TablesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
.setAttributes(new AttributesBuilder().setUptodate(Boolean.TRUE).build()).setRoutes(new Ipv4RoutesCaseBuilder().build()).build(), true);
wTx.submit();
- this.ipv4RouteIID = path.builder().child(Ipv4Routes.class).child(Ipv4Route.class, new Ipv4RouteKey(new Ipv4Prefix(ROUTE_IP4PREFIX))).toInstance();
+ this.ipv4RouteIID = path.builder().child(Ipv4Routes.class).child(Ipv4Route.class, new Ipv4RouteKey(new Ipv4Prefix(ROUTE_IP4PREFIX))).build();
}
@Test
wTx.put(LogicalDatastoreType.OPERATIONAL, path, new TablesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
.setAttributes(new AttributesBuilder().setUptodate(Boolean.TRUE).build()).setRoutes(new Ipv6RoutesCaseBuilder().build()).build(), true);
wTx.submit();
- this.ipv6RouteIID = path.builder().child(Ipv6Routes.class).child(Ipv6Route.class, new Ipv6RouteKey(new Ipv6Prefix(ROUTE_IP6PREFIX))).toInstance();
+ this.ipv6RouteIID = path.builder().child(Ipv6Routes.class).child(Ipv6Route.class, new Ipv6RouteKey(new Ipv6Prefix(ROUTE_IP6PREFIX))).build();
}
@Test
wTx.put(LogicalDatastoreType.OPERATIONAL, path, new TablesBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class)
.setAttributes(new AttributesBuilder().setUptodate(Boolean.TRUE).build()).setRoutes(new LinkstateRoutesCaseBuilder().build()).build(), true);
wTx.submit();
- this.linkstateRouteIID = (InstanceIdentifier<LinkstateRoute>) path.builder().child((Class)LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).toInstance();
+ this.linkstateRouteIID = (InstanceIdentifier<LinkstateRoute>) path.builder().child((Class)LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).build();
}
@Test
public class DefaultInstanceReferenceTest {
- private static final InstanceIdentifier<NetworkTopology> IID = InstanceIdentifier.builder(NetworkTopology.class).toInstance();
+ private static final InstanceIdentifier<NetworkTopology> IID = InstanceIdentifier.builder(NetworkTopology.class).build();
@Test
public void testDefaultInstanceReference() {
public java.lang.AutoCloseable createInstance() {
final TopologyDataChangeCounter counter = new TopologyDataChangeCounter(getDataProviderDependency());
final InstanceIdentifier<Topology> topoIId = InstanceIdentifier.builder(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(new TopologyId(getTopologyName()))).toInstance();
+ .child(Topology.class, new TopologyKey(new TopologyId(getTopologyName()))).build();
final ListenerRegistration<DataChangeListener> registration = getDataProviderDependency().registerDataChangeListener(
LogicalDatastoreType.OPERATIONAL, topoIId, counter, DataBroker.DataChangeScope.SUBTREE);
return new DataChangeCounterCloseable(counter, registration);
private static final Logger LOG = LoggerFactory.getLogger(TopologyDataChangeCounter.class);
protected static final InstanceIdentifier<DataChangeCounter> IID = InstanceIdentifier
- .builder(DataChangeCounter.class).toInstance();
+ .builder(DataChangeCounter.class).build();
private final DataBroker dataBroker;
private AtomicLong count;
assertNotNull(getBroker());
final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
- new TopologyKey(getTopologyId("Topo1"))).toInstance();
+ new TopologyKey(getTopologyId("Topo1"))).build();
BindingAwareProvider provider1 = new AbstractTestProvider() {
broker.registerProvider(provider1, getBundleContext());
final InstanceIdentifier<Topology> topology2 = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
- new TopologyKey(getTopologyId("Topo2"))).toInstance();
+ new TopologyKey(getTopologyId("Topo2"))).build();
BindingAwareProvider provider2 = new AbstractTestProvider() {
assertNotNull(getBroker());
final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
- new TopologyKey(getTopologyId("Topo1"))).toInstance();
+ new TopologyKey(getTopologyId("Topo1"))).build();
BindingAwareProvider provider1 = new AbstractTestProvider() {
broker.registerProvider(provider1, getBundleContext());
final InstanceIdentifier<Topology> topology2 = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
- new TopologyKey(getTopologyId("Topo2"))).toInstance();
+ new TopologyKey(getTopologyId("Topo2"))).build();
BindingAwareProvider provider2 = new AbstractTestProvider() {
assertNotNull(getBroker());
final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
- new TopologyKey(getTopologyId("Topo1"))).toInstance();
+ new TopologyKey(getTopologyId("Topo1"))).build();
BindingAwareProvider provider1 = new AbstractTestProvider() {
broker.registerProvider(provider1, getBundleContext());
final InstanceIdentifier<Topology> topology2 = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
- new TopologyKey(getTopologyId("Topo2"))).toInstance();
+ new TopologyKey(getTopologyId("Topo2"))).build();
BindingAwareProvider provider2 = new AbstractTestProvider() {
import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPMonitoringReplyMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPMonitoringRequestMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPNotificationMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPMonitoringObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPOverloadObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPccIdReqIPv4ObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPccIdReqIPv6ObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPceIdIPv4ObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPPceIdIPv6ObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPProcTimeObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
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.Pcerr;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcmonrep;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcmonreq;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcntf;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcrep;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcreq;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.load.balancing.object.LoadBalancing;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDuration;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.setup.type.tlv.PathSetupType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.NoPath;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure._case.no.path.tlvs.NoPathVector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Rro;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissing;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
final PCEPCloseMessageParser closeParser = new PCEPCloseMessageParser(objReg);
regs.add(context.registerMessageParser(PCEPCloseMessageParser.TYPE, closeParser));
regs.add(context.registerMessageSerializer(Close.class, closeParser));
+
+ final PCEPMonitoringReplyMessageParser monRepParser = new PCEPMonitoringReplyMessageParser(objReg);
+ regs.add(context.registerMessageParser(PCEPMonitoringReplyMessageParser.TYPE, monRepParser));
+ regs.add(context.registerMessageSerializer(Pcmonrep.class, monRepParser));
+
+ final PCEPMonitoringRequestMessageParser monReqParser = new PCEPMonitoringRequestMessageParser(objReg, viObjReg);
+ regs.add(context.registerMessageParser(PCEPMonitoringRequestMessageParser.TYPE, monReqParser));
+ regs.add(context.registerMessageSerializer(Pcmonreq.class, monReqParser));
+
return regs;
}
final PCEPGlobalConstraintsObjectParser gcParser = new PCEPGlobalConstraintsObjectParser(tlvReg, viTlvReg);
regs.add(context.registerObjectParser(PCEPGlobalConstraintsObjectParser.CLASS, PCEPGlobalConstraintsObjectParser.TYPE, gcParser));
regs.add(context.registerObjectSerializer(Gc.class, gcParser));
+
+ registerMonitoringExtensionParsers(regs, context, tlvReg, viTlvReg);
}
private void registerEROParsers(final List<AutoCloseable> regs, final PCEPExtensionProviderContext context, final LabelRegistry labelReg) {
regs.add(context.registerTlvParser(PathSetupTypeTlvParser.TYPE, pstParser));
regs.add(context.registerTlvSerializer(PathSetupType.class, pstParser));
}
+
+ private void registerMonitoringExtensionParsers(final List<AutoCloseable> regs, final PCEPExtensionProviderContext context,
+ final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
+ final PCEPMonitoringObjectParser monParser = new PCEPMonitoringObjectParser(tlvReg, viTlvReg);
+ regs.add(context.registerObjectParser(PCEPMonitoringObjectParser.CLASS, PCEPMonitoringObjectParser.TYPE, monParser));
+ regs.add(context.registerObjectSerializer(Monitoring.class, monParser));
+
+ final PCEPPccIdReqIPv4ObjectParser pccIdIPv4Parser = new PCEPPccIdReqIPv4ObjectParser();
+ regs.add(context.registerObjectParser(PCEPPccIdReqIPv4ObjectParser.CLASS, PCEPPccIdReqIPv4ObjectParser.IPV4_TYPE, pccIdIPv4Parser));
+ regs.add(context.registerObjectSerializer(PccIdReq.class, pccIdIPv4Parser));
+
+ final PCEPPccIdReqIPv6ObjectParser pccIdIPv6Parser = new PCEPPccIdReqIPv6ObjectParser();
+ regs.add(context.registerObjectParser(PCEPPccIdReqIPv6ObjectParser.CLASS, PCEPPccIdReqIPv6ObjectParser.IPV6_TYPE, pccIdIPv6Parser));
+ regs.add(context.registerObjectSerializer(PccIdReq.class, pccIdIPv6Parser));
+
+ final PCEPPceIdIPv4ObjectParser pceIdIP4Parser = new PCEPPceIdIPv4ObjectParser();
+ regs.add(context.registerObjectParser(PCEPPceIdIPv4ObjectParser.CLASS, PCEPPceIdIPv4ObjectParser.IPV4_TYPE, pceIdIP4Parser));
+ regs.add(context.registerObjectSerializer(PceId.class, pceIdIP4Parser));
+
+ final PCEPPceIdIPv6ObjectParser pceIdIP6Parser = new PCEPPceIdIPv6ObjectParser();
+ regs.add(context.registerObjectParser(PCEPPceIdIPv6ObjectParser.CLASS, PCEPPceIdIPv6ObjectParser.IPV6_TYPE, pceIdIP6Parser));
+ regs.add(context.registerObjectSerializer(PceId.class, pceIdIP6Parser));
+
+ final PCEPProcTimeObjectParser procTimeParser = new PCEPProcTimeObjectParser();
+ regs.add(context.registerObjectParser(PCEPProcTimeObjectParser.CLASS, PCEPProcTimeObjectParser.TYPE, procTimeParser));
+ regs.add(context.registerObjectSerializer(ProcTime.class, procTimeParser));
+
+ final PCEPOverloadObjectParser overloadParser = new PCEPOverloadObjectParser();
+ regs.add(context.registerObjectParser(PCEPOverloadObjectParser.CLASS, PCEPOverloadObjectParser.TYPE, overloadParser));
+ regs.add(context.registerObjectSerializer(Overload.class, overloadParser));
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.pcep.impl.message;
+
+import com.google.common.base.Optional;
+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;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcmonrep;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcmonrepBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.GeneralMetricsList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.SpecificMetricsList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.SpecificMetricsListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetrics;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetricsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcmonrep.message.PcmonrepMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcmonrep.message.PcmonrepMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
+
+/**
+ * Parser for {@link Pcmonrep}
+ * @see https://tools.ietf.org/html/rfc5886#section-3.2
+ */
+public class PCEPMonitoringReplyMessageParser extends AbstractMessageParser {
+
+ public static final int TYPE = 9;
+
+ public PCEPMonitoringReplyMessageParser(final ObjectRegistry registry) {
+ super(registry);
+ }
+
+ @Override
+ public void serializeMessage(final Message message, final ByteBuf buffer) {
+ Preconditions.checkArgument(message instanceof Pcmonrep, "Wrong instance of Message. Passed instance of %s. Need Pcmonrep.", message.getClass());
+ final PcmonrepMessage monRepMsg = ((Pcmonrep) message).getPcmonrepMessage();
+ Preconditions.checkArgument(monRepMsg.getMonitoring() != null, "MONITORING object is mandatory.");
+ final ByteBuf body = Unpooled.buffer();
+ serializeObject(monRepMsg.getMonitoring(), body);
+ serializeObject(monRepMsg.getPccIdReq(), body);
+ if (monRepMsg.getMonitoringMetricsList() instanceof GeneralMetricsList) {
+ final GeneralMetricsList gml = (GeneralMetricsList) monRepMsg.getMonitoringMetricsList();
+ if (gml.getMetricPce() != null) {
+ for (final MetricPce metricPce : gml.getMetricPce()) {
+ serializeMetricPce(metricPce, body);
+ }
+ }
+ } else if (monRepMsg.getMonitoringMetricsList() instanceof SpecificMetricsList) {
+ final SpecificMetricsList sml = (SpecificMetricsList) monRepMsg.getMonitoringMetricsList();
+ if (sml.getSpecificMetrics() != null) {
+ for (final SpecificMetrics specificMetrics : sml.getSpecificMetrics()) {
+ serializeObject(specificMetrics.getRp(), body);
+ if (specificMetrics.getMetricPce() != null) {
+ for (final MetricPce metricPce : specificMetrics.getMetricPce()) {
+ serializeMetricPce(metricPce, body);
+ }
+ }
+ }
+ }
+ }
+
+ MessageUtil.formatMessage(TYPE, body, buffer);
+ }
+
+ private void serializeMetricPce(final MetricPce metricPce, final ByteBuf buffer) {
+ Preconditions.checkArgument(metricPce.getPceId() != null, "PCE-ID must be present.");
+ serializeObject(metricPce.getPceId(), buffer);
+ serializeObject(metricPce.getProcTime(), buffer);
+ serializeObject(metricPce.getOverload(), buffer);
+ }
+
+ @Override
+ protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
+ if (objects == null) {
+ throw new IllegalArgumentException("Passed list can't be null.");
+ }
+ if (objects.isEmpty()) {
+ throw new PCEPDeserializerException("Pcmonrep message cannot be empty.");
+ }
+ if (!(objects.get(0) instanceof Monitoring)) {
+ errors.add(createErrorMsg(PCEPErrors.MONITORING_OBJECT_MISSING, Optional.<Rp>absent()));
+ return null;
+ }
+ final PcmonrepMessageBuilder builder = new PcmonrepMessageBuilder();
+ builder.setMonitoring((Monitoring) objects.get(0));
+ objects.remove(0);
+ if (!objects.isEmpty() && objects.get(0) instanceof PccIdReq) {
+ builder.setPccIdReq((PccIdReq) objects.get(0));
+ objects.remove(0);
+ }
+ final List<SpecificMetrics> specificMetrics = new ArrayList<>();
+ while (!objects.isEmpty()) {
+ final SpecificMetricsBuilder smb = new SpecificMetricsBuilder();
+ final List<MetricPce> metricPceList = new ArrayList<>();
+ if (objects.get(0) instanceof Rp) {
+ smb.setRp((Rp) objects.get(0));
+ objects.remove(0);
+ }
+ while (!objects.isEmpty() && !(objects.get(0) instanceof Rp)) {
+ metricPceList.add(validateMonitoringMetrics(objects));
+ }
+ if (smb.getRp() != null) {
+ smb.setMetricPce(metricPceList);
+ specificMetrics.add(smb.build());
+ } else if (!metricPceList.isEmpty()) {
+ builder.setMonitoringMetricsList(new GeneralMetricsListBuilder().setMetricPce(metricPceList).build());
+ }
+ }
+ if (!specificMetrics.isEmpty()) {
+ builder.setMonitoringMetricsList(new SpecificMetricsListBuilder().setSpecificMetrics(specificMetrics).build());
+ }
+ if (!objects.isEmpty()) {
+ throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
+ }
+ return new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build();
+ }
+
+ private MetricPce validateMonitoringMetrics(final List<Object> objects) throws PCEPDeserializerException {
+ final MetricPceBuilder metricPceBuilder = new MetricPceBuilder();
+ if (!(objects.get(0) instanceof PceId)) {
+ throw new PCEPDeserializerException("metric-pce-list must start with PCE-ID object.");
+ }
+ metricPceBuilder.setPceId((PceId) (objects.get(0)));
+ objects.remove(0);
+ State state = State.START;
+ while (!objects.isEmpty() && !state.equals(State.END)) {
+ final Object obj = objects.get(0);
+ switch(state) {
+ case START :
+ state = State.PROC_TIME;
+ if (obj instanceof ProcTime) {
+ metricPceBuilder.setProcTime((ProcTime) obj);
+ break;
+ }
+ case PROC_TIME :
+ state = State.OVERLOAD;
+ if (obj instanceof Overload) {
+ metricPceBuilder.setOverload((Overload) obj);
+ break;
+ }
+ case OVERLOAD :
+ state = State.END;
+ break;
+ case END :
+ break;
+ }
+ if (!state.equals(State.END)) {
+ objects.remove(0);
+ }
+ }
+ return metricPceBuilder.build();
+ }
+
+ private enum State {
+ START, PROC_TIME, OVERLOAD, END;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.pcep.impl.message;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.List;
+import org.opendaylight.protocol.pcep.spi.MessageUtil;
+import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcmonreq;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcmonreqBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.PcreqMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.PcreqMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.MonitoringRequest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Svec;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
+
+/**
+ * Parser for {@link Pcmonreq}
+ * @see https://tools.ietf.org/html/rfc5886#section-3.3
+ */
+public class PCEPMonitoringRequestMessageParser extends PCEPRequestMessageParser {
+
+ public static final int TYPE = 8;
+
+ public PCEPMonitoringRequestMessageParser(final ObjectRegistry registry, final VendorInformationObjectRegistry viRegistry) {
+ super(registry, viRegistry);
+ }
+
+ @Override
+ public void serializeMessage(Message message, ByteBuf out) {
+ Preconditions.checkArgument(message instanceof Pcmonreq, "Wrong instance of Message. Passed instance of %s. Need Pcmonreq.", message.getClass());
+ final PcreqMessage msg = ((Pcmonreq) message).getPcreqMessage();
+ if (msg.getMonitoringRequest() == null) {
+ throw new IllegalArgumentException("MONITORING object MUST be present.");
+ }
+ final ByteBuf buffer = Unpooled.buffer();
+ serializeMonitoringRequest(msg.getMonitoringRequest(), buffer);
+ if (msg.getSvec() != null) {
+ serializeSvec(msg, buffer);
+ }
+ if (msg.getRequests() != null && !msg.getRequests().isEmpty()) {
+ serializeRequest(msg, buffer);
+ }
+ MessageUtil.formatMessage(TYPE, buffer, out);
+ }
+
+ @Override
+ protected Message validate(List<Object> objects, List<Message> errors) throws PCEPDeserializerException {
+ if (objects == null) {
+ throw new IllegalArgumentException("Passed list can't be null.");
+ }
+ if (objects.isEmpty()) {
+ throw new PCEPDeserializerException("Pcmonreq message cannot be empty.");
+ }
+ final MonitoringRequest monReq = getMonitoring(objects);
+ if (monReq == null) {
+ errors.add(createErrorMsg(PCEPErrors.MONITORING_OBJECT_MISSING, Optional.<Rp>absent()));
+ }
+ final PcreqMessageBuilder mBuilder = new PcreqMessageBuilder();
+ mBuilder.setMonitoringRequest(monReq);
+ final List<Svec> svecs = getSvecs(objects, errors);
+ if (!svecs.isEmpty()) {
+ mBuilder.setSvec(svecs);
+ }
+ final List<Requests> requests = getRequests(objects, errors);
+ if (requests != null && !requests.isEmpty()) {
+ mBuilder.setRequests(requests);
+ }
+ if (!objects.isEmpty()) {
+ throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
+ }
+ return new PcmonreqBuilder().setPcreqMessage(mBuilder.build()).build();
+ }
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.MetricsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.PcrepMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.Replies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.RepliesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.SuccessBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.Paths;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject;
protected void serializeReply(final Replies reply, final ByteBuf buffer) {
serializeObject(reply.getRp(), buffer);
+ serializeMonitoring(reply, buffer);
serializeVendorInformationObjects(reply.getVendorInformationObject(), buffer);
if (reply.getResult() == null) {
return;
}
serializeVendorInformationObjects(s.getSuccess().getVendorInformationObject(), buffer);
}
+ serializeMonitoringMetrics(reply, buffer);
+ }
+
+ private void serializeMonitoring(final Replies reply, final ByteBuf buffer) {
+ serializeObject(reply.getMonitoring(), buffer);
+ serializeObject(reply.getPccIdReq(), buffer);
+ }
+
+ private void serializeMonitoringMetrics(final Replies reply, final ByteBuf buffer) {
+ if (reply.getMetricPce() != null) {
+ for (final MetricPce metricPce : reply.getMetricPce()) {
+ serializeMetricPce(metricPce, buffer);
+ }
+ }
+ }
+
+ protected void serializeMetricPce(final MetricPce metricPce, final ByteBuf buffer) {
+ Preconditions.checkArgument(metricPce.getPceId() != null, "PCE-ID must be present.");
+ serializeObject(metricPce.getPceId(), buffer);
+ serializeObject(metricPce.getProcTime(), buffer);
+ serializeObject(metricPce.getOverload(), buffer);
}
@Override
return new PcrepBuilder().setPcrepMessage(new PcrepMessageBuilder().setReplies(replies).build()).build();
}
- protected Replies getValidReply(final List<Object> objects, final List<Message> errors) {
+ protected Replies getValidReply(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
if (!(objects.get(0) instanceof Rp)) {
errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.<Rp>absent()));
return null;
}
final Rp rp = (Rp) objects.get(0);
objects.remove(0);
+ final RepliesBuilder repliesBuilder = new RepliesBuilder();
+ if (!objects.isEmpty() && objects.get(0) instanceof Monitoring) {
+ repliesBuilder.setMonitoring((Monitoring) objects.get(0));
+ objects.remove(0);
+ }
+ if (!objects.isEmpty() && objects.get(0) instanceof PccIdReq) {
+ repliesBuilder.setPccIdReq((PccIdReq) objects.get(0));
+ objects.remove(0);
+ }
final List<VendorInformationObject> vendorInfo = addVendorInformationObjects(objects);
Result res = null;
if (!objects.isEmpty()) {
objects.remove(0);
final FailureCaseBuilder builder = new FailureCaseBuilder();
builder.setNoPath(noPath);
- while (!objects.isEmpty()) {
+ while (!objects.isEmpty() && !(objects.get(0) instanceof PceId)) {
this.parseAttributes(builder, objects);
}
res = builder.build();
final List<Paths> paths = new ArrayList<>();
final PathsBuilder pBuilder = new PathsBuilder();
pBuilder.setEro(ero);
- while (!objects.isEmpty()) {
+ while (!objects.isEmpty() && !(objects.get(0) instanceof PceId)) {
final List<VendorInformationObject> vendorInfoObjects = addVendorInformationObjects(objects);
if (!vendorInfoObjects.isEmpty()) {
builder.setVendorInformationObject(vendorInfoObjects);
res = new SuccessCaseBuilder().setSuccess(builder.build()).build();
}
}
- final RepliesBuilder builder = new RepliesBuilder();
+ final List<MetricPce> metricPceList = new ArrayList<>();
+ if (!objects.isEmpty() && objects.get(0) instanceof PceId) {
+ while (!objects.isEmpty()) {
+ metricPceList.add(validateMetricPce(objects));
+ }
+ }
if (!vendorInfo.isEmpty()) {
- builder.setVendorInformationObject(vendorInfo);
+ repliesBuilder.setVendorInformationObject(vendorInfo);
}
- return builder.setRp(rp).setResult(res).build();
+ if (!metricPceList.isEmpty()) {
+ repliesBuilder.setMetricPce(metricPceList);
+ }
+ return repliesBuilder.setRp(rp).setResult(res).build();
}
protected void parseAttributes(final FailureCaseBuilder builder, final List<Object> objects) {
private enum State {
INIT, LSPA_IN, OF_IN, BANDWIDTH_IN, METRIC_IN, IRO_IN, END
}
+
+ protected MetricPce validateMetricPce(final List<Object> objects) throws PCEPDeserializerException {
+ final MetricPceBuilder metricPceBuilder = new MetricPceBuilder();
+ if (!(objects.get(0) instanceof PceId)) {
+ throw new PCEPDeserializerException("metric-pce-list must start with PCE-ID object.");
+ }
+ metricPceBuilder.setPceId((PceId) (objects.get(0)));
+ objects.remove(0);
+ MetricPceState state = MetricPceState.START;
+ while (!objects.isEmpty() && !state.equals(MetricPceState.END)) {
+ final Object obj = objects.get(0);
+ switch(state) {
+ case START :
+ state = MetricPceState.PROC_TIME;
+ if (obj instanceof ProcTime) {
+ metricPceBuilder.setProcTime((ProcTime) obj);
+ break;
+ }
+ case PROC_TIME :
+ state = MetricPceState.OVERLOAD;
+ if (obj instanceof Overload) {
+ metricPceBuilder.setOverload((Overload) obj);
+ break;
+ }
+ case OVERLOAD :
+ state = MetricPceState.END;
+ break;
+ case END :
+ break;
+ }
+ if (!state.equals(MetricPceState.END)) {
+ objects.remove(0);
+ }
+ }
+ return metricPceBuilder.build();
+ }
+
+ private enum MetricPceState {
+ START, PROC_TIME, OVERLOAD, END;
+ }
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.MetricsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.key.object.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.PcreqMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.PcreqMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.MonitoringRequest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.MonitoringRequestBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Svec;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.monitoring.request.PceIdList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.monitoring.request.PceIdListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.PathKeyExpansionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.SegmentComputation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.SegmentComputationBuilder;
throw new IllegalArgumentException("Requests cannot be null or empty.");
}
final ByteBuf buffer = Unpooled.buffer();
+ if (msg.getMonitoringRequest() != null) {
+ serializeMonitoringRequest(msg.getMonitoringRequest(), buffer);
+ }
+ if (msg.getSvec() != null) {
+ serializeSvec(msg, buffer);
+ }
+ serializeRequest(msg, buffer);
+ MessageUtil.formatMessage(TYPE, buffer, out);
+ }
+
+ protected void serializeRequest(final PcreqMessage msg, final ByteBuf buffer) {
for (final Requests req : msg.getRequests()) {
serializeObject(req.getRp(), buffer);
serializeVendorInformationObjects(req.getVendorInformationObject(), buffer);
}
}
}
- if (msg.getSvec() != null) {
- for (final Svec s : msg.getSvec()) {
- serializeObject(s.getSvec(), buffer);
- serializeObject(s.getOf(), buffer);
- serializeObject(s.getGc(), buffer);
- serializeObject(s.getXro(), buffer);
- if (s.getMetric() != null) {
- for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.Metric m : s.getMetric()) {
- serializeObject(m.getMetric(), buffer);
- }
+ }
+
+ protected void serializeSvec(final PcreqMessage msg, final ByteBuf buffer) {
+ for (final Svec s : msg.getSvec()) {
+ serializeObject(s.getSvec(), buffer);
+ serializeObject(s.getOf(), buffer);
+ serializeObject(s.getGc(), buffer);
+ serializeObject(s.getXro(), buffer);
+ if (s.getMetric() != null) {
+ for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.Metric m : s.getMetric()) {
+ serializeObject(m.getMetric(), buffer);
}
- serializeVendorInformationObjects(s.getVendorInformationObject(), buffer);
}
+ serializeVendorInformationObjects(s.getVendorInformationObject(), buffer);
}
- MessageUtil.formatMessage(TYPE, buffer, out);
}
protected void serializeP2P(final ByteBuf buffer, final P2p p2p) {
serializeObject(p2p.getClassType(), buffer);
}
+ protected void serializeMonitoringRequest(final MonitoringRequest monReq, final ByteBuf out) {
+ serializeObject(monReq.getMonitoring(), out);
+ serializeObject(monReq.getPccIdReq(), out);
+ if (monReq.getPceIdList() != null) {
+ for (final PceIdList pceId : monReq.getPceIdList()) {
+ serializeObject(pceId.getPceId(), out);
+ }
+ }
+ }
+
@Override
- protected Message validate(
- final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object> objects,
- final List<Message> errors) throws PCEPDeserializerException {
+ protected Message validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
if (objects == null) {
throw new IllegalArgumentException("Passed list can't be null.");
}
- final List<Requests> requests = new ArrayList<>();
+ if (objects.isEmpty()) {
+ throw new PCEPDeserializerException("Pcrep message cannot be empty.");
+ }
+ final PcreqMessageBuilder mBuilder = new PcreqMessageBuilder();
+ mBuilder.setMonitoringRequest(getMonitoring(objects));
+ final List<Svec> svecs = getSvecs(objects, errors);
+ if (!svecs.isEmpty()) {
+ mBuilder.setSvec(svecs);
+ }
+ final List<Requests> requests = getRequests(objects, errors);
+ if (requests != null && !requests.isEmpty()) {
+ mBuilder.setRequests(requests);
+ } else {
+ errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.<Rp>absent()));
+ }
+ if (!objects.isEmpty()) {
+ throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
+ }
+ return new PcreqBuilder().setPcreqMessage(mBuilder.build()).build();
+ }
+
+ protected List<Svec> getSvecs(final List<Object> objects, final List<Message> errors) {
final List<Svec> svecList = new ArrayList<>();
+ while (!objects.isEmpty()) {
+ final SvecBuilder sBuilder = new SvecBuilder();
+ final Svec svecComp = getValidSvec(sBuilder, objects);
+ if (svecComp == null) {
+ break;
+ }
+ svecList.add(svecComp);
+ }
+ return svecList;
+ }
+
+ protected List<Requests> getRequests(final List<Object> objects, final List<Message> errors) {
+ final List<Requests> requests = new ArrayList<>();
while (!objects.isEmpty()) {
final RequestsBuilder rBuilder = new RequestsBuilder();
Rp rpObj = null;
final P2pBuilder p2pBuilder = new P2pBuilder();
- if (objects.get(0) instanceof EndpointsObj) {
+ if (!objects.isEmpty() && objects.get(0) instanceof EndpointsObj) {
final EndpointsObj ep = (EndpointsObj) objects.get(0);
objects.remove(0);
if (!ep.isProcessingRule()) {
rBuilder.setSegmentComputation(segm);
}
}
- while (!objects.isEmpty()) {
- final SvecBuilder sBuilder = new SvecBuilder();
- final Svec svecComp = getValidSvec(sBuilder, objects);
- if (svecComp == null) {
- break;
- }
- svecList.add(svecComp);
- }
requests.add(rBuilder.build());
}
-
- final PcreqMessageBuilder mBuilder = new PcreqMessageBuilder();
- mBuilder.setRequests(requests);
- if (!svecList.isEmpty()) {
- mBuilder.setSvec(svecList);
- }
- return new PcreqBuilder().setPcreqMessage(mBuilder.build()).build();
+ return requests;
}
protected SegmentComputation getSegmentComputation(final P2pBuilder builder, final List<Object> objects, final List<Message> errors,
if (objects == null || objects.isEmpty()) {
throw new IllegalArgumentException("List cannot be null or empty.");
}
- if (!(objects.get(0) instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec)) {
+
+ if (objects.get(0) instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec) {
+ builder.setSvec((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec) objects.get(0));
+ objects.remove(0);
+ } else {
return null;
}
- builder.setSvec((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec) objects.get(0));
- objects.remove(0);
final List<Metrics> metrics = new ArrayList<>();
final List<VendorInformationObject> viObjects = new ArrayList<>();
private enum SvecState {
INIT, OF_IN, GC_IN, XRO_IN, METRIC_IN, VENDOR_INFO, END
}
+
+ protected MonitoringRequest getMonitoring(final List<Object> objects) {
+ final MonitoringRequestBuilder builder = new MonitoringRequestBuilder();
+ if (!objects.isEmpty() && objects.get(0) instanceof Monitoring) {
+ builder.setMonitoring((Monitoring) objects.get(0));
+ objects.remove(0);
+ } else {
+ return null;
+ }
+ if (!objects.isEmpty() && objects.get(0) instanceof PccIdReq) {
+ builder.setPccIdReq((PccIdReq) objects.get(0));
+ objects.remove(0);
+ }
+ final List<PceIdList> pceIdList = new ArrayList<>();
+ while(!objects.isEmpty() && objects.get(0) instanceof PceId) {
+ pceIdList.add(new PceIdListBuilder().setPceId((PceId) objects.get(0)).build());
+ objects.remove(0);
+ }
+ if (!pceIdList.isEmpty()) {
+ builder.setPceIdList(pceIdList);
+ }
+ return builder.build();
+ }
}
import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPErrorMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPMonitoringReplyMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPMonitoringRequestMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPNotificationMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPOpenMessageParser;
import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
import org.opendaylight.protocol.util.ByteArray;
+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.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
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.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcerrBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcmonrepBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcmonreqBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcntfBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcrepBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.PcreqBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.Lspa;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.LspaBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.MetricBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPce;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPceBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.MonitoringBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.GeneralMetricsListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.SpecificMetricsListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.response.monitoring.metrics.list.specific.metrics.list.SpecificMetricsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotification;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.CNotificationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.OfBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.Overload;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.object.OverloadBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReq;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcc.id.req.object.PccIdReqBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceIdBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.PcerrMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.SessionCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.RequestBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.session._case.SessionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcmonrep.message.PcmonrepMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.PcntfMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.Notifications;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcntf.message.pcntf.message.NotificationsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.Paths;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.success._case.success.PathsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.PcreqMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.MonitoringRequestBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.monitoring.request.PceIdList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.monitoring.request.PceIdListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.SegmentComputationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.P2pBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTime;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.proc.time.object.ProcTimeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.RpBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.Svec;
private EndpointsObj endpoints;
private Svec svec;
private List<VendorInformationObject> viObjects;
+ private Monitoring monitoring;
+ private PccIdReq pccIdReq;
+ private PceId pceId;
+ private ProcTime procTime;
+ private Overload overload;
private AsNumberCase eroASSubobject;
final VendorInformationObject viObj = new VendorInformationObjectBuilder().setEnterpriseNumber(new EnterpriseNumber(0L))
.setEnterpriseSpecificInformation(esInfo).build();
this.viObjects.add(viObj);
+
+ this.monitoring = new MonitoringBuilder()
+ .setMonitoringId(100L)
+ .setFlags(new Flags(false, false, false, false, false))
+ .setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder().build()).build();
+ this.pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
+ this.pceId = new PceIdBuilder().setIpAddress(new IpAddress(new Ipv4Address("127.0.0.2"))).build();
+
+ final ProcTimeBuilder procTimeBuilder = new ProcTimeBuilder();
+ procTimeBuilder.setEstimated(false);
+ procTimeBuilder.setCurrentProcTime(1L);
+ procTimeBuilder.setMinProcTime(2L);
+ procTimeBuilder.setMaxProcTime(3L);
+ procTimeBuilder.setAverageProcTime(4L);
+ procTimeBuilder.setVarianceProcTime(5L);
+ this.procTime = procTimeBuilder.build();
+ this.overload = new OverloadBuilder().setDuration(120).build();
}
@Test
parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
assertArrayEquals(result.array(), buf.array());
}
+
+ @Test
+ public void testMonRepMsg() throws PCEPDeserializerException, IOException {
+ final PCEPMonitoringReplyMessageParser parser = new PCEPMonitoringReplyMessageParser(this.objectRegistry);
+ final PcmonrepMessageBuilder builder = new PcmonrepMessageBuilder();
+ builder.setMonitoring(this.monitoring);
+ builder.setMonitoringMetricsList(new GeneralMetricsListBuilder().setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build())).build());
+
+ final byte[] msgBytes = {
+ 0x20, 0x09, 0x00, 0x18,
+ /* monitoring object */
+ 0x13, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64,
+ /* pce-id object */
+ 0x19, 0x10, 0x00, 0x08, 0x7f, 0x00, 0x00, 0x02
+ };
+
+ ByteBuf result = Unpooled.wrappedBuffer(msgBytes);
+ assertEquals(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4,
+ result.readableBytes() - 4), Collections.<Message> emptyList()));
+ ByteBuf buf = Unpooled.buffer(result.readableBytes());
+ parser.serializeMessage(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), buf);
+ assertArrayEquals(result.array(), buf.array());
+
+ builder.setMonitoring(this.monitoring);
+ builder.setPccIdReq(this.pccIdReq);
+ final SpecificMetricsBuilder smBuilder = new SpecificMetricsBuilder();
+ smBuilder.setRp(this.rpTrue);
+ final List<MetricPce> metricPces = Lists.newArrayList();
+ metricPces.add(new MetricPceBuilder().setOverload(this.overload).setPceId(this.pceId).setProcTime(this.procTime).build());
+ metricPces.add(new MetricPceBuilder().setPceId(this.pceId).setProcTime(this.procTime).build());
+ smBuilder.setMetricPce(metricPces);
+ final SpecificMetricsBuilder smBuilder2 = new SpecificMetricsBuilder();
+ final List<MetricPce> metricPces2 = Lists.newArrayList();
+ smBuilder2.setRp(this.rpTrue);
+ metricPces2.add(new MetricPceBuilder().setOverload(this.overload).setPceId(this.pceId).build());
+ smBuilder2.setMetricPce(metricPces2);
+ builder.setMonitoringMetricsList(new SpecificMetricsListBuilder().setSpecificMetrics(Lists.newArrayList(smBuilder.build(), smBuilder2.build())).build());
+
+ result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCMonRep.bin"));
+ assertEquals(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4,
+ result.readableBytes() - 4), Collections.<Message> emptyList()));
+ buf = Unpooled.buffer(result.readableBytes());
+ parser.serializeMessage(new PcmonrepBuilder().setPcmonrepMessage(builder.build()).build(), buf);
+ assertArrayEquals(result.array(), buf.array());
+ }
+
+ @Test
+ public void testRepWithMonitoring() throws IOException, PCEPDeserializerException {
+ final PCEPReplyMessageParser parser = new PCEPReplyMessageParser(this.objectRegistry, this.viObjRegistry);
+
+ final PcrepMessageBuilder builder = new PcrepMessageBuilder();
+ RepliesBuilder rBuilder = new RepliesBuilder();
+
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCRepMon.5.bin"));
+ final List<Replies> replies4 = Lists.newArrayList();
+ rBuilder = new RepliesBuilder();
+ rBuilder.setRp(this.rpTrue);
+ rBuilder.setMonitoring(this.monitoring);
+ rBuilder.setPccIdReq(pccIdReq);
+ rBuilder.setMetricPce(Lists.newArrayList(new MetricPceBuilder().setPceId(this.pceId).build()));
+ final List<Paths> paths = Lists.newArrayList();
+ final PathsBuilder paBuilder = new PathsBuilder();
+ paBuilder.setEro(this.ero);
+ paBuilder.setLspa(this.lspa);
+ paBuilder.setMetrics(Lists.newArrayList(this.metrics));
+ paBuilder.setIro(this.iro);
+ paBuilder.setOf(this.of);
+ paths.add(paBuilder.build());
+ rBuilder.setResult(new SuccessCaseBuilder().setSuccess(new SuccessBuilder().setPaths(paths).build()).build()).build();
+ replies4.add(rBuilder.build());
+ builder.setReplies(replies4);
+
+ assertEquals(new PcrepBuilder().setPcrepMessage(builder.build()).build(), parser.parseMessage(result.slice(4,
+ result.readableBytes() - 4), Collections.<Message> emptyList()));
+ final ByteBuf buf = Unpooled.buffer(result.readableBytes());
+ parser.serializeMessage(new PcrepBuilder().setPcrepMessage(builder.build()).build(), buf);
+ assertArrayEquals(result.array(), buf.array());
+ }
+
+ @Test
+ public void testReqWithMonitoring() throws IOException, PCEPDeserializerException {
+ final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCReq.8.bin"));
+
+ final PCEPRequestMessageParser parser = new PCEPRequestMessageParser(this.objectRegistry, this.viObjRegistry);
+
+ final PcreqMessageBuilder builder = new PcreqMessageBuilder();
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests> reqs1 = Lists.newArrayList();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder rBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder();
+ rBuilder.setRp(this.rpTrue);
+ rBuilder.setSegmentComputation(new SegmentComputationBuilder().setP2p(new P2pBuilder().setEndpointsObj(this.endpoints).build()).build());
+ reqs1.add(rBuilder.build());
+ final MonitoringRequestBuilder monReqBuilder = new MonitoringRequestBuilder();
+ monReqBuilder.setMonitoring(this.monitoring);
+ monReqBuilder.setPccIdReq(this.pccIdReq);
+ monReqBuilder.setPceIdList(Lists.newArrayList(new PceIdListBuilder().setPceId(this.pceId).build()));
+ builder.setMonitoringRequest(monReqBuilder.build());
+ builder.setRequests(reqs1);
+
+ assertEquals(new PcreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4,
+ result.readableBytes() - 4), Collections.<Message> emptyList()));
+ final ByteBuf buf = Unpooled.buffer(result.readableBytes());
+ parser.serializeMessage(new PcreqBuilder().setPcreqMessage(builder.build()).build(), buf);
+
+ assertArrayEquals(result.array(), buf.array());
+ }
+
+ @Test
+ public void testMonReqMsg() throws PCEPDeserializerException, IOException {
+ final PCEPMonitoringRequestMessageParser parser = new PCEPMonitoringRequestMessageParser(this.objectRegistry, this.viObjRegistry);
+
+ final PcreqMessageBuilder builder = new PcreqMessageBuilder();
+ final MonitoringRequestBuilder monReqBuilder = new MonitoringRequestBuilder();
+ monReqBuilder.setMonitoring(this.monitoring);
+ monReqBuilder.setPceIdList(Lists.newArrayList(new PceIdListBuilder().setPceId(this.pceId).build()));
+ builder.setMonitoringRequest(monReqBuilder.build());
+ final byte[] msgBytes = {
+ 0x20, 0x08, 0x00, 0x18,
+ /* monitoring object */
+ 0x13, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64,
+ /* pce-id object */
+ 0x19, 0x10, 0x00, 0x08, 0x7f, 0x00, 0x00, 0x02
+ };
+ ByteBuf result = Unpooled.wrappedBuffer(msgBytes);
+ assertEquals(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4,
+ result.readableBytes() - 4), Collections.<Message> emptyList()));
+ ByteBuf buf = Unpooled.buffer(result.readableBytes());
+ parser.serializeMessage(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(), buf);
+ assertArrayEquals(result.array(), buf.array());
+
+ result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCMonReq.bin"));
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.Requests> reqs2 = Lists.newArrayList();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder rBuilder1 = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.RequestsBuilder();
+ rBuilder1.setRp(this.rpTrue);
+ final P2pBuilder p2pBuilder = new P2pBuilder();
+ p2pBuilder.setEndpointsObj(this.endpoints);
+ p2pBuilder.setMetrics(Lists.newArrayList(this.metrics));
+ p2pBuilder.setIro(this.iro);
+ rBuilder1.setSegmentComputation(new SegmentComputationBuilder().setP2p(p2pBuilder.build()).build());
+ reqs2.add(rBuilder1.build());
+ builder.setRequests(reqs2);
+ builder.setSvec(Lists.newArrayList(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder().setSvec(
+ this.svec).build()));
+ monReqBuilder.setMonitoring(this.monitoring);
+ monReqBuilder.setPccIdReq(this.pccIdReq);
+ final PceIdList pceIdList = new PceIdListBuilder().setPceId(this.pceId).build();
+ monReqBuilder.setPceIdList(Lists.newArrayList(pceIdList, pceIdList));
+ builder.setMonitoringRequest(monReqBuilder.build());
+
+ assertEquals(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(), parser.parseMessage(result.slice(4,
+ result.readableBytes() - 4), Collections.<Message> emptyList()));
+ buf = Unpooled.buffer(result.readableBytes());
+ parser.serializeMessage(new PcmonreqBuilder().setPcreqMessage(builder.build()).build(), buf);
+ assertArrayEquals(result.array(), buf.array());
+ }
}
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>
import java.util.List;
import org.opendaylight.protocol.pcep.impl.message.PCEPReplyMessageParser;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
}
@Override
- protected Replies getValidReply(List<Object> objects, List<Message> errors) {
+ protected Replies getValidReply(List<Object> objects, List<Message> errors) throws PCEPDeserializerException {
if (!(objects.get(0) instanceof Rp)) {
errors.add(createErrorMsg(PCEPErrors.RP_MISSING, Optional.<Rp>absent()));
return null;
/**
* Invalid traffic engineering path setup type: Mismatched path setup type
*/
- MISMATCHED_PST(21, 2);
+ MISMATCHED_PST(21, 2),
+ /**
+ * MONITORING object missing
+ */
+ MONITORING_OBJECT_MISSING(6, 4);
private PCEPErrorIdentifier errorId;
private static final Map<PCEPErrorIdentifier, PCEPErrors> VALUE_MAP;
@Override
public java.lang.AutoCloseable createInstance() {
final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
- new TopologyKey(getTopologyId())).toInstance();
+ new TopologyKey(getTopologyId())).build();
final InetSocketAddress address = new InetSocketAddress(listenAddress(), getListenPort().getValue());
final KeyMapping keys = contructKeys();
protected static final String TEST_TOPOLOGY_NAME = "testtopo";
protected static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(
- Topology.class, new TopologyKey(new TopologyId(TEST_TOPOLOGY_NAME))).toInstance();
+ Topology.class, new TopologyKey(new TopologyId(TEST_TOPOLOGY_NAME))).build();
protected static final String TEST_ADDRESS = "127.0.0.1";
protected static final NodeId NODE_ID = new NodeId("pcc://" + TEST_ADDRESS);
protected static final String TEST_LSP_NAME = "tunnel0";
}
for (final ReportedLsp l : pccnode.getPathComputationClient().getReportedLsp()) {
- lsps.add(id.builder().augmentation(Node1.class).child(PathComputationClient.class).child(ReportedLsp.class, l.getKey()).toInstance());
+ lsps.add(id.builder().augmentation(Node1.class).child(PathComputationClient.class).child(ReportedLsp.class, l.getKey()).build());
}
}
for (final IpAddress a : ((Ip) tpt).getIpAddress()) {
if (addr.equals(a)) {
handleSni(sni, n, inControl, trans);
- return this.target.builder().child(Node.class, n.getKey()).child(TerminationPoint.class, tp.getKey()).toInstance();
+ return this.target.builder().child(Node.class, n.getKey()).child(TerminationPoint.class, tp.getKey()).build();
}
}
} else {
}
private InstanceIdentifier<TerminationPoint> tpIdentifier(final NodeId node, final TpId tp) {
- return this.target.builder().child(Node.class, new NodeKey(node)).child(TerminationPoint.class, new TerminationPointKey(tp)).toInstance();
+ return this.target.builder().child(Node.class, new NodeKey(node)).child(TerminationPoint.class, new TerminationPointKey(tp)).build();
}
private InstanceIdentifier<Node> nodeIdentifier(final NodeId node) {
public static PCEPTunnelTopologyProvider create(final DataBroker dataProvider,
final InstanceIdentifier<Topology> sourceTopology, final TopologyId targetTopology) {
final InstanceIdentifier<Topology> dst = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
- new TopologyKey(targetTopology)).toInstance();
+ new TopologyKey(targetTopology)).build();
final NodeChangedListener ncl = new NodeChangedListener(dataProvider, dst);
final InstanceIdentifier<Node> src = sourceTopology.child(Node.class);
final BindingAwareBroker.RoutedRpcRegistration<TopologyTunnelPcepProgrammingService> reg = getRpcRegistryDependency().addRoutedRpcImplementation(
TopologyTunnelPcepProgrammingService.class, tp);
final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
- new TopologyKey(getTopologyId())).toInstance();
+ new TopologyKey(getTopologyId())).build();
reg.registerPath(NetworkTopologyContext.class, topology);
final class TunnelTopologyReferenceCloseable extends DefaultTopologyReference implements AutoCloseable {
private static final String LSP2_NAME = "lsp2";
private static final long LSP2_ID = 2;
- private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).toInstance();
- private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).toInstance();
+ private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).build();
+ private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).build();
private ListenerRegistration<DataChangeListener> listenerRegistration;
node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address))).build());
nodeBuilder.addAugmentation(Node1.class, node1Builder.build());
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).toInstance(), nodeBuilder.build());
+ wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build(), nodeBuilder.build());
wTx.submit().checkedGet();
}
private void removeNode(final NodeId nodeId) throws TransactionCommitFailedException {
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- wTx.delete(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).toInstance());
+ wTx.delete(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build());
wTx.submit().checkedGet();
}
public class TunnelProgrammingTest extends AbstractDataBrokerTest {
private static final TopologyId TOPOLOGY_ID = new TopologyId("tunnel-topo");
- private static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TOPOLOGY_ID)).toInstance();
+ private static final InstanceIdentifier<Topology> TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TOPOLOGY_ID)).build();
private static final String NODE1_IPV4 = "127.0.0.1";
private static final NodeId NODE1_ID = new NodeId("pcc://" + NODE1_IPV4);
linkBuilder.setKey(new LinkKey(LINK1_ID));
linkBuilder.addAugmentation(Link1.class, new Link1Builder().setSymbolicPathName(LINK1_ID.getValue()).build());
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- wTx.put(LogicalDatastoreType.OPERATIONAL, TOPO_IID.builder().child(Link.class, new LinkKey(LINK1_ID)).toInstance(), linkBuilder.build(), true);
+ wTx.put(LogicalDatastoreType.OPERATIONAL, TOPO_IID.builder().child(Link.class, new LinkKey(LINK1_ID)).build(), linkBuilder.build(), true);
wTx.submit().checkedGet();
}
<artifactId>releasepom</artifactId>
<packaging>pom</packaging>
- <name>BGPCEP release</name>
+ <name>bgpcep</name> <!-- Used by Sonar to set project name -->
<description>BGPCEP top-level pom</description>
<modules>
this.notifs = Preconditions.checkNotNull(notifs);
this.executor = Preconditions.checkNotNull(executor);
this.timer = Preconditions.checkNotNull(timer);
- this.qid = InstanceIdentifier.builder(InstructionsQueue.class).toInstance();
+ this.qid = InstanceIdentifier.builder(InstructionsQueue.class).build();
final ReadWriteTransaction t = dataProvider.newReadWriteTransaction();
try {
private boolean assertInstructionExists(final InstructionId id) {
try {
- return getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(InstructionsQueue.class).toInstance().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.queue.Instruction.class,
+ return getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(InstructionsQueue.class).build().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev130930.instruction.queue.Instruction.class,
new InstructionKey(id))).get().isPresent();
} catch (InterruptedException | ExecutionException e) {
return false;