blob: 55802b0c542a7ae2bd05ae9e6eca4601a10498a0 [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
Ray Milkey4ae02822014-03-24 17:00:40 -070012 * arbiter for allowing controllers to control switches.
13 *
14 * The OVS/OF1.{2,3} fault tolerance model is a switch connects to multiple
Jonathan Hart7bf62172013-02-28 13:17:18 -080015 * controllers, and the controllers send role requests to determine what their
16 * role is in controlling the switch.
Ray Milkey4ae02822014-03-24 17:00:40 -070017 *
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
Jonathan Hart7bf62172013-02-28 13:17:18 -080020 * mechanism that enables them to decide who should control a each switch.
21 * The registry service provides this mechanism.
Jonathan Hart7bf62172013-02-28 13:17:18 -080022 *
Ray Milkey4ae02822014-03-24 17:00:40 -070023 * @author jono
Jonathan Hart7bf62172013-02-28 13:17:18 -080024 */
Jonathan Hartd82f20d2013-02-21 18:04:24 -080025public interface IControllerRegistryService extends IFloodlightService {
Pavlin Radoslavovf1377ce2014-02-05 17:37:24 -080026
Ray Milkey4ae02822014-03-24 17:00:40 -070027 /**
28 * Callback interface for control change events.
29 */
30 public interface ControlChangeCallback {
Nick Karanatsios8abe7172014-02-19 20:31:48 -080031 /**
Ray Milkey4ae02822014-03-24 17:00:40 -070032 * Called whenever the control changes from the point of view of the
33 * registry. The callee can check whether they have control or not
34 * using the hasControl parameter.
35 *
36 * @param dpid The switch that control has changed for
37 * @param hasControl Whether the listener now has control or not
Nick Karanatsios8abe7172014-02-19 20:31:48 -080038 */
Ray Milkey4ae02822014-03-24 17:00:40 -070039 void controlChanged(long dpid, boolean hasControl);
40 }
41
42 /**
43 * Request for control of a switch. This method does not block. When
44 * control for a switch changes, the controlChanged method on the
45 * callback object will be called. This happens any time the control
46 * changes while the request is still active (until releaseControl is
47 * called)
48 *
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;
56
57 /**
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 *
63 * @param dpid Switch to release control of
64 */
65 public void releaseControl(long dpid);
66
67 /**
68 * Check whether the controller has control of the switch
69 * This call doesn't block.
70 *
71 * @param dpid Switch to check control of
72 * @return true if controller has control of the switch.
73 */
74 public boolean hasControl(long dpid);
75
76 /**
77 * Check whether this instance is the leader for the cluster.
78 * This call doesn't block.
79 *
80 * @return true if the instance is the leader for the cluster,
81 * otherwise false.
82 */
83 public boolean isClusterLeader();
84
85 /**
86 * Get the unique ID used to identify this controller in the cluster.
87 *
88 * @return controller ID.
89 */
90 public String getControllerId();
91
92 /**
93 * Register a controller to the ONOS cluster. Must be called before
94 * the registry can be used to take control of any switches.
95 *
96 * @param controllerId A unique string ID identifying this controller
97 * in the cluster
98 * @throws RegistryException for errors connecting to registry service,
99 * controllerId already registered
100 */
101 public void registerController(String controllerId)
102 throws RegistryException;
103
104 /**
105 * Get all controllers in the cluster.
106 *
107 * @return Collection of controller IDs
108 * @throws RegistryException on error
109 */
110 public Collection<String> getAllControllers() throws RegistryException;
111
112 /**
113 * Get all switches in the cluster, along with which controller is
114 * in control of them (if any) and any other controllers that have
115 * requested control.
116 *
117 * @return Map of all switches.
118 */
119 public Map<String, List<ControllerRegistryEntry>> getAllSwitches();
120
121 /**
122 * Get the controller that has control of a given switch.
123 *
124 * @param dpid Switch to find controller for
125 * @return controller ID
126 * @throws RegistryException Errors contacting registry service
127 */
128 public String getControllerForSwitch(long dpid) throws RegistryException;
129
130 /**
131 * Get all switches controlled by a given controller.
132 *
133 * @param controllerId ID of the controller
134 * @return Collection of dpids
135 */
136 public Collection<Long> getSwitchesControlledByController(String controllerId);
137
138 /**
139 * Get a unique Id Block.
140 *
141 * @return Id Block.
142 */
143 public IdBlock allocateUniqueIdBlock();
144
145 /**
146 * Get next unique id and retrieve a new range of ids if needed.
147 * @param range range to use for the identifier
148 * @return Id Block.
149 */
150 public IdBlock allocateUniqueIdBlock(long range);
Pavlin Radoslavov52163ed2014-03-19 11:39:34 -0700151
152
Ray Milkey4ae02822014-03-24 17:00:40 -0700153 /**
154 * Get a globally unique ID.
155 *
156 * @return a globally unique ID.
157 */
158 public long getNextUniqueId();
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -0800159}