Cleanup deprecation warnings in bgp/extensions/labeled-unicast
[bgpcep.git] / bgp / extensions / labeled-unicast / src / main / java / org / opendaylight / protocol / bgp / labeled / unicast / LabeledUnicastIpv4RIBSupport.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.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.Ipv4Prefix;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.LabeledUnicastRoutes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.LabeledUnicastRoutesBuilder;
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.DestinationLabeledUnicastCaseBuilder;
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.labeled.unicast._case.DestinationLabeledUnicast;
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.labeled.unicast._case.DestinationLabeledUnicastBuilder;
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.Ipv4AddressFamily;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
30 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
31 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
32
33 public final class LabeledUnicastIpv4RIBSupport
34         extends AbstractLabeledUnicastRIBSupport<LabeledUnicastRoutesCase, LabeledUnicastRoutes> {
35     private static final LabeledUnicastRoutes EMPTY_CONTAINER = new LabeledUnicastRoutesBuilder().build();
36     private static LabeledUnicastIpv4RIBSupport SINGLETON;
37
38     private LabeledUnicastIpv4RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
39         super(mappingService,
40                 LabeledUnicastRoutesCase.class,
41                 LabeledUnicastRoutes.class,
42                 Ipv4AddressFamily.class,
43                 DestinationLabeledUnicast.QNAME);
44     }
45
46     static synchronized LabeledUnicastIpv4RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) {
47         if (SINGLETON == null) {
48             SINGLETON = new LabeledUnicastIpv4RIBSupport(mappingService);
49         }
50         return SINGLETON;
51     }
52
53     @Override
54     protected DestinationType buildDestination(final Collection<MapEntryNode> routes) {
55         return new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
56                 new DestinationLabeledUnicastBuilder()
57                         .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build();
58     }
59
60     @Override
61     protected DestinationType buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
62         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
63                 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
64                 .DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1
65                 .urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri
66                 .withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
67                 .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build();
68     }
69
70     @Override
71     public IpPrefix extractPrefix(
72             final DataContainerNode<? extends PathArgument> route,
73             final NodeIdentifier prefixTypeNid) {
74         if (route.getChild(prefixTypeNid).isPresent()) {
75             final String prefixType = (String) route.getChild(prefixTypeNid).get().getValue();
76             return new IpPrefix(new Ipv4Prefix(prefixType));
77         }
78         return null;
79     }
80
81     @Override
82     public LabeledUnicastRoutes emptyRoutesContainer() {
83         return EMPTY_CONTAINER;
84     }
85
86     @Override
87     public Map<LabeledUnicastRouteKey, LabeledUnicastRoute> extractAdjRibInRoutes(final Routes routes) {
88         verify(routes instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast
89             .rev180329.bgp.rib.rib.peer.adj.rib.in.tables.routes.LabeledUnicastRoutesCase, "Unrecognized routes %s",
90             routes);
91         return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
92                 .bgp.rib.rib.peer.adj.rib.in.tables.routes.LabeledUnicastRoutesCase) routes).getLabeledUnicastRoutes()
93                 .nonnullLabeledUnicastRoute();
94     }
95 }