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.vpnservice.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.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.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.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;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import java.util.List;
33 public class NeutronvpnProvider implements BindingAwareProvider, INeutronVpnManager, AutoCloseable {
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;
50 public NeutronvpnProvider(RpcProviderRegistry rpcRegistry,NotificationPublishService notificationPublishService,
51 NotificationService notificationService) {
52 this.rpcProviderRegistry = rpcRegistry;
53 this.notificationPublishService = notificationPublishService;
54 this.notificationService = notificationService;
57 public RpcProviderRegistry getRpcProviderRegistry() {
58 return rpcProviderRegistry;
61 public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
62 this.rpcProviderRegistry = rpcProviderRegistry;
65 public void setMdsalManager(IMdsalApiManager mdsalManager) {
66 this.mdsalManager = mdsalManager;
69 public void setLockManager(LockManagerService lockManager) {
70 this.lockManager = lockManager;
73 public void setEntityOwnershipService(EntityOwnershipService entityOwnershipService) {
74 this.entityOwnershipService = entityOwnershipService;
78 public void onSessionInitiated(ProviderContext session) {
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);
93 LOG.info("NeutronvpnProvider Session Initiated");
94 } catch (Exception e) {
95 LOG.error("Error initializing services", e);
100 public void close() throws Exception {
101 portListener.close();
102 subnetListener.close();
103 routerListener.close();
104 networkListener.close();
105 bgpvpnListener.close();
107 l2GatewayProvider.close();
108 LOG.info("NeutronvpnProvider Closed");
112 public List<String> showNeutronPortsCLI() {
113 return nvManager.showNeutronPortsCLI();
117 public List<String> showVpnConfigCLI(Uuid vuuid) {
118 return nvManager.showVpnConfigCLI(vuuid);
122 public void addSubnetToVpn(Uuid vpnId, Uuid subnet) {
123 nvManager.addSubnetToVpn(vpnId, subnet);
127 public List<Uuid> getSubnetsforVpn(Uuid vpnid) {
128 return nvManager.getSubnetsforVpn(vpnid);
132 public void removeSubnetFromVpn(Uuid vpnId, Uuid subnet) {
133 nvManager.removeSubnetFromVpn(vpnId, subnet);
137 public Port getNeutronPort(String name) {
138 return nvManager.getNeutronPort(name);
142 public Port getNeutronPort(Uuid portId) {
143 return nvManager.getNeutronPort(portId);
147 public Subnet getNeutronSubnet(Uuid subnetId) {
148 return nvManager.getNeutronSubnet(subnetId);
152 public String uuidToTapPortName(Uuid id) {
153 return NeutronvpnUtils.uuidToTapPortName(id);
157 public IpAddress getNeutronSubnetGateway(Uuid subnetId) {
158 return nvManager.getNeutronSubnetGateway(subnetId);