2 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.l3vpn.mcast;
10 import static com.google.common.base.Verify.verify;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import java.util.Collection;
15 import java.util.Collections;
17 import java.util.Optional;
18 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
19 import org.opendaylight.protocol.bgp.l3vpn.mcast.nlri.L3vpnMcastNlriSerializer;
20 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
21 import org.opendaylight.protocol.util.ByteArray;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.bgp.rib.rib.loc.rib.tables.routes.L3vpnMcastRoutesIpv4Case;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.destination.L3vpnMcastDestination;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.L3vpnMcastRoute;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.L3vpnMcastRouteKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.ipv4.L3vpnMcastRoutesIpv4;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.ipv4.L3vpnMcastRoutesIpv4Builder;
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.DestinationL3vpnMcastIpv4AdvertizedCase;
31 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.DestinationL3vpnMcastIpv4AdvertizedCaseBuilder;
32 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.ipv4.advertized._case.DestinationIpv4L3vpnMcast;
33 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.ipv4.advertized._case.DestinationIpv4L3vpnMcastBuilder;
34 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.DestinationL3vpnMcastIpv4WithdrawnCase;
35 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.DestinationL3vpnMcastIpv4WithdrawnCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
38 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
39 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
40 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
41 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
42 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
45 * Ipv4 L3VPN Multicast RIBSupport.
47 * @author Claudio D. Gasparini
49 public final class L3VpnMcastIpv4RIBSupport
50 extends AbstractL3vpnMcastIpRIBSupport<L3vpnMcastRoutesIpv4Case, L3vpnMcastRoutesIpv4> {
51 private static final L3vpnMcastRoutesIpv4 EMPTY_CONTAINER = new L3vpnMcastRoutesIpv4Builder().build();
52 private static L3VpnMcastIpv4RIBSupport SINGLETON;
55 private L3VpnMcastIpv4RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
57 L3vpnMcastRoutesIpv4Case.class,
58 L3vpnMcastRoutesIpv4.class,
59 Ipv4AddressFamily.class,
60 DestinationIpv4L3vpnMcast.QNAME,
61 L3vpnMcastDestination.QNAME);
64 public static synchronized L3VpnMcastIpv4RIBSupport getInstance(
65 final BindingNormalizedNodeSerializer mappingService) {
66 if (SINGLETON == null) {
67 SINGLETON = new L3VpnMcastIpv4RIBSupport(mappingService);
74 protected DestinationL3vpnMcastIpv4AdvertizedCase buildDestination(final Collection<MapEntryNode> routes) {
75 return new DestinationL3vpnMcastIpv4AdvertizedCaseBuilder().setDestinationIpv4L3vpnMcast(
76 new DestinationIpv4L3vpnMcastBuilder().setL3vpnMcastDestination(extractRoutes(routes)).build()).build();
80 protected DestinationL3vpnMcastIpv4WithdrawnCase buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
81 return new DestinationL3vpnMcastIpv4WithdrawnCaseBuilder().setDestinationIpv4L3vpnMcast(
82 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update
83 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.l3vpn.mcast.ipv4
84 .withdrawn._case.DestinationIpv4L3vpnMcastBuilder()
85 .setL3vpnMcastDestination(extractRoutes(routes)).build()).build();
89 public L3vpnMcastRoutesIpv4 emptyRoutesContainer() {
90 return EMPTY_CONTAINER;
94 protected IpPrefix createPrefix(final String prefix) {
95 return new IpPrefix(new Ipv4Prefix(prefix));
99 public NodeIdentifierWithPredicates createRouteKey(final UnkeyedListEntryNode l3vpn) {
100 final ByteBuf buffer = Unpooled.buffer();
101 final L3vpnMcastDestination dest = extractDestinations(l3vpn);
102 L3vpnMcastNlriSerializer.serializeNlri(Collections.singletonList(dest), buffer);
103 final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf =
104 l3vpn.getChild(routePathIdNid());
105 return PathIdUtil.createNidKey(routeQName(), routeKeyTemplate(),
106 ByteArray.encodeBase64(buffer), maybePathIdLeaf);
110 public Map<L3vpnMcastRouteKey, L3vpnMcastRoute> extractAdjRibInRoutes(final Routes routes) {
111 verify(routes instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast
112 .rev180417.bgp.rib.rib.peer.adj.rib.in.tables.routes.L3vpnMcastRoutesIpv4Case, "Unrecognized routes %s",
114 return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417
115 .bgp.rib.rib.peer.adj.rib.in.tables.routes.L3vpnMcastRoutesIpv4Case) routes).getL3vpnMcastRoutesIpv4()
116 .nonnullL3vpnMcastRoute();