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