Ray Milkey
Committed by Gerrit Code Review

Remove deprecated Flow Rule constructors

Change-Id: I2a078cbfbeb9db4a04ef1c59acde2fb45672a3cf
......@@ -127,11 +127,17 @@ public class LambdaForwarding {
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);
......
......@@ -130,8 +130,14 @@ public class MPLSForwarding {
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);
}
......
......@@ -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.device.DeviceService;
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.Intent;
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 @@ public class DemoInstaller implements DemoAPI {
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);
......
......@@ -34,6 +34,7 @@ import org.onosproject.net.device.DeviceService;
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 @@ public class AddFlowsCommand extends AbstractShellCommand {
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);
}
}
......
......@@ -18,7 +18,6 @@ package org.onosproject.net.flow;
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 @@ public class DefaultFlowEntry extends DefaultFlowRule
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);
......
......@@ -45,119 +45,6 @@ public class DefaultFlowRule implements FlowRule {
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 @@ public class DefaultFlowRule implements FlowRule {
.add("treatment", treatment == null ? "N/A" : treatment.allInstructions())
.add("tableId", tableId)
.add("created", created)
.add("payLoad", payLoad).toString()
.add("payLoad", payLoad)
.toString();
}
......
......@@ -37,16 +37,17 @@ public class DefaultFlowEntryTest {
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);
......
......@@ -41,10 +41,8 @@ public class DefaultFlowRuleTest {
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 @@ public class DefaultFlowRuleTest {
/**
* 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 @@ public class DefaultFlowRuleTest {
assertThat(rule.timeout(), is(44));
}
/**
* Tests creation of a DefaultFlowRule using a PayLoad constructor.
*/
......@@ -136,10 +141,16 @@ public class DefaultFlowRuleTest {
*/
@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));
......
......@@ -135,7 +135,7 @@ public class LinkCollectionIntentCompiler implements IntentCompiler<LinkCollecti
}
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);
}
......
......@@ -256,6 +256,13 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
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();
}
}
......
......@@ -97,7 +97,14 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
}
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) {
......
......@@ -144,7 +144,14 @@ public class FlowRuleManagerTest {
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();
}
......
......@@ -28,6 +28,7 @@ import org.onlab.util.Bandwidth;
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 @@ public class KryoSerializerTest {
@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 =
......