Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 2 | |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 3 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 4 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 5 | /** |
| 6 | * The class representing a network port of a switch. |
| 7 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 8 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 9 | public class Port { |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 10 | /** |
| 11 | * Special port values. |
| 12 | * |
| 13 | * Those values are taken as-is from the OpenFlow-v1.0.0 specification |
| 14 | * (pp 18-19). |
| 15 | */ |
| 16 | public enum PortValues { |
| 17 | /* Maximum number of physical switch ports. */ |
| 18 | PORT_MAX ((short)0xff00), |
| 19 | |
| 20 | /* Fake output "ports". */ |
| 21 | |
| 22 | /* Send the packet out the input port. This |
| 23 | virtual port must be explicitly used |
| 24 | in order to send back out of the input |
| 25 | port. */ |
| 26 | PORT_IN_PORT ((short)0xfff8), |
| 27 | |
| 28 | /* Perform actions in flow table. |
| 29 | NB: This can only be the destination |
| 30 | port for packet-out messages. */ |
| 31 | PORT_TABLE ((short)0xfff9), |
| 32 | |
| 33 | /* Process with normal L2/L3 switching. */ |
| 34 | PORT_NORMAL ((short)0xfffa), |
| 35 | |
| 36 | /* All physical ports except input port and |
| 37 | those disabled by STP. */ |
| 38 | PORT_FLOOD ((short)0xfffb), |
| 39 | |
| 40 | /* All physical ports except input port. */ |
| 41 | PORT_ALL ((short)0xfffc), |
| 42 | |
| 43 | /* Send to controller. */ |
| 44 | PORT_CONTROLLER ((short)0xfffd), |
| 45 | |
| 46 | /* Local openflow "port". */ |
| 47 | PORT_LOCAL ((short)0xfffe), |
| 48 | |
| 49 | /* Not associated with a physical port. */ |
| 50 | PORT_NONE ((short)0xffff); |
| 51 | |
| 52 | private final short value; // The value |
| 53 | |
| 54 | /** |
| 55 | * Constructor for a given value. |
| 56 | * |
| 57 | * @param value the value to use for the initialization. |
| 58 | */ |
| 59 | private PortValues(short value) { |
| 60 | this.value = value; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Get the value as a short integer. |
| 65 | * |
| 66 | * @return the value as a short integer. |
| 67 | */ |
| 68 | private short value() { return this.value; } |
| 69 | } |
| 70 | |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 71 | private short value; |
| 72 | |
| 73 | /** |
| 74 | * Default constructor. |
| 75 | */ |
| 76 | public Port() { |
| 77 | this.value = 0; |
| 78 | } |
| 79 | |
| 80 | /** |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 81 | * Constructor from another entry. |
| 82 | * |
| 83 | * @param other the other entry to use. |
| 84 | */ |
| 85 | public Port(Port other) { |
| 86 | this.value = other.value(); |
| 87 | } |
| 88 | |
| 89 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 90 | * Constructor from a short integer value. |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 91 | * |
| 92 | * @param value the value to use. |
| 93 | */ |
| 94 | public Port(short value) { |
| 95 | this.value = value; |
| 96 | } |
| 97 | |
| 98 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 99 | * Constructor from a PortValues enum value. |
| 100 | * |
| 101 | * @param value the value to use. |
| 102 | */ |
| 103 | public Port(PortValues value) { |
| 104 | this.value = value.value(); |
| 105 | } |
| 106 | |
| 107 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 108 | * Get the value of the port. |
| 109 | * |
| 110 | * @return the value of the port. |
| 111 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 112 | @JsonProperty("value") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 113 | public short value() { return value; } |
| 114 | |
| 115 | /** |
| 116 | * Set the value of the port. |
| 117 | * |
| 118 | * @param value the value to set. |
| 119 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 120 | @JsonProperty("value") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 121 | public void setValue(short value) { |
| 122 | this.value = value; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Convert the port value to a string. |
| 127 | * |
| 128 | * @return the port value as a string. |
| 129 | */ |
| 130 | @Override |
| 131 | public String toString() { |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 132 | return Short.toString(this.value); |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 133 | } |
| 134 | } |