blob: 5e7b0e4932220dec065e2e41ee5461779a98c3fb [file] [log] [blame]
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07001package org.onlab.onos.mastership;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -07002
Ayaka Koshibe45503ce2014-10-14 11:26:45 -07003import java.util.List;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -07004import java.util.Set;
5
Yuta HIGUCHI80912e62014-10-12 00:15:47 -07006import org.onlab.onos.cluster.NodeId;
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 Koshibe45503ce2014-10-14 11:26:45 -070045 * Returns the controllers connected to a device, in mastership-
46 * preference order.
47 *
48 * @param deviceId the device identifier
49 * @return an ordered list of controller IDs
50 */
51 List<NodeId> getNodes(DeviceId deviceId);
52
53 /**
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070054 * Returns the devices that a controller instance is master of.
55 *
tome4729872014-09-23 00:37:37 -070056 * @param nodeId the instance identifier
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070057 * @return a set of device identifiers
58 */
tome4729872014-09-23 00:37:37 -070059 Set<DeviceId> getDevices(NodeId nodeId);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070060
Ayaka Koshibe45503ce2014-10-14 11:26:45 -070061
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070062 /**
tomb41d1ac2014-09-24 01:51:24 -070063 * Sets a device's role for a specified controller instance.
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070064 *
tomb41d1ac2014-09-24 01:51:24 -070065 * @param nodeId controller instance identifier
66 * @param deviceId device identifier
tomb41d1ac2014-09-24 01:51:24 -070067 * @return a mastership event
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070068 */
Ayaka Koshibe406d0102014-09-24 16:08:12 -070069 MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
Ayaka Koshibeb70d34b2014-09-25 15:43:01 -070070
71 /**
72 * Returns the current master and number of past mastership hand-offs
73 * (terms) for a device.
74 *
75 * @param deviceId the device identifier
76 * @return the current master's ID and the term value for device, or null
77 */
78 MastershipTerm getTermFor(DeviceId deviceId);
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070079
80 /**
Ayaka Koshibec4047702014-10-07 14:43:52 -070081 * Sets a controller instance's mastership role to STANDBY for a device.
82 * If the role is MASTER, another controller instance will be selected
83 * as a candidate master.
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070084 *
85 * @param nodeId the controller instance identifier
Ayaka Koshibec4047702014-10-07 14:43:52 -070086 * @param deviceId device to revoke mastership role for
Ayaka Koshibed9f693e2014-09-29 18:04:54 -070087 * @return a mastership event
88 */
Ayaka Koshibec4047702014-10-07 14:43:52 -070089 MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
90
91 /**
92 * Allows a controller instance to give up its current role for a device.
93 * If the role is MASTER, another controller instance will be selected
94 * as a candidate master.
95 *
96 * @param nodeId the controller instance identifier
97 * @param deviceId device to revoke mastership role for
98 * @return a mastership event
99 */
100 MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
101
Ayaka Koshibe8d504a92014-09-22 17:07:36 -0700102}