Brian O'Connor

Adding emptyTreatment() and emptySelector()

Note: There was a change that adds a DROP action to
a traffic treatment if there are no other actions present.
To get a traffic treatment without the drop rule, use
emptyTreatment()

Change-Id: I1f23ed5e1fa7519eb94fcafa85facbad815d5e9c
Showing 25 changed files with 83 additions and 57 deletions
......@@ -205,8 +205,8 @@ public class DemoInstaller implements DemoAPI {
@Override
public void run() {
TrafficSelector selector = DefaultTrafficSelector.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficSelector selector = DefaultTrafficSelector.emptySelector();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
List<Constraint> constraint = Lists.newArrayList();
List<Host> hosts = Lists.newArrayList(hostService.getHosts());
while (!hosts.isEmpty()) {
......@@ -405,8 +405,8 @@ public class DemoInstaller implements DemoAPI {
private final Host src;
private final Host dst;
private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
private final List<Constraint> constraint = Lists.newArrayList();
private final HostToHostIntent intent;
......
......@@ -157,8 +157,8 @@ public class IntentReactiveForwarding {
// Install a rule forwarding the packet to the specified port.
private void setUpConnectivity(PacketContext context, HostId srcId, HostId dstId) {
TrafficSelector selector = DefaultTrafficSelector.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficSelector selector = DefaultTrafficSelector.emptySelector();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
HostToHostIntent intent = new HostToHostIntent(appId, srcId, dstId,
selector, treatment);
......
......@@ -203,7 +203,7 @@ public class IntentPerfInstaller {
//FIXME we currently ignore the path length and always use the same device
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthDst(MacAddress.valueOf(count)).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
ConnectPoint ingress = new ConnectPoint(ingressDevice.id(), PortNumber.portNumber(1));
ConnectPoint egress = new ConnectPoint(ingressDevice.id(), PortNumber.portNumber(2));
......
......@@ -166,8 +166,7 @@ public class PeerConnectivityManager {
return intents;
}
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
TrafficSelector selector;
......
......@@ -108,7 +108,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
new ConnectPoint(deviceId2, PortNumber.portNumber(1));
private final TrafficTreatment noTreatment =
DefaultTrafficTreatment.builder().build();
DefaultTrafficTreatment.emptyTreatment();
@Before
public void setUp() throws Exception {
......
......@@ -50,8 +50,8 @@ public class AddHostToHostIntentCommand extends ConnectivityIntentCommand {
HostId oneId = HostId.hostId(one);
HostId twoId = HostId.hostId(two);
TrafficSelector selector = DefaultTrafficSelector.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficSelector selector = DefaultTrafficSelector.emptySelector();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
List<Constraint> constraints = buildConstraints();
HostToHostIntent intent = new HostToHostIntent(appId(), key(),
......
......@@ -68,7 +68,7 @@ public class AddSinglePointToMultiPointIntentCommand extends ConnectivityIntentC
}
TrafficSelector selector = buildTrafficSelector();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
List<Constraint> constraints = buildConstraints();
SinglePointToMultiPointIntent intent =
......
......@@ -120,7 +120,7 @@ public class IntentCycleCommand extends AbstractShellCommand
private List<Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) {
TrafficSelector.Builder selectorBldr = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
List<Intent> intents = Lists.newArrayList();
for (int i = 0; i < count; i++) {
......
......@@ -129,7 +129,7 @@ public class IntentPushTestCommand extends AbstractShellCommand
private List<Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) {
TrafficSelector.Builder selectorBldr = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
List<Intent> intents = Lists.newArrayList();
for (int i = 0; i < count; i++) {
......
......@@ -67,8 +67,8 @@ public class RandomIntentCommand extends AbstractShellCommand {
}
private Collection<Intent> generateIntents() {
TrafficSelector selector = DefaultTrafficSelector.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficSelector selector = DefaultTrafficSelector.emptySelector();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
List<Host> hosts = Lists.newArrayList(hostService.getHosts());
List<Intent> fullMesh = Lists.newArrayList();
......
......@@ -15,22 +15,22 @@
*/
package org.onosproject.net.flow;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import org.onlab.packet.IpPrefix;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* Default traffic selector implementation.
......@@ -39,6 +39,9 @@ public final class DefaultTrafficSelector implements TrafficSelector {
private final Set<Criterion> criteria;
private static final TrafficSelector EMPTY
= new DefaultTrafficSelector(Collections.emptySet());
/**
* Creates a new traffic selector with the specified criteria.
*
......@@ -98,6 +101,15 @@ public final class DefaultTrafficSelector implements TrafficSelector {
}
/**
* Returns an empty traffic selector.
*
* @return empty traffic selector
*/
public static TrafficSelector emptySelector() {
return EMPTY;
}
/**
* Returns a new traffic selector builder primed to produce entities
* patterned after the supplied selector.
*
......
......@@ -27,6 +27,7 @@ import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
......@@ -41,6 +42,9 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
private final boolean hasClear;
private static final DefaultTrafficTreatment EMPTY
= new DefaultTrafficTreatment(Collections.emptyList());
/**
* Creates a new traffic treatment from the specified list of instructions.
*
......@@ -99,6 +103,15 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
}
/**
* Returns an empty traffic treatment.
*
* @return empty traffic treatment
*/
public static TrafficTreatment emptyTreatment() {
return EMPTY;
}
/**
* Returns a new traffic treatment builder primed to produce entities
* patterned after the supplied treatment.
*
......
......@@ -273,12 +273,14 @@ public interface TrafficTreatment {
/**
* Builds an immutable traffic treatment descriptor.
* <p>
* If the treatment is empty when build() is called, it will add a default
* drop rule automatically. For a treatment that is actually empty, use
* {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
* </p>
*
* @return traffic treatment
*/
TrafficTreatment build();
}
}
......
......@@ -50,8 +50,8 @@ public final class HostToHostIntent extends ConnectivityIntent {
*/
public HostToHostIntent(ApplicationId appId, HostId one, HostId two) {
this(appId, one, two,
DefaultTrafficSelector.builder().build(),
DefaultTrafficTreatment.builder().build(),
DefaultTrafficSelector.emptySelector(),
DefaultTrafficTreatment.emptyTreatment(),
ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
}
......
......@@ -51,8 +51,8 @@ public final class TwoWayP2PIntent extends ConnectivityIntent {
*/
public TwoWayP2PIntent(ApplicationId appId, ConnectPoint one, ConnectPoint two) {
this(appId, one, two,
DefaultTrafficSelector.builder().build(),
DefaultTrafficTreatment.builder().build(),
DefaultTrafficSelector.emptySelector(),
DefaultTrafficTreatment.emptyTreatment(),
ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
}
......
......@@ -35,8 +35,8 @@ public abstract class ConnectivityIntentTest extends IntentTest {
public static final ApplicationId APPID = new TestApplicationId("foo");
public static final IntentId IID = new IntentId(123);
public static final TrafficSelector MATCH = DefaultTrafficSelector.builder().build();
public static final TrafficTreatment NOP = DefaultTrafficTreatment.builder().build();
public static final TrafficSelector MATCH = DefaultTrafficSelector.emptySelector();
public static final TrafficTreatment NOP = DefaultTrafficTreatment.emptyTreatment();
public static final ConnectPoint P1 = new ConnectPoint(DeviceId.deviceId("111"), PortNumber.portNumber(0x1));
public static final ConnectPoint P2 = new ConnectPoint(DeviceId.deviceId("222"), PortNumber.portNumber(0x2));
......
......@@ -63,8 +63,8 @@ public class CompilingTest {
private final ApplicationId appId = new TestApplicationId("test");
private final ProviderId pid = new ProviderId("of", "test");
private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
......
......@@ -64,8 +64,8 @@ public class InstallCoordinatingTest {
private final ApplicationId appId = new TestApplicationId("test");
private final ProviderId pid = new ProviderId("of", "test");
private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
......
......@@ -64,8 +64,8 @@ public class InstallingTest {
private final ApplicationId appId = new TestApplicationId("test");
private final ProviderId pid = new ProviderId("of", "test");
private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
......
......@@ -65,8 +65,8 @@ public class WithdrawCoordinatingTest {
private final ApplicationId appId = new TestApplicationId("test");
private final ProviderId pid = new ProviderId("of", "test");
private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
......
......@@ -63,8 +63,8 @@ public class WithdrawingTest {
private final ApplicationId appId = new TestApplicationId("test");
private final ProviderId pid = new ProviderId("of", "test");
private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
private final TrafficSelector selector = DefaultTrafficSelector.emptySelector();
private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
private final ConnectPoint cp1 = new ConnectPoint(deviceId("1"), portNumber(1));
private final ConnectPoint cp2 = new ConnectPoint(deviceId("1"), portNumber(2));
private final ConnectPoint cp3 = new ConnectPoint(deviceId("2"), portNumber(1));
......
......@@ -205,8 +205,8 @@ public class KryoSerializerTest {
@Test
public void testFlowRuleBatchEntry() {
final FlowRule rule1 =
new DefaultFlowRule(DID1, DefaultTrafficSelector.builder().build(),
DefaultTrafficTreatment.builder().build(), 0, 0, 0, true);
new DefaultFlowRule(DID1, DefaultTrafficSelector.emptySelector(),
DefaultTrafficTreatment.emptyTreatment(), 0, 0, 0, true);
final FlowRuleBatchEntry entry1 =
new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
final FlowRuleBatchEntry entry2 =
......
......@@ -67,9 +67,9 @@ public class IntentCodecTest extends AbstractIntentTest {
private final HostId id2 = hid("12:34:56:78:92:ab/1");
private final ApplicationId appId = new DefaultApplicationId(3, "test");
final TrafficSelector emptySelector =
DefaultTrafficSelector.builder().build();
DefaultTrafficSelector.emptySelector();
final TrafficTreatment emptyTreatment =
DefaultTrafficTreatment.builder().build();
DefaultTrafficTreatment.emptyTreatment();
private final CodecContext context = new MockCodecContext();
/**
......
......@@ -312,8 +312,8 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase {
HostToHostIntent intent =
new HostToHostIntent(appId, one, two,
DefaultTrafficSelector.builder().build(),
DefaultTrafficTreatment.builder().build());
DefaultTrafficSelector.emptySelector(),
DefaultTrafficTreatment.emptyTreatment());
intentService.submit(intent);
startMonitoringIntent(event, intent);
......@@ -333,7 +333,7 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase {
// FIXME: clearly, this is not enough
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthDst(dstHost.mac()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
MultiPointToSinglePointIntent intent =
new MultiPointToSinglePointIntent(appId, selector, treatment,
......
......@@ -350,8 +350,8 @@ public class TopologyViewWebSocket
HostToHostIntent intent =
new HostToHostIntent(appId, one, two,
DefaultTrafficSelector.builder().build(),
DefaultTrafficTreatment.builder().build());
DefaultTrafficSelector.emptySelector(),
DefaultTrafficTreatment.emptyTreatment());
intentService.submit(intent);
startMonitoringIntent(event, intent);
......@@ -371,7 +371,7 @@ public class TopologyViewWebSocket
// FIXME: clearly, this is not enough
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchEthDst(dstHost.mac()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
MultiPointToSinglePointIntent intent =
new MultiPointToSinglePointIntent(appId, selector, treatment,
......