3d731ae5d26a81e0f90d857601c1494082149091
[netvirt.git] / vpnservice / neutronvpn / neutronvpn-impl / src / main / java / org / opendaylight / netvirt / 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.netvirt.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.netvirt.neutronvpn.interfaces.INeutronVpnManager;
19 import org.opendaylight.netvirt.neutronvpn.l2gw.L2GatewayProvider;
20 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.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.genius.lockmanager.rev160413.LockManagerService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronvpnService;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import java.util.List;
31
32 public class NeutronvpnProvider implements BindingAwareProvider, INeutronVpnManager, AutoCloseable {
33
34     private static final Logger LOG = LoggerFactory.getLogger(NeutronvpnProvider.class);
35     private NeutronvpnManager nvManager;
36     private NeutronvpnNatManager nvNatManager;
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             nvNatManager = new NeutronvpnNatManager(dbx, mdsalManager);
82             nvManager = new NeutronvpnManager(dbx, mdsalManager,notificationPublishService,notificationService, nvNatManager);
83             final BindingAwareBroker.RpcRegistration<NeutronvpnService> rpcRegistration =
84                     getRpcProviderRegistry().addRpcImplementation(NeutronvpnService.class, nvManager);
85             bgpvpnListener = new NeutronBgpvpnChangeListener(dbx, nvManager);
86             networkListener = new NeutronNetworkChangeListener(dbx, nvManager, nvNatManager);
87             subnetListener = new NeutronSubnetChangeListener(dbx, nvManager);
88             routerListener = new NeutronRouterChangeListener(dbx, nvManager, nvNatManager);
89             portListener = new NeutronPortChangeListener(dbx, nvManager, nvNatManager,
90                     notificationPublishService,notificationService);
91             portListener.setLockManager(lockManager);
92             portListener.setLockManager(lockManager);
93             nvManager.setLockManager(lockManager);
94             l2GatewayProvider = new L2GatewayProvider(dbx, rpcProviderRegistry, entityOwnershipService);
95
96             LOG.info("NeutronvpnProvider Session Initiated");
97         } catch (Exception e) {
98             LOG.error("Error initializing services", e);
99         }
100     }
101
102     @Override
103     public void close() throws Exception {
104         portListener.close();
105         subnetListener.close();
106         routerListener.close();
107         networkListener.close();
108         bgpvpnListener.close();
109         nvManager.close();
110         l2GatewayProvider.close();
111         LOG.info("NeutronvpnProvider Closed");
112     }
113
114     @Override
115     public List<String> showNeutronPortsCLI() {
116         return nvManager.showNeutronPortsCLI();
117     }
118
119     @Override
120     public List<String> showVpnConfigCLI(Uuid vuuid) {
121         return nvManager.showVpnConfigCLI(vuuid);
122     }
123
124     @Override
125     public void addSubnetToVpn(Uuid vpnId, Uuid subnet) {
126         nvManager.addSubnetToVpn(vpnId, subnet);
127     }
128
129     @Override
130     public List<Uuid> getSubnetsforVpn(Uuid vpnid) {
131         return nvManager.getSubnetsforVpn(vpnid);
132     }
133
134     @Override
135     public void removeSubnetFromVpn(Uuid vpnId, Uuid subnet) {
136         nvManager.removeSubnetFromVpn(vpnId, subnet);
137     }
138
139     @Override
140     public Port getNeutronPort(String name) {
141         return nvManager.getNeutronPort(name);
142     }
143
144     @Override
145     public Port getNeutronPort(Uuid portId) {
146         return nvManager.getNeutronPort(portId);
147     }
148
149     @Override
150     public Subnet getNeutronSubnet(Uuid subnetId) {
151         return nvManager.getNeutronSubnet(subnetId);
152     }
153
154     @Override
155     public String uuidToTapPortName(Uuid id) {
156         return NeutronvpnUtils.uuidToTapPortName(id);
157     }
158
159     @Override
160     public IpAddress getNeutronSubnetGateway(Uuid subnetId) {
161         return nvManager.getNeutronSubnetGateway(subnetId);
162     }
163
164 }