blob: 8912803171f209d774142c6b948befe0c2cca5ee [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.util;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08002
Pavlin Radoslavovad008e02013-02-21 18:42:42 -08003import org.codehaus.jackson.annotate.JsonProperty;
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08004
5/**
6 * The class representing a Switch-Port.
7 */
8public class SwitchPort {
Jonathan Hart3edb1752013-11-14 13:28:17 -08009 private Dpid dpid; // The DPID of the switch
10 private Port port; // The port of the switch
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080011
Jonathan Hart3edb1752013-11-14 13:28:17 -080012 /**
13 * Default constructor.
14 */
15 public SwitchPort() {
16 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080017
Jonathan Hart3edb1752013-11-14 13:28:17 -080018 /**
19 * Constructor for a given DPID and a port.
20 *
21 * @param dpid the DPID to use.
22 * @param port the port to use.
23 */
24 public SwitchPort(Dpid dpid, Port port) {
25 this.dpid = dpid;
26 this.port = port;
27 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080028
Jonathan Hart3edb1752013-11-14 13:28:17 -080029 /**
30 * Get the DPID value of the Switch-Port.
31 *
32 * @return the DPID value of the Switch-Port.
33 */
34 @JsonProperty("dpid")
35 public Dpid dpid() { return dpid; }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080036
Jonathan Hart3edb1752013-11-14 13:28:17 -080037 /**
38 * Set the DPID value of the Switch-Port.
39 *
40 * @param dpid the DPID to use.
41 */
42 @JsonProperty("dpid")
43 public void setDpid(Dpid dpid) {
44 this.dpid = dpid;
45 }
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080046
Jonathan Hart3edb1752013-11-14 13:28:17 -080047 /**
48 * Get the port value of the Switch-Port.
49 *
50 * @return the port value of the Switch-Port.
51 */
52 @JsonProperty("port")
53 public Port port() { return port; }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080054
Jonathan Hart3edb1752013-11-14 13:28:17 -080055 /**
56 * Set the port value of the Switch-Port.
57 *
58 * @param port the port to use.
59 */
60 @JsonProperty("port")
61 public void setPort(Port port) {
62 this.port = port;
63 }
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080064
Jonathan Hart3edb1752013-11-14 13:28:17 -080065 /**
66 * Set the DPID and port values of the Switch-Port.
67 *
68 * @param dpid the DPID to use.
69 * @param port the port to use.
70 */
71 public void setValue(Dpid dpid, Port port) {
72 this.dpid = dpid;
73 this.port = port;
74 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080075
Jonathan Hart3edb1752013-11-14 13:28:17 -080076 /**
77 * Convert the Switch-Port value to a string.
78 *
79 * The string has the following form:
80 * 01:02:03:04:05:06:07:08/1234
81 *
82 * @return the Switch-Port value as a string.
83 */
84 @Override
85 public String toString() {
86 return this.dpid.toString() + "/" + this.port;
87 }
88
Jonathan Hartf0a81792013-11-14 11:36:06 -080089
Jonathan Hart3edb1752013-11-14 13:28:17 -080090 @Override
91 public boolean equals(Object other) {
92 if (!(other instanceof SwitchPort)) {
93 return false;
94 }
Jonathan Hartf0a81792013-11-14 11:36:06 -080095
Jonathan Hart3edb1752013-11-14 13:28:17 -080096 SwitchPort otherSwitchPort = (SwitchPort) other;
Jonathan Hartf0a81792013-11-14 11:36:06 -080097
Jonathan Hart3edb1752013-11-14 13:28:17 -080098 return (dpid.equals(otherSwitchPort.dpid) &&
99 port.equals(otherSwitchPort.port));
100 }
Jonathan Hartf0a81792013-11-14 11:36:06 -0800101
Jonathan Hart3edb1752013-11-14 13:28:17 -0800102 @Override
103 public int hashCode() {
104 int hash = 17;
105 hash += 31 * hash + dpid.hashCode();
106 hash += 31 * hash + port.hashCode();
107 return hash;
108 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800109}