Fixup Augmentable and Identifiable methods changing
[netvirt.git] / dhcpservice / impl / src / main / java / org / opendaylight / netvirt / dhcpservice / jobs / DhcpInterfaceUpdateJob.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.dhcpservice.jobs;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.math.BigInteger;
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.concurrent.Callable;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
17 import org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager;
18 import org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 public class DhcpInterfaceUpdateJob implements Callable<List<ListenableFuture<Void>>> {
27
28     private static final Logger LOG = LoggerFactory.getLogger(DhcpInterfaceUpdateJob.class);
29     private final DhcpExternalTunnelManager dhcpExternalTunnelManager;
30     private final DataBroker dataBroker;
31     private final String interfaceName;
32     private final BigInteger dpnId;
33     private final OperStatus operStatus;
34     private final IInterfaceManager interfaceManager;
35
36     public DhcpInterfaceUpdateJob(DhcpExternalTunnelManager dhcpExternalTunnelManager,
37                                   DataBroker dataBroker, String interfaceName, BigInteger dpnId,
38                                   OperStatus operStatus, IInterfaceManager interfaceManager) {
39         this.dhcpExternalTunnelManager = dhcpExternalTunnelManager;
40         this.dataBroker = dataBroker;
41         this.interfaceName = interfaceName;
42         this.dpnId = dpnId;
43         this.operStatus = operStatus;
44         this.interfaceManager = interfaceManager;
45     }
46
47     @Override
48     public List<ListenableFuture<Void>> call() {
49         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
50                 interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
51         if (iface == null) {
52             LOG.trace("Interface {} is not present in the config DS", interfaceName);
53             return Collections.emptyList();
54         }
55         if (Tunnel.class.equals(iface.getType())) {
56             IfTunnel tunnelInterface = iface.augmentation(IfTunnel.class);
57             if (tunnelInterface != null && !tunnelInterface.isInternal()) {
58                 IpAddress tunnelIp = tunnelInterface.getTunnelDestination();
59                 List<BigInteger> dpns = DhcpServiceUtils.getListOfDpns(dataBroker);
60                 if (dpns.contains(dpnId)) {
61                     if (operStatus == OperStatus.Down) {
62                         return dhcpExternalTunnelManager.handleTunnelStateDown(tunnelIp, dpnId);
63                     } else if (operStatus == OperStatus.Up) {
64                         return dhcpExternalTunnelManager.handleTunnelStateUp(tunnelIp, dpnId);
65                     }
66                 }
67             }
68         }
69         return Collections.emptyList();
70     }
71 }