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 | |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 3 | import net.onrc.onos.ofcontroller.util.Port; |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 4 | |
| 5 | import org.codehaus.jackson.annotate.JsonProperty; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 6 | |
| 7 | /** |
| 8 | * The class representing a Switch-Port. |
| 9 | */ |
| 10 | public class SwitchPort { |
| 11 | private Dpid dpid; // The DPID of the switch |
| 12 | private Port port; // The port of the switch |
| 13 | |
| 14 | /** |
| 15 | * Default constructor. |
| 16 | */ |
| 17 | public SwitchPort() { |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Constructor for a given DPID and a port. |
| 22 | * |
| 23 | * @param dpid the DPID to use. |
| 24 | * @param port the port to use. |
| 25 | */ |
| 26 | public SwitchPort(Dpid dpid, Port port) { |
| 27 | this.dpid = dpid; |
| 28 | this.port = port; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Get the DPID value of the Switch-Port. |
| 33 | * |
| 34 | * @return the DPID value of the Switch-Port. |
| 35 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 36 | @JsonProperty("dpid") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 37 | public Dpid dpid() { return dpid; } |
| 38 | |
| 39 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 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) { |
| 46 | this.dpid = dpid; |
| 47 | } |
| 48 | |
| 49 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 50 | * Get the port value of the Switch-Port. |
| 51 | * |
| 52 | * @return the port value of the Switch-Port. |
| 53 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 54 | @JsonProperty("port") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 55 | public Port port() { return port; } |
| 56 | |
| 57 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 58 | * Set the port value of the Switch-Port. |
| 59 | * |
| 60 | * @param port the port to use. |
| 61 | */ |
| 62 | @JsonProperty("port") |
| 63 | public void setPort(Port port) { |
| 64 | this.port = port; |
| 65 | } |
| 66 | |
| 67 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 68 | * Set the DPID and port values of the Switch-Port. |
| 69 | * |
| 70 | * @param dpid the DPID to use. |
| 71 | * @param port the port to use. |
| 72 | */ |
| 73 | public void setValue(Dpid dpid, Port port) { |
| 74 | this.dpid = dpid; |
| 75 | this.port = port; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Convert the Switch-Port value to a string. |
| 80 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 81 | * The string has the following form: |
| 82 | * 01:02:03:04:05:06:07:08/1234 |
| 83 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 84 | * @return the Switch-Port value as a string. |
| 85 | */ |
| 86 | @Override |
| 87 | public String toString() { |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 88 | return this.dpid.toString() + "/" + this.port; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 89 | } |
| 90 | } |