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