2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bgp.rib.spi;
11 import com.google.common.collect.ImmutableMap;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26 * Implements common methods for Advertisement of Multiple Paths on ribSupport.
28 public abstract class MultiPathAbstractRIBSupport extends AbstractRIBSupport {
29 private final QName routeKeyQname;
30 private final QName pathIdQname;
31 private final NodeIdentifier pathIdNid;
34 * Default constructor. Requires the QName of the container augmented under the routes choice
35 * node in instantiations of the rib grouping. It is assumed that this container is defined by
36 * the same model which populates it with route grouping instantiation, and by extension with
37 * the route attributes container.
39 * @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null
40 * @param containerClass Binding class of the container in routes choice, must not be null.
41 * @param listClass Binding class of the route list, nust not be null;
42 * @param addressFamilyClass address Family Class
43 * @param safiClass SubsequentAddressFamily
44 * @param routeKeyNaming Route Key name (prefix/ route-key / etc..)
45 * @param destinationQname destination Qname
47 protected MultiPathAbstractRIBSupport(final Class<? extends Routes> cazeClass,
48 final Class<? extends DataObject> containerClass,
49 final Class<? extends Route> listClass, final Class<? extends AddressFamily> addressFamilyClass,
50 final Class<? extends SubsequentAddressFamily> safiClass, final String routeKeyNaming,
51 final QName destinationQname) {
52 super(cazeClass, containerClass, listClass, addressFamilyClass, safiClass, destinationQname);
53 this.routeKeyQname = QName.create(routeQName(), routeKeyNaming).intern();
54 this.pathIdQname = QName.create(routeQName(), "path-id").intern();
55 this.pathIdNid = new NodeIdentifier(this.pathIdQname);
58 protected final NodeIdentifier routePathIdNid() {
59 return this.pathIdNid;
62 protected final QName pathIdQName() {
63 return this.pathIdQname;
66 public final QName routeKeyQName() {
67 return this.routeKeyQname;
71 public final Long extractPathId(final NormalizedNode<?, ?> data) {
72 final Long pathId = PathIdUtil.extractPathId(data, this.routePathIdNid());
74 return PathIdUtil.NON_PATH_ID;
81 public final PathArgument getRouteIdAddPath(final long pathId, final PathArgument routeId) {
82 return PathIdUtil.createNidKey(pathId, routeId, routeQName(), pathIdQName(), routeKeyQName());
86 public final PathArgument createRouteKeyPathArgument(final PathArgument routeKey) {
87 final ImmutableMap<QName, Object> keyValues = ImmutableMap.of(routeKeyQName(),
88 PathIdUtil.getObjectKey(routeKey, routeKeyQName()));
89 return new NodeIdentifierWithPredicates(routeQName(), keyValues);