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.jobs;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev170119.Tunnel;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
21 import org.opendaylight.yangtools.yang.common.Uint64;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class DhcpInterfaceUpdateJob implements Callable<List<? extends ListenableFuture<?>>> {
27 private static final Logger LOG = LoggerFactory.getLogger(DhcpInterfaceUpdateJob.class);
28 private final DhcpExternalTunnelManager dhcpExternalTunnelManager;
29 private final DataBroker dataBroker;
30 private final String interfaceName;
31 private final Uint64 dpnId;
32 private final OperStatus operStatus;
33 private final IInterfaceManager interfaceManager;
35 public DhcpInterfaceUpdateJob(DhcpExternalTunnelManager dhcpExternalTunnelManager,
36 DataBroker dataBroker, String interfaceName, Uint64 dpnId,
37 OperStatus operStatus, IInterfaceManager interfaceManager) {
38 this.dhcpExternalTunnelManager = dhcpExternalTunnelManager;
39 this.dataBroker = dataBroker;
40 this.interfaceName = interfaceName;
42 this.operStatus = operStatus;
43 this.interfaceManager = interfaceManager;
47 public List<ListenableFuture<Void>> call() {
48 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
49 interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
51 LOG.trace("Interface {} is not present in the config DS", interfaceName);
52 return Collections.emptyList();
54 if (Tunnel.class.equals(iface.getType())) {
55 IfTunnel tunnelInterface = iface.augmentation(IfTunnel.class);
56 if (tunnelInterface != null && !tunnelInterface.isInternal()) {
57 IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
58 if (operStatus == OperStatus.Down) {
59 return dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp, dpnId);
60 } else if (operStatus == OperStatus.Up) {
61 return dhcpExternalTunnelManager.handleTunnelStateUp(tunnelIp, dpnId);
65 return Collections.emptyList();