blob: c989732ca7aa81afde4ba803c26b194754514117 [file] [log] [blame]
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -07001package net.onrc.onos.ofcontroller.util;
2
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 {
10 public enum SwitchState {
11 INACTIVE,
12 ACTIVE,
13 }
14
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070015 private Dpid dpid; // The DPID of the switch
16 private SwitchState state; // The state of the switch
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070017
18 /**
19 * Default constructor.
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070020 *
21 * NOTE: The default state for the switch is INACTIVE.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070022 */
23 public Switch() {
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070024 this.dpid = new Dpid();
25 this.state = SwitchState.INACTIVE;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070026 }
27
28 /**
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070029 * Constructor for a given DPID.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070030 *
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070031 * NOTE: The state for the switch with a given DPID is ACTIVE.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070032 *
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070033 * @param dpid the DPID to use.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070034 */
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070035 public Switch(Dpid dpid) {
36 this.dpid = dpid;
37 this.state = SwitchState.ACTIVE;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070038 }
39
40 /**
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070041 * Constructor for a given DPID and Switch State.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070042 *
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070043 * @param dpid the DPID to use.
44 * @param state the Switch State to use.
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070045 */
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070046 public Switch(Dpid dpid, SwitchState state) {
47 this.dpid = dpid;
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070048 this.state = state;
49 }
50
51 /**
52 * Get the DPID.
53 *
54 * @return the DPID.
55 */
56 @JsonProperty("dpid")
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070057 public Dpid dpid() { return dpid; }
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070058
59 /**
60 * Set the DPID.
61 *
62 * @param dpid the DPID to use.
63 */
64 @JsonProperty("dpid")
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070065 public void setDpid(Dpid dpid) {
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -070066 this.dpid = dpid;
67 }
68
69 /**
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -070070 * Get the state.
71 *
72 * @return the state.
73 */
74 @JsonProperty("state")
75 public SwitchState state() { return state; }
76
77 /**
78 * Set the state.
79 *
80 * @param state the state to use.
81 */
82 @JsonProperty("state")
83 public void setState(SwitchState state) {
84 this.state = state;
85 }
86
87 /**
88 * Set the Switch State to ACTIVE.
89 */
90 public void setStateActive() {
91 this.state = SwitchState.ACTIVE;
92 }
93
94 /**
95 * Set the Switch State to INACTIVE.
96 */
97 public void setStateInactive() {
98 this.state = SwitchState.INACTIVE;
99 }
100
101 /**
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700102 * Convert the Switch value to a string.
103 *
104 * The string has the following form:
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -0700105 * dpid/state
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700106 *
107 * @return the Switch value as a string.
108 */
109 @Override
110 public String toString() {
Pavlin Radoslavovffc5bbc2013-10-17 18:23:20 -0700111 return this.dpid.toString() + "/" + this.state.toString();
Pavlin Radoslavova2d35f12013-10-17 16:46:39 -0700112 }
113}