2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.equivalence;
11 import com.google.common.base.Equivalence;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionList;
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Objects;
22 * Custom {@link Equivalence} for {@link Match}
24 * @see FlowEquivalence
26 public class MatchEquivalence extends Equivalence<Match> {
32 protected boolean doEquivalent(Match a, Match b) {
34 if (!Objects.equals(a.getEthernetMatch(), b.getEthernetMatch())) {
37 if (!Objects.equals(a.getIcmpv4Match(), b.getIcmpv4Match())) {
40 if (!Objects.equals(a.getIcmpv6Match(), b.getIcmpv6Match())) {
43 if (!Objects.equals(a.getInPhyPort(), b.getInPhyPort())) {
46 if (!Objects.equals(a.getInPort(), b.getInPort())) {
49 if (!Objects.equals(a.getIpMatch(), b.getIpMatch())) {
52 if (!Objects.equals(a.getLayer3Match(), b.getLayer3Match())) {
55 if (!Objects.equals(a.getLayer4Match(), b.getLayer4Match())) {
58 if (!Objects.equals(a.getMetadata(), b.getMetadata())) {
61 if (!Objects.equals(a.getProtocolMatchFields(), b.getProtocolMatchFields())) {
64 if (!Objects.equals(a.getTcpFlagMatch(), b.getTcpFlagMatch())) {
67 if (!Objects.equals(a.getTunnel(), b.getTunnel())) {
70 if (!Objects.equals(a.getVlanMatch(), b.getVlanMatch())) {
73 GeneralAugMatchNodesNodeTableFlow generalAugMatchA =
74 a.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
75 GeneralAugMatchNodesNodeTableFlow generalAugMatchB =
76 b.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
78 if (generalAugMatchA != null && generalAugMatchB != null) {
79 // if both have GeneralAugMatchNodesNodeTableFlow augmentation
80 // create sets of ExtentionList type (not a List/Collection at all, as of yet)
81 Set<ExtensionList> setA = new HashSet<>();
82 Set<ExtensionList> setB = new HashSet<>();
83 if (generalAugMatchA.getExtensionList() != null) {
84 setA = new HashSet<>(generalAugMatchA.getExtensionList());
86 if (generalAugMatchB.getExtensionList() != null) {
87 setB = new HashSet<>(generalAugMatchB.getExtensionList());
89 if (!setA.equals(setB)) {
93 } else if ((generalAugMatchA == null && generalAugMatchB != null)
94 || generalAugMatchA != null) {
95 // if only one has GeneralAugMatchNodesNodeTableFlow augmentation, they are not equal
97 } // if no-one has GeneralAugMatchNodesNodeTableFlow augmentation, continue matching
103 protected int doHash(Match m) {
104 final int prime = 31;
106 result = prime * result + ((m.getEthernetMatch() == null) ? 0 : m.getEthernetMatch().hashCode());
107 result = prime * result + ((m.getIcmpv4Match() == null) ? 0 : m.getIcmpv4Match().hashCode());
108 result = prime * result + ((m.getIcmpv6Match() == null) ? 0 : m.getIcmpv6Match().hashCode());
109 result = prime * result + ((m.getInPhyPort() == null) ? 0 : m.getInPhyPort().hashCode());
110 result = prime * result + ((m.getInPort() == null) ? 0 : m.getInPort().hashCode());
111 result = prime * result + ((m.getIpMatch() == null) ? 0 : m.getIpMatch().hashCode());
112 result = prime * result + ((m.getLayer3Match() == null) ? 0 : m.getLayer3Match().hashCode());
113 result = prime * result + ((m.getLayer4Match() == null) ? 0 : m.getLayer4Match().hashCode());
114 result = prime * result + ((m.getMetadata() == null) ? 0 : m.getMetadata().hashCode());
115 result = prime * result + ((m.getProtocolMatchFields() == null) ? 0 : m.getProtocolMatchFields().hashCode());
116 result = prime * result + ((m.getTcpFlagMatch() == null) ? 0 : m.getTcpFlagMatch().hashCode());
117 result = prime * result + ((m.getTunnel() == null) ? 0 : m.getTunnel().hashCode());
118 result = prime * result + ((m.getVlanMatch() == null) ? 0 : m.getVlanMatch().hashCode());
120 GeneralAugMatchNodesNodeTableFlow generalAugMatch =
121 m.getAugmentation(GeneralAugMatchNodesNodeTableFlow.class);
122 if (generalAugMatch != null) {
123 List<ExtensionList> augMatchExtensionList = generalAugMatch.getExtensionList();
124 Set<ExtensionList> extensionListSet = new HashSet<>();
125 if (augMatchExtensionList != null) {
127 new HashSet<>(augMatchExtensionList);
129 result = prime * result + extensionListSet.hashCode();