Create common parent for extensions families
[bgpcep.git] / bgp / extensions / l3vpn / src / main / java / org / opendaylight / protocol / bgp / l3vpn / mcast / L3VpnMcastIpv6RIBSupport.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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.l3vpn.mcast;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.Optional;
16 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
17 import org.opendaylight.protocol.bgp.l3vpn.mcast.nlri.L3vpnMcastNlriSerializer;
18 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
19 import org.opendaylight.protocol.util.ByteArray;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.bgp.rib.rib.loc.rib.tables.routes.L3vpnMcastRoutesIpv6Case;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.bgp.rib.rib.loc.rib.tables.routes.L3vpnMcastRoutesIpv6CaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.destination.L3vpnMcastDestination;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.ipv6.L3vpnMcastRoutesIpv6;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.ipv6.L3vpnMcastRoutesIpv6Builder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationL3vpnMcastIpv6AdvertizedCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationL3vpnMcastIpv6AdvertizedCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.l3vpn.mcast.ipv6.advertized._case.DestinationIpv6L3vpnMcast;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.l3vpn.mcast.ipv6.advertized._case.DestinationIpv6L3vpnMcastBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationL3vpnMcastIpv6WithdrawnCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationL3vpnMcastIpv6WithdrawnCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
34 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
35 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
36 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
37 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
38 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
39
40 /**
41  * Ipv6 L3VPN Multicast RIBSupport.
42  *
43  * @author Claudio D. Gasparini
44  */
45 public final class L3VpnMcastIpv6RIBSupport
46         extends AbstractL3vpnMcastIpRIBSupport<L3vpnMcastRoutesIpv6Case, L3vpnMcastRoutesIpv6> {
47     private static final L3vpnMcastRoutesIpv6 EMPTY_CONTAINER
48             = new L3vpnMcastRoutesIpv6Builder().setL3vpnMcastRoute(Collections.emptyList()).build();
49     private static final L3vpnMcastRoutesIpv6Case EMPTY_CASE
50             = new L3vpnMcastRoutesIpv6CaseBuilder().setL3vpnMcastRoutesIpv6(EMPTY_CONTAINER).build();
51     private static L3VpnMcastIpv6RIBSupport SINGLETON;
52
53
54     private L3VpnMcastIpv6RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
55         super(mappingService,
56                 L3vpnMcastRoutesIpv6Case.class,
57                 L3vpnMcastRoutesIpv6.class,
58                 Ipv6AddressFamily.class,
59                 DestinationIpv6L3vpnMcast.QNAME,
60                 L3vpnMcastDestination.QNAME);
61     }
62
63     public static synchronized L3VpnMcastIpv6RIBSupport getInstance(
64             final BindingNormalizedNodeSerializer mappingService) {
65         if (SINGLETON == null) {
66             SINGLETON = new L3VpnMcastIpv6RIBSupport(mappingService);
67         }
68         return SINGLETON;
69     }
70
71
72     @Override
73     protected DestinationL3vpnMcastIpv6AdvertizedCase buildDestination(final Collection<MapEntryNode> routes) {
74         return new DestinationL3vpnMcastIpv6AdvertizedCaseBuilder().setDestinationIpv6L3vpnMcast(
75                 new DestinationIpv6L3vpnMcastBuilder().setL3vpnMcastDestination(extractRoutes(routes)).build()).build();
76     }
77
78     @Override
79     protected DestinationL3vpnMcastIpv6WithdrawnCase buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
80         return new DestinationL3vpnMcastIpv6WithdrawnCaseBuilder().setDestinationIpv6L3vpnMcast(
81                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update
82                         .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.l3vpn.mcast.ipv6
83                         .withdrawn._case.DestinationIpv6L3vpnMcastBuilder()
84                         .setL3vpnMcastDestination(extractRoutes(routes)).build()).build();
85     }
86
87     @Override
88     public L3vpnMcastRoutesIpv6Case emptyRoutesCase() {
89         return EMPTY_CASE;
90     }
91
92     @Override
93     public L3vpnMcastRoutesIpv6 emptyRoutesContainer() {
94         return EMPTY_CONTAINER;
95     }
96
97     @Override
98     protected IpPrefix createPrefix(final String prefix) {
99         return new IpPrefix(new Ipv6Prefix(prefix));
100     }
101
102     @Override
103     public NodeIdentifierWithPredicates createRouteKey(final UnkeyedListEntryNode l3vpn) {
104         final ByteBuf buffer = Unpooled.buffer();
105         final L3vpnMcastDestination dest = extractDestinations(l3vpn);
106         L3vpnMcastNlriSerializer.serializeNlri(Collections.singletonList(dest), buffer);
107         final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
108                 l3vpn.getChild(routePathIdNid());
109         return PathIdUtil.createNidKey(routeQName(), routeKeyQName(),
110                 pathIdQName(), ByteArray.encodeBase64(buffer), maybePathIdLeaf);
111     }
112 }