Bump versions by 0.1.0 for next dev cycle
[vpnservice.git] / neutronvpn / neutronvpn-impl / src / main / java / org / opendaylight / vpnservice / neutronvpn / NeutronvpnProvider.java
1 /*
2  * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. 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 package org.opendaylight.vpnservice.neutronvpn;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
12 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
13 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
17 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
18 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
19 import org.opendaylight.vpnservice.neutronvpn.interfaces.INeutronVpnManager;
20 import org.opendaylight.vpnservice.neutronvpn.l2gw.L2GatewayProvider;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.lockmanager.rev150819.LockManagerService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.NeutronvpnService;
27
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 import java.util.List;
32
33 public class NeutronvpnProvider implements BindingAwareProvider, INeutronVpnManager, AutoCloseable {
34
35     private static final Logger LOG = LoggerFactory.getLogger(NeutronvpnProvider.class);
36     private NeutronvpnManager nvManager;
37     private IMdsalApiManager mdsalManager;
38     private LockManagerService lockManager;
39     private NeutronBgpvpnChangeListener bgpvpnListener;
40     private NeutronNetworkChangeListener networkListener;
41     private NeutronSubnetChangeListener subnetListener;
42     private NeutronRouterChangeListener routerListener;
43     private NeutronPortChangeListener portListener;
44     private RpcProviderRegistry rpcProviderRegistry;
45     private L2GatewayProvider l2GatewayProvider;
46     private NotificationPublishService notificationPublishService;
47     private NotificationService notificationService;
48     private EntityOwnershipService entityOwnershipService;
49
50     public NeutronvpnProvider(RpcProviderRegistry rpcRegistry,NotificationPublishService notificationPublishService,
51                               NotificationService notificationService) {
52         this.rpcProviderRegistry = rpcRegistry;
53         this.notificationPublishService = notificationPublishService;
54         this.notificationService = notificationService;
55     }
56
57     public RpcProviderRegistry getRpcProviderRegistry() {
58         return rpcProviderRegistry;
59     }
60
61     public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
62         this.rpcProviderRegistry = rpcProviderRegistry;
63     }
64
65     public void setMdsalManager(IMdsalApiManager mdsalManager) {
66         this.mdsalManager = mdsalManager;
67     }
68
69     public void setLockManager(LockManagerService lockManager) {
70         this.lockManager = lockManager;
71     }
72
73     public void setEntityOwnershipService(EntityOwnershipService entityOwnershipService) {
74         this.entityOwnershipService = entityOwnershipService;
75     }
76
77     @Override
78     public void onSessionInitiated(ProviderContext session) {
79         try {
80             final DataBroker dbx = session.getSALService(DataBroker.class);
81             nvManager = new NeutronvpnManager(dbx, mdsalManager,notificationPublishService,notificationService);
82             final BindingAwareBroker.RpcRegistration<NeutronvpnService> rpcRegistration =
83                     getRpcProviderRegistry().addRpcImplementation(NeutronvpnService.class, nvManager);
84             bgpvpnListener = new NeutronBgpvpnChangeListener(dbx, nvManager);
85             networkListener = new NeutronNetworkChangeListener(dbx, nvManager);
86             subnetListener = new NeutronSubnetChangeListener(dbx, nvManager);
87             routerListener = new NeutronRouterChangeListener(dbx, nvManager);
88             portListener = new NeutronPortChangeListener(dbx, nvManager,notificationPublishService,notificationService);
89             portListener.setLockManager(lockManager);
90             nvManager.setLockManager(lockManager);
91             l2GatewayProvider = new L2GatewayProvider(dbx, rpcProviderRegistry, entityOwnershipService);
92
93             LOG.info("NeutronvpnProvider Session Initiated");
94         } catch (Exception e) {
95             LOG.error("Error initializing services", e);
96         }
97     }
98
99     @Override
100     public void close() throws Exception {
101         portListener.close();
102         subnetListener.close();
103         routerListener.close();
104         networkListener.close();
105         bgpvpnListener.close();
106         nvManager.close();
107         l2GatewayProvider.close();
108         LOG.info("NeutronvpnProvider Closed");
109     }
110
111     @Override
112     public List<String> showNeutronPortsCLI() {
113         return nvManager.showNeutronPortsCLI();
114     }
115
116     @Override
117     public List<String> showVpnConfigCLI(Uuid vuuid) {
118         return nvManager.showVpnConfigCLI(vuuid);
119     }
120
121     @Override
122     public void addSubnetToVpn(Uuid vpnId, Uuid subnet) {
123         nvManager.addSubnetToVpn(vpnId, subnet);
124     }
125
126     @Override
127     public List<Uuid> getSubnetsforVpn(Uuid vpnid) {
128         return nvManager.getSubnetsforVpn(vpnid);
129     }
130
131     @Override
132     public void removeSubnetFromVpn(Uuid vpnId, Uuid subnet) {
133         nvManager.removeSubnetFromVpn(vpnId, subnet);
134     }
135
136     @Override
137     public Port getNeutronPort(String name) {
138         return nvManager.getNeutronPort(name);
139     }
140
141     @Override
142     public Port getNeutronPort(Uuid portId) {
143         return nvManager.getNeutronPort(portId);
144     }
145
146     @Override
147     public Subnet getNeutronSubnet(Uuid subnetId) {
148         return nvManager.getNeutronSubnet(subnetId);
149     }
150
151     @Override
152     public String uuidToTapPortName(Uuid id) {
153         return NeutronvpnUtils.uuidToTapPortName(id);
154     }
155
156     @Override
157     public IpAddress getNeutronSubnetGateway(Uuid subnetId) {
158         return nvManager.getNeutronSubnetGateway(subnetId);
159     }
160
161 }