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