leaf port-fixedip { type string; }
leaf port-name { type string; }
leaf mac-address { type string; }
+ leaf creation-time { type string; }
}
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.AlivenessMonitorService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.LivenessState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorEvent;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
LivenessState livenessState = notification.getEventData().getMonitorState();
if (livenessState.equals(LivenessState.Down)) {
- DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
- coordinator.enqueueJob(ArpMonitoringHandler.buildJobKey(macEntry.getIpAddress().getHostAddress(),
- macEntry.getVpnName()),
- new ArpMonitorStopTask(macEntry, dataBroker, alivenessManager));
+ String vpnName = macEntry.getVpnName();
+ String learntIp = macEntry.getIpAddress().getHostAddress();
+ LearntVpnVipToPort vpnVipToPort = VpnUtil.getLearntVpnVipToPort(dataBroker, vpnName, learntIp);
+ if (vpnVipToPort != null && macEntry.getCreatedTime().equals(vpnVipToPort.getCreationTime())) {
+ DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
+ coordinator.enqueueJob(ArpMonitoringHandler.buildJobKey(macEntry.getIpAddress().getHostAddress(),
+ macEntry.getVpnName()), new ArpMonitorStopTask(macEntry, dataBroker, alivenessManager));
+ }
+
}
}
package org.opendaylight.netvirt.vpnmanager;
import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
+
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.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.AlivenessMonitorService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies;
@Override
public List<ListenableFuture<Void>> call() throws Exception {
final List<ListenableFuture<Void>> futures = new ArrayList<>();
- WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
java.util.Optional<Long> monitorIdOptional = AlivenessMonitorUtils.getMonitorIdFromInterface(macEntry);
- monitorIdOptional.ifPresent(aLong -> AlivenessMonitorUtils.stopArpMonitoring(alivenessManager, aLong));
- removeMipAdjacency(macEntry.getIpAddress().getHostAddress(),
- macEntry.getVpnName(), macEntry.getInterfaceName(), tx);
- VpnUtil.removeLearntVpnVipToPort(dataBroker, macEntry.getVpnName(),
- macEntry.getIpAddress().getHostAddress());
- CheckedFuture<Void, TransactionCommitFailedException> txFutures = tx.submit();
- try {
- txFutures.get();
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("Error writing to datastore {}", e);
- }
- futures.add(txFutures);
+ monitorIdOptional.ifPresent(monitorId -> {
+ AlivenessMonitorUtils.stopArpMonitoring(alivenessManager, monitorId);
+ removeMipAdjacency(macEntry.getIpAddress().getHostAddress(),
+ macEntry.getVpnName(), macEntry.getInterfaceName());
+ VpnUtil.removeLearntVpnVipToPort(dataBroker, macEntry.getVpnName(),
+ macEntry.getIpAddress().getHostAddress());
+ });
return futures;
}
- private void removeMipAdjacency(String fixedip, String vpnName, String interfaceName, WriteTransaction tx) {
+ private void removeMipAdjacency(String fixedip, String vpnName, String interfaceName) {
synchronized (interfaceName.intern()) {
InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
if (adjacencies.isPresent()) {
InstanceIdentifier<Adjacency> adid = vpnIfId.augmentation(Adjacencies.class).child(Adjacency.class,
new AdjacencyKey(ipToPrefix(fixedip)));
- tx.delete(LogicalDatastoreType.CONFIGURATION, adid);
- LOG.info("deleting the adjacencies for vpn {} interface {}", vpnName, interfaceName);
+ try {
+ SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adid);
+ } catch (TransactionCommitFailedException e) {
+ LOG.error("Failed to delete the learned-ip-adjacency for vpn {} interface {} prefix {}",
+ vpnName, interfaceName, ipToPrefix(fixedip), e);
+ return;
+ }
+ LOG.info("Successfully deleted the learned-ip-adjacency prefix {} on vpn {} for interface {}",
+ ipToPrefix(fixedip), vpnName, interfaceName);
}
}
}
}
MacAddress srcMacAddress = MacAddress.getDefaultInstance(value.getMacAddress());
String vpnName = value.getVpnName();
- String interfaceName = value.getPortName();
- MacEntry macEntry = new MacEntry(vpnName, srcMacAddress, srcInetAddr, interfaceName);
+ MacEntry macEntry = new MacEntry(vpnName, srcMacAddress, srcInetAddr, value.getPortName(),
+ value.getCreationTime());
DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
coordinator.enqueueJob(buildJobKey(srcInetAddr.toString(), vpnName),
new ArpMonitorStartTask(macEntry, arpMonitorProfileId, dataBroker, alivenessManager,
LOG.warn("The mac address received is null for LearntVpnVipToPort {}, ignoring the DTCN", value);
return;
}
- MacAddress srcMacAddress = MacAddress.getDefaultInstance(value.getMacAddress());
String vpnName = value.getVpnName();
+ String learntIp = srcInetAddr.getHostAddress();
+ LearntVpnVipToPort vpnVipToPort = VpnUtil.getLearntVpnVipToPort(dataBroker, vpnName, learntIp);
+ if (vpnVipToPort != null && !vpnVipToPort.getCreationTime().equals(value.getCreationTime())) {
+ LOG.warn("The MIP {} over vpn {} has been learnt again and processed. "
+ + "Ignoring this remove event.", learntIp, vpnName);
+ return;
+ }
+ MacAddress srcMacAddress = MacAddress.getDefaultInstance(value.getMacAddress());
String interfaceName = value.getPortName();
- MacEntry macEntry = new MacEntry(vpnName, srcMacAddress, srcInetAddr, interfaceName);
+ MacEntry macEntry = new MacEntry(vpnName, srcMacAddress, srcInetAddr, interfaceName,
+ value.getCreationTime());
DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
coordinator.enqueueJob(buildJobKey(srcInetAddr.toString(), vpnName),
new ArpMonitorStopTask(macEntry, dataBroker, alivenessManager));
new VpnInterfaceKey(vpnInterface)).augmentation(Adjacencies.class).child(Adjacency.class,
new AdjacencyKey(ip)).build();
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adjacencyIdentifier);
- LOG.trace("Successfully Deleted Adjacency into VpnInterface {}", vpnInterface);
+ LOG.info("Successfully deleted the learned-ip-adjacency for prefix {} on vpn {} for interface {}",
+ ip, vpnName, vpnInterface);
}
}
}
private MacAddress macAddress;
private InetAddress ipAddress;
private String interfaceName;
+ private String createdTime;
- public MacEntry(String vpnName, MacAddress macAddress,
- InetAddress inetAddress, String interfaceName) {
+ public MacEntry(String vpnName, MacAddress macAddress, InetAddress inetAddress,
+ String interfaceName, String createdTime) {
this.vpnName = vpnName;
this.macAddress = macAddress;
this.ipAddress = inetAddress;
this.interfaceName = interfaceName;
+ this.createdTime = createdTime;
}
public String getVpnName() {
return ipAddress;
}
+ public String getCreatedTime() {
+ return createdTime;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
return false;
} else {
MacEntry other = (MacEntry) obj;
- return vpnName.equals(other.vpnName) && macAddress.equals(other.macAddress)
- && ipAddress.equals(other.ipAddress) && interfaceName.equals(other.interfaceName);
+ return vpnName.equals(other.vpnName)
+ && macAddress.equals(other.macAddress)
+ && ipAddress.equals(other.ipAddress)
+ && interfaceName.equals(other.interfaceName)
+ && createdTime.equals(other.getCreatedTime());
}
}
@Override
public String toString() {
return "MacEntry [vpnName=" + vpnName + ", macAddress=" + macAddress + ", ipAddress=" + ipAddress
- + ", interfaceName=" + interfaceName + "]";
+ + ", interfaceName=" + interfaceName + ", createdTime=" + createdTime + "]";
}
}
import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
InstanceIdentifier<LearntVpnVipToPort> id = buildLearntVpnVipToPortIdentifier(vpnName, fixedIp);
LearntVpnVipToPortBuilder builder =
new LearntVpnVipToPortBuilder().setKey(new LearntVpnVipToPortKey(fixedIp, vpnName)).setVpnName(
- vpnName).setPortFixedip(fixedIp).setPortName(portName).setMacAddress(
- macAddress.toLowerCase());
+ vpnName).setPortFixedip(fixedIp).setPortName(portName)
+ .setMacAddress(macAddress.toLowerCase())
+ .setCreationTime(new SimpleDateFormat("MM/dd/yyyy h:mm:ss a").format(new Date()));
MDSALUtil.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, id, builder.build());
LOG.debug("ARP learned for fixedIp: {}, vpn {}, interface {}, mac {}, isSubnetIp {} added to "
+ "VpnPortipToPort DS", fixedIp, vpnName, portName, macAddress);