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.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
18 import org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DhcpConfig;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.dhcp.config.Configs;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 public class DhcpConfigListener extends AsyncClusteredDataTreeChangeListenerBase<DhcpConfig, DhcpConfigListener> {
28 private static final Logger LOG = LoggerFactory.getLogger(DhcpConfigListener.class);
30 private final DhcpManager dhcpManager;
31 private final DataBroker dataBroker;
34 public DhcpConfigListener(final DataBroker db, final DhcpManager dhcpMgr) {
35 super(DhcpConfig.class, DhcpConfigListener.class);
36 dhcpManager = dhcpMgr;
42 registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
46 protected InstanceIdentifier<DhcpConfig> getWildCardPath() {
47 return InstanceIdentifier.create(DhcpConfig.class);
54 LOG.debug("DhcpConfig Listener Closed");
58 protected void remove(InstanceIdentifier<DhcpConfig> identifier, DhcpConfig del) {
59 LOG.trace("DhcpConfig removed: {}", del);
64 protected void update(InstanceIdentifier<DhcpConfig> identifier, DhcpConfig original, DhcpConfig update) {
65 LOG.trace("DhcpConfig changed to {}", update);
70 protected void add(InstanceIdentifier<DhcpConfig> identifier, DhcpConfig add) {
71 LOG.trace("DhcpConfig added {}", add);
75 private void updateConfig(@Nullable DhcpConfig update) {
76 //TODO: Update operational with actual values
77 if (update == null || update.getConfigs() == null || update.getConfigs().isEmpty()) {
78 dhcpManager.setLeaseDuration(DhcpMConstants.DEFAULT_LEASE_TIME);
79 dhcpManager.setDefaultDomain(DhcpMConstants.DEFAULT_DOMAIN_NAME);
82 Configs config = update.getConfigs().get(0);
83 if (config.getLeaseDuration() != null) {
84 dhcpManager.setLeaseDuration(config.getLeaseDuration());
86 if (config.getDefaultDomain() != null) {
87 dhcpManager.setDefaultDomain(config.getDefaultDomain());
88 //TODO: What to do if string is ""
93 protected DhcpConfigListener getDataTreeChangeListener() {
94 return DhcpConfigListener.this;