summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow
diff options
context:
space:
mode:
authorAshlee Young <ashlee@onosfw.com>2015-09-09 22:15:21 -0700
committerAshlee Young <ashlee@onosfw.com>2015-09-09 22:15:21 -0700
commit13d05bc8458758ee39cb829098241e89616717ee (patch)
tree22a4d1ce65f15952f07a3df5af4b462b4697cb3a /framework/src/onos/core/api/src/test/java/org/onosproject/net/flow
parent6139282e1e93c2322076de4b91b1c85d0bc4a8b3 (diff)
ONOS checkin based on commit tag e796610b1f721d02f9b0e213cf6f7790c10ecd60
Change-Id: Ife8810491034fe7becdba75dda20de4267bd15cd
Diffstat (limited to 'framework/src/onos/core/api/src/test/java/org/onosproject/net/flow')
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/BatchOperationTest.java153
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowEntryTest.java161
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowRuleTest.java161
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficSelectorTest.java295
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficTreatmentTest.java124
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowIdTest.java65
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleBatchOperationTest.java60
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleBatchRequestTest.java63
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleEventTest.java77
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleExtPayLoadTest.java36
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleServiceAdapter.java75
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java1138
-rw-r--r--framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/instructions/InstructionsTest.java725
13 files changed, 3133 insertions, 0 deletions
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/BatchOperationTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/BatchOperationTest.java
new file mode 100644
index 00000000..9e142e59
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/BatchOperationTest.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
+
+/**
+ * Unit tests for the BatchOperationTest object.
+ */
+public class BatchOperationTest {
+
+ private enum TestType {
+ OP1,
+ OP2,
+ OP3
+ }
+
+ final TestEntry entry1 = new TestEntry(TestType.OP1, new TestTarget(1));
+ final TestEntry entry2 = new TestEntry(TestType.OP2, new TestTarget(2));
+
+
+ private static final class TestTarget {
+ private int id;
+
+ private TestTarget(int id) {
+ this.id = id;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (o == null) {
+ return false;
+ }
+
+ if (getClass() != o.getClass()) {
+ return false;
+ }
+ TestTarget that = (TestTarget) o;
+ return this.id == that.id;
+ }
+
+ }
+
+ private static final class TestEntry extends BatchOperationEntry<TestType, TestTarget> {
+ public TestEntry(TestType operator, TestTarget target) {
+ super(operator, target);
+ }
+ }
+
+ private static final class TestOperation extends BatchOperation<TestEntry> {
+ private TestOperation() {
+ super();
+ }
+
+ private TestOperation(Collection<TestEntry> batchOperations) {
+ super(batchOperations);
+ }
+ }
+
+ /**
+ * Checks that the DefaultFlowRule class is immutable.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutableBaseClass(BatchOperation.class);
+ }
+
+ /**
+ * Tests the equals(), hashCode() and toString() operations.
+ */
+ @Test
+ public void testEquals() {
+ final List<TestEntry> ops1 = new LinkedList<>();
+ ops1.add(entry1);
+ final List<TestEntry> ops2 = new LinkedList<>();
+ ops2.add(entry2);
+
+ final TestOperation op1 = new TestOperation(ops1);
+ final TestOperation sameAsOp1 = new TestOperation(ops1);
+ final TestOperation op2 = new TestOperation(ops2);
+
+ new EqualsTester()
+ .addEqualityGroup(op1, sameAsOp1)
+ .addEqualityGroup(op2)
+ .testEquals();
+ }
+
+ /**
+ * Tests the constructors for a BatchOperation.
+ */
+ @Test
+ public void testConstruction() {
+ final List<TestEntry> ops = new LinkedList<>();
+ ops.add(entry2);
+
+ final TestOperation op1 = new TestOperation();
+ assertThat(op1.size(), is(0));
+ assertThat(op1.getOperations(), hasSize(0));
+
+ final TestOperation op2 = new TestOperation(ops);
+ op1.addOperation(entry1);
+ op1.addAll(op2);
+ assertThat(op1.size(), is(2));
+ assertThat(op1.getOperations(), hasSize(2));
+
+ op2.clear();
+ assertThat(op2.size(), is(0));
+ assertThat(op2.getOperations(), hasSize(0));
+ }
+
+ /**
+ * Tests the constructor for BatchOperationEntries.
+ */
+ @Test
+ public void testEntryConstruction() {
+ final TestEntry entry = new TestEntry(TestType.OP3, new TestTarget(3));
+
+ assertThat(entry.operator(), is(TestType.OP3));
+ assertThat(entry.target().id, is(3));
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowEntryTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowEntryTest.java
new file mode 100644
index 00000000..412acb62
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowEntryTest.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2014 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow;
+
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Test;
+import org.onosproject.net.intent.IntentTestsMocks;
+
+import com.google.common.testing.EqualsTester;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.is;
+import static org.onosproject.net.NetTestTools.did;
+
+/**
+ * Unit tests for the DefaultFlowEntry class.
+ */
+public class DefaultFlowEntryTest {
+ private static final IntentTestsMocks.MockSelector SELECTOR =
+ new IntentTestsMocks.MockSelector();
+ private static final IntentTestsMocks.MockTreatment TREATMENT =
+ new IntentTestsMocks.MockTreatment();
+
+ private static DefaultFlowEntry makeFlowEntry(int uniqueValue) {
+ FlowRule rule = DefaultFlowRule.builder()
+ .forDevice(did("id" + Integer.toString(uniqueValue)))
+ .withSelector(SELECTOR)
+ .withTreatment(TREATMENT)
+ .withPriority(uniqueValue)
+ .withCookie(uniqueValue)
+ .makeTemporary(uniqueValue)
+ .build();
+
+ return new DefaultFlowEntry(rule, FlowEntry.FlowEntryState.ADDED,
+ uniqueValue, uniqueValue, uniqueValue);
+ }
+
+ final DefaultFlowEntry defaultFlowEntry1 = makeFlowEntry(1);
+ final DefaultFlowEntry sameAsDefaultFlowEntry1 = makeFlowEntry(1);
+ final DefaultFlowEntry defaultFlowEntry2 = makeFlowEntry(2);
+
+ /**
+ * Tests the equals, hashCode and toString methods using Guava EqualsTester.
+ */
+ @Test
+ public void testEquals() {
+ new EqualsTester()
+ .addEqualityGroup(defaultFlowEntry1, sameAsDefaultFlowEntry1)
+ .addEqualityGroup(defaultFlowEntry2)
+ .testEquals();
+ }
+
+ /**
+ * Tests the construction of a default flow entry from a device id.
+ */
+ @Test
+ public void testDeviceBasedObject() {
+ assertThat(defaultFlowEntry1.deviceId(), is(did("id1")));
+ assertThat(defaultFlowEntry1.selector(), is(SELECTOR));
+ assertThat(defaultFlowEntry1.treatment(), is(TREATMENT));
+ assertThat(defaultFlowEntry1.timeout(), is(1));
+ assertThat(defaultFlowEntry1.life(), is(1L));
+ assertThat(defaultFlowEntry1.packets(), is(1L));
+ assertThat(defaultFlowEntry1.bytes(), is(1L));
+ assertThat(defaultFlowEntry1.state(), is(FlowEntry.FlowEntryState.ADDED));
+ assertThat(defaultFlowEntry1.lastSeen(),
+ greaterThan(System.currentTimeMillis() -
+ TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS)));
+ }
+
+ /**
+ * Tests the setters on a default flow entry object.
+ */
+ @Test
+ public void testSetters() {
+ final DefaultFlowEntry entry = makeFlowEntry(1);
+
+ entry.setLastSeen();
+ entry.setState(FlowEntry.FlowEntryState.PENDING_REMOVE);
+ entry.setPackets(11);
+ entry.setBytes(22);
+ entry.setLife(33);
+
+ assertThat(entry.deviceId(), is(did("id1")));
+ assertThat(entry.selector(), is(SELECTOR));
+ assertThat(entry.treatment(), is(TREATMENT));
+ assertThat(entry.timeout(), is(1));
+ assertThat(entry.life(), is(33L));
+ assertThat(entry.packets(), is(11L));
+ assertThat(entry.bytes(), is(22L));
+ assertThat(entry.state(), is(FlowEntry.FlowEntryState.PENDING_REMOVE));
+ assertThat(entry.lastSeen(),
+ greaterThan(System.currentTimeMillis() -
+ TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS)));
+ }
+
+ /**
+ * Tests a default flow rule built for an error.
+ */
+ @Test
+ public void testErrorObject() {
+ final DefaultFlowEntry errorEntry =
+ new DefaultFlowEntry(new IntentTestsMocks.MockFlowRule(1),
+ 111,
+ 222);
+ assertThat(errorEntry.errType(), is(111));
+ assertThat(errorEntry.errCode(), is(222));
+ assertThat(errorEntry.state(), is(FlowEntry.FlowEntryState.FAILED));
+ assertThat(errorEntry.lastSeen(),
+ greaterThan(System.currentTimeMillis() -
+ TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS)));
+ }
+
+ /**
+ * Tests a default flow entry constructed from a flow rule.
+ */
+ @Test
+ public void testFlowBasedObject() {
+ final DefaultFlowEntry entry =
+ new DefaultFlowEntry(new IntentTestsMocks.MockFlowRule(1));
+ assertThat(entry.priority(), is(1));
+ assertThat(entry.appId(), is((short) 0));
+ assertThat(entry.lastSeen(),
+ greaterThan(System.currentTimeMillis() -
+ TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS)));
+ }
+
+ /**
+ * Tests a default flow entry constructed from a flow rule plus extra
+ * parameters.
+ */
+ @Test
+ public void testFlowBasedObjectWithParameters() {
+ final DefaultFlowEntry entry =
+ new DefaultFlowEntry(new IntentTestsMocks.MockFlowRule(33),
+ FlowEntry.FlowEntryState.REMOVED,
+ 101, 102, 103);
+ assertThat(entry.state(), is(FlowEntry.FlowEntryState.REMOVED));
+ assertThat(entry.life(), is(101L));
+ assertThat(entry.packets(), is(102L));
+ assertThat(entry.bytes(), is(103L));
+ assertThat(entry.lastSeen(),
+ greaterThan(System.currentTimeMillis() -
+ TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS)));
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowRuleTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowRuleTest.java
new file mode 100644
index 00000000..62acd16a
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowRuleTest.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2014 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.flow;
+
+import org.junit.Test;
+import org.onosproject.core.DefaultGroupId;
+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.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.did;
+
+/**
+ * Unit tests for the default flow rule class.
+ */
+public class DefaultFlowRuleTest {
+ private static final IntentTestsMocks.MockSelector SELECTOR =
+ new IntentTestsMocks.MockSelector();
+ private static final IntentTestsMocks.MockTreatment TREATMENT =
+ new IntentTestsMocks.MockTreatment();
+
+ private static byte [] b = new byte[3];
+ private static FlowRuleExtPayLoad payLoad = FlowRuleExtPayLoad.flowRuleExtPayLoad(b);
+ final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1, payLoad);
+ final FlowRule sameAsFlowRule1 = new IntentTestsMocks.MockFlowRule(1, payLoad);
+ final DefaultFlowRule defaultFlowRule1 = new DefaultFlowRule(flowRule1);
+ final DefaultFlowRule sameAsDefaultFlowRule1 = new DefaultFlowRule(sameAsFlowRule1);
+
+ /**
+ * Checks that the DefaultFlowRule class is immutable but can be inherited
+ * from.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutableBaseClass(DefaultFlowRule.class);
+ }
+
+ /**
+ * Tests the equals, hashCode and toString methods using Guava EqualsTester.
+ */
+ @Test
+ public void testEquals() {
+ new EqualsTester()
+ .addEqualityGroup(defaultFlowRule1, sameAsDefaultFlowRule1)
+ .testEquals();
+ }
+
+ /**
+ * Tests creation of a DefaultFlowRule using a FlowRule constructor.
+ */
+ @Test
+ public void testCreationFromFlowRule() {
+ assertThat(defaultFlowRule1.deviceId(), is(flowRule1.deviceId()));
+ assertThat(defaultFlowRule1.appId(), is(flowRule1.appId()));
+ assertThat(defaultFlowRule1.id(), is(flowRule1.id()));
+ assertThat(defaultFlowRule1.isPermanent(), is(flowRule1.isPermanent()));
+ assertThat(defaultFlowRule1.priority(), is(flowRule1.priority()));
+ assertThat(defaultFlowRule1.selector(), is(flowRule1.selector()));
+ assertThat(defaultFlowRule1.treatment(), is(flowRule1.treatment()));
+ assertThat(defaultFlowRule1.timeout(), is(flowRule1.timeout()));
+ assertThat(defaultFlowRule1.payLoad(), is(flowRule1.payLoad()));
+ }
+
+ /**
+ * Tests creation of a DefaultFlowRule using a FlowId constructor.
+ */
+
+ @Test
+ public void testCreationWithFlowId() {
+ final FlowRule rule =
+ DefaultFlowRule.builder()
+ .forDevice(did("1"))
+ .withSelector(SELECTOR)
+ .withTreatment(TREATMENT)
+ .withPriority(22)
+ .makeTemporary(44)
+ .fromApp(APP_ID)
+ .build();
+
+ 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.timeout(), is(44));
+ }
+
+
+ /**
+ * Tests creation of a DefaultFlowRule using a PayLoad constructor.
+ */
+ @Test
+ public void testCreationWithPayLoadByFlowTable() {
+ final DefaultFlowRule rule =
+ new DefaultFlowRule(did("1"), null,
+ null, 22, APP_ID,
+ 44, false, payLoad);
+ assertThat(rule.deviceId(), is(did("1")));
+ assertThat(rule.isPermanent(), is(false));
+ assertThat(rule.priority(), is(22));
+ assertThat(rule.timeout(), is(44));
+ assertThat(defaultFlowRule1.payLoad(), is(payLoad));
+ }
+
+ /**
+ * Tests creation of a DefaultFlowRule using a PayLoad constructor.
+ */
+ @Test
+ public void testCreationWithPayLoadByGroupTable() {
+ final DefaultFlowRule rule =
+ new DefaultFlowRule(did("1"), null,
+ null, 22, APP_ID, new DefaultGroupId(0),
+ 44, false, payLoad);
+ assertThat(rule.deviceId(), is(did("1")));
+ assertThat(rule.isPermanent(), is(false));
+ assertThat(rule.priority(), is(22));
+ assertThat(rule.timeout(), is(44));
+ assertThat(rule.groupId(), is(new DefaultGroupId(0)));
+ assertThat(defaultFlowRule1.payLoad(), is(payLoad));
+ }
+ /**
+ * Tests the creation of a DefaultFlowRule using an AppId constructor.
+ */
+ @Test
+ public void testCreationWithAppId() {
+ final FlowRule rule =
+ DefaultFlowRule.builder()
+ .forDevice(did("1"))
+ .withSelector(SELECTOR)
+ .withTreatment(TREATMENT)
+ .withPriority(22)
+ .fromApp(APP_ID)
+ .makeTemporary(44)
+ .build();
+
+ 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.timeout(), is(44));
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficSelectorTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficSelectorTest.java
new file mode 100644
index 00000000..b871397b
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficSelectorTest.java
@@ -0,0 +1,295 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow;
+
+import java.util.Set;
+
+import org.hamcrest.Description;
+import org.hamcrest.Factory;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.junit.Test;
+import org.onlab.packet.Ip6Address;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.MplsLabel;
+import org.onlab.packet.TpPort;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.IndexedLambda;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.flow.criteria.Criteria;
+import org.onosproject.net.flow.criteria.Criterion;
+
+import com.google.common.testing.EqualsTester;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.onosproject.net.flow.criteria.Criterion.Type;
+
+/**
+ * Unit tests for default traffic selector class.
+ */
+public class DefaultTrafficSelectorTest {
+
+ /**
+ * Checks that the DefaultFlowRule class is immutable.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(DefaultTrafficSelector.class);
+ }
+
+ /**
+ * Tests equals(), hashCode() and toString() methods.
+ */
+ @Test
+ public void testEquals() {
+ final short one = 1;
+ final short two = 2;
+
+ final TrafficSelector selector1 = DefaultTrafficSelector.builder()
+ .add(Criteria.matchLambda(new IndexedLambda(one)))
+ .build();
+ final TrafficSelector sameAsSelector1 = DefaultTrafficSelector.builder()
+ .add(Criteria.matchLambda(new IndexedLambda(one)))
+ .build();
+ final TrafficSelector selector2 = DefaultTrafficSelector.builder()
+ .add(Criteria.matchLambda(new IndexedLambda(two)))
+ .build();
+
+ new EqualsTester()
+ .addEqualityGroup(selector1, sameAsSelector1)
+ .addEqualityGroup(selector2)
+ .testEquals();
+ }
+
+ /**
+ * Hamcrest matcher to check that a selector contains a
+ * Criterion with the specified type.
+ */
+ public static final class CriterionExistsMatcher
+ extends TypeSafeMatcher<TrafficSelector> {
+ private final Criterion.Type type;
+
+ /**
+ * Constructs a matcher for the given criterion type.
+ *
+ * @param typeValue criterion type to match
+ */
+ public CriterionExistsMatcher(Criterion.Type typeValue) {
+ type = typeValue;
+ }
+
+ @Override
+ public boolean matchesSafely(TrafficSelector selector) {
+ final Set<Criterion> criteria = selector.criteria();
+
+ return notNullValue().matches(criteria) &&
+ hasSize(1).matches(criteria) &&
+ notNullValue().matches(selector.getCriterion(type));
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("a criterion with type \" ").
+ appendText(type.toString()).
+ appendText("\"");
+ }
+ }
+
+
+ /**
+ * Creates a criterion type matcher. Returns a matcher
+ * for a criterion with the given type.
+ *
+ * @param type type of Criterion to match
+ * @return Matcher object
+ */
+ @Factory
+ public static Matcher<TrafficSelector> hasCriterionWithType(Criterion.Type type) {
+ return new CriterionExistsMatcher(type);
+ }
+
+
+ /**
+ * Tests the builder functions that add specific criteria.
+ */
+ @Test
+ public void testCriteriaCreation() {
+ TrafficSelector selector;
+
+ final long longValue = 0x12345678;
+ final int intValue = 22;
+ final short shortValue = 33;
+ final byte byteValue = 44;
+ final byte dscpValue = 0xf;
+ final byte ecnValue = 3;
+ final MacAddress macValue = MacAddress.valueOf("11:22:33:44:55:66");
+ final IpPrefix ipPrefixValue = IpPrefix.valueOf("192.168.1.0/24");
+ final IpPrefix ipv6PrefixValue = IpPrefix.valueOf("fe80::1/64");
+ final Ip6Address ipv6AddressValue = Ip6Address.valueOf("fe80::1");
+
+ selector = DefaultTrafficSelector.builder()
+ .matchInPort(PortNumber.portNumber(11)).build();
+ assertThat(selector, hasCriterionWithType(Type.IN_PORT));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchInPhyPort(PortNumber.portNumber(11)).build();
+ assertThat(selector, hasCriterionWithType(Type.IN_PHY_PORT));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchMetadata(longValue).build();
+ assertThat(selector, hasCriterionWithType(Type.METADATA));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchEthDst(macValue).build();
+ assertThat(selector, hasCriterionWithType(Type.ETH_DST));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchEthSrc(macValue).build();
+ assertThat(selector, hasCriterionWithType(Type.ETH_SRC));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchEthType(shortValue).build();
+ assertThat(selector, hasCriterionWithType(Type.ETH_TYPE));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchVlanId(VlanId.vlanId(shortValue)).build();
+ assertThat(selector, hasCriterionWithType(Type.VLAN_VID));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchVlanPcp(byteValue).build();
+ assertThat(selector, hasCriterionWithType(Type.VLAN_PCP));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPDscp(dscpValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IP_DSCP));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPEcn(ecnValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IP_ECN));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPProtocol(byteValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IP_PROTO));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPSrc(ipPrefixValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV4_SRC));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPDst(ipPrefixValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV4_DST));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchTcpSrc(TpPort.tpPort(intValue)).build();
+ assertThat(selector, hasCriterionWithType(Type.TCP_SRC));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchTcpDst(TpPort.tpPort(intValue)).build();
+ assertThat(selector, hasCriterionWithType(Type.TCP_DST));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchUdpSrc(TpPort.tpPort(intValue)).build();
+ assertThat(selector, hasCriterionWithType(Type.UDP_SRC));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchUdpDst(TpPort.tpPort(intValue)).build();
+ assertThat(selector, hasCriterionWithType(Type.UDP_DST));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchSctpSrc(TpPort.tpPort(intValue)).build();
+ assertThat(selector, hasCriterionWithType(Type.SCTP_SRC));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchSctpDst(TpPort.tpPort(intValue)).build();
+ assertThat(selector, hasCriterionWithType(Type.SCTP_DST));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIcmpType(byteValue).build();
+ assertThat(selector, hasCriterionWithType(Type.ICMPV4_TYPE));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIcmpCode(byteValue).build();
+ assertThat(selector, hasCriterionWithType(Type.ICMPV4_CODE));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPv6Src(ipv6PrefixValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV6_SRC));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPv6Dst(ipv6PrefixValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV6_DST));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPv6FlowLabel(intValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV6_FLABEL));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIcmpv6Type(byteValue).build();
+ assertThat(selector, hasCriterionWithType(Type.ICMPV6_TYPE));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPv6NDTargetAddress(ipv6AddressValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV6_ND_TARGET));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPv6NDSourceLinkLayerAddress(macValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV6_ND_SLL));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPv6NDTargetLinkLayerAddress(macValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV6_ND_TLL));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchMplsLabel(MplsLabel.mplsLabel(3)).build();
+ assertThat(selector, hasCriterionWithType(Type.MPLS_LABEL));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPv6ExthdrFlags(Criterion.IPv6ExthdrFlags.NONEXT.getValue()).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV6_EXTHDR));
+
+ selector = DefaultTrafficSelector.builder()
+ .add(Criteria.matchLambda(new IndexedLambda(shortValue))).build();
+ assertThat(selector, hasCriterionWithType(Type.OCH_SIGID));
+
+ selector = DefaultTrafficSelector.builder()
+ .add(Criteria.matchOpticalSignalType(shortValue)).build();
+ assertThat(selector, hasCriterionWithType(Type.OCH_SIGTYPE));
+ }
+
+ /**
+ * Tests the traffic selector builder.
+ */
+ @Test
+ public void testTrafficSelectorBuilder() {
+ TrafficSelector selector;
+ final short shortValue = 33;
+
+ final TrafficSelector baseSelector = DefaultTrafficSelector.builder()
+ .add(Criteria.matchLambda(new IndexedLambda(shortValue))).build();
+ selector = DefaultTrafficSelector.builder(baseSelector)
+ .build();
+ assertThat(selector, hasCriterionWithType(Type.OCH_SIGID));
+
+ final Criterion criterion = Criteria.matchLambda(shortValue);
+ selector = DefaultTrafficSelector.builder()
+ .add(criterion).build();
+ assertThat(selector, hasCriterionWithType(Type.OCH_SIGID));
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficTreatmentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficTreatmentTest.java
new file mode 100644
index 00000000..288f5f2f
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficTreatmentTest.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.IndexedLambda;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.flow.instructions.Instruction;
+import org.onosproject.net.flow.instructions.Instructions;
+
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+
+/**
+ * Unit tests for the DefaultTrafficTreatment class.
+ */
+public class DefaultTrafficTreatmentTest {
+
+ // Tests for the nested Builder class
+
+ /**
+ * Tests that the Builder constructors return equivalent objects
+ * when given the same data.
+ */
+ @Test
+ public void testTreatmentBuilderConstructors() {
+ final TrafficTreatment treatment1 =
+ DefaultTrafficTreatment.builder()
+ .add(Instructions.modL0Lambda(new IndexedLambda(4)))
+ .build();
+ final TrafficTreatment treatment2 =
+ DefaultTrafficTreatment.builder(treatment1).build();
+ assertThat(treatment1, is(equalTo(treatment2)));
+ }
+
+ /**
+ * Tests methods defined on the Builder.
+ */
+ @Test
+ public void testBuilderMethods() {
+ final Instruction instruction1 =
+ Instructions.modL0Lambda(new IndexedLambda(4));
+
+ final TrafficTreatment.Builder builder1 =
+ DefaultTrafficTreatment.builder()
+ .add(instruction1)
+ .setEthDst(MacAddress.BROADCAST)
+ .setEthSrc(MacAddress.BROADCAST)
+ .setIpDst(IpAddress.valueOf("1.1.1.1"))
+ .setIpSrc(IpAddress.valueOf("2.2.2.2"))
+ .add(Instructions.modL0Lambda(new IndexedLambda(4)))
+ .setOutput(PortNumber.portNumber(2))
+ .setVlanId(VlanId.vlanId((short) 4))
+ .setVlanPcp((byte) 3);
+
+ final TrafficTreatment treatment1 = builder1.build();
+
+ final List<Instruction> instructions1 = treatment1.immediate();
+ assertThat(instructions1, hasSize(9));
+
+ builder1.drop();
+ builder1.add(instruction1);
+
+ final List<Instruction> instructions2 = builder1.build().immediate();
+ assertThat(instructions2, hasSize(11));
+
+ builder1.deferred()
+ .popVlan()
+ .pushVlan()
+ .setVlanId(VlanId.vlanId((short) 5));
+
+ final List<Instruction> instructions3 = builder1.build().immediate();
+ assertThat(instructions3, hasSize(11));
+ final List<Instruction> instructions4 = builder1.build().deferred();
+ assertThat(instructions4, hasSize(3));
+ }
+
+ /**
+ * Tests equals(), hashCode() and toString() methods of
+ * DefaultTrafficTreatment.
+ */
+ @Test
+ public void testEquals() {
+ final IndexedLambda lambda1 = new IndexedLambda(4);
+ final IndexedLambda lambda2 = new IndexedLambda(5);
+ final TrafficTreatment treatment1 =
+ DefaultTrafficTreatment.builder()
+ .add(Instructions.modL0Lambda(lambda1))
+ .build();
+ final TrafficTreatment sameAsTreatment1 =
+ DefaultTrafficTreatment.builder()
+ .add(Instructions.modL0Lambda(lambda1))
+ .build();
+ final TrafficTreatment treatment2 =
+ DefaultTrafficTreatment.builder()
+ .add(Instructions.modL0Lambda(lambda2))
+ .build();
+ new EqualsTester()
+ .addEqualityGroup(treatment1, sameAsTreatment1)
+ .addEqualityGroup(treatment2)
+ .testEquals();
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowIdTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowIdTest.java
new file mode 100644
index 00000000..263d4031
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowIdTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2014 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+/**
+ * Unit tests for flow id class.
+ */
+public class FlowIdTest {
+
+ final FlowId flowId1 = FlowId.valueOf(1);
+ final FlowId sameAsFlowId1 = FlowId.valueOf(1);
+ final FlowId flowId2 = FlowId.valueOf(2);
+
+ /**
+ * Checks that the FlowId class is immutable.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(FlowId.class);
+ }
+
+ /**
+ * Checks the operation of equals(), hashCode() and toString() methods.
+ */
+ @Test
+ public void testEquals() {
+ new EqualsTester()
+ .addEqualityGroup(flowId1, sameAsFlowId1)
+ .addEqualityGroup(flowId2)
+ .testEquals();
+ }
+
+ /**
+ * Checks the construction of a FlowId object.
+ */
+ @Test
+ public void testConstruction() {
+ final long flowIdValue = 7777L;
+ final FlowId flowId = FlowId.valueOf(flowIdValue);
+ assertThat(flowId, is(notNullValue()));
+ assertThat(flowId.value(), is(flowIdValue));
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleBatchOperationTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleBatchOperationTest.java
new file mode 100644
index 00000000..4fa3492a
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleBatchOperationTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow;
+
+import java.util.LinkedList;
+
+import org.junit.Test;
+import org.onosproject.net.intent.IntentTestsMocks;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Unit tests for flow rule batch classes.
+ */
+public class FlowRuleBatchOperationTest {
+
+ /**
+ * Tests the equals(), hashCode() and toString() methods.
+ */
+ @Test
+ public void testEquals() {
+ final FlowRule rule = new IntentTestsMocks.MockFlowRule(1);
+ final FlowRuleBatchEntry entry1 = new FlowRuleBatchEntry(
+ FlowRuleBatchEntry.FlowRuleOperation.ADD, rule);
+ final FlowRuleBatchEntry entry2 = new FlowRuleBatchEntry(
+ FlowRuleBatchEntry.FlowRuleOperation.MODIFY, rule);
+ final FlowRuleBatchEntry entry3 = new FlowRuleBatchEntry(
+ FlowRuleBatchEntry.FlowRuleOperation.REMOVE, rule);
+ final LinkedList<FlowRuleBatchEntry> ops1 = new LinkedList<>();
+ ops1.add(entry1);
+ final LinkedList<FlowRuleBatchEntry> ops2 = new LinkedList<>();
+ ops1.add(entry2);
+ final LinkedList<FlowRuleBatchEntry> ops3 = new LinkedList<>();
+ ops3.add(entry3);
+
+ final FlowRuleBatchOperation operation1 = new FlowRuleBatchOperation(ops1, null, 0);
+ final FlowRuleBatchOperation sameAsOperation1 = new FlowRuleBatchOperation(ops1, null, 0);
+ final FlowRuleBatchOperation operation2 = new FlowRuleBatchOperation(ops2, null, 0);
+ final FlowRuleBatchOperation operation3 = new FlowRuleBatchOperation(ops3, null, 0);
+
+ new EqualsTester()
+ .addEqualityGroup(operation1, sameAsOperation1)
+ .addEqualityGroup(operation2)
+ .addEqualityGroup(operation3)
+ .testEquals();
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleBatchRequestTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleBatchRequestTest.java
new file mode 100644
index 00000000..b379a6ec
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleBatchRequestTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow;
+
+import org.junit.Test;
+import org.onosproject.net.intent.IntentTestsMocks;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation.ADD;
+import static org.onosproject.net.flow.FlowRuleBatchEntry.FlowRuleOperation.REMOVE;
+
+/**
+ * Unit tests for the FlowRuleBatchRequest class.
+ */
+public class FlowRuleBatchRequestTest {
+
+ /**
+ * Tests that construction of FlowRuleBatchRequest objects returns the
+ * correct objects.
+ */
+ @Test
+ public void testConstruction() {
+ final FlowRule rule1 = new IntentTestsMocks.MockFlowRule(1);
+ final FlowRule rule2 = new IntentTestsMocks.MockFlowRule(2);
+ final Set<FlowRuleBatchEntry> batch = new HashSet<>();
+ batch.add(new FlowRuleBatchEntry(ADD, rule1));
+
+ batch.add(new FlowRuleBatchEntry(REMOVE, rule2));
+
+
+ final FlowRuleBatchRequest request =
+ new FlowRuleBatchRequest(1, batch);
+
+ assertThat(request.ops(), hasSize(2));
+ assertThat(request.batchId(), is(1L));
+
+ final FlowRuleBatchOperation op = request.asBatchOperation(rule1.deviceId());
+ assertThat(op.size(), is(2));
+
+ final List<FlowRuleBatchEntry> ops = op.getOperations();
+ assertThat(ops, hasSize(2));
+ }
+
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleEventTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleEventTest.java
new file mode 100644
index 00000000..2d79c893
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleEventTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2014 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow;
+
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Test;
+import org.onosproject.event.AbstractEventTest;
+import org.onosproject.net.intent.IntentTestsMocks;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Unit Tests for the FlowRuleEvent class.
+ */
+public class FlowRuleEventTest extends AbstractEventTest {
+
+ @Test
+ public void testEquals() {
+ final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1);
+ final FlowRule flowRule2 = new IntentTestsMocks.MockFlowRule(2);
+ final long time = 123L;
+ final FlowRuleEvent event1 =
+ new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, flowRule1, time);
+ final FlowRuleEvent sameAsEvent1 =
+ new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, flowRule1, time);
+ final FlowRuleEvent event2 =
+ new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADD_REQUESTED,
+ flowRule2, time);
+
+ // Equality for events is based on Object, these should all compare
+ // as different.
+ new EqualsTester()
+ .addEqualityGroup(event1)
+ .addEqualityGroup(sameAsEvent1)
+ .addEqualityGroup(event2)
+ .testEquals();
+ }
+
+ /**
+ * Tests the constructor where a time is passed in.
+ */
+ @Test
+ public void testTimeConstructor() {
+ final long time = 123L;
+ final FlowRule flowRule = new IntentTestsMocks.MockFlowRule(1);
+ final FlowRuleEvent event =
+ new FlowRuleEvent(FlowRuleEvent.Type.RULE_REMOVE_REQUESTED, flowRule, time);
+ validateEvent(event, FlowRuleEvent.Type.RULE_REMOVE_REQUESTED, flowRule, time);
+ }
+
+ /**
+ * Tests the constructor with the default time value.
+ */
+ @Test
+ public void testConstructor() {
+ final long time = System.currentTimeMillis();
+ final FlowRule flowRule = new IntentTestsMocks.MockFlowRule(1);
+ final FlowRuleEvent event =
+ new FlowRuleEvent(FlowRuleEvent.Type.RULE_UPDATED, flowRule);
+ validateEvent(event, FlowRuleEvent.Type.RULE_UPDATED, flowRule, time,
+ time + TimeUnit.SECONDS.toMillis(30));
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleExtPayLoadTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleExtPayLoadTest.java
new file mode 100644
index 00000000..30326a2e
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleExtPayLoadTest.java
@@ -0,0 +1,36 @@
+package org.onosproject.net.flow;
+
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+/**
+ * Test for FlowRuleExtPayLoad.
+ */
+public class FlowRuleExtPayLoadTest {
+ final byte[] b = new byte[3];
+ final byte[] b1 = new byte[5];
+ final FlowRuleExtPayLoad payLoad1 = FlowRuleExtPayLoad.flowRuleExtPayLoad(b);
+ final FlowRuleExtPayLoad sameAsPayLoad1 = FlowRuleExtPayLoad.flowRuleExtPayLoad(b);
+ final FlowRuleExtPayLoad payLoad2 = FlowRuleExtPayLoad.flowRuleExtPayLoad(b1);
+
+ /**
+ * Checks that the FlowRuleExtPayLoad class is immutable.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(FlowRuleExtPayLoad.class);
+ }
+
+ /**
+ * Checks the operation of equals(), hashCode() and toString() methods.
+ */
+ @Test
+ public void testEquals() {
+ new EqualsTester()
+ .addEqualityGroup(payLoad1, sameAsPayLoad1)
+ .addEqualityGroup(payLoad2)
+ .testEquals();
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleServiceAdapter.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleServiceAdapter.java
new file mode 100644
index 00000000..c7b78791
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/FlowRuleServiceAdapter.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.flow;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.DeviceId;
+
+/**
+ * Test adapter for flow rule service.
+ */
+public class FlowRuleServiceAdapter implements FlowRuleService {
+ @Override
+ public int getFlowRuleCount() {
+ return 0;
+ }
+
+ @Override
+ public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public void applyFlowRules(FlowRule... flowRules) {
+
+ }
+
+ @Override
+ public void removeFlowRules(FlowRule... flowRules) {
+
+ }
+
+ @Override
+ public void removeFlowRulesById(ApplicationId appId) {
+
+ }
+
+ @Override
+ public Iterable<FlowRule> getFlowRulesById(ApplicationId id) {
+ return null;
+ }
+
+ @Override
+ public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
+ return null;
+ }
+
+ @Override
+ public void apply(FlowRuleOperations ops) {
+
+ }
+
+ @Override
+ public void addListener(FlowRuleListener listener) {
+
+ }
+
+ @Override
+ public void removeListener(FlowRuleListener listener) {
+
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
new file mode 100644
index 00000000..ee294f6f
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
@@ -0,0 +1,1138 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow.criteria;
+
+import org.junit.Test;
+import org.onlab.packet.EthType;
+import org.onlab.packet.Ip6Address;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.MplsLabel;
+import org.onlab.packet.TpPort;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.GridType;
+import org.onosproject.net.Lambda;
+import org.onosproject.net.PortNumber;
+
+import com.google.common.testing.EqualsTester;
+import org.onosproject.net.OchSignalType;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
+import static org.onosproject.net.PortNumber.portNumber;
+
+/**
+ * Unit tests for the Criteria class and its subclasses.
+ */
+public class CriteriaTest {
+
+ final PortNumber port1 = portNumber(1);
+ final PortNumber port2 = portNumber(2);
+
+ Criterion matchInPort1 = Criteria.matchInPort(port1);
+ Criterion sameAsMatchInPort1 = Criteria.matchInPort(port1);
+ Criterion matchInPort2 = Criteria.matchInPort(port2);
+
+ Criterion matchInPhyPort1 = Criteria.matchInPhyPort(port1);
+ Criterion sameAsMatchInPhyPort1 = Criteria.matchInPhyPort(port1);
+ Criterion matchInPhyPort2 = Criteria.matchInPhyPort(port2);
+
+ long metadata1 = 1;
+ long metadata2 = 2;
+ Criterion matchMetadata1 = Criteria.matchMetadata(metadata1);
+ Criterion sameAsMatchMetadata1 = Criteria.matchMetadata(metadata1);
+ Criterion matchMetadata2 = Criteria.matchMetadata(metadata2);
+
+ private static final String MAC1 = "00:00:00:00:00:01";
+ private static final String MAC2 = "00:00:00:00:00:02";
+ private MacAddress mac1 = MacAddress.valueOf(MAC1);
+ private MacAddress mac2 = MacAddress.valueOf(MAC2);
+ Criterion matchEth1 = Criteria.matchEthSrc(mac1);
+ Criterion sameAsMatchEth1 = Criteria.matchEthSrc(mac1);
+ Criterion matchEth2 = Criteria.matchEthDst(mac2);
+
+ int ethType1 = 1;
+ int ethType2 = 2;
+ Criterion matchEthType1 = Criteria.matchEthType(ethType1);
+ Criterion sameAsMatchEthType1 = Criteria.matchEthType(ethType1);
+ Criterion matchEthType2 = Criteria.matchEthType(ethType2);
+
+ short vlan1 = 1;
+ short vlan2 = 2;
+ VlanId vlanId1 = VlanId.vlanId(vlan1);
+ VlanId vlanId2 = VlanId.vlanId(vlan2);
+ Criterion matchVlanId1 = Criteria.matchVlanId(vlanId1);
+ Criterion sameAsMatchVlanId1 = Criteria.matchVlanId(vlanId1);
+ Criterion matchVlanId2 = Criteria.matchVlanId(vlanId2);
+
+ byte vlanPcp1 = 1;
+ byte vlanPcp2 = 2;
+ Criterion matchVlanPcp1 = Criteria.matchVlanPcp(vlanPcp1);
+ Criterion sameAsMatchVlanPcp1 = Criteria.matchVlanPcp(vlanPcp1);
+ Criterion matchVlanPcp2 = Criteria.matchVlanPcp(vlanPcp2);
+
+ byte ipDscp1 = 1;
+ byte ipDscp2 = 2;
+ Criterion matchIpDscp1 = Criteria.matchIPDscp(ipDscp1);
+ Criterion sameAsMatchIpDscp1 = Criteria.matchIPDscp(ipDscp1);
+ Criterion matchIpDscp2 = Criteria.matchIPDscp(ipDscp2);
+
+ byte ipEcn1 = 1;
+ byte ipEcn2 = 2;
+ Criterion matchIpEcn1 = Criteria.matchIPEcn(ipEcn1);
+ Criterion sameAsMatchIpEcn1 = Criteria.matchIPEcn(ipEcn1);
+ Criterion matchIpEcn2 = Criteria.matchIPEcn(ipEcn2);
+
+ short protocol1 = 1;
+ short protocol2 = 2;
+ Criterion matchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
+ Criterion sameAsMatchIpProtocol1 = Criteria.matchIPProtocol(protocol1);
+ Criterion matchIpProtocol2 = Criteria.matchIPProtocol(protocol2);
+
+ private static final String IP1 = "1.2.3.4/24";
+ private static final String IP2 = "5.6.7.8/24";
+ private static final String IPV61 = "fe80::1/64";
+ private static final String IPV62 = "fc80::2/64";
+ private IpPrefix ip1 = IpPrefix.valueOf(IP1);
+ private IpPrefix ip2 = IpPrefix.valueOf(IP2);
+ private IpPrefix ipv61 = IpPrefix.valueOf(IPV61);
+ private IpPrefix ipv62 = IpPrefix.valueOf(IPV62);
+ Criterion matchIp1 = Criteria.matchIPSrc(ip1);
+ Criterion sameAsMatchIp1 = Criteria.matchIPSrc(ip1);
+ Criterion matchIp2 = Criteria.matchIPSrc(ip2);
+ Criterion matchIpv61 = Criteria.matchIPSrc(ipv61);
+ Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61);
+ Criterion matchIpv62 = Criteria.matchIPSrc(ipv62);
+
+ private TpPort tpPort1 = TpPort.tpPort(1);
+ private TpPort tpPort2 = TpPort.tpPort(2);
+ Criterion matchTcpPort1 = Criteria.matchTcpSrc(tpPort1);
+ Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc(tpPort1);
+ Criterion matchTcpPort2 = Criteria.matchTcpDst(tpPort2);
+
+ Criterion matchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
+ Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc(tpPort1);
+ Criterion matchUdpPort2 = Criteria.matchUdpDst(tpPort2);
+
+ Criterion matchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
+ Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc(tpPort1);
+ Criterion matchSctpPort2 = Criteria.matchSctpDst(tpPort2);
+
+ short icmpType1 = 1;
+ short icmpType2 = 2;
+ Criterion matchIcmpType1 = Criteria.matchIcmpType(icmpType1);
+ Criterion sameAsMatchIcmpType1 = Criteria.matchIcmpType(icmpType1);
+ Criterion matchIcmpType2 = Criteria.matchIcmpType(icmpType2);
+
+ short icmpCode1 = 1;
+ short icmpCode2 = 2;
+ Criterion matchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
+ Criterion sameAsMatchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
+ Criterion matchIcmpCode2 = Criteria.matchIcmpCode(icmpCode2);
+
+ int flowLabel1 = 1;
+ int flowLabel2 = 2;
+ Criterion matchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
+ Criterion sameAsMatchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
+ Criterion matchFlowLabel2 = Criteria.matchIPv6FlowLabel(flowLabel2);
+
+ short icmpv6Type1 = 1;
+ short icmpv6Type2 = 2;
+ Criterion matchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
+ Criterion sameAsMatchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
+ Criterion matchIcmpv6Type2 = Criteria.matchIcmpv6Type(icmpv6Type2);
+
+ short icmpv6Code1 = 1;
+ short icmpv6Code2 = 2;
+ Criterion matchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
+ Criterion sameAsMatchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
+ Criterion matchIcmpv6Code2 = Criteria.matchIcmpv6Code(icmpv6Code2);
+
+ private static final String IPV6_ADDR1 = "fe80::1";
+ private static final String IPV6_ADDR2 = "fe80::2";
+ private Ip6Address ip6TargetAddress1 = Ip6Address.valueOf(IPV6_ADDR1);
+ private Ip6Address ip6TargetAddress2 = Ip6Address.valueOf(IPV6_ADDR2);
+ Criterion matchIpv6TargetAddr1 =
+ Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
+ Criterion sameAsMatchIpv6TargetAddr1 =
+ Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
+ Criterion matchIpv6TargetAddr2 =
+ Criteria.matchIPv6NDTargetAddress(ip6TargetAddress2);
+
+ private static final String LL_MAC1 = "00:00:00:00:00:01";
+ private static final String LL_MAC2 = "00:00:00:00:00:02";
+ private MacAddress llMac1 = MacAddress.valueOf(LL_MAC1);
+ private MacAddress llMac2 = MacAddress.valueOf(LL_MAC2);
+ Criterion matchSrcLlAddr1 =
+ Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
+ Criterion sameAsMatchSrcLlAddr1 =
+ Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
+ Criterion matchSrcLlAddr2 =
+ Criteria.matchIPv6NDSourceLinkLayerAddress(llMac2);
+ Criterion matchTargetLlAddr1 =
+ Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
+ Criterion sameAsMatchTargetLlAddr1 =
+ Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
+ Criterion matchTargetLlAddr2 =
+ Criteria.matchIPv6NDTargetLinkLayerAddress(llMac2);
+
+ MplsLabel mpls1 = MplsLabel.mplsLabel(1);
+ MplsLabel mpls2 = MplsLabel.mplsLabel(2);
+ Criterion matchMpls1 = Criteria.matchMplsLabel(mpls1);
+ Criterion sameAsMatchMpls1 = Criteria.matchMplsLabel(mpls1);
+ Criterion matchMpls2 = Criteria.matchMplsLabel(mpls2);
+
+ long tunnelId1 = 1;
+ long tunnelId2 = 2;
+ Criterion matchTunnelId1 = Criteria.matchTunnelId(tunnelId1);
+ Criterion sameAsMatchTunnelId1 = Criteria.matchTunnelId(tunnelId1);
+ Criterion matchTunnelId2 = Criteria.matchTunnelId(tunnelId2);
+
+ int ipv6ExthdrFlags1 =
+ Criterion.IPv6ExthdrFlags.NONEXT.getValue() |
+ Criterion.IPv6ExthdrFlags.ESP.getValue() |
+ Criterion.IPv6ExthdrFlags.AUTH.getValue() |
+ Criterion.IPv6ExthdrFlags.DEST.getValue() |
+ Criterion.IPv6ExthdrFlags.FRAG.getValue() |
+ Criterion.IPv6ExthdrFlags.ROUTER.getValue() |
+ Criterion.IPv6ExthdrFlags.HOP.getValue() |
+ Criterion.IPv6ExthdrFlags.UNREP.getValue();
+ int ipv6ExthdrFlags2 = ipv6ExthdrFlags1 |
+ Criterion.IPv6ExthdrFlags.UNSEQ.getValue();
+ Criterion matchIpv6ExthdrFlags1 =
+ Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
+ Criterion sameAsMatchIpv6ExthdrFlags1 =
+ Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
+ Criterion matchIpv6ExthdrFlags2 =
+ Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags2);
+
+ int lambda1 = 1;
+ int lambda2 = 2;
+ Criterion matchLambda1 = Criteria.matchLambda(lambda1);
+ Criterion sameAsMatchLambda1 = Criteria.matchLambda(lambda1);
+ Criterion matchLambda2 = Criteria.matchLambda(lambda2);
+
+ Criterion matchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
+ Criterion sameAsMatchOchSignalType1 = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID);
+ Criterion matchOchSignalType2 = Criteria.matchOchSignalType(OchSignalType.FLEX_GRID);
+
+ Criterion matchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
+ Criterion sameAsMatchIndexedLambda1 = Criteria.matchLambda(Lambda.indexedLambda(1));
+ Criterion matchIndexedLambda2 = Criteria.matchLambda(Lambda.indexedLambda(2));
+
+ short signalLambda1 = 1;
+ short signalLambda2 = 2;
+ Criterion matchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1);
+ Criterion sameAsMatchSignalLambda1 = Criteria.matchOpticalSignalType(signalLambda1);
+ Criterion matchSignalLambda2 = Criteria.matchOpticalSignalType(signalLambda2);
+
+ Criterion matchOchSignal1 =
+ Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
+ Criterion sameAsMatchOchSignal1 =
+ Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
+ Criterion matchOchSignal2 =
+ Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8));
+
+ /**
+ * Checks that a Criterion object has the proper type, and then converts
+ * it to the proper type.
+ *
+ * @param criterion Criterion object to convert
+ * @param type Enumerated type value for the Criterion class
+ * @param clazz Desired Criterion class
+ * @param <T> The type the caller wants returned
+ * @return converted object
+ */
+ @SuppressWarnings("unchecked")
+ private <T> T checkAndConvert(Criterion criterion, Criterion.Type type, Class clazz) {
+ assertThat(criterion, is(notNullValue()));
+ assertThat(criterion.type(), is(equalTo(type)));
+ assertThat(criterion, instanceOf(clazz));
+ return (T) criterion;
+ }
+
+ /**
+ * Check that the Criteria class is a valid utility class.
+ */
+ @Test
+ public void testCriteriaUtility() {
+ assertThatClassIsUtility(Criteria.class);
+ }
+
+ /**
+ * Check that the Criteria implementations are immutable.
+ */
+ @Test
+ public void testCriteriaImmutability() {
+ assertThatClassIsImmutable(PortCriterion.class);
+ assertThatClassIsImmutable(MetadataCriterion.class);
+ assertThatClassIsImmutable(EthCriterion.class);
+ assertThatClassIsImmutable(EthTypeCriterion.class);
+ assertThatClassIsImmutable(VlanIdCriterion.class);
+ assertThatClassIsImmutable(VlanPcpCriterion.class);
+ assertThatClassIsImmutable(IPDscpCriterion.class);
+ assertThatClassIsImmutable(IPEcnCriterion.class);
+ assertThatClassIsImmutable(IPProtocolCriterion.class);
+ assertThatClassIsImmutable(IPCriterion.class);
+ assertThatClassIsImmutable(TcpPortCriterion.class);
+ assertThatClassIsImmutable(UdpPortCriterion.class);
+ assertThatClassIsImmutable(SctpPortCriterion.class);
+ assertThatClassIsImmutable(IcmpTypeCriterion.class);
+ assertThatClassIsImmutable(IcmpCodeCriterion.class);
+ assertThatClassIsImmutable(IPv6FlowLabelCriterion.class);
+ assertThatClassIsImmutable(Icmpv6TypeCriterion.class);
+ assertThatClassIsImmutable(Icmpv6CodeCriterion.class);
+ assertThatClassIsImmutable(IPv6NDTargetAddressCriterion.class);
+ assertThatClassIsImmutable(IPv6NDLinkLayerAddressCriterion.class);
+ assertThatClassIsImmutable(MplsCriterion.class);
+ assertThatClassIsImmutable(IPv6ExthdrFlagsCriterion.class);
+ assertThatClassIsImmutable(LambdaCriterion.class);
+ assertThatClassIsImmutable(OpticalSignalTypeCriterion.class);
+ }
+
+ // PortCriterion class
+
+ /**
+ * Test the matchInPort method.
+ */
+ @Test
+ public void testMatchInPortMethod() {
+ PortNumber p1 = portNumber(1);
+ Criterion matchInPort = Criteria.matchInPort(p1);
+ PortCriterion portCriterion =
+ checkAndConvert(matchInPort,
+ Criterion.Type.IN_PORT,
+ PortCriterion.class);
+ assertThat(portCriterion.port(), is(equalTo(p1)));
+ }
+
+ /**
+ * Test the matchInPhyPort method.
+ */
+ @Test
+ public void testMatchInPhyPortMethod() {
+ PortNumber p1 = portNumber(1);
+ Criterion matchInPhyPort = Criteria.matchInPhyPort(p1);
+ PortCriterion portCriterion =
+ checkAndConvert(matchInPhyPort,
+ Criterion.Type.IN_PHY_PORT,
+ PortCriterion.class);
+ assertThat(portCriterion.port(), is(equalTo(p1)));
+ }
+
+ /**
+ * Test the equals() method of the PortCriterion class.
+ */
+ @Test
+ public void testPortCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchInPort1, sameAsMatchInPort1)
+ .addEqualityGroup(matchInPort2)
+ .testEquals();
+
+ new EqualsTester()
+ .addEqualityGroup(matchInPhyPort1, sameAsMatchInPhyPort1)
+ .addEqualityGroup(matchInPhyPort2)
+ .testEquals();
+ }
+
+ // MetadataCriterion class
+
+ /**
+ * Test the matchMetadata method.
+ */
+ @Test
+ public void testMatchMetadataMethod() {
+ Long metadata = 12L;
+ Criterion matchMetadata = Criteria.matchMetadata(metadata);
+ MetadataCriterion metadataCriterion =
+ checkAndConvert(matchMetadata,
+ Criterion.Type.METADATA,
+ MetadataCriterion.class);
+ assertThat(metadataCriterion.metadata(), is(equalTo(metadata)));
+ }
+
+ /**
+ * Test the equals() method of the MetadataCriterion class.
+ */
+ @Test
+ public void testMetadataCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchMetadata1, sameAsMatchMetadata1)
+ .addEqualityGroup(matchMetadata2)
+ .testEquals();
+ }
+
+ // EthCriterion class
+
+ /**
+ * Test the matchEthDst method.
+ */
+ @Test
+ public void testMatchEthDstMethod() {
+ Criterion matchEthDst = Criteria.matchEthDst(mac1);
+ EthCriterion ethCriterion =
+ checkAndConvert(matchEthDst,
+ Criterion.Type.ETH_DST,
+ EthCriterion.class);
+ assertThat(ethCriterion.mac(), is(equalTo(mac1)));
+ }
+
+ /**
+ * Test the matchEthSrc method.
+ */
+ @Test
+ public void testMatchEthSrcMethod() {
+ Criterion matchEthSrc = Criteria.matchEthSrc(mac1);
+ EthCriterion ethCriterion =
+ checkAndConvert(matchEthSrc,
+ Criterion.Type.ETH_SRC,
+ EthCriterion.class);
+ assertThat(ethCriterion.mac(), is(mac1));
+ }
+
+ /**
+ * Test the equals() method of the EthCriterion class.
+ */
+ @Test
+ public void testEthCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchEth1, sameAsMatchEth1)
+ .addEqualityGroup(matchEth2)
+ .testEquals();
+ }
+
+ // EthTypeCriterion class
+
+ /**
+ * Test the matchEthType method.
+ */
+ @Test
+ public void testMatchEthTypeMethod() {
+ EthType ethType = new EthType(12);
+ Criterion matchEthType = Criteria.matchEthType(new EthType(12));
+ EthTypeCriterion ethTypeCriterion =
+ checkAndConvert(matchEthType,
+ Criterion.Type.ETH_TYPE,
+ EthTypeCriterion.class);
+ assertThat(ethTypeCriterion.ethType(), is(equalTo(ethType)));
+ }
+
+ /**
+ * Test the equals() method of the EthTypeCriterion class.
+ */
+ @Test
+ public void testEthTypeCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchEthType1, sameAsMatchEthType1)
+ .addEqualityGroup(matchEthType2)
+ .testEquals();
+ }
+
+ // VlanIdCriterion class
+
+ /**
+ * Test the matchVlanId method.
+ */
+ @Test
+ public void testMatchVlanIdMethod() {
+ Criterion matchVlanId = Criteria.matchVlanId(vlanId1);
+ VlanIdCriterion vlanIdCriterion =
+ checkAndConvert(matchVlanId,
+ Criterion.Type.VLAN_VID,
+ VlanIdCriterion.class);
+ assertThat(vlanIdCriterion.vlanId(), is(equalTo(vlanId1)));
+ }
+
+ /**
+ * Test the equals() method of the VlanIdCriterion class.
+ */
+ @Test
+ public void testVlanIdCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchVlanId1, sameAsMatchVlanId1)
+ .addEqualityGroup(matchVlanId2)
+ .testEquals();
+ }
+
+ // VlanPcpCriterion class
+
+ /**
+ * Test the matchVlanPcp method.
+ */
+ @Test
+ public void testMatchVlanPcpMethod() {
+ Criterion matchVlanPcp = Criteria.matchVlanPcp(vlanPcp1);
+ VlanPcpCriterion vlanPcpCriterion =
+ checkAndConvert(matchVlanPcp,
+ Criterion.Type.VLAN_PCP,
+ VlanPcpCriterion.class);
+ assertThat(vlanPcpCriterion.priority(), is(equalTo(vlanPcp1)));
+ }
+
+ /**
+ * Test the equals() method of the VlanPcpCriterion class.
+ */
+ @Test
+ public void testVlanPcpCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchVlanPcp1, sameAsMatchVlanPcp1)
+ .addEqualityGroup(matchVlanPcp2)
+ .testEquals();
+ }
+
+ // IPDscpCriterion class
+
+ /**
+ * Test the matchIPDscp method.
+ */
+ @Test
+ public void testMatchIPDscpMethod() {
+ Criterion matchIPDscp = Criteria.matchIPDscp(ipDscp1);
+ IPDscpCriterion ipDscpCriterion =
+ checkAndConvert(matchIPDscp,
+ Criterion.Type.IP_DSCP,
+ IPDscpCriterion.class);
+ assertThat(ipDscpCriterion.ipDscp(), is(equalTo(ipDscp1)));
+ }
+
+ /**
+ * Test the equals() method of the IPDscpCriterion class.
+ */
+ @Test
+ public void testIPDscpCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIpDscp1, sameAsMatchIpDscp1)
+ .addEqualityGroup(matchIpDscp2)
+ .testEquals();
+ }
+
+ // IPEcnCriterion class
+
+ /**
+ * Test the matchIPEcn method.
+ */
+ @Test
+ public void testMatchIPEcnMethod() {
+ Criterion matchIPEcn = Criteria.matchIPEcn(ipEcn1);
+ IPEcnCriterion ipEcnCriterion =
+ checkAndConvert(matchIPEcn,
+ Criterion.Type.IP_ECN,
+ IPEcnCriterion.class);
+ assertThat(ipEcnCriterion.ipEcn(), is(equalTo(ipEcn1)));
+ }
+
+ /**
+ * Test the equals() method of the IPEcnCriterion class.
+ */
+ @Test
+ public void testIPEcnCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIpEcn1, sameAsMatchIpEcn1)
+ .addEqualityGroup(matchIpEcn2)
+ .testEquals();
+ }
+
+ // IpProtocolCriterion class
+
+ /**
+ * Test the matchIpProtocol method.
+ */
+ @Test
+ public void testMatchIpProtocolMethod() {
+ Criterion matchIPProtocol = Criteria.matchIPProtocol(protocol1);
+ IPProtocolCriterion ipProtocolCriterion =
+ checkAndConvert(matchIPProtocol,
+ Criterion.Type.IP_PROTO,
+ IPProtocolCriterion.class);
+ assertThat(ipProtocolCriterion.protocol(), is(equalTo(protocol1)));
+ }
+
+ /**
+ * Test the equals() method of the IpProtocolCriterion class.
+ */
+ @Test
+ public void testIpProtocolCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIpProtocol1, sameAsMatchIpProtocol1)
+ .addEqualityGroup(matchIpProtocol2)
+ .testEquals();
+ }
+
+ // IPCriterion class
+
+ /**
+ * Test the matchIPSrc method: IPv4.
+ */
+ @Test
+ public void testMatchIPSrcMethod() {
+ Criterion matchIpSrc = Criteria.matchIPSrc(ip1);
+ IPCriterion ipCriterion =
+ checkAndConvert(matchIpSrc,
+ Criterion.Type.IPV4_SRC,
+ IPCriterion.class);
+ assertThat(ipCriterion.ip(), is(ip1));
+ }
+
+ /**
+ * Test the matchIPDst method: IPv4.
+ */
+ @Test
+ public void testMatchIPDstMethod() {
+ Criterion matchIPDst = Criteria.matchIPDst(ip1);
+ IPCriterion ipCriterion =
+ checkAndConvert(matchIPDst,
+ Criterion.Type.IPV4_DST,
+ IPCriterion.class);
+ assertThat(ipCriterion.ip(), is(equalTo(ip1)));
+ }
+
+ /**
+ * Test the matchIPSrc method: IPv6.
+ */
+ @Test
+ public void testMatchIPv6SrcMethod() {
+ Criterion matchIpv6Src = Criteria.matchIPv6Src(ipv61);
+ IPCriterion ipCriterion =
+ checkAndConvert(matchIpv6Src,
+ Criterion.Type.IPV6_SRC,
+ IPCriterion.class);
+ assertThat(ipCriterion.ip(), is(ipv61));
+ }
+
+ /**
+ * Test the matchIPDst method: IPv6.
+ */
+ @Test
+ public void testMatchIPv6DstMethod() {
+ Criterion matchIPv6Dst = Criteria.matchIPv6Dst(ipv61);
+ IPCriterion ipCriterion =
+ checkAndConvert(matchIPv6Dst,
+ Criterion.Type.IPV6_DST,
+ IPCriterion.class);
+ assertThat(ipCriterion.ip(), is(equalTo(ipv61)));
+ }
+
+ /**
+ * Test the equals() method of the IpCriterion class.
+ */
+ @Test
+ public void testIPCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIp1, sameAsMatchIp1)
+ .addEqualityGroup(matchIp2)
+ .testEquals();
+
+ new EqualsTester()
+ .addEqualityGroup(matchIpv61, sameAsMatchIpv61)
+ .addEqualityGroup(matchIpv62)
+ .testEquals();
+ }
+
+ // TcpPortCriterion class
+
+ /**
+ * Test the matchTcpSrc method.
+ */
+ @Test
+ public void testMatchTcpSrcMethod() {
+ Criterion matchTcpSrc = Criteria.matchTcpSrc(tpPort1);
+ TcpPortCriterion tcpPortCriterion =
+ checkAndConvert(matchTcpSrc,
+ Criterion.Type.TCP_SRC,
+ TcpPortCriterion.class);
+ assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
+ }
+
+ /**
+ * Test the matchTcpDst method.
+ */
+ @Test
+ public void testMatchTcpDstMethod() {
+ Criterion matchTcpDst = Criteria.matchTcpDst(tpPort1);
+ TcpPortCriterion tcpPortCriterion =
+ checkAndConvert(matchTcpDst,
+ Criterion.Type.TCP_DST,
+ TcpPortCriterion.class);
+ assertThat(tcpPortCriterion.tcpPort(), is(equalTo(tpPort1)));
+ }
+
+ /**
+ * Test the equals() method of the TcpPortCriterion class.
+ */
+ @Test
+ public void testTcpPortCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchTcpPort1, sameAsMatchTcpPort1)
+ .addEqualityGroup(matchTcpPort2)
+ .testEquals();
+ }
+
+ // UdpPortCriterion class
+
+ /**
+ * Test the matchUdpSrc method.
+ */
+ @Test
+ public void testMatchUdpSrcMethod() {
+ Criterion matchUdpSrc = Criteria.matchUdpSrc(tpPort1);
+ UdpPortCriterion udpPortCriterion =
+ checkAndConvert(matchUdpSrc,
+ Criterion.Type.UDP_SRC,
+ UdpPortCriterion.class);
+ assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
+ }
+
+ /**
+ * Test the matchUdpDst method.
+ */
+ @Test
+ public void testMatchUdpDstMethod() {
+ Criterion matchUdpDst = Criteria.matchUdpDst(tpPort1);
+ UdpPortCriterion udpPortCriterion =
+ checkAndConvert(matchUdpDst,
+ Criterion.Type.UDP_DST,
+ UdpPortCriterion.class);
+ assertThat(udpPortCriterion.udpPort(), is(equalTo(tpPort1)));
+ }
+
+ /**
+ * Test the equals() method of the UdpPortCriterion class.
+ */
+ @Test
+ public void testUdpPortCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchUdpPort1, sameAsMatchUdpPort1)
+ .addEqualityGroup(matchUdpPort2)
+ .testEquals();
+ }
+
+ // SctpPortCriterion class
+
+ /**
+ * Test the matchSctpSrc method.
+ */
+ @Test
+ public void testMatchSctpSrcMethod() {
+ Criterion matchSctpSrc = Criteria.matchSctpSrc(tpPort1);
+ SctpPortCriterion sctpPortCriterion =
+ checkAndConvert(matchSctpSrc,
+ Criterion.Type.SCTP_SRC,
+ SctpPortCriterion.class);
+ assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
+ }
+
+ /**
+ * Test the matchSctpDst method.
+ */
+ @Test
+ public void testMatchSctpDstMethod() {
+ Criterion matchSctpDst = Criteria.matchSctpDst(tpPort1);
+ SctpPortCriterion sctpPortCriterion =
+ checkAndConvert(matchSctpDst,
+ Criterion.Type.SCTP_DST,
+ SctpPortCriterion.class);
+ assertThat(sctpPortCriterion.sctpPort(), is(equalTo(tpPort1)));
+ }
+
+ /**
+ * Test the equals() method of the SctpPortCriterion class.
+ */
+ @Test
+ public void testSctpPortCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchSctpPort1, sameAsMatchSctpPort1)
+ .addEqualityGroup(matchSctpPort2)
+ .testEquals();
+ }
+
+ // IcmpTypeCriterion class
+
+ /**
+ * Test the matchIcmpType method.
+ */
+ @Test
+ public void testMatchIcmpTypeMethod() {
+ short icmpType = 12;
+ Criterion matchIcmpType = Criteria.matchIcmpType(icmpType);
+ IcmpTypeCriterion icmpTypeCriterion =
+ checkAndConvert(matchIcmpType,
+ Criterion.Type.ICMPV4_TYPE,
+ IcmpTypeCriterion.class);
+ assertThat(icmpTypeCriterion.icmpType(), is(equalTo(icmpType)));
+ }
+
+ /**
+ * Test the equals() method of the IcmpTypeCriterion class.
+ */
+ @Test
+ public void testIcmpTypeCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIcmpType1, sameAsMatchIcmpType1)
+ .addEqualityGroup(matchIcmpType2)
+ .testEquals();
+ }
+
+ // IcmpCodeCriterion class
+
+ /**
+ * Test the matchIcmpCode method.
+ */
+ @Test
+ public void testMatchIcmpCodeMethod() {
+ short icmpCode = 12;
+ Criterion matchIcmpCode = Criteria.matchIcmpCode(icmpCode);
+ IcmpCodeCriterion icmpCodeCriterion =
+ checkAndConvert(matchIcmpCode,
+ Criterion.Type.ICMPV4_CODE,
+ IcmpCodeCriterion.class);
+ assertThat(icmpCodeCriterion.icmpCode(), is(equalTo(icmpCode)));
+ }
+
+ /**
+ * Test the equals() method of the IcmpCodeCriterion class.
+ */
+ @Test
+ public void testIcmpCodeCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIcmpCode1, sameAsMatchIcmpCode1)
+ .addEqualityGroup(matchIcmpCode2)
+ .testEquals();
+ }
+
+ // IPv6FlowLabelCriterion class
+
+ /**
+ * Test the matchIPv6FlowLabel method.
+ */
+ @Test
+ public void testMatchIPv6FlowLabelMethod() {
+ int flowLabel = 12;
+ Criterion matchFlowLabel = Criteria.matchIPv6FlowLabel(flowLabel);
+ IPv6FlowLabelCriterion flowLabelCriterion =
+ checkAndConvert(matchFlowLabel,
+ Criterion.Type.IPV6_FLABEL,
+ IPv6FlowLabelCriterion.class);
+ assertThat(flowLabelCriterion.flowLabel(), is(equalTo(flowLabel)));
+ }
+
+ /**
+ * Test the equals() method of the IPv6FlowLabelCriterion class.
+ */
+ @Test
+ public void testIPv6FlowLabelCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchFlowLabel1, sameAsMatchFlowLabel1)
+ .addEqualityGroup(matchFlowLabel2)
+ .testEquals();
+ }
+
+ // Icmpv6TypeCriterion class
+
+ /**
+ * Test the matchIcmpv6Type method.
+ */
+ @Test
+ public void testMatchIcmpv6TypeMethod() {
+ short icmpv6Type = 12;
+ Criterion matchIcmpv6Type = Criteria.matchIcmpv6Type(icmpv6Type);
+ Icmpv6TypeCriterion icmpv6TypeCriterion =
+ checkAndConvert(matchIcmpv6Type,
+ Criterion.Type.ICMPV6_TYPE,
+ Icmpv6TypeCriterion.class);
+ assertThat(icmpv6TypeCriterion.icmpv6Type(), is(equalTo(icmpv6Type)));
+ }
+
+ /**
+ * Test the equals() method of the Icmpv6TypeCriterion class.
+ */
+ @Test
+ public void testIcmpv6TypeCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIcmpv6Type1, sameAsMatchIcmpv6Type1)
+ .addEqualityGroup(matchIcmpv6Type2)
+ .testEquals();
+ }
+
+ // Icmpv6CodeCriterion class
+
+ /**
+ * Test the matchIcmpv6Code method.
+ */
+ @Test
+ public void testMatchIcmpv6CodeMethod() {
+ short icmpv6Code = 12;
+ Criterion matchIcmpv6Code = Criteria.matchIcmpv6Code(icmpv6Code);
+ Icmpv6CodeCriterion icmpv6CodeCriterion =
+ checkAndConvert(matchIcmpv6Code,
+ Criterion.Type.ICMPV6_CODE,
+ Icmpv6CodeCriterion.class);
+ assertThat(icmpv6CodeCriterion.icmpv6Code(), is(equalTo(icmpv6Code)));
+ }
+
+ /**
+ * Test the equals() method of the Icmpv6CodeCriterion class.
+ */
+ @Test
+ public void testIcmpv6CodeCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIcmpv6Code1, sameAsMatchIcmpv6Code1)
+ .addEqualityGroup(matchIcmpv6Code2)
+ .testEquals();
+ }
+
+ // IPv6NDTargetAddressCriterion class
+
+ /**
+ * Test the matchIPv6NDTargetAddress method.
+ */
+ @Test
+ public void testMatchIPv6NDTargetAddressMethod() {
+ Criterion matchTargetAddress =
+ Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
+ IPv6NDTargetAddressCriterion targetAddressCriterion =
+ checkAndConvert(matchTargetAddress,
+ Criterion.Type.IPV6_ND_TARGET,
+ IPv6NDTargetAddressCriterion.class);
+ assertThat(targetAddressCriterion.targetAddress(),
+ is(ip6TargetAddress1));
+ }
+
+ /**
+ * Test the equals() method of the IPv6NDTargetAddressCriterion class.
+ */
+ @Test
+ public void testIPv6NDTargetAddressCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIpv6TargetAddr1,
+ sameAsMatchIpv6TargetAddr1)
+ .addEqualityGroup(matchIpv6TargetAddr2)
+ .testEquals();
+ }
+
+ // IPv6NDLinkLayerAddressCriterion class
+
+ /**
+ * Test the matchIPv6NDSourceLinkLayerAddress method.
+ */
+ @Test
+ public void testMatchIPv6NDSourceLinkLayerAddressMethod() {
+ Criterion matchSrcLlAddr =
+ Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
+ IPv6NDLinkLayerAddressCriterion srcLlCriterion =
+ checkAndConvert(matchSrcLlAddr,
+ Criterion.Type.IPV6_ND_SLL,
+ IPv6NDLinkLayerAddressCriterion.class);
+ assertThat(srcLlCriterion.mac(), is(equalTo(llMac1)));
+ }
+
+ /**
+ * Test the matchIPv6NDTargetLinkLayerAddress method.
+ */
+ @Test
+ public void testMatchIPv6NDTargetLinkLayerAddressMethod() {
+ Criterion matchTargetLlAddr =
+ Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
+ IPv6NDLinkLayerAddressCriterion targetLlCriterion =
+ checkAndConvert(matchTargetLlAddr,
+ Criterion.Type.IPV6_ND_TLL,
+ IPv6NDLinkLayerAddressCriterion.class);
+ assertThat(targetLlCriterion.mac(), is(equalTo(llMac1)));
+ }
+
+ /**
+ * Test the equals() method of the IPv6NDLinkLayerAddressCriterion class.
+ */
+ @Test
+ public void testIPv6NDLinkLayerAddressCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchSrcLlAddr1, sameAsMatchSrcLlAddr1)
+ .addEqualityGroup(matchSrcLlAddr2)
+ .testEquals();
+
+ new EqualsTester()
+ .addEqualityGroup(matchTargetLlAddr1, sameAsMatchTargetLlAddr1)
+ .addEqualityGroup(matchTargetLlAddr2)
+ .testEquals();
+ }
+
+ // MplsCriterion class
+
+ /**
+ * Test the matchMplsLabel method.
+ */
+ @Test
+ public void testMatchMplsLabelMethod() {
+ Criterion matchMplsLabel = Criteria.matchMplsLabel(mpls1);
+ MplsCriterion mplsCriterion =
+ checkAndConvert(matchMplsLabel,
+ Criterion.Type.MPLS_LABEL,
+ MplsCriterion.class);
+ assertThat(mplsCriterion.label(), is(equalTo(mpls1)));
+ }
+
+ /**
+ * Test the equals() method of the MplsCriterion class.
+ */
+ @Test
+ public void testMplsCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchMpls1, sameAsMatchMpls1)
+ .addEqualityGroup(matchMpls2)
+ .testEquals();
+ }
+
+ // TunnelIdCriterion class
+
+ /**
+ * Test the matchTunnelId method.
+ */
+ @Test
+ public void testMatchTunnelIdMethod() {
+ Criterion matchTunnelId = Criteria.matchTunnelId(tunnelId1);
+ TunnelIdCriterion tunnelIdCriterion =
+ checkAndConvert(matchTunnelId,
+ Criterion.Type.TUNNEL_ID,
+ TunnelIdCriterion.class);
+ assertThat(tunnelIdCriterion.tunnelId(), is(equalTo(tunnelId1)));
+
+ }
+
+ /**
+ * Test the equals() method of the TunnelIdCriterion class.
+ */
+ @Test
+ public void testTunnelIdCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchTunnelId1, sameAsMatchTunnelId1)
+ .addEqualityGroup(matchTunnelId2)
+ .testEquals();
+ }
+
+ // IPv6ExthdrFlagsCriterion class
+
+ /**
+ * Test the matchIPv6ExthdrFlags method.
+ */
+ @Test
+ public void testMatchIPv6ExthdrFlagsMethod() {
+ Criterion matchExthdrFlags =
+ Criteria.matchIPv6ExthdrFlags(ipv6ExthdrFlags1);
+ IPv6ExthdrFlagsCriterion exthdrFlagsCriterion =
+ checkAndConvert(matchExthdrFlags,
+ Criterion.Type.IPV6_EXTHDR,
+ IPv6ExthdrFlagsCriterion.class);
+ assertThat(exthdrFlagsCriterion.exthdrFlags(),
+ is(equalTo(ipv6ExthdrFlags1)));
+ }
+
+ /**
+ * Test the equals() method of the IPv6ExthdrFlagsCriterion class.
+ */
+ @Test
+ public void testIPv6ExthdrFlagsCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIpv6ExthdrFlags1,
+ sameAsMatchIpv6ExthdrFlags1)
+ .addEqualityGroup(matchIpv6ExthdrFlags2)
+ .testEquals();
+ }
+
+ // LambdaCriterion class
+
+ /**
+ * Test the matchLambda method.
+ */
+ @Test
+ public void testMatchLambdaMethod() {
+ Criterion matchLambda = Criteria.matchLambda(lambda1);
+ LambdaCriterion lambdaCriterion =
+ checkAndConvert(matchLambda,
+ Criterion.Type.OCH_SIGID,
+ LambdaCriterion.class);
+ assertThat(lambdaCriterion.lambda(), is(equalTo(lambda1)));
+ }
+
+ /**
+ * Test the equals() method of the LambdaCriterion class.
+ */
+ @Test
+ public void testLambdaCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchLambda1, sameAsMatchLambda1)
+ .addEqualityGroup(matchLambda2)
+ .testEquals();
+ }
+
+ @Test
+ public void testIndexedLambdaCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchIndexedLambda1, sameAsMatchIndexedLambda1)
+ .addEqualityGroup(matchIndexedLambda2)
+ .testEquals();
+ }
+
+ @Test
+ public void testOchSignalCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchOchSignal1, sameAsMatchOchSignal1)
+ .addEqualityGroup(matchOchSignal2)
+ .testEquals();
+ }
+
+ /**
+ * Test the equals() method of the OchSignalTypeCriterion class.
+ */
+ @Test
+ public void testOchSignalTypeCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchOchSignalType1, sameAsMatchOchSignalType1)
+ .addEqualityGroup(matchOchSignalType2)
+ .testEquals();
+ }
+
+ // OpticalSignalTypeCriterion class
+
+ /**
+ * Test the matchOpticalSignalType method.
+ */
+ @Test
+ public void testMatchOpticalSignalTypeMethod() {
+ Criterion matchLambda = Criteria.matchOpticalSignalType(signalLambda1);
+ OpticalSignalTypeCriterion opticalSignalTypeCriterion =
+ checkAndConvert(matchLambda,
+ Criterion.Type.OCH_SIGTYPE,
+ OpticalSignalTypeCriterion.class);
+ assertThat(opticalSignalTypeCriterion.signalType(), is(equalTo(signalLambda1)));
+ }
+
+ /**
+ * Test the equals() method of the OpticalSignalTypeCriterion class.
+ */
+ @Test
+ public void testOpticalSignalTypeCriterionEquals() {
+ new EqualsTester()
+ .addEqualityGroup(matchSignalLambda1, sameAsMatchSignalLambda1)
+ .addEqualityGroup(matchSignalLambda2)
+ .testEquals();
+ }
+}
diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/instructions/InstructionsTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/instructions/InstructionsTest.java
new file mode 100644
index 00000000..410349b5
--- /dev/null
+++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/flow/instructions/InstructionsTest.java
@@ -0,0 +1,725 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.flow.instructions;
+
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.MplsLabel;
+import org.onlab.packet.TpPort;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.ChannelSpacing;
+import org.onosproject.net.GridType;
+import org.onosproject.net.IndexedLambda;
+import org.onosproject.net.Lambda;
+import org.onosproject.net.PortNumber;
+
+import com.google.common.testing.EqualsTester;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
+import static org.onosproject.net.PortNumber.portNumber;
+
+/**
+ * Unit tests for the Instructions class.
+ */
+public class InstructionsTest {
+
+ /**
+ * Checks that a Criterion object has the proper type, and then converts
+ * it to the proper type.
+ *
+ * @param instruction Instruction object to convert
+ * @param type Enumerated type value for the Criterion class
+ * @param clazz Desired Criterion class
+ * @param <T> The type the caller wants returned
+ * @return converted object
+ */
+ @SuppressWarnings("unchecked")
+ private <T> T checkAndConvert(Instruction instruction, Instruction.Type type, Class clazz) {
+ assertThat(instruction, is(notNullValue()));
+ assertThat(instruction.type(), is(equalTo(type)));
+ assertThat(instruction, instanceOf(clazz));
+ return (T) instruction;
+ }
+
+ /**
+ * Checks the equals() and toString() methods of a Criterion class.
+ *
+ * @param c1 first object to compare
+ * @param c1match object that should be equal to the first
+ * @param c2 object that should be not equal to the first
+ * @param <T> type of the arguments
+ */
+ private <T extends Instruction> void checkEqualsAndToString(T c1, T c1match,
+ T c2) {
+
+ new EqualsTester()
+ .addEqualityGroup(c1, c1match)
+ .addEqualityGroup(c2)
+ .testEquals();
+ }
+
+ /**
+ * Checks that Instructions is a proper utility class.
+ */
+ @Test
+ public void testInstructionsUtilityClass() {
+ assertThatClassIsUtility(Instructions.class);
+ }
+
+ /**
+ * Checks that the Instruction class implementations are immutable.
+ */
+ @Test
+ public void testImmutabilityOfInstructions() {
+ assertThatClassIsImmutable(Instructions.DropInstruction.class);
+ assertThatClassIsImmutable(Instructions.OutputInstruction.class);
+ assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class);
+ assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class);
+ assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class);
+ assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class);
+ assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class);
+ assertThatClassIsImmutable(L3ModificationInstruction.ModIPInstruction.class);
+ assertThatClassIsImmutable(L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
+ assertThatClassIsImmutable(L2ModificationInstruction.ModMplsLabelInstruction.class);
+ assertThatClassIsImmutable(L2ModificationInstruction.PushHeaderInstructions.class);
+ }
+
+ // DropInstruction
+
+ private final Instructions.DropInstruction drop1 = Instructions.createDrop();
+ private final Instructions.DropInstruction drop2 = Instructions.createDrop();
+
+ /**
+ * Test the createDrop method.
+ */
+ @Test
+ public void testCreateDropMethod() {
+ Instructions.DropInstruction instruction = Instructions.createDrop();
+ checkAndConvert(instruction,
+ Instruction.Type.DROP,
+ Instructions.DropInstruction.class);
+ }
+
+ /**
+ * Test the equals() method of the DropInstruction class.
+ */
+
+ @Test
+ public void testDropInstructionEquals() throws Exception {
+ assertThat(drop1, is(equalTo(drop2)));
+ }
+
+ /**
+ * Test the hashCode() method of the DropInstruction class.
+ */
+
+ @Test
+ public void testDropInstructionHashCode() {
+ assertThat(drop1.hashCode(), is(equalTo(drop2.hashCode())));
+ }
+
+ // OutputInstruction
+
+ private final PortNumber port1 = portNumber(1);
+ private final PortNumber port2 = portNumber(2);
+ private final Instructions.OutputInstruction output1 = Instructions.createOutput(port1);
+ private final Instructions.OutputInstruction sameAsOutput1 = Instructions.createOutput(port1);
+ private final Instructions.OutputInstruction output2 = Instructions.createOutput(port2);
+
+ /**
+ * Test the createOutput method.
+ */
+ @Test
+ public void testCreateOutputMethod() {
+ final Instruction instruction = Instructions.createOutput(port2);
+ final Instructions.OutputInstruction outputInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.OUTPUT,
+ Instructions.OutputInstruction.class);
+ assertThat(outputInstruction.port(), is(equalTo(port2)));
+ }
+
+
+ /**
+ * Test the equals() method of the OutputInstruction class.
+ */
+
+ @Test
+ public void testOutputInstructionEquals() throws Exception {
+ checkEqualsAndToString(output1, sameAsOutput1, output2);
+ }
+
+ /**
+ * Test the hashCode() method of the OutputInstruction class.
+ */
+
+ @Test
+ public void testOutputInstructionHashCode() {
+ assertThat(output1.hashCode(), is(equalTo(sameAsOutput1.hashCode())));
+ assertThat(output1.hashCode(), is(not(equalTo(output2.hashCode()))));
+ }
+
+ // ModLambdaInstruction
+
+ private final IndexedLambda lambda1 = new IndexedLambda(1);
+ private final IndexedLambda lambda2 = new IndexedLambda(2);
+ private final Instruction lambdaInstruction1 = Instructions.modL0Lambda(lambda1);
+ private final Instruction sameAsLambdaInstruction1 = Instructions.modL0Lambda(lambda1);
+ private final Instruction lambdaInstruction2 = Instructions.modL0Lambda(lambda2);
+
+ /**
+ * Test the modL0Lambda method.
+ */
+ @Test
+ public void testCreateLambdaMethod() {
+ final Instruction instruction = Instructions.modL0Lambda(lambda1);
+ final L0ModificationInstruction.ModLambdaInstruction lambdaInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L0MODIFICATION,
+ L0ModificationInstruction.ModLambdaInstruction.class);
+ assertThat(lambdaInstruction.lambda(), is(equalTo((short) lambda1.index())));
+ }
+
+ /**
+ * Test the equals() method of the ModLambdaInstruction class.
+ */
+
+ @Test
+ public void testModLambdaInstructionEquals() throws Exception {
+ checkEqualsAndToString(lambdaInstruction1,
+ sameAsLambdaInstruction1,
+ lambdaInstruction2);
+ }
+
+ /**
+ * Test the hashCode() method of the ModLambdaInstruction class.
+ */
+
+ @Test
+ public void testModLambdaInstructionHashCode() {
+ assertThat(lambdaInstruction1.hashCode(),
+ is(equalTo(sameAsLambdaInstruction1.hashCode())));
+ assertThat(lambdaInstruction1.hashCode(),
+ is(not(equalTo(lambdaInstruction2.hashCode()))));
+ }
+
+ private final Lambda och1 = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
+ private final Lambda och2 = Lambda.ochSignal(GridType.CWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
+ private final Instruction ochInstruction1 = Instructions.modL0Lambda(och1);
+ private final Instruction sameAsOchInstruction1 = Instructions.modL0Lambda(och1);
+ private final Instruction ochInstruction2 = Instructions.modL0Lambda(och2);
+
+ /**
+ * Test the modL0Lambda().
+ */
+ @Test
+ public void testModL0LambdaMethod() {
+ Instruction instruction = Instructions.modL0Lambda(och1);
+ L0ModificationInstruction.ModOchSignalInstruction ochInstruction =
+ checkAndConvert(instruction, Instruction.Type.L0MODIFICATION,
+ L0ModificationInstruction.ModOchSignalInstruction.class);
+ assertThat(ochInstruction.lambda(), is(och1));
+ }
+
+ /**
+ * Test the equals() method of the ModOchSignalInstruction class.
+ */
+ @Test
+ public void testModOchSignalInstructionEquals() {
+ checkEqualsAndToString(ochInstruction1, sameAsOchInstruction1, ochInstruction2);
+ }
+
+ /**
+ * Test the hashCode() method of the ModOchSignalInstruction class.
+ */
+ @Test
+ public void testModOchSignalInstructionHashCode() {
+ assertThat(ochInstruction1.hashCode(), is(sameAsOchInstruction1.hashCode()));
+ assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode())));
+ }
+
+ // ModEtherInstruction
+
+ private static final String MAC1 = "00:00:00:00:00:01";
+ private static final String MAC2 = "00:00:00:00:00:02";
+ private final MacAddress mac1 = MacAddress.valueOf(MAC1);
+ private final MacAddress mac2 = MacAddress.valueOf(MAC2);
+ private final Instruction modEtherInstruction1 = Instructions.modL2Src(mac1);
+ private final Instruction sameAsModEtherInstruction1 = Instructions.modL2Src(mac1);
+ private final Instruction modEtherInstruction2 = Instructions.modL2Src(mac2);
+
+ /**
+ * Test the modL2Src method.
+ */
+ @Test
+ public void testModL2SrcMethod() {
+ final Instruction instruction = Instructions.modL2Src(mac1);
+ final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L2MODIFICATION,
+ L2ModificationInstruction.ModEtherInstruction.class);
+ assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
+ assertThat(modEtherInstruction.subtype(),
+ is(equalTo(L2ModificationInstruction.L2SubType.ETH_SRC)));
+ }
+
+ /**
+ * Test the modL2Dst method.
+ */
+ @Test
+ public void testModL2DstMethod() {
+ final Instruction instruction = Instructions.modL2Dst(mac1);
+ final L2ModificationInstruction.ModEtherInstruction modEtherInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L2MODIFICATION,
+ L2ModificationInstruction.ModEtherInstruction.class);
+ assertThat(modEtherInstruction.mac(), is(equalTo(mac1)));
+ assertThat(modEtherInstruction.subtype(),
+ is(equalTo(L2ModificationInstruction.L2SubType.ETH_DST)));
+ }
+
+ /**
+ * Test the equals() method of the ModEtherInstruction class.
+ */
+
+ @Test
+ public void testModEtherInstructionEquals() throws Exception {
+ checkEqualsAndToString(modEtherInstruction1,
+ sameAsModEtherInstruction1,
+ modEtherInstruction2);
+ }
+
+ /**
+ * Test the hashCode() method of the ModEtherInstruction class.
+ */
+
+ @Test
+ public void testModEtherInstructionHashCode() {
+ assertThat(modEtherInstruction1.hashCode(),
+ is(equalTo(sameAsModEtherInstruction1.hashCode())));
+ assertThat(modEtherInstruction1.hashCode(),
+ is(not(equalTo(modEtherInstruction2.hashCode()))));
+ }
+
+
+ // ModVlanIdInstruction
+
+ private final short vlan1 = 1;
+ private final short vlan2 = 2;
+ private final VlanId vlanId1 = VlanId.vlanId(vlan1);
+ private final VlanId vlanId2 = VlanId.vlanId(vlan2);
+ private final Instruction modVlanId1 = Instructions.modVlanId(vlanId1);
+ private final Instruction sameAsModVlanId1 = Instructions.modVlanId(vlanId1);
+ private final Instruction modVlanId2 = Instructions.modVlanId(vlanId2);
+
+ /**
+ * Test the modVlanId method.
+ */
+ @Test
+ public void testModVlanIdMethod() {
+ final Instruction instruction = Instructions.modVlanId(vlanId1);
+ final L2ModificationInstruction.ModVlanIdInstruction modEtherInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L2MODIFICATION,
+ L2ModificationInstruction.ModVlanIdInstruction.class);
+ assertThat(modEtherInstruction.vlanId(), is(equalTo(vlanId1)));
+ assertThat(modEtherInstruction.subtype(),
+ is(equalTo(L2ModificationInstruction.L2SubType.VLAN_ID)));
+ }
+
+ /**
+ * Test the equals() method of the ModVlanIdInstruction class.
+ */
+
+ @Test
+ public void testModVlanIdInstructionEquals() throws Exception {
+ checkEqualsAndToString(modVlanId1,
+ sameAsModVlanId1,
+ modVlanId2);
+ }
+
+ /**
+ * Test the hashCode() method of the ModEtherInstruction class.
+ */
+
+ @Test
+ public void testModVlanIdInstructionHashCode() {
+ assertThat(modVlanId1.hashCode(),
+ is(equalTo(sameAsModVlanId1.hashCode())));
+ assertThat(modVlanId1.hashCode(),
+ is(not(equalTo(modVlanId2.hashCode()))));
+ }
+
+
+ // ModVlanPcpInstruction
+
+ private final byte vlanPcp1 = 1;
+ private final byte vlanPcp2 = 2;
+ private final Instruction modVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
+ private final Instruction sameAsModVlanPcp1 = Instructions.modVlanPcp(vlanPcp1);
+ private final Instruction modVlanPcp2 = Instructions.modVlanPcp(vlanPcp2);
+
+ /**
+ * Test the modVlanPcp method.
+ */
+ @Test
+ public void testModVlanPcpMethod() {
+ final Instruction instruction = Instructions.modVlanPcp(vlanPcp1);
+ final L2ModificationInstruction.ModVlanPcpInstruction modEtherInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L2MODIFICATION,
+ L2ModificationInstruction.ModVlanPcpInstruction.class);
+ assertThat(modEtherInstruction.vlanPcp(), is(equalTo(vlanPcp1)));
+ assertThat(modEtherInstruction.subtype(),
+ is(equalTo(L2ModificationInstruction.L2SubType.VLAN_PCP)));
+ }
+
+ /**
+ * Test the equals() method of the ModVlanPcpInstruction class.
+ */
+
+ @Test
+ public void testModVlanPcpInstructionEquals() throws Exception {
+ checkEqualsAndToString(modVlanPcp1,
+ sameAsModVlanPcp1,
+ modVlanPcp2);
+ }
+
+ /**
+ * Test the hashCode() method of the ModEtherInstruction class.
+ */
+
+ @Test
+ public void testModVlanPcpInstructionHashCode() {
+ assertThat(modVlanPcp1.hashCode(),
+ is(equalTo(sameAsModVlanPcp1.hashCode())));
+ assertThat(modVlanPcp1.hashCode(),
+ is(not(equalTo(modVlanPcp2.hashCode()))));
+ }
+
+ // ModIPInstruction
+
+ private static final String IP41 = "1.2.3.4";
+ private static final String IP42 = "5.6.7.8";
+ private IpAddress ip41 = IpAddress.valueOf(IP41);
+ private IpAddress ip42 = IpAddress.valueOf(IP42);
+ private final Instruction modIPInstruction1 = Instructions.modL3Src(ip41);
+ private final Instruction sameAsModIPInstruction1 = Instructions.modL3Src(ip41);
+ private final Instruction modIPInstruction2 = Instructions.modL3Src(ip42);
+
+ private static final String IP61 = "1111::2222";
+ private static final String IP62 = "3333::4444";
+ private IpAddress ip61 = IpAddress.valueOf(IP61);
+ private IpAddress ip62 = IpAddress.valueOf(IP62);
+ private final Instruction modIPv6Instruction1 =
+ Instructions.modL3IPv6Src(ip61);
+ private final Instruction sameAsModIPv6Instruction1 =
+ Instructions.modL3IPv6Src(ip61);
+ private final Instruction modIPv6Instruction2 =
+ Instructions.modL3IPv6Src(ip62);
+
+ /**
+ * Test the modL3Src method.
+ */
+ @Test
+ public void testModL3SrcMethod() {
+ final Instruction instruction = Instructions.modL3Src(ip41);
+ final L3ModificationInstruction.ModIPInstruction modIPInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L3MODIFICATION,
+ L3ModificationInstruction.ModIPInstruction.class);
+ assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
+ assertThat(modIPInstruction.subtype(),
+ is(equalTo(L3ModificationInstruction.L3SubType.IPV4_SRC)));
+ }
+
+ /**
+ * Test the modL3Dst method.
+ */
+ @Test
+ public void testModL3DstMethod() {
+ final Instruction instruction = Instructions.modL3Dst(ip41);
+ final L3ModificationInstruction.ModIPInstruction modIPInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L3MODIFICATION,
+ L3ModificationInstruction.ModIPInstruction.class);
+ assertThat(modIPInstruction.ip(), is(equalTo(ip41)));
+ assertThat(modIPInstruction.subtype(),
+ is(equalTo(L3ModificationInstruction.L3SubType.IPV4_DST)));
+ }
+
+ /**
+ * Test the modL3IPv6Src method.
+ */
+ @Test
+ public void testModL3IPv6SrcMethod() {
+ final Instruction instruction = Instructions.modL3IPv6Src(ip61);
+ final L3ModificationInstruction.ModIPInstruction modIPInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L3MODIFICATION,
+ L3ModificationInstruction.ModIPInstruction.class);
+ assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
+ assertThat(modIPInstruction.subtype(),
+ is(equalTo(L3ModificationInstruction.L3SubType.IPV6_SRC)));
+ }
+
+ /**
+ * Test the modL3IPv6Dst method.
+ */
+ @Test
+ public void testModL3IPv6DstMethod() {
+ final Instruction instruction = Instructions.modL3IPv6Dst(ip61);
+ final L3ModificationInstruction.ModIPInstruction modIPInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L3MODIFICATION,
+ L3ModificationInstruction.ModIPInstruction.class);
+ assertThat(modIPInstruction.ip(), is(equalTo(ip61)));
+ assertThat(modIPInstruction.subtype(),
+ is(equalTo(L3ModificationInstruction.L3SubType.IPV6_DST)));
+ }
+
+ /**
+ * Test the equals() method of the ModIPInstruction class.
+ */
+ @Test
+ public void testModIPInstructionEquals() throws Exception {
+ checkEqualsAndToString(modIPInstruction1,
+ sameAsModIPInstruction1,
+ modIPInstruction2);
+ }
+
+ /**
+ * Test the hashCode() method of the ModIPInstruction class.
+ */
+ @Test
+ public void testModIPInstructionHashCode() {
+ assertThat(modIPInstruction1.hashCode(),
+ is(equalTo(sameAsModIPInstruction1.hashCode())));
+ assertThat(modIPInstruction1.hashCode(),
+ is(not(equalTo(modIPInstruction2.hashCode()))));
+ }
+
+ private final int flowLabel1 = 0x11111;
+ private final int flowLabel2 = 0x22222;
+ private final Instruction modIPv6FlowLabelInstruction1 =
+ Instructions.modL3IPv6FlowLabel(flowLabel1);
+ private final Instruction sameAsModIPv6FlowLabelInstruction1 =
+ Instructions.modL3IPv6FlowLabel(flowLabel1);
+ private final Instruction modIPv6FlowLabelInstruction2 =
+ Instructions.modL3IPv6FlowLabel(flowLabel2);
+
+ /**
+ * Test the modL3IPv6FlowLabel method.
+ */
+ @Test
+ public void testModL3IPv6FlowLabelMethod() {
+ final Instruction instruction =
+ Instructions.modL3IPv6FlowLabel(flowLabel1);
+ final L3ModificationInstruction.ModIPv6FlowLabelInstruction
+ modIPv6FlowLabelInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L3MODIFICATION,
+ L3ModificationInstruction.ModIPv6FlowLabelInstruction.class);
+ assertThat(modIPv6FlowLabelInstruction.flowLabel(),
+ is(equalTo(flowLabel1)));
+ assertThat(modIPv6FlowLabelInstruction.subtype(),
+ is(equalTo(L3ModificationInstruction.L3SubType.IPV6_FLABEL)));
+ }
+
+ /**
+ * Test the equals() method of the ModIPv6FlowLabelInstruction class.
+ */
+ @Test
+ public void testModIPv6FlowLabelInstructionEquals() throws Exception {
+ checkEqualsAndToString(modIPv6FlowLabelInstruction1,
+ sameAsModIPv6FlowLabelInstruction1,
+ modIPv6FlowLabelInstruction2);
+ }
+
+ /**
+ * Test the hashCode() method of the ModIPv6FlowLabelInstruction class.
+ */
+ @Test
+ public void testModIPv6FlowLabelInstructionHashCode() {
+ assertThat(modIPv6FlowLabelInstruction1.hashCode(),
+ is(equalTo(sameAsModIPv6FlowLabelInstruction1.hashCode())));
+ assertThat(modIPv6FlowLabelInstruction1.hashCode(),
+ is(not(equalTo(modIPv6FlowLabelInstruction2.hashCode()))));
+ }
+
+ private Instruction modMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
+ private Instruction sameAsModMplsLabelInstruction1 = Instructions.modMplsLabel(MplsLabel.mplsLabel(1));
+ private Instruction modMplsLabelInstruction2 = Instructions.modMplsLabel(MplsLabel.mplsLabel(2));
+
+ /**
+ * Test the modMplsLabel method.
+ */
+ @Test
+ public void testModMplsMethod() {
+ final MplsLabel mplsLabel = MplsLabel.mplsLabel(33);
+ final Instruction instruction = Instructions.modMplsLabel(mplsLabel);
+ final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction =
+ checkAndConvert(instruction,
+ Instruction.Type.L2MODIFICATION,
+ L2ModificationInstruction.ModMplsLabelInstruction.class);
+ assertThat(modMplsLabelInstruction.mplsLabel(), is(equalTo(mplsLabel)));
+ assertThat(modMplsLabelInstruction.subtype(),
+ is(equalTo(L2ModificationInstruction.L2SubType.MPLS_LABEL)));
+ }
+
+ /**
+ * Test the equals(), hashCode and toString() methods of the
+ * ModMplsLabelInstruction class.
+ */
+ @Test
+ public void testModMplsLabelInstructionEquals() throws Exception {
+ checkEqualsAndToString(modMplsLabelInstruction1,
+ sameAsModMplsLabelInstruction1,
+ modMplsLabelInstruction2);
+ }
+
+ // ModTunnelIdInstruction
+
+ private final long tunnelId1 = 1L;
+ private final long tunnelId2 = 2L;
+ private final Instruction modTunnelId1 = Instructions.modTunnelId(tunnelId1);
+ private final Instruction sameAsModTunnelId1 = Instructions.modTunnelId(tunnelId1);
+ private final Instruction modTunnelId2 = Instructions.modTunnelId(tunnelId2);
+
+ /**
+ * Test the modTunnelId method.
+ */
+ @Test
+ public void testModTunnelIdMethod() {
+ final Instruction instruction = Instructions.modTunnelId(tunnelId1);
+ final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction =
+ checkAndConvert(instruction, Instruction.Type.L2MODIFICATION,
+ L2ModificationInstruction.ModTunnelIdInstruction.class);
+ assertThat(modTunnelIdInstruction.tunnelId(), is(equalTo(tunnelId1)));
+ assertThat(modTunnelIdInstruction.subtype(),
+ is(equalTo(L2ModificationInstruction.L2SubType.TUNNEL_ID)));
+ }
+
+ /***
+ * Test the equals() method of the ModTunnelIdInstruction class.
+ */
+ @Test
+ public void testModTunnelIdInstructionEquals() throws Exception {
+ checkEqualsAndToString(modTunnelId1, sameAsModTunnelId1, modTunnelId2);
+ }
+
+ /**
+ * Test the hashCode() method of the ModTunnelIdInstruction class.
+ */
+ @Test
+ public void testModTunnelIdInstructionHashCode() {
+ assertThat(modTunnelId1.hashCode(), is(equalTo(sameAsModTunnelId1.hashCode())));
+ assertThat(modTunnelId1.hashCode(), is(not(equalTo(modTunnelId2.hashCode()))));
+ }
+
+ // ModTransportPortInstruction
+
+ private final TpPort tpPort1 = TpPort.tpPort(1);
+ private final TpPort tpPort2 = TpPort.tpPort(2);
+ private final Instruction modTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
+ private final Instruction sameAsModTransportPortInstruction1 = Instructions.modTcpSrc(tpPort1);
+ private final Instruction modTransportPortInstruction2 = Instructions.modTcpSrc(tpPort2);
+
+ /**
+ * Test the modTcpSrc() method.
+ */
+ @Test
+ public void testModTcpSrcMethod() {
+ final Instruction instruction = Instructions.modTcpSrc(tpPort1);
+ final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
+ checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
+ L4ModificationInstruction.ModTransportPortInstruction.class);
+ assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
+ assertThat(modTransportPortInstruction.subtype(),
+ is(equalTo(L4ModificationInstruction.L4SubType.TCP_SRC)));
+ }
+
+ /**
+ * Test the modTcpDst() method.
+ */
+ @Test
+ public void testModTcpDstMethod() {
+ final Instruction instruction = Instructions.modTcpDst(tpPort1);
+ final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
+ checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
+ L4ModificationInstruction.ModTransportPortInstruction.class);
+ assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
+ assertThat(modTransportPortInstruction.subtype(),
+ is(equalTo(L4ModificationInstruction.L4SubType.TCP_DST)));
+ }
+
+ /**
+ * Test the modUdpSrc() method.
+ */
+ @Test
+ public void testModUdpSrcMethod() {
+ final Instruction instruction = Instructions.modUdpSrc(tpPort1);
+ final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
+ checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
+ L4ModificationInstruction.ModTransportPortInstruction.class);
+ assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
+ assertThat(modTransportPortInstruction.subtype(),
+ is(equalTo(L4ModificationInstruction.L4SubType.UDP_SRC)));
+ }
+
+ /**
+ * Test the modUdpDst() method.
+ */
+ @Test
+ public void testModUdpDstMethod() {
+ final Instruction instruction = Instructions.modUdpDst(tpPort1);
+ final L4ModificationInstruction.ModTransportPortInstruction modTransportPortInstruction =
+ checkAndConvert(instruction, Instruction.Type.L4MODIFICATION,
+ L4ModificationInstruction.ModTransportPortInstruction.class);
+ assertThat(modTransportPortInstruction.port(), is(equalTo(tpPort1)));
+ assertThat(modTransportPortInstruction.subtype(),
+ is(equalTo(L4ModificationInstruction.L4SubType.UDP_DST)));
+ }
+
+ /**
+ * Test the equals() method of the ModTransportPortInstruction class.
+ */
+ @Test
+ public void testModTransportPortInstructionEquals() throws Exception {
+ checkEqualsAndToString(modTransportPortInstruction1,
+ sameAsModTransportPortInstruction1,
+ modTransportPortInstruction2);
+ }
+
+ /**
+ * Test the hashCode() method of the ModTransportPortInstruction class.
+ */
+ @Test
+ public void testModTransportPortInstructionHashCode() {
+ assertThat(modTransportPortInstruction1.hashCode(),
+ is(equalTo(sameAsModTransportPortInstruction1.hashCode())));
+ assertThat(modTransportPortInstruction1.hashCode(),
+ is(not(equalTo(modTransportPortInstruction2.hashCode()))));
+ }
+}