Code clean up
[bgpcep.git] / bgp / 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 java.util.Collection;
11 import java.util.Collections;
12 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCaseBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.LabeledUnicastRoutes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.LabeledUnicastRoutesBuilder;
19 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;
20 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;
21 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;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
26 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
28
29 public final class LabeledUnicastIpv4RIBSupport
30         extends AbstractLabeledUnicastRIBSupport<LabeledUnicastRoutesCase, LabeledUnicastRoutes> {
31     private static final LabeledUnicastRoutes EMPTY_CONTAINER
32             = new LabeledUnicastRoutesBuilder().setLabeledUnicastRoute(Collections.emptyList()).build();
33     private static final LabeledUnicastRoutesCase EMPTY_CASE
34             = new LabeledUnicastRoutesCaseBuilder().setLabeledUnicastRoutes(EMPTY_CONTAINER).build();
35     private static LabeledUnicastIpv4RIBSupport SINGLETON;
36
37     private LabeledUnicastIpv4RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
38         super(mappingService,
39                 LabeledUnicastRoutesCase.class,
40                 LabeledUnicastRoutes.class,
41                 Ipv4AddressFamily.class,
42                 DestinationLabeledUnicast.QNAME);
43     }
44
45     static synchronized LabeledUnicastIpv4RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) {
46         if (SINGLETON == null) {
47             SINGLETON = new LabeledUnicastIpv4RIBSupport(mappingService);
48         }
49         return SINGLETON;
50     }
51
52     @Override
53     protected DestinationType buildDestination(final Collection<MapEntryNode> routes) {
54         return new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
55                 new DestinationLabeledUnicastBuilder()
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                 .DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1
64                 .urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri
65                 .withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
66                 .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build();
67     }
68
69     @Override
70     public IpPrefix extractPrefix(
71             final DataContainerNode<? extends PathArgument> route,
72             final NodeIdentifier prefixTypeNid) {
73         if (route.getChild(prefixTypeNid).isPresent()) {
74             final String prefixType = (String) route.getChild(prefixTypeNid).get().getValue();
75             return new IpPrefix(new Ipv4Prefix(prefixType));
76         }
77         return null;
78     }
79
80     @Override
81     public LabeledUnicastRoutesCase emptyRoutesCase() {
82         return EMPTY_CASE;
83     }
84
85     @Override
86     public LabeledUnicastRoutes emptyRoutesContainer() {
87         return EMPTY_CONTAINER;
88     }
89 }