blob: 41f0d555e2b3bfa8c1722a9a8ef78ac0e58baeff [file] [log] [blame]
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08001package net.floodlightcontroller.util;
2
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 {
Pavlin Radoslavovede97582013-03-08 18:57:28 -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),
19
20 /* Fake output "ports". */
21
22 /* 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),
27
28 /* Perform actions in flow table.
29 NB: This can only be the destination
30 port for packet-out messages. */
31 PORT_TABLE ((short)0xfff9),
32
33 /* Process with normal L2/L3 switching. */
34 PORT_NORMAL ((short)0xfffa),
35
36 /* All physical ports except input port and
37 those disabled by STP. */
38 PORT_FLOOD ((short)0xfffb),
39
40 /* All physical ports except input port. */
41 PORT_ALL ((short)0xfffc),
42
43 /* Send to controller. */
44 PORT_CONTROLLER ((short)0xfffd),
45
46 /* Local openflow "port". */
47 PORT_LOCAL ((short)0xfffe),
48
49 /* Not associated with a physical port. */
50 PORT_NONE ((short)0xffff);
51
52 private final short value; // The value
53
54 /**
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 }
62
63 /**
64 * Get the value as a short integer.
65 *
66 * @return the value as a short integer.
67 */
68 private short value() { return this.value; }
69 }
70
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080071 private short value;
72
73 /**
74 * Default constructor.
75 */
76 public Port() {
77 this.value = 0;
78 }
79
80 /**
Pavlin Radoslavovf83aa442013-02-26 14:09:01 -080081 * Constructor from another entry.
82 *
83 * @param other the other entry to use.
84 */
85 public Port(Port other) {
86 this.value = other.value();
87 }
88
89 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -080090 * Constructor from a short integer value.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080091 *
92 * @param value the value to use.
93 */
94 public Port(short value) {
95 this.value = value;
96 }
97
98 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -080099 * 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 }
106
107 /**
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800108 * Get the value of the port.
109 *
110 * @return the value of the port.
111 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800112 @JsonProperty("value")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800113 public short value() { return value; }
114
115 /**
116 * Set the value of the port.
117 *
118 * @param value the value to set.
119 */
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -0800120 @JsonProperty("value")
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800121 public void setValue(short value) {
122 this.value = value;
123 }
124
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() {
Pavlin Radoslavovad008e02013-02-21 18:42:42 -0800132 return Short.toString(this.value);
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800133 }
134}