Jonathan Hart | d82f20d | 2013-02-21 18:04:24 -0800 | [diff] [blame] | 1 | package net.onrc.onos.registry.controller; |
Umesh Krishnaswamy | b56bb29 | 2013-02-12 20:28:27 -0800 | [diff] [blame] | 2 | |
Jonathan Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 3 | import java.util.Collection; |
Jonathan Hart | 3d7730a | 2013-02-22 11:51:17 -0800 | [diff] [blame] | 4 | import java.util.List; |
Jonathan Hart | d82f20d | 2013-02-21 18:04:24 -0800 | [diff] [blame] | 5 | import java.util.Map; |
Jonathan Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 6 | |
Umesh Krishnaswamy | b56bb29 | 2013-02-12 20:28:27 -0800 | [diff] [blame] | 7 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 8 | |
Jonathan Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 9 | /** |
| 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 Hart | d82f20d | 2013-02-21 18:04:24 -0800 | [diff] [blame] | 26 | public interface IControllerRegistryService extends IFloodlightService { |
Umesh Krishnaswamy | b56bb29 | 2013-02-12 20:28:27 -0800 | [diff] [blame] | 27 | |
Jonathan Hart | 97801ac | 2013-02-26 14:29:16 -0800 | [diff] [blame] | 28 | /** |
| 29 | * Callback interface for control change events |
| 30 | * |
| 31 | */ |
Jonathan Hart | d82f20d | 2013-02-21 18:04:24 -0800 | [diff] [blame] | 32 | public interface ControlChangeCallback { |
Jonathan Hart | 97801ac | 2013-02-26 14:29:16 -0800 | [diff] [blame] | 33 | /** |
| 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 Hart | d82f20d | 2013-02-21 18:04:24 -0800 | [diff] [blame] | 40 | public void controlChanged(long dpid, boolean hasControl); |
Jonathan Hart | bd181b6 | 2013-02-17 16:05:38 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Jonathan Hart | 97801ac | 2013-02-26 14:29:16 -0800 | [diff] [blame] | 43 | /** |
| 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 Krishnaswamy | b56bb29 | 2013-02-12 20:28:27 -0800 | [diff] [blame] | 56 | |
Jonathan Hart | 97801ac | 2013-02-26 14:29:16 -0800 | [diff] [blame] | 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 | * @param dpid Switch to release control of |
| 63 | */ |
Jonathan Hart | d82f20d | 2013-02-21 18:04:24 -0800 | [diff] [blame] | 64 | public void releaseControl(long dpid); |
Jonathan Hart | 97801ac | 2013-02-26 14:29:16 -0800 | [diff] [blame] | 65 | |
| 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 Hart | d82f20d | 2013-02-21 18:04:24 -0800 | [diff] [blame] | 72 | public boolean hasControl(long dpid); |
Umesh Krishnaswamy | b56bb29 | 2013-02-12 20:28:27 -0800 | [diff] [blame] | 73 | |
Jonathan Hart | 97801ac | 2013-02-26 14:29:16 -0800 | [diff] [blame] | 74 | /** |
| 75 | * Get the unique ID used to identify this controller in the cluster |
| 76 | * @return |
| 77 | */ |
Jonathan Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 78 | public String getControllerId (); |
Umesh Krishnaswamy | b56bb29 | 2013-02-12 20:28:27 -0800 | [diff] [blame] | 79 | |
Jonathan Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 80 | /** |
Jonathan Hart | 97801ac | 2013-02-26 14:29:16 -0800 | [diff] [blame] | 81 | * Register a controller to the ONOS cluster. Must be called before |
| 82 | * the registry can be used to take control of any switches. |
| 83 | * @param controller A unique string ID identifying this controller |
| 84 | * in the cluster |
| 85 | * @throws errors connecting to registry service, |
| 86 | * controllerId already registered |
Jonathan Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 87 | */ |
Jonathan Hart | 57080fb | 2013-02-21 10:55:46 -0800 | [diff] [blame] | 88 | public void registerController(String controllerId) throws RegistryException; |
Jonathan Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * Get all controllers in the cluster |
Jonathan Hart | 97801ac | 2013-02-26 14:29:16 -0800 | [diff] [blame] | 92 | * @return Collection of controller IDs |
Jonathan Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 93 | */ |
Jonathan Hart | 57080fb | 2013-02-21 10:55:46 -0800 | [diff] [blame] | 94 | public Collection<String> getAllControllers() throws RegistryException; |
Jonathan Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 95 | |
Jonathan Hart | 97801ac | 2013-02-26 14:29:16 -0800 | [diff] [blame] | 96 | /** |
| 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 Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 103 | |
Jonathan Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 104 | /** |
| 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 Hart | 57080fb | 2013-02-21 10:55:46 -0800 | [diff] [blame] | 110 | public String getControllerForSwitch(long dpid) throws RegistryException; |
Jonathan Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 111 | |
Jonathan Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 112 | /** |
| 113 | * Get all switches controlled by a given controller |
| 114 | * @param controllerId |
| 115 | * @return Collection of dpids |
| 116 | */ |
Jonathan Hart | edd6a44 | 2013-02-20 15:22:06 -0800 | [diff] [blame] | 117 | public Collection<Long> getSwitchesControlledByController(String controllerId); |
Jonathan Hart | 1530ccc | 2013-04-03 19:36:02 -0700 | [diff] [blame^] | 118 | |
| 119 | public IdBlock allocateUniqueIdBlock(); |
| 120 | |
Umesh Krishnaswamy | b56bb29 | 2013-02-12 20:28:27 -0800 | [diff] [blame] | 121 | } |