blob: eb72b7228b5d038dafd96bc4c39789a5155c641e [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 Radoslavov5363c2a2013-02-18 09:55:42 -08004
5/**
6 * The class representing a Switch-Port.
7 */
8public class SwitchPort {
Ray Milkey269ffb92014-04-03 14:43:30 -07009 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) {
Ray Milkey269ffb92014-04-03 14:43:30 -070025 this.dpid = dpid;
26 this.port = port;
Jonathan Hart3edb1752013-11-14 13:28:17 -080027 }
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")
Ray Milkey269ffb92014-04-03 14:43:30 -070035 public Dpid dpid() {
36 return dpid;
37 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080038
Jonathan Hart3edb1752013-11-14 13:28:17 -080039 /**
40 * Set the DPID value of the Switch-Port.
41 *
42 * @param dpid the DPID to use.
43 */
44 @JsonProperty("dpid")
45 public void setDpid(Dpid dpid) {
Ray Milkey269ffb92014-04-03 14:43:30 -070046 this.dpid = dpid;
Jonathan Hart3edb1752013-11-14 13:28:17 -080047 }
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080048
Jonathan Hart3edb1752013-11-14 13:28:17 -080049 /**
50 * Get the port value of the Switch-Port.
51 *
52 * @return the port value of the Switch-Port.
53 */
54 @JsonProperty("port")
Ray Milkey269ffb92014-04-03 14:43:30 -070055 public Port port() {
56 return port;
57 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080058
Jonathan Hart3edb1752013-11-14 13:28:17 -080059 /**
60 * Set the port value of the Switch-Port.
61 *
62 * @param port the port to use.
63 */
64 @JsonProperty("port")
65 public void setPort(Port port) {
Ray Milkey269ffb92014-04-03 14:43:30 -070066 this.port = port;
Jonathan Hart3edb1752013-11-14 13:28:17 -080067 }
Pavlin Radoslavov2013cbb2013-02-26 10:15:18 -080068
Jonathan Hart3edb1752013-11-14 13:28:17 -080069 /**
70 * Set the DPID and port values of the Switch-Port.
71 *
72 * @param dpid the DPID to use.
73 * @param port the port to use.
74 */
75 public void setValue(Dpid dpid, Port port) {
Ray Milkey269ffb92014-04-03 14:43:30 -070076 this.dpid = dpid;
77 this.port = port;
Jonathan Hart3edb1752013-11-14 13:28:17 -080078 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080079
Jonathan Hart3edb1752013-11-14 13:28:17 -080080 /**
81 * Convert the Switch-Port value to a string.
Ray Milkey269ffb92014-04-03 14:43:30 -070082 * <p/>
Jonathan Hart3edb1752013-11-14 13:28:17 -080083 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -070084 * 01:02:03:04:05:06:07:08/1234
Jonathan Hart3edb1752013-11-14 13:28:17 -080085 *
86 * @return the Switch-Port value as a string.
87 */
88 @Override
89 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -070090 return this.dpid.toString() + "/" + this.port;
Jonathan Hart3edb1752013-11-14 13:28:17 -080091 }
Ray Milkey269ffb92014-04-03 14:43:30 -070092
Jonathan Hartf0a81792013-11-14 11:36:06 -080093
Jonathan Hart3edb1752013-11-14 13:28:17 -080094 @Override
95 public boolean equals(Object other) {
Ray Milkey269ffb92014-04-03 14:43:30 -070096 if (!(other instanceof SwitchPort)) {
97 return false;
98 }
Jonathan Hartf0a81792013-11-14 11:36:06 -080099
Ray Milkey269ffb92014-04-03 14:43:30 -0700100 SwitchPort otherSwitchPort = (SwitchPort) other;
Jonathan Hartf0a81792013-11-14 11:36:06 -0800101
Ray Milkey269ffb92014-04-03 14:43:30 -0700102 return (dpid.equals(otherSwitchPort.dpid) &&
103 port.equals(otherSwitchPort.port));
Jonathan Hart3edb1752013-11-14 13:28:17 -0800104 }
Jonathan Hartf0a81792013-11-14 11:36:06 -0800105
Jonathan Hart3edb1752013-11-14 13:28:17 -0800106 @Override
107 public int hashCode() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700108 int hash = 17;
109 hash += 31 * hash + dpid.hashCode();
110 hash += 31 * hash + port.hashCode();
111 return hash;
Jonathan Hart3edb1752013-11-14 13:28:17 -0800112 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -0800113}