Merge "L3: Add eth to br-ex"
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / translator / iaware / impl / NeutronIAwareUtil.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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
9 package org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.impl;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronPort;
15 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronRouter_Interface;
16 import org.opendaylight.ovsdb.openstack.netvirt.translator.Neutron_IPs;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.router.Interfaces;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
20 import org.osgi.framework.BundleContext;
21 import org.osgi.framework.FrameworkUtil;
22 import org.osgi.framework.ServiceReference;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 public class NeutronIAwareUtil {
27     private static final Logger LOGGER = LoggerFactory
28             .getLogger(NeutronIAwareUtil.class);
29
30     private NeutronIAwareUtil() {
31     }
32
33     public static Object[] getInstances(Class<?> clazz,Object bundle) {
34         Object instances[] = null;
35         try {
36             BundleContext bCtx = FrameworkUtil.getBundle(bundle.getClass())
37                     .getBundleContext();
38
39             ServiceReference<?>[] services = null;
40                 services = bCtx.getServiceReferences(clazz.getName(),
41                         null);
42             if (services != null) {
43                 instances = new Object[services.length];
44                 for (int i = 0; i < services.length; i++) {
45                     instances[i] = bCtx.getService(services[i]);
46                 }
47             }
48         } catch (Exception e) {
49             LOGGER.error("Instance reference is NULL", e);
50         }
51         return instances;
52     }
53
54     public static List<Neutron_IPs> convertMDSalIpToNeutronIp(List<FixedIps> fixedIps) {
55         List<Neutron_IPs> ips = null;
56         if (fixedIps != null) {
57             ips = new ArrayList<Neutron_IPs>();
58             for (FixedIps mdIP : fixedIps) {
59                 Neutron_IPs ip = new Neutron_IPs();
60                 ip.setIpAddress(String.valueOf(mdIP.getIpAddress().getValue()));
61                 ip.setSubnetUUID(mdIP.getSubnetId().getValue());
62                 ips.add(ip);
63             }
64         }
65         return ips;
66     }
67
68     public static NeutronRouter_Interface convertMDSalInterfaceToNeutronRouterInterface(
69             Port routerInterface) {
70         NeutronRouter_Interface neutronInterface = new NeutronRouter_Interface();
71         String id = String.valueOf(routerInterface.getUuid().getValue());
72         neutronInterface.setID(id);
73         neutronInterface.setTenantID(routerInterface.getTenantId().getValue());
74         neutronInterface.setSubnetUUID(routerInterface.getFixedIps().get(0).getSubnetId().getValue());
75         neutronInterface.setPortUUID(routerInterface.getUuid().getValue());
76         return neutronInterface;
77     }
78
79
80
81 }