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.BindingAwareBroker.RpcRegistration;
18 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
19 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronFloatingIpAware;
20 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronListener;
21 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronNetworkAware;
22 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronNetworkDao;
23 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronPortAware;
24 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronRouterAware;
25 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronSubnetAware;
26 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.group.NeutronSecurityGroupAware;
27 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.group.SecGroupDao;
28 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule.NeutronGbpMapperServiceImpl;
29 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule.NeutronSecurityRuleAware;
30 import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.rule.SecRuleDao;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.NeutronGbpMapperService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.floatingips.attributes.Floatingips;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.floatingips.attributes.floatingips.Floatingip;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.groups.attributes.SecurityGroups;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.groups.attributes.security.groups.SecurityGroup;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.SecurityRules;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.rules.attributes.security.rules.SecurityRule;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
48 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
49 import org.osgi.framework.ServiceRegistration;
51 public class NeutronMapper implements AutoCloseable {
53 private final List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
54 private final DataBroker dataProvider;
55 private final RpcProviderRegistry providerRegistry;
56 private final EndpointService epService;
57 private RpcRegistration<NeutronGbpMapperService> rpcRegistration;
58 private NeutronListener neutronListener;
60 public NeutronMapper(DataBroker dataProvider, RpcProviderRegistry rpcProvider) {
61 this.dataProvider = checkNotNull(dataProvider);
62 this.providerRegistry = checkNotNull(rpcProvider);
63 this.epService = rpcProvider.getRpcService(EndpointService.class);
64 neutronListener = new NeutronListener(dataProvider);
65 registerAwareProviders();
68 private void registerAwareProviders() {
69 SecGroupDao secGroupDao = new SecGroupDao();
70 SecRuleDao secRuleDao = new SecRuleDao();
71 NeutronNetworkDao networkDao = new NeutronNetworkDao();
72 NeutronSecurityRuleAware securityRuleAware = new NeutronSecurityRuleAware(dataProvider, secRuleDao, secGroupDao);
73 NeutronSecurityGroupAware securityGroupAware = new NeutronSecurityGroupAware(dataProvider, securityRuleAware, secGroupDao);
74 neutronListener.registerMappingProviders(
75 InstanceIdentifier.builder(Neutron.class).child(Floatingips.class).child(Floatingip.class).build(),
76 new NeutronFloatingIpAware(dataProvider));
77 neutronListener.registerMappingProviders(
78 InstanceIdentifier.builder(Neutron.class).child(Ports.class).child(Port.class).build(),
79 new NeutronPortAware(dataProvider, epService, securityRuleAware, securityGroupAware));
80 neutronListener.registerMappingProviders(
81 InstanceIdentifier.builder(Neutron.class).child(Routers.class).child(Router.class).build(),
82 new NeutronRouterAware(dataProvider, epService));
83 neutronListener.registerMappingProviders(
84 InstanceIdentifier.builder(Neutron.class).child(SecurityRules.class).child(SecurityRule.class).build(),
86 neutronListener.registerMappingProviders(
87 InstanceIdentifier.builder(Neutron.class).child(SecurityGroups.class).child(SecurityGroup.class).build(),
89 neutronListener.registerMappingProviders(
90 InstanceIdentifier.builder(Neutron.class).child(Subnets.class).child(Subnet.class).build(),
91 new NeutronSubnetAware(dataProvider, networkDao));
92 neutronListener.registerMappingProviders(
93 InstanceIdentifier.builder(Neutron.class).child(Networks.class).child(Network.class).build(),
94 new NeutronNetworkAware(dataProvider, securityGroupAware, networkDao));
95 NeutronGbpMapperService neutronGbpMapperService = new NeutronGbpMapperServiceImpl(dataProvider, securityRuleAware);
96 rpcRegistration = providerRegistry.addRpcImplementation(NeutronGbpMapperService.class, neutronGbpMapperService);
100 * @see java.lang.AutoCloseable#close()
103 public void close() throws Exception {
104 for (ServiceRegistration<?> registration : registrations) {
105 registration.unregister();
107 if (neutronListener != null) {
108 neutronListener.close();
109 neutronListener = null;
111 rpcRegistration.close();