Charles Chan
Committed by Gerrit Code Review

[CORD-197] Properly handles a flow with empty instruction

Change-Id: Ia465fdc8df1dca7a46249cd4cd8d41faf8461c3a
......@@ -234,6 +234,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
switch (instruction.type()) {
case DROP:
case NOACTION:
case OUTPUT:
case GROUP:
case L0MODIFICATION:
......@@ -259,9 +260,23 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
return this;
}
/**
* Add a NOACTION when DROP instruction is explicitly specified.
*
* @return the traffic treatment builder
*/
@Override
public Builder drop() {
return add(Instructions.createDrop());
return add(Instructions.createNoAction());
}
/**
* Add a NOACTION when no instruction is specified.
*
* @return the traffic treatment builder
*/
private Builder noAction() {
return add(Instructions.createNoAction());
}
@Override
......@@ -459,14 +474,10 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
@Override
public TrafficTreatment build() {
//Don't add DROP instruction by default when instruction
//set is empty. This will be handled in DefaultSingleTablePipeline
//driver.
//if (deferred.size() == 0 && immediate.size() == 0
// && table == null && !clear) {
// drop();
//}
if (deferred.size() == 0 && immediate.size() == 0
&& table == null && !clear) {
noAction();
}
return new DefaultTrafficTreatment(deferred, immediate, table, clear, meta, meter);
}
......
......@@ -27,9 +27,18 @@ public interface Instruction {
/**
* Signifies that the traffic should be dropped.
*/
@Deprecated
DROP,
/**
* Signifies that the traffic requires no action.
*
* In OF10, the behavior of NOACTION is DROP.
* In OF13, the behavior depends on current Action Set.
*/
NOACTION,
/**
* Signifies that the traffic should be output to a port.
*/
OUTPUT,
......
......@@ -68,11 +68,21 @@ public final class Instructions {
*
* @return drop instruction
*/
@Deprecated
public static DropInstruction createDrop() {
return new DropInstruction();
}
/**
* Creates a no action instruction.
*
* @return no action instruction
*/
public static NoActionInstruction createNoAction() {
return new NoActionInstruction();
}
/**
* Creates a group instruction.
*
* @param groupId Group Id
......@@ -450,6 +460,7 @@ public final class Instructions {
/**
* Drop instruction.
*/
@Deprecated
public static final class DropInstruction implements Instruction {
private DropInstruction() {}
......@@ -482,6 +493,40 @@ public final class Instructions {
}
/**
* No Action instruction.
*/
public static final class NoActionInstruction implements Instruction {
private NoActionInstruction() {}
@Override
public Type type() {
return Type.NOACTION;
}
@Override
public String toString() {
return toStringHelper(type().toString()).toString();
}
@Override
public int hashCode() {
return Objects.hash(type().ordinal());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof NoActionInstruction) {
return true;
}
return false;
}
}
/**
* Output Instruction.
*/
public static final class OutputInstruction implements Instruction {
......
......@@ -339,6 +339,7 @@ public final class KryoNamespaces {
Criterion.Type.class,
DefaultTrafficTreatment.class,
Instructions.DropInstruction.class,
Instructions.NoActionInstruction.class,
Instructions.OutputInstruction.class,
Instructions.GroupInstruction.class,
Instructions.TableTypeTransition.class,
......
......@@ -221,11 +221,6 @@ public class FlowEntryBuilder {
private TrafficTreatment buildTreatment() {
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
// If this is a drop rule
if (instructions.size() == 0) {
builder.drop();
return builder.build();
}
for (OFInstruction in : instructions) {
switch (in.getType()) {
case GOTO_TABLE:
......
......@@ -142,7 +142,7 @@ public class FlowModBuilderVer10 extends FlowModBuilder {
for (Instruction i : treatment.immediate()) {
switch (i.type()) {
case DROP:
log.warn("Saw drop action; assigning drop action");
case NOACTION:
return Collections.emptyList();
case L2MODIFICATION:
act = buildL2Modification(i);
......
......@@ -215,6 +215,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
for (Instruction i : treatments) {
switch (i.type()) {
case DROP:
case NOACTION:
return Collections.emptyList();
case L0MODIFICATION:
actions.add(buildL0Modification(i));
......