Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.util; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 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 { |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -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), | ||||
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 19 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 20 | /* Fake output "ports". */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 21 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 22 | /* Send the packet out the input port. This |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 23 | virtual port must be explicitly used |
24 | in order to send back out of the input | ||||
25 | port. */ | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 26 | PORT_IN_PORT ((short)0xfff8), |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 27 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 28 | /* Perform actions in flow table. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 29 | NB: This can only be the destination |
30 | port for packet-out messages. */ | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 31 | PORT_TABLE ((short)0xfff9), |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 32 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 33 | /* Process with normal L2/L3 switching. */ |
34 | PORT_NORMAL ((short)0xfffa), | ||||
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 35 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 36 | /* All physical ports except input port and |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 37 | those disabled by STP. */ |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 38 | PORT_FLOOD ((short)0xfffb), |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 39 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 40 | /* All physical ports except input port. */ |
41 | PORT_ALL ((short)0xfffc), | ||||
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 42 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 43 | /* Send to controller. */ |
44 | PORT_CONTROLLER ((short)0xfffd), | ||||
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 45 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 46 | /* Local openflow "port". */ |
47 | PORT_LOCAL ((short)0xfffe), | ||||
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 48 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 49 | /* Not associated with a physical port. */ |
50 | PORT_NONE ((short)0xffff); | ||||
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 51 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 52 | private final short value; // The value |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 53 | |
54 | /** | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 55 | * Constructor for a given value. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 56 | * |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 57 | * @param value the value to use for the initialization. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 58 | */ |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 59 | private PortValues(short value) { |
60 | this.value = value; | ||||
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 61 | } |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 62 | |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 63 | /** |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 64 | * Get the value as a short integer. |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 65 | * |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 66 | * @return the value as a short integer. |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 67 | */ |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 68 | private short value() { return this.value; } |
69 | } | ||||
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 70 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 71 | private short value; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 72 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 73 | /** |
74 | * Default constructor. | ||||
75 | */ | ||||
76 | public Port() { | ||||
77 | this.value = 0; | ||||
78 | } | ||||
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 79 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 80 | /** |
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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 88 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 89 | /** |
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 Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 97 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 98 | /** |
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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 106 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 107 | /** |
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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 114 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 115 | /** |
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 Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 124 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 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() { | ||||
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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 153 | } |