blob: cfe14403f47228ac8fb1323fa0b9c81a18124169 [file] [log] [blame]
tom8bb16062014-09-12 14:47:46 -07001package org.onlab.onos.net.flow;
2
alshabib030111e2014-09-15 15:56:42 -07003import static com.google.common.base.Preconditions.checkNotNull;
tom8bb16062014-09-12 14:47:46 -07004
alshabib030111e2014-09-15 15:56:42 -07005import org.onlab.onos.net.PortNumber;
tom8bb16062014-09-12 14:47:46 -07006/**
7 * Factory class for creating various traffic treatment instructions.
8 */
9public final class Instructions {
10
11 // Ban construction
alshabib1d4cace2014-09-13 19:16:26 -070012 private Instructions() {}
tom8bb16062014-09-12 14:47:46 -070013
14 /**
15 * Creates an output instruction using the specified port number. This can
16 * include logical ports such as CONTROLLER, FLOOD, etc.
17 *
18 * @param number port number
19 * @return output instruction
20 */
alshabib030111e2014-09-15 15:56:42 -070021 public static OutputInstruction createOutput(final PortNumber number) {
22 checkNotNull(number, "PortNumber cannot be null");
23 return new OutputInstruction(number);
24 }
alshabib1d4cace2014-09-13 19:16:26 -070025
tom89b63c52014-09-16 09:19:51 -070026 // TODO: Move these out into separate classes and to flow.instruction package
alshabib030111e2014-09-15 15:56:42 -070027 public static DropInstruction createDrop() {
28 return new DropInstruction();
tom8bb16062014-09-12 14:47:46 -070029 }
30
31 // TODO: add create methods
32
alshabib030111e2014-09-15 15:56:42 -070033 public static final class DropInstruction implements Instruction {
alshabib030111e2014-09-15 15:56:42 -070034 @Override
35 public Type type() {
36 return Type.DROP;
37 }
38 }
39
40
41 public static final class OutputInstruction implements Instruction {
alshabib030111e2014-09-15 15:56:42 -070042 private final PortNumber port;
43
44 private OutputInstruction(PortNumber port) {
45 this.port = port;
46 }
47
48 public PortNumber port() {
49 return port;
50 }
51
52 @Override
53 public Type type() {
54 return Type.OUTPUT;
55 }
alshabib030111e2014-09-15 15:56:42 -070056 }
57
tom8bb16062014-09-12 14:47:46 -070058}