}
}
- augment "/bgp-msg:update/bgp-msg:path-attributes/bgp-mp:mp-reach-nlri/bgp-mp:advertized-routes/bgp-mp:nlri" {
- case linkstate {
+ augment "/bgp-msg:update/bgp-msg:path-attributes/bgp-mp:mp-reach-nlri/bgp-mp:advertized-routes/bgp-mp:destination-type" {
+ case destination-linkstate {
uses linkstate-destination;
}
}
- augment "/bgp-msg:update/bgp-msg:path-attributes/bgp-mp:mp-unreach-nlri/bgp-mp:withdrawn-routes/bgp-mp:nlri" {
- case linkstate {
+ augment "/bgp-msg:update/bgp-msg:path-attributes/bgp-mp:mp-unreach-nlri/bgp-mp:withdrawn-routes/bgp-mp:destination-type" {
+ case destination-linkstate {
uses linkstate-destination;
}
}
}
grouping destination {
- choice nlri {
- case ipv4 {
+ choice destination-type {
+ case destination-ipv4 {
when "../../afi = ipv4";
leaf-list ipv4-prefixes {
type inet:ipv4-prefix;
}
}
- case ipv6 {
+ case destination-ipv6 {
when "../../afi = ipv6";
leaf-list ipv6-prefixes {
type inet:ipv6-prefix;
--- /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.parser.impl.message.update;
+
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
+import org.opendaylight.protocol.bgp.parser.spi.NlriUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.DestinationType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+
+abstract class IpNlriParser implements NlriParser {
+ protected abstract DestinationType parseNlri(final byte[] nlri);
+
+ @Override
+ public final void parseNlri(final byte[] nlri, final MpUnreachNlriBuilder builder) {
+ builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(parseNlri(nlri)).build());
+ }
+
+ @Override
+ public final void parseNlri(final byte[] nlri, final byte[] nextHop, final MpReachNlriBuilder builder) throws BGPParsingException {
+ builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(parseNlri(nlri)).build());
+ NlriUtil.parseNextHop(nextHop, builder);
+ }
+}
\ No newline at end of file
--- /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.parser.impl.message.update;
+
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv4Builder;
+
+final class Ipv4NlriParser extends IpNlriParser {
+ @Override
+ protected DestinationIpv4 parseNlri(final byte[] nlri) {
+ return new DestinationIpv4Builder().setIpv4Prefixes(Ipv4Util.prefixListForBytes(nlri)).build();
+ }
+}
\ No newline at end of file
--- /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.parser.impl.message.update;
+
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.destination.type.DestinationIpv6Builder;
+
+final class Ipv6NlriParser extends IpNlriParser {
+ @Override
+ protected DestinationIpv6 parseNlri(final byte[] nlri) {
+ return new DestinationIpv6Builder().setIpv6Prefixes(Ipv6Util.prefixListForBytes(nlri)).build();
+ }
+}
\ No newline at end of file
*/
package org.opendaylight.protocol.bgp.parser.impl.message.update;
-import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import org.opendaylight.protocol.concepts.Ipv4Util;
import org.opendaylight.protocol.concepts.Ipv6Util;
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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.AdministrativeGroup;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.AreaIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.DomainIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ExtendedRouteTag;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Identifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.IgpBits.UpDown;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv4InterfaceIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv4RouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv6InterfaceIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv6RouterIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.IsisAreaIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkProtectionType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.MplsProtocolMask;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NodeFlagBits;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NodeIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.OspfInterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.OspfRouteType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.PathAttributes1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.RouteDistinguisher;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.RouteTag;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.SharedRiskLinkGroup;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.isis.lan.identifier.IsIsRouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.isis.lan.identifier.IsIsRouterIdentifierBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.link.state.UnreservedBandwidthBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestinationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.CRouterIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisPseudonodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfPseudonodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.isis.node.IsisNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.isis.pseudonode.IsisPseudonodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.node.OspfNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.pseudonode.OspfPseudonodeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.prefix.state.IgpBitsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.LinkstatePathAttribute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.LinkstatePathAttributeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.linkstate.path.attribute.link.state.attribute.PrefixAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.IgpMetric;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.IsoSystemIdentifier;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Metric;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.TeMetric;
import org.slf4j.Logger;
private static final int LENGTH_SIZE = 2;
- 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 Set<Integer> nodeTlvs = Sets.newHashSet(263, 1024, 1025, 1026, 1027, 1028, 1029);
private static final Set<Integer> linkTlvs = Sets.newHashSet(1028, 1029, 1030, 1031, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095,
builder.addAugmentation(PathAttributes1.class, a);
}
- /**
- * Parses common parts for Link State Nodes, Links and Prefixes, that includes protocol ID and identifier tlv.
- *
- * @param reachable
- * @param safi
- * @param bytes
- * @return BGPLinkMP or BGPNodeMP
- * @throws BGPParsingException
- */
- protected static CLinkstateDestination parseLSNlri(final Class<? extends SubsequentAddressFamily> safi, final byte[] bytes)
- throws BGPParsingException {
- if (bytes.length == 0) {
- return null;
- }
- int byteOffset = 0;
-
- final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
-
- while (byteOffset != bytes.length) {
- final NlriType type = NlriType.forValue(ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TYPE_LENGTH)));
- builder.setNlriType(type);
-
- byteOffset += TYPE_LENGTH;
- // length means total length of the tlvs including route distinguisher not including the type field
- final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
- byteOffset += LENGTH_SIZE;
- RouteDistinguisher distinguisher = null;
- if (safi == MplsLabeledVpnSubsequentAddressFamily.class) {
- // this parses route distinguisher
- distinguisher = new RouteDistinguisher(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(bytes, byteOffset,
- ROUTE_DISTINGUISHER_LENGTH))));
- builder.setDistinguisher(distinguisher);
- byteOffset += ROUTE_DISTINGUISHER_LENGTH;
- }
- // parse source protocol
- final ProtocolId sp = ProtocolId.forValue(ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, PROTOCOL_ID_LENGTH)));
- byteOffset += PROTOCOL_ID_LENGTH;
- builder.setProtocolId(sp);
-
- // parse identifier
- final Identifier identifier = new Identifier(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(bytes, byteOffset,
- IDENTIFIER_LENGTH))));
- byteOffset += IDENTIFIER_LENGTH;
- builder.setIdentifier(identifier);
-
- // if we are dealing with linkstate nodes/links, parse local node descriptor
- NodeIdentifier localDescriptor = null;
- int locallength = 0;
- final int localtype = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TYPE_LENGTH));
- byteOffset += TYPE_LENGTH;
- locallength = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
- byteOffset += LENGTH_SIZE;
- if (localtype == 256) {
- localDescriptor = parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, locallength));
- }
- byteOffset += locallength;
- builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
- final int restLength = length - ((safi == MplsLabeledVpnSubsequentAddressFamily.class) ? ROUTE_DISTINGUISHER_LENGTH : 0)
- - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH - TYPE_LENGTH - LENGTH_SIZE - locallength;
- logger.debug("Restlength {}", restLength);
- switch (type) {
- case Link:
- parseLink(builder, ByteArray.subByte(bytes, byteOffset, restLength));
- break;
- case Ipv4Prefix:
- case Ipv6Prefix:
- builder.setPrefixDescriptors(parsePrefixDescriptors(localDescriptor, ByteArray.subByte(bytes, byteOffset, restLength)));
- break;
- case Node:
- // node nlri is already parsed as it contains only the common fields for node and link nlri
- break;
- }
- byteOffset += restLength;
- }
- return builder.build();
- }
public static boolean verifyLink(final Set<Integer> keys) {
for (final Integer i : keys) {
return true;
}
- private static NodeIdentifier parseLink(final CLinkstateDestinationBuilder builder, final byte[] bytes) throws BGPParsingException {
- int byteOffset = 0;
- final int type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TYPE_LENGTH));
- byteOffset += TYPE_LENGTH;
- final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
- byteOffset += LENGTH_SIZE;
- final NodeIdentifier remote = null;
- if (type == 257) {
- builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, length)));
- byteOffset += length;
- }
- builder.setLinkDescriptors(parseLinkDescriptors(ByteArray.subByte(bytes, byteOffset, bytes.length - byteOffset)));
- return remote;
- }
-
- private static LinkDescriptors parseLinkDescriptors(final byte[] bytes) throws BGPParsingException {
- int byteOffset = 0;
- final LinkDescriptorsBuilder builder = new LinkDescriptorsBuilder();
- while (byteOffset != bytes.length) {
- final int type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TYPE_LENGTH));
- byteOffset += TYPE_LENGTH;
- final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
- byteOffset += LENGTH_SIZE;
- final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
- logger.debug("Parsing Link Descriptor: {}", Arrays.toString(value));
- switch (type) {
- case 258:
- builder.setLinkLocalIdentifier(ByteArray.subByte(value, 0, 4));
- builder.setLinkRemoteIdentifier(ByteArray.subByte(value, 4, 4));
- logger.trace("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
- builder.getLinkRemoteIdentifier());
- break;
- case 259:
- final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
- builder.setIpv4InterfaceAddress(lipv4);
- logger.trace("Parsed IPv4 interface address {}.", lipv4);
- break;
- case 260:
- final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
- builder.setIpv4NeighborAddress(ripv4);
- logger.trace("Parsed IPv4 neighbor address {}.", ripv4);
- break;
- case 261:
- final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
- builder.setIpv6InterfaceAddress(lipv6);
- logger.trace("Parsed IPv6 interface address {}.", lipv6);
- break;
- case 262:
- final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
- builder.setIpv6NeighborAddress(ripv6);
- logger.trace("Parsed IPv6 neighbor address {}.", ripv6);
- break;
- case 263:
- final TopologyIdentifier topId = new TopologyIdentifier(ByteArray.bytesToInt(value) & 0x3fff);
- builder.setMultiTopologyId(topId);
- logger.trace("Parsed topology identifier {}.", topId);
- break;
- default:
- throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
- }
- byteOffset += length;
- }
- logger.debug("Finished parsing Link descriptors.");
- return builder.build();
- }
-
- private static NodeIdentifier parseNodeDescriptors(final byte[] bytes) throws BGPParsingException {
- int byteOffset = 0;
- AsNumber asnumber = null;
- DomainIdentifier bgpId = null;
- AreaIdentifier ai = null;
- CRouterIdentifier routerId = null;
- while (byteOffset != bytes.length) {
- final int type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TYPE_LENGTH));
- byteOffset += TYPE_LENGTH;
- final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
- byteOffset += LENGTH_SIZE;
- final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
- logger.debug("Parsing Node Descriptor: {}", Arrays.toString(value));
- switch (type) {
- case 512:
- asnumber = new AsNumber(ByteArray.bytesToLong(value));
- logger.trace("Parsed AS number {}", asnumber);
- break;
- case 513:
- bgpId = new DomainIdentifier(value);
- logger.trace("Parsed bgpId {}", bgpId);
- break;
- case 514:
- ai = new AreaIdentifier(value);
- logger.trace("Parsed area identifier {}", ai);
- break;
- case 515:
- if (value.length == 6) {
- routerId = new CIsisNodeBuilder().setIsisNode(
- new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
- } else if (value.length == 7) {
- if (value[6] == 0) {
- logger.warn("PSN octet is 0. Ignoring System ID.");
- routerId = new CIsisNodeBuilder().setIsisNode(
- new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
- break;
- } else {
- final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
- new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build();
- routerId = new CIsisPseudonodeBuilder().setIsisPseudonode(
- new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) UnsignedBytes.toInt(value[6])).build()).build();
- }
- } else if (value.length == 4) {
- routerId = new COspfNodeBuilder().setOspfNode(
- new OspfNodeBuilder().setOspfRouterId(ByteArray.subByte(value, 0, 4)).build()).build();
- } else if (value.length == 8) {
- final byte[] o = ByteArray.subByte(value, 0, 4); // FIXME: OSPFv3 vs OSPFv2
- final OspfInterfaceIdentifier a = new OspfInterfaceIdentifier(ByteArray.subByte(value, 4, 4));
- routerId = new COspfPseudonodeBuilder().setOspfPseudonode(
- new OspfPseudonodeBuilder().setOspfRouterId(o).setLanInterface(a).build()).build();
- }
- logger.trace("Parsed Router Identifier {}", routerId);
- break;
- default:
- throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
- }
- byteOffset += length;
- }
- logger.debug("Finished parsing Node descriptors.");
- return new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
- }
-
- private static PrefixDescriptors parsePrefixDescriptors(final NodeIdentifier localDescriptor, final byte[] bytes)
- throws BGPParsingException {
- int byteOffset = 0;
- final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
- while (byteOffset != bytes.length) {
- final int type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TYPE_LENGTH));
- byteOffset += TYPE_LENGTH;
- final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
- byteOffset += LENGTH_SIZE;
- final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
- logger.trace("Parsing Prefix Descriptor: {}", Arrays.toString(value));
- switch (type) {
- case 263:
- final TopologyIdentifier topologyId = new TopologyIdentifier(ByteArray.bytesToInt(value) & 0x3fff);
- builder.setMultiTopologyId(topologyId);
- logger.trace("Parsed Topology Identifier: {}", topologyId);
- break;
- case 264:
- final int rt = ByteArray.bytesToInt(value);
- final OspfRouteType routeType = OspfRouteType.forValue(rt);
- if (routeType == null) {
- throw new BGPParsingException("Unknown OSPF Route Type: " + rt);
- }
- builder.setOspfRouteType(routeType);
- logger.trace("Parser RouteType: {}", routeType);
- break;
- case 265:
- IpPrefix prefix = null;
- final int prefixLength = UnsignedBytes.toInt(value[0]);
- final int size = prefixLength / 8 + ((prefixLength % 8 == 0) ? 0 : 1);
- if (size != value.length - 1) {
- logger.debug("Expected length {}, actual length {}.", size, value.length - 1);
- throw new BGPParsingException("Illegal length of IP reachability TLV: " + (value.length - 1));
- }
- if (size == 4) {
- prefix = new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(value, 1, size), prefixLength));
- } else {
- prefix = new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.subByte(value, 1, size), prefixLength));
- }
- builder.setIpReachabilityInformation(prefix);
- logger.trace("Parsed IP reachability info: {}", prefix);
- break;
- default:
- throw new BGPParsingException("Prefix Descriptor not recognized, type: " + type);
- }
- byteOffset += length;
- }
- logger.debug("Finished parsing Prefix descriptors.");
- return builder.build();
- }
-
protected static LinkstatePathAttribute parseLinkState(final byte[] bytes) throws BGPParsingException {
final Map<Integer, ByteList> map = new HashMap<Integer, ByteList>();
int byteOffset = 0;
--- /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.parser.impl.message.update;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
+import org.opendaylight.protocol.bgp.parser.spi.NlriUtil;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.AreaIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.DomainIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Identifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv4InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.Ipv6InterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NlriType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.NodeIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.OspfInterfaceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.OspfRouteType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.ProtocolId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.RouteDistinguisher;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.isis.lan.identifier.IsIsRouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.isis.lan.identifier.IsIsRouterIdentifierBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.CLinkstateDestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.LocalNodeDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.PrefixDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.linkstate.destination.c.linkstate.destination.RemoteNodeDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.CRouterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.CIsisPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.COspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.isis.node.IsisNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.isis.pseudonode.IsisPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.node.OspfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.node.identifier.c.router.identifier.c.ospf.pseudonode.OspfPseudonodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.DestinationType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.IsoSystemIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.primitives.UnsignedBytes;
+
+final class LinkstateNlriParser implements NlriParser {
+ private static final Logger logger = 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 final boolean isVpn;
+
+ public LinkstateNlriParser(final boolean isVpn) {
+ this.isVpn = isVpn;
+ }
+
+ private static NodeIdentifier parseLink(final CLinkstateDestinationBuilder builder, final byte[] bytes) throws BGPParsingException {
+ int byteOffset = 0;
+ final int type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TYPE_LENGTH));
+ byteOffset += TYPE_LENGTH;
+ final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
+ byteOffset += LENGTH_SIZE;
+ final NodeIdentifier remote = null;
+ if (type == 257) {
+ builder.setRemoteNodeDescriptors((RemoteNodeDescriptors) parseNodeDescriptors(ByteArray.subByte(bytes, byteOffset, length)));
+ byteOffset += length;
+ }
+ builder.setLinkDescriptors(parseLinkDescriptors(ByteArray.subByte(bytes, byteOffset, bytes.length - byteOffset)));
+ return remote;
+ }
+
+ private static LinkDescriptors parseLinkDescriptors(final byte[] bytes) throws BGPParsingException {
+ int byteOffset = 0;
+ final LinkDescriptorsBuilder builder = new LinkDescriptorsBuilder();
+ while (byteOffset != bytes.length) {
+ final int type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TYPE_LENGTH));
+ byteOffset += TYPE_LENGTH;
+ final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
+ byteOffset += LENGTH_SIZE;
+ final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
+ logger.debug("Parsing Link Descriptor: {}", Arrays.toString(value));
+ switch (type) {
+ case 258:
+ builder.setLinkLocalIdentifier(ByteArray.subByte(value, 0, 4));
+ builder.setLinkRemoteIdentifier(ByteArray.subByte(value, 4, 4));
+ logger.trace("Parsed link local {} remote {} Identifiers.", builder.getLinkLocalIdentifier(),
+ builder.getLinkRemoteIdentifier());
+ break;
+ case 259:
+ final Ipv4InterfaceIdentifier lipv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
+ builder.setIpv4InterfaceAddress(lipv4);
+ logger.trace("Parsed IPv4 interface address {}.", lipv4);
+ break;
+ case 260:
+ final Ipv4InterfaceIdentifier ripv4 = new Ipv4InterfaceIdentifier(Ipv4Util.addressForBytes(value));
+ builder.setIpv4NeighborAddress(ripv4);
+ logger.trace("Parsed IPv4 neighbor address {}.", ripv4);
+ break;
+ case 261:
+ final Ipv6InterfaceIdentifier lipv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
+ builder.setIpv6InterfaceAddress(lipv6);
+ logger.trace("Parsed IPv6 interface address {}.", lipv6);
+ break;
+ case 262:
+ final Ipv6InterfaceIdentifier ripv6 = new Ipv6InterfaceIdentifier(Ipv6Util.addressForBytes(value));
+ builder.setIpv6NeighborAddress(ripv6);
+ logger.trace("Parsed IPv6 neighbor address {}.", ripv6);
+ break;
+ case 263:
+ final TopologyIdentifier topId = new TopologyIdentifier(ByteArray.bytesToInt(value) & 0x3fff);
+ builder.setMultiTopologyId(topId);
+ logger.trace("Parsed topology identifier {}.", topId);
+ break;
+ default:
+ throw new BGPParsingException("Link Descriptor not recognized, type: " + type);
+ }
+ byteOffset += length;
+ }
+ logger.debug("Finished parsing Link descriptors.");
+ return builder.build();
+ }
+
+ private static NodeIdentifier parseNodeDescriptors(final byte[] bytes) throws BGPParsingException {
+ int byteOffset = 0;
+ AsNumber asnumber = null;
+ DomainIdentifier bgpId = null;
+ AreaIdentifier ai = null;
+ CRouterIdentifier routerId = null;
+ while (byteOffset != bytes.length) {
+ final int type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TYPE_LENGTH));
+ byteOffset += TYPE_LENGTH;
+ final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
+ byteOffset += LENGTH_SIZE;
+ final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
+ logger.debug("Parsing Node Descriptor: {}", Arrays.toString(value));
+ switch (type) {
+ case 512:
+ asnumber = new AsNumber(ByteArray.bytesToLong(value));
+ logger.trace("Parsed AS number {}", asnumber);
+ break;
+ case 513:
+ bgpId = new DomainIdentifier(value);
+ logger.trace("Parsed bgpId {}", bgpId);
+ break;
+ case 514:
+ ai = new AreaIdentifier(value);
+ logger.trace("Parsed area identifier {}", ai);
+ break;
+ case 515:
+ if (value.length == 6) {
+ routerId = new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
+ } else if (value.length == 7) {
+ if (value[6] == 0) {
+ logger.warn("PSN octet is 0. Ignoring System ID.");
+ routerId = new CIsisNodeBuilder().setIsisNode(
+ new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build()).build();
+ break;
+ } else {
+ final IsIsRouterIdentifier iri = new IsIsRouterIdentifierBuilder().setIsoSystemId(
+ new IsoSystemIdentifier(ByteArray.subByte(value, 0, 6))).build();
+ routerId = new CIsisPseudonodeBuilder().setIsisPseudonode(
+ new IsisPseudonodeBuilder().setIsIsRouterIdentifier(iri).setPsn((short) UnsignedBytes.toInt(value[6])).build()).build();
+ }
+ } else if (value.length == 4) {
+ routerId = new COspfNodeBuilder().setOspfNode(
+ new OspfNodeBuilder().setOspfRouterId(ByteArray.subByte(value, 0, 4)).build()).build();
+ } else if (value.length == 8) {
+ final byte[] o = ByteArray.subByte(value, 0, 4); // FIXME: OSPFv3 vs OSPFv2
+ final OspfInterfaceIdentifier a = new OspfInterfaceIdentifier(ByteArray.subByte(value, 4, 4));
+ routerId = new COspfPseudonodeBuilder().setOspfPseudonode(
+ new OspfPseudonodeBuilder().setOspfRouterId(o).setLanInterface(a).build()).build();
+ }
+ logger.trace("Parsed Router Identifier {}", routerId);
+ break;
+ default:
+ throw new BGPParsingException("Node Descriptor not recognized, type: " + type);
+ }
+ byteOffset += length;
+ }
+ logger.debug("Finished parsing Node descriptors.");
+ return new LocalNodeDescriptorsBuilder().setAsNumber(asnumber).setDomainId(bgpId).setAreaId(ai).setCRouterIdentifier(routerId).build();
+ }
+
+ private static PrefixDescriptors parsePrefixDescriptors(final NodeIdentifier localDescriptor, final byte[] bytes) throws BGPParsingException {
+ int byteOffset = 0;
+ final PrefixDescriptorsBuilder builder = new PrefixDescriptorsBuilder();
+ while (byteOffset != bytes.length) {
+ final int type = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, TYPE_LENGTH));
+ byteOffset += TYPE_LENGTH;
+ final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
+ byteOffset += LENGTH_SIZE;
+ final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
+ logger.trace("Parsing Prefix Descriptor: {}", Arrays.toString(value));
+ switch (type) {
+ case 263:
+ final TopologyIdentifier topologyId = new TopologyIdentifier(ByteArray.bytesToInt(value) & 0x3fff);
+ builder.setMultiTopologyId(topologyId);
+ logger.trace("Parsed Topology Identifier: {}", topologyId);
+ break;
+ case 264:
+ final int rt = ByteArray.bytesToInt(value);
+ final OspfRouteType routeType = OspfRouteType.forValue(rt);
+ if (routeType == null) {
+ throw new BGPParsingException("Unknown OSPF Route Type: " + rt);
+ }
+ builder.setOspfRouteType(routeType);
+ logger.trace("Parser RouteType: {}", routeType);
+ break;
+ case 265:
+ IpPrefix prefix = null;
+ final int prefixLength = UnsignedBytes.toInt(value[0]);
+ final int size = prefixLength / 8 + ((prefixLength % 8 == 0) ? 0 : 1);
+ if (size != value.length - 1) {
+ logger.debug("Expected length {}, actual length {}.", size, value.length - 1);
+ throw new BGPParsingException("Illegal length of IP reachability TLV: " + (value.length - 1));
+ }
+ if (size == 4) {
+ prefix = new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(value, 1, size), prefixLength));
+ } else {
+ prefix = new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.subByte(value, 1, size), prefixLength));
+ }
+ builder.setIpReachabilityInformation(prefix);
+ logger.trace("Parsed IP reachability info: {}", prefix);
+ break;
+ default:
+ throw new BGPParsingException("Prefix Descriptor not recognized, type: " + type);
+ }
+ byteOffset += length;
+ }
+ logger.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
+ * @return BGPLinkMP or BGPNodeMP
+ * @throws BGPParsingException
+ */
+ private final CLinkstateDestination parseNlri(final byte[] nlri) throws BGPParsingException {
+ if (nlri.length == 0) {
+ return null;
+ }
+ int byteOffset = 0;
+
+ final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder();
+
+ while (byteOffset != nlri.length) {
+ final NlriType type = NlriType.forValue(ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, TYPE_LENGTH)));
+ builder.setNlriType(type);
+
+ byteOffset += TYPE_LENGTH;
+ // length means total length of the tlvs including route distinguisher not including the type field
+ final int length = ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, LENGTH_SIZE));
+ byteOffset += LENGTH_SIZE;
+ RouteDistinguisher distinguisher = null;
+ if (isVpn) {
+ // this parses route distinguisher
+ distinguisher = new RouteDistinguisher(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(nlri, byteOffset,
+ ROUTE_DISTINGUISHER_LENGTH))));
+ builder.setDistinguisher(distinguisher);
+ byteOffset += ROUTE_DISTINGUISHER_LENGTH;
+ }
+ // parse source protocol
+ final ProtocolId sp = ProtocolId.forValue(ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, PROTOCOL_ID_LENGTH)));
+ byteOffset += PROTOCOL_ID_LENGTH;
+ builder.setProtocolId(sp);
+
+ // parse identifier
+ final Identifier identifier = new Identifier(BigInteger.valueOf(ByteArray.bytesToLong(ByteArray.subByte(nlri, byteOffset,
+ IDENTIFIER_LENGTH))));
+ byteOffset += IDENTIFIER_LENGTH;
+ builder.setIdentifier(identifier);
+
+ // if we are dealing with linkstate nodes/links, parse local node descriptor
+ NodeIdentifier localDescriptor = null;
+ int locallength = 0;
+ final int localtype = ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, TYPE_LENGTH));
+ byteOffset += TYPE_LENGTH;
+ locallength = ByteArray.bytesToInt(ByteArray.subByte(nlri, byteOffset, LENGTH_SIZE));
+ byteOffset += LENGTH_SIZE;
+ if (localtype == 256) {
+ localDescriptor = parseNodeDescriptors(ByteArray.subByte(nlri, byteOffset, locallength));
+ }
+ byteOffset += locallength;
+ builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
+ final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0)
+ - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH - TYPE_LENGTH - LENGTH_SIZE - locallength;
+ logger.debug("Restlength {}", restLength);
+ switch (type) {
+ case Link:
+ parseLink(builder, ByteArray.subByte(nlri, byteOffset, restLength));
+ break;
+ case Ipv4Prefix:
+ case Ipv6Prefix:
+ builder.setPrefixDescriptors(parsePrefixDescriptors(localDescriptor, ByteArray.subByte(nlri, byteOffset, restLength)));
+ break;
+ case Node:
+ // node nlri is already parsed as it contains only the common fields for node and link nlri
+ break;
+ }
+ byteOffset += restLength;
+ }
+ return builder.build();
+ }
+
+ @Override
+ public final void parseNlri(final byte[] nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
+ final CLinkstateDestination dst = parseNlri(nlri);
+
+ // FIXME: This cast is because of a bug in yangtools (augmented choice has no relationship with base choice)
+ final DestinationType s = (DestinationType)new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build();
+
+ builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(s).build());
+ }
+
+ @Override
+ public final void parseNlri(final byte[] nlri, final byte[] nextHop, final MpReachNlriBuilder builder) throws BGPParsingException {
+ final CLinkstateDestination dst = parseNlri(nlri);
+
+ // FIXME: This cast is because of a bug in yangtools (augmented choice has no relationship with base choice)
+ final DestinationType s = (DestinationType)new DestinationLinkstateBuilder().setCLinkstateDestination(dst).build();
+
+ builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(s).build());
+ NlriUtil.parseNextHop(nextHop, builder);
+ }
+}
\ No newline at end of file
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
+import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1Builder;
+import com.google.common.base.Preconditions;
+
final class MPReachAttributeParser implements AttributeParser {
static final int TYPE = 14;
+ private final NlriRegistry reg;
+
+ MPReachAttributeParser(final NlriRegistry reg) {
+ this.reg = Preconditions.checkNotNull(reg);
+ }
+
@Override
public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) throws BGPDocumentedException {
try {
- final PathAttributes1 a = new PathAttributes1Builder().setMpReachNlri(MPReachParser.parseMPReach(bytes)).build();
-
+ final PathAttributes1 a = new PathAttributes1Builder().setMpReachNlri(reg.parseMpReach(bytes)).build();
builder.addAugmentation(PathAttributes1.class, a);
} catch (final BGPParsingException e) {
throw new BGPDocumentedException("Could not parse MP_REACH_NLRI: " + e.getMessage(), BGPError.OPT_ATTR_ERROR);
+++ /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.parser.impl.message.update;
-
-import java.util.List;
-
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.impl.SimpleAddressFamilyRegistry;
-import org.opendaylight.protocol.bgp.parser.impl.SimpleSubsequentAddressFamilyRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
-import org.opendaylight.protocol.concepts.Ipv4Util;
-import org.opendaylight.protocol.concepts.Ipv6Util;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.nlri.LinkstateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.Nlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.nlri.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.nlri.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.unreach.nlri.WithdrawnRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHopBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv4.next.hop.Ipv4NextHopBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
-
-import com.google.common.primitives.UnsignedBytes;
-
-/**
- * Parser for MP_REACH or MP_UNREACH fields.
- */
-public class MPReachParser {
- private static final int ADDRESS_FAMILY_IDENTIFIER_SIZE = 2;
-
- private static final int SUBSEQUENT_ADDRESS_FAMILY_IDENTIFIER_SIZE = 1;
-
- private static final int NEXT_HOP_LENGTH_SIZE = 1;
-
- private static final int RESERVED_SIZE = 1;
-
- private static final AddressFamilyRegistry afiReg = SimpleAddressFamilyRegistry.INSTANCE;
- private static final SubsequentAddressFamilyRegistry safiReg = SimpleSubsequentAddressFamilyRegistry.INSTANCE;
-
- private MPReachParser() {
- }
-
- static MpUnreachNlri parseMPUnreach(final byte[] bytes) throws BGPParsingException {
- int byteOffset = 0;
- final MpUnreachNlriBuilder builder = new MpUnreachNlriBuilder();
-
- final int afiVal = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, ADDRESS_FAMILY_IDENTIFIER_SIZE));
- final Class<? extends AddressFamily> afi = afiReg.classForFamily(afiVal);
- if (afi == null) {
- throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
- }
- byteOffset += ADDRESS_FAMILY_IDENTIFIER_SIZE;
- builder.setAfi(afi);
-
- final int safiVal = UnsignedBytes.toInt(bytes[byteOffset]);
- final Class<? extends SubsequentAddressFamily> safi = safiReg.classForFamily(safiVal);
- if (safi == null) {
- throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
- }
- byteOffset += SUBSEQUENT_ADDRESS_FAMILY_IDENTIFIER_SIZE;
- builder.setSafi(safi);
-
- final WithdrawnRoutes routes = new WithdrawnRoutesBuilder().setNlri(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.Nlri) chooseReachParser(
- afi, safi, ByteArray.subByte(bytes, byteOffset, bytes.length - byteOffset))).build();
- builder.setWithdrawnRoutes(routes);
- return builder.build();
- }
-
- static MpReachNlri parseMPReach(final byte[] bytes) throws BGPParsingException {
- int byteOffset = 0;
- final MpReachNlriBuilder builder = new MpReachNlriBuilder();
-
- final int afiVal = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, ADDRESS_FAMILY_IDENTIFIER_SIZE));
- final Class<? extends AddressFamily> afi = afiReg.classForFamily(afiVal);
- if (afi == null) {
- throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
- }
- byteOffset += ADDRESS_FAMILY_IDENTIFIER_SIZE;
- builder.setAfi(afi);
-
- final int safiVal = UnsignedBytes.toInt(bytes[byteOffset]);
- final Class<? extends SubsequentAddressFamily> safi = safiReg.classForFamily(safiVal);
- if (safi == null) {
- throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
- }
- byteOffset += SUBSEQUENT_ADDRESS_FAMILY_IDENTIFIER_SIZE;
- builder.setSafi(safi);
-
- final int nextHopLength = UnsignedBytes.toInt(bytes[byteOffset]);
- byteOffset += NEXT_HOP_LENGTH_SIZE;
- final CNextHop nextHop = parseNextHop(ByteArray.subByte(bytes, byteOffset, nextHopLength));
- byteOffset += nextHopLength + RESERVED_SIZE;
- builder.setCNextHop(nextHop);
-
- final AdvertizedRoutes routes = new AdvertizedRoutesBuilder().setNlri(
- (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.destination.Nlri) chooseReachParser(
- afi, safi, ByteArray.subByte(bytes, byteOffset, bytes.length - (byteOffset)))).build();
- builder.setAdvertizedRoutes(routes);
- return builder.build();
- }
-
- private static Nlri chooseReachParser(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi,
- final byte[] bytes) throws BGPParsingException {
- if (afi == Ipv4AddressFamily.class) {
- final List<Ipv4Prefix> nlri4 = Ipv4Util.prefixListForBytes(bytes);
- return new Ipv4Builder().setIpv4Prefixes(nlri4).build();
- } else if (afi == Ipv6AddressFamily.class) {
- final List<Ipv6Prefix> nlri6 = Ipv6Util.prefixListForBytes(bytes);
- return new Ipv6Builder().setIpv6Prefixes(nlri6).build();
- } else if (afi == LinkstateAddressFamily.class) {
- return new LinkstateBuilder().setCLinkstateDestination(LinkstateAttributeParser.parseLSNlri(safi, bytes)).build();
- }
- return null;
- }
-
- private static CNextHop parseNextHop(final byte[] bytes) throws BGPParsingException {
- final CNextHop addr;
- switch (bytes.length) {
- case 4:
- addr = new CIpv4NextHopBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(Ipv4Util.addressForBytes(bytes)).build()).build();
- break;
- case 16:
- addr = new CIpv6NextHopBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForBytes(bytes)).build()).build();
- break;
- case 32:
- addr = new CIpv6NextHopBuilder().setIpv6NextHop(
- new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForBytes(ByteArray.subByte(bytes, 0, 16))).setLinkLocal(
- Ipv6Util.addressForBytes(ByteArray.subByte(bytes, 16, 16))).build()).build();
- break;
- default:
- throw new BGPParsingException("Cannot parse NEXT_HOP attribute. Wrong bytes length: " + bytes.length);
- }
- return addr;
- }
-}
import org.opendaylight.protocol.bgp.parser.BGPError;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
+import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2Builder;
+import com.google.common.base.Preconditions;
+
final class MPUnreachAttributeParser implements AttributeParser {
static final int TYPE = 15;
+ private final NlriRegistry reg;
+
+ MPUnreachAttributeParser(final NlriRegistry reg) {
+ this.reg = Preconditions.checkNotNull(reg);
+ }
+
@Override
public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) throws BGPDocumentedException {
try {
- final PathAttributes2 a = new PathAttributes2Builder().setMpUnreachNlri(MPReachParser.parseMPUnreach(bytes)).build();
+ final PathAttributes2 a = new PathAttributes2Builder().setMpUnreachNlri(reg.parseMpUnreach(bytes)).build();
builder.addAugmentation(PathAttributes2.class, a);
} catch (final BGPParsingException e) {
throw new BGPDocumentedException("Could not parse MP_UNREACH_NLRI: " + e.getMessage(), BGPError.OPT_ATTR_ERROR);
reg.registerAttributeParser(CommunitiesAttributeParser.TYPE, new CommunitiesAttributeParser());
reg.registerAttributeParser(OriginatorIdAttributeParser.TYPE, new OriginatorIdAttributeParser());
reg.registerAttributeParser(ClusterIdAttributeParser.TYPE, new ClusterIdAttributeParser());
- reg.registerAttributeParser(MPReachAttributeParser.TYPE, new MPReachAttributeParser());
- reg.registerAttributeParser(MPUnreachAttributeParser.TYPE, new MPUnreachAttributeParser());
+ reg.registerAttributeParser(MPReachAttributeParser.TYPE, new MPReachAttributeParser(SimpleNlriRegistry.INSTANCE));
+ reg.registerAttributeParser(MPUnreachAttributeParser.TYPE, new MPUnreachAttributeParser(SimpleNlriRegistry.INSTANCE));
reg.registerAttributeParser(ExtendedCommunitiesAttributeParser.TYPE, new ExtendedCommunitiesAttributeParser());
reg.registerAttributeParser(AS4AggregatorAttributeParser.TYPE, new AS4AggregatorAttributeParser());
reg.registerAttributeParser(AS4PathAttributeParser.TYPE, new AS4PathAttributeParser());
--- /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.parser.impl.message.update;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.protocol.bgp.parser.impl.SimpleAddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.impl.SimpleSubsequentAddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
+import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+import org.opendaylight.protocol.concepts.AbstractRegistration;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.MplsLabeledVpnSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.UnsignedBytes;
+
+public final class SimpleNlriRegistry implements NlriRegistry {
+ public static final NlriRegistry INSTANCE;
+
+ static {
+ final NlriRegistry reg = new SimpleNlriRegistry(SimpleAddressFamilyRegistry.INSTANCE,
+ SimpleSubsequentAddressFamilyRegistry.INSTANCE);
+
+ final NlriParser ipv4 = new Ipv4NlriParser();
+ reg.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, ipv4);
+
+ final NlriParser ipv6 = new Ipv6NlriParser();
+ reg.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, ipv6);
+
+ reg.registerNlriParser(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new LinkstateNlriParser(false));
+ reg.registerNlriParser(LinkstateAddressFamily.class, MplsLabeledVpnSubsequentAddressFamily.class, new LinkstateNlriParser(true));
+
+ INSTANCE = reg;
+ }
+
+ private static BgpTableType createKey(final Class<? extends AddressFamily> afi,
+ final Class<? extends SubsequentAddressFamily> safi) {
+ Preconditions.checkNotNull(afi);
+ Preconditions.checkNotNull(safi);
+ return new BgpTableTypeImpl(afi, safi);
+ }
+
+ private final ConcurrentMap<BgpTableType, NlriParser> handlers = new ConcurrentHashMap<>();
+ private final SubsequentAddressFamilyRegistry safiReg;
+ private final AddressFamilyRegistry afiReg;
+
+ public SimpleNlriRegistry(final AddressFamilyRegistry afiReg, final SubsequentAddressFamilyRegistry safiReg) {
+ this.afiReg = Preconditions.checkNotNull(afiReg);
+ this.safiReg = Preconditions.checkNotNull(safiReg);
+ }
+
+ @Override
+ public synchronized AutoCloseable registerNlriParser(final Class<? extends AddressFamily> afi,
+ final Class<? extends SubsequentAddressFamily> safi, final NlriParser parser) {
+ final BgpTableType key = createKey(afi, safi);
+ final NlriParser prev = handlers.get(key);
+ Preconditions.checkState(prev == null, "AFI/SAFI is already bound to parser " + prev);
+
+ handlers.put(key, parser);
+ final Object lock = this;
+ return new AbstractRegistration() {
+ @Override
+ protected void removeRegistration() {
+ synchronized (lock) {
+ handlers.remove(key);
+ }
+ }
+ };
+ }
+
+ private Class<? extends AddressFamily> getAfi(final byte[] header) throws BGPParsingException {
+ final int afiVal = UnsignedBytes.toInt(header[0]) * 256 + UnsignedBytes.toInt(header[1]);
+ final Class<? extends AddressFamily> afi = afiReg.classForFamily(afiVal);
+ if (afi == null) {
+ throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
+ }
+
+ return afi;
+ }
+
+ private Class<? extends SubsequentAddressFamily> getSafi(final byte[] header) throws BGPParsingException {
+ final int safiVal = UnsignedBytes.toInt(header[2]);
+ final Class<? extends SubsequentAddressFamily> safi = safiReg.classForFamily(safiVal);
+ if (safi == null) {
+ throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
+ }
+
+ return safi;
+ }
+
+ @Override
+ public MpUnreachNlri parseMpUnreach(final byte[] bytes) throws BGPParsingException {
+ final MpUnreachNlriBuilder builder = new MpUnreachNlriBuilder();
+ builder.setAfi(getAfi(bytes));
+ builder.setSafi(getSafi(bytes));
+
+ final NlriParser parser = handlers.get(createKey(builder.getAfi(), builder.getSafi()));
+ parser.parseNlri(ByteArray.subByte(bytes, 3, bytes.length - 3), builder);
+
+ // builder.setWithdrawnRoutes(routes);
+ return builder.build();
+ }
+
+ @Override
+ public MpReachNlri parseMpReach(final byte[] bytes) throws BGPParsingException {
+ final MpReachNlriBuilder builder = new MpReachNlriBuilder();
+ builder.setAfi(getAfi(bytes));
+ builder.setSafi(getSafi(bytes));
+
+ final NlriParser parser = handlers.get(createKey(builder.getAfi(), builder.getSafi()));
+
+ final int nextHopLength = UnsignedBytes.toInt(bytes[3]);
+ int byteOffset = 4;
+
+ final byte[] nextHop = ByteArray.subByte(bytes, byteOffset, nextHopLength);
+ byteOffset += nextHopLength + 1;
+
+ final byte[] nlri = ByteArray.subByte(bytes, byteOffset, bytes.length - byteOffset);
+ parser.parseNlri(nlri, nextHop, builder);
+
+ return builder.build();
+ }
+}
--- /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.parser.spi;
+
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlriBuilder;
+
+public interface NlriParser {
+ public void parseNlri(byte[] nlri, MpUnreachNlriBuilder builder) throws BGPParsingException;
+ public void parseNlri(byte[] nlri, byte[] nextHop, MpReachNlriBuilder builder) throws BGPParsingException;
+}
--- /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.parser.spi;
+
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
+
+public interface NlriRegistry {
+ public AutoCloseable registerNlriParser(Class<? extends AddressFamily> afi,
+ Class<? extends SubsequentAddressFamily> safi, NlriParser parser);
+ // public AutoCloseable registerNlriSerializer(Class<? extends DataObject> nlriClass, NlriSerializer serializer);
+
+ public MpUnreachNlri parseMpUnreach(final byte[] bytes) throws BGPParsingException;
+ public MpReachNlri parseMpReach(final byte[] bytes) throws BGPParsingException;
+ // public byte[] serializeNlri(DataObject attribute);
+}
--- /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.parser.spi;
+
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+public interface NlriSerializer {
+ public byte[] serializeAttribute(final DataObject attribute);
+}
--- /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.parser.spi;
+
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv4NextHopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.CIpv6NextHopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv4.next.hop.Ipv4NextHopBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.c.ipv6.next.hop.Ipv6NextHopBuilder;
+
+public final class NlriUtil {
+ private NlriUtil() {
+
+ }
+
+ public static void parseNextHop(final byte[] bytes, final MpReachNlriBuilder builder) throws BGPParsingException {
+ final CNextHop addr;
+
+ switch (bytes.length) {
+ case 4:
+ addr = new CIpv4NextHopBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(Ipv4Util.addressForBytes(bytes)).build()).build();
+ break;
+ case 16:
+ addr = new CIpv6NextHopBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForBytes(bytes)).build()).build();
+ break;
+ case 32:
+ addr = new CIpv6NextHopBuilder().setIpv6NextHop(
+ new Ipv6NextHopBuilder().setGlobal(Ipv6Util.addressForBytes(ByteArray.subByte(bytes, 0, 16))).setLinkLocal(
+ Ipv6Util.addressForBytes(ByteArray.subByte(bytes, 16, 16))).build()).build();
+ break;
+ default:
+ throw new BGPParsingException("Cannot parse NEXT_HOP attribute. Wrong bytes length: " + bytes.length);
+ }
+
+ builder.setCNextHop(addr);
+ }
+}
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction ;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
import org.opendaylight.protocol.bgp.rib.spi.AbstractAdjRIBsIn;
import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsIn;
import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsInFactory;
}
};
- for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.unreach.nlri.withdrawn.routes.nlri.Ipv4)nlri.getAdvertizedRoutes().getNlri()).getIpv4Prefixes()) {
+ for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4)nlri.getAdvertizedRoutes().getDestinationType()).getIpv4Prefixes()) {
super.add(trans, peer, id, data);
}
}
@Override
public void removeRoutes(final DataModificationTransaction trans, final Peer peer,
final MpUnreachNlri nlri) {
- for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.unreach.nlri.withdrawn.routes.nlri.Ipv4)nlri.getWithdrawnRoutes().getNlri()).getIpv4Prefixes()) {
+ for (Ipv4Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4)nlri.getWithdrawnRoutes().getDestinationType()).getIpv4Prefixes()) {
super.remove(trans, peer, id);
}
}
}
};
- for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.nlri.Ipv6)nlri.getAdvertizedRoutes().getNlri()).getIpv6Prefixes()) {
+ for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6)nlri.getAdvertizedRoutes().getDestinationType()).getIpv6Prefixes()) {
super.add(trans, peer, id, data);
}
}
@Override
public void removeRoutes(final DataModificationTransaction trans, final Peer peer,
final MpUnreachNlri nlri) {
- for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.unreach.nlri.withdrawn.routes.nlri.Ipv6)nlri.getWithdrawnRoutes().getNlri()).getIpv6Prefixes()) {
+ for (Ipv6Prefix id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6)nlri.getWithdrawnRoutes().getDestinationType()).getIpv6Prefixes()) {
super.remove(trans, peer, id);
}
}
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes attributes) {
final CLinkstateDestination key =
((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.
- update.path.attributes.mp.reach.nlri.advertized.routes.nlri.Linkstate) nlri.getAdvertizedRoutes().getNlri()).getCLinkstateDestination();
+ update.path.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstate) nlri.getAdvertizedRoutes().getDestinationType()).getCLinkstateDestination();
RIBEntryData data = null;
switch (key.getNlriType()) {
final MpUnreachNlri nlri) {
final CLinkstateDestination key =
((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.
- update.path.attributes.mp.unreach.nlri.withdrawn.routes.nlri.Linkstate) nlri.getWithdrawnRoutes().getNlri()).getCLinkstateDestination();
+ update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstate) nlri.getWithdrawnRoutes().getDestinationType()).getCLinkstateDestination();
super.remove(trans, peer, key);
}