2 * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. 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
8 package org.opendaylight.netvirt.neutronvpn;
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;
30 import java.util.List;
32 public class NeutronvpnProvider implements BindingAwareProvider, INeutronVpnManager, AutoCloseable {
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 NeutronSecurityRuleListener securityRuleListener;
45 private NeutronFloatingToFixedIpMappingChangeListener floatingIpMapListener;
46 private RpcProviderRegistry rpcProviderRegistry;
47 private L2GatewayProvider l2GatewayProvider;
48 private NotificationPublishService notificationPublishService;
49 private NotificationService notificationService;
50 private EntityOwnershipService entityOwnershipService;
52 public NeutronvpnProvider(RpcProviderRegistry rpcRegistry,NotificationPublishService notificationPublishService,
53 NotificationService notificationService) {
54 this.rpcProviderRegistry = rpcRegistry;
55 this.notificationPublishService = notificationPublishService;
56 this.notificationService = notificationService;
59 public RpcProviderRegistry getRpcProviderRegistry() {
60 return rpcProviderRegistry;
63 public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
64 this.rpcProviderRegistry = rpcProviderRegistry;
67 public void setMdsalManager(IMdsalApiManager mdsalManager) {
68 this.mdsalManager = mdsalManager;
71 public void setLockManager(LockManagerService lockManager) {
72 this.lockManager = lockManager;
75 public void setEntityOwnershipService(EntityOwnershipService entityOwnershipService) {
76 this.entityOwnershipService = entityOwnershipService;
80 public void onSessionInitiated(ProviderContext session) {
82 final DataBroker dbx = session.getSALService(DataBroker.class);
83 nvNatManager = new NeutronvpnNatManager(dbx, mdsalManager);
84 floatingIpMapListener = new NeutronFloatingToFixedIpMappingChangeListener(dbx);
85 nvManager = new NeutronvpnManager(dbx, mdsalManager,notificationPublishService,notificationService,
86 nvNatManager, floatingIpMapListener);
87 final BindingAwareBroker.RpcRegistration<NeutronvpnService> rpcRegistration =
88 getRpcProviderRegistry().addRpcImplementation(NeutronvpnService.class, nvManager);
89 bgpvpnListener = new NeutronBgpvpnChangeListener(dbx, nvManager);
90 networkListener = new NeutronNetworkChangeListener(dbx, nvManager, nvNatManager);
91 subnetListener = new NeutronSubnetChangeListener(dbx, nvManager);
92 routerListener = new NeutronRouterChangeListener(dbx, nvManager, nvNatManager);
93 portListener = new NeutronPortChangeListener(dbx, nvManager, nvNatManager,
94 notificationPublishService,notificationService);
95 portListener.setLockManager(lockManager);
96 portListener.setLockManager(lockManager);
97 nvManager.setLockManager(lockManager);
98 portListener.setLockManager(lockManager);
99 floatingIpMapListener.setLockManager(lockManager);
100 l2GatewayProvider = new L2GatewayProvider(dbx, rpcProviderRegistry, entityOwnershipService);
101 securityRuleListener = new NeutronSecurityRuleListener(dbx);
102 securityRuleListener.registerListener();
103 LOG.info("NeutronvpnProvider Session Initiated");
104 } catch (Exception e) {
105 LOG.error("Error initializing services", e);
110 public void close() throws Exception {
111 portListener.close();
112 subnetListener.close();
113 routerListener.close();
114 networkListener.close();
115 floatingIpMapListener.close();
116 bgpvpnListener.close();
118 l2GatewayProvider.close();
119 securityRuleListener.close();
120 LOG.info("NeutronvpnProvider Closed");
124 public List<String> showNeutronPortsCLI() {
125 return nvManager.showNeutronPortsCLI();
129 public List<String> showVpnConfigCLI(Uuid vuuid) {
130 return nvManager.showVpnConfigCLI(vuuid);
134 public void addSubnetToVpn(Uuid vpnId, Uuid subnet) {
135 nvManager.addSubnetToVpn(vpnId, subnet);
139 public List<Uuid> getSubnetsforVpn(Uuid vpnid) {
140 return nvManager.getSubnetsforVpn(vpnid);
144 public void removeSubnetFromVpn(Uuid vpnId, Uuid subnet) {
145 nvManager.removeSubnetFromVpn(vpnId, subnet);
149 public Port getNeutronPort(String name) {
150 return nvManager.getNeutronPort(name);
154 public Port getNeutronPort(Uuid portId) {
155 return nvManager.getNeutronPort(portId);
159 public Subnet getNeutronSubnet(Uuid subnetId) {
160 return nvManager.getNeutronSubnet(subnetId);
164 public String getVifPortName(Port port) {
165 return NeutronvpnUtils.getVifPortName(port);
169 public IpAddress getNeutronSubnetGateway(Uuid subnetId) {
170 return nvManager.getNeutronSubnetGateway(subnetId);