package org.opendaylight.netvirt.aclservice.api;
import java.util.Collection;
+import javax.annotation.Nullable;
import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace;
MATCH_DESTINATION
}
- void notify(AclInterface port, AclInterface oldPort, Action action);
+ void notify(AclInterface port, @Nullable AclInterface oldPort, Action action);
void notifyAce(AclInterface port, Action action, String aclName, Ace ace);
import java.math.BigInteger;
import java.util.List;
import java.util.SortedSet;
+import javax.annotation.Nullable;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.port.subnets.port.subnet.SubnetInfo;
private BigInteger dpId;
private Long elanId;
private boolean portSecurityEnabled;
- private List<Uuid> securityGroups;
- private List<AllowedAddressPairs> allowedAddressPairs;
- private List<SubnetInfo> subnetInfo;
- private SortedSet<Integer> ingressRemoteAclTags;
- private SortedSet<Integer> egressRemoteAclTags;
+ private @Nullable List<Uuid> securityGroups;
+ private @Nullable List<AllowedAddressPairs> allowedAddressPairs;
+ private @Nullable List<SubnetInfo> subnetInfo;
+ private @Nullable SortedSet<Integer> ingressRemoteAclTags;
+ private @Nullable SortedSet<Integer> egressRemoteAclTags;
private boolean isMarkedForDelete;
private Builder() {
return this;
}
- public Builder securityGroups(List<Uuid> list) {
+ public Builder securityGroups(@Nullable List<Uuid> list) {
this.securityGroups = list == null ? null : ImmutableList.copyOf(list);
return this;
}
- public Builder allowedAddressPairs(List<AllowedAddressPairs> list) {
+ public Builder allowedAddressPairs(@Nullable List<AllowedAddressPairs> list) {
this.allowedAddressPairs = list == null ? null : ImmutableList.copyOf(list);
return this;
}
- public Builder subnetInfo(List<SubnetInfo> list) {
+ public Builder subnetInfo(@Nullable List<SubnetInfo> list) {
this.subnetInfo = list == null ? null : ImmutableList.copyOf(list);
return this;
}
- public Builder ingressRemoteAclTags(SortedSet<Integer> list) {
+ public Builder ingressRemoteAclTags(@Nullable SortedSet<Integer> list) {
this.ingressRemoteAclTags = list == null ? null : ImmutableSortedSet.copyOf(list);
return this;
}
- public Builder egressRemoteAclTags(SortedSet<Integer> list) {
+ public Builder egressRemoteAclTags(@Nullable SortedSet<Integer> list) {
this.egressRemoteAclTags = list == null ? null : ImmutableSortedSet.copyOf(list);
return this;
}
import java.util.Set;
import java.util.SortedSet;
import java.util.stream.Collectors;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.genius.infra.Datastore;
import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
continue;
}
AccessListEntries accessListEntries = acl.getAccessListEntries();
- List<Ace> aceList = accessListEntries.getAce();
- for (Ace ace: aceList) {
- programAceRule(port, aclUuid.getValue(), ace, addOrRemove);
+ if (accessListEntries != null && accessListEntries.getAce() != null) {
+ for (Ace ace: accessListEntries.getAce()) {
+ programAceRule(port, aclUuid.getValue(), ace, addOrRemove);
+ }
}
}
return true;
* @param addOrRemove whether to delete or add flow
*/
protected void programAceRule(AclInterface port, String aclName, Ace ace, int addOrRemove) {
- SecurityRuleAttr aceAttr = AclServiceUtils.getAccesssListAttributes(ace);
+ SecurityRuleAttr aceAttr = AclServiceUtils.getAccessListAttributes(ace);
if (!isValidDirection(aceAttr.getDirection())) {
LOG.trace("Ignoring {} direction while processing for {} ACE Rule {}", aceAttr.getDirection(),
this.directionString, ace.getRuleName());
port.getInterfaceId());
Matches matches = ace.getMatches();
- Map<String, List<MatchInfoBase>> flowMap = null;
- if (matches.getAceType() instanceof AceIp) {
- flowMap = AclServiceOFFlowBuilder.programIpFlow(matches);
+ if (matches != null && matches.getAceType() instanceof AceIp) {
+ Map<String, List<MatchInfoBase>> flowMap = AclServiceOFFlowBuilder.programIpFlow(matches);
if (!AclServiceUtils.doesAceHaveRemoteGroupId(aceAttr)) {
// programming for ACE which doesn't have any remote group Id
programForAceNotHavingRemoteAclId(port, aclName, ace, flowMap, addOrRemove);
}
protected void programForAceNotHavingRemoteAclId(AclInterface port, String aclName, Ace ace,
- Map<String, List<MatchInfoBase>> flowMap, int addOrRemove) {
+ @Nullable Map<String, List<MatchInfoBase>> flowMap, int addOrRemove) {
if (null == flowMap) {
return;
}
}
protected void programAceSpecificFlows(AclInterface port, String aclName, Ace ace,
- Map<String, List<MatchInfoBase>> flowMap, Uuid remoteAclId, int addOrRemove) {
+ @Nullable Map<String, List<MatchInfoBase>> flowMap, Uuid remoteAclId, int addOrRemove) {
if (null == flowMap) {
return;
}
protected void handleRemoteAclUpdate(Acl aclBefore, Acl aclAfter, Collection<AclInterface> portsBefore) {
String aclName = aclAfter.getAclName();
Collection<AclInterface> interfaceList = aclDataUtil.getInterfaceList(new Uuid(aclName));
- if (interfaceList == null || interfaceList.isEmpty()) {
+ if (interfaceList.isEmpty()) {
LOG.trace("handleRemoteAclUpdate: No interfaces found with ACL={}", aclName);
return;
}
private void programRemoteAclTable(String aclName, Set<Uuid> remoteAclIds, Set<BigInteger> dpns, int addOrRemove) {
for (Uuid remoteAclId : remoteAclIds) {
Collection<AclInterface> remoteAclInterfaces = aclDataUtil.getInterfaceList(remoteAclId);
- if (remoteAclInterfaces == null || remoteAclInterfaces.isEmpty()) {
+ if (remoteAclInterfaces.isEmpty()) {
continue;
}
Set<AllowedAddressPairs> aaps =
private void syncRemoteAclTableFromOtherDpns(AclInterface port, Uuid remoteAclId, int addOrRemove) {
Collection<AclInterface> aclInterfaces = aclDataUtil.getInterfaceList(remoteAclId);
- if (aclInterfaces != null && !aclInterfaces.isEmpty() && isFirstPortInDpnWithRemoteAclId(port, remoteAclId)) {
+ if (!aclInterfaces.isEmpty() && isFirstPortInDpnWithRemoteAclId(port, remoteAclId)) {
Integer aclTag = aclServiceUtils.getAclTag(remoteAclId);
for (AclInterface aclInterface : aclInterfaces) {
if (port.getInterfaceId().equals(aclInterface.getInterfaceId())) {
protected abstract void programRemoteAclTableFlow(BigInteger dpId, Integer aclTag, AllowedAddressPairs aap,
int addOrRemove);
- protected Set<BigInteger> collectDpns(Map<String, Set<AclInterface>> mapAclWithPortSet) {
+ protected Set<BigInteger> collectDpns(@Nullable Map<String, Set<AclInterface>> mapAclWithPortSet) {
Set<BigInteger> dpns = new HashSet<>();
if (mapAclWithPortSet == null) {
return dpns;
AclConstants.COOKIE_ACL_BASE, matches, instructions, addOrRemove);
}
+ @Nullable
protected Long getElanIdFromAclInterface(String elanInterfaceName) {
AclInterface aclInterface = aclInterfaceCache.get(elanInterfaceName);
if (null != aclInterface) {
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.inject.Singleton;
import org.opendaylight.netvirt.aclservice.api.AclInterfaceCache;
import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
}
@Override
+ @Nullable
public AclInterface remove(String interfaceId) {
AclInterface aclInterface = cache.get(interfaceId);
if (aclInterface == null) {
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
// Find and update deleted ace rules in acl
List<Ace> deletedAceRules = getChangedAceList(aclBefore, aclAfter);
- if (interfacesBefore != null && aclClusterUtil.isEntityOwner()) {
+ if (aclClusterUtil.isEntityOwner()) {
LOG.debug("On update event, remove Ace rules: {} for ACL: {}", deletedAceRules, aclName);
updateAceRules(interfacesBefore, aclName, deletedAceRules, AclServiceManager.Action.REMOVE);
}
updateAclCaches(aclBefore, aclAfter, interfacesBefore);
- if (interfacesBefore != null && aclClusterUtil.isEntityOwner()) {
+ if (aclClusterUtil.isEntityOwner()) {
LOG.debug("On update event, add Ace rules: {} for ACL: {}", addedAceRules, aclName);
updateAceRules(interfacesBefore, aclName, addedAceRules, AclServiceManager.Action.ADD);
* @param aclName the acl name
* @param action the action
*/
- private void updateRemoteAclCache(List<Ace> aceList, String aclName, AclServiceManager.Action action) {
+ private void updateRemoteAclCache(@Nullable List<Ace> aceList, String aclName, AclServiceManager.Action action) {
if (null == aceList) {
return;
}
return this;
}
+ @Nonnull
private List<Ace> getChangedAceList(Acl updatedAcl, Acl currentAcl) {
if (updatedAcl == null) {
- return null;
+ return Collections.emptyList();
}
- List<Ace> updatedAceList = updatedAcl.getAccessListEntries() == null ? new ArrayList<>()
+ List<Ace> updatedAceList =
+ updatedAcl.getAccessListEntries() == null || updatedAcl.getAccessListEntries().getAce() == null
+ ? new ArrayList<>()
: new ArrayList<>(updatedAcl.getAccessListEntries().getAce());
if (currentAcl == null) {
return updatedAceList;
}
- List<Ace> currentAceList = currentAcl.getAccessListEntries() == null ? new ArrayList<>()
+ List<Ace> currentAceList =
+ currentAcl.getAccessListEntries() == null || currentAcl.getAccessListEntries().getAce() == null
+ ? new ArrayList<>()
: new ArrayList<>(currentAcl.getAccessListEntries().getAce());
for (Iterator<Ace> iterator = updatedAceList.iterator(); iterator.hasNext();) {
Ace ace1 = iterator.next();
for (Ace ace2 : currentAceList) {
- if (ace1.getRuleName().equals(ace2.getRuleName())) {
+ if (Objects.equals(ace1.getRuleName(), ace2.getRuleName())) {
iterator.remove();
}
}
package org.opendaylight.netvirt.aclservice.listeners;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
}
@Override
- public void update(InstanceIdentifier<Interface> key, Interface portBefore, Interface portAfter) {
+ public void update(@Nullable InstanceIdentifier<Interface> key, Interface portBefore, Interface portAfter) {
if (portBefore.augmentation(ParentRefs.class) == null
&& portAfter.augmentation(ParentRefs.class) != null) {
LOG.trace("Ignoring event for update in ParentRefs for {} ", portAfter.getName());
isPortSecurityEnable);
aclServiceManager.notify(aclInterfaceAfter, null, Action.UNBIND);
}
- if (interfaceState != null && interfaceState.getOperStatus().equals(
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces
- .state.Interface.OperStatus.Up)) {
+ if (interfaceState != null && org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces
+ .rev140508.interfaces.state.Interface.OperStatus.Up.equals(interfaceState.getOperStatus())) {
// if port security enable is changed and is enabled, bind ACL service
if (isPortSecurityEnableBefore != isPortSecurityEnable && isPortSecurityEnable) {
LOG.debug("Notify bind ACL service for interface={}, isPortSecurityEnable={}", interfaceId,
&& aclInPortAfter.isPortSecurityEnabled();
}
- private boolean isSecurityGroupsChanged(List<Uuid> sgsBefore, List<Uuid> sgsAfter) {
+ private boolean isSecurityGroupsChanged(@Nullable List<Uuid> sgsBefore, @Nullable List<Uuid> sgsAfter) {
if (sgsBefore == null && sgsAfter == null) {
return false;
}
- if ((sgsBefore == null && sgsAfter != null) || (sgsBefore != null && sgsAfter == null)) {
+ if (sgsBefore == null || sgsAfter == null) {
return true;
}
- if (sgsBefore != null && sgsAfter != null) {
- return !(new HashSet<>(sgsBefore)).equals(new HashSet<>(sgsAfter));
- }
- return true;
+ return !(sgsBefore.containsAll(sgsAfter) && sgsAfter.containsAll(sgsBefore));
}
private AclInterface addOrUpdateAclInterfaceCache(String interfaceId, InterfaceAcl aclInPort) {
}
private AclInterface addOrUpdateAclInterfaceCache(String interfaceId, InterfaceAcl aclInPort, boolean isSgChanged,
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state
- .Interface interfaceState) {
+ @Nullable org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces
+ .state.Interface interfaceState) {
AclInterface aclInterface = aclInterfaceCache.addOrUpdate(interfaceId, (prevAclInterface, builder) -> {
List<Uuid> sgs = new ArrayList<>();
if (aclInPort != null) {
import java.math.BigInteger;
import java.util.Collections;
+import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
private final AclServiceUtils aclServiceUtils;
private final JobCoordinator jobCoordinator;
+ @Nullable
private SecurityGroupMode securityGroupMode = null;
@Inject
Interface interfaceBefore = interfaceOptional.get();
LOG.debug("Starting Recovery of acl Instance {} for interface {}", entityId, interfaceBefore.getName());
InterfaceAcl interfaceAclBefore = interfaceBefore.augmentation(InterfaceAcl.class);
- List<Uuid> sgList = new ArrayList<>(interfaceAclBefore.getSecurityGroups());
+ List<Uuid> sgList = interfaceAclBefore.getSecurityGroups() != null ? new ArrayList<>(
+ interfaceAclBefore.getSecurityGroups()) : new ArrayList<>();
sgList.remove(aclId);
InterfaceAcl interfaceAclAfter = new InterfaceAclBuilder(interfaceAclBefore).setSecurityGroups(sgList)
.build();
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.genius.mdsalutil.MetaDataUtil;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.netvirt.aclservice.utils.AclConstants;
+import org.opendaylight.netvirt.aclservice.utils.AclDataUtil;
import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.acl.drop.stats.BytesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.acl.drop.stats.PacketsBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @param dataBroker the data broker
* @return the acl port stats
*/
- public static List<AclPortStats> getAclPortStats(Direction direction, List<String> interfaceNames,
+ public static List<AclPortStats> getAclPortStats(Direction direction, @Nullable List<String> interfaceNames,
OpendaylightDirectStatisticsService odlDirectStatsService, DataBroker dataBroker) {
LOG.trace("Get ACL port stats for direction {} and interfaces {}", direction, interfaceNames);
List<AclPortStats> lstAclPortStats = new ArrayList<>();
FlowCookie aclDropFlowCookieMask = new FlowCookie(COOKIE_ACL_DROP_FLOW_MASK);
- for (String interfaceName : interfaceNames) {
+ for (String interfaceName : AclDataUtil.requireNonNullElse(interfaceNames, Collections.<String>emptyList())) {
AclPortStatsBuilder aclStatsBuilder = new AclPortStatsBuilder().setInterfaceName(interfaceName);
Interface interfaceState = AclServiceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
* @param rpcResult the rpc result
*/
private static void handleRpcErrors(List<AclPortStats> lstAclPortStats, AclPortStatsBuilder aclStatsBuilder,
- RpcResult<GetFlowStatisticsOutput> rpcResult) {
+ @Nullable RpcResult<GetFlowStatisticsOutput> rpcResult) {
LOG.error("Unable to retrieve drop counts due to error: {}", rpcResult);
String errMsg = "Unable to retrieve drop counts due to error: ";
- if (rpcResult != null && rpcResult.getErrors() != null) {
- for (RpcError error : rpcResult.getErrors()) {
- errMsg += error.getMessage();
- break;
- }
+ if (rpcResult != null && rpcResult.getErrors() != null && !rpcResult.getErrors().isEmpty()) {
+ errMsg += rpcResult.getErrors().iterator().next().getMessage();
} else {
errMsg += "Internal RPC call failed.";
}
for (FlowAndStatisticsMapList flowStats : flowAndStatisticsMapList) {
switch (flowStats.getTableId()) {
case NwConstants.INGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE:
- if (flowStats.getPriority().equals(AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY)) {
+ if (AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY.equals(flowStats.getPriority())) {
portEgressBytesBuilder.setInvalidDropCount(flowStats.getByteCount().getValue());
portEgressPacketsBuilder.setInvalidDropCount(flowStats.getPacketCount().getValue());
- } else if (flowStats.getPriority().equals(AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY)
- || flowStats.getPriority().equals(AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY)) {
+ } else if (AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY.equals(flowStats.getPriority())
+ || AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY.equals(flowStats.getPriority())) {
BigInteger portEgressBytesBuilderDropCount = BigInteger.valueOf(0);
BigInteger portEgressPacketsBuilderDropCount = BigInteger.valueOf(0);
if (portEgressBytesBuilder.getDropCount() != null) {
break;
case NwConstants.EGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE:
- if (flowStats.getPriority().equals(AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY)) {
+ if (AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY.equals(flowStats.getPriority())) {
portIngressBytesBuilder.setInvalidDropCount(flowStats.getByteCount().getValue());
portIngressPacketsBuilder.setInvalidDropCount(flowStats.getPacketCount().getValue());
- } else if (flowStats.getPriority().equals(AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY)
- || flowStats.getPriority().equals(AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY)) {
+ } else if (AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY.equals(flowStats.getPriority())
+ || AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY.equals(flowStats.getPriority())) {
BigInteger portIngressBytesBuilderDropCount = BigInteger.valueOf(0);
BigInteger portIngressPacketsBuilderDropCount = BigInteger.valueOf(0);
if (portIngressBytesBuilder.getDropCount() != null) {
// TODO: Update stats for other drops
break;
case NwConstants.INGRESS_ACL_COMMITTER_TABLE:
- if (flowStats.getPriority().equals(AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY)) {
+ if (AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY.equals(flowStats.getPriority())) {
portEgressBytesBuilder.setAntiSpoofDropCount(flowStats.getByteCount().getValue());
portEgressPacketsBuilder.setAntiSpoofDropCount(flowStats.getPacketCount().getValue());
}
break;
case NwConstants.EGRESS_ACL_COMMITTER_TABLE:
- if (flowStats.getPriority().equals(AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY)) {
+ if (AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY.equals(flowStats.getPriority())) {
portIngressBytesBuilder.setAntiSpoofDropCount(flowStats.getByteCount().getValue());
portIngressPacketsBuilder.setAntiSpoofDropCount(flowStats.getPacketCount().getValue());
}
package org.opendaylight.netvirt.aclservice.utils;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import java.math.BigInteger;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.inject.Singleton;
import org.opendaylight.netvirt.aclservice.api.utils.AclDataCache;
import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
}
@Override
+ @Nonnull
public Collection<AclInterface> getInterfaceList(Uuid acl) {
final ConcurrentMap<String, AclInterface> interfaceMap = aclInterfaceMap.get(acl);
return interfaceMap != null ? interfaceMap.values() : Collections.emptySet();
* @return the set of ACL interfaces per ACL (in a map) which has specified
* remote ACL ID.
*/
+ @Nullable
public Map<String, Set<AclInterface>> getRemoteAclInterfaces(Uuid remoteAclId,
Class<? extends DirectionBase> direction) {
Collection<Uuid> remoteAclList = getRemoteAcl(remoteAclId, direction);
Map<String, Set<AclInterface>> mapOfAclWithInterfaces = new HashMap<>();
for (Uuid acl : remoteAclList) {
- Set<AclInterface> interfaceSet = new HashSet<>();
Collection<AclInterface> interfaces = getInterfaceList(acl);
- if (interfaces != null && !interfaces.isEmpty()) {
- interfaceSet.addAll(interfaces);
+ if (!interfaces.isEmpty()) {
+ Set<AclInterface> interfaceSet = new HashSet<>(interfaces);
mapOfAclWithInterfaces.put(acl.getValue(), interfaceSet);
}
}
public Map<String, Acl> getAclMap() {
return ImmutableMap.copyOf(aclMap);
}
+
+ // Use Objects.requireNonNullElse instead with JDK9+
+ @Nonnull
+ public static <T> T requireNonNullElse(@Nullable T obj, @Nonnull T defaultObj) {
+ return obj != null ? obj : requireNonNull(defaultObj);
+ }
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import javax.annotation.Nullable;
import org.opendaylight.genius.infra.Datastore.Configuration;
import org.opendaylight.genius.infra.TypedWriteTransaction;
import org.opendaylight.genius.mdsalutil.ActionInfo;
addGotoOrResubmitTableMissFlow(tableId, nextTableId, null);
}
- private void addGotoOrResubmitTableMissFlow(short tableId, short nextTableId, List<InstructionInfo> instructions) {
+ private void addGotoOrResubmitTableMissFlow(short tableId, short nextTableId,
+ @Nullable List<InstructionInfo> instructions) {
List<MatchInfoBase> matches = Collections.emptyList();
List<InstructionInfo> ins = getGotoOrResubmitInstructions(tableId, nextTableId);
if (instructions != null && !instructions.isEmpty()) {
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiFunction;
+import javax.annotation.Nullable;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
import org.opendaylight.genius.mdsalutil.MatchInfoBase;
* the matches
* @return the map containing the flows and the respective flow id
*/
+ @Nullable
public static Map<String, List<MatchInfoBase>> programIpFlow(Matches matches) {
if (matches != null) {
AceIp acl = (AceIp) matches.getAceType();
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
* @param interfaceName the interface name.
* @return the interface state.
*/
+ @Nullable
public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state
.Interface getInterfaceStateFromOperDS(DataBroker dataBroker, String interfaceName) {
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508
* @param ace the access list entry
* @return the security rule attributes
*/
- public static SecurityRuleAttr getAccesssListAttributes(Ace ace) {
+ @Nullable
+ public static SecurityRuleAttr getAccessListAttributes(Ace ace) {
if (ace == null) {
LOG.error("Ace is Null");
return null;
return newAclList;
}
+ @Nullable
public static List<AllowedAddressPairs> getUpdatedAllowedAddressPairs(
- List<AllowedAddressPairs> updatedAllowedAddressPairs,
- List<AllowedAddressPairs> currentAllowedAddressPairs) {
+ @Nullable List<AllowedAddressPairs> updatedAllowedAddressPairs,
+ @Nullable List<AllowedAddressPairs> currentAllowedAddressPairs) {
if (updatedAllowedAddressPairs == null) {
return null;
}
return newAllowedAddressPairs;
}
+ @Nullable
public static BigInteger getDpIdFromIterfaceState(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
.interfaces.rev140508.interfaces.state.Interface interfaceState) {
BigInteger dpId = null;
return isNotIpv4AllNetwork(aap) && isNotIpv6AllNetwork(aap);
}
- public static Long getElanIdFromInterface(String elanInterfaceName,DataBroker broker) {
+ @Nullable
+ public static Long getElanIdFromInterface(String elanInterfaceName, DataBroker broker) {
ElanInterface elanInterface = getElanInterfaceByElanInterfaceName(elanInterfaceName, broker);
if (null != elanInterface) {
ElanInstance elanInfo = getElanInstanceByName(elanInterface.getElanInstanceName(), broker);
return null;
}
+ @Nullable
public static ElanInterface getElanInterfaceByElanInterfaceName(String elanInterfaceName,DataBroker broker) {
InstanceIdentifier<ElanInterface> elanInterfaceId = getElanInterfaceConfigurationDataPathId(elanInterfaceName);
return read(broker, LogicalDatastoreType.CONFIGURATION, elanInterfaceId).orNull();
}
// elan-instances config container
+ @Nullable
public static ElanInstance getElanInstanceByName(String elanInstanceName, DataBroker broker) {
InstanceIdentifier<ElanInstance> elanIdentifierId = getElanInstanceConfigurationDataPath(elanInstanceName);
return read(broker, LogicalDatastoreType.CONFIGURATION, elanIdentifierId).orNull();
.child(ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build();
}
+ @Nullable
public List<SubnetInfo> getSubnetInfo(String portId) {
InstanceIdentifier<PortSubnet> id = InstanceIdentifier.builder(PortSubnets.class)
.child(PortSubnet.class, new PortSubnetKey(portId)).build();
* @param aclId the acl id
* @return the acl tag
*/
+ @Nullable
public Integer getAclTag(final Uuid aclId) {
String aclName = aclId.getValue();
Integer aclTag = this.aclDataUtil.getAclTag(aclName);
return aceAttr != null && aceAttr.getRemoteGroupId() != null;
}
- public SortedSet<Integer> getRemoteAclTags(List<Uuid> aclIds, Class<? extends DirectionBase> direction) {
+ public SortedSet<Integer> getRemoteAclTags(@Nullable List<Uuid> aclIds, Class<? extends DirectionBase> direction) {
SortedSet<Integer> remoteAclTags = new TreeSet<>();
Set<Uuid> remoteAclIds = getRemoteAclIdsByDirection(aclIds, direction);
for (Uuid remoteAclId : remoteAclIds) {
return remoteAclTags;
}
- public Set<Uuid> getRemoteAclIdsByDirection(List<Uuid> aclIds, Class<? extends DirectionBase> direction) {
+ public Set<Uuid> getRemoteAclIdsByDirection(@Nullable List<Uuid> aclIds, Class<? extends DirectionBase> direction) {
Set<Uuid> remoteAclIds = new HashSet<>();
if (aclIds == null || aclIds.isEmpty()) {
return remoteAclIds;
AccessListEntries accessListEntries = acl.getAccessListEntries();
if (accessListEntries != null && accessListEntries.getAce() != null) {
for (Ace ace : accessListEntries.getAce()) {
- SecurityRuleAttr aceAttr = AclServiceUtils.getAccesssListAttributes(ace);
- if (aceAttr.getDirection().equals(direction) && doesAceHaveRemoteGroupId(aceAttr)) {
+ SecurityRuleAttr aceAttr = AclServiceUtils.getAccessListAttributes(ace);
+ if (Objects.equals(aceAttr.getDirection(), direction) && doesAceHaveRemoteGroupId(aceAttr)) {
remoteAclIds.add(aceAttr.getRemoteGroupId());
}
}
return instructions;
}
- public static List<AllowedAddressPairs> excludeMulticastAAPs(List<AllowedAddressPairs> allowedAddresses) {
+ public static List<AllowedAddressPairs> excludeMulticastAAPs(@Nullable List<AllowedAddressPairs> allowedAddresses) {
List<AllowedAddressPairs> filteredAAPs = new ArrayList<>();
- for (AllowedAddressPairs allowedAddress : allowedAddresses) {
- InetAddress inetAddr = getInetAddress(allowedAddress.getIpAddress());
- if (inetAddr != null && !inetAddr.isMulticastAddress()) {
- filteredAAPs.add(allowedAddress);
+ if (allowedAddresses != null) {
+ for (AllowedAddressPairs allowedAddress : allowedAddresses) {
+ InetAddress inetAddr = getInetAddress(allowedAddress.getIpAddress());
+ if (inetAddr != null && !inetAddr.isMulticastAddress()) {
+ filteredAAPs.add(allowedAddress);
+ }
}
}
return filteredAAPs;
return NetvirtAcl.class.toString();
}
+ @Nullable
private static InetAddress getInetAddress(IpPrefixOrAddress ipPrefixOrAddress) {
- InetAddress inetAddress = null;
- String addr = null;
+ String addr;
IpPrefix ipPrefix = ipPrefixOrAddress.getIpPrefix();
if (ipPrefix != null) {
}
}
try {
- inetAddress = InetAddress.getByName(addr);
+ return InetAddress.getByName(addr);
} catch (UnknownHostException e) {
LOG.error("Invalid address : {}", addr, e);
return null;
}
- return inetAddress;
}
public static Boolean isIpv6Subnet(List<SubnetInfo> subnetInfoList) {