blob: bd7a35435b659a88399f261116bba85dce4a7aa6 [file] [log] [blame]
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07001package org.onlab.onos.mastership;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -07002
3import java.util.Set;
4
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07005import org.onlab.onos.cluster.NodeId;
Ayaka Koshibeabedb092014-10-20 17:01:31 -07006import org.onlab.onos.cluster.RoleInfo;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -07007import org.onlab.onos.net.DeviceId;
8import org.onlab.onos.net.MastershipRole;
tomf80c9722014-09-24 14:49:18 -07009import org.onlab.onos.store.Store;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070010
11/**
tome4729872014-09-23 00:37:37 -070012 * Manages inventory of mastership roles for devices, across controller
13 * instances; not intended for direct use.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070014 */
tomf80c9722014-09-24 14:49:18 -070015public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> {
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070016
tome4729872014-09-23 00:37:37 -070017 // three things to map: NodeId, DeviceId, MastershipRole
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070018
19 /**
tomb41d1ac2014-09-24 01:51:24 -070020 * Requests role of the local node for the specified device.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070021 *
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070022 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070023 * @return established or newly negotiated mastership role
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070024 */
tomb41d1ac2014-09-24 01:51:24 -070025 MastershipRole requestRole(DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070026
27 /**
tomb41d1ac2014-09-24 01:51:24 -070028 * Returns the role of a device for a specific controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070029 *
tomb41d1ac2014-09-24 01:51:24 -070030 * @param nodeId the instance identifier
31 * @param deviceId the device identifiers
32 * @return the role
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070033 */
tomb41d1ac2014-09-24 01:51:24 -070034 MastershipRole getRole(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070035
36 /**
37 * Returns the master for a device.
38 *
39 * @param deviceId the device identifier
40 * @return the instance identifier of the master
41 */
tome4729872014-09-23 00:37:37 -070042 NodeId getMaster(DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070043
44 /**
Ayaka Koshibeabedb092014-10-20 17:01:31 -070045 * Returns the master and backup nodes for a device.
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070046 *
47 * @param deviceId the device identifier
Ayaka Koshibeabedb092014-10-20 17:01:31 -070048 * @return a RoleInfo containing controller IDs
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070049 */
Ayaka Koshibeabedb092014-10-20 17:01:31 -070050 RoleInfo getNodes(DeviceId deviceId);
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070051
52 /**
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070053 * Returns the devices that a controller instance is master of.
54 *
tome4729872014-09-23 00:37:37 -070055 * @param nodeId the instance identifier
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070056 * @return a set of device identifiers
57 */
tome4729872014-09-23 00:37:37 -070058 Set<DeviceId> getDevices(NodeId nodeId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070059
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070060
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070061 /**
tomb41d1ac2014-09-24 01:51:24 -070062 * Sets a device's role for a specified controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070063 *
tomb41d1ac2014-09-24 01:51:24 -070064 * @param nodeId controller instance identifier
65 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070066 * @return a mastership event
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070067 */
Ayaka Koshibe406d0102014-09-24 16:08:12 -070068 MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070069
70 /**
71 * Returns the current master and number of past mastership hand-offs
72 * (terms) for a device.
73 *
74 * @param deviceId the device identifier
75 * @return the current master's ID and the term value for device, or null
76 */
77 MastershipTerm getTermFor(DeviceId deviceId);
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070078
79 /**
Ayaka Koshibec4047702014-10-07 14:43:52 -070080 * Sets a controller instance's mastership role to STANDBY for a device.
81 * If the role is MASTER, another controller instance will be selected
82 * as a candidate master.
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070083 *
84 * @param nodeId the controller instance identifier
Ayaka Koshibec4047702014-10-07 14:43:52 -070085 * @param deviceId device to revoke mastership role for
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070086 * @return a mastership event
87 */
Ayaka Koshibec4047702014-10-07 14:43:52 -070088 MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
89
90 /**
91 * Allows a controller instance to give up its current role for a device.
92 * If the role is MASTER, another controller instance will be selected
93 * as a candidate master.
94 *
95 * @param nodeId the controller instance identifier
96 * @param deviceId device to revoke mastership role for
97 * @return a mastership event
98 */
99 MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
100
Ayaka Koshibe8d504a92014-09-22 17:07:36 -0700101}