Clean up RibSupport registration
[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 {@link TablesKey}.
37      *
38      * @param tablesKey Tables key representing table.
39      * @return NodeIdentifierWithPredicates of {@link Tables} for specified AFI, SAFI combination.
40      */
41     public static NodeIdentifierWithPredicates toYangTablesKey(final TablesKey tablesKey) {
42         return toYangKey(Tables.QNAME, tablesKey.getAfi(), tablesKey.getSafi());
43     }
44
45     /**
46      * Creates Yang Instance Identifier path argument from supplied AFI and SAFI.
47      *
48      * @param id   QNAME representing node
49      * @param afi  Class representing AFI
50      * @param safi Class representing SAFI
51      * @return NodeIdentifierWithPredicates of 'id' for specified AFI, SAFI combination.
52      */
53     public static NodeIdentifierWithPredicates toYangKey(final QName id, final AddressFamily afi,
54             final SubsequentAddressFamily safi) {
55         return NodeIdentifierWithPredicates.of(id, AFI_SAFI_TEMPLATE.instantiateWithValues(
56             BindingReflections.getQName(afi), BindingReflections.getQName(safi)));
57     }
58
59     /**
60      * Creates Yang Instance Identifier path argument from supplied {@link TablesKey}.
61      *
62      * @param id QNAME representing node
63      * @param tablesKey  Tables key representing table.
64      * @return NodeIdentifierWithPredicates of 'id' for specified AFI, SAFI combination.
65      */
66     public static NodeIdentifierWithPredicates toYangKey(final QName id, final TablesKey tablesKey) {
67         return toYangKey(id, tablesKey.getAfi(), tablesKey.getSafi());
68     }
69
70     /**
71      * Creates Yang Instance Identifier path argument from supplied {@link TablesKey}.
72      *
73      * @param id QNAME representing node
74      * @param tablesKey  Add PAth Tables key representing table.
75      * @return NodeIdentifierWithPredicates of 'id' for specified AFI, SAFI combination.
76      */
77     public static NodeIdentifierWithPredicates toYangKey(final QName id, final SupportedTablesKey tablesKey) {
78         return toYangPathKey(id, tablesKey.getAfi(), tablesKey.getSafi());
79     }
80
81     /**
82      * Creates Yang Instance Identifier path argument from supplied AFI and SAFI.
83      *
84      * @param id   QNAME representing node
85      * @param afi  Class representing AFI
86      * @param safi Class representing SAFI
87      * @return NodeIdentifierWithPredicates of 'id' for specified AFI, SAFI combination.
88      */
89     public static NodeIdentifierWithPredicates toYangPathKey(final QName id, final AddressFamily afi,
90             final SubsequentAddressFamily safi) {
91         return NodeIdentifierWithPredicates.of(id, ADD_PATH_AFI_SAFI_TEMPLATE.instantiateWithValues(
92             BindingReflections.getQName(afi), BindingReflections.getQName(safi)));
93     }
94 }