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 | import net.floodlightcontroller.util.serializers.SwitchPortSerializer; |
| 6 | |
| 7 | import org.codehaus.jackson.annotate.JsonProperty; |
| 8 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 9 | |
| 10 | /** |
| 11 | * The class representing a Switch-Port. |
| 12 | */ |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 13 | @JsonSerialize(using=SwitchPortSerializer.class) |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 14 | public class SwitchPort { |
| 15 | private Dpid dpid; // The DPID of the switch |
| 16 | private Port port; // The port of the switch |
| 17 | |
| 18 | /** |
| 19 | * Default constructor. |
| 20 | */ |
| 21 | public SwitchPort() { |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Constructor for a given DPID and a port. |
| 26 | * |
| 27 | * @param dpid the DPID to use. |
| 28 | * @param port the port to use. |
| 29 | */ |
| 30 | public SwitchPort(Dpid dpid, Port port) { |
| 31 | this.dpid = dpid; |
| 32 | this.port = port; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Get the DPID value of the Switch-Port. |
| 37 | * |
| 38 | * @return the DPID value of the Switch-Port. |
| 39 | */ |
| 40 | public Dpid dpid() { return dpid; } |
| 41 | |
| 42 | /** |
| 43 | * Get the port value of the Switch-Port. |
| 44 | * |
| 45 | * @return the port value of the Switch-Port. |
| 46 | */ |
| 47 | public Port port() { return port; } |
| 48 | |
| 49 | /** |
| 50 | * Set the DPID and port values of the Switch-Port. |
| 51 | * |
| 52 | * @param dpid the DPID to use. |
| 53 | * @param port the port to use. |
| 54 | */ |
| 55 | public void setValue(Dpid dpid, Port port) { |
| 56 | this.dpid = dpid; |
| 57 | this.port = port; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Convert the Switch-Port value to a string. |
| 62 | * |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 63 | * The string has the following form: |
| 64 | * 01:02:03:04:05:06:07:08/1234 |
| 65 | * |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 66 | * @return the Switch-Port value as a string. |
| 67 | */ |
| 68 | @Override |
| 69 | public String toString() { |
Pavlin Radoslavov | ad008e0 | 2013-02-21 18:42:42 -0800 | [diff] [blame] | 70 | return this.dpid.toString() + "/" + this.port; |
Pavlin Radoslavov | 5363c2a | 2013-02-18 09:55:42 -0800 | [diff] [blame] | 71 | } |
| 72 | } |