2 * Copyright © 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.netvirt.vpnmanager.iplearn;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import org.opendaylight.netvirt.vpnmanager.VpnUtil;
15 import org.opendaylight.netvirt.vpnmanager.iplearn.model.MacEntry;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class IpMonitorStopTask implements Callable<List<ListenableFuture<Void>>> {
21 private static final Logger LOG = LoggerFactory.getLogger(IpMonitorStopTask.class);
22 private MacEntry macEntry;
23 private final AlivenessMonitorUtils alivenessMonitorUtils;
24 private boolean isRemoveMipAdjAndLearntIp;
25 private final VpnUtil vpnUtil;
27 public IpMonitorStopTask(MacEntry macEntry, boolean removeMipAdjAndLearntIp, VpnUtil vpnUtil,
28 AlivenessMonitorUtils alivenessMonitorUtils) {
29 this.macEntry = macEntry;
30 this.alivenessMonitorUtils = alivenessMonitorUtils;
31 this.isRemoveMipAdjAndLearntIp = removeMipAdjAndLearntIp;
32 this.vpnUtil = vpnUtil;
36 public List<ListenableFuture<Void>> call() {
37 final List<ListenableFuture<Void>> futures = new ArrayList<>();
38 java.util.Optional<Long> monitorIdOptional = AlivenessMonitorUtils.getMonitorIdFromInterface(macEntry);
39 monitorIdOptional.ifPresent(monitorId -> {
40 alivenessMonitorUtils.stopIpMonitoring(monitorId);
43 String learntIp = macEntry.getIpAddress().getHostAddress();
44 if (this.isRemoveMipAdjAndLearntIp) {
45 String vpnName = macEntry.getVpnName();
46 LearntVpnVipToPort vpnVipToPort = vpnUtil.getLearntVpnVipToPort(vpnName, learntIp);
47 if (vpnVipToPort != null && !vpnVipToPort.getCreationTime().equals(macEntry.getCreatedTime())) {
48 LOG.warn("The MIP {} over vpn {} has been learnt again and processed. "
49 + "Ignoring this remove event.", learntIp, vpnName);
52 vpnUtil.removeMipAdjAndLearntIp(vpnName, macEntry.getInterfaceName(), learntIp);
54 // Delete only MIP adjacency
55 vpnUtil.removeMipAdjacency(macEntry.getInterfaceName(), learntIp);