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;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.neutron.spi.INeutronL2gatewayCRUD;
15 import org.opendaylight.neutron.spi.NeutronL2gateway;
16 import org.opendaylight.neutron.spi.NeutronL2gatewayDevice;
17 import org.opendaylight.neutron.spi.NeutronL2gatewayDeviceInterface;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.DevicesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.InterfacesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gatewayBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gatewayKey;
27 public final class NeutronL2gatewayInterface
28 extends AbstractNeutronInterface<L2gateway, L2gateways, L2gatewayKey, NeutronL2gateway>
29 implements INeutronL2gatewayCRUD {
30 NeutronL2gatewayInterface(DataBroker db) {
31 super(L2gatewayBuilder.class, db);
35 protected List<L2gateway> getDataObjectList(L2gateways l2gateways) {
36 return l2gateways.getL2gateway();
40 protected NeutronL2gateway fromMd(L2gateway l2gateway) {
41 final NeutronL2gateway result = new NeutronL2gateway();
42 final List<NeutronL2gatewayDevice> neutronL2gatewayDevices = new ArrayList<NeutronL2gatewayDevice>();
44 if (l2gateway.getUuid() != null) {
45 result.setID(l2gateway.getUuid().getValue());
47 if (l2gateway.getL2gatewayName() != null) {
48 result.setName(String.valueOf(l2gateway.getL2gatewayName()));
50 if (l2gateway.getTenantId() != null) {
51 result.setTenantID(l2gateway.getTenantId());
53 if (l2gateway.getDevices() != null) {
54 for (final Devices device : l2gateway.getDevices()) {
55 final NeutronL2gatewayDevice neutronL2gatewayDevice = new NeutronL2gatewayDevice();
56 final List<NeutronL2gatewayDeviceInterface> neutronL2gatewayDeviceInterfaces = new ArrayList<
57 NeutronL2gatewayDeviceInterface>();
58 if (device.getDeviceName() != null) {
59 neutronL2gatewayDevice.setDeviceName(device.getDeviceName().toString());
61 if (device.getUuid() != null) {
62 neutronL2gatewayDevice.setID(device.getUuid().getValue());
64 if (device.getInterfaces() != null) {
65 for (final Interfaces deviceInterface : device.getInterfaces()) {
66 final NeutronL2gatewayDeviceInterface neutronL2gatewayDeviceInterface =
67 new NeutronL2gatewayDeviceInterface();
68 String interfaceName = null;
69 final List<Integer> segmentationIds = new ArrayList<Integer>();
70 if (deviceInterface.getInterfaceName() != null) {
71 interfaceName = deviceInterface.getInterfaceName().toString();
73 if (deviceInterface.getSegmentationIds() != null) {
74 for (final Integer segmentId : deviceInterface.getSegmentationIds()) {
75 segmentationIds.add(segmentId);
77 neutronL2gatewayDeviceInterface.setSegmentationId(segmentationIds);
79 neutronL2gatewayDeviceInterface.setInterfaceName(interfaceName);
80 neutronL2gatewayDeviceInterfaces.add(neutronL2gatewayDeviceInterface);
83 neutronL2gatewayDevice.setNeutronL2gatewayDeviceInterfaces(neutronL2gatewayDeviceInterfaces);
84 neutronL2gatewayDevices.add(neutronL2gatewayDevice);
87 result.setNeutronL2gatewayDevices(neutronL2gatewayDevices);
92 protected L2gateway toMd(NeutronL2gateway neutronObject) {
93 final L2gatewayBuilder l2gatewayBuilder = new L2gatewayBuilder();
94 if (neutronObject.getName() != null) {
95 l2gatewayBuilder.setL2gatewayName(neutronObject.getName());
97 if (neutronObject.getID() != null) {
98 l2gatewayBuilder.setUuid(toUuid(neutronObject.getID()));
100 if (neutronObject.getTenantID() != null) {
101 l2gatewayBuilder.setTenantId(toUuid(neutronObject.getTenantID()));
104 if (neutronObject.getNeutronL2gatewayDevices() != null) {
105 final List<Devices> devices = new ArrayList<>();
106 for (final NeutronL2gatewayDevice neutronL2gatewayDevice : neutronObject.getNeutronL2gatewayDevices()) {
107 final DevicesBuilder deviceBuilder = new DevicesBuilder();
108 final List<Interfaces> interfaces = new ArrayList<Interfaces>();
109 for (final NeutronL2gatewayDeviceInterface neutronL2gatewayDeviceInterface : neutronL2gatewayDevice
110 .getNeutronL2gatewayDeviceInterfaces()) {
111 final InterfacesBuilder interfacesBuilder = new InterfacesBuilder();
112 final List<Integer> segmentIds = new ArrayList<Integer>();
113 interfacesBuilder.setInterfaceName(neutronL2gatewayDeviceInterface.getInterfaceName());
114 if (neutronL2gatewayDeviceInterface.getSegmentationId() != null) {
115 for (final Integer segmentationId : neutronL2gatewayDeviceInterface.getSegmentationId()) {
116 segmentIds.add(segmentationId);
118 interfacesBuilder.setSegmentationIds(segmentIds);
120 interfaces.add(interfacesBuilder.build());
122 deviceBuilder.setDeviceName(neutronL2gatewayDevice.getDeviceName());
123 deviceBuilder.setUuid(toUuid(neutronL2gatewayDevice.getID()));
124 deviceBuilder.setInterfaces(interfaces);
125 devices.add(deviceBuilder.build());
127 l2gatewayBuilder.setDevices(devices);
129 return l2gatewayBuilder.build();