Provide codec Serializer via RibSupport
[bgpcep.git] / bgp / labeled-unicast / src / main / java / org / opendaylight / protocol / bgp / labeled / unicast / LabeledUnicastIpv4RIBSupport.java
index 1527cfcaabfa90edfac0af816bcfe90c9108b9a4..acc98b595099906be5237175020d0a905bcd6432 100644 (file)
@@ -8,52 +8,68 @@
 package org.opendaylight.protocol.bgp.labeled.unicast;
 
 import java.util.Collection;
+import java.util.Collections;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.LabeledUnicastSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.LabeledUnicastRoutesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.LabeledUnicastRoutes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.LabeledUnicastRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.list.LabeledUnicastRoute;
 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;
 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;
 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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 
-public final class LabeledUnicastIpv4RIBSupport extends AbstractLabeledUnicastRIBSupport {
-    private static final LabeledUnicastIpv4RIBSupport SINGLETON = new LabeledUnicastIpv4RIBSupport();
+public final class LabeledUnicastIpv4RIBSupport
+        extends AbstractLabeledUnicastRIBSupport<LabeledUnicastRoutesCase, LabeledUnicastRoutes> {
+    private static final LabeledUnicastRoutes EMPTY_CONTAINER
+            = new LabeledUnicastRoutesBuilder().setLabeledUnicastRoute(Collections.emptyList()).build();
+    private static final LabeledUnicastRoutesCase EMPTY_CASE
+            = new LabeledUnicastRoutesCaseBuilder().setLabeledUnicastRoutes(EMPTY_CONTAINER).build();
+    private static LabeledUnicastIpv4RIBSupport SINGLETON;
 
-    private LabeledUnicastIpv4RIBSupport() {
-        super(LabeledUnicastRoutesCase.class, LabeledUnicastRoutes.class, LabeledUnicastRoute.class,
-                Ipv4AddressFamily.class, LabeledUnicastSubsequentAddressFamily.class, DestinationLabeledUnicast.QNAME);
+    private LabeledUnicastIpv4RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
+        super(mappingService,
+                LabeledUnicastRoutesCase.class,
+                LabeledUnicastRoutes.class,
+                Ipv4AddressFamily.class,
+                DestinationLabeledUnicast.QNAME);
     }
 
-    static LabeledUnicastIpv4RIBSupport getInstance() {
+    static synchronized LabeledUnicastIpv4RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) {
+        if (SINGLETON == null) {
+            SINGLETON = new LabeledUnicastIpv4RIBSupport(mappingService);
+        }
         return SINGLETON;
     }
 
     @Override
     protected DestinationType buildDestination(final Collection<MapEntryNode> routes) {
         return new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
-                new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(extractRoutes(routes)).build()).build();
+                new DestinationLabeledUnicastBuilder()
+                        .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build();
     }
 
     @Override
     protected DestinationType buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
-        return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
-                new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(
-                        extractRoutes(routes)).build()).build();
+        return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
+                .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
+                .DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1
+                .urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri
+                .withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
+                .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build();
     }
 
     @Override
-    public IpPrefix extractPrefix(final DataContainerNode<? extends PathArgument> route, final NodeIdentifier prefixTypeNid) {
+    public IpPrefix extractPrefix(
+            final DataContainerNode<? extends PathArgument> route,
+            final NodeIdentifier prefixTypeNid) {
         if (route.getChild(prefixTypeNid).isPresent()) {
             final String prefixType = (String) route.getChild(prefixTypeNid).get().getValue();
             return new IpPrefix(new Ipv4Prefix(prefixType));
@@ -62,8 +78,12 @@ public final class LabeledUnicastIpv4RIBSupport extends AbstractLabeledUnicastRI
     }
 
     @Override
-    public Routes emptyRoutesContainer() {
-        return new LabeledUnicastRoutesCaseBuilder()
-                .setLabeledUnicastRoutes(new LabeledUnicastRoutesBuilder().build()).build();
+    public LabeledUnicastRoutesCase emptyRoutesCase() {
+        return EMPTY_CASE;
+    }
+
+    @Override
+    public LabeledUnicastRoutes emptyRoutesContainer() {
+        return EMPTY_CONTAINER;
     }
 }