blob: eb27cf924be8caada138bd765f2fd80c0bea417f [file] [log] [blame]
Jonathan Hartd82f20d2013-02-21 18:04:24 -08001package net.onrc.onos.registry.controller;
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -08002
Jonathan Hartedd6a442013-02-20 15:22:06 -08003import java.util.Collection;
Jonathan Hart3d7730a2013-02-22 11:51:17 -08004import java.util.List;
Jonathan Hartd82f20d2013-02-21 18:04:24 -08005import java.util.Map;
Jonathan Hartedd6a442013-02-20 15:22:06 -08006
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -08007import net.floodlightcontroller.core.module.IFloodlightService;
8
Jonathan Hart7bf62172013-02-28 13:17:18 -08009/**
10 * A registry service that allows ONOS to register controllers and switches
11 * in a way that is global to the entire ONOS cluster. The registry is the
12 * arbiter for allowing controllers to control switches.
13 *
14 * The OVS/OF1.{2,3} fault tolerance model is a switch connects to multiple
15 * controllers, and the controllers send role requests to determine what their
16 * role is in controlling the switch.
17 *
18 * The ONOS fault tolerance model allows only a single controller to have
19 * control of a switch (MASTER role) at once. Controllers therefore need a
20 * mechanism that enables them to decide who should control a each switch.
21 * The registry service provides this mechanism.
22 *
23 * @author jono
24 *
25 */
Jonathan Hartd82f20d2013-02-21 18:04:24 -080026public interface IControllerRegistryService extends IFloodlightService {
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -080027
Jonathan Hart97801ac2013-02-26 14:29:16 -080028 /**
29 * Callback interface for control change events
30 *
31 */
Jonathan Hartd82f20d2013-02-21 18:04:24 -080032 public interface ControlChangeCallback {
Jonathan Hart97801ac2013-02-26 14:29:16 -080033 /**
34 * Called whenever the control changes from the point of view of the
35 * registry. The callee can check whether they have control or not
36 * using the hasControl parameter.
37 * @param dpid The switch that control has changed for
38 * @param hasControl Whether the listener now has control or not
39 */
Jonathan Hartd82f20d2013-02-21 18:04:24 -080040 public void controlChanged(long dpid, boolean hasControl);
Jonathan Hartbd181b62013-02-17 16:05:38 -080041 }
42
Jonathan Hart97801ac2013-02-26 14:29:16 -080043 /**
44 * Request for control of a switch. This method does not block. When
45 * control for a switch changes, the controlChanged method on the
46 * callback object will be called. This happens any time the control
47 * changes while the request is still active (until releaseControl is
48 * called)
49 * @param dpid Switch to request control for
50 * @param cb Callback that will be used to notify caller of control
51 * changes
52 * @throws RegistryException Errors contacting the registry service
53 */
54 public void requestControl(long dpid, ControlChangeCallback cb)
55 throws RegistryException;
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -080056
Jonathan Hart97801ac2013-02-26 14:29:16 -080057 /**
58 * Stop trying to take control of a switch. This removes the entry
59 * for this controller requesting this switch in the registry.
60 * If the controller had control when this is called, another controller
61 * will now gain control of the switch. This call doesn't block.
62 * @param dpid Switch to release control of
63 */
Jonathan Hartd82f20d2013-02-21 18:04:24 -080064 public void releaseControl(long dpid);
Jonathan Hart97801ac2013-02-26 14:29:16 -080065
66 /**
67 * Check whether the controller has control of the switch
68 * This call doesn't block.
69 * @param dpid Switch to check control of
70 * @return
71 */
Jonathan Hartd82f20d2013-02-21 18:04:24 -080072 public boolean hasControl(long dpid);
Pavlin Radoslavovf1377ce2014-02-05 17:37:24 -080073
74 /**
75 * Check whether this instance is the leader for the cluster.
76 * This call doesn't block.
77 *
78 * @return true if the instance is the leader for the cluster,
79 * otherwise false.
80 */
81 public boolean isClusterLeader();
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -080082
Jonathan Hart97801ac2013-02-26 14:29:16 -080083 /**
84 * Get the unique ID used to identify this controller in the cluster
85 * @return
86 */
Jonathan Hart7bf62172013-02-28 13:17:18 -080087 public String getControllerId ();
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -080088
Jonathan Hartedd6a442013-02-20 15:22:06 -080089 /**
Jonathan Hart97801ac2013-02-26 14:29:16 -080090 * Register a controller to the ONOS cluster. Must be called before
91 * the registry can be used to take control of any switches.
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -070092 * @param controllerId A unique string ID identifying this controller
Jonathan Hart97801ac2013-02-26 14:29:16 -080093 * in the cluster
94 * @throws errors connecting to registry service,
95 * controllerId already registered
Jonathan Hartedd6a442013-02-20 15:22:06 -080096 */
Jonathan Hart57080fb2013-02-21 10:55:46 -080097 public void registerController(String controllerId) throws RegistryException;
Jonathan Hartedd6a442013-02-20 15:22:06 -080098
99 /**
100 * Get all controllers in the cluster
Jonathan Hart97801ac2013-02-26 14:29:16 -0800101 * @return Collection of controller IDs
Jonathan Hartedd6a442013-02-20 15:22:06 -0800102 */
Jonathan Hart57080fb2013-02-21 10:55:46 -0800103 public Collection<String> getAllControllers() throws RegistryException;
Jonathan Hartedd6a442013-02-20 15:22:06 -0800104
Jonathan Hart97801ac2013-02-26 14:29:16 -0800105 /**
106 * Get all switches in the cluster, along with which controller is
107 * in control of them (if any) and any other controllers that have
108 * requested control.
109 * @return
110 */
111 public Map<String, List<ControllerRegistryEntry>> getAllSwitches();
Jonathan Hartedd6a442013-02-20 15:22:06 -0800112
Jonathan Hart7bf62172013-02-28 13:17:18 -0800113 /**
114 * Get the controller that has control of a given switch
115 * @param dpid Switch to find controller for
116 * @return controller ID
117 * @throws RegistryException Errors contacting registry service
118 */
Jonathan Hart57080fb2013-02-21 10:55:46 -0800119 public String getControllerForSwitch(long dpid) throws RegistryException;
Jonathan Hartedd6a442013-02-20 15:22:06 -0800120
Jonathan Hart7bf62172013-02-28 13:17:18 -0800121 /**
122 * Get all switches controlled by a given controller
123 * @param controllerId
124 * @return Collection of dpids
125 */
Jonathan Hartedd6a442013-02-20 15:22:06 -0800126 public Collection<Long> getSwitchesControlledByController(String controllerId);
Jonathan Hart1530ccc2013-04-03 19:36:02 -0700127
Nick Karanatsios8abe7172014-02-19 20:31:48 -0800128 /**
129 * Get
130 * @return
131 */
Jonathan Hart1530ccc2013-04-03 19:36:02 -0700132 public IdBlock allocateUniqueIdBlock();
Nick Karanatsios8abe7172014-02-19 20:31:48 -0800133
134 /**
135 * Get next unique id and retrieve a new range of ids if needed.
136 */
137 public IdBlock allocateUniqueIdBlock(long range);
Jonathan Hart1530ccc2013-04-03 19:36:02 -0700138
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -0800139}