blob: 0117d0d06ec842ad551084132e8666548c2ecfea [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 Koshibe8d504a92014-09-22 17:07:36 -07006import org.onlab.onos.net.DeviceId;
7import org.onlab.onos.net.MastershipRole;
tomf80c9722014-09-24 14:49:18 -07008import org.onlab.onos.store.Store;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -07009
10/**
tome4729872014-09-23 00:37:37 -070011 * Manages inventory of mastership roles for devices, across controller
12 * instances; not intended for direct use.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070013 */
tomf80c9722014-09-24 14:49:18 -070014public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> {
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070015
tome4729872014-09-23 00:37:37 -070016 // three things to map: NodeId, DeviceId, MastershipRole
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070017
18 /**
tomb41d1ac2014-09-24 01:51:24 -070019 * Requests role of the local node for the specified device.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070020 *
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070021 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070022 * @return established or newly negotiated mastership role
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070023 */
tomb41d1ac2014-09-24 01:51:24 -070024 MastershipRole requestRole(DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070025
26 /**
tomb41d1ac2014-09-24 01:51:24 -070027 * Returns the role of a device for a specific controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070028 *
tomb41d1ac2014-09-24 01:51:24 -070029 * @param nodeId the instance identifier
30 * @param deviceId the device identifiers
31 * @return the role
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070032 */
tomb41d1ac2014-09-24 01:51:24 -070033 MastershipRole getRole(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070034
35 /**
36 * Returns the master for a device.
37 *
38 * @param deviceId the device identifier
39 * @return the instance identifier of the master
40 */
tome4729872014-09-23 00:37:37 -070041 NodeId getMaster(DeviceId deviceId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070042
43 /**
44 * Returns the devices that a controller instance is master of.
45 *
tome4729872014-09-23 00:37:37 -070046 * @param nodeId the instance identifier
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070047 * @return a set of device identifiers
48 */
tome4729872014-09-23 00:37:37 -070049 Set<DeviceId> getDevices(NodeId nodeId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070050
51 /**
tomb41d1ac2014-09-24 01:51:24 -070052 * Sets a device's role for a specified controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070053 *
tomb41d1ac2014-09-24 01:51:24 -070054 * @param nodeId controller instance identifier
55 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070056 * @return a mastership event
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070057 */
Ayaka Koshibe406d0102014-09-24 16:08:12 -070058 MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070059
60 /**
61 * Returns the current master and number of past mastership hand-offs
62 * (terms) for a device.
63 *
64 * @param deviceId the device identifier
65 * @return the current master's ID and the term value for device, or null
66 */
67 MastershipTerm getTermFor(DeviceId deviceId);
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070068
69 /**
Ayaka Koshibec4047702014-10-07 14:43:52 -070070 * Sets a controller instance's mastership role to STANDBY for a device.
71 * If the role is MASTER, another controller instance will be selected
72 * as a candidate master.
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070073 *
74 * @param nodeId the controller instance identifier
Ayaka Koshibec4047702014-10-07 14:43:52 -070075 * @param deviceId device to revoke mastership role for
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070076 * @return a mastership event
77 */
Ayaka Koshibec4047702014-10-07 14:43:52 -070078 MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
79
80 /**
81 * Allows a controller instance to give up its current role for a device.
82 * If the role is MASTER, another controller instance will be selected
83 * as a candidate master.
84 *
85 * @param nodeId the controller instance identifier
86 * @param deviceId device to revoke mastership role for
87 * @return a mastership event
88 */
89 MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
90
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070091}