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.inventory.rev130819.tables.table.Flow;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
15 import java.util.ArrayList;
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Objects;
22 * Custom {@link Equivalence} for {@link Flow}
25 public class FlowEquivalence extends Equivalence<Flow> {
31 protected boolean doEquivalent(Flow a, Flow b) {
33 if (!Objects.equals(a.getBufferId(), b.getBufferId())) {
36 if (!Objects.equals(a.getContainerName(), b.getContainerName())) {
39 if (!Objects.equals(a.getCookie(), b.getCookie())) {
42 if (!Objects.equals(a.getCookieMask(), b.getCookieMask())) {
45 if (!Objects.equals(a.getFlags(), b.getFlags())) {
48 if (!Objects.equals(a.getFlowName(), b.getFlowName())) {
52 List<Instruction> listA = new ArrayList<>();
53 if (a.getInstructions() != null) {
54 listA = a.getInstructions().getInstruction();
56 Set<Instruction> setA = new HashSet<>();
58 setA = new HashSet<>(listA);
60 List<Instruction> listB = new ArrayList<>();
61 if (b.getInstructions() != null) {
62 listB = b.getInstructions().getInstruction();
64 Set<Instruction> setB = new HashSet<>();
66 setB = new HashSet<>(listB);
68 if (!setA.equals(setB)) {
72 if (!EquivalenceFabric.MATCH_EQUIVALENCE
73 .equivalent(a.getMatch(), b.getMatch())) {
76 if (!Objects.equals(a.getOutGroup(), b.getOutGroup())) {
79 if (!Objects.equals(a.getOutPort(), b.getOutPort())) {
82 if (!Objects.equals(a.getPriority(), b.getPriority())) {
85 if (!Objects.equals(a.getTableId(), b.getTableId())) {
88 if (!Objects.equals(a.isBarrier(), b.isBarrier())) {
91 if (!Objects.equals(a.isInstallHw(), b.isInstallHw())) {
94 if (!Objects.equals(a.isStrict(), b.isStrict())) {
102 protected int doHash(Flow flow) {
103 final int prime = 31;
106 result = prime * result + ((flow.getBufferId() == null) ? 0 : flow.getBufferId().hashCode());
107 result = prime * result + ((flow.getContainerName() == null) ? 0 : flow.getContainerName().hashCode());
108 result = prime * result + ((flow.getCookie() == null) ? 0 : flow.getCookie().hashCode());
109 result = prime * result + ((flow.getCookieMask() == null) ? 0 : flow.getCookieMask().hashCode());
110 result = prime * result + ((flow.getFlags() == null) ? 0 : flow.getFlags().hashCode());
111 result = prime * result + ((flow.getFlowName() == null) ? 0 : flow.getFlowName().hashCode());
113 if (flow.getInstructions() != null
114 && flow.getInstructions().getInstruction() != null
115 && !flow.getInstructions().getInstruction().isEmpty()) {
116 Set<Instruction> instructions = new HashSet<>(flow.getInstructions().getInstruction());
117 result = prime * result + instructions.hashCode();
120 result = prime * result + ((flow.getMatch() == null) ? 0
121 : EquivalenceFabric.MATCH_EQUIVALENCE.wrap(flow.getMatch()).hashCode());
122 result = prime * result + ((flow.getOutGroup() == null) ? 0 : flow.getOutGroup().hashCode());
123 result = prime * result + ((flow.getOutPort() == null) ? 0 : flow.getOutPort().hashCode());
124 result = prime * result + ((flow.getPriority() == null) ? 0 : flow.getPriority().hashCode());
125 result = prime * result + ((flow.getTableId() == null) ? 0 : flow.getTableId().hashCode());
126 result = prime * result + ((flow.isBarrier() == null) ? 0 : flow.isBarrier().hashCode());
127 result = prime * result + ((flow.isInstallHw() == null) ? 0 : flow.isInstallHw().hashCode());
128 result = prime * result + ((flow.isStrict() == null) ? 0 : flow.isStrict().hashCode());