2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.neutron.transcriber;
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;
31 @Service(classes = INeutronBgpvpnCRUD.class)
32 public final class NeutronBgpvpnInterface extends AbstractNeutronInterface<Bgpvpn, Bgpvpns, BgpvpnKey, NeutronBgpvpn>
33 implements INeutronBgpvpnCRUD {
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();
40 public NeutronBgpvpnInterface(DataBroker db) {
41 super(BgpvpnBuilder.class, db);
45 protected Collection<Bgpvpn> getDataObjectList(Bgpvpns bgpvpns) {
46 return bgpvpns.nonnullBgpvpn().values();
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());
58 if (bgpvpn.getType() != null) {
59 result.setType(BGPVPN_TYPE_MAP.get(bgpvpn.getType()));
61 if (bgpvpn.getTechnique() != null) {
62 result.setTechnique(bgpvpn.getTechnique());
64 if (bgpvpn.getRouteTargets() != null) {
65 final List<String> routeTargets = new ArrayList<>();
66 for (final String routeTarget : bgpvpn.getRouteTargets()) {
67 routeTargets.add(routeTarget);
69 result.setRouteTargets(routeTargets);
71 if (bgpvpn.getImportTargets() != null) {
72 final List<String> importTargets = new ArrayList<>();
73 for (final String importTarget : bgpvpn.getImportTargets()) {
74 importTargets.add(importTarget);
76 result.setImportTargets(importTargets);
78 if (bgpvpn.getExportTargets() != null) {
79 final List<String> exportTargets = new ArrayList<>();
80 for (final String exportTarget : bgpvpn.getExportTargets()) {
81 exportTargets.add(exportTarget);
83 result.setExportTargets(exportTargets);
85 if (bgpvpn.getRouteDistinguishers() != null) {
86 final List<String> routeDistinguishers = new ArrayList<>();
87 for (final String routeDistinguisher : bgpvpn.getRouteDistinguishers()) {
88 routeDistinguishers.add(routeDistinguisher);
90 result.setRouteDistinguishers(routeDistinguishers);
92 if (bgpvpn.getRouters() != null) {
93 final List<String> routers = new ArrayList<>();
94 for (final Uuid router : bgpvpn.getRouters()) {
95 routers.add(router.getValue());
97 result.setRouters(routers);
99 if (bgpvpn.getNetworks() != null) {
100 final List<String> networks = new ArrayList<>();
101 for (final Uuid network : bgpvpn.getNetworks()) {
102 networks.add(network.getValue());
104 result.setNetworks(networks);
110 protected Bgpvpn toMd(NeutronBgpvpn bgpvpn) {
111 final BgpvpnBuilder bgpvpnBuilder = new BgpvpnBuilder();
113 toMdBaseAttributes(bgpvpn, bgpvpnBuilder);
114 toMdAdminAttributes(bgpvpn, bgpvpnBuilder);
115 if (bgpvpn.getAutoAggregate() != null) {
116 bgpvpnBuilder.setAutoAggregate(bgpvpn.getAutoAggregate());
118 if (bgpvpn.getVni() != null) {
119 bgpvpnBuilder.setVni(Uint32.valueOf(bgpvpn.getVni()));
121 if (bgpvpn.getType() != null) {
122 final ImmutableBiMap<String, Class<? extends BgpvpnTypeBase>> mapper = BGPVPN_TYPE_MAP.inverse();
123 bgpvpnBuilder.setType(mapper.get(bgpvpn.getType()));
125 if (bgpvpn.getTechnique() != null) {
126 bgpvpnBuilder.setTechnique(bgpvpn.getTechnique());
128 if (bgpvpn.getRouteTargets() != null) {
129 final List<String> routeTargets = new ArrayList<>();
130 for (final String routeTarget : bgpvpn.getRouteTargets()) {
131 routeTargets.add(routeTarget);
133 bgpvpnBuilder.setRouteTargets(routeTargets);
135 if (bgpvpn.getImportTargets() != null) {
136 final List<String> importTargets = new ArrayList<>();
137 for (final String importTarget : bgpvpn.getImportTargets()) {
138 importTargets.add(importTarget);
140 bgpvpnBuilder.setImportTargets(importTargets);
142 if (bgpvpn.getExportTargets() != null) {
143 final List<String> exportTargets = new ArrayList<>();
144 for (final String exportTarget : bgpvpn.getExportTargets()) {
145 exportTargets.add(exportTarget);
147 bgpvpnBuilder.setExportTargets(exportTargets);
149 if (bgpvpn.getRouteDistinguishers() != null) {
150 final List<String> routeDistinguishers = new ArrayList<>();
151 for (final String routeDistinguisher : bgpvpn.getRouteDistinguishers()) {
152 routeDistinguishers.add(routeDistinguisher);
154 bgpvpnBuilder.setRouteDistinguishers(routeDistinguishers);
156 if (bgpvpn.getRouters() != null) {
157 final List<Uuid> routers = new ArrayList<>();
158 for (final String router : bgpvpn.getRouters()) {
159 routers.add(toUuid(router));
161 bgpvpnBuilder.setRouters(routers);
163 if (bgpvpn.getNetworks() != null) {
164 final List<Uuid> networks = new ArrayList<>();
165 for (final String network : bgpvpn.getNetworks()) {
166 networks.add(toUuid(network));
168 bgpvpnBuilder.setNetworks(networks);
170 return bgpvpnBuilder.build();