blob: 136f09e48efde5836da22867c4d921eaffe08a04 [file] [log] [blame]
Yoonseon Hana578d762017-05-08 13:42:02 -07001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
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;
22import org.onosproject.mastership.MastershipStoreDelegate;
23import org.onosproject.mastership.MastershipTerm;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.MastershipRole;
26
27import java.util.Set;
28import java.util.concurrent.CompletableFuture;
29
30/**
31 * Manages inventory of mastership roles for devices, across controller
32 * instances for virtual networks; not intended for direct use.
33 */
34public interface VirtualNetworkMastershipStore
35 extends VirtualStore<MastershipEvent, MastershipStoreDelegate> {
36
37 // three things to map: NodeId, DeviceId, MastershipRole
38
39 /**
40 * Requests role of the local node for the specified device.
41 *
42 * @param networkId the virtual network identifier
43 * @param deviceId the device identifier
44 * @return established or newly negotiated mastership role
45 */
46 CompletableFuture<MastershipRole> requestRole(NetworkId networkId, DeviceId deviceId);
47
48 /**
49 * Returns the role of a device for a specific controller instance.
50 *
51 * @param networkId virtual network identifier
52 * @param nodeId the instance identifier
53 * @param deviceId the device identifiers
54 * @return the role
55 */
56 MastershipRole getRole(NetworkId networkId, NodeId nodeId, DeviceId deviceId);
57
58 /**
59 * Returns the master for a device.
60 *
61 * @param networkId virtual network identifier
62 * @param deviceId the device identifier
63 * @return the instance identifier of the master
64 */
65 NodeId getMaster(NetworkId networkId, DeviceId deviceId);
66
67 /**
68 * Returns the master and backup nodes for a device.
69 *
70 * @param networkId virtual network identifier
71 * @param deviceId the device identifier
72 * @return a RoleInfo containing controller IDs
73 */
74 RoleInfo getNodes(NetworkId networkId, DeviceId deviceId);
75
76 /**
77 * Returns the devices that a controller instance is master of.
78 *
79 * @param networkId virtual network identifier
80 * @param nodeId the instance identifier
81 * @return a set of device identifiers
82 */
83 Set<DeviceId> getDevices(NetworkId networkId, NodeId nodeId);
84
85
86 /**
87 * Sets a device's role for a specified controller instance.
88 *
89 * @param networkId virtual network identifier
90 * @param nodeId controller instance identifier
91 * @param deviceId device identifier
92 * @return a mastership event
93 */
94 CompletableFuture<MastershipEvent> setMaster(NetworkId networkId,
95 NodeId nodeId, DeviceId deviceId);
96
97 /**
98 * Returns the current master and number of past mastership hand-offs
99 * (terms) for a device.
100 *
101 * @param networkId virtual network identifier
102 * @param deviceId the device identifier
103 * @return the current master's ID and the term value for device, or null
104 */
105 MastershipTerm getTermFor(NetworkId networkId, DeviceId deviceId);
106
107 /**
108 * Sets a controller instance's mastership role to STANDBY for a device.
109 * If the role is MASTER, another controller instance will be selected
110 * as a candidate master.
111 *
112 * @param networkId virtual network identifier
113 * @param nodeId the controller instance identifier
114 * @param deviceId device to revoke mastership role for
115 * @return a mastership event
116 */
117 CompletableFuture<MastershipEvent> setStandby(NetworkId networkId,
118 NodeId nodeId, DeviceId deviceId);
119
120 /**
121 * Allows a controller instance to give up its current role for a device.
122 * If the role is MASTER, another controller instance will be selected
123 * as a candidate master.
124 *
125 * @param networkId virtual network identifier
126 * @param nodeId the controller instance identifier
127 * @param deviceId device to revoke mastership role for
128 * @return a mastership event
129 */
130 CompletableFuture<MastershipEvent> relinquishRole(NetworkId networkId,
131 NodeId nodeId, DeviceId deviceId);
132
133 /**
134 * Removes all the roles for the specified controller instance.
135 * If the role was MASTER, another controller instance will be selected
136 * as a candidate master.
137 *
138 * @param networkId virtual network identifier
139 * @param nodeId the controller instance identifier
140 */
141 void relinquishAllRole(NetworkId networkId, NodeId nodeId);
142}