X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fregistry%2Fflow%2FFlowRegistryKeyFactory.java;h=64da79a9d7531c971eb09c84c4347730759d16c6;hb=137e4d7d86e8f402f3d52fd0fa162792f9ff60eb;hp=1a9948a2bd1137036ce9af73f678550595784c57;hpb=ed4fc64f42635bd69b27708eeef1fad23ffafa04;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/FlowRegistryKeyFactory.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/FlowRegistryKeyFactory.java index 1a9948a2bd..64da79a9d7 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/FlowRegistryKeyFactory.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/FlowRegistryKeyFactory.java @@ -11,65 +11,146 @@ package org.opendaylight.openflowplugin.impl.registry.flow; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import java.math.BigInteger; +import java.util.Objects; +import javax.annotation.Nonnull; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey; +import org.opendaylight.openflowplugin.impl.util.MatchNormalizationUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; - -/** - * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015. - */ -public class FlowRegistryKeyFactory { +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList; +public final class FlowRegistryKeyFactory { - public FlowRegistryKeyFactory() { + private FlowRegistryKeyFactory() { + // Hide implicit constructor } - public static FlowRegistryKey create(final Flow flow) { - return new FlowRegistryKeyDto(flow); + @Nonnull + public static FlowRegistryKey create(final short version, @Nonnull final Flow flow) { + //TODO: mandatory flow input values (or default values) should be specified via yang model + final short tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null"); + final int priority = MoreObjects.firstNonNull(flow.getPriority(), OFConstants.DEFAULT_FLOW_PRIORITY); + final BigInteger cookie = + MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue(); + Match match = MatchNormalizationUtil + .normalizeMatch(MoreObjects.firstNonNull(flow.getMatch(), OFConstants.EMPTY_MATCH), version); + return new FlowRegistryKeyDto(tableId, priority, cookie, match); } private static final class FlowRegistryKeyDto implements FlowRegistryKey { - private final short tableId; private final int priority; private final BigInteger cookie; private final Match match; - public FlowRegistryKeyDto(final Flow flow) { - //TODO: mandatory flow input values (or default values) should be specified via yang model - tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null"); - priority = MoreObjects.firstNonNull(flow.getPriority(), OFConstants.DEFAULT_FLOW_PRIORITY); - match = flow.getMatch()==null? new MatchBuilder().build(): flow.getMatch(); - cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue(); + private FlowRegistryKeyDto(final short tableId, + final int priority, + @Nonnull final BigInteger cookie, + @Nonnull final Match match) { + this.tableId = tableId; + this.priority = priority; + this.cookie = cookie; + this.match = match; } @Override - public boolean equals(final Object o) { - if (this == o) { + public boolean equals(final Object object) { + if (this == object) { return true; } - if (o == null || !(o instanceof FlowRegistryKey)) { + if (object == null || !(object instanceof FlowRegistryKey)) { return false; } - final FlowRegistryKey that = (FlowRegistryKey) o; + final FlowRegistryKey that = (FlowRegistryKey) object; - return getPriority() == that.getPriority() && - getTableId() == that.getTableId() && - getMatch().equals(that.getMatch()); + return getPriority() == that.getPriority() + && getTableId() == that.getTableId() + && getCookie().equals(that.getCookie()) + && equalMatch(that.getMatch()); + } + + private boolean equalMatch(final Match input) { + GeneralAugMatchNodesNodeTableFlow thisAug = match.augmentation(GeneralAugMatchNodesNodeTableFlow.class); + GeneralAugMatchNodesNodeTableFlow inputAug = input.augmentation(GeneralAugMatchNodesNodeTableFlow.class); + if (thisAug != inputAug) { + if (thisAug != null) { + if (inputAug == null) { + return false; + } + if (!Objects.equals(match.getEthernetMatch(), input.getEthernetMatch())) { + return false; + } + if (!Objects.equals(match.getIcmpv4Match(), input.getIcmpv4Match())) { + return false; + } + if (!Objects.equals(match.getIcmpv6Match(), input.getIcmpv6Match())) { + return false; + } + if (!Objects.equals(match.getInPhyPort(), input.getInPhyPort())) { + return false; + } + if (!Objects.equals(match.getInPort(), input.getInPort())) { + return false; + } + if (!Objects.equals(match.getIpMatch(), input.getIpMatch())) { + return false; + } + if (!Objects.equals(match.getLayer3Match(), input.getLayer3Match())) { + return false; + } + if (!Objects.equals(match.getLayer4Match(), input.getLayer4Match())) { + return false; + } + if (!Objects.equals(match.getMetadata(), input.getMetadata())) { + return false; + } + if (!Objects.equals(match.getProtocolMatchFields(), input.getProtocolMatchFields())) { + return false; + } + if (!Objects.equals(match.getTcpFlagsMatch(), input.getTcpFlagsMatch())) { + return false; + } + if (!Objects.equals(match.getTunnel(), input.getTunnel())) { + return false; + } + if (!Objects.equals(match.getVlanMatch(), input.getVlanMatch())) { + return false; + } + for (ExtensionList inputExtensionList : inputAug.getExtensionList()) { + if (!thisAug.getExtensionList().contains(inputExtensionList)) { + return false; + } + } + } + } else { + return getMatch().equals(input); + } + return true; } @Override public int hashCode() { int result = tableId; result = 31 * result + priority; + result = 31 * result + cookie.hashCode(); result = 31 * result + match.hashCode(); return result; } + @Override + public String toString() { + return "FlowRegistryKeyDto{" + + "tableId=" + tableId + + ", priority=" + priority + + ", cookie=" + cookie + + ", match=" + match + + '}'; + } + @Override public short getTableId() { return tableId;