Cleanup deprecation warnings in bgp/extensions/labeled-unicast
[bgpcep.git] / bgp / extensions / labeled-unicast / src / main / java / org / opendaylight / protocol / bgp / labeled / unicast / LabeledUnicastIpv6RIBSupport.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 package org.opendaylight.protocol.bgp.labeled.unicast;
9
10 import static com.google.common.base.Verify.verify;
11
12 import java.util.Collection;
13 import java.util.Map;
14 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastIpv6RoutesCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.ipv6.routes.LabeledUnicastIpv6Routes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.ipv6.routes.LabeledUnicastIpv6RoutesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.list.LabeledUnicastRoute;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.list.LabeledUnicastRouteKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicast;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
31
32 final class LabeledUnicastIpv6RIBSupport
33         extends AbstractLabeledUnicastRIBSupport<LabeledUnicastIpv6RoutesCase, LabeledUnicastIpv6Routes> {
34     private static final LabeledUnicastIpv6Routes EMPTY_CONTAINER = new LabeledUnicastIpv6RoutesBuilder().build();
35     private static LabeledUnicastIpv6RIBSupport SINGLETON;
36
37     private LabeledUnicastIpv6RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
38         super(mappingService,
39                 LabeledUnicastIpv6RoutesCase.class,
40                 LabeledUnicastIpv6Routes.class,
41                 Ipv6AddressFamily.class,
42                 DestinationIpv6LabeledUnicast.QNAME);
43     }
44
45     static synchronized LabeledUnicastIpv6RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) {
46         if (SINGLETON == null) {
47             SINGLETON = new LabeledUnicastIpv6RIBSupport(mappingService);
48         }
49         return SINGLETON;
50     }
51
52     @Override
53     protected DestinationType buildDestination(final Collection<MapEntryNode> routes) {
54         return new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
55                 new DestinationIpv6LabeledUnicastBuilder()
56                         .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build();
57     }
58
59     @Override
60     protected DestinationType buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
61         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
62                 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
63                 .DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
64                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
65                         .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6
66                         .labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
67                         .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build();
68     }
69
70     @Override
71     protected IpPrefix extractPrefix(final DataContainerNode<? extends YangInstanceIdentifier.PathArgument> route,
72             final YangInstanceIdentifier.NodeIdentifier prefixTypeNid) {
73         if (route.getChild(prefixTypeNid).isPresent()) {
74             final String prefixType = (String) route.getChild(prefixTypeNid).get().getValue();
75             return new IpPrefix(new Ipv6Prefix(prefixType));
76         }
77         return null;
78     }
79
80     @Override
81     public LabeledUnicastIpv6Routes emptyRoutesContainer() {
82         return EMPTY_CONTAINER;
83     }
84
85     @Override
86     public Map<LabeledUnicastRouteKey, LabeledUnicastRoute> extractAdjRibInRoutes(final Routes routes) {
87         verify(routes instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast
88             .rev180329.bgp.rib.rib.peer.adj.rib.in.tables.routes.LabeledUnicastIpv6RoutesCase, "Unrecognized routes %s",
89             routes);
90         return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
91                 .bgp.rib.rib.peer.adj.rib.in.tables.routes.LabeledUnicastIpv6RoutesCase) routes)
92                 .getLabeledUnicastIpv6Routes().nonnullLabeledUnicastRoute();
93     }
94 }