2 * Copyright (c) 2015 Hewlett-Packard Development Company, L.P. 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
9 package org.opendaylight.neutron.transcriber;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.neutron.spi.INeutronL2gatewayCRUD;
18 import org.opendaylight.neutron.spi.NeutronL2gatewayDevice;
19 import org.opendaylight.neutron.spi.NeutronL2gatewayDeviceInterface;
20 import org.opendaylight.neutron.spi.NeutronL2gateway;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.DevicesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.InterfacesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gatewayBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 public class NeutronL2gatewayInterface extends
32 AbstractNeutronInterface<L2gateway, L2gateways, NeutronL2gateway>
33 implements INeutronL2gatewayCRUD {
34 private static final Logger LOGGER = LoggerFactory.getLogger(NeutronL2gatewayInterface.class);
36 NeutronL2gatewayInterface(DataBroker db) {
41 protected List<L2gateway> getDataObjectList(L2gateways l2gateways) {
42 return l2gateways.getL2gateway();
46 public boolean inUse(String l2gatewayID) {
47 return !exists(l2gatewayID);
51 protected InstanceIdentifier<L2gateway>
52 createInstanceIdentifier(L2gateway l2gateway) {
53 return InstanceIdentifier.create(Neutron.class).child(L2gateways.class)
54 .child(L2gateway.class,l2gateway.getKey());
58 protected InstanceIdentifier<L2gateways> createInstanceIdentifier() {
59 return InstanceIdentifier.create(Neutron.class).child(L2gateways.class);
63 protected NeutronL2gateway fromMd(L2gateway l2gateway){
64 final NeutronL2gateway result = new NeutronL2gateway();
65 final List<NeutronL2gatewayDevice> neutronL2gatewayDevices = new ArrayList<NeutronL2gatewayDevice>();
67 if (l2gateway.getUuid() != null){
68 result.setID(l2gateway.getUuid().getValue());
70 if (l2gateway.getUuid() != null){
71 result.setID(l2gateway.getUuid().getValue());
73 if (l2gateway.getL2gatewayName() != null){
74 result.setL2gatewayName(String.valueOf(l2gateway.getL2gatewayName()));
76 if (l2gateway.getTenantId() != null){
77 result.setTenantID(l2gateway.getTenantId());
79 if (l2gateway.getDevices() != null){
80 for (final Devices device:l2gateway.getDevices()){
81 final NeutronL2gatewayDevice neutronL2gatewayDevice = new NeutronL2gatewayDevice();
82 final List<NeutronL2gatewayDeviceInterface> neutronL2gatewayDeviceInterfaces =
83 new ArrayList<NeutronL2gatewayDeviceInterface>();
84 if (device.getDeviceName() != null){
85 neutronL2gatewayDevice.setDeviceName(device.getDeviceName().toString());
87 if (device.getUuid() != null) {
88 neutronL2gatewayDevice.setID(device.getUuid().getValue());
90 if(device.getInterfaces() != null){
91 for(final Interfaces deviceInterface:device.getInterfaces()){
92 final NeutronL2gatewayDeviceInterface neutronL2gatewayDeviceInterface =
93 new NeutronL2gatewayDeviceInterface();
94 String interfaceName = null;
95 final List<Integer> segmentationIds = new ArrayList<Integer>();
96 if (deviceInterface.getInterfaceName() != null){
97 interfaceName = deviceInterface
98 .getInterfaceName().toString();
100 if (deviceInterface.getSegmentationIds() != null){
101 for(final Integer segmentId:deviceInterface.getSegmentationIds()){
102 segmentationIds.add(segmentId);
104 neutronL2gatewayDeviceInterface.setSegmentationId(segmentationIds);
106 neutronL2gatewayDeviceInterface.setInterfaceName(interfaceName);
107 neutronL2gatewayDeviceInterfaces.add(neutronL2gatewayDeviceInterface);
110 neutronL2gatewayDevice.setNeutronL2gatewayDeviceInterfaces(neutronL2gatewayDeviceInterfaces);
111 neutronL2gatewayDevices.add(neutronL2gatewayDevice);
114 result.setNeutronL2gatewayDevices(neutronL2gatewayDevices);
119 protected L2gateway toMd(NeutronL2gateway neutronObject) {
120 final L2gatewayBuilder l2gatewayBuilder = new L2gatewayBuilder();
121 if (neutronObject.getL2gatewayName() != null){
122 l2gatewayBuilder.setL2gatewayName(neutronObject.getL2gatewayName());
124 if (neutronObject.getID() != null){
125 l2gatewayBuilder.setUuid(toUuid(neutronObject.getID()));
127 if (neutronObject.getTenantID() != null){
128 l2gatewayBuilder.setTenantId(toUuid(neutronObject.getTenantID()));
131 if (neutronObject.getNeutronL2gatewayDevices() != null){
132 final List<Devices> devices = new ArrayList<>();
133 for(final NeutronL2gatewayDevice neutronL2gatewayDevice:neutronObject.getNeutronL2gatewayDevices()){
134 final DevicesBuilder deviceBuilder = new DevicesBuilder();
135 final List<Interfaces> interfaces = new ArrayList<Interfaces>();
136 for(final NeutronL2gatewayDeviceInterface neutronL2gatewayDeviceInterface:neutronL2gatewayDevice
137 .getNeutronL2gatewayDeviceInterfaces()){
138 final InterfacesBuilder interfacesBuilder = new InterfacesBuilder();
139 final List<Integer> segmentIds = new ArrayList<Integer>();
140 interfacesBuilder.setInterfaceName(neutronL2gatewayDeviceInterface.getInterfaceName());
141 if (neutronL2gatewayDeviceInterface.getSegmentationId() != null){
142 for(final Integer segmentationId:neutronL2gatewayDeviceInterface
143 .getSegmentationId()){
144 segmentIds.add(segmentationId);
146 interfacesBuilder.setSegmentationIds(segmentIds);
148 interfaces.add(interfacesBuilder.build());
150 deviceBuilder.setDeviceName(neutronL2gatewayDevice.getDeviceName());
151 deviceBuilder.setUuid(toUuid(neutronL2gatewayDevice.getID()));
152 deviceBuilder.setInterfaces(interfaces);
153 devices.add(deviceBuilder.build());
155 l2gatewayBuilder.setDevices(devices);
157 return l2gatewayBuilder.build();
161 protected L2gateway toMd(String uuid) {
162 final L2gatewayBuilder l2gatewayBuilder = new L2gatewayBuilder();
163 l2gatewayBuilder.setUuid(toUuid(uuid));
164 return l2gatewayBuilder.build();