Rib support refactoring II
[bgpcep.git] / bgp / rib-spi / src / main / java / org / opendaylight / protocol / bgp / rib / spi / MultiPathAbstractRIBSupport.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.rib.spi;
10
11 import javax.annotation.Nonnull;
12 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22
23 /**
24  * Implements common methods for Advertisement of Multiple Paths on ribSupport
25  */
26 public abstract class MultiPathAbstractRIBSupport extends AbstractRIBSupport {
27     private final QName routeKeyQname;
28     private final QName pathIdQname;
29     private final NodeIdentifier pathIdNid;
30
31     /**
32      * Default constructor. Requires the QName of the container augmented under the routes choice
33      * node in instantiations of the rib grouping. It is assumed that this container is defined by
34      * the same model which populates it with route grouping instantiation, and by extension with
35      * the route attributes container.
36      * @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null
37      * @param containerClass Binding class of the container in routes choice, must not be null.
38      * @param listClass Binding class of the route list, nust not be null;
39      * @param addressFamilyClass  address Family Class
40      * @param safiClass  SubsequentAddressFamily
41      * @param routeKeyNaming Route Key name (prefix/ route-key / etc..)
42      * @param destinationQname destination Qname
43      */
44     protected MultiPathAbstractRIBSupport(final Class<? extends Routes> cazeClass, final Class<? extends DataObject> containerClass,
45         final Class<? extends Route> listClass, final Class<? extends AddressFamily> addressFamilyClass,
46         final Class<? extends SubsequentAddressFamily> safiClass, final String routeKeyNaming, final QName destinationQname) {
47         super(cazeClass, containerClass, listClass, addressFamilyClass, safiClass, destinationQname);
48         this.routeKeyQname = QName.create(routeQName(), routeKeyNaming).intern();
49         this.pathIdQname = QName.create(routeQName(), "path-id").intern();
50         this.pathIdNid = new NodeIdentifier(this.pathIdQname);
51     }
52
53     protected final NodeIdentifier routePathIdNid() {
54         return this.pathIdNid;
55     }
56
57     protected QName pathIdQName() {
58         return this.pathIdQname;
59     }
60
61     protected QName routeKeyQName() {
62         return this.routeKeyQname;
63     }
64
65     @Nonnull
66     @Override
67     public final PathArgument getRouteIdAddPath(final long pathId, final PathArgument routeId) {
68         return PathIdUtil.createNidKey(pathId, routeId, routeQName(), pathIdQName(), routeKeyQName());
69     }
70
71     @Override
72     public final Long extractPathId(final NormalizedNode<?, ?> data) {
73         return PathIdUtil.extractPathId(data, this.routePathIdNid());
74     }
75 }