HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.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 | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 4 | |
| 5 | /** |
| 6 | * The class representing a Switch-Port. |
| 7 | */ |
| 8 | public class SwitchPort { |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 9 | private Dpid dpid; // The DPID of the switch |
| 10 | private Port port; // The port of the switch |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 11 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 12 | /** |
| 13 | * Default constructor. |
| 14 | */ |
| 15 | public SwitchPort() { |
| 16 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 17 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 18 | /** |
| 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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 28 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 29 | /** |
| 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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 36 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 37 | /** |
| 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 46 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 47 | /** |
| 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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 54 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 55 | /** |
| 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 Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 64 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 65 | /** |
| 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 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 | * 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 Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 89 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 90 | @Override |
| 91 | public boolean equals(Object other) { |
| 92 | if (!(other instanceof SwitchPort)) { |
| 93 | return false; |
| 94 | } |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 95 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 96 | SwitchPort otherSwitchPort = (SwitchPort) other; |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 97 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 98 | return (dpid.equals(otherSwitchPort.dpid) && |
| 99 | port.equals(otherSwitchPort.port)); |
| 100 | } |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 101 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 102 | @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 Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 109 | } |