2 * Copyright (c) 2015 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.itm.impl;
10 import java.math.BigInteger;
11 import java.util.List;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.Future;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
17 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
21 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
22 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
23 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
24 import org.opendaylight.vpnservice.itm.api.IITMProvider;
25 import org.opendaylight.vpnservice.itm.globals.ITMConstants;
26 import org.opendaylight.vpnservice.itm.listeners.TransportZoneListener;
27 import org.opendaylight.vpnservice.itm.rpc.ItmManagerRpcService;
28 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.CreateIdPoolInputBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.OdlInterfaceRpcService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rpcs.rev151217.ItmRpcService;
35 import org.opendaylight.yangtools.yang.common.RpcResult;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMProvider /*,ItmStateService */{
41 private static final Logger LOG = LoggerFactory.getLogger(ItmProvider.class);
42 private IInterfaceManager interfaceManager;
43 private ITMManager itmManager;
44 private IMdsalApiManager mdsalManager;
45 private DataBroker dataBroker;
46 private NotificationPublishService notificationPublishService;
47 private ItmManagerRpcService itmRpcService ;
48 private IdManagerService idManager;
49 private NotificationService notificationService;
50 private TransportZoneListener tzChangeListener;
51 private RpcProviderRegistry rpcProviderRegistry;
53 public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
54 this.rpcProviderRegistry = rpcProviderRegistry;
57 public RpcProviderRegistry getRpcProviderRegistry() {
58 return this.rpcProviderRegistry;
62 public void onSessionInitiated(ProviderContext session) {
63 LOG.info("ItmProvider Session Initiated");
65 dataBroker = session.getSALService(DataBroker.class);
66 idManager = getRpcProviderRegistry().getRpcService(IdManagerService.class);
68 itmManager = new ITMManager(dataBroker);
69 tzChangeListener = new TransportZoneListener(dataBroker, idManager) ;
70 itmRpcService = new ItmManagerRpcService(dataBroker, idManager);
71 final BindingAwareBroker.RpcRegistration<ItmRpcService> rpcRegistration = getRpcProviderRegistry().addRpcImplementation(ItmRpcService.class, itmRpcService);
72 itmRpcService.setMdsalManager(mdsalManager);
73 itmManager.setMdsalManager(mdsalManager);
74 itmManager.setNotificationPublishService(notificationPublishService);
75 itmManager.setMdsalManager(mdsalManager);
76 tzChangeListener.setMdsalManager(mdsalManager);
77 tzChangeListener.setItmManager(itmManager);
78 tzChangeListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
80 } catch (Exception e) {
81 LOG.error("Error initializing services", e);
85 public void setInterfaceManager(IInterfaceManager interfaceManager) {
86 this.interfaceManager = interfaceManager;
89 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
90 this.notificationPublishService = notificationPublishService;
93 public void setMdsalApiManager(IMdsalApiManager mdsalMgr) {
94 this.mdsalManager = mdsalMgr;
96 public void setNotificationService(NotificationService notificationService) {
97 this.notificationService = notificationService;
101 public void close() throws Exception {
102 if (itmManager != null) {
105 if (tzChangeListener != null) {
106 tzChangeListener.close();
109 LOG.info("ItmProvider Closed");
112 private void createIdPool() {
113 CreateIdPoolInput createPool = new CreateIdPoolInputBuilder()
114 .setPoolName(ITMConstants.ITM_IDPOOL_NAME)
115 .setLow(ITMConstants.ITM_IDPOOL_START)
116 .setHigh(new BigInteger(ITMConstants.ITM_IDPOOL_SIZE).longValue())
119 Future<RpcResult<Void>> result = idManager.createIdPool(createPool);
120 if ((result != null) && (result.get().isSuccessful())) {
121 LOG.debug("Created IdPool for ITM Service");
123 } catch (InterruptedException | ExecutionException e) {
124 LOG.error("Failed to create idPool for ITM Service",e);