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