tom

Merge remote-tracking branch 'origin/master'

......@@ -2,6 +2,8 @@ package org.onlab.onos.net.flow;
import java.util.List;
import org.onlab.onos.net.flow.criteria.Criterion;
/**
* Abstraction of a slice of network traffic.
*/
......
package org.onlab.onos.net.flow;
package org.onlab.onos.net.flow.criteria;
/**
* Factory class to create various traffic selection criteria.
......
package org.onlab.onos.net.flow;
package org.onlab.onos.net.flow.criteria;
/**
* Representation of a single header field selection.
......
......@@ -5,6 +5,12 @@ package org.onlab.onos.net.flow.instructions;
*/
public interface Instruction {
interface SubType { }
public enum NoneSubType implements SubType {
NONE;
}
/**
* Represents the type of traffic treatment.
*/
......@@ -39,4 +45,10 @@ public interface Instruction {
*/
public Type type();
/**
* Returns the subtype of the modification instruction.
* @return type of instruction
*/
public SubType subtype();
}
......
......@@ -3,8 +3,12 @@ package org.onlab.onos.net.flow.instructions;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.L2SubType;
import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.SubType;
import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.L3SubType;
import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPProtoInstruction;
import org.onlab.packet.IPAddress;
import org.onlab.packet.MACAddress;
/**
* Factory class for creating various traffic treatment instructions.
......@@ -42,7 +46,7 @@ public final class Instructions {
*/
public static L2ModificationInstruction modL2Src(MACAddress addr) {
checkNotNull(addr, "Src l2 address cannot be null");
return new ModEtherInstruction(SubType.L2_SRC, addr);
return new ModEtherInstruction(L2SubType.L2_SRC, addr);
}
/**
......@@ -52,7 +56,7 @@ public final class Instructions {
*/
public static L2ModificationInstruction modL2Dst(MACAddress addr) {
checkNotNull(addr, "Dst l2 address cannot be null");
return new L2ModificationInstruction.ModEtherInstruction(SubType.L2_DST, addr);
return new L2ModificationInstruction.ModEtherInstruction(L2SubType.L2_DST, addr);
}
/**
......@@ -65,11 +69,56 @@ public final class Instructions {
return new L2ModificationInstruction.ModEtherTypeInstruction(l2Type);
}
/**
* Creates a Vlan id modification.
* @param vlanId the vlan id to modify to.
* @return a L2 modification
*/
public static L2ModificationInstruction modVlanId(Short vlanId) {
checkNotNull(vlanId, "VLAN id cannot be null");
return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
}
/**
* Creates a Vlan pcp modification.
* @param vlanPcp the pcp to modify to.
* @return a L2 modification
*/
public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
}
/**
* Creates a L3 src modification.
* @param addr the ip address to modify to.
* @return a L3 modification
*/
public static L3ModificationInstruction modL3Src(IPAddress addr) {
checkNotNull(addr, "Src l3 address cannot be null");
return new ModIPInstruction(L3SubType.L3_SRC, addr);
}
/**
* Creates a L3 dst modification.
* @param addr the ip address to modify to.
* @return a L3 modification
*/
public static L3ModificationInstruction modL3Dst(IPAddress addr) {
checkNotNull(addr, "Dst l3 address cannot be null");
return new ModIPInstruction(L3SubType.L3_DST, addr);
}
/**
* Creates an L3 protocol modification.
* @param proto the protocol to change to
* @return a L3 modification
*/
public static L3ModificationInstruction modIPProto(Byte proto) {
checkNotNull(proto, "IP protocol cannot be null");
return new ModIPProtoInstruction(proto);
}
/*
* Output instructions
*/
......@@ -79,6 +128,11 @@ public final class Instructions {
public Type type() {
return Type.DROP;
}
@Override
public SubType subtype() {
return NoneSubType.NONE;
}
}
......@@ -97,6 +151,11 @@ public final class Instructions {
public Type type() {
return Type.OUTPUT;
}
@Override
public SubType subtype() {
return NoneSubType.NONE;
}
}
}
......
......@@ -11,7 +11,7 @@ public abstract class L2ModificationInstruction implements Instruction {
/**
* Represents the type of traffic treatment.
*/
public enum SubType {
public enum L2SubType implements SubType {
/**
* Ether src modification.
*/
......@@ -41,10 +41,7 @@ public abstract class L2ModificationInstruction implements Instruction {
// TODO: Create factory class 'Instructions' that will have various factory
// to create specific instructions.
/**
* Returns the subtype of the modification instruction.
* @return type of instruction
*/
@Override
public abstract SubType subtype();
@Override
......@@ -89,7 +86,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public SubType subtype() {
return SubType.L2_TYPE;
return L2SubType.L2_TYPE;
}
public short l2Type() {
......@@ -111,7 +108,7 @@ public abstract class L2ModificationInstruction implements Instruction {
@Override
public SubType subtype() {
return SubType.VLAN_ID;
return L2SubType.VLAN_ID;
}
public Short vlanId() {
......@@ -120,5 +117,27 @@ public abstract class L2ModificationInstruction implements Instruction {
}
/**
* Represents a VLAN PCP modification instruction.
*/
public static final class ModVlanPcpInstruction extends L2ModificationInstruction {
public final Byte vlanPcp;
public ModVlanPcpInstruction(Byte vlanPcp) {
this.vlanPcp = vlanPcp;
}
@Override
public SubType subtype() {
return L2SubType.VLAN_PCP;
}
public Byte vlanPcp() {
return this.vlanPcp;
}
}
}
......
package org.onlab.onos.net.flow.instructions;
import org.onlab.packet.IPAddress;
/**
* Abstraction of a single traffic treatment step.
* @param <T> the type parameter for the instruction
*/
public abstract class L3ModificationInstruction implements Instruction {
/**
* Represents the type of traffic treatment.
*/
public enum L3SubType implements SubType {
/**
* Ether src modification.
*/
L3_SRC,
/**
* Ether dst modification.
*/
L3_DST,
/**
* Ethertype modification.
*/
L3_PROTO,
//TODO: remaining types
}
/**
* Returns the subtype of the modification instruction.
* @return type of instruction
*/
public abstract SubType subtype();
@Override
public Type type() {
return Type.MODIFICATION;
}
/**
* Represents a L3 src/dst modification instruction.
*/
public static final class ModIPInstruction extends L3ModificationInstruction {
private final SubType subtype;
private final IPAddress ip;
public ModIPInstruction(SubType subType, IPAddress addr) {
this.subtype = subType;
this.ip = addr;
}
@Override
public SubType subtype() {
return this.subtype;
}
public IPAddress ip() {
return this.ip;
}
}
/**
* Represents a L3 proto modification instruction.
*/
public static final class ModIPProtoInstruction extends L3ModificationInstruction {
public final Byte proto;
public ModIPProtoInstruction(Byte proto) {
this.proto = proto;
}
@Override
public SubType subtype() {
return L3SubType.L3_PROTO;
}
public short proto() {
return this.proto;
}
}
}