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