blob: e3c525f0bb957cb23401305f0aa411deac7a6249 [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.util;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -07002
3import org.codehaus.jackson.annotate.JsonProperty;
4
5/**
6 * The class representing a Switch.
7 * NOTE: Currently this class is (almost) not used.
8 */
9public class Switch {
Pavlin Radoslavov8a6912a2013-10-25 15:28:11 -070010 /**
11 * The Switch state.
12 */
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070013 public enum SwitchState {
14 INACTIVE,
15 ACTIVE,
16 }
17
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070018 private Dpid dpid; // The DPID of the switch
19 private SwitchState state; // The state of the switch
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070020
21 /**
22 * Default constructor.
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070023 *
24 * NOTE: The default state for the switch is INACTIVE.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070025 */
26 public Switch() {
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070027 this.dpid = new Dpid();
28 this.state = SwitchState.INACTIVE;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070029 }
30
31 /**
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070032 * Constructor for a given DPID.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070033 *
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070034 * NOTE: The state for the switch with a given DPID is ACTIVE.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070035 *
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070036 * @param dpid the DPID to use.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070037 */
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070038 public Switch(Dpid dpid) {
39 this.dpid = dpid;
40 this.state = SwitchState.ACTIVE;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070041 }
42
43 /**
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070044 * Constructor for a given DPID and Switch State.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070045 *
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070046 * @param dpid the DPID to use.
47 * @param state the Switch State to use.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070048 */
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070049 public Switch(Dpid dpid, SwitchState state) {
50 this.dpid = dpid;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070051 this.state = state;
52 }
53
54 /**
55 * Get the DPID.
56 *
57 * @return the DPID.
58 */
59 @JsonProperty("dpid")
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070060 public Dpid dpid() { return dpid; }
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070061
62 /**
63 * Set the DPID.
64 *
65 * @param dpid the DPID to use.
66 */
67 @JsonProperty("dpid")
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070068 public void setDpid(Dpid dpid) {
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070069 this.dpid = dpid;
70 }
71
72 /**
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070073 * Get the state.
74 *
75 * @return the state.
76 */
77 @JsonProperty("state")
78 public SwitchState state() { return state; }
79
80 /**
81 * Set the state.
82 *
83 * @param state the state to use.
84 */
85 @JsonProperty("state")
86 public void setState(SwitchState state) {
87 this.state = state;
88 }
89
90 /**
91 * Set the Switch State to ACTIVE.
92 */
93 public void setStateActive() {
94 this.state = SwitchState.ACTIVE;
95 }
96
97 /**
98 * Set the Switch State to INACTIVE.
99 */
100 public void setStateInactive() {
101 this.state = SwitchState.INACTIVE;
102 }
103
104 /**
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700105 * Convert the Switch value to a string.
106 *
107 * The string has the following form:
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -0700108 * dpid/state
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700109 *
110 * @return the Switch value as a string.
111 */
112 @Override
113 public String toString() {
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -0700114 return this.dpid.toString() + "/" + this.state.toString();
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700115 }
116}