Remove deprecated Flow Rule constructors
Change-Id: I2a078cbfbeb9db4a04ef1c59acde2fb45672a3cf
diff --git a/apps/optical/src/main/java/org/onosproject/optical/testapp/LambdaForwarding.java b/apps/optical/src/main/java/org/onosproject/optical/testapp/LambdaForwarding.java
index 703ef44..cba1b302 100644
--- a/apps/optical/src/main/java/org/onosproject/optical/testapp/LambdaForwarding.java
+++ b/apps/optical/src/main/java/org/onosproject/optical/testapp/LambdaForwarding.java
@@ -127,11 +127,17 @@
default:
}
- TrafficTreatment treatement = tbuilder.build();
+ TrafficTreatment treatment = tbuilder.build();
TrafficSelector selector = sbuilder.build();
- FlowRule f = new DefaultFlowRule(device.id(), selector,
- treatement, 100, appId, 600, false);
+ FlowRule f = DefaultFlowRule.builder()
+ .forDevice(device.id())
+ .withSelector(selector)
+ .withTreatment(treatment)
+ .withPriority(100)
+ .fromApp(appId)
+ .makeTemporary(600)
+ .build();
flowRuleService.applyFlowRules(f);
diff --git a/apps/optical/src/main/java/org/onosproject/optical/testapp/MPLSForwarding.java b/apps/optical/src/main/java/org/onosproject/optical/testapp/MPLSForwarding.java
index f64d982..c784c82 100644
--- a/apps/optical/src/main/java/org/onosproject/optical/testapp/MPLSForwarding.java
+++ b/apps/optical/src/main/java/org/onosproject/optical/testapp/MPLSForwarding.java
@@ -130,8 +130,14 @@
TrafficTreatment treatement = tbuilder.build();
TrafficSelector selector = sbuilder.build();
- FlowRule f = new DefaultFlowRule(device.id(), selector,
- treatement, 100, appId, 600, false);
+ FlowRule f = DefaultFlowRule.builder()
+ .forDevice(device.id())
+ .withSelector(selector)
+ .withTreatment(treatement)
+ .withPriority(100)
+ .fromApp(appId)
+ .makeTemporary(600)
+ .build();
flowRuleService.applyFlowRules(f);
}
diff --git a/apps/test/demo/src/main/java/org/onosproject/demo/DemoInstaller.java b/apps/test/demo/src/main/java/org/onosproject/demo/DemoInstaller.java
index a149e75..27d1ca9 100644
--- a/apps/test/demo/src/main/java/org/onosproject/demo/DemoInstaller.java
+++ b/apps/test/demo/src/main/java/org/onosproject/demo/DemoInstaller.java
@@ -15,15 +15,25 @@
*/
package org.onosproject.demo;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.base.Predicate;
-import com.google.common.base.Stopwatch;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
import org.apache.commons.lang.math.RandomUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -47,6 +57,7 @@
import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.flow.FlowRuleOperationsContext;
import org.onosproject.net.flow.FlowRuleService;
@@ -59,24 +70,15 @@
import org.onosproject.net.intent.IntentService;
import org.slf4j.Logger;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Random;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Predicate;
+import com.google.common.base.Stopwatch;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
import static org.slf4j.LoggerFactory.getLogger;
@@ -557,8 +559,14 @@
int randomPriority = RandomUtils.nextInt();
- DefaultFlowRule f = new DefaultFlowRule(d.id(), sbuilder.build(), treatment,
- randomPriority, appId, 10, false);
+ FlowRule f = DefaultFlowRule.builder()
+ .forDevice(d.id())
+ .withSelector(sbuilder.build())
+ .withTreatment(treatment)
+ .withPriority(randomPriority)
+ .fromApp(appId)
+ .makeTemporary(10)
+ .build();
rules.add(f);
remove.remove(f);
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java
index c8d91d5..cdb4b53 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddFlowsCommand.java
@@ -34,6 +34,7 @@
import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.flow.FlowRuleOperationsContext;
import org.onosproject.net.flow.FlowRuleService;
@@ -89,10 +90,26 @@
int randomPriority = RandomUtils.nextInt();
- rules.add(new DefaultFlowRule(d.id(), sbuilder.build(), treatment,
- randomPriority, appId, 10, false));
- remove.remove(new DefaultFlowRule(d.id(), sbuilder.build(), treatment,
- randomPriority, appId, 10, false));
+
+ FlowRule addRule = DefaultFlowRule.builder()
+ .forDevice(d.id())
+ .withSelector(sbuilder.build())
+ .withTreatment(treatment)
+ .withPriority(randomPriority)
+ .fromApp(appId)
+ .makeTemporary(10)
+ .build();
+ FlowRule removeRule = DefaultFlowRule.builder()
+ .forDevice(d.id())
+ .withSelector(sbuilder.build())
+ .withTreatment(treatment)
+ .withPriority(randomPriority)
+ .fromApp(appId)
+ .makeTemporary(10)
+ .build();
+
+ rules.add(addRule);
+ remove.remove(removeRule);
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowEntry.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowEntry.java
index 8eaaa32..f7e7708 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowEntry.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowEntry.java
@@ -18,7 +18,6 @@
import static com.google.common.base.MoreObjects.toStringHelper;
import static org.slf4j.LoggerFactory.getLogger;
-import org.onosproject.net.DeviceId;
import org.slf4j.Logger;
public class DefaultFlowEntry extends DefaultFlowRule
@@ -37,21 +36,6 @@
private final int errCode;
-
- public DefaultFlowEntry(DeviceId deviceId, TrafficSelector selector,
- TrafficTreatment treatment, int priority, FlowEntryState state,
- long life, long packets, long bytes, long flowId,
- int timeout) {
- super(deviceId, selector, treatment, priority, flowId, timeout, false);
- this.state = state;
- this.life = life;
- this.packets = packets;
- this.bytes = bytes;
- this.errCode = -1;
- this.errType = -1;
- this.lastSeen = System.currentTimeMillis();
- }
-
public DefaultFlowEntry(FlowRule rule, FlowEntryState state,
long life, long packets, long bytes) {
super(rule);
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
index 5a68887..293f12f 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultFlowRule.java
@@ -45,119 +45,6 @@
private final Integer tableId;
private final FlowRuleExtPayLoad payLoad;
- @Deprecated
- public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
- TrafficTreatment treatment, int priority,
- long flowId, int timeout, boolean permanent) {
- this.deviceId = deviceId;
- this.priority = priority;
- this.selector = selector;
- this.treatment = treatment;
- this.timeout = timeout;
- this.permanent = permanent;
- this.created = System.currentTimeMillis();
-
- this.appId = (short) (flowId >>> 48);
- this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF));
- this.id = FlowId.valueOf(flowId);
- this.tableId = 0;
- this.payLoad = null;
- }
-
- @Deprecated
- public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
- TrafficTreatment treatment, int priority,
- long flowId, int timeout, boolean permanent,
- Type tableType) {
- this.deviceId = deviceId;
- this.priority = priority;
- this.selector = selector;
- this.treatment = treatment;
- this.timeout = timeout;
- this.permanent = permanent;
- this.created = System.currentTimeMillis();
-
- this.appId = (short) (flowId >>> 48);
- this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF));
- this.id = FlowId.valueOf(flowId);
- this.tableId = tableType.ordinal();
-
- this.payLoad = null;
- }
-
- @Deprecated
- public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
- TrafficTreatment treatment, int priority,
- ApplicationId appId, int timeout, boolean permanent) {
- this(deviceId, selector, treatment, priority, appId,
- new DefaultGroupId(0), timeout, permanent);
- }
-
- @Deprecated
- public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
- TrafficTreatment treatment, int priority,
- ApplicationId appId, int timeout, boolean permanent,
- Type type) {
-
- if (priority < FlowRule.MIN_PRIORITY) {
- throw new IllegalArgumentException("Priority cannot be less than "
- + MIN_PRIORITY);
- }
-
- this.deviceId = deviceId;
- this.priority = priority;
- this.selector = selector;
- this.treatment = treatment;
- this.appId = appId.id();
- this.groupId = new DefaultGroupId(0);
- this.timeout = timeout;
- this.permanent = permanent;
- this.created = System.currentTimeMillis();
- this.tableId = type.ordinal();
-
- this.payLoad = null;
- /*
- * id consists of the following. | appId (16 bits) | groupId (16 bits) |
- * flowId (32 bits) |
- */
- this.id = FlowId.valueOf((((long) this.appId) << 48)
- | (((long) this.groupId.id()) << 32)
- | (this.hash() & 0xffffffffL));
-
- }
-
- @Deprecated
- public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
- TrafficTreatment treatment, int priority,
- ApplicationId appId, GroupId groupId, int timeout,
- boolean permanent) {
-
- if (priority < FlowRule.MIN_PRIORITY) {
- throw new IllegalArgumentException("Priority cannot be less than "
- + MIN_PRIORITY);
- }
-
- this.deviceId = deviceId;
- this.priority = priority;
- this.selector = selector;
- this.treatment = treatment;
- this.appId = appId.id();
- this.groupId = groupId;
- this.timeout = timeout;
- this.permanent = permanent;
- this.created = System.currentTimeMillis();
- this.tableId = 0;
- this.payLoad = null;
-
- /*
- * id consists of the following. | appId (16 bits) | groupId (16 bits) |
- * flowId (32 bits) |
- */
- this.id = FlowId.valueOf((((long) this.appId) << 48)
- | (((long) this.groupId.id()) << 32)
- | (this.hash() & 0xffffffffL));
- }
-
public DefaultFlowRule(FlowRule rule) {
this.deviceId = rule.deviceId();
this.priority = rule.priority();
@@ -371,7 +258,7 @@
.add("treatment", treatment == null ? "N/A" : treatment.allInstructions())
.add("tableId", tableId)
.add("created", created)
- .add("payLoad", payLoad).toString()
+ .add("payLoad", payLoad)
.toString();
}
diff --git a/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowEntryTest.java b/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowEntryTest.java
index f8dc27a..412acb6 100644
--- a/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowEntryTest.java
+++ b/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowEntryTest.java
@@ -37,16 +37,17 @@
new IntentTestsMocks.MockTreatment();
private static DefaultFlowEntry makeFlowEntry(int uniqueValue) {
- return new DefaultFlowEntry(did("id" + Integer.toString(uniqueValue)),
- SELECTOR,
- TREATMENT,
- uniqueValue,
- FlowEntry.FlowEntryState.ADDED,
- uniqueValue,
- uniqueValue,
- uniqueValue,
- uniqueValue,
- 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);
diff --git a/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowRuleTest.java b/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowRuleTest.java
index 7ad8f70..62acd16 100644
--- a/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowRuleTest.java
+++ b/core/api/src/test/java/org/onosproject/net/flow/DefaultFlowRuleTest.java
@@ -41,10 +41,8 @@
private static FlowRuleExtPayLoad payLoad = FlowRuleExtPayLoad.flowRuleExtPayLoad(b);
final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1, payLoad);
final FlowRule sameAsFlowRule1 = new IntentTestsMocks.MockFlowRule(1, payLoad);
- final FlowRule flowRule2 = new IntentTestsMocks.MockFlowRule(2, payLoad);
final DefaultFlowRule defaultFlowRule1 = new DefaultFlowRule(flowRule1);
final DefaultFlowRule sameAsDefaultFlowRule1 = new DefaultFlowRule(sameAsFlowRule1);
- final DefaultFlowRule defaultFlowRule2 = new DefaultFlowRule(flowRule2);
/**
* Checks that the DefaultFlowRule class is immutable but can be inherited
@@ -84,14 +82,20 @@
/**
* Tests creation of a DefaultFlowRule using a FlowId constructor.
*/
+
@Test
public void testCreationWithFlowId() {
- final DefaultFlowRule rule =
- new DefaultFlowRule(did("1"), SELECTOR,
- TREATMENT, 22, 33,
- 44, false);
+ 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.id().value(), is(33L));
assertThat(rule.isPermanent(), is(false));
assertThat(rule.priority(), is(22));
assertThat(rule.selector(), is(SELECTOR));
@@ -99,6 +103,7 @@
assertThat(rule.timeout(), is(44));
}
+
/**
* Tests creation of a DefaultFlowRule using a PayLoad constructor.
*/
@@ -136,10 +141,16 @@
*/
@Test
public void testCreationWithAppId() {
- final DefaultFlowRule rule =
- new DefaultFlowRule(did("1"), SELECTOR,
- TREATMENT, 22, APP_ID,
- 44, false);
+ 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));
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
index 9085f08..43a7fb7 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
@@ -135,7 +135,7 @@
}
DefaultFlowRule rule = new DefaultFlowRule(deviceId, selector, treatment, 123, appId,
- new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), 0, true);
+ new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), 0, true, null);
rules.add(rule);
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
index d6eae35..f9e445a 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
@@ -256,6 +256,13 @@
protected FlowRule createFlowRule(MplsPathIntent intent, DeviceId deviceId,
TrafficSelector selector, TrafficTreatment treat) {
- return new DefaultFlowRule(deviceId, selector, treat, intent.priority(), appId, 0, true);
+ return DefaultFlowRule.builder()
+ .forDevice(deviceId)
+ .withSelector(selector)
+ .withTreatment(treat)
+ .withPriority(intent.priority())
+ .fromApp(appId)
+ .makePermanent()
+ .build();
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
index d6187cd..90e3981 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
@@ -97,7 +97,14 @@
}
TrafficTreatment treatment = treatmentBuilder.setOutput(egress.port()).build();
- return new DefaultFlowRule(ingress.deviceId(), selector, treatment, 123, appId, 0, true);
+ return DefaultFlowRule.builder()
+ .forDevice(ingress.deviceId())
+ .withSelector(selector)
+ .withTreatment(treatment)
+ .withPriority(123)
+ .fromApp(appId)
+ .makePermanent()
+ .build();
}
private boolean isLast(List<Link> links, int i) {
diff --git a/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java b/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
index 5097bb8..520cb8c 100644
--- a/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
@@ -144,7 +144,14 @@
private FlowRule flowRule(int tsval, int trval) {
TestSelector ts = new TestSelector(tsval);
TestTreatment tr = new TestTreatment(trval);
- return new DefaultFlowRule(DID, ts, tr, 10, appId, TIMEOUT, false);
+ return DefaultFlowRule.builder()
+ .forDevice(DID)
+ .withSelector(ts)
+ .withTreatment(tr)
+ .withPriority(10)
+ .fromApp(appId)
+ .makeTemporary(TIMEOUT)
+ .build();
}
diff --git a/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java b/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
index ac9da38..9795dab 100644
--- a/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
+++ b/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
@@ -28,6 +28,7 @@
import org.onlab.util.Frequency;
import org.onosproject.cluster.NodeId;
import org.onosproject.cluster.RoleInfo;
+import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.mastership.MastershipTerm;
import org.onosproject.net.Annotations;
@@ -236,8 +237,15 @@
@Test
public void testFlowRuleBatchEntry() {
final FlowRule rule1 =
- new DefaultFlowRule(DID1, DefaultTrafficSelector.emptySelector(),
- DefaultTrafficTreatment.emptyTreatment(), 0, 0, 0, true);
+ DefaultFlowRule.builder()
+ .forDevice(DID1)
+ .withSelector(DefaultTrafficSelector.emptySelector())
+ .withTreatment(DefaultTrafficTreatment.emptyTreatment())
+ .withPriority(0)
+ .fromApp(new DefaultApplicationId(1, "1"))
+ .makeTemporary(1)
+ .build();
+
final FlowRuleBatchEntry entry1 =
new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
final FlowRuleBatchEntry entry2 =