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