2 * Copyright (c) 2015 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.inet;
10 import static com.google.common.base.Verify.verify;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.List;
16 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
17 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv6RoutesCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.DestinationIpv6;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.DestinationIpv6Builder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.destination.ipv6.Ipv6Prefixes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.Ipv6Routes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.Ipv6RoutesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.ipv6.routes.Ipv6Route;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.ipv6.routes.Ipv6RouteBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.ipv6.routes.Ipv6RouteKey;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6CaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
35 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
36 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
39 * Class supporting IPv6 unicast RIBs.
41 final class IPv6RIBSupport extends AbstractIPRibSupport<Ipv6RoutesCase, Ipv6Routes, Ipv6Route, Ipv6RouteKey> {
43 private static final Ipv6Routes EMPTY_CONTAINER
44 = new Ipv6RoutesBuilder().setIpv6Route(Collections.emptyList()).build();
45 private static IPv6RIBSupport SINGLETON;
47 private IPv6RIBSupport(final BindingNormalizedNodeSerializer mappingService) {
49 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.Ipv6Prefix.class,
50 Ipv6AddressFamily.class,
54 DestinationIpv6.QNAME,
58 static synchronized IPv6RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) {
59 if (SINGLETON == null) {
60 SINGLETON = new IPv6RIBSupport(mappingService);
66 protected DestinationType buildDestination(final Collection<MapEntryNode> routes) {
67 return new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder()
68 .setIpv6Prefixes(extractPrefixes(routes)).build()).build();
72 protected DestinationType buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
73 return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update
74 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder()
75 .setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(extractPrefixes(routes))
79 private List<Ipv6Prefixes> extractPrefixes(final Collection<MapEntryNode> routes) {
80 final List<Ipv6Prefixes> prefs = new ArrayList<>(routes.size());
81 for (final MapEntryNode route : routes) {
82 final String prefix = (String) NormalizedNodes.findNode(route, routePrefixIdentifier()).get().getValue();
83 prefs.add(new Ipv6PrefixesBuilder().setPathId(PathIdUtil.buildPathId(route, routePathIdNid()))
84 .setPrefix(new Ipv6Prefix(prefix)).build());
90 public Ipv6Route createRoute(final Ipv6Route route, final Ipv6RouteKey key, final Attributes attributes) {
91 final Ipv6RouteBuilder builder;
93 builder = new Ipv6RouteBuilder(route);
95 builder = new Ipv6RouteBuilder();
97 return builder.withKey(key).setAttributes(attributes).build();
101 public Ipv6Routes emptyRoutesContainer() {
102 return EMPTY_CONTAINER;
106 public Ipv6RouteKey createRouteListKey(final PathId pathId, final String routeKey) {
107 return new Ipv6RouteKey(pathId, routeKey);
111 public PathId extractPathId(final Ipv6RouteKey routeListKey) {
112 return routeListKey.getPathId();
116 public String extractRouteKey(final Ipv6RouteKey routeListKey) {
117 return routeListKey.getRouteKey();
121 public List<Ipv6Route> extractAdjRibInRoutes(final Routes routes) {
122 verify(routes instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329
123 .bgp.rib.rib.peer.adj.rib.in.tables.routes.Ipv6RoutesCase, "Unrecognized routes %s", routes);
124 return ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.peer
125 .adj.rib.in.tables.routes.Ipv6RoutesCase) routes).getIpv6Routes().nonnullIpv6Route();