blob: 77d983b0e7945aaa712ffe0a1f9c29f0728f04e2 [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/**
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.
Ray Milkey269ffb92014-04-03 14:43:30 -070012 * <p/>
Jonathan Hart3edb1752013-11-14 13:28:17 -080013 * Those values are taken as-is from the OpenFlow-v1.0.0 specification
14 * (pp 18-19).
15 */
16 public enum PortValues {
Ray Milkey269ffb92014-04-03 14:43:30 -070017 /* Maximum number of physical switch ports. */
18 PORT_MAX((short) 0xff00),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080019
Ray Milkey269ffb92014-04-03 14:43:30 -070020 /* Fake output "ports". */
Pavlin Radoslavovede97582013-03-08 18:57:28 -080021
Ray Milkey269ffb92014-04-03 14:43:30 -070022 /* 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),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080027
Ray Milkey269ffb92014-04-03 14:43:30 -070028 /* Perform actions in flow table.
29 NB: This can only be the destination
30 port for packet-out messages. */
31 PORT_TABLE((short) 0xfff9),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080032
Ray Milkey269ffb92014-04-03 14:43:30 -070033 /* Process with normal L2/L3 switching. */
34 PORT_NORMAL((short) 0xfffa),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080035
Ray Milkey269ffb92014-04-03 14:43:30 -070036 /* All physical ports except input port and
37 those disabled by STP. */
38 PORT_FLOOD((short) 0xfffb),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080039
Ray Milkey269ffb92014-04-03 14:43:30 -070040 /* All physical ports except input port. */
41 PORT_ALL((short) 0xfffc),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080042
Ray Milkey269ffb92014-04-03 14:43:30 -070043 /* Send to controller. */
44 PORT_CONTROLLER((short) 0xfffd),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080045
Ray Milkey269ffb92014-04-03 14:43:30 -070046 /* Local openflow "port". */
47 PORT_LOCAL((short) 0xfffe),
Pavlin Radoslavovede97582013-03-08 18:57:28 -080048
Ray Milkey269ffb92014-04-03 14:43:30 -070049 /* Not associated with a physical port. */
50 PORT_NONE((short) 0xffff);
Pavlin Radoslavovede97582013-03-08 18:57:28 -080051
Ray Milkey269ffb92014-04-03 14:43:30 -070052 private final short value; // The value
Pavlin Radoslavovede97582013-03-08 18:57:28 -080053
Ray Milkey269ffb92014-04-03 14:43:30 -070054 /**
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 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080062
Ray Milkey269ffb92014-04-03 14:43:30 -070063 /**
64 * Get the value as a short integer.
65 *
66 * @return the value as a short integer.
67 */
68 private short value() {
69 return this.value;
70 }
Jonathan Hart3edb1752013-11-14 13:28:17 -080071 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080072
Jonathan Hart3edb1752013-11-14 13:28:17 -080073 private short value;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080074
Jonathan Hart3edb1752013-11-14 13:28:17 -080075 /**
76 * Default constructor.
77 */
78 public Port() {
Ray Milkey269ffb92014-04-03 14:43:30 -070079 this.value = 0;
Jonathan Hart3edb1752013-11-14 13:28:17 -080080 }
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080081
Jonathan Hart3edb1752013-11-14 13:28:17 -080082 /**
83 * Copy constructor.
84 *
85 * @param other the object to copy from.
86 */
87 public Port(Port other) {
Ray Milkey269ffb92014-04-03 14:43:30 -070088 this.value = other.value();
Jonathan Hart3edb1752013-11-14 13:28:17 -080089 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080090
Jonathan Hart3edb1752013-11-14 13:28:17 -080091 /**
92 * Constructor from a short integer value.
93 *
94 * @param value the value to use.
95 */
96 public Port(short value) {
Ray Milkey269ffb92014-04-03 14:43:30 -070097 this.value = value;
Jonathan Hart3edb1752013-11-14 13:28:17 -080098 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080099
Jonathan Hart3edb1752013-11-14 13:28:17 -0800100 /**
101 * Constructor from a PortValues enum value.
102 *
103 * @param value the value to use.
104 */
105 public Port(PortValues value) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700106 this.value = value.value();
Jonathan Hart3edb1752013-11-14 13:28:17 -0800107 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800108
Jonathan Hart3edb1752013-11-14 13:28:17 -0800109 /**
110 * Get the value of the port.
111 *
112 * @return the value of the port.
113 */
114 @JsonProperty("value")
Ray Milkey269ffb92014-04-03 14:43:30 -0700115 public short value() {
116 return value;
117 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800118
Jonathan Hart3edb1752013-11-14 13:28:17 -0800119 /**
120 * Set the value of the port.
121 *
122 * @param value the value to set.
123 */
124 @JsonProperty("value")
125 public void setValue(short value) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700126 this.value = value;
Jonathan Hart3edb1752013-11-14 13:28:17 -0800127 }
Jonathan Hartf0a81792013-11-14 11:36:06 -0800128
Jonathan Hart3edb1752013-11-14 13:28:17 -0800129 /**
130 * Convert the port value to a string.
131 *
132 * @return the port value as a string.
133 */
134 @Override
135 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700136 return Short.toString(this.value);
Jonathan Hart3edb1752013-11-14 13:28:17 -0800137 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700138
Jonathan Hart3edb1752013-11-14 13:28:17 -0800139
140 @Override
141 public boolean equals(Object other) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700142 if (!(other instanceof Port)) {
143 return false;
144 }
Jonathan Hart3edb1752013-11-14 13:28:17 -0800145
Ray Milkey269ffb92014-04-03 14:43:30 -0700146 Port otherPort = (Port) other;
Jonathan Hart3edb1752013-11-14 13:28:17 -0800147
Ray Milkey269ffb92014-04-03 14:43:30 -0700148 return value == otherPort.value;
Jonathan Hart3edb1752013-11-14 13:28:17 -0800149 }
150
151 @Override
152 public int hashCode() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700153 int hash = 17;
154 hash += 31 * hash + (int) value;
155 return hash;
Jonathan Hart3edb1752013-11-14 13:28:17 -0800156 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800157}