e47c0a26c2151b0c797b235ba4b2f30c1f132954
[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.rev171207.L3vpnIpv4Destination;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev171207.l3vpn.ipv4.destination.VpnIpv4DestinationBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev171207.l3vpn.ip.destination.type.VpnDestination;
20
21 final class VpnIpv4NlriParser extends AbstractVpnNlriParser {
22
23     private <T extends L3vpnIpv4Destination> List<VpnDestination> getVpnDestination(DestinationType dst, Class<T> dstTypeCaseClazz) {
24         if (dstTypeCaseClazz.isInstance(dst)) {
25             return dstTypeCaseClazz.cast(dst).getVpnIpv4Destination().getVpnDestination();
26         } else {
27             return null;
28         }
29     }
30
31     @Override
32     protected List<VpnDestination> getWithdrawnVpnDestination(DestinationType dstType) {
33         return getVpnDestination(dstType, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv4Case.class);
34     }
35
36     @Override
37     protected List<VpnDestination> getAdvertizedVpnDestination(DestinationType dstType) {
38         return getVpnDestination(dstType, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv4Case.class);
39     }
40
41     @Override
42     protected WithdrawnRoutes getWithdrawnRoutesByDestination(List<VpnDestination> dst) {
43         return new WithdrawnRoutesBuilder().setDestinationType(
44             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination(
45                 new VpnIpv4DestinationBuilder().setVpnDestination(dst).build()
46             ).build()
47         ).build();
48     }
49
50     @Override
51     protected AdvertizedRoutes getAdvertizedRoutesByDestination(List<VpnDestination> dst) {
52         return new AdvertizedRoutesBuilder().setDestinationType(
53             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination(
54                 new VpnIpv4DestinationBuilder().setVpnDestination(dst).build()
55             ).build()
56         ).build();
57     }
58 }