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.dhcpservice;
10 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
12 import org.opendaylight.yangtools.concepts.Registration;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
16 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class DhcpProvider implements BindingAwareProvider, AutoCloseable {
22 private static final Logger LOG = LoggerFactory.getLogger(DhcpProvider.class);
23 private IMdsalApiManager mdsalManager;
24 private DhcpPktHandler dhcpPktHandler;
25 private Registration packetListener = null;
26 private NotificationProviderService notificationService;
29 public void onSessionInitiated(ProviderContext session) {
30 LOG.info("DhcpProvider Session Initiated");
32 final DataBroker dataBroker = session.getSALService(DataBroker.class);
33 dhcpPktHandler = new DhcpPktHandler(dataBroker);
34 packetListener = notificationService.registerNotificationListener(dhcpPktHandler);
35 } catch (Exception e) {
36 LOG.error("Error initializing services", e);
41 public void setMdsalManager(IMdsalApiManager mdsalManager) {
42 this.mdsalManager = mdsalManager;
46 public void close() throws Exception {
47 if(packetListener != null) {
48 packetListener.close();
50 if(dhcpPktHandler != null) {
51 dhcpPktHandler.close();
53 LOG.info("DhcpProvider closed");
56 public void setNotificationProviderService(NotificationProviderService notificationServiceDependency) {
57 this.notificationService = notificationServiceDependency;