blob: 33ba272a3648088f3c7ec7fdc1a54f36b802bdc1 [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);
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -080073
Jonathan Hart97801ac2013-02-26 14:29:16 -080074 /**
75 * Get the unique ID used to identify this controller in the cluster
76 * @return
77 */
Jonathan Hart7bf62172013-02-28 13:17:18 -080078 public String getControllerId ();
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -080079
Jonathan Hartedd6a442013-02-20 15:22:06 -080080 /**
Jonathan Hart97801ac2013-02-26 14:29:16 -080081 * Register a controller to the ONOS cluster. Must be called before
82 * the registry can be used to take control of any switches.
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -070083 * @param controllerId A unique string ID identifying this controller
Jonathan Hart97801ac2013-02-26 14:29:16 -080084 * in the cluster
85 * @throws errors connecting to registry service,
86 * controllerId already registered
Jonathan Hartedd6a442013-02-20 15:22:06 -080087 */
Jonathan Hart57080fb2013-02-21 10:55:46 -080088 public void registerController(String controllerId) throws RegistryException;
Jonathan Hartedd6a442013-02-20 15:22:06 -080089
90 /**
91 * Get all controllers in the cluster
Jonathan Hart97801ac2013-02-26 14:29:16 -080092 * @return Collection of controller IDs
Jonathan Hartedd6a442013-02-20 15:22:06 -080093 */
Jonathan Hart57080fb2013-02-21 10:55:46 -080094 public Collection<String> getAllControllers() throws RegistryException;
Jonathan Hartedd6a442013-02-20 15:22:06 -080095
Jonathan Hart97801ac2013-02-26 14:29:16 -080096 /**
97 * Get all switches in the cluster, along with which controller is
98 * in control of them (if any) and any other controllers that have
99 * requested control.
100 * @return
101 */
102 public Map<String, List<ControllerRegistryEntry>> getAllSwitches();
Jonathan Hartedd6a442013-02-20 15:22:06 -0800103
Jonathan Hart7bf62172013-02-28 13:17:18 -0800104 /**
105 * Get the controller that has control of a given switch
106 * @param dpid Switch to find controller for
107 * @return controller ID
108 * @throws RegistryException Errors contacting registry service
109 */
Jonathan Hart57080fb2013-02-21 10:55:46 -0800110 public String getControllerForSwitch(long dpid) throws RegistryException;
Jonathan Hartedd6a442013-02-20 15:22:06 -0800111
Jonathan Hart7bf62172013-02-28 13:17:18 -0800112 /**
113 * Get all switches controlled by a given controller
114 * @param controllerId
115 * @return Collection of dpids
116 */
Jonathan Hartedd6a442013-02-20 15:22:06 -0800117 public Collection<Long> getSwitchesControlledByController(String controllerId);
Jonathan Hart1530ccc2013-04-03 19:36:02 -0700118
119 public IdBlock allocateUniqueIdBlock();
120
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -0800121}