918570eef880fb7e2ddce106e58ab8a04af3fa1f
[bgpcep.git] / bgp / rib-spi / src / main / java / org / opendaylight / protocol / bgp / rib / spi / RibSupportUtils.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.protocol.bgp.rib.spi;
9
10 import com.google.common.collect.ImmutableList;
11 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpAddPathTableType;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.peer.SupportedTablesKey;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily;
18 import org.opendaylight.yangtools.util.ImmutableOffsetMapTemplate;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
21
22 public final class RibSupportUtils {
23     private static final ImmutableOffsetMapTemplate<QName> AFI_SAFI_TEMPLATE =
24             ImmutableOffsetMapTemplate.ordered(ImmutableList.of(QName.create(Tables.QNAME, "afi").intern(),
25                 QName.create(Tables.QNAME, "safi").intern()));
26
27     private static final ImmutableOffsetMapTemplate<QName> ADD_PATH_AFI_SAFI_TEMPLATE =
28             ImmutableOffsetMapTemplate.ordered(ImmutableList.of(QName.create(BgpAddPathTableType.QNAME, "afi").intern(),
29                 QName.create(BgpAddPathTableType.QNAME, "safi").intern()));
30
31     private RibSupportUtils() {
32         // Hidden on purpose
33     }
34
35     /**
36      * Creates Yang Instance Identifier path argument from supplied AFI and SAFI.
37      *
38      * @param afi  Class representing AFI
39      * @param safi Class representing SAFI
40      * @return NodeIdentifierWithPredicates of {@link Tables} for specified AFI, SAFI combination.
41      */
42     public static NodeIdentifierWithPredicates toYangTablesKey(final AddressFamily afi,
43             final SubsequentAddressFamily safi) {
44         return toYangKey(Tables.QNAME, afi, safi);
45     }
46
47     /**
48      * Creates Yang Instance Identifier path argument from supplied AFI and SAFI.
49      *
50      * @param id   QNAME representing node
51      * @param afi  Class representing AFI
52      * @param safi Class representing SAFI
53      * @return NodeIdentifierWithPredicates of 'id' for specified AFI, SAFI combination.
54      */
55     public static NodeIdentifierWithPredicates toYangKey(final QName id, final AddressFamily afi,
56             final SubsequentAddressFamily safi) {
57         return NodeIdentifierWithPredicates.of(id, AFI_SAFI_TEMPLATE.instantiateWithValues(
58             BindingReflections.findQName(afi.implementedInterface()),
59             BindingReflections.findQName(safi.implementedInterface())));
60     }
61
62     /**
63      * Creates Yang Instance Identifier path argument from supplied AFI and SAFI.
64      *
65      * @param id   QNAME representing node
66      * @param afi  Class representing AFI
67      * @param safi Class representing SAFI
68      * @return NodeIdentifierWithPredicates of 'id' for specified AFI, SAFI combination.
69      */
70     public static NodeIdentifierWithPredicates toYangPathKey(final QName id, final AddressFamily afi,
71             final SubsequentAddressFamily safi) {
72         return NodeIdentifierWithPredicates.of(id, ADD_PATH_AFI_SAFI_TEMPLATE.instantiateWithValues(
73             BindingReflections.findQName(afi.implementedInterface()),
74             BindingReflections.findQName(safi.implementedInterface())));
75     }
76
77     /**
78      * Creates Yang Instance Identifier path argument from supplied {@link TablesKey}.
79      *
80      * @param id QNAME representing node
81      * @param tablesKey  Tables key representing table.
82      * @return NodeIdentifierWithPredicates of 'id' for specified AFI, SAFI combination.
83      */
84     @SuppressWarnings("checkstyle:OverloadMethodsDeclarationOrder")
85     public static NodeIdentifierWithPredicates toYangKey(final QName id, final TablesKey tablesKey) {
86         return toYangKey(id, tablesKey.getAfi(), tablesKey.getSafi());
87     }
88
89     /**
90      * Creates Yang Instance Identifier path argument from supplied {@link TablesKey}.
91      *
92      * @param id QNAME representing node
93      * @param tablesKey  Add PAth Tables key representing table.
94      * @return NodeIdentifierWithPredicates of 'id' for specified AFI, SAFI combination.
95      */
96     public static NodeIdentifierWithPredicates toYangKey(final QName id, final SupportedTablesKey tablesKey) {
97         return toYangPathKey(id, tablesKey.getAfi(), tablesKey.getSafi());
98     }
99
100     /**
101      * Creates Yang Instance Identifier path argument from supplied {@link TablesKey}.
102      *
103      * @param tablesKey Tables key representing table.
104      * @return NodeIdentifierWithPredicates of {@link Tables} for specified AFI, SAFI combination.
105      */
106     @SuppressWarnings("checkstyle:OverloadMethodsDeclarationOrder")
107     public static NodeIdentifierWithPredicates toYangTablesKey(final TablesKey tablesKey) {
108         return toYangTablesKey(tablesKey.getAfi(), tablesKey.getSafi());
109     }
110 }