0da7f548c5a58853e5f16067927ddbe0be274d19
[bgpcep.git] / bgp / l3vpn / src / main / java / org / opendaylight / protocol / bgp / l3vpn / ipv4 / VpnIpv4NlriParser.java
1 /*
2  * Copyright (c) 2016 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.l3vpn.ipv4;
9
10 import java.util.List;
11 import org.opendaylight.protocol.bgp.l3vpn.AbstractVpnNlriParser;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.destination.DestinationType;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutes;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.L3vpnIpv4Destination;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.l3vpn.ipv4.destination.VpnIpv4DestinationBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.destination.type.VpnDestination;
20
21 final class VpnIpv4NlriParser extends AbstractVpnNlriParser {
22
23     private <T extends L3vpnIpv4Destination> List<VpnDestination> getVpnDestination(DestinationType dst,
24             Class<T> dstTypeCaseClazz) {
25         if (dstTypeCaseClazz.isInstance(dst)) {
26             return dstTypeCaseClazz.cast(dst).getVpnIpv4Destination().getVpnDestination();
27         } else {
28             return null;
29         }
30     }
31
32     @Override
33     protected List<VpnDestination> getWithdrawnVpnDestination(DestinationType dstType) {
34         return getVpnDestination(dstType, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4
35                 .rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
36                 .DestinationVpnIpv4Case.class);
37     }
38
39     @Override
40     protected List<VpnDestination> getAdvertizedVpnDestination(DestinationType dstType) {
41         return getVpnDestination(dstType, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4
42                 .rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type
43                 .DestinationVpnIpv4Case.class);
44     }
45
46     @Override
47     protected WithdrawnRoutes getWithdrawnRoutesByDestination(List<VpnDestination> dst) {
48         return new WithdrawnRoutesBuilder().setDestinationType(
49             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.update
50                     .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv4CaseBuilder()
51                     .setVpnIpv4Destination(new VpnIpv4DestinationBuilder()
52                             .setVpnDestination(dst).build()).build()).build();
53     }
54
55     @Override
56     protected AdvertizedRoutes getAdvertizedRoutesByDestination(List<VpnDestination> dst) {
57         return new AdvertizedRoutesBuilder().setDestinationType(
58             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.update
59                     .attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv4CaseBuilder()
60                     .setVpnIpv4Destination(new VpnIpv4DestinationBuilder()
61                             .setVpnDestination(dst).build()).build()).build();
62     }
63 }