blob: fedc8df1494cc79019e19ca8f2ef8cd7de313807 [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08003import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08004
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08005/**
6 * The class representing a network port of a switch.
7 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08008
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08009public class Port {
Jonathan Hart3edb1752013-11-14 13:28:17 -080010 /**
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),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080019
Jonathan Hart3edb1752013-11-14 13:28:17 -080020 /* Fake output "ports". */
Pavlin Radoslavovede97582013-03-08 18:57:28 -080021
Jonathan Hart3edb1752013-11-14 13:28:17 -080022 /* Send the packet out the input port. This
Pavlin Radoslavovede97582013-03-08 18:57:28 -080023 virtual port must be explicitly used
24 in order to send back out of the input
25 port. */
Jonathan Hart3edb1752013-11-14 13:28:17 -080026 PORT_IN_PORT ((short)0xfff8),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080027
Jonathan Hart3edb1752013-11-14 13:28:17 -080028 /* Perform actions in flow table.
Pavlin Radoslavovede97582013-03-08 18:57:28 -080029 NB: This can only be the destination
30 port for packet-out messages. */
Jonathan Hart3edb1752013-11-14 13:28:17 -080031 PORT_TABLE ((short)0xfff9),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080032
Jonathan Hart3edb1752013-11-14 13:28:17 -080033 /* Process with normal L2/L3 switching. */
34 PORT_NORMAL ((short)0xfffa),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080035
Jonathan Hart3edb1752013-11-14 13:28:17 -080036 /* All physical ports except input port and
Pavlin Radoslavovede97582013-03-08 18:57:28 -080037 those disabled by STP. */
Jonathan Hart3edb1752013-11-14 13:28:17 -080038 PORT_FLOOD ((short)0xfffb),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080039
Jonathan Hart3edb1752013-11-14 13:28:17 -080040 /* All physical ports except input port. */
41 PORT_ALL ((short)0xfffc),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080042
Jonathan Hart3edb1752013-11-14 13:28:17 -080043 /* Send to controller. */
44 PORT_CONTROLLER ((short)0xfffd),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080045
Jonathan Hart3edb1752013-11-14 13:28:17 -080046 /* Local openflow "port". */
47 PORT_LOCAL ((short)0xfffe),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080048
Jonathan Hart3edb1752013-11-14 13:28:17 -080049 /* Not associated with a physical port. */
50 PORT_NONE ((short)0xffff);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080051
Jonathan Hart3edb1752013-11-14 13:28:17 -080052 private final short value; // The value
Pavlin Radoslavovede97582013-03-08 18:57:28 -080053
54 /**
Jonathan Hart3edb1752013-11-14 13:28:17 -080055 * Constructor for a given value.
Pavlin Radoslavovede97582013-03-08 18:57:28 -080056 *
Jonathan Hart3edb1752013-11-14 13:28:17 -080057 * @param value the value to use for the initialization.
Pavlin Radoslavovede97582013-03-08 18:57:28 -080058 */
Jonathan Hart3edb1752013-11-14 13:28:17 -080059 private PortValues(short value) {
60 this.value = value;
Jonathan Hartf0a81792013-11-14 11:36:06 -080061 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080062
Jonathan Hartf0a81792013-11-14 11:36:06 -080063 /**
Jonathan Hart3edb1752013-11-14 13:28:17 -080064 * Get the value as a short integer.
Jonathan Hartf0a81792013-11-14 11:36:06 -080065 *
Jonathan Hart3edb1752013-11-14 13:28:17 -080066 * @return the value as a short integer.
Jonathan Hartf0a81792013-11-14 11:36:06 -080067 */
Jonathan Hart3edb1752013-11-14 13:28:17 -080068 private short value() { return this.value; }
69 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080070
Jonathan Hart3edb1752013-11-14 13:28:17 -080071 private short value;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080072
Jonathan Hart3edb1752013-11-14 13:28:17 -080073 /**
74 * Default constructor.
75 */
76 public Port() {
77 this.value = 0;
78 }
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080079
Jonathan Hart3edb1752013-11-14 13:28:17 -080080 /**
81 * Copy constructor.
82 *
83 * @param other the object to copy from.
84 */
85 public Port(Port other) {
86 this.value = other.value();
87 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080088
Jonathan Hart3edb1752013-11-14 13:28:17 -080089 /**
90 * Constructor from a short integer value.
91 *
92 * @param value the value to use.
93 */
94 public Port(short value) {
95 this.value = value;
96 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080097
Jonathan Hart3edb1752013-11-14 13:28:17 -080098 /**
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 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800106
Jonathan Hart3edb1752013-11-14 13:28:17 -0800107 /**
108 * Get the value of the port.
109 *
110 * @return the value of the port.
111 */
112 @JsonProperty("value")
113 public short value() { return value; }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800114
Jonathan Hart3edb1752013-11-14 13:28:17 -0800115 /**
116 * Set the value of the port.
117 *
118 * @param value the value to set.
119 */
120 @JsonProperty("value")
121 public void setValue(short value) {
122 this.value = value;
123 }
Jonathan Hartf0a81792013-11-14 11:36:06 -0800124
Jonathan Hart3edb1752013-11-14 13:28:17 -0800125 /**
126 * Convert the port value to a string.
127 *
128 * @return the port value as a string.
129 */
130 @Override
131 public String toString() {
132 return Short.toString(this.value);
133 }
134
135
136 @Override
137 public boolean equals(Object other) {
138 if (!(other instanceof Port)) {
139 return false;
140 }
141
142 Port otherPort = (Port) other;
143
144 return value == otherPort.value;
145 }
146
147 @Override
148 public int hashCode() {
149 int hash = 17;
150 hash += 31 * hash + (int)value;
151 return hash;
152 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800153}