2 * Copyright (c) 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.netvirt.dhcpservice;
10 import javax.annotation.PostConstruct;
11 import javax.annotation.PreDestroy;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
17 import org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfig;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dhcp.config.Configs;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 public class DhcpConfigListener extends AsyncClusteredDataTreeChangeListenerBase<DhcpConfig, DhcpConfigListener> {
27 private static final Logger LOG = LoggerFactory.getLogger(DhcpConfigListener.class);
29 private final DhcpManager dhcpManager;
30 private final DataBroker dataBroker;
33 public DhcpConfigListener(final DataBroker db, final DhcpManager dhcpMgr) {
34 super(DhcpConfig.class, DhcpConfigListener.class);
35 dhcpManager = dhcpMgr;
41 registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
45 protected InstanceIdentifier<DhcpConfig> getWildCardPath() {
46 return InstanceIdentifier.create(DhcpConfig.class);
53 LOG.debug("DhcpConfig Listener Closed");
57 protected void remove(InstanceIdentifier<DhcpConfig> identifier, DhcpConfig del) {
58 LOG.trace("DhcpConfig removed: {}", del);
63 protected void update(InstanceIdentifier<DhcpConfig> identifier, DhcpConfig original, DhcpConfig update) {
64 LOG.trace("DhcpConfig changed to {}", update);
69 protected void add(InstanceIdentifier<DhcpConfig> identifier, DhcpConfig add) {
70 LOG.trace("DhcpConfig added {}", add);
74 private void updateConfig(DhcpConfig update) {
75 //TODO: Update operational with actual values
76 if (update == null || update.getConfigs() == null || update.getConfigs().isEmpty()) {
77 dhcpManager.setLeaseDuration(DhcpMConstants.DEFAULT_LEASE_TIME);
78 dhcpManager.setDefaultDomain(DhcpMConstants.DEFAULT_DOMAIN_NAME);
81 Configs config = update.getConfigs().get(0);
82 if (config.getLeaseDuration() != null) {
83 dhcpManager.setLeaseDuration(config.getLeaseDuration());
85 if (config.getDefaultDomain() != null) {
86 dhcpManager.setDefaultDomain(config.getDefaultDomain());
87 //TODO: What to do if string is ""
92 protected DhcpConfigListener getDataTreeChangeListener() {
93 return DhcpConfigListener.this;