blob: f9f27bdf395c5b26fe084fa63197f0dae4b1c49b [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.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/**
Yuta HIGUCHIfb564502014-06-16 21:29:00 -07006 * Immutable class representing a port number.
7 * <p/>
8 * Current implementation supports only OpenFlow 1.0 (16 bit unsigned) port number.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08009 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070010public final class PortNumber {
Jonathan Hart3edb1752013-11-14 13:28:17 -080011 /**
12 * Special port values.
Ray Milkey269ffb92014-04-03 14:43:30 -070013 * <p/>
Jonathan Hart3edb1752013-11-14 13:28:17 -080014 * Those values are taken as-is from the OpenFlow-v1.0.0 specification
15 * (pp 18-19).
16 */
17 public enum PortValues {
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070018 /** Maximum number of physical switch ports. */
Ray Milkey269ffb92014-04-03 14:43:30 -070019 PORT_MAX((short) 0xff00),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080020
Ray Milkey269ffb92014-04-03 14:43:30 -070021 /* Fake output "ports". */
Pavlin Radoslavovede97582013-03-08 18:57:28 -080022
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070023 /** Send the packet out the input port. This
Ray Milkey269ffb92014-04-03 14:43:30 -070024 virtual port must be explicitly used
25 in order to send back out of the input
26 port. */
27 PORT_IN_PORT((short) 0xfff8),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080028
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070029 /** Perform actions in flow table.
Ray Milkey269ffb92014-04-03 14:43:30 -070030 NB: This can only be the destination
31 port for packet-out messages. */
32 PORT_TABLE((short) 0xfff9),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080033
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070034 /** Process with normal L2/L3 switching. */
Ray Milkey269ffb92014-04-03 14:43:30 -070035 PORT_NORMAL((short) 0xfffa),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080036
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070037 /** All physical ports except input port and
Ray Milkey269ffb92014-04-03 14:43:30 -070038 those disabled by STP. */
39 PORT_FLOOD((short) 0xfffb),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080040
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070041 /** All physical ports except input port. */
Ray Milkey269ffb92014-04-03 14:43:30 -070042 PORT_ALL((short) 0xfffc),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080043
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070044 /** Send to controller. */
Ray Milkey269ffb92014-04-03 14:43:30 -070045 PORT_CONTROLLER((short) 0xfffd),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080046
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070047 /** Local openflow "port". */
Ray Milkey269ffb92014-04-03 14:43:30 -070048 PORT_LOCAL((short) 0xfffe),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080049
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070050 /** Not associated with a physical port. */
Ray Milkey269ffb92014-04-03 14:43:30 -070051 PORT_NONE((short) 0xffff);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080052
Ray Milkey269ffb92014-04-03 14:43:30 -070053 private final short value; // The value
Pavlin Radoslavovede97582013-03-08 18:57:28 -080054
Ray Milkey269ffb92014-04-03 14:43:30 -070055 /**
56 * Constructor for a given value.
57 *
58 * @param value the value to use for the initialization.
59 */
60 private PortValues(short value) {
61 this.value = value;
62 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080063
Ray Milkey269ffb92014-04-03 14:43:30 -070064 /**
65 * Get the value as a short integer.
66 *
67 * @return the value as a short integer.
68 */
69 private short value() {
70 return this.value;
71 }
Jonathan Hart3edb1752013-11-14 13:28:17 -080072 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080073
Pavlin Radoslavov29a2a882014-04-08 17:40:54 -070074 private final short value;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080075
Jonathan Hart3edb1752013-11-14 13:28:17 -080076 /**
77 * Default constructor.
78 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070079 protected PortNumber() {
Ray Milkey269ffb92014-04-03 14:43:30 -070080 this.value = 0;
Jonathan Hart3edb1752013-11-14 13:28:17 -080081 }
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080082
Jonathan Hart3edb1752013-11-14 13:28:17 -080083 /**
84 * Copy constructor.
85 *
86 * @param other the object to copy from.
87 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070088 public PortNumber(PortNumber other) {
Ray Milkey269ffb92014-04-03 14:43:30 -070089 this.value = other.value();
Jonathan Hart3edb1752013-11-14 13:28:17 -080090 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080091
Jonathan Hart3edb1752013-11-14 13:28:17 -080092 /**
93 * Constructor from a short integer value.
94 *
95 * @param value the value to use.
96 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070097 public PortNumber(short value) {
Ray Milkey269ffb92014-04-03 14:43:30 -070098 this.value = value;
Jonathan Hart3edb1752013-11-14 13:28:17 -080099 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800100
Jonathan Hart3edb1752013-11-14 13:28:17 -0800101 /**
102 * Constructor from a PortValues enum value.
103 *
104 * @param value the value to use.
105 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700106 public PortNumber(PortValues value) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700107 this.value = value.value();
Jonathan Hart3edb1752013-11-14 13:28:17 -0800108 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800109
Jonathan Hart3edb1752013-11-14 13:28:17 -0800110 /**
111 * Get the value of the port.
112 *
113 * @return the value of the port.
114 */
115 @JsonProperty("value")
Ray Milkey269ffb92014-04-03 14:43:30 -0700116 public short value() {
117 return value;
118 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800119
Jonathan Hart3edb1752013-11-14 13:28:17 -0800120 /**
Jonathan Hart3edb1752013-11-14 13:28:17 -0800121 * Convert the port value to a string.
122 *
123 * @return the port value as a string.
124 */
125 @Override
126 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700127 return Short.toString(this.value);
Jonathan Hart3edb1752013-11-14 13:28:17 -0800128 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700129
Jonathan Hart3edb1752013-11-14 13:28:17 -0800130 @Override
131 public boolean equals(Object other) {
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700132 if (!(other instanceof PortNumber)) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700133 return false;
134 }
Jonathan Hart3edb1752013-11-14 13:28:17 -0800135
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700136 PortNumber otherPort = (PortNumber) other;
Jonathan Hart3edb1752013-11-14 13:28:17 -0800137
Ray Milkey269ffb92014-04-03 14:43:30 -0700138 return value == otherPort.value;
Jonathan Hart3edb1752013-11-14 13:28:17 -0800139 }
140
141 @Override
142 public int hashCode() {
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700143 return value;
Jonathan Hart3edb1752013-11-14 13:28:17 -0800144 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800145}