Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.registry; |
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 |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 12 | * arbiter for allowing controllers to control switches. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 13 | * <p/> |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 14 | * The OVS/OF1.{2,3} fault tolerance model is a switch connects to multiple |
Jonathan Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 15 | * controllers, and the controllers send role requests to determine what their |
| 16 | * role is in controlling the switch. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 17 | * <p/> |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 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 Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 20 | * mechanism that enables them to decide who should control a each switch. |
| 21 | * The registry service provides this mechanism. |
Jonathan Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 22 | * |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 23 | * @author jono |
Jonathan Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 24 | */ |
Jonathan Hart | d82f20d | 2013-02-21 18:04:24 -0800 | [diff] [blame] | 25 | public interface IControllerRegistryService extends IFloodlightService { |
Pavlin Radoslavov | f1377ce | 2014-02-05 17:37:24 -0800 | [diff] [blame] | 26 | |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Callback interface for control change events. |
| 29 | */ |
| 30 | public interface ControlChangeCallback { |
Nick Karanatsios | 8abe717 | 2014-02-19 20:31:48 -0800 | [diff] [blame] | 31 | /** |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 32 | * 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 Karanatsios | 8abe717 | 2014-02-19 20:31:48 -0800 | [diff] [blame] | 38 | */ |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 39 | 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) |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 55 | throws RegistryException; |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 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 |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 97 | * in the cluster |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 98 | * @throws RegistryException for errors connecting to registry service, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 99 | * controllerId already registered |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 100 | */ |
| 101 | public void registerController(String controllerId) |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 102 | throws RegistryException; |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 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. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 147 | * |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 148 | * @param range range to use for the identifier |
| 149 | * @return Id Block. |
| 150 | */ |
| 151 | public IdBlock allocateUniqueIdBlock(long range); |
Pavlin Radoslavov | 52163ed | 2014-03-19 11:39:34 -0700 | [diff] [blame] | 152 | |
| 153 | |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 154 | /** |
| 155 | * Get a globally unique ID. |
| 156 | * |
| 157 | * @return a globally unique ID. |
| 158 | */ |
| 159 | public long getNextUniqueId(); |
Umesh Krishnaswamy | b56bb29 | 2013-02-12 20:28:27 -0800 | [diff] [blame] | 160 | } |