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.neutron.transcriber;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
14 import org.opendaylight.neutron.spi.INeutronCRUD;
15 import org.opendaylight.neutron.spi.INeutronFirewallCRUD;
16 import org.opendaylight.neutron.spi.INeutronFirewallPolicyCRUD;
17 import org.opendaylight.neutron.spi.INeutronFirewallRuleCRUD;
18 import org.opendaylight.neutron.spi.INeutronFloatingIPCRUD;
19 import org.opendaylight.neutron.spi.INeutronL2gatewayCRUD;
20 import org.opendaylight.neutron.spi.INeutronL2gatewayConnectionCRUD;
21 import org.opendaylight.neutron.spi.INeutronLoadBalancerCRUD;
22 import org.opendaylight.neutron.spi.INeutronLoadBalancerHealthMonitorCRUD;
23 import org.opendaylight.neutron.spi.INeutronLoadBalancerListenerCRUD;
24 import org.opendaylight.neutron.spi.INeutronLoadBalancerPoolCRUD;
25 import org.opendaylight.neutron.spi.INeutronMeteringLabelCRUD;
26 import org.opendaylight.neutron.spi.INeutronMeteringLabelRuleCRUD;
27 import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
28 import org.opendaylight.neutron.spi.INeutronPortCRUD;
29 import org.opendaylight.neutron.spi.INeutronRouterCRUD;
30 import org.opendaylight.neutron.spi.INeutronSecurityGroupCRUD;
31 import org.opendaylight.neutron.spi.INeutronSecurityRuleCRUD;
32 import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
33 import org.opendaylight.neutron.spi.INeutronVPNIKEPolicyCRUD;
34 import org.opendaylight.neutron.spi.INeutronVPNIPSECPolicyCRUD;
35 import org.opendaylight.neutron.spi.INeutronVPNIPSECSiteConnectionsCRUD;
36 import org.opendaylight.neutron.spi.INeutronVPNServiceCRUD;
37 import org.osgi.framework.BundleContext;
38 import org.osgi.framework.ServiceRegistration;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 import java.util.ArrayList;
43 import java.util.List;
46 public class NeutronTranscriberProvider
47 implements AutoCloseable, NeutronTranscriber {
48 private static final Logger LOGGER = LoggerFactory.getLogger(NeutronTranscriberProvider.class);
50 private BundleContext context;
51 private DataBroker db;
52 private final List<ServiceRegistration<? extends INeutronCRUD<?>>> registrations = new ArrayList<>();
53 private final List<AutoCloseable> neutronInterfaces = new ArrayList<>();
55 private NeutronBgpvpnInterface bgpvpnInterface;
56 private NeutronFirewallInterface firewallInterface;
57 private NeutronFirewallPolicyInterface firewallPolicyInterface;
58 private NeutronFirewallRuleInterface firewallRuleInterface;
59 private NeutronFloatingIPInterface floatingIPInterface;
60 private NeutronL2gatewayConnectionInterface l2gatewayConnectionInterface;
61 private NeutronL2gatewayInterface l2gatewayInterface;
62 private NeutronLoadBalancerHealthMonitorInterface loadBalancerHealthMonitorInterface;
63 private NeutronLoadBalancerInterface loadBalancerInterface;
64 private NeutronLoadBalancerListenerInterface loadBalancerListenerInterface;
65 private NeutronLoadBalancerPoolInterface loadBalancerPoolInterface;
66 private NeutronMeteringLabelInterface meteringLabelInterface;
67 private NeutronMeteringLabelRuleInterface meteringLabelRuleInterface;
68 private NeutronNetworkInterface networkInterface;
69 private NeutronPortInterface portInterface;
70 private NeutronRouterInterface routerInterface;
71 private NeutronSecurityGroupInterface securityGroupInterface;
72 private NeutronSecurityRuleInterface securityRuleInterface;
73 private NeutronSubnetInterface subnetInterface;
74 private NeutronVPNIKEPolicyInterface vPNIKEPolicyInterface;
75 private NeutronVPNIPSECPolicyInterface vPNIPSECPolicyInterface;
76 private NeutronVPNIPSECSiteConnectionsInterface vPNIPSECSiteConnectionsInterface;
77 private NeutronVPNServiceInterface vPNServiceInterface;
79 public NeutronTranscriberProvider(BundleContext context, DataBroker db) {
80 LOGGER.debug("DataBroker set to: {}", db);
81 this.context = Preconditions.checkNotNull(context);
82 this.db = Preconditions.checkNotNull(db);
85 private <S extends INeutronCRUD<?>, T extends AutoCloseable /* & S */>
86 void registerCRUDInterface(java.lang.Class<S> clazz, T crudInterface) {
87 neutronInterfaces.add(crudInterface);
88 final ServiceRegistration<S> crudInterfaceRegistration =
89 context.registerService(clazz, (S)crudInterface, null);
90 registrations.add(crudInterfaceRegistration);
94 bgpvpnInterface = new NeutronBgpvpnInterface(db);
95 registerCRUDInterface(INeutronBgpvpnCRUD.class, bgpvpnInterface);
97 firewallInterface = new NeutronFirewallInterface(db);
98 registerCRUDInterface(INeutronFirewallCRUD.class, firewallInterface);
100 firewallPolicyInterface = new NeutronFirewallPolicyInterface(db);
101 registerCRUDInterface(INeutronFirewallPolicyCRUD.class, firewallPolicyInterface);
103 firewallRuleInterface = new NeutronFirewallRuleInterface(db);
104 registerCRUDInterface(INeutronFirewallRuleCRUD.class, firewallRuleInterface);
106 floatingIPInterface = new NeutronFloatingIPInterface(db);
107 registerCRUDInterface(INeutronFloatingIPCRUD.class, floatingIPInterface);
109 l2gatewayConnectionInterface = new NeutronL2gatewayConnectionInterface(db);
110 registerCRUDInterface(INeutronL2gatewayConnectionCRUD.class, l2gatewayConnectionInterface);
112 l2gatewayInterface = new NeutronL2gatewayInterface(db);
113 registerCRUDInterface(INeutronL2gatewayCRUD.class, l2gatewayInterface);
115 loadBalancerHealthMonitorInterface = new NeutronLoadBalancerHealthMonitorInterface(db);
116 registerCRUDInterface(INeutronLoadBalancerHealthMonitorCRUD.class, loadBalancerHealthMonitorInterface);
118 loadBalancerInterface = new NeutronLoadBalancerInterface(db);
119 registerCRUDInterface(INeutronLoadBalancerCRUD.class, loadBalancerInterface);
121 loadBalancerListenerInterface = new NeutronLoadBalancerListenerInterface(db);
122 registerCRUDInterface(INeutronLoadBalancerListenerCRUD.class, loadBalancerListenerInterface);
124 loadBalancerPoolInterface = new NeutronLoadBalancerPoolInterface(db);
125 registerCRUDInterface(INeutronLoadBalancerPoolCRUD.class, loadBalancerPoolInterface);
127 meteringLabelInterface = new NeutronMeteringLabelInterface(db);
128 registerCRUDInterface(INeutronMeteringLabelCRUD.class, meteringLabelInterface);
130 meteringLabelRuleInterface = new NeutronMeteringLabelRuleInterface(db);
131 registerCRUDInterface(INeutronMeteringLabelRuleCRUD.class, meteringLabelRuleInterface);
133 networkInterface = new NeutronNetworkInterface(db);
134 registerCRUDInterface(INeutronNetworkCRUD.class, networkInterface);
136 portInterface = new NeutronPortInterface(db);
137 registerCRUDInterface(INeutronPortCRUD.class, portInterface);
139 routerInterface = new NeutronRouterInterface(db);
140 registerCRUDInterface(INeutronRouterCRUD.class, routerInterface);
142 securityGroupInterface = new NeutronSecurityGroupInterface(db);
143 registerCRUDInterface(INeutronSecurityGroupCRUD.class, securityGroupInterface);
145 securityRuleInterface = new NeutronSecurityRuleInterface(db);
146 registerCRUDInterface(INeutronSecurityRuleCRUD.class, securityRuleInterface);
148 subnetInterface = new NeutronSubnetInterface(db);
149 registerCRUDInterface(INeutronSubnetCRUD.class, subnetInterface);
151 vPNIKEPolicyInterface = new NeutronVPNIKEPolicyInterface(db);
152 registerCRUDInterface(INeutronVPNIKEPolicyCRUD.class, vPNIKEPolicyInterface);
154 vPNIPSECPolicyInterface = new NeutronVPNIPSECPolicyInterface(db);
155 registerCRUDInterface(INeutronVPNIPSECPolicyCRUD.class, vPNIPSECPolicyInterface);
157 vPNIPSECSiteConnectionsInterface = new NeutronVPNIPSECSiteConnectionsInterface(db);
158 registerCRUDInterface(INeutronVPNIPSECSiteConnectionsCRUD.class, vPNIPSECSiteConnectionsInterface);
160 vPNServiceInterface = new NeutronVPNServiceInterface(db);
161 registerCRUDInterface(INeutronVPNServiceCRUD.class, vPNServiceInterface);
163 // We don't need context any more
168 public void close() throws Exception {
169 for (final ServiceRegistration registration : registrations) {
170 registration.unregister();
172 for (final AutoCloseable neutronCRUD : neutronInterfaces) {
175 neutronInterfaces.clear();