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.NeutronNetworkDao;
21 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronPortAware;
22 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronRouterAware;
23 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronSubnetAware;
24 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.group.NeutronSecurityGroupAware;
25 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.group.SecGroupDao;
26 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule.NeutronSecurityRuleAware;
27 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule.SecRuleDao;
28 import org.opendaylight.neutron.spi.INeutronFloatingIPAware;
29 import org.opendaylight.neutron.spi.INeutronNetworkAware;
30 import org.opendaylight.neutron.spi.INeutronPortAware;
31 import org.opendaylight.neutron.spi.INeutronRouterAware;
32 import org.opendaylight.neutron.spi.INeutronSecurityGroupAware;
33 import org.opendaylight.neutron.spi.INeutronSecurityRuleAware;
34 import org.opendaylight.neutron.spi.INeutronSubnetAware;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
36 import org.osgi.framework.BundleContext;
37 import org.osgi.framework.ServiceRegistration;
39 public class NeutronMapper implements AutoCloseable {
41 private final List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
43 public NeutronMapper(DataBroker dataProvider, RpcProviderRegistry rpcProvider, BundleContext context) {
44 checkNotNull(dataProvider);
45 checkNotNull(rpcProvider);
46 checkNotNull(context);
47 EndpointService epService = rpcProvider.getRpcService(EndpointService.class);
48 registerAwareProviders(dataProvider, epService, context);
51 private void registerAwareProviders(DataBroker dataProvider, EndpointService epService, BundleContext context) {
52 SecGroupDao secGroupDao = new SecGroupDao();
53 SecRuleDao secRuleDao = new SecRuleDao();
54 NeutronNetworkDao networkDao = new NeutronNetworkDao();
56 ServiceRegistration<INeutronSubnetAware> neutronSubnetAwareRegistration =
57 context.registerService(INeutronSubnetAware.class, new NeutronSubnetAware(dataProvider, networkDao), null);
58 registrations.add(neutronSubnetAwareRegistration);
60 NeutronSecurityRuleAware securityRuleAware = new NeutronSecurityRuleAware(dataProvider, secRuleDao, secGroupDao);
61 ServiceRegistration<INeutronSecurityRuleAware> neutronSecurityRuleAwareRegistration =
62 context.registerService(INeutronSecurityRuleAware.class, securityRuleAware, null);
63 registrations.add(neutronSecurityRuleAwareRegistration);
65 NeutronSecurityGroupAware securityGroupAware = new NeutronSecurityGroupAware(dataProvider, securityRuleAware, secGroupDao);
66 ServiceRegistration<INeutronSecurityGroupAware> neutronSecurityGroupAwareRegistration =
67 context.registerService(INeutronSecurityGroupAware.class, securityGroupAware, null);
68 registrations.add(neutronSecurityGroupAwareRegistration);
70 ServiceRegistration<INeutronNetworkAware> neutronNetworkAwareRegistration = context.registerService(
71 INeutronNetworkAware.class, new NeutronNetworkAware(dataProvider, securityGroupAware, networkDao), null);
72 registrations.add(neutronNetworkAwareRegistration);
74 NeutronPortAware portAware =
75 new NeutronPortAware(dataProvider, epService, securityRuleAware, securityGroupAware);
76 ServiceRegistration<INeutronPortAware> neutronPortAwareRegistration =
77 context.registerService(INeutronPortAware.class, portAware, null);
78 registrations.add(neutronPortAwareRegistration);
80 NeutronRouterAware routerAware = new NeutronRouterAware(dataProvider, epService);
81 ServiceRegistration<INeutronRouterAware> neutronRouterAwareRegistration =
82 context.registerService(INeutronRouterAware.class, routerAware, null);
83 registrations.add(neutronRouterAwareRegistration);
85 ServiceRegistration<INeutronFloatingIPAware> neutronFloatingIpAwareRegistration = context
86 .registerService(INeutronFloatingIPAware.class, new NeutronFloatingIpAware(dataProvider), null);
87 registrations.add(neutronFloatingIpAwareRegistration);
91 * @see java.lang.AutoCloseable#close()
94 public void close() throws Exception {
95 for (ServiceRegistration<?> registration : registrations) {
96 registration.unregister();