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 | /** |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 6 | * Immutable class representing a port number. |
7 | * <p/> | ||||
8 | * Current implementation supports only OpenFlow 1.0 (16 bit unsigned) port number. | ||||
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 9 | */ |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 10 | public final class PortNumber { |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 11 | /** |
12 | * Special port values. | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 13 | * <p/> |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 14 | * Those values are taken as-is from the OpenFlow-v1.0.0 specification |
15 | * (pp 18-19). | ||||
16 | */ | ||||
17 | public enum PortValues { | ||||
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 18 | /** Maximum number of physical switch ports. */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 19 | PORT_MAX((short) 0xff00), |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 20 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 21 | /* Fake output "ports". */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 22 | |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 23 | /** Send the packet out the input port. This |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 24 | 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 Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 28 | |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 29 | /** Perform actions in flow table. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 30 | NB: This can only be the destination |
31 | port for packet-out messages. */ | ||||
32 | PORT_TABLE((short) 0xfff9), | ||||
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 33 | |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 34 | /** Process with normal L2/L3 switching. */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | PORT_NORMAL((short) 0xfffa), |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 36 | |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 37 | /** All physical ports except input port and |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 38 | those disabled by STP. */ |
39 | PORT_FLOOD((short) 0xfffb), | ||||
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 40 | |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 41 | /** All physical ports except input port. */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 42 | PORT_ALL((short) 0xfffc), |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 43 | |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 44 | /** Send to controller. */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 45 | PORT_CONTROLLER((short) 0xfffd), |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 46 | |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 47 | /** Local openflow "port". */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 48 | PORT_LOCAL((short) 0xfffe), |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 49 | |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 50 | /** Not associated with a physical port. */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 51 | PORT_NONE((short) 0xffff); |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 52 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 53 | private final short value; // The value |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 54 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 55 | /** |
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 Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 63 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 64 | /** |
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 Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 72 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 73 | |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 74 | private final short value; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 75 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 76 | /** |
77 | * Default constructor. | ||||
78 | */ | ||||
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 79 | protected PortNumber() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 80 | this.value = 0; |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 81 | } |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 82 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 83 | /** |
84 | * Copy constructor. | ||||
85 | * | ||||
86 | * @param other the object to copy from. | ||||
87 | */ | ||||
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 88 | public PortNumber(PortNumber other) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 89 | this.value = other.value(); |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 90 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 91 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 92 | /** |
93 | * Constructor from a short integer value. | ||||
94 | * | ||||
95 | * @param value the value to use. | ||||
96 | */ | ||||
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 97 | public PortNumber(short value) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 98 | this.value = value; |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 99 | } |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 100 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 101 | /** |
102 | * Constructor from a PortValues enum value. | ||||
103 | * | ||||
104 | * @param value the value to use. | ||||
105 | */ | ||||
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 106 | public PortNumber(PortValues value) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 107 | this.value = value.value(); |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 108 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 109 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 110 | /** |
111 | * Get the value of the port. | ||||
112 | * | ||||
113 | * @return the value of the port. | ||||
114 | */ | ||||
115 | @JsonProperty("value") | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 116 | public short value() { |
117 | return value; | ||||
118 | } | ||||
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 119 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 120 | /** |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 121 | * Convert the port value to a string. |
122 | * | ||||
123 | * @return the port value as a string. | ||||
124 | */ | ||||
125 | @Override | ||||
126 | public String toString() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 127 | return Short.toString(this.value); |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 128 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 129 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 130 | @Override |
131 | public boolean equals(Object other) { | ||||
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 132 | if (!(other instanceof PortNumber)) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 133 | return false; |
134 | } | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 135 | |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 136 | PortNumber otherPort = (PortNumber) other; |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 137 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 138 | return value == otherPort.value; |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 139 | } |
140 | |||||
141 | @Override | ||||
142 | public int hashCode() { | ||||
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame^] | 143 | return value; |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 144 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 145 | } |