Bump MRI upstreams
[neutron.git] / transcriber / src / main / java / org / opendaylight / neutron / transcriber / NeutronBgpvpnInterface.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.neutron.transcriber;
9
10 import com.google.common.collect.ImmutableBiMap;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.List;
14 import javax.inject.Inject;
15 import javax.inject.Singleton;
16 import org.apache.aries.blueprint.annotation.service.Service;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
19 import org.opendaylight.neutron.spi.NeutronBgpvpn;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.BgpvpnTypeBase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.BgpvpnTypeL2;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.BgpvpnTypeL3;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.Bgpvpns;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.Bgpvpn;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.BgpvpnBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.bgpvpns.rev150903.bgpvpns.attributes.bgpvpns.BgpvpnKey;
28 import org.opendaylight.yangtools.yang.common.Uint32;
29
30 @Singleton
31 @Service(classes = INeutronBgpvpnCRUD.class)
32 public final class NeutronBgpvpnInterface extends AbstractNeutronInterface<Bgpvpn, Bgpvpns, BgpvpnKey, NeutronBgpvpn>
33         implements INeutronBgpvpnCRUD {
34
35     private static final ImmutableBiMap<Class<? extends BgpvpnTypeBase>,
36             String> BGPVPN_TYPE_MAP = new ImmutableBiMap.Builder<Class<? extends BgpvpnTypeBase>, String>()
37                     .put(BgpvpnTypeL2.class, "l2").put(BgpvpnTypeL3.class, "l3").build();
38
39     @Inject
40     public NeutronBgpvpnInterface(DataBroker db) {
41         super(BgpvpnBuilder.class, db);
42     }
43
44     @Override
45     protected Collection<Bgpvpn> getDataObjectList(Bgpvpns bgpvpns) {
46         return bgpvpns.nonnullBgpvpn().values();
47     }
48
49     @Override
50     protected NeutronBgpvpn fromMd(Bgpvpn bgpvpn) {
51         final NeutronBgpvpn result = new NeutronBgpvpn();
52         fromMdBaseAttributes(bgpvpn, result);
53         fromMdAdminAttributes(bgpvpn, result);
54         result.setAutoAggregate(bgpvpn.getAutoAggregate());
55         if (bgpvpn.getVni() != null) {
56             result.setVni(bgpvpn.getVni().toJava());
57         }
58         if (bgpvpn.getType() != null) {
59             result.setType(BGPVPN_TYPE_MAP.get(bgpvpn.getType()));
60         }
61         if (bgpvpn.getTechnique() != null) {
62             result.setTechnique(bgpvpn.getTechnique());
63         }
64         if (bgpvpn.getRouteTargets() != null) {
65             final List<String> routeTargets = new ArrayList<>();
66             for (final String routeTarget : bgpvpn.getRouteTargets()) {
67                 routeTargets.add(routeTarget);
68             }
69             result.setRouteTargets(routeTargets);
70         }
71         if (bgpvpn.getImportTargets() != null) {
72             final List<String> importTargets = new ArrayList<>();
73             for (final String importTarget : bgpvpn.getImportTargets()) {
74                 importTargets.add(importTarget);
75             }
76             result.setImportTargets(importTargets);
77         }
78         if (bgpvpn.getExportTargets() != null) {
79             final List<String> exportTargets = new ArrayList<>();
80             for (final String exportTarget : bgpvpn.getExportTargets()) {
81                 exportTargets.add(exportTarget);
82             }
83             result.setExportTargets(exportTargets);
84         }
85         if (bgpvpn.getRouteDistinguishers() != null) {
86             final List<String> routeDistinguishers = new ArrayList<>();
87             for (final String routeDistinguisher : bgpvpn.getRouteDistinguishers()) {
88                 routeDistinguishers.add(routeDistinguisher);
89             }
90             result.setRouteDistinguishers(routeDistinguishers);
91         }
92         if (bgpvpn.getRouters() != null) {
93             final List<String> routers = new ArrayList<>();
94             for (final Uuid router : bgpvpn.getRouters()) {
95                 routers.add(router.getValue());
96             }
97             result.setRouters(routers);
98         }
99         if (bgpvpn.getNetworks() != null) {
100             final List<String> networks = new ArrayList<>();
101             for (final Uuid network : bgpvpn.getNetworks()) {
102                 networks.add(network.getValue());
103             }
104             result.setNetworks(networks);
105         }
106         return result;
107     }
108
109     @Override
110     protected Bgpvpn toMd(NeutronBgpvpn bgpvpn) {
111         final BgpvpnBuilder bgpvpnBuilder = new BgpvpnBuilder();
112
113         toMdBaseAttributes(bgpvpn, bgpvpnBuilder);
114         toMdAdminAttributes(bgpvpn, bgpvpnBuilder);
115         if (bgpvpn.getAutoAggregate() != null) {
116             bgpvpnBuilder.setAutoAggregate(bgpvpn.getAutoAggregate());
117         }
118         if (bgpvpn.getVni() != null) {
119             bgpvpnBuilder.setVni(Uint32.valueOf(bgpvpn.getVni()));
120         }
121         if (bgpvpn.getType() != null) {
122             final ImmutableBiMap<String, Class<? extends BgpvpnTypeBase>> mapper = BGPVPN_TYPE_MAP.inverse();
123             bgpvpnBuilder.setType(mapper.get(bgpvpn.getType()));
124         }
125         if (bgpvpn.getTechnique() != null) {
126             bgpvpnBuilder.setTechnique(bgpvpn.getTechnique());
127         }
128         if (bgpvpn.getRouteTargets() != null) {
129             final List<String> routeTargets = new ArrayList<>();
130             for (final String routeTarget : bgpvpn.getRouteTargets()) {
131                 routeTargets.add(routeTarget);
132             }
133             bgpvpnBuilder.setRouteTargets(routeTargets);
134         }
135         if (bgpvpn.getImportTargets() != null) {
136             final List<String> importTargets = new ArrayList<>();
137             for (final String importTarget : bgpvpn.getImportTargets()) {
138                 importTargets.add(importTarget);
139             }
140             bgpvpnBuilder.setImportTargets(importTargets);
141         }
142         if (bgpvpn.getExportTargets() != null) {
143             final List<String> exportTargets = new ArrayList<>();
144             for (final String exportTarget : bgpvpn.getExportTargets()) {
145                 exportTargets.add(exportTarget);
146             }
147             bgpvpnBuilder.setExportTargets(exportTargets);
148         }
149         if (bgpvpn.getRouteDistinguishers() != null) {
150             final List<String> routeDistinguishers = new ArrayList<>();
151             for (final String routeDistinguisher : bgpvpn.getRouteDistinguishers()) {
152                 routeDistinguishers.add(routeDistinguisher);
153             }
154             bgpvpnBuilder.setRouteDistinguishers(routeDistinguishers);
155         }
156         if (bgpvpn.getRouters() != null) {
157             final List<Uuid> routers = new ArrayList<>();
158             for (final String router : bgpvpn.getRouters()) {
159                 routers.add(toUuid(router));
160             }
161             bgpvpnBuilder.setRouters(routers);
162         }
163         if (bgpvpn.getNetworks() != null) {
164             final List<Uuid> networks = new ArrayList<>();
165             for (final String network : bgpvpn.getNetworks()) {
166                 networks.add(toUuid(network));
167             }
168             bgpvpnBuilder.setNetworks(networks);
169         }
170         return bgpvpnBuilder.build();
171     }
172 }