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 { |
| 9 | private Dpid dpid; // The DPID of the switch |
| 10 | private Port port; // The port of the switch |
| 11 | |
| 12 | /** |
| 13 | * Default constructor. |
| 14 | */ |
| 15 | public SwitchPort() { |
| 16 | } |
| 17 | |
| 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 | } |
| 28 | |
| 29 | /** |
| 30 | * Get the DPID value of the Switch-Port. |
| 31 | * |
| 32 | * @return the DPID value of the Switch-Port. |
| 33 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 34 | @JsonProperty("dpid") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 35 | public Dpid dpid() { return dpid; } |
| 36 | |
| 37 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 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 | } |
| 46 | |
| 47 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 48 | * Get the port value of the Switch-Port. |
| 49 | * |
| 50 | * @return the port value of the Switch-Port. |
| 51 | */ |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 52 | @JsonProperty("port") |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 53 | public Port port() { return port; } |
| 54 | |
| 55 | /** |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 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 | } |
| 64 | |
| 65 | /** |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 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 | } |
| 75 | |
| 76 | /** |
| 77 | * Convert the Switch-Port value to a string. |
| 78 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 79 | * The string has the following form: |
| 80 | * 01:02:03:04:05:06:07:08/1234 |
| 81 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 82 | * @return the Switch-Port value as a string. |
| 83 | */ |
| 84 | @Override |
| 85 | public String toString() { |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 86 | return this.dpid.toString() + "/" + this.port; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 87 | } |
| 88 | } |