*/
package org.opendaylight.netvirt.elan.internal;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
import javax.inject.Inject;
import javax.inject.Singleton;
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.genius.infra.ManagedNewTransactionRunner;
import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.genius.mdsalutil.packet.Ethernet;
import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
import org.opendaylight.netvirt.elan.evpn.utils.EvpnUtils;
import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
import org.opendaylight.netvirt.elan.utils.ElanUtils;
-import org.opendaylight.openflowplugin.libraries.liblldp.NetUtils;
import org.opendaylight.openflowplugin.libraries.liblldp.PacketException;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
private final EvpnUtils evpnUtils;
private final JobCoordinator jobCoordinator;
private final ElanInstanceCache elanInstanceCache;
+ private final ElanManagerCounters elanManagerCounters;
@Inject
public ElanPacketInHandler(DataBroker dataBroker, final IInterfaceManager interfaceManager, ElanUtils elanUtils,
EvpnUtils evpnUtils, ElanL2GatewayUtils elanL2GatewayUtils, JobCoordinator jobCoordinator,
- ElanInstanceCache elanInstanceCache) {
+ ElanInstanceCache elanInstanceCache, ElanManagerCounters elanManagerCounters) {
this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
this.interfaceManager = interfaceManager;
this.elanUtils = elanUtils;
this.evpnUtils = evpnUtils;
this.jobCoordinator = jobCoordinator;
this.elanInstanceCache = elanInstanceCache;
+ this.elanManagerCounters = elanManagerCounters;
}
@Override
Class<? extends PacketInReason> pktInReason = notification.getPacketInReason();
short tableId = notification.getTableId().getValue();
if (pktInReason == NoMatch.class && tableId == NwConstants.ELAN_SMAC_TABLE) {
- ElanManagerCounters.unknown_smac_pktin_rcv.inc();
+ elanManagerCounters.unknownSmacPktinRcv();
try {
byte[] data = notification.getPayload();
Ethernet res = new Ethernet();
- res.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
+ res.deserialize(data, 0, data.length * Byte.SIZE);
byte[] srcMac = res.getSourceMACAddress();
final String macAddress = NWUtil.toStringMacAddress(srcMac);
MacEntry oldMacEntry, MacEntry newMacEntry,
final boolean isVlanOrFlatProviderIface) {
jobCoordinator.enqueueJob(ElanUtils.getElanMacKey(elanTag, macAddress),
- () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- if (oldMacEntry != null && oldMacEntry.getInterface().equals(interfaceName)) {
+ () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
+ if (oldMacEntry != null && Objects.equals(oldMacEntry.getInterface(), interfaceName)) {
// This should never occur because of ovs temporary mac learning
- ElanManagerCounters.unknown_smac_pktin_forwarding_entries_removed.inc();
+ elanManagerCounters.unknownSmacPktinForwardingEntriesRemoved();
} else if (oldMacEntry != null && !isVlanOrFlatProviderIface) {
long macTimeStamp = oldMacEntry.getControllerLearnedForwardingEntryTimestamp().longValue();
if (System.currentTimeMillis() > macTimeStamp + 1000) {
InstanceIdentifier<MacEntry> macEntryId = ElanUtils
.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName,
physAddress);
- tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryId);
+ tx.delete(macEntryId);
} else {
// New FEs flood their packets on all interfaces. This can lead
// to many contradicting packet_ins. Ignore all packets received
// within 1s after the first packet_in
- ElanManagerCounters.unknown_smac_pktin_mac_migration_ignored_due_to_protection.inc();
+ elanManagerCounters.unknownSmacPktinMacMigrationIgnoredDueToProtection();
}
} else if (oldMacEntry != null) {
- ElanManagerCounters.unknown_smac_pktin_removed_for_relearned.inc();
+ elanManagerCounters.unknownSmacPktinRemovedForRelearned();
}
// This check is required only to update elan-forwarding-tables when mac is learned
// in ports (example: VM interfaces) other than on vlan provider port.
if (!isVlanOrFlatProviderIface && oldMacEntry == null) {
InstanceIdentifier<MacEntry> elanMacEntryId =
ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress);
- tx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, newMacEntry,
- WriteTransaction.CREATE_MISSING_PARENTS);
+ tx.put(elanMacEntryId, newMacEntry, WriteTransaction.CREATE_MISSING_PARENTS);
}
})));
}
BigInteger dpId = interfaceManager.getDpnForInterface(interfaceName);
elanL2GatewayUtils.scheduleAddDpnMacInExtDevices(elanInstance.getElanInstanceName(), dpId,
Collections.singletonList(physAddress));
- ElanManagerCounters.unknown_smac_pktin_learned.inc();
- return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
- elanUtils.setupMacFlows(elanInstance, interfaceInfo, elanInstance.getMacTimeout(),
+ elanManagerCounters.unknownSmacPktinLearned();
+ List<ListenableFuture<Void>> futures = new ArrayList<>();
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, operTx -> {
+ elanUtils.setupMacFlows(elanInstance, interfaceInfo, elanInstance.getMacTimeout(),
macAddress, !isVlanOrFlatProviderIface, tx);
- InstanceIdentifier<MacEntry> macEntryId =
+ InstanceIdentifier<MacEntry> macEntryId =
ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
- tx.put(LogicalDatastoreType.OPERATIONAL, macEntryId, newMacEntry,
- WriteTransaction.CREATE_MISSING_PARENTS);
+ operTx.put(macEntryId, newMacEntry, WriteTransaction.CREATE_MISSING_PARENTS);
+ }));
}));
+ return futures;
});
}
private void macMigrationFlowsCleanup(String interfaceName, ElanInstance elanInstance, MacEntry macEntry,
boolean isVlanOrFlatProviderIface) {
- if (macEntry != null && !macEntry.getInterface().equals(interfaceName)
+ if (macEntry != null && !Objects.equals(macEntry.getInterface(), interfaceName)
&& !isVlanOrFlatProviderIface) {
tryAndRemoveInvalidMacEntry(elanInstance.getElanInstanceName(), macEntry);
- ElanManagerCounters.unknown_smac_pktin_flows_removed_for_relearned.inc();
+ elanManagerCounters.unknownSmacPktinFlowsRemovedForRelearned();
}
}
macEntry.getMacAddress(), macEntry.getInterface());
return;
}
- ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+ LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
tx -> elanUtils.deleteMacFlows(elanInfo, oldInterfaceLport, macEntry, tx)), LOG,
"Error deleting invalid MAC entry");
elanL2GatewayUtils.removeMacsFromElanExternalDevices(elanInfo,