tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.flow; |
| 2 | |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame^] | 3 | import static com.google.common.base.Preconditions.checkNotNull; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 4 | |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame^] | 5 | import org.onlab.onos.net.PortNumber; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 6 | /** |
| 7 | * Factory class for creating various traffic treatment instructions. |
| 8 | */ |
| 9 | public final class Instructions { |
| 10 | |
| 11 | // Ban construction |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 12 | private Instructions() {} |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 13 | |
| 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 | */ |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame^] | 21 | public static OutputInstruction createOutput(final PortNumber number) { |
| 22 | checkNotNull(number, "PortNumber cannot be null"); |
| 23 | return new OutputInstruction(number); |
| 24 | } |
alshabib | 1d4cace | 2014-09-13 19:16:26 -0700 | [diff] [blame] | 25 | |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame^] | 26 | public static DropInstruction createDrop() { |
| 27 | return new DropInstruction(); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | // TODO: add create methods |
| 31 | |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame^] | 32 | public static final class DropInstruction implements Instruction { |
| 33 | |
| 34 | @Override |
| 35 | public Type type() { |
| 36 | return Type.DROP; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | |
| 41 | public static final class OutputInstruction implements Instruction { |
| 42 | |
| 43 | private final PortNumber port; |
| 44 | |
| 45 | private OutputInstruction(PortNumber port) { |
| 46 | this.port = port; |
| 47 | } |
| 48 | |
| 49 | public PortNumber port() { |
| 50 | return port; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public Type type() { |
| 55 | return Type.OUTPUT; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | } |
| 60 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 61 | } |