* @return The path identifier from data change
*/
public static Long extractPathId(final NormalizedNode<?, ?> data, final NodeIdentifier pathNii) {
- final Long pathId = (Long) NormalizedNodes.findNode(data, pathNii).get().getValue();
- Preconditions.checkNotNull(pathId);
- return pathId;
+ final NormalizedNode<?, ?> pathId = NormalizedNodes.findNode(data, pathNii).orNull();
+ if (pathId == null) {
+ return null;
+ }
+ return (Long) pathId.getValue();
}
/**
* @param routeId Route Id value
* @param routeQname route QName provided per each RibSupport
* @param pathidQname Path Id QName provided per each RibSupport
- * @param prefixQname Prefix QName provided per each RibSupport
+ * @param routeKeyQname Prefix QName provided per each RibSupport
* @return Route Key Nid
*/
public static PathArgument createNidKey(final long pathId, final PathArgument routeId, final QName routeQname, final QName pathidQname,
- final QName prefixQname) {
- final String prefix = (String) (((NodeIdentifierWithPredicates) routeId).getKeyValues()).get(prefixQname);
- return createNodeIdentifierWithPredicates(routeQname, pathidQname, pathId, prefixQname, prefix);
+ final QName routeKeyQname) {
+ return createNodeIdentifierWithPredicates(routeQname, pathidQname, pathId, routeKeyQname, getObjectKey(routeId, routeKeyQname));
+ }
+
+ /**
+ * Get route key object ( prefgit stat ix / key-value/ .. )
+ *
+ * @param routeId PathArgument containing the key
+ * @param routeKeyQname routeKey Qname
+ * @return key
+ */
+ public static Object getObjectKey(final PathArgument routeId, final QName routeKeyQname) {
+ return (((NodeIdentifierWithPredicates) routeId).getKeyValues()).get(routeKeyQname);
}
- private static NodeIdentifierWithPredicates createNodeIdentifierWithPredicates(final QName routeQname, final QName pathidQname, final Object pathId,
- final QName prefixQname, final Object prefix) {
- final ImmutableMap<QName, Object> keyValues = ImmutableMap.of(pathidQname, pathId, prefixQname, prefix);
+ public static NodeIdentifierWithPredicates createNodeIdentifierWithPredicates(final QName routeQname, final QName pathidQname, final Object pathId,
+ final QName routeKeyQname, final Object keyObject) {
+ final ImmutableMap<QName, Object> keyValues = ImmutableMap.of(pathidQname, pathId, routeKeyQname, keyObject);
return new NodeIdentifierWithPredicates(routeQname, keyValues);
}
*/
public static PathId buildPathId(final DataContainerNode<? extends PathArgument> routesCont, final NodeIdentifier pathIdNii) {
final Long pathIdVal = PathIdUtil.extractPathId(routesCont, pathIdNii);
- return new PathId(pathIdVal);
+ return pathIdVal == null ? null : new PathId(pathIdVal);
}
/**
this.values = newAttributes;
this.offsets = newOffsets;
this.pathsId = newPathsId;
- this.offsets.setValue(this.pathsId, offset, this.pathIdCounter++);
+ this.offsets.setValue(this.pathsId, offset, ++this.pathIdCounter);
}
this.offsets.setValue(this.values, offset, attributes);
LOG.trace("Added route from {} attributes {}", key.getRouteId(), attributes);
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.bgp.types.rev130919.Ipv4AddressFamily;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
/**
* Class supporting IPv4 unicast RIBs.
private List<Ipv4Prefixes> extractPrefixes(final Collection<MapEntryNode> routes) {
final List<Ipv4Prefixes> prefs = new ArrayList<>(routes.size());
for (final MapEntryNode route : routes) {
- final String prefix = (String) route.getChild(this.routePrefixIdentifier()).get().getValue();
+ final String prefix = (String) NormalizedNodes.findNode(route, this.routePrefixIdentifier()).get().getValue();
final Ipv4PrefixesBuilder prefixBuilder = new Ipv4PrefixesBuilder().setPrefix(new Ipv4Prefix(prefix));
prefixBuilder.setPathId(PathIdUtil.buildPathId(route, this.routePathIdNid()));
prefs.add(prefixBuilder.build());
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.bgp.types.rev130919.Ipv6AddressFamily;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
/**
* Class supporting IPv6 unicast RIBs.
private List<Ipv6Prefixes> extractPrefixes(final Collection<MapEntryNode> routes) {
final List<Ipv6Prefixes> prefs = new ArrayList<>(routes.size());
- for (final MapEntryNode ipv6Route : routes) {
- final String prefix = (String) ipv6Route.getChild(this.routePrefixIdentifier()).get().getValue();
- prefs.add(new Ipv6PrefixesBuilder().setPathId(PathIdUtil.buildPathId(ipv6Route, this.routePathIdNid())).setPrefix(new Ipv6Prefix(prefix)).build());
+ for (final MapEntryNode route : routes) {
+ final String prefix = (String) NormalizedNodes.findNode(route, this.routePrefixIdentifier()).get().getValue();
+ prefs.add(new Ipv6PrefixesBuilder().setPathId(PathIdUtil.buildPathId(route, this.routePathIdNid())).setPrefix(new Ipv6Prefix(prefix)).build());
}
return prefs;
}
final UnsignedInteger routerId = RouterIds.routerIdForPeerId(peerId);
final Collection<DataTreeCandidateNode> modifiedRoutes = this.ribSupport.changedRoutes(child);
for (final DataTreeCandidateNode route : modifiedRoutes) {
- final PathArgument routeId = route.getIdentifier();
+ final PathArgument routeId = this.ribSupport.createRouteKeyPathArgument(route.getIdentifier());
RouteEntry entry = this.routeEntries.get(routeId);
final Optional<NormalizedNode<?, ?>> maybeData = route.getDataAfter();
final Optional<NormalizedNode<?, ?>> maybeDataBefore = route.getDataBefore();
@Nullable default PathArgument getRouteIdAddPath(long pathId, PathArgument routeId) {
return null;
}
+
+ /**
+ * Create a new Path Argument for route Key removing remove Path Id from key
+ * For non extension which doesnt support Multiple Path this step is not required
+ * @param routeKeyPathArgument routeKey Path Argument
+ * @return new route Key
+ */
+ default PathArgument createRouteKeyPathArgument(PathArgument routeKeyPathArgument) {
+ return routeKeyPathArgument;
+ }
}
package org.opendaylight.protocol.bgp.rib.spi;
+import com.google.common.collect.ImmutableMap;
import javax.annotation.Nonnull;
import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
* node in instantiations of the rib grouping. It is assumed that this container is defined by
* the same model which populates it with route grouping instantiation, and by extension with
* the route attributes container.
+ *
* @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null
* @param containerClass Binding class of the container in routes choice, must not be null.
* @param listClass Binding class of the route list, nust not be null;
- * @param addressFamilyClass address Family Class
- * @param safiClass SubsequentAddressFamily
+ * @param addressFamilyClass address Family Class
+ * @param safiClass SubsequentAddressFamily
* @param routeKeyNaming Route Key name (prefix/ route-key / etc..)
* @param destinationQname destination Qname
*/
return this.routeKeyQname;
}
+ @Override
+ public final Long extractPathId(final NormalizedNode<?, ?> data) {
+ final Long pathId = PathIdUtil.extractPathId(data, this.routePathIdNid());
+ if(pathId == null) {
+ return PathIdUtil.NON_PATH_ID;
+ }
+ return pathId;
+ }
+
@Nonnull
@Override
public final PathArgument getRouteIdAddPath(final long pathId, final PathArgument routeId) {
}
@Override
- public final Long extractPathId(final NormalizedNode<?, ?> data) {
- return PathIdUtil.extractPathId(data, this.routePathIdNid());
+ public PathArgument createRouteKeyPathArgument(PathArgument routeKey) {
+ final ImmutableMap<QName, Object> keyValues = ImmutableMap.of(routeKeyQName(), PathIdUtil.getObjectKey(routeKey, routeKeyQName()));
+ return new NodeIdentifierWithPredicates(routeQName(), keyValues);
}
+
}