2 * Copyright (c) 2016, 2017 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.genius.itm.confighelpers;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.ArrayList;
12 import java.util.Collection;
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.itm.cache.DPNTEPsInfoCache;
17 import org.opendaylight.genius.itm.impl.ItmUtils;
18 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPoints;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.dc.gateway.ip.list.DcGatewayIp;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.TransportZone;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class ItmTepRemoveWorker implements Callable<List<ListenableFuture<Void>>> {
28 private static final Logger LOG = LoggerFactory.getLogger(ItmTepRemoveWorker.class);
30 private final DataBroker dataBroker;
31 private final List<DPNTEPsInfo> delDpnList ;
32 private Collection<DPNTEPsInfo> meshedDpnList ;
33 private final IMdsalApiManager mdsalManager;
34 private final List<HwVtep> cfgdHwVteps;
35 private final TransportZone originalTZone;
36 private final ItmInternalTunnelDeleteWorker itmInternalTunnelDeleteWorker;
37 private final DPNTEPsInfoCache dpnTEPsInfoCache;
39 public ItmTepRemoveWorker(List<DPNTEPsInfo> delDpnList, List<HwVtep> delHwList, TransportZone originalTZone,
40 DataBroker broker, IMdsalApiManager mdsalManager,
41 ItmInternalTunnelDeleteWorker itmInternalTunnelDeleteWorker, DPNTEPsInfoCache dpnTEPsInfoCache) {
42 this.delDpnList = delDpnList;
43 this.dataBroker = broker;
44 this.mdsalManager = mdsalManager;
45 this.cfgdHwVteps = delHwList;
46 this.originalTZone = originalTZone;
47 this.itmInternalTunnelDeleteWorker = itmInternalTunnelDeleteWorker;
48 this.dpnTEPsInfoCache = dpnTEPsInfoCache;
49 LOG.trace("ItmTepRemoveWorker initialized with DpnList {}", delDpnList);
50 LOG.trace("ItmTepRemoveWorker initialized with cfgdHwTeps {}", delHwList);
54 public List<ListenableFuture<Void>> call() {
55 List<ListenableFuture<Void>> futures = new ArrayList<>() ;
56 this.meshedDpnList = dpnTEPsInfoCache.getAllPresent();
57 futures.addAll(itmInternalTunnelDeleteWorker.deleteTunnels(mdsalManager, delDpnList,
59 LOG.debug("Invoking Internal Tunnel delete method with DpnList to be deleted {} ; Meshed DpnList {} ",
60 delDpnList, meshedDpnList);
61 // IF EXTERNAL TUNNELS NEEDS TO BE DELETED, DO IT HERE, IT COULD BE TO DC GATEWAY OR TOR SWITCH
62 List<DcGatewayIp> dcGatewayIpList = ItmUtils.getDcGatewayIpList(dataBroker);
63 if (dcGatewayIpList != null && !dcGatewayIpList.isEmpty()) {
64 List<DPNTEPsInfo> dpnDeleteList = new ArrayList<>();
65 for (DPNTEPsInfo dpnTEPInfo : delDpnList) {
66 List<TunnelEndPoints> tunnelEndPointsList = dpnTEPInfo.getTunnelEndPoints();
67 if (tunnelEndPointsList.size() == 1) {
68 dpnDeleteList.add(dpnTEPInfo);
70 LOG.error("DPNTEPInfo not available in data store for dpnId {}. Unable to delete external tunnel "
71 + "for dpn ", dpnTEPInfo.getDPNID());
74 for (DcGatewayIp dcGatewayIp : dcGatewayIpList) {
75 futures.addAll(ItmExternalTunnelDeleteWorker.deleteTunnels(dataBroker,
76 dpnDeleteList , meshedDpnList, dcGatewayIp.getIpAddress(), dcGatewayIp.getTunnnelType()));
80 futures.addAll(ItmExternalTunnelDeleteWorker.deleteHwVtepsTunnels(dataBroker, delDpnList,
81 cfgdHwVteps, this.originalTZone));
86 public String toString() {
87 return "ItmTepRemoveWorker { "
88 + "Delete Dpn List : " + delDpnList + " }" ;