Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.util; |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 2 | |
| 3 | import org.codehaus.jackson.annotate.JsonProperty; |
| 4 | |
| 5 | /** |
| 6 | * The class representing a Switch. |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 7 | * This class is almost immutable: the switch state is mutable. |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 8 | * NOTE: Currently this class is (almost) not used. |
| 9 | */ |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 10 | public final class Switch { |
Pavlin Radoslavov | 8a6912a | 2013-10-25 15:28:11 -0700 | [diff] [blame] | 11 | /** |
| 12 | * The Switch state. |
| 13 | */ |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 14 | public enum SwitchState { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 15 | INACTIVE, |
| 16 | ACTIVE, |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 17 | } |
| 18 | |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 19 | private final Dpid dpid; // The DPID of the switch |
| 20 | private SwitchState state; // The state of the switch |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Default constructor. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 24 | * <p/> |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 25 | * NOTE: The default state for the switch is INACTIVE. |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 26 | */ |
| 27 | public Switch() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 28 | this.dpid = new Dpid(); |
| 29 | this.state = SwitchState.INACTIVE; |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | /** |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 33 | * Constructor for a given DPID. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | * <p/> |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 35 | * NOTE: The state for the switch with a given DPID is ACTIVE. |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 36 | * |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 37 | * @param dpid the DPID to use. |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 38 | */ |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 39 | public Switch(Dpid dpid) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 40 | this.dpid = dpid; |
| 41 | this.state = SwitchState.ACTIVE; |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 45 | * Constructor for a given DPID and Switch State. |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 46 | * |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 47 | * @param dpid the DPID to use. |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 48 | * @param state the Switch State to use. |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 49 | */ |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 50 | public Switch(Dpid dpid, SwitchState state) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 51 | this.dpid = dpid; |
| 52 | this.state = state; |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get the DPID. |
| 57 | * |
| 58 | * @return the DPID. |
| 59 | */ |
| 60 | @JsonProperty("dpid") |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 61 | public Dpid dpid() { |
| 62 | return dpid; |
| 63 | } |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 66 | * Get the state. |
| 67 | * |
| 68 | * @return the state. |
| 69 | */ |
| 70 | @JsonProperty("state") |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 71 | public SwitchState state() { |
| 72 | return state; |
| 73 | } |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Set the state. |
| 77 | * |
| 78 | * @param state the state to use. |
| 79 | */ |
| 80 | @JsonProperty("state") |
| 81 | public void setState(SwitchState state) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 82 | this.state = state; |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Set the Switch State to ACTIVE. |
| 87 | */ |
| 88 | public void setStateActive() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 89 | this.state = SwitchState.ACTIVE; |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Set the Switch State to INACTIVE. |
| 94 | */ |
| 95 | public void setStateInactive() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 96 | this.state = SwitchState.INACTIVE; |
Pavlin Radoslavov | ffc5bbc | 2013-10-17 18:23:20 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 100 | * Convert the Switch value to a string. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 101 | * <p/> |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 102 | * The string has the following form: |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 103 | * dpid/state |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 104 | * |
| 105 | * @return the Switch value as a string. |
| 106 | */ |
| 107 | @Override |
| 108 | public String toString() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 109 | return this.dpid.toString() + "/" + this.state.toString(); |
Pavlin Radoslavov | a2d35f1 | 2013-10-17 16:46:39 -0700 | [diff] [blame] | 110 | } |
| 111 | } |