blob: d1a463cf9905c15df200749d1af2f4e6a088ccd2 [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 {
Ray Milkey269ffb92014-04-03 14:43:30 -070014 INACTIVE,
15 ACTIVE,
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070016 }
17
Ray Milkey269ffb92014-04-03 14:43:30 -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.
Ray Milkey269ffb92014-04-03 14:43:30 -070023 * <p/>
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070024 * NOTE: The default state for the switch is INACTIVE.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070025 */
26 public Switch() {
Ray Milkey269ffb92014-04-03 14:43:30 -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.
Ray Milkey269ffb92014-04-03 14:43:30 -070033 * <p/>
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) {
Ray Milkey269ffb92014-04-03 14:43:30 -070039 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 *
Ray Milkey269ffb92014-04-03 14:43:30 -070046 * @param dpid the DPID to use.
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070047 * @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) {
Ray Milkey269ffb92014-04-03 14:43:30 -070050 this.dpid = dpid;
51 this.state = state;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070052 }
53
54 /**
55 * Get the DPID.
56 *
57 * @return the DPID.
58 */
59 @JsonProperty("dpid")
Ray Milkey269ffb92014-04-03 14:43:30 -070060 public Dpid dpid() {
61 return dpid;
62 }
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070063
64 /**
65 * Set the DPID.
66 *
67 * @param dpid the DPID to use.
68 */
69 @JsonProperty("dpid")
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070070 public void setDpid(Dpid dpid) {
Ray Milkey269ffb92014-04-03 14:43:30 -070071 this.dpid = dpid;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070072 }
73
74 /**
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070075 * Get the state.
76 *
77 * @return the state.
78 */
79 @JsonProperty("state")
Ray Milkey269ffb92014-04-03 14:43:30 -070080 public SwitchState state() {
81 return state;
82 }
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070083
84 /**
85 * Set the state.
86 *
87 * @param state the state to use.
88 */
89 @JsonProperty("state")
90 public void setState(SwitchState state) {
Ray Milkey269ffb92014-04-03 14:43:30 -070091 this.state = state;
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070092 }
93
94 /**
95 * Set the Switch State to ACTIVE.
96 */
97 public void setStateActive() {
Ray Milkey269ffb92014-04-03 14:43:30 -070098 this.state = SwitchState.ACTIVE;
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070099 }
100
101 /**
102 * Set the Switch State to INACTIVE.
103 */
104 public void setStateInactive() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700105 this.state = SwitchState.INACTIVE;
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -0700106 }
107
108 /**
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700109 * Convert the Switch value to a string.
Ray Milkey269ffb92014-04-03 14:43:30 -0700110 * <p/>
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700111 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -0700112 * dpid/state
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700113 *
114 * @return the Switch value as a string.
115 */
116 @Override
117 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700118 return this.dpid.toString() + "/" + this.state.toString();
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700119 }
120}