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=f796080517503f24283d979faf8b1f6c1bf55c0e;hb=05f8db12159673d0e0a95642fe86e62c14b7dc7b;hp=80d5c7e3ba034d11566d94056dd22afe685088ca;hpb=7a226a870f147fa41d6c64acdacb59fbe98acd50;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 80d5c7e3ba..f796080517 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 @@ -10,61 +10,127 @@ 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 org.eclipse.jdt.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.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList; +import org.opendaylight.yangtools.yang.common.Uint16; +import org.opendaylight.yangtools.yang.common.Uint64; +import org.opendaylight.yangtools.yang.common.Uint8; -/** - * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015. - */ -public class FlowRegistryKeyFactory { - +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 Uint8 tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null"); + final Uint16 priority = MoreObjects.firstNonNull(flow.getPriority(), OFConstants.DEFAULT_FLOW_PRIORITY); + final Uint64 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.toJava(), priority.toJava(), cookie, match); } private static final class FlowRegistryKeyDto implements FlowRegistryKey { - private final short tableId; private final int priority; - private final BigInteger cookie; + private final Uint64 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 = Preconditions.checkNotNull(flow.getMatch(), "Match value must not be null"); - cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue(); + private FlowRegistryKeyDto(final short tableId, + final int priority, + @NonNull final Uint64 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 || getClass() != o.getClass()) { + + if (object == null || !(object instanceof FlowRegistryKey)) { return false; } - final FlowRegistryKeyDto that = (FlowRegistryKeyDto) o; + final FlowRegistryKey that = (FlowRegistryKey) object; - if (priority != that.priority) { - return false; - } - if (tableId != that.tableId) { - return false; - } - if (!match.equals(that.match)) { - return false; - } + 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.nonnullExtensionList().values()) { + if (!thisAug.nonnullExtensionList().containsValue(inputExtensionList)) { + return false; + } + } + } + } else { + return getMatch().equals(input); + } return true; } @@ -72,10 +138,21 @@ public class FlowRegistryKeyFactory { 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; @@ -87,8 +164,13 @@ public class FlowRegistryKeyFactory { } @Override - public BigInteger getCookie() { + public Uint64 getCookie() { return cookie; } + + @Override + public Match getMatch() { + return match; + } } }