Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.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. | ||||
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 7 | * This class is immutable. |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 8 | */ |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 9 | public final class SwitchPort { |
10 | private final Dpid dpid; // The DPID of the switch | ||||
11 | private final Port port; // The port of the switch | ||||
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 12 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 13 | /** |
14 | * Default constructor. | ||||
15 | */ | ||||
16 | public SwitchPort() { | ||||
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 17 | this.dpid = null; |
18 | this.port = null; | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 19 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 20 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 21 | /** |
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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 28 | this.dpid = dpid; |
29 | this.port = port; | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 30 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 31 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 32 | /** |
33 | * Get the DPID value of the Switch-Port. | ||||
34 | * | ||||
35 | * @return the DPID value of the Switch-Port. | ||||
36 | */ | ||||
37 | @JsonProperty("dpid") | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 38 | public Dpid dpid() { |
39 | return dpid; | ||||
40 | } | ||||
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 41 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 42 | /** |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 43 | * Get the port value of the Switch-Port. |
44 | * | ||||
45 | * @return the port value of the Switch-Port. | ||||
46 | */ | ||||
47 | @JsonProperty("port") | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 48 | public Port port() { |
49 | return port; | ||||
50 | } | ||||
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 51 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 52 | /** |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 53 | * Convert the Switch-Port value to a string. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 54 | * <p/> |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 55 | * The string has the following form: |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 56 | * 01:02:03:04:05:06:07:08/1234 |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 57 | * |
58 | * @return the Switch-Port value as a string. | ||||
59 | */ | ||||
60 | @Override | ||||
61 | public String toString() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 62 | return this.dpid.toString() + "/" + this.port; |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 63 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 64 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 65 | @Override |
66 | public boolean equals(Object other) { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 67 | if (!(other instanceof SwitchPort)) { |
68 | return false; | ||||
69 | } | ||||
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 70 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 71 | SwitchPort otherSwitchPort = (SwitchPort) other; |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 72 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 73 | return (dpid.equals(otherSwitchPort.dpid) && |
74 | port.equals(otherSwitchPort.port)); | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 75 | } |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 76 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 77 | @Override |
78 | public int hashCode() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 79 | int hash = 17; |
80 | hash += 31 * hash + dpid.hashCode(); | ||||
81 | hash += 31 * hash + port.hashCode(); | ||||
82 | return hash; | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 83 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 84 | } |