package org.opendaylight.netvirt.elan.utils;
import static java.util.Collections.emptyList;
-import static java.util.Objects.requireNonNull;
import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
-
+import edu.umd.cs.findbugs.annotations.CheckReturnValue;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
-
-import javax.annotation.CheckReturnValue;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.genius.infra.TypedReadWriteTransaction;
import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
-import org.opendaylight.genius.interfacemanager.globals.InterfaceServiceUtil;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.itm.api.IITMProvider;
import org.opendaylight.genius.itm.globals.ITMConstants;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeLeafTagNameBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanForwardingTables;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaceForwardingEntries;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaces;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanState;
*/
@Deprecated
@SuppressWarnings("checkstyle:IllegalCatch")
- public static <T extends DataObject> Optional<T> read(@Nonnull DataBroker broker,
+ public static <T extends DataObject> Optional<T> read(@NonNull DataBroker broker,
LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
return tx.read(datastoreType, path).get();
Futures.addCallback(tx.submit(), DEFAULT_CALLBACK, MoreExecutors.directExecutor());
}
- @SuppressWarnings("checkstyle:ForbidCertainMethod")
- public static <T extends DataObject> void delete(DataBroker broker, LogicalDatastoreType datastoreType,
- InstanceIdentifier<T> path, FutureCallback<Void> callback) {
- WriteTransaction tx = broker.newWriteOnlyTransaction();
- tx.delete(datastoreType, path);
- Futures.addCallback(tx.submit(), callback, MoreExecutors.directExecutor());
- }
-
- public static InstanceIdentifier<ElanInstance> getElanInstanceIdentifier() {
- return InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class).build();
- }
-
public static InstanceIdentifier<ElanInterface> getElanInterfaceConfigurationDataPathId(String interfaceName) {
return InstanceIdentifier.builder(ElanInterfaces.class)
.child(ElanInterface.class, new ElanInterfaceKey(interfaceName)).build();
return read(dataBroker, LogicalDatastoreType.OPERATIONAL, elanInterfaceId).orNull();
}
- /**
- * Gets the elan interface mac addresses.
- *
- * @param interfaceName
- * the interface name
- * @return the elan interface mac addresses
- */
- public List<PhysAddress> getElanInterfaceMacAddresses(String interfaceName) {
- List<PhysAddress> macAddresses = new ArrayList<>();
- ElanInterfaceMac elanInterfaceMac = getElanInterfaceMacByInterfaceName(interfaceName);
- if (elanInterfaceMac != null && elanInterfaceMac.getMacEntry() != null) {
- List<MacEntry> macEntries = elanInterfaceMac.getMacEntry();
- for (MacEntry macEntry : macEntries) {
- macAddresses.add(macEntry.getMacAddress());
- }
- }
- return macAddresses;
- }
-
public static InstanceIdentifier<ElanInterfaceMac> getElanInterfaceMacEntriesOperationalDataPath(
String interfaceName) {
return InstanceIdentifier.builder(ElanInterfaceForwardingEntries.class)
* the elan instance name
* @return list of dpIds
*/
- @Nonnull
+ @NonNull
public List<BigInteger> getParticipatingDpnsInElanInstance(String elanInstanceName) {
List<BigInteger> dpIds = new ArrayList<>();
InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanInstanceName);
if (!existingElanDpnInterfaces.isPresent()) {
return dpIds;
}
- List<DpnInterfaces> dpnInterfaces =
- requireNonNullElse(existingElanDpnInterfaces.get().getDpnInterfaces(), emptyList());
+ List<DpnInterfaces> dpnInterfaces = existingElanDpnInterfaces.get().nonnullDpnInterfaces();
for (DpnInterfaces dpnInterface : dpnInterfaces) {
dpIds.add(dpnInterface.getDpId());
}
return dpIds;
}
- /**
- * To check given dpId is already present in Elan instance. This can be used
- * to program flow entry in external tunnel table when a new access port
- * added for first time into the ELAN instance
- *
- * @param dpId
- * the dp id
- * @param elanInstanceName
- * the elan instance name
- * @return true if dpId is already present, otherwise return false
- */
- public boolean isDpnAlreadyPresentInElanInstance(BigInteger dpId, String elanInstanceName) {
- InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanInstanceName);
- Optional<ElanDpnInterfacesList> existingElanDpnInterfaces = read(broker,
- LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
- if (!existingElanDpnInterfaces.isPresent()) {
- return false;
- }
- List<DpnInterfaces> dpnInterfaces =
- requireNonNullElse(existingElanDpnInterfaces.get().getDpnInterfaces(), emptyList());
- for (DpnInterfaces dpnInterface : dpnInterfaces) {
- if (Objects.equals(dpnInterface.getDpId(), dpId)) {
- return true;
- }
- }
- return false;
- }
-
- @Nullable
- public ElanForwardingTables getElanForwardingList() {
- InstanceIdentifier<ElanForwardingTables> elanForwardingTableId = InstanceIdentifier
- .builder(ElanForwardingTables.class).build();
- return read(broker, LogicalDatastoreType.OPERATIONAL, elanForwardingTableId).orNull();
- }
-
public static long getElanRemoteBroadCastGroupID(long elanTag) {
return ElanConstants.ELAN_GID_MIN + elanTag % ElanConstants.ELAN_GID_MIN * 2;
}
* @return the egress actions for interface
*/
@SuppressWarnings("checkstyle:IllegalCatch")
- @Nonnull
+ @NonNull
public List<Action> getEgressActionsForInterface(String ifName, @Nullable Long tunnelKey) {
List<Action> listAction = new ArrayList<>();
try {
LOG.debug("RPC Call to Get egress actions for interface {} returned with Errors {}", ifName,
rpcResult.getErrors());
} else {
- listAction = requireNonNullElse(rpcResult.getResult().getAction(), emptyList());
+ listAction = rpcResult.getResult().nonnullAction();
}
} catch (Exception e) {
LOG.warn("Exception when egress actions for interface {}", ifName, e);
// TODO: Make sure that the same is performed against the ElanDevices.
}
- @Nonnull
+ @NonNull
public List<DpnInterfaces> getInvolvedDpnsInElan(String elanName) {
return getElanDPNByName(elanName);
}
- @Nonnull
+ @NonNull
public List<DpnInterfaces> getElanDPNByName(String elanInstanceName) {
InstanceIdentifier<ElanDpnInterfacesList> elanIdentifier = getElanDpnOperationDataPath(elanInstanceName);
return MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, elanIdentifier).toJavaUtil().map(
return read(broker, LogicalDatastoreType.CONFIGURATION, node).isPresent();
}
- public static ServicesInfo getServiceInfo(String elanInstanceName, String interfaceName) {
- return InterfaceServiceUtil.buildServiceInfo(elanInstanceName + "." + interfaceName,
- ElanConstants.ELAN_SERVICE_PRIORITY);
- }
-
public static String getElanServiceName(String elanName, String interfaceName) {
return "elan." + elanName + interfaceName;
}
* the data broker
* @return the interface state from oper ds
*/
- @Nullable
- public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceStateFromOperDS(
- String interfaceName, DataBroker dataBroker) {
- InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId = createInterfaceStateInstanceIdentifier(
- interfaceName);
- return MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, ifStateId).orNull();
+ public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state
+ .@Nullable Interface getInterfaceStateFromOperDS(String interfaceName, DataBroker dataBroker) {
+ return MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
+ createInterfaceStateInstanceIdentifier(interfaceName)).orNull();
}
/**
return idBuilder.build();
}
- @CheckReturnValue
- public static CheckedFuture<Void, TransactionCommitFailedException> waitForTransactionToComplete(
- WriteTransaction tx) {
- CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
- try {
- futures.get();
- } catch (InterruptedException | ExecutionException e) {
- // NETVIRT-1215: Do not log.error() here, only debug(); but callers *MUST* @CheckReturnValue
- LOG.debug("Error writing to datastore", e);
- }
- return futures;
- }
-
@CheckReturnValue
public static ListenableFuture<Void> waitForTransactionToComplete(ListenableFuture<Void> future) {
try {
new StaticMacEntriesKey(new PhysAddress(macAddress))).build();
}
- public static List<StaticMacEntries> getDeletedEntries(List<StaticMacEntries> originalStaticMacEntries,
- List<StaticMacEntries> updatedStaticMacEntries) {
- if (isEmpty(originalStaticMacEntries)) {
- return Collections.EMPTY_LIST;
- }
- List<StaticMacEntries> deleted = Lists.newArrayList(originalStaticMacEntries);
- if (isNotEmpty(updatedStaticMacEntries)) {
- deleted.removeAll(updatedStaticMacEntries);
- }
- return deleted;
- }
-
public static <T> List<T> diffOf(List<T> orig, List<T> updated) {
if (isEmpty(orig)) {
return Collections.EMPTY_LIST;
return diff;
}
- public static void segregateToBeDeletedAndAddEntries(List<StaticMacEntries> originalStaticMacEntries,
- List<StaticMacEntries> updatedStaticMacEntries) {
- if (isNotEmpty(updatedStaticMacEntries)) {
- List<StaticMacEntries> existingClonedStaticMacEntries = new ArrayList<>();
- if (isNotEmpty(originalStaticMacEntries)) {
- existingClonedStaticMacEntries.addAll(0, originalStaticMacEntries);
- originalStaticMacEntries.removeAll(updatedStaticMacEntries);
- updatedStaticMacEntries.removeAll(existingClonedStaticMacEntries);
- }
- }
- }
-
public static boolean isEmpty(Collection collection) {
return collection == null || collection.isEmpty();
}
return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:" + dpnId)))
.augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(new GroupId(groupId))).build();
}
-
- // Use Objects.requireNonNullElse instead with JDK9+
- @Nonnull
- public static <T> T requireNonNullElse(@Nullable T obj, @Nonnull T defaultObj) {
- return obj != null ? obj : requireNonNull(defaultObj);
- }
}