2 * Copyright (c) 2015 Cisco Systems, Inc. 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.groupbasedpolicy.neutron.mapper;
11 import static com.google.common.base.Preconditions.checkNotNull;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
18 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronFloatingIpAware;
19 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronNetworkAware;
20 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronPortAware;
21 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronRouterAware;
22 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronSecurityGroupAware;
23 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronSecurityRuleAware;
24 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronSubnetAware;
25 import org.opendaylight.neutron.spi.INeutronFloatingIPAware;
26 import org.opendaylight.neutron.spi.INeutronNetworkAware;
27 import org.opendaylight.neutron.spi.INeutronPortAware;
28 import org.opendaylight.neutron.spi.INeutronRouterAware;
29 import org.opendaylight.neutron.spi.INeutronSecurityGroupAware;
30 import org.opendaylight.neutron.spi.INeutronSecurityRuleAware;
31 import org.opendaylight.neutron.spi.INeutronSubnetAware;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
33 import org.osgi.framework.BundleContext;
34 import org.osgi.framework.ServiceRegistration;
36 public class NeutronMapper implements AutoCloseable {
38 private final List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
40 public NeutronMapper(DataBroker dataProvider, RpcProviderRegistry rpcProvider, BundleContext context) {
41 checkNotNull(dataProvider);
42 checkNotNull(rpcProvider);
43 checkNotNull(context);
44 EndpointService epService = rpcProvider.getRpcService(EndpointService.class);
46 registerAwareProviders(dataProvider, epService, context);
49 private void registerAwareProviders(DataBroker dataProvider, EndpointService epService, BundleContext context) {
50 ServiceRegistration<INeutronNetworkAware> neutronNetworkAwareRegistration = context.registerService(
51 INeutronNetworkAware.class, new NeutronNetworkAware(dataProvider), null);
52 registrations.add(neutronNetworkAwareRegistration);
54 ServiceRegistration<INeutronSubnetAware> neutronSubnetAwareRegistration = context.registerService(
55 INeutronSubnetAware.class, new NeutronSubnetAware(dataProvider), null);
56 registrations.add(neutronSubnetAwareRegistration);
58 ServiceRegistration<INeutronPortAware> neutronPortAwareRegistration = context.registerService(
59 INeutronPortAware.class, new NeutronPortAware(dataProvider, epService), null);
60 registrations.add(neutronPortAwareRegistration);
62 ServiceRegistration<INeutronSecurityGroupAware> neutronSecurityGroupAwareRegistration = context.registerService(
63 INeutronSecurityGroupAware.class, new NeutronSecurityGroupAware(dataProvider), null);
64 registrations.add(neutronSecurityGroupAwareRegistration);
66 ServiceRegistration<INeutronSecurityRuleAware> neutronSecurityRuleAwareRegistration = context.registerService(
67 INeutronSecurityRuleAware.class, new NeutronSecurityRuleAware(dataProvider), null);
68 registrations.add(neutronSecurityRuleAwareRegistration);
70 NeutronRouterAware.init(dataProvider, epService);
71 ServiceRegistration<INeutronRouterAware> neutronRouterAwareRegistration = context.registerService(
72 INeutronRouterAware.class, NeutronRouterAware.getInstance(), null);
73 registrations.add(neutronRouterAwareRegistration);
75 ServiceRegistration<INeutronFloatingIPAware> neutronFloatingIpAwareRegistration = context.registerService(
76 INeutronFloatingIPAware.class, new NeutronFloatingIpAware(dataProvider, epService), null);
77 registrations.add(neutronFloatingIpAwareRegistration);
81 * @see java.lang.AutoCloseable#close()
84 public void close() throws Exception {
85 for (ServiceRegistration<?> registration : registrations) {
86 registration.unregister();