blob: 8ea1184a1d41d134d8e5692ddd8a6eda02f25efa [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.
Pavlin Radoslavov29a2a882014-04-08 17:40:54 -07007 * This class is almost immutable: the switch state is mutable.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -07008 * NOTE: Currently this class is (almost) not used.
9 */
Pavlin Radoslavov29a2a882014-04-08 17:40:54 -070010public final class Switch {
Pavlin Radoslavov8a6912a2013-10-25 15:28:11 -070011 /**
12 * The Switch state.
13 */
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070014 public enum SwitchState {
Ray Milkey269ffb92014-04-03 14:43:30 -070015 INACTIVE,
16 ACTIVE,
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070017 }
18
Pavlin Radoslavov29a2a882014-04-08 17:40:54 -070019 private final Dpid dpid; // The DPID of the switch
20 private SwitchState state; // The state of the switch
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070021
22 /**
23 * Default constructor.
Ray Milkey269ffb92014-04-03 14:43:30 -070024 * <p/>
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070025 * NOTE: The default state for the switch is INACTIVE.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070026 */
27 public Switch() {
Ray Milkey269ffb92014-04-03 14:43:30 -070028 this.dpid = new Dpid();
29 this.state = SwitchState.INACTIVE;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070030 }
31
32 /**
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070033 * Constructor for a given DPID.
Ray Milkey269ffb92014-04-03 14:43:30 -070034 * <p/>
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070035 * NOTE: The state for the switch with a given DPID is ACTIVE.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070036 *
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070037 * @param dpid the DPID to use.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070038 */
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070039 public Switch(Dpid dpid) {
Ray Milkey269ffb92014-04-03 14:43:30 -070040 this.dpid = dpid;
41 this.state = SwitchState.ACTIVE;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070042 }
43
44 /**
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070045 * Constructor for a given DPID and Switch State.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070046 *
Ray Milkey269ffb92014-04-03 14:43:30 -070047 * @param dpid the DPID to use.
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070048 * @param state the Switch State to use.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070049 */
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070050 public Switch(Dpid dpid, SwitchState state) {
Ray Milkey269ffb92014-04-03 14:43:30 -070051 this.dpid = dpid;
52 this.state = state;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070053 }
54
55 /**
56 * Get the DPID.
57 *
58 * @return the DPID.
59 */
60 @JsonProperty("dpid")
Ray Milkey269ffb92014-04-03 14:43:30 -070061 public Dpid dpid() {
62 return dpid;
63 }
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070064
65 /**
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070066 * Get the state.
67 *
68 * @return the state.
69 */
70 @JsonProperty("state")
Ray Milkey269ffb92014-04-03 14:43:30 -070071 public SwitchState state() {
72 return state;
73 }
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070074
75 /**
76 * Set the state.
77 *
78 * @param state the state to use.
79 */
80 @JsonProperty("state")
81 public void setState(SwitchState state) {
Ray Milkey269ffb92014-04-03 14:43:30 -070082 this.state = state;
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070083 }
84
85 /**
86 * Set the Switch State to ACTIVE.
87 */
88 public void setStateActive() {
Ray Milkey269ffb92014-04-03 14:43:30 -070089 this.state = SwitchState.ACTIVE;
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070090 }
91
92 /**
93 * Set the Switch State to INACTIVE.
94 */
95 public void setStateInactive() {
Ray Milkey269ffb92014-04-03 14:43:30 -070096 this.state = SwitchState.INACTIVE;
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070097 }
98
99 /**
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700100 * Convert the Switch value to a string.
Ray Milkey269ffb92014-04-03 14:43:30 -0700101 * <p/>
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700102 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -0700103 * dpid/state
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700104 *
105 * @return the Switch value as a string.
106 */
107 @Override
108 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700109 return this.dpid.toString() + "/" + this.state.toString();
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700110 }
111}