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. | ||||
7 | */ | ||||
8 | public class SwitchPort { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [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) { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 25 | this.dpid = dpid; |
26 | this.port = port; | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 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") | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | public Dpid dpid() { |
36 | return dpid; | ||||
37 | } | ||||
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 38 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 39 | /** |
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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 46 | this.dpid = dpid; |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 47 | } |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 48 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 49 | /** |
50 | * Get the port value of the Switch-Port. | ||||
51 | * | ||||
52 | * @return the port value of the Switch-Port. | ||||
53 | */ | ||||
54 | @JsonProperty("port") | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 55 | public Port port() { |
56 | return port; | ||||
57 | } | ||||
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 58 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 59 | /** |
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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 66 | this.port = port; |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 67 | } |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 68 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 69 | /** |
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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 76 | this.dpid = dpid; |
77 | this.port = port; | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 78 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 79 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 80 | /** |
81 | * Convert the Switch-Port value to a string. | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 82 | * <p/> |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 83 | * The string has the following form: |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 84 | * 01:02:03:04:05:06:07:08/1234 |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 85 | * |
86 | * @return the Switch-Port value as a string. | ||||
87 | */ | ||||
88 | @Override | ||||
89 | public String toString() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 90 | return this.dpid.toString() + "/" + this.port; |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 91 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 92 | |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 93 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 94 | @Override |
95 | public boolean equals(Object other) { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 96 | if (!(other instanceof SwitchPort)) { |
97 | return false; | ||||
98 | } | ||||
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 99 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 100 | SwitchPort otherSwitchPort = (SwitchPort) other; |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 101 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 102 | return (dpid.equals(otherSwitchPort.dpid) && |
103 | port.equals(otherSwitchPort.port)); | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 104 | } |
Jonathan Hart | f0a8179 | 2013-11-14 11:36:06 -0800 | [diff] [blame] | 105 | |
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 106 | @Override |
107 | public int hashCode() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 108 | int hash = 17; |
109 | hash += 31 * hash + dpid.hashCode(); | ||||
110 | hash += 31 * hash + port.hashCode(); | ||||
111 | return hash; | ||||
Jonathan Hart | 3edb175 | 2013-11-14 13:28:17 -0800 | [diff] [blame] | 112 | } |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 113 | } |