package org.opendaylight.netvirt.sfc.classifier.providers;
+import static org.opendaylight.netvirt.sfc.classifier.utils.SfcUtils.nullToEmpty;
+
import com.google.common.net.InetAddresses;
import java.math.BigInteger;
import java.util.Collections;
}
Class<? extends InterfaceTypeBase> ifType = tp.getInterfaceType();
- if (ifType.equals(InterfaceTypeVxlan.class)) {
- List<Options> tpOptions = tp.getOptions();
- for (Options tpOption : tpOptions) {
+ if (InterfaceTypeVxlan.class.equals(ifType)) {
+ for (Options tpOption : nullToEmpty(tp.getOptions())) {
// From the VXLAN Tunnels, we want the one with the GPE option set
- if (tpOption.key().getOption().equals(OPTION_KEY_REMOTE_IP)) {
- if (tpOption.getValue().equals(OPTION_VALUE_FLOW) && tp.getOfport() != null) {
+ if (OPTION_KEY_REMOTE_IP.equals(tpOption.key().getOption())) {
+ if (OPTION_VALUE_FLOW.equals(tpOption.getValue()) && tp.getOfport() != null) {
return Optional.ofNullable(tp.getOfport());
}
}
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
+import javax.annotation.Nullable;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.genius.infra.Datastore.Configuration;
public static final String OF_URI_SEPARATOR = ":";
public static final Ipv4Address NULL_IP = new Ipv4Address("0.0.0.0");
+ @Nullable
public List<MatchBuilder> getMatchBuilderFromAceMatches(Matches matches) {
if (matches == null) {
return null;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.inject.Inject;
SffSfDataPlaneLocator sffSfDataPlaneLocator = sff.map(ServiceFunctionForwarder::getServiceFunctionDictionary)
.orElse(Collections.emptyList())
.stream()
- .filter(serviceFunctionDictionary -> serviceFunctionDictionary.getName().equals(sfName))
+ .filter(serviceFunctionDictionary -> Objects.equals(serviceFunctionDictionary.getName(), sfName))
.findAny()
.map(ServiceFunctionDictionary::getSffSfDataPlaneLocator)
.orElse(null);
Optional<String> interfaceName = sff.map(ServiceFunctionForwarderBase::getSffDataPlaneLocator)
.orElse(Collections.emptyList())
.stream()
- .filter(sffDataPlaneLocator -> sffDataPlaneLocator.getName().equals(locatorName))
+ .filter(sffDataPlaneLocator -> Objects.equals(sffDataPlaneLocator.getName(), locatorName))
.findAny()
.map(SffDataPlaneLocator::getDataPlaneLocator)
.filter(dataPlaneLocator -> dataPlaneLocator.getLocatorType() instanceof LogicalInterface)
import com.google.common.base.MoreObjects;
import java.util.Objects;
+import javax.annotation.Nullable;
import org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierEntryRenderer;
import org.opendaylight.netvirt.sfc.classifier.service.domain.api.ClassifierRenderableEntry;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches;
}
private final EntryType entryType;
- private final NodeId node;
- private final InterfaceKey interfaceKey;
- private final String connector;
- private final Matches matches;
- private final Long nsp;
- private final Short nsi;
- private final Short nsl;
- private final String destinationIp;
- private final String firstHopIp;
+ // TODO skitt Rework using a class hierarchy so we can enforce null constraints
+ private final @Nullable NodeId node;
+ private final @Nullable InterfaceKey interfaceKey;
+ private final @Nullable String connector;
+ private final @Nullable Matches matches;
+ private final @Nullable Long nsp;
+ private final @Nullable Short nsi;
+ private final @Nullable Short nsl;
+ private final @Nullable String destinationIp;
+ private final @Nullable String firstHopIp;
- private ClassifierEntry(EntryType entryType, NodeId node, InterfaceKey interfaceKey, String connector,
- Matches matches, Long nsp, Short nsi, Short nsl, String destinationIp,
- String firstHopIp) {
+ private ClassifierEntry(EntryType entryType, @Nullable NodeId node, @Nullable InterfaceKey interfaceKey,
+ @Nullable String connector, @Nullable Matches matches, @Nullable Long nsp,
+ @Nullable Short nsi, @Nullable Short nsl, @Nullable String destinationIp,
+ @Nullable String firstHopIp) {
this.entryType = entryType;
this.node = node;
this.interfaceKey = interfaceKey;
* @return the {@code ClassifierEntry}.
*/
public static ClassifierEntry buildPathEntry(NodeId node, Long nsp, short nsi, short nsl,
- String firstHopIp) {
+ @Nullable String firstHopIp) {
return new ClassifierEntry(
EntryType.PATH_ENTRY_TYPE,
node,
.orElse(null);
RenderedServicePath reverseRsp = rsps.stream()
.filter(RenderedServicePath::isReversePath)
- .filter(rsp -> forwardRsp != null && rsp.getSymmetricPathId().equals(forwardRsp.getPathId()))
+ .filter(rsp -> forwardRsp != null && Objects.equals(rsp.getSymmetricPathId(), forwardRsp.getPathId()))
.findAny()
.orElse(null);
}
if (portMatches.isEmpty()) {
newMatches.add(this.matchBuilder);
- } else if (!portMatches.isEmpty()) {
+ } else {
for (GeneralAugMatchNodesNodeTableFlow portMatch : portMatches) {
newMatches.add(new MatchBuilder(matchBuilder.build())
.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, portMatch));
--- /dev/null
+/*
+ * Copyright © 2018 Red Hat, Inc. and others.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netvirt.sfc.classifier.utils;
+
+import static java.util.Collections.emptyList;
+
+import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+public final class SfcUtils {
+ private SfcUtils() {
+ // Utility class
+ }
+
+ // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3
+ @Nonnull
+ public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
+ return input != null ? input : emptyList();
+ }
+}
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
.setNameFormat("NeutronSfcListener-%d").build();
private final ExecutorService executorService = Executors.newFixedThreadPool(1, THREAD_FACTORY);
private final INeutronSfcDataProcessor<T> dataProcessor;
+ @Nullable
private ListenerRegistration<DelegatingDataTreeListener<T>> listenerRegistration;
public DelegatingDataTreeListener(DataBroker db, DataTreeIdentifier<T> treeId) {
listenerRegistration.close();
listenerRegistration = null;
}
- if (executorService != null) {
- executorService.shutdownNow();
- }
+ executorService.shutdownNow();
}
}
package org.opendaylight.netvirt.sfc.translator;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
this.dataBroker = dataBroker;
}
+ @Nullable
public Port getNeutronPort(Uuid portId) {
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
LogicalDatastoreType.CONFIGURATION, getNeutronPortPath(portId)).orNull();
}
+ @Nullable
public PortPair getNeutronPortPair(Uuid portPairId) {
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
LogicalDatastoreType.CONFIGURATION, getNeutronPortPairPath(portPairId)).orNull();
}
+ @Nullable
public PortPairGroup getNeutronPortPairGroup(Uuid portPairGroupId) {
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
LogicalDatastoreType.CONFIGURATION, getNeutronPortPairGroupPath(portPairGroupId)).orNull();
}
+ @Nullable
public SfcFlowClassifier getNeutronFlowClassifier(Uuid flowClassifierId) {
return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
LogicalDatastoreType.CONFIGURATION, getNeutronSfcFlowClassifierPath(flowClassifierId)).orNull();
package org.opendaylight.netvirt.sfc.translator;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
}
//Service Function
+ @Nullable
public ServiceFunction readServiceFunction(ServiceFunctionKey sfKey) {
InstanceIdentifier<ServiceFunction> sfIid = getSFPath(sfKey);
LOG.info("Read Service Function {} from config data store at {}",sfKey, sfIid);
}
//Service Function Forwarder
+ @Nullable
public ServiceFunctionForwarder readServiceFunctionForwarder(ServiceFunctionForwarderKey sffKey) {
InstanceIdentifier<ServiceFunctionForwarder> sffIid = getSFFPath(sffKey);
LOG.info("Read Service Function Forwarder from config data store at {}", sffIid);
--- /dev/null
+/*
+ * Copyright © 2018 Red Hat, Inc. and others.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netvirt.sfc.translator;
+
+import static java.util.Collections.emptyList;
+
+import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+public final class SfcTranslatorUtils {
+ private SfcTranslatorUtils() {
+ // Utility class
+ }
+
+ // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3
+ @Nonnull
+ public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
+ return input != null ? input : emptyList();
+ }
+}
package org.opendaylight.netvirt.sfc.translator.flowclassifier;
import java.util.ArrayList;
+import javax.annotation.Nullable;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.Ipv4Acl;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.Ipv6Acl;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl;
return buildAcl(flowClassifier, null);
}
- public static Acl buildAcl(SfcFlowClassifier flowClassifier, String sfpName) {
+ public static Acl buildAcl(SfcFlowClassifier flowClassifier, @Nullable String sfpName) {
LOG.info("OpenStack Networking SFC pushed Flow classifier : {}", flowClassifier);
AclBuilder aclBuilder = new AclBuilder();
AceBuilder aceBuilder = new AceBuilder();
if (sourceIp != null && sourceIp.getIpv6Prefix() != null) {
aceIpv6Builder.setSourceIpv6Network(sourceIp.getIpv6Prefix());
}
- if (sourceIp != null && destinationIp.getIpv6Prefix() != null) {
+ if (destinationIp != null && destinationIp.getIpv6Prefix() != null) {
aceIpv6Builder.setDestinationIpv6Network(destinationIp.getIpv6Prefix());
}
aceIpBuilder.setAceIpVersion(aceIpv6Builder.build());
package org.opendaylight.netvirt.sfc.translator.portchain;
+import static org.opendaylight.netvirt.sfc.translator.SfcTranslatorUtils.nullToEmpty;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
*/
@Override
public void update(PortChain origPortChain, PortChain updatePortChain) {
- List<Uuid> oldFcList = origPortChain.getFlowClassifiers();
- oldFcList.removeAll(updatePortChain.getFlowClassifiers());
+ List<Uuid> oldFcList = new ArrayList<>(nullToEmpty(origPortChain.getFlowClassifiers()));
+ oldFcList.removeAll(nullToEmpty(updatePortChain.getFlowClassifiers()));
if (!oldFcList.isEmpty()) {
LOG.debug("Removing old list {}", oldFcList);
processFlowClassifiers(origPortChain, oldFcList, null, false);
List<ServiceFunction> portChainServiceFunctionList = new ArrayList<>();
//Read chain related port pair group from neutron data store
- for (Uuid ppgUuid : newPortChain.getPortPairGroups()) {
+ for (Uuid ppgUuid : nullToEmpty(newPortChain.getPortPairGroups())) {
PortPairGroup ppg = neutronMdsalHelper.getNeutronPortPairGroup(ppgUuid);
if (ppg != null) {
List<PortPair> portPairList = new ArrayList<>();
portPairGroupList.add(ppg);
- for (Uuid ppUuid : ppg.getPortPairs()) {
+ for (Uuid ppUuid : nullToEmpty(ppg.getPortPairs())) {
PortPair pp = neutronMdsalHelper.getNeutronPortPair(ppUuid);
if (pp == null) {
LOG.error("Port pair {} does not exist in the neutron data store", ppUuid);
// The RSP will automatically be created from the SFP added above.
// Add ACLs from flow classifiers
- processFlowClassifiers(newPortChain, newPortChain.getFlowClassifiers(), sfp.getName().getValue(), true);
+ processFlowClassifiers(newPortChain, nullToEmpty(newPortChain.getFlowClassifiers()), sfp.getName().getValue(),
+ true);
}
- private void processFlowClassifiers(PortChain pc, List<Uuid> flowClassifiers, String sfpName, boolean added) {
+ private void processFlowClassifiers(PortChain pc, @Nonnull List<Uuid> flowClassifiers, @Nullable String sfpName,
+ boolean added) {
for (Uuid uuid : flowClassifiers) {
SfcFlowClassifier fc = neutronMdsalHelper.getNeutronFlowClassifier(uuid);
if (fc != null) {
List<ChainParameters> cpList = portChain.getChainParameters();
if (cpList != null && !cpList.isEmpty()) {
for (ChainParameters cp : cpList) {
- if (cp.getChainParameter().equals(SYMMETRIC_PARAM)) {
+ if (SYMMETRIC_PARAM.equals(cp.getChainParameter())) {
//Override the symmetric default value.
sfcBuilder.setSymmetric(Boolean.valueOf(cp.getChainParameterValue()));
break;