2 * Copyright (c) 2016 Cisco Systems, Inc. and others. 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.labeled.unicast;
10 import static com.google.common.base.Verify.verify;
12 import java.util.Collection;
13 import java.util.Collections;
14 import java.util.List;
15 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastIpv6RoutesCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.ipv6.routes.LabeledUnicastIpv6Routes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.ipv6.routes.LabeledUnicastIpv6RoutesBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.list.LabeledUnicastRoute;
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.DestinationIpv6LabeledUnicastCaseBuilder;
23 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;
24 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;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
32 final class LabeledUnicastIpv6RIBSupport
33 extends AbstractLabeledUnicastRIBSupport<LabeledUnicastIpv6RoutesCase, LabeledUnicastIpv6Routes> {
35 private static final LabeledUnicastIpv6Routes EMPTY_CONTAINER
36 = new LabeledUnicastIpv6RoutesBuilder().setLabeledUnicastRoute(Collections.emptyList()).build();
37 private static LabeledUnicastIpv6RIBSupport SINGLETON;
39 private LabeledUnicastIpv6RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
41 LabeledUnicastIpv6RoutesCase.class,
42 LabeledUnicastIpv6Routes.class,
43 Ipv6AddressFamily.class,
44 DestinationIpv6LabeledUnicast.QNAME);
47 static synchronized LabeledUnicastIpv6RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) {
48 if (SINGLETON == null) {
49 SINGLETON = new LabeledUnicastIpv6RIBSupport(mappingService);
55 protected DestinationType buildDestination(final Collection<MapEntryNode> routes) {
56 return new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
57 new DestinationIpv6LabeledUnicastBuilder()
58 .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build();
62 protected DestinationType buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
63 return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
64 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
65 .DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
66 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
67 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6
68 .labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
69 .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build();
73 protected IpPrefix extractPrefix(final DataContainerNode<? extends YangInstanceIdentifier.PathArgument> route,
74 final YangInstanceIdentifier.NodeIdentifier prefixTypeNid) {
75 if (route.getChild(prefixTypeNid).isPresent()) {
76 final String prefixType = (String) route.getChild(prefixTypeNid).get().getValue();
77 return new IpPrefix(new Ipv6Prefix(prefixType));
83 public LabeledUnicastIpv6Routes emptyRoutesContainer() {
84 return EMPTY_CONTAINER;
88 public List<LabeledUnicastRoute> extractAdjRibInRoutes(final Routes routes) {
89 verify(routes instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast
90 .rev180329.bgp.rib.rib.peer.adj.rib.in.tables.routes.LabeledUnicastIpv6RoutesCase, "Unrecognized routes %s",
92 return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
93 .bgp.rib.rib.peer.adj.rib.in.tables.routes.LabeledUnicastIpv6RoutesCase) routes)
94 .getLabeledUnicastIpv6Routes().nonnullLabeledUnicastRoute();