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; |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame^] | 8 | import net.onrc.onos.core.util.OnosInstanceId; |
Umesh Krishnaswamy | b56bb29 | 2013-02-12 20:28:27 -0800 | [diff] [blame] | 9 | |
Jonathan Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 10 | /** |
| 11 | * A registry service that allows ONOS to register controllers and switches |
| 12 | * 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] | 13 | * arbiter for allowing controllers to control switches. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 14 | * <p/> |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 15 | * 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] | 16 | * controllers, and the controllers send role requests to determine what their |
| 17 | * role is in controlling the switch. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 18 | * <p/> |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 19 | * The ONOS fault tolerance model allows only a single controller to have |
| 20 | * control of a switch (MASTER role) at once. Controllers therefore need a |
Jonathan Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 21 | * mechanism that enables them to decide who should control a each switch. |
| 22 | * The registry service provides this mechanism. |
Jonathan Hart | 7bf6217 | 2013-02-28 13:17:18 -0800 | [diff] [blame] | 23 | */ |
Jonathan Hart | d82f20d | 2013-02-21 18:04:24 -0800 | [diff] [blame] | 24 | public interface IControllerRegistryService extends IFloodlightService { |
Pavlin Radoslavov | f1377ce | 2014-02-05 17:37:24 -0800 | [diff] [blame] | 25 | |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Callback interface for control change events. |
| 28 | */ |
| 29 | public interface ControlChangeCallback { |
Nick Karanatsios | 8abe717 | 2014-02-19 20:31:48 -0800 | [diff] [blame] | 30 | /** |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 31 | * Called whenever the control changes from the point of view of the |
| 32 | * registry. The callee can check whether they have control or not |
| 33 | * using the hasControl parameter. |
| 34 | * |
| 35 | * @param dpid The switch that control has changed for |
| 36 | * @param hasControl Whether the listener now has control or not |
Nick Karanatsios | 8abe717 | 2014-02-19 20:31:48 -0800 | [diff] [blame] | 37 | */ |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 38 | void controlChanged(long dpid, boolean hasControl); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Request for control of a switch. This method does not block. When |
| 43 | * control for a switch changes, the controlChanged method on the |
| 44 | * callback object will be called. This happens any time the control |
| 45 | * changes while the request is still active (until releaseControl is |
| 46 | * called) |
| 47 | * |
| 48 | * @param dpid Switch to request control for |
| 49 | * @param cb Callback that will be used to notify caller of control |
| 50 | * changes |
| 51 | * @throws RegistryException Errors contacting the registry service |
| 52 | */ |
| 53 | public void requestControl(long dpid, ControlChangeCallback cb) |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 54 | throws RegistryException; |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Stop trying to take control of a switch. This removes the entry |
| 58 | * for this controller requesting this switch in the registry. |
| 59 | * If the controller had control when this is called, another controller |
| 60 | * will now gain control of the switch. This call doesn't block. |
| 61 | * |
| 62 | * @param dpid Switch to release control of |
| 63 | */ |
| 64 | public void releaseControl(long dpid); |
| 65 | |
| 66 | /** |
| 67 | * Check whether the controller has control of the switch |
| 68 | * This call doesn't block. |
| 69 | * |
| 70 | * @param dpid Switch to check control of |
| 71 | * @return true if controller has control of the switch. |
| 72 | */ |
| 73 | public boolean hasControl(long dpid); |
| 74 | |
| 75 | /** |
| 76 | * Check whether this instance is the leader for the cluster. |
| 77 | * This call doesn't block. |
| 78 | * |
| 79 | * @return true if the instance is the leader for the cluster, |
| 80 | * otherwise false. |
| 81 | */ |
| 82 | public boolean isClusterLeader(); |
| 83 | |
| 84 | /** |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame^] | 85 | * Gets the unique ID used to identify this ONOS instance in the cluster. |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 86 | * |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame^] | 87 | * @return ONOS Instance ID. |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 88 | */ |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame^] | 89 | public OnosInstanceId getOnosInstanceId(); |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Register a controller to the ONOS cluster. Must be called before |
| 93 | * the registry can be used to take control of any switches. |
| 94 | * |
| 95 | * @param controllerId A unique string ID identifying this controller |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 96 | * in the cluster |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 97 | * @throws RegistryException for errors connecting to registry service, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 98 | * controllerId already registered |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 99 | */ |
| 100 | public void registerController(String controllerId) |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 101 | throws RegistryException; |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Get all controllers in the cluster. |
| 105 | * |
| 106 | * @return Collection of controller IDs |
| 107 | * @throws RegistryException on error |
| 108 | */ |
| 109 | public Collection<String> getAllControllers() throws RegistryException; |
| 110 | |
| 111 | /** |
| 112 | * Get all switches in the cluster, along with which controller is |
| 113 | * in control of them (if any) and any other controllers that have |
| 114 | * requested control. |
| 115 | * |
| 116 | * @return Map of all switches. |
| 117 | */ |
| 118 | public Map<String, List<ControllerRegistryEntry>> getAllSwitches(); |
| 119 | |
| 120 | /** |
| 121 | * Get the controller that has control of a given switch. |
| 122 | * |
| 123 | * @param dpid Switch to find controller for |
| 124 | * @return controller ID |
| 125 | * @throws RegistryException Errors contacting registry service |
| 126 | */ |
| 127 | public String getControllerForSwitch(long dpid) throws RegistryException; |
| 128 | |
| 129 | /** |
| 130 | * Get all switches controlled by a given controller. |
| 131 | * |
| 132 | * @param controllerId ID of the controller |
| 133 | * @return Collection of dpids |
| 134 | */ |
| 135 | public Collection<Long> getSwitchesControlledByController(String controllerId); |
| 136 | |
| 137 | /** |
| 138 | * Get a unique Id Block. |
| 139 | * |
| 140 | * @return Id Block. |
| 141 | */ |
| 142 | public IdBlock allocateUniqueIdBlock(); |
| 143 | |
| 144 | /** |
| 145 | * 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] | 146 | * |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 147 | * @param range range to use for the identifier |
| 148 | * @return Id Block. |
| 149 | */ |
| 150 | public IdBlock allocateUniqueIdBlock(long range); |
Pavlin Radoslavov | 52163ed | 2014-03-19 11:39:34 -0700 | [diff] [blame] | 151 | |
| 152 | |
Ray Milkey | 4ae0282 | 2014-03-24 17:00:40 -0700 | [diff] [blame] | 153 | /** |
| 154 | * Get a globally unique ID. |
| 155 | * |
| 156 | * @return a globally unique ID. |
| 157 | */ |
| 158 | public long getNextUniqueId(); |
Umesh Krishnaswamy | b56bb29 | 2013-02-12 20:28:27 -0800 | [diff] [blame] | 159 | } |