blob: 9178267e88592e6fe8e120bf7bbb3b9edbd87b73 [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.
Pavlin Radoslavov29a2a882014-04-08 17:40:54 -07007 * This class is immutable.
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -08008 */
Pavlin Radoslavov29a2a882014-04-08 17:40:54 -07009public final class SwitchPort {
10 private final Dpid dpid; // The DPID of the switch
11 private final Port port; // The port of the switch
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080012
Jonathan Hart3edb1752013-11-14 13:28:17 -080013 /**
14 * Default constructor.
15 */
16 public SwitchPort() {
Pavlin Radoslavov29a2a882014-04-08 17:40:54 -070017 this.dpid = null;
18 this.port = null;
Jonathan Hart3edb1752013-11-14 13:28:17 -080019 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080020
Jonathan Hart3edb1752013-11-14 13:28:17 -080021 /**
22 * Constructor for a given DPID and a port.
23 *
24 * @param dpid the DPID to use.
25 * @param port the port to use.
26 */
27 public SwitchPort(Dpid dpid, Port port) {
Ray Milkey269ffb92014-04-03 14:43:30 -070028 this.dpid = dpid;
29 this.port = port;
Jonathan Hart3edb1752013-11-14 13:28:17 -080030 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080031
Jonathan Hart3edb1752013-11-14 13:28:17 -080032 /**
33 * Get the DPID value of the Switch-Port.
34 *
35 * @return the DPID value of the Switch-Port.
36 */
37 @JsonProperty("dpid")
Ray Milkey269ffb92014-04-03 14:43:30 -070038 public Dpid dpid() {
39 return dpid;
40 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080041
Jonathan Hart3edb1752013-11-14 13:28:17 -080042 /**
Jonathan Hart3edb1752013-11-14 13:28:17 -080043 * Get the port value of the Switch-Port.
44 *
45 * @return the port value of the Switch-Port.
46 */
47 @JsonProperty("port")
Ray Milkey269ffb92014-04-03 14:43:30 -070048 public Port port() {
49 return port;
50 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080051
Jonathan Hart3edb1752013-11-14 13:28:17 -080052 /**
Jonathan Hart3edb1752013-11-14 13:28:17 -080053 * Convert the Switch-Port value to a string.
Ray Milkey269ffb92014-04-03 14:43:30 -070054 * <p/>
Jonathan Hart3edb1752013-11-14 13:28:17 -080055 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -070056 * 01:02:03:04:05:06:07:08/1234
Jonathan Hart3edb1752013-11-14 13:28:17 -080057 *
58 * @return the Switch-Port value as a string.
59 */
60 @Override
61 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -070062 return this.dpid.toString() + "/" + this.port;
Jonathan Hart3edb1752013-11-14 13:28:17 -080063 }
Ray Milkey269ffb92014-04-03 14:43:30 -070064
Jonathan Hart3edb1752013-11-14 13:28:17 -080065 @Override
66 public boolean equals(Object other) {
Ray Milkey269ffb92014-04-03 14:43:30 -070067 if (!(other instanceof SwitchPort)) {
68 return false;
69 }
Jonathan Hartf0a81792013-11-14 11:36:06 -080070
Ray Milkey269ffb92014-04-03 14:43:30 -070071 SwitchPort otherSwitchPort = (SwitchPort) other;
Jonathan Hartf0a81792013-11-14 11:36:06 -080072
Ray Milkey269ffb92014-04-03 14:43:30 -070073 return (dpid.equals(otherSwitchPort.dpid) &&
74 port.equals(otherSwitchPort.port));
Jonathan Hart3edb1752013-11-14 13:28:17 -080075 }
Jonathan Hartf0a81792013-11-14 11:36:06 -080076
Jonathan Hart3edb1752013-11-14 13:28:17 -080077 @Override
78 public int hashCode() {
Ray Milkey269ffb92014-04-03 14:43:30 -070079 int hash = 17;
80 hash += 31 * hash + dpid.hashCode();
81 hash += 31 * hash + port.hashCode();
82 return hash;
Jonathan Hart3edb1752013-11-14 13:28:17 -080083 }
Pavlin Radoslavov5363c2a2013-02-18 09:55:42 -080084}