blob: 31fdfcd9c135f47c44260f0bb637c4bc1b1434a2 [file] [log] [blame]
Yoonseon Hana578d762017-05-08 13:42:02 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yoonseon Hana578d762017-05-08 13:42:02 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.incubator.net.virtual;
18
19import org.onosproject.cluster.NodeId;
20import org.onosproject.cluster.RoleInfo;
21import org.onosproject.mastership.MastershipEvent;
Jordan Halterman0a2bd452018-06-13 17:24:58 -070022import org.onosproject.mastership.MastershipInfo;
Yoonseon Hana578d762017-05-08 13:42:02 -070023import org.onosproject.mastership.MastershipStoreDelegate;
24import org.onosproject.mastership.MastershipTerm;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.MastershipRole;
27
28import java.util.Set;
29import java.util.concurrent.CompletableFuture;
30
31/**
32 * Manages inventory of mastership roles for devices, across controller
33 * instances for virtual networks; not intended for direct use.
34 */
35public interface VirtualNetworkMastershipStore
36 extends VirtualStore<MastershipEvent, MastershipStoreDelegate> {
37
38 // three things to map: NodeId, DeviceId, MastershipRole
39
40 /**
41 * Requests role of the local node for the specified device.
42 *
43 * @param networkId the virtual network identifier
44 * @param deviceId the device identifier
45 * @return established or newly negotiated mastership role
46 */
47 CompletableFuture<MastershipRole> requestRole(NetworkId networkId, DeviceId deviceId);
48
49 /**
50 * Returns the role of a device for a specific controller instance.
51 *
52 * @param networkId virtual network identifier
53 * @param nodeId the instance identifier
54 * @param deviceId the device identifiers
55 * @return the role
56 */
57 MastershipRole getRole(NetworkId networkId, NodeId nodeId, DeviceId deviceId);
58
59 /**
60 * Returns the master for a device.
61 *
62 * @param networkId virtual network identifier
63 * @param deviceId the device identifier
64 * @return the instance identifier of the master
65 */
66 NodeId getMaster(NetworkId networkId, DeviceId deviceId);
67
68 /**
69 * Returns the master and backup nodes for a device.
70 *
71 * @param networkId virtual network identifier
72 * @param deviceId the device identifier
73 * @return a RoleInfo containing controller IDs
74 */
75 RoleInfo getNodes(NetworkId networkId, DeviceId deviceId);
76
77 /**
Jordan Halterman0a2bd452018-06-13 17:24:58 -070078 * Returns the mastership info for a device.
79 *
80 * @param networkId virtual network identifier
81 * @param deviceId the device identifier
82 * @return the mastership info
83 */
84 MastershipInfo getMastership(NetworkId networkId, DeviceId deviceId);
85
86 /**
Yoonseon Hana578d762017-05-08 13:42:02 -070087 * Returns the devices that a controller instance is master of.
88 *
89 * @param networkId virtual network identifier
90 * @param nodeId the instance identifier
91 * @return a set of device identifiers
92 */
93 Set<DeviceId> getDevices(NetworkId networkId, NodeId nodeId);
94
95
96 /**
97 * Sets a device's role for a specified controller instance.
98 *
99 * @param networkId virtual network identifier
100 * @param nodeId controller instance identifier
101 * @param deviceId device identifier
102 * @return a mastership event
103 */
104 CompletableFuture<MastershipEvent> setMaster(NetworkId networkId,
105 NodeId nodeId, DeviceId deviceId);
106
107 /**
108 * Returns the current master and number of past mastership hand-offs
109 * (terms) for a device.
110 *
111 * @param networkId virtual network identifier
112 * @param deviceId the device identifier
113 * @return the current master's ID and the term value for device, or null
114 */
115 MastershipTerm getTermFor(NetworkId networkId, DeviceId deviceId);
116
117 /**
118 * Sets a controller instance's mastership role to STANDBY for a device.
119 * If the role is MASTER, another controller instance will be selected
120 * as a candidate master.
121 *
122 * @param networkId virtual network identifier
123 * @param nodeId the controller instance identifier
124 * @param deviceId device to revoke mastership role for
125 * @return a mastership event
126 */
127 CompletableFuture<MastershipEvent> setStandby(NetworkId networkId,
128 NodeId nodeId, DeviceId deviceId);
129
130 /**
131 * Allows a controller instance to give up its current role for a device.
132 * If the role is MASTER, another controller instance will be selected
133 * as a candidate master.
134 *
135 * @param networkId virtual network identifier
136 * @param nodeId the controller instance identifier
137 * @param deviceId device to revoke mastership role for
138 * @return a mastership event
139 */
140 CompletableFuture<MastershipEvent> relinquishRole(NetworkId networkId,
141 NodeId nodeId, DeviceId deviceId);
142
143 /**
144 * Removes all the roles for the specified controller instance.
145 * If the role was MASTER, another controller instance will be selected
146 * as a candidate master.
147 *
148 * @param networkId virtual network identifier
149 * @param nodeId the controller instance identifier
150 */
151 void relinquishAllRole(NetworkId networkId, NodeId nodeId);
152}