BGPCEP-754: Rework EffectiveRibInWriter
[bgpcep.git] / bgp / l3vpn / src / main / java / org / opendaylight / protocol / bgp / l3vpn / ipv6 / VpnIpv6RIBSupport.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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.l3vpn.ipv6;
9
10 import java.util.Collection;
11 import java.util.Collections;
12 import java.util.List;
13 import org.opendaylight.protocol.bgp.l3vpn.AbstractVpnRIBSupport;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.destination.DestinationType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev171207.bgp.rib.rib.loc.rib.tables.routes.VpnIpv6RoutesCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev171207.l3vpn.ipv6.destination.VpnIpv6Destination;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev171207.l3vpn.ipv6.destination.VpnIpv6DestinationBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev171207.l3vpn.ipv6.routes.VpnIpv6Routes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev171207.l3vpn.ip.destination.type.VpnDestination;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev171207.l3vpn.ip.route.VpnRoute;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
26
27 final class VpnIpv6RIBSupport extends AbstractVpnRIBSupport<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
28         .ns.yang.bgp.vpn.ipv6.rev171207.bgp.rib.rib.peer.adj.rib.in.tables.routes.VpnIpv6RoutesCase> {
29
30     /**
31      * Default constructor. Requires the QName of the container augmented under the routes choice
32      * node in instantiations of the rib grouping. It is assumed that this container is defined by
33      * the same model which populates it with route grouping instantiation, and by extension with
34      * the route attributes container.
35      */
36     VpnIpv6RIBSupport() {
37         super(VpnIpv6RoutesCase.class, VpnIpv6Routes.class, VpnRoute.class,
38                 Ipv6AddressFamily.class, VpnIpv6Destination.QNAME);
39     }
40
41     @Override
42     protected IpPrefix extractPrefix(final DataContainerNode<? extends YangInstanceIdentifier.PathArgument> route,
43             final YangInstanceIdentifier.NodeIdentifier prefixTypeNid) {
44         if (route.getChild(prefixTypeNid).isPresent()) {
45             final String prefixType = (String) route.getChild(prefixTypeNid).get().getValue();
46             return new IpPrefix(new Ipv6Prefix(prefixType));
47         }
48         return null;
49     }
50
51     @Override
52     protected DestinationType getAdvertisedDestinationType(List<VpnDestination> dests) {
53         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev171207.update
54                 .attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv6CaseBuilder()
55                 .setVpnIpv6Destination(new VpnIpv6DestinationBuilder().setVpnDestination(dests).build()).build();
56     }
57
58     @Override
59     protected DestinationType getWithdrawnDestinationType(List<VpnDestination> dests) {
60         return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev171207.update
61                 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv6CaseBuilder()
62                 .setVpnIpv6Destination(new VpnIpv6DestinationBuilder().setVpnDestination(dests).build()).build();
63     }
64
65     @Override
66     public Collection<VpnRoute> changedRoutes(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
67             .bgp.vpn.ipv6.rev171207.bgp.rib.rib.peer.adj.rib.in.tables.routes.VpnIpv6RoutesCase routes) {
68         final VpnIpv6Routes routeCont =  routes.getVpnIpv6Routes();
69         if (routeCont == null) {
70             return Collections.emptyList();
71         }
72         return routeCont.getVpnRoute();
73     }
74 }