BGPCEP-574: Remove unnesary methods
[bgpcep.git] / bgp / inet / src / main / java / org / opendaylight / protocol / bgp / inet / IPv6RIBSupport.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  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 package org.opendaylight.protocol.bgp.inet;
9
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import java.util.List;
13 import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.bgp.rib.rib.loc.rib.tables.routes.Ipv6RoutesCase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.prefixes.DestinationIpv6;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.prefixes.DestinationIpv6Builder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.prefixes.destination.ipv6.Ipv6Prefixes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.routes.Ipv6Routes;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.routes.ipv6.routes.Ipv6Route;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.routes.ipv6.routes.Ipv6RouteBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv6.routes.ipv6.routes.Ipv6RouteKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6CaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.PathId;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.destination.DestinationType;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
29 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
30 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
31
32 /**
33  * Class supporting IPv6 unicast RIBs.
34  */
35 final class IPv6RIBSupport extends AbstractIPRibSupport<Ipv6Route, Ipv6RouteKey> {
36
37     private static final IPv6RIBSupport SINGLETON = new IPv6RIBSupport();
38
39     private IPv6RIBSupport() {
40         super(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.Ipv6Prefix.class,
41                 Ipv6AddressFamily.class, Ipv6RoutesCase.class, Ipv6Routes.class, Ipv6Route.class,
42                 DestinationIpv6.QNAME, Ipv6Prefixes.QNAME);
43     }
44
45     static IPv6RIBSupport getInstance() {
46         return SINGLETON;
47     }
48
49     @Override
50     protected DestinationType buildDestination(final Collection<MapEntryNode> routes) {
51         return new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder()
52                 .setIpv6Prefixes(extractPrefixes(routes)).build()).build();
53     }
54
55     @Override
56     protected DestinationType buildWithdrawnDestination(final Collection<MapEntryNode> routes) {
57         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.update
58                 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder()
59                 .setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(extractPrefixes(routes))
60                         .build()).build();
61     }
62
63     private List<Ipv6Prefixes> extractPrefixes(final Collection<MapEntryNode> routes) {
64         final List<Ipv6Prefixes> prefs = new ArrayList<>(routes.size());
65         for (final MapEntryNode route : routes) {
66             final String prefix = (String) NormalizedNodes.findNode(route, routePrefixIdentifier()).get().getValue();
67             prefs.add(new Ipv6PrefixesBuilder().setPathId(PathIdUtil.buildPathId(route, routePathIdNid()))
68                     .setPrefix(new Ipv6Prefix(prefix)).build());
69         }
70         return prefs;
71     }
72
73     @Override
74     public Ipv6Route createRoute(final Ipv6Route route, final Ipv6RouteKey routeKey, final PathId pathId,
75             final Attributes attributes) {
76         final Ipv6RouteBuilder builder;
77         if (route != null) {
78             builder = new Ipv6RouteBuilder(route);
79         } else {
80             builder = new Ipv6RouteBuilder();
81         }
82         return builder.setPrefix(routeKey.getPrefix()).setPathId(pathId).setAttributes(attributes).build();
83     }
84
85     @Override
86     public Ipv6RouteKey createNewRouteKey(final PathId pathId, final Ipv6RouteKey routeKey) {
87         return new Ipv6RouteKey(pathId, routeKey.getPrefix());
88     }
89 }