Ayaka Koshibe

FlowRule equals() incorporates FlowId to factor in treatment.

Reference: ONOS-481

Change-Id: Ia1fcba3f827c662c89801afc84916ffef78af66d
......@@ -203,7 +203,8 @@ public class DefaultFlowRule implements FlowRule {
DefaultFlowRule that = (DefaultFlowRule) obj;
return Objects.equals(deviceId, that.deviceId) &&
Objects.equals(priority, that.priority) &&
Objects.equals(selector, that.selector);
Objects.equals(selector, that.selector) &&
Objects.equals(id, that.id());
}
return false;
......
......@@ -17,12 +17,15 @@
package org.onosproject.net.flow;
import org.junit.Test;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.intent.IntentTestsMocks;
import com.google.common.testing.EqualsTester;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.NetTestTools.did;
......@@ -33,8 +36,12 @@ import static org.onosproject.net.NetTestTools.did;
public class DefaultFlowRuleTest {
private static final IntentTestsMocks.MockSelector SELECTOR =
new IntentTestsMocks.MockSelector();
private static final IntentTestsMocks.MockTreatment TREATMENT =
new IntentTestsMocks.MockTreatment();
private static final IntentTestsMocks.MockTreatment TREATMENT1 =
new IntentTestsMocks.MockTreatment(
Instructions.createOutput(PortNumber.portNumber(1)));
private static final IntentTestsMocks.MockTreatment TREATMENT2 =
new IntentTestsMocks.MockTreatment(
Instructions.createOutput(PortNumber.portNumber(2)));
final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1);
final FlowRule sameAsFlowRule1 = new IntentTestsMocks.MockFlowRule(1);
......@@ -85,14 +92,14 @@ public class DefaultFlowRuleTest {
public void testCreationWithFlowId() {
final DefaultFlowRule rule =
new DefaultFlowRule(did("1"), SELECTOR,
TREATMENT, 22, 33,
TREATMENT1, 22, 33,
44, false);
assertThat(rule.deviceId(), is(did("1")));
assertThat(rule.id().value(), is(33L));
assertThat(rule.isPermanent(), is(false));
assertThat(rule.priority(), is(22));
assertThat(rule.selector(), is(SELECTOR));
assertThat(rule.treatment(), is(TREATMENT));
assertThat(rule.treatment(), is(TREATMENT1));
assertThat(rule.timeout(), is(44));
}
......@@ -103,13 +110,25 @@ public class DefaultFlowRuleTest {
public void testCreationWithAppId() {
final DefaultFlowRule rule =
new DefaultFlowRule(did("1"), SELECTOR,
TREATMENT, 22, APP_ID,
TREATMENT1, 22, APP_ID,
44, false);
assertThat(rule.deviceId(), is(did("1")));
assertThat(rule.isPermanent(), is(false));
assertThat(rule.priority(), is(22));
assertThat(rule.selector(), is(SELECTOR));
assertThat(rule.treatment(), is(TREATMENT));
assertThat(rule.treatment(), is(TREATMENT1));
assertThat(rule.timeout(), is(44));
}
/**
* Tests equality that factors in TrafficTreatment through the flowId.
*/
@Test
public void testActionEquals() {
final DefaultFlowRule rule1 = new DefaultFlowRule(did("1"), SELECTOR,
TREATMENT1, 22, APP_ID, 44, false);
final DefaultFlowRule rule2 = new DefaultFlowRule(did("1"), SELECTOR,
TREATMENT2, 22, APP_ID, 44, false);
assertThat(rule1, not(rule2));
}
}
......
......@@ -80,9 +80,19 @@ public class IntentTestsMocks {
* Mock traffic treatment class used for satisfying API requirements.
*/
public static class MockTreatment implements TrafficTreatment {
private List<Instruction> instructions = new ArrayList<>();
public MockTreatment() {
}
public MockTreatment(Instruction... insts) {
this.instructions.addAll(Arrays.asList(insts));
}
@Override
public List<Instruction> instructions() {
return new ArrayList<>();
return this.instructions;
}
}
......