Hyunsun Moon
Committed by Gerrit Code Review

ONOS-2403 Support setting TCP/UDP port action in flow rule for OpenFlow13

Change-Id: I4ce84aba9db03a66ebcfb34959c11cc4acadb07b
...@@ -224,6 +224,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { ...@@ -224,6 +224,7 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
224 case L0MODIFICATION: 224 case L0MODIFICATION:
225 case L2MODIFICATION: 225 case L2MODIFICATION:
226 case L3MODIFICATION: 226 case L3MODIFICATION:
227 + case L4MODIFICATION:
227 current.add(instruction); 228 current.add(instruction);
228 break; 229 break;
229 case TABLE: 230 case TABLE:
...@@ -390,6 +391,26 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { ...@@ -390,6 +391,26 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
390 } 391 }
391 392
392 @Override 393 @Override
394 + public TrafficTreatment.Builder setTcpSrc(short port) {
395 + return add(Instructions.modTcpSrc(port));
396 + }
397 +
398 + @Override
399 + public TrafficTreatment.Builder setTcpDst(short port) {
400 + return add(Instructions.modTcpDst(port));
401 + }
402 +
403 + @Override
404 + public TrafficTreatment.Builder setUdpSrc(short port) {
405 + return add(Instructions.modUdpSrc(port));
406 + }
407 +
408 + @Override
409 + public TrafficTreatment.Builder setUdpDst(short port) {
410 + return add(Instructions.modUdpDst(port));
411 + }
412 +
413 + @Override
393 public TrafficTreatment build() { 414 public TrafficTreatment build() {
394 //Don't add DROP instruction by default when instruction 415 //Don't add DROP instruction by default when instruction
395 //set is empty. This will be handled in DefaultSingleTablePipeline 416 //set is empty. This will be handled in DefaultSingleTablePipeline
......
...@@ -319,6 +319,38 @@ public interface TrafficTreatment { ...@@ -319,6 +319,38 @@ public interface TrafficTreatment {
319 Builder setTunnelId(long tunnelId); 319 Builder setTunnelId(long tunnelId);
320 320
321 /** 321 /**
322 + * Sets the src TCP port.
323 + *
324 + * @param port a port number
325 + * @return a treatment builder
326 + */
327 + Builder setTcpSrc(short port);
328 +
329 + /**
330 + * Sets the dst TCP port.
331 + *
332 + * @param port a port number
333 + * @return a treatment builder
334 + */
335 + Builder setTcpDst(short port);
336 +
337 + /**
338 + * Sets the src UDP port.
339 + *
340 + * @param port a port number
341 + * @return a treatment builder
342 + */
343 + Builder setUdpSrc(short port);
344 +
345 + /**
346 + * Sets the dst UDP port.
347 + *
348 + * @param port a port number
349 + * @return a treatment builder
350 + */
351 + Builder setUdpDst(short port);
352 +
353 + /**
322 * Builds an immutable traffic treatment descriptor. 354 * Builds an immutable traffic treatment descriptor.
323 * <p> 355 * <p>
324 * If the treatment is empty when build() is called, it will add a default 356 * If the treatment is empty when build() is called, it will add a default
......
...@@ -32,6 +32,8 @@ import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType ...@@ -32,6 +32,8 @@ import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType
32 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; 32 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
33 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; 33 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
34 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction; 34 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
35 +import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType;
36 +import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
35 37
36 import java.util.Objects; 38 import java.util.Objects;
37 39
...@@ -361,6 +363,50 @@ public final class Instructions { ...@@ -361,6 +363,50 @@ public final class Instructions {
361 } 363 }
362 364
363 /** 365 /**
366 + * Creates a TCP src modification.
367 + *
368 + * @param port the TCP port number to modify to
369 + * @return a L4 modification
370 + */
371 + public static L4ModificationInstruction modTcpSrc(short port) {
372 + checkNotNull(port, "Src TCP port cannot be null");
373 + return new ModTransportPortInstruction(L4SubType.TCP_SRC, port);
374 + }
375 +
376 + /**
377 + * Creates a TCP dst modification.
378 + *
379 + * @param port the TCP port number to modify to
380 + * @return a L4 modification
381 + */
382 + public static L4ModificationInstruction modTcpDst(short port) {
383 + checkNotNull(port, "Dst TCP port cannot be null");
384 + return new ModTransportPortInstruction(L4SubType.TCP_DST, port);
385 + }
386 +
387 + /**
388 + * Creates a UDP src modification.
389 + *
390 + * @param port the UDP port number to modify to
391 + * @return a L4 modification
392 + */
393 + public static L4ModificationInstruction modUdpSrc(short port) {
394 + checkNotNull(port, "Src UDP port cannot be null");
395 + return new ModTransportPortInstruction(L4SubType.UDP_SRC, port);
396 + }
397 +
398 + /**
399 + * Creates a UDP dst modification.
400 + *
401 + * @param port the UDP port number to modify to
402 + * @return a L4 modification
403 + */
404 + public static L4ModificationInstruction modUdpDst(short port) {
405 + checkNotNull(port, "Dst UDP port cannot be null");
406 + return new ModTransportPortInstruction(L4SubType.UDP_DST, port);
407 + }
408 +
409 + /**
364 * Drop instruction. 410 * Drop instruction.
365 */ 411 */
366 public static final class DropInstruction implements Instruction { 412 public static final class DropInstruction implements Instruction {
......
...@@ -66,12 +66,12 @@ public abstract class L4ModificationInstruction implements Instruction { ...@@ -66,12 +66,12 @@ public abstract class L4ModificationInstruction implements Instruction {
66 /** 66 /**
67 * Represents a L4 src/dst modification instruction. 67 * Represents a L4 src/dst modification instruction.
68 */ 68 */
69 - public static final class ModL4PortInstruction extends L4ModificationInstruction { 69 + public static final class ModTransportPortInstruction extends L4ModificationInstruction {
70 70
71 private final L4SubType subtype; 71 private final L4SubType subtype;
72 private final short port; 72 private final short port;
73 73
74 - public ModL4PortInstruction(L4SubType subtype, short port) { 74 + public ModTransportPortInstruction(L4SubType subtype, short port) {
75 this.subtype = subtype; 75 this.subtype = subtype;
76 this.port = port; 76 this.port = port;
77 } 77 }
...@@ -101,8 +101,8 @@ public abstract class L4ModificationInstruction implements Instruction { ...@@ -101,8 +101,8 @@ public abstract class L4ModificationInstruction implements Instruction {
101 if (this == obj) { 101 if (this == obj) {
102 return true; 102 return true;
103 } 103 }
104 - if (obj instanceof ModL4PortInstruction) { 104 + if (obj instanceof ModTransportPortInstruction) {
105 - ModL4PortInstruction that = (ModL4PortInstruction) obj; 105 + ModTransportPortInstruction that = (ModTransportPortInstruction) obj;
106 return Objects.equals(port, that.port) && 106 return Objects.equals(port, that.port) &&
107 Objects.equals(this.subtype(), that.subtype()); 107 Objects.equals(this.subtype(), that.subtype());
108 } 108 }
......
...@@ -127,6 +127,7 @@ import org.onosproject.net.flow.instructions.Instructions; ...@@ -127,6 +127,7 @@ import org.onosproject.net.flow.instructions.Instructions;
127 import org.onosproject.net.flow.instructions.L0ModificationInstruction; 127 import org.onosproject.net.flow.instructions.L0ModificationInstruction;
128 import org.onosproject.net.flow.instructions.L2ModificationInstruction; 128 import org.onosproject.net.flow.instructions.L2ModificationInstruction;
129 import org.onosproject.net.flow.instructions.L3ModificationInstruction; 129 import org.onosproject.net.flow.instructions.L3ModificationInstruction;
130 +import org.onosproject.net.flow.instructions.L4ModificationInstruction;
130 import org.onosproject.net.host.DefaultHostDescription; 131 import org.onosproject.net.host.DefaultHostDescription;
131 import org.onosproject.net.host.HostDescription; 132 import org.onosproject.net.host.HostDescription;
132 import org.onosproject.net.intent.ConnectivityIntent; 133 import org.onosproject.net.intent.ConnectivityIntent;
...@@ -354,6 +355,9 @@ public final class KryoNamespaces { ...@@ -354,6 +355,9 @@ public final class KryoNamespaces {
354 L3ModificationInstruction.ModIPInstruction.class, 355 L3ModificationInstruction.ModIPInstruction.class,
355 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class, 356 L3ModificationInstruction.ModIPv6FlowLabelInstruction.class,
356 L3ModificationInstruction.ModTtlInstruction.class, 357 L3ModificationInstruction.ModTtlInstruction.class,
358 + L4ModificationInstruction.class,
359 + L4ModificationInstruction.L4SubType.class,
360 + L4ModificationInstruction.ModTransportPortInstruction.class,
357 RoleInfo.class, 361 RoleInfo.class,
358 FlowRuleBatchEvent.class, 362 FlowRuleBatchEvent.class,
359 FlowRuleBatchEvent.Type.class, 363 FlowRuleBatchEvent.Type.class,
......
...@@ -71,6 +71,7 @@ import org.projectfloodlight.openflow.types.IPv4Address; ...@@ -71,6 +71,7 @@ import org.projectfloodlight.openflow.types.IPv4Address;
71 import org.projectfloodlight.openflow.types.IPv6Address; 71 import org.projectfloodlight.openflow.types.IPv6Address;
72 import org.projectfloodlight.openflow.types.Masked; 72 import org.projectfloodlight.openflow.types.Masked;
73 import org.projectfloodlight.openflow.types.OFVlanVidMatch; 73 import org.projectfloodlight.openflow.types.OFVlanVidMatch;
74 +import org.projectfloodlight.openflow.types.TransportPort;
74 import org.projectfloodlight.openflow.types.U32; 75 import org.projectfloodlight.openflow.types.U32;
75 import org.projectfloodlight.openflow.types.U64; 76 import org.projectfloodlight.openflow.types.U64;
76 import org.projectfloodlight.openflow.types.U8; 77 import org.projectfloodlight.openflow.types.U8;
...@@ -408,6 +409,26 @@ public class FlowEntryBuilder { ...@@ -408,6 +409,26 @@ public class FlowEntryBuilder {
408 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm; 409 OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
409 builder.setTunnelId(tunnelId.getValue().getValue()); 410 builder.setTunnelId(tunnelId.getValue().getValue());
410 break; 411 break;
412 + case TCP_DST:
413 + @SuppressWarnings("unchecked")
414 + OFOxm<TransportPort> tcpdst = (OFOxm<TransportPort>) oxm;
415 + builder.setTcpDst((short) tcpdst.getValue().getPort());
416 + break;
417 + case TCP_SRC:
418 + @SuppressWarnings("unchecked")
419 + OFOxm<TransportPort> tcpsrc = (OFOxm<TransportPort>) oxm;
420 + builder.setTcpSrc((short) tcpsrc.getValue().getPort());
421 + break;
422 + case UDP_DST:
423 + @SuppressWarnings("unchecked")
424 + OFOxm<TransportPort> udpdst = (OFOxm<TransportPort>) oxm;
425 + builder.setUdpDst((short) udpdst.getValue().getPort());
426 + break;
427 + case UDP_SRC:
428 + @SuppressWarnings("unchecked")
429 + OFOxm<TransportPort> udpsrc = (OFOxm<TransportPort>) oxm;
430 + builder.setUdpSrc((short) udpsrc.getValue().getPort());
431 + break;
411 case ARP_OP: 432 case ARP_OP:
412 case ARP_SHA: 433 case ARP_SHA:
413 case ARP_SPA: 434 case ARP_SPA:
...@@ -455,10 +476,6 @@ public class FlowEntryBuilder { ...@@ -455,10 +476,6 @@ public class FlowEntryBuilder {
455 case OCH_SIGTYPE_BASIC: 476 case OCH_SIGTYPE_BASIC:
456 case SCTP_DST: 477 case SCTP_DST:
457 case SCTP_SRC: 478 case SCTP_SRC:
458 - case TCP_DST:
459 - case TCP_SRC:
460 - case UDP_DST:
461 - case UDP_SRC:
462 default: 479 default:
463 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id); 480 log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
464 break; 481 break;
......
...@@ -39,6 +39,8 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnel ...@@ -39,6 +39,8 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnel
39 import org.onosproject.net.flow.instructions.L3ModificationInstruction; 39 import org.onosproject.net.flow.instructions.L3ModificationInstruction;
40 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; 40 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
41 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; 41 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
42 +import org.onosproject.net.flow.instructions.L4ModificationInstruction;
43 +import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
42 import org.projectfloodlight.openflow.protocol.OFFactory; 44 import org.projectfloodlight.openflow.protocol.OFFactory;
43 import org.projectfloodlight.openflow.protocol.OFFlowAdd; 45 import org.projectfloodlight.openflow.protocol.OFFlowAdd;
44 import org.projectfloodlight.openflow.protocol.OFFlowDelete; 46 import org.projectfloodlight.openflow.protocol.OFFlowDelete;
...@@ -61,6 +63,7 @@ import org.projectfloodlight.openflow.types.OFGroup; ...@@ -61,6 +63,7 @@ import org.projectfloodlight.openflow.types.OFGroup;
61 import org.projectfloodlight.openflow.types.OFPort; 63 import org.projectfloodlight.openflow.types.OFPort;
62 import org.projectfloodlight.openflow.types.OFVlanVidMatch; 64 import org.projectfloodlight.openflow.types.OFVlanVidMatch;
63 import org.projectfloodlight.openflow.types.TableId; 65 import org.projectfloodlight.openflow.types.TableId;
66 +import org.projectfloodlight.openflow.types.TransportPort;
64 import org.projectfloodlight.openflow.types.U32; 67 import org.projectfloodlight.openflow.types.U32;
65 import org.projectfloodlight.openflow.types.U64; 68 import org.projectfloodlight.openflow.types.U64;
66 import org.projectfloodlight.openflow.types.VlanPcp; 69 import org.projectfloodlight.openflow.types.VlanPcp;
...@@ -214,6 +217,9 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -214,6 +217,9 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
214 case L3MODIFICATION: 217 case L3MODIFICATION:
215 actions.add(buildL3Modification(i)); 218 actions.add(buildL3Modification(i));
216 break; 219 break;
220 + case L4MODIFICATION:
221 + actions.add(buildL4Modification(i));
222 + break;
217 case OUTPUT: 223 case OUTPUT:
218 OutputInstruction out = (OutputInstruction) i; 224 OutputInstruction out = (OutputInstruction) i;
219 OFActionOutput.Builder action = factory().actions().buildOutput() 225 OFActionOutput.Builder action = factory().actions().buildOutput()
...@@ -327,7 +333,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -327,7 +333,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
327 ModMplsLabelInstruction mplsLabel = 333 ModMplsLabelInstruction mplsLabel =
328 (ModMplsLabelInstruction) l2m; 334 (ModMplsLabelInstruction) l2m;
329 oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label() 335 oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label()
330 - .longValue())); 336 + .longValue()));
331 break; 337 break;
332 case DEC_MPLS_TTL: 338 case DEC_MPLS_TTL:
333 return factory().actions().decMplsTtl(); 339 return factory().actions().decMplsTtl();
...@@ -402,4 +408,36 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -402,4 +408,36 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
402 return null; 408 return null;
403 } 409 }
404 410
411 + private OFAction buildL4Modification(Instruction i) {
412 + L4ModificationInstruction l4m = (L4ModificationInstruction) i;
413 + ModTransportPortInstruction tp;
414 + OFOxm<?> oxm = null;
415 + switch (l4m.subtype()) {
416 + case TCP_SRC:
417 + tp = (ModTransportPortInstruction) l4m;
418 + oxm = factory().oxms().tcpSrc(TransportPort.of(tp.port()));
419 + break;
420 + case TCP_DST:
421 + tp = (ModTransportPortInstruction) l4m;
422 + oxm = factory().oxms().tcpDst(TransportPort.of(tp.port()));
423 + break;
424 + case UDP_SRC:
425 + tp = (ModTransportPortInstruction) l4m;
426 + oxm = factory().oxms().udpSrc(TransportPort.of(tp.port()));
427 + break;
428 + case UDP_DST:
429 + tp = (ModTransportPortInstruction) l4m;
430 + oxm = factory().oxms().udpDst(TransportPort.of(tp.port()));
431 + break;
432 + default:
433 + log.warn("Unimplemented action type {}.", l4m.subtype());
434 + break;
435 + }
436 +
437 + if (oxm != null) {
438 + return factory().actions().buildSetField().setField(oxm).build();
439 + }
440 + return null;
441 + }
442 +
405 } 443 }
......