Initial Alivenessmonitor code
[vpnservice.git] / alivenessmonitor / alivenessmonitor-impl / src / main / java / org / opendaylight / vpnservice / alivenessmonitor / internal / AlivenessMonitorProvider.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.alivenessmonitor.internal;
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.sal.binding.api.BindingAwareBroker.ProviderContext;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
15 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
16 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.AlivenessMonitorService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.EtherTypes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.arputil.rev151126.OdlArputilService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rpcs.rev151003.OdlInterfaceRpcService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
23 import org.opendaylight.yangtools.concepts.ListenerRegistration;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 public class AlivenessMonitorProvider implements BindingAwareProvider,
28                                         AutoCloseable {
29     private static final Logger LOG = LoggerFactory.getLogger(AlivenessMonitorProvider.class);
30     private AlivenessMonitor alivenessMonitor;
31     private RpcProviderRegistry rpcProviderRegistry;
32     private OdlInterfaceRpcService interfaceManager;
33     private RpcRegistration<AlivenessMonitorService> rpcRegistration;
34     private ListenerRegistration<AlivenessMonitor> listenerRegistration;
35     private NotificationService notificationService;
36     private NotificationPublishService notificationPublishService;
37
38     public AlivenessMonitorProvider(RpcProviderRegistry rpcProviderRegistry) {
39         this.rpcProviderRegistry = rpcProviderRegistry;
40     }
41
42     public RpcProviderRegistry getRpcProviderRegistry() {
43         return rpcProviderRegistry;
44     }
45
46     public void setNotificationService(NotificationService notificationService) {
47         this.notificationService = notificationService;
48     }
49
50     public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
51         this.notificationPublishService = notificationPublishService;
52     }
53
54     @Override
55     public void close() throws Exception {
56         rpcRegistration.close();
57         listenerRegistration.close();
58         alivenessMonitor.close();
59     }
60
61     @Override
62     public void onSessionInitiated(ProviderContext session) {
63         LOG.info("AlivenessMonitorProvider Session Initiated");
64         try {
65             final  DataBroker dataBroker = session.getSALService(DataBroker.class);
66             PacketProcessingService pktProcessingService = session.getRpcService(PacketProcessingService.class);
67             IdManagerService idManager = rpcProviderRegistry.getRpcService(IdManagerService.class);
68             OdlInterfaceRpcService interfaceService = rpcProviderRegistry.getRpcService(OdlInterfaceRpcService.class);
69             alivenessMonitor = new AlivenessMonitor(dataBroker);
70             alivenessMonitor.setPacketProcessingService(pktProcessingService);
71             alivenessMonitor.setNotificationPublishService(notificationPublishService);
72             alivenessMonitor.setIdManager(idManager);
73             alivenessMonitor.setInterfaceManager(interfaceService);
74             rpcRegistration = getRpcProviderRegistry().addRpcImplementation(AlivenessMonitorService.class, alivenessMonitor);
75             listenerRegistration = notificationService.registerNotificationListener(alivenessMonitor);
76
77             //ARP Handler
78             AlivenessProtocolHandler arpHandler = new AlivenessProtocolHandlerARP(alivenessMonitor);
79             OdlArputilService arpService = rpcProviderRegistry.getRpcService(OdlArputilService.class);
80             ((AlivenessProtocolHandlerARP) arpHandler).setArpManagerService(arpService);
81             alivenessMonitor.registerHandler(EtherTypes.Arp, arpHandler);
82
83             //LLDP Handler
84             AlivenessProtocolHandler lldpHandler = new AlivenessProtocolHandlerLLDP(alivenessMonitor);
85             alivenessMonitor.registerHandler(EtherTypes.Lldp, lldpHandler);
86
87             //TODO: Enable Interface Event Listener
88             //DelegatingInterfaceEventListener listener = new DelegatingInterfaceEventListener(alivenessMonitor);
89             //interfaceListenerRegistration = notificationService.registerNotificationListener(listener);
90         } catch (Exception e) {
91             LOG.error("Error initializing AlivenessMonitor service", e);
92         }
93     }
94
95 }