package org.opendaylight.netvirt.dhcpservice;
+import com.google.common.util.concurrent.ListenableFuture;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
+import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants;
-import org.opendaylight.netvirt.dhcpservice.jobs.DhcpInterfaceConfigRemoveJob;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final DataBroker dataBroker;
private final DhcpExternalTunnelManager dhcpExternalTunnelManager;
+ private final DhcpManager dhcpManager;
private DataStoreJobCoordinator dataStoreJobCoordinator;
- public DhcpInterfaceConfigListener(DataBroker dataBroker, DhcpExternalTunnelManager dhcpExternalTunnelManager) {
+ public DhcpInterfaceConfigListener(DataBroker dataBroker,
+ DhcpExternalTunnelManager dhcpExternalTunnelManager, DhcpManager dhcpManager) {
super(Interface.class, DhcpInterfaceConfigListener.class);
this.dataBroker = dataBroker;
this.dhcpExternalTunnelManager = dhcpExternalTunnelManager;
+ this.dhcpManager = dhcpManager;
registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
dataStoreJobCoordinator = DataStoreJobCoordinator.getInstance();
}
@Override
protected void remove(InstanceIdentifier<Interface> identifier, Interface del) {
- DhcpInterfaceConfigRemoveJob job = new DhcpInterfaceConfigRemoveJob(dhcpExternalTunnelManager, dataBroker, del);
- dataStoreJobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(del.getName()), job, DhcpMConstants.RETRY_COUNT );
+ dataStoreJobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(del.getName()), () -> {
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ IfTunnel tunnelInterface = del.getAugmentation(IfTunnel.class);
+ IfL2vlan vlanInterface = del.getAugmentation(IfL2vlan.class);
+ String interfaceName = del.getName();
+ if (tunnelInterface != null && !tunnelInterface.isInternal()) {
+ IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
+ ParentRefs interfce = del.getAugmentation(ParentRefs.class);
+ if (interfce != null) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Calling handleTunnelStateDown for tunnelIp {} and interface {}",
+ tunnelIp, interfaceName);
+ }
+ dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp,
+ interfce.getDatapathNodeIdentifier(), futures);
+ return futures;
+ }
+ }
+ if (vlanInterface != null) {
+ WriteTransaction unbindTx = dataBroker.newWriteOnlyTransaction();
+ DhcpServiceUtils.unbindDhcpService(interfaceName, unbindTx);
+ futures.add(unbindTx.submit());
+ }
+ return futures;
+ }, DhcpMConstants.RETRY_COUNT );
}
@Override
@Override
protected void add(InstanceIdentifier<Interface> identifier, Interface add) {
+ dataStoreJobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(add.getName()), () -> {
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ String interfaceName = add.getName();
+ IfL2vlan vlanInterface = add.getAugmentation(IfL2vlan.class);
+ if (vlanInterface == null) {
+ return futures;
+ }
+ Port port = dhcpManager.getNeutronPort(interfaceName);
+ Subnet subnet = dhcpManager.getNeutronSubnet(port);
+ if (null != subnet && subnet.isEnableDhcp()) {
+ WriteTransaction bindServiceTx = dataBroker.newWriteOnlyTransaction();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Binding DHCP service for interface {}", interfaceName);
+ }
+ DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, bindServiceTx);
+ futures.add(bindServiceTx.submit());
+ }
+ return futures;
+ }, DhcpMConstants.RETRY_COUNT );
}
@Override
protected DhcpInterfaceConfigListener getDataTreeChangeListener() {
return DhcpInterfaceConfigListener.this;
}
-}
+}
\ No newline at end of file
import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
+
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.mdsalutil.MDSALDataStoreUtils;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
-import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager;
import org.opendaylight.netvirt.dhcpservice.DhcpManager;
import org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils;
private void installDhcpEntries(String interfaceName, BigInteger dpId, List<ListenableFuture<Void>> futures) {
String vmMacAddress = getAndUpdateVmMacAddress(interfaceName);
WriteTransaction flowTx = dataBroker.newWriteOnlyTransaction();
- WriteTransaction bindServiceTx = dataBroker.newWriteOnlyTransaction();
- DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, bindServiceTx);
dhcpManager.installDhcpEntries(dpId, vmMacAddress, flowTx);
- futures.add(bindServiceTx.submit());
futures.add(flowTx.submit());
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netvirt.dhcpservice.jobs;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Callable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class DhcpInterfaceConfigRemoveJob implements Callable<List<ListenableFuture<Void>>> {
-
- private static final Logger LOG = LoggerFactory.getLogger(DhcpInterfaceConfigRemoveJob.class);
- DhcpExternalTunnelManager dhcpExternalTunnelManager;
- DataBroker dataBroker;
- Interface iface;
-
- public DhcpInterfaceConfigRemoveJob(DhcpExternalTunnelManager dhcpExternalTunnelManager, DataBroker dataBroker,
- Interface iface) {
- super();
- this.dhcpExternalTunnelManager = dhcpExternalTunnelManager;
- this.dataBroker = dataBroker;
- this.iface = iface;
- }
-
- @Override
- public List<ListenableFuture<Void>> call() throws Exception {
- List<ListenableFuture<Void>> futures = new ArrayList<>();
- IfTunnel tunnelInterface = iface.getAugmentation(IfTunnel.class);
- if (tunnelInterface != null && !tunnelInterface.isInternal()) {
- IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
- ParentRefs interfce = iface.getAugmentation(ParentRefs.class);
- if (interfce != null) {
- LOG.trace("Calling handleTunnelStateDown for tunnelIp {} and interface {}", tunnelIp, iface.getName());
- dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp,
- interfce.getDatapathNodeIdentifier(), futures);
- }
- }
- return futures;
- }
-}
\ No newline at end of file