mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-21 04:12:23 +02:00
ONOS-2403 Support setting TCP/UDP port action in flow rule for OpenFlow13
Change-Id: I4ce84aba9db03a66ebcfb34959c11cc4acadb07b
This commit is contained in:
parent
9c9ff7c170
commit
c8bd97c5e1
@ -224,6 +224,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
|
|||||||
case L0MODIFICATION:
|
case L0MODIFICATION:
|
||||||
case L2MODIFICATION:
|
case L2MODIFICATION:
|
||||||
case L3MODIFICATION:
|
case L3MODIFICATION:
|
||||||
|
case L4MODIFICATION:
|
||||||
current.add(instruction);
|
current.add(instruction);
|
||||||
break;
|
break;
|
||||||
case TABLE:
|
case TABLE:
|
||||||
@ -389,6 +390,26 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
|
|||||||
return add(Instructions.modTunnelId(tunnelId));
|
return add(Instructions.modTunnelId(tunnelId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TrafficTreatment.Builder setTcpSrc(short port) {
|
||||||
|
return add(Instructions.modTcpSrc(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TrafficTreatment.Builder setTcpDst(short port) {
|
||||||
|
return add(Instructions.modTcpDst(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TrafficTreatment.Builder setUdpSrc(short port) {
|
||||||
|
return add(Instructions.modUdpSrc(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TrafficTreatment.Builder setUdpDst(short port) {
|
||||||
|
return add(Instructions.modUdpDst(port));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TrafficTreatment build() {
|
public TrafficTreatment build() {
|
||||||
//Don't add DROP instruction by default when instruction
|
//Don't add DROP instruction by default when instruction
|
||||||
|
@ -318,6 +318,38 @@ public interface TrafficTreatment {
|
|||||||
*/
|
*/
|
||||||
Builder setTunnelId(long tunnelId);
|
Builder setTunnelId(long tunnelId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the src TCP port.
|
||||||
|
*
|
||||||
|
* @param port a port number
|
||||||
|
* @return a treatment builder
|
||||||
|
*/
|
||||||
|
Builder setTcpSrc(short port);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the dst TCP port.
|
||||||
|
*
|
||||||
|
* @param port a port number
|
||||||
|
* @return a treatment builder
|
||||||
|
*/
|
||||||
|
Builder setTcpDst(short port);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the src UDP port.
|
||||||
|
*
|
||||||
|
* @param port a port number
|
||||||
|
* @return a treatment builder
|
||||||
|
*/
|
||||||
|
Builder setUdpSrc(short port);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the dst UDP port.
|
||||||
|
*
|
||||||
|
* @param port a port number
|
||||||
|
* @return a treatment builder
|
||||||
|
*/
|
||||||
|
Builder setUdpDst(short port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds an immutable traffic treatment descriptor.
|
* Builds an immutable traffic treatment descriptor.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -32,6 +32,8 @@ import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType
|
|||||||
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
|
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
|
||||||
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
|
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
|
||||||
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
|
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
|
||||||
|
import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType;
|
||||||
|
import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -360,6 +362,50 @@ public final class Instructions {
|
|||||||
return new L2ModificationInstruction.ModTunnelIdInstruction(tunnelId);
|
return new L2ModificationInstruction.ModTunnelIdInstruction(tunnelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a TCP src modification.
|
||||||
|
*
|
||||||
|
* @param port the TCP port number to modify to
|
||||||
|
* @return a L4 modification
|
||||||
|
*/
|
||||||
|
public static L4ModificationInstruction modTcpSrc(short port) {
|
||||||
|
checkNotNull(port, "Src TCP port cannot be null");
|
||||||
|
return new ModTransportPortInstruction(L4SubType.TCP_SRC, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a TCP dst modification.
|
||||||
|
*
|
||||||
|
* @param port the TCP port number to modify to
|
||||||
|
* @return a L4 modification
|
||||||
|
*/
|
||||||
|
public static L4ModificationInstruction modTcpDst(short port) {
|
||||||
|
checkNotNull(port, "Dst TCP port cannot be null");
|
||||||
|
return new ModTransportPortInstruction(L4SubType.TCP_DST, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a UDP src modification.
|
||||||
|
*
|
||||||
|
* @param port the UDP port number to modify to
|
||||||
|
* @return a L4 modification
|
||||||
|
*/
|
||||||
|
public static L4ModificationInstruction modUdpSrc(short port) {
|
||||||
|
checkNotNull(port, "Src UDP port cannot be null");
|
||||||
|
return new ModTransportPortInstruction(L4SubType.UDP_SRC, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a UDP dst modification.
|
||||||
|
*
|
||||||
|
* @param port the UDP port number to modify to
|
||||||
|
* @return a L4 modification
|
||||||
|
*/
|
||||||
|
public static L4ModificationInstruction modUdpDst(short port) {
|
||||||
|
checkNotNull(port, "Dst UDP port cannot be null");
|
||||||
|
return new ModTransportPortInstruction(L4SubType.UDP_DST, port);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drop instruction.
|
* Drop instruction.
|
||||||
*/
|
*/
|
||||||
|
@ -66,12 +66,12 @@ public abstract class L4ModificationInstruction implements Instruction {
|
|||||||
/**
|
/**
|
||||||
* Represents a L4 src/dst modification instruction.
|
* Represents a L4 src/dst modification instruction.
|
||||||
*/
|
*/
|
||||||
public static final class ModL4PortInstruction extends L4ModificationInstruction {
|
public static final class ModTransportPortInstruction extends L4ModificationInstruction {
|
||||||
|
|
||||||
private final L4SubType subtype;
|
private final L4SubType subtype;
|
||||||
private final short port;
|
private final short port;
|
||||||
|
|
||||||
public ModL4PortInstruction(L4SubType subtype, short port) {
|
public ModTransportPortInstruction(L4SubType subtype, short port) {
|
||||||
this.subtype = subtype;
|
this.subtype = subtype;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
@ -101,8 +101,8 @@ public abstract class L4ModificationInstruction implements Instruction {
|
|||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof ModL4PortInstruction) {
|
if (obj instanceof ModTransportPortInstruction) {
|
||||||
ModL4PortInstruction that = (ModL4PortInstruction) obj;
|
ModTransportPortInstruction that = (ModTransportPortInstruction) obj;
|
||||||
return Objects.equals(port, that.port) &&
|
return Objects.equals(port, that.port) &&
|
||||||
Objects.equals(this.subtype(), that.subtype());
|
Objects.equals(this.subtype(), that.subtype());
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,7 @@ import org.onosproject.net.flow.instructions.Instructions;
|
|||||||
import org.onosproject.net.flow.instructions.L0ModificationInstruction;
|
import org.onosproject.net.flow.instructions.L0ModificationInstruction;
|
||||||
import org.onosproject.net.flow.instructions.L2ModificationInstruction;
|
import org.onosproject.net.flow.instructions.L2ModificationInstruction;
|
||||||
import org.onosproject.net.flow.instructions.L3ModificationInstruction;
|
import org.onosproject.net.flow.instructions.L3ModificationInstruction;
|
||||||
|
import org.onosproject.net.flow.instructions.L4ModificationInstruction;
|
||||||
import org.onosproject.net.host.DefaultHostDescription;
|
import org.onosproject.net.host.DefaultHostDescription;
|
||||||
import org.onosproject.net.host.HostDescription;
|
import org.onosproject.net.host.HostDescription;
|
||||||
import org.onosproject.net.intent.ConnectivityIntent;
|
import org.onosproject.net.intent.ConnectivityIntent;
|
||||||
@ -354,6 +355,9 @@ public final class KryoNamespaces {
|
|||||||
L3ModificationInstruction.ModIPInstruction.class,
|
L3ModificationInstruction.ModIPInstruction.class,
|
||||||
L3ModificationInstruction.ModIPv6FlowLabelInstruction.class,
|
L3ModificationInstruction.ModIPv6FlowLabelInstruction.class,
|
||||||
L3ModificationInstruction.ModTtlInstruction.class,
|
L3ModificationInstruction.ModTtlInstruction.class,
|
||||||
|
L4ModificationInstruction.class,
|
||||||
|
L4ModificationInstruction.L4SubType.class,
|
||||||
|
L4ModificationInstruction.ModTransportPortInstruction.class,
|
||||||
RoleInfo.class,
|
RoleInfo.class,
|
||||||
FlowRuleBatchEvent.class,
|
FlowRuleBatchEvent.class,
|
||||||
FlowRuleBatchEvent.Type.class,
|
FlowRuleBatchEvent.Type.class,
|
||||||
|
@ -71,6 +71,7 @@ import org.projectfloodlight.openflow.types.IPv4Address;
|
|||||||
import org.projectfloodlight.openflow.types.IPv6Address;
|
import org.projectfloodlight.openflow.types.IPv6Address;
|
||||||
import org.projectfloodlight.openflow.types.Masked;
|
import org.projectfloodlight.openflow.types.Masked;
|
||||||
import org.projectfloodlight.openflow.types.OFVlanVidMatch;
|
import org.projectfloodlight.openflow.types.OFVlanVidMatch;
|
||||||
|
import org.projectfloodlight.openflow.types.TransportPort;
|
||||||
import org.projectfloodlight.openflow.types.U32;
|
import org.projectfloodlight.openflow.types.U32;
|
||||||
import org.projectfloodlight.openflow.types.U64;
|
import org.projectfloodlight.openflow.types.U64;
|
||||||
import org.projectfloodlight.openflow.types.U8;
|
import org.projectfloodlight.openflow.types.U8;
|
||||||
@ -408,6 +409,26 @@ public class FlowEntryBuilder {
|
|||||||
OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
|
OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
|
||||||
builder.setTunnelId(tunnelId.getValue().getValue());
|
builder.setTunnelId(tunnelId.getValue().getValue());
|
||||||
break;
|
break;
|
||||||
|
case TCP_DST:
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
|
||||||
|
builder.setTcpDst((short) tcpdst.getValue().getPort());
|
||||||
|
break;
|
||||||
|
case TCP_SRC:
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
|
||||||
|
builder.setTcpSrc((short) tcpsrc.getValue().getPort());
|
||||||
|
break;
|
||||||
|
case UDP_DST:
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
|
||||||
|
builder.setUdpDst((short) udpdst.getValue().getPort());
|
||||||
|
break;
|
||||||
|
case UDP_SRC:
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
|
||||||
|
builder.setUdpSrc((short) udpsrc.getValue().getPort());
|
||||||
|
break;
|
||||||
case ARP_OP:
|
case ARP_OP:
|
||||||
case ARP_SHA:
|
case ARP_SHA:
|
||||||
case ARP_SPA:
|
case ARP_SPA:
|
||||||
@ -455,10 +476,6 @@ public class FlowEntryBuilder {
|
|||||||
case OCH_SIGTYPE_BASIC:
|
case OCH_SIGTYPE_BASIC:
|
||||||
case SCTP_DST:
|
case SCTP_DST:
|
||||||
case SCTP_SRC:
|
case SCTP_SRC:
|
||||||
case TCP_DST:
|
|
||||||
case TCP_SRC:
|
|
||||||
case UDP_DST:
|
|
||||||
case UDP_SRC:
|
|
||||||
default:
|
default:
|
||||||
log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
|
log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
|
||||||
break;
|
break;
|
||||||
|
@ -39,6 +39,8 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnel
|
|||||||
import org.onosproject.net.flow.instructions.L3ModificationInstruction;
|
import org.onosproject.net.flow.instructions.L3ModificationInstruction;
|
||||||
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
|
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
|
||||||
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
|
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
|
||||||
|
import org.onosproject.net.flow.instructions.L4ModificationInstruction;
|
||||||
|
import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
|
||||||
import org.projectfloodlight.openflow.protocol.OFFactory;
|
import org.projectfloodlight.openflow.protocol.OFFactory;
|
||||||
import org.projectfloodlight.openflow.protocol.OFFlowAdd;
|
import org.projectfloodlight.openflow.protocol.OFFlowAdd;
|
||||||
import org.projectfloodlight.openflow.protocol.OFFlowDelete;
|
import org.projectfloodlight.openflow.protocol.OFFlowDelete;
|
||||||
@ -61,6 +63,7 @@ import org.projectfloodlight.openflow.types.OFGroup;
|
|||||||
import org.projectfloodlight.openflow.types.OFPort;
|
import org.projectfloodlight.openflow.types.OFPort;
|
||||||
import org.projectfloodlight.openflow.types.OFVlanVidMatch;
|
import org.projectfloodlight.openflow.types.OFVlanVidMatch;
|
||||||
import org.projectfloodlight.openflow.types.TableId;
|
import org.projectfloodlight.openflow.types.TableId;
|
||||||
|
import org.projectfloodlight.openflow.types.TransportPort;
|
||||||
import org.projectfloodlight.openflow.types.U32;
|
import org.projectfloodlight.openflow.types.U32;
|
||||||
import org.projectfloodlight.openflow.types.U64;
|
import org.projectfloodlight.openflow.types.U64;
|
||||||
import org.projectfloodlight.openflow.types.VlanPcp;
|
import org.projectfloodlight.openflow.types.VlanPcp;
|
||||||
@ -214,6 +217,9 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
|
|||||||
case L3MODIFICATION:
|
case L3MODIFICATION:
|
||||||
actions.add(buildL3Modification(i));
|
actions.add(buildL3Modification(i));
|
||||||
break;
|
break;
|
||||||
|
case L4MODIFICATION:
|
||||||
|
actions.add(buildL4Modification(i));
|
||||||
|
break;
|
||||||
case OUTPUT:
|
case OUTPUT:
|
||||||
OutputInstruction out = (OutputInstruction) i;
|
OutputInstruction out = (OutputInstruction) i;
|
||||||
OFActionOutput.Builder action = factory().actions().buildOutput()
|
OFActionOutput.Builder action = factory().actions().buildOutput()
|
||||||
@ -327,7 +333,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
|
|||||||
ModMplsLabelInstruction mplsLabel =
|
ModMplsLabelInstruction mplsLabel =
|
||||||
(ModMplsLabelInstruction) l2m;
|
(ModMplsLabelInstruction) l2m;
|
||||||
oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label()
|
oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label()
|
||||||
.longValue()));
|
.longValue()));
|
||||||
break;
|
break;
|
||||||
case DEC_MPLS_TTL:
|
case DEC_MPLS_TTL:
|
||||||
return factory().actions().decMplsTtl();
|
return factory().actions().decMplsTtl();
|
||||||
@ -402,4 +408,36 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OFAction buildL4Modification(Instruction i) {
|
||||||
|
L4ModificationInstruction l4m = (L4ModificationInstruction) i;
|
||||||
|
ModTransportPortInstruction tp;
|
||||||
|
OFOxm<?> oxm = null;
|
||||||
|
switch (l4m.subtype()) {
|
||||||
|
case TCP_SRC:
|
||||||
|
tp = (ModTransportPortInstruction) l4m;
|
||||||
|
oxm = factory().oxms().tcpSrc(TransportPort.of(tp.port()));
|
||||||
|
break;
|
||||||
|
case TCP_DST:
|
||||||
|
tp = (ModTransportPortInstruction) l4m;
|
||||||
|
oxm = factory().oxms().tcpDst(TransportPort.of(tp.port()));
|
||||||
|
break;
|
||||||
|
case UDP_SRC:
|
||||||
|
tp = (ModTransportPortInstruction) l4m;
|
||||||
|
oxm = factory().oxms().udpSrc(TransportPort.of(tp.port()));
|
||||||
|
break;
|
||||||
|
case UDP_DST:
|
||||||
|
tp = (ModTransportPortInstruction) l4m;
|
||||||
|
oxm = factory().oxms().udpDst(TransportPort.of(tp.port()));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log.warn("Unimplemented action type {}.", l4m.subtype());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oxm != null) {
|
||||||
|
return factory().actions().buildSetField().setField(oxm).build();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user