Merge "Adding ITM internal/external tunnel build logic"
[vpnservice.git] / itm / itm-impl / src / main / java / org / opendaylight / vpnservice / itm / impl / ItmProvider.java
1 /*
2  * Copyright (c) 2015 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.itm.impl;
9
10 import java.math.BigInteger;
11 import java.util.List;
12 import java.util.concurrent.Future;
13
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
16 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
19 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
20 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
21 import org.opendaylight.vpnservice.itm.api.IITMProvider;
22 import org.opendaylight.vpnservice.itm.listeners.TransportZoneListener;
23 import org.opendaylight.vpnservice.itm.rpc.ItmManagerRpcService;
24 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.op.rev150701.GetTunnelIdInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.op.rev150701.GetTunnelIdOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.op.rev150701.ItmStateService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.op.rev150701.TunnelsState;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.itm.rev150701.transport.zones.transport.zone.*;;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class ItmProvider implements BindingAwareProvider, AutoCloseable, IITMProvider,ItmStateService {
35
36     private static final Logger LOG = LoggerFactory.getLogger(ItmProvider.class);
37     private IInterfaceManager interfaceManager;
38     private ITMManager itmManager;
39     private IMdsalApiManager mdsalManager;
40     private DataBroker dataBroker;
41     private NotificationPublishService notificationPublishService;
42     private ItmManagerRpcService itmRpcService ;
43     private NotificationService notificationService;
44     private TransportZoneListener tzChangeListener;
45
46     @Override
47     public void onSessionInitiated(ProviderContext session) {
48         LOG.info("ItmProvider Session Initiated");
49         try {
50             dataBroker = session.getSALService(DataBroker.class);
51
52             itmManager = new ITMManager(dataBroker);
53             tzChangeListener = new TransportZoneListener(dataBroker) ;
54             itmRpcService = new ItmManagerRpcService(dataBroker);
55
56             itmManager.setMdsalManager(mdsalManager);
57             itmManager.setNotificationPublishService(notificationPublishService);
58             itmManager.setMdsalManager(mdsalManager);
59             tzChangeListener.setItmManager(itmManager);
60             tzChangeListener.registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
61         } catch (Exception e) {
62             LOG.error("Error initializing services", e);
63         }
64     }
65
66     public void setInterfaceManager(IInterfaceManager interfaceManager) {
67         this.interfaceManager = interfaceManager;
68     }
69
70     public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
71         this.notificationPublishService = notificationPublishService;
72     }
73     
74     public void setMdsalApiManager(IMdsalApiManager mdsalMgr) {
75         this.mdsalManager = mdsalMgr;
76     }
77     public void setNotificationService(NotificationService notificationService) {
78         this.notificationService = notificationService;
79     }
80
81     @Override
82     public void close() throws Exception {
83         if (itmManager != null) {
84             itmManager.close();
85         }
86         if (tzChangeListener != null) {
87             tzChangeListener.close();
88         }
89
90         LOG.info("ItmProvider Closed");
91     }
92
93     @Override
94     public Future<RpcResult<GetTunnelIdOutput>> getTunnelId(
95          GetTunnelIdInput input) {
96          // TODO Auto-generated method stub
97          return null;
98     }
99
100 }