blob: ef441db5af28a56e51ac786cf4bbe004d71f4de2 [file] [log] [blame]
Jonathan Hartdeda0ba2014-04-03 11:14:12 -07001package net.onrc.onos.core.registry;
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -08002
Jonathan Hartedd6a442013-02-20 15:22:06 -08003import java.util.Collection;
Jonathan Hart3d7730a2013-02-22 11:51:17 -08004import java.util.List;
Jonathan Hartd82f20d2013-02-21 18:04:24 -08005import java.util.Map;
Jonathan Hartedd6a442013-02-20 15:22:06 -08006
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -08007import net.floodlightcontroller.core.module.IFloodlightService;
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -07008import net.onrc.onos.core.util.OnosInstanceId;
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -08009
Jonathan Hart7bf62172013-02-28 13:17:18 -080010/**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070011 * 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 Milkey269ffb92014-04-03 14:43:30 -070014 * <p/>
Ray Milkey4ae02822014-03-24 17:00:40 -070015 * The OVS/OF1.{2,3} fault tolerance model is a switch connects to multiple
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070016 * controllers, and the controllers send role requests to tell the switch their
17 * role in controlling the switch.
Ray Milkey269ffb92014-04-03 14:43:30 -070018 * <p/>
Ray Milkey4ae02822014-03-24 17:00:40 -070019 * 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'Connorc67f9fa2014-08-07 18:17:46 -070021 * mechanism that enables them to decide who should control a each switch. The
22 * registry service provides this mechanism.
Jonathan Hart7bf62172013-02-28 13:17:18 -080023 */
Jonathan Hartd82f20d2013-02-21 18:04:24 -080024public interface IControllerRegistryService extends IFloodlightService {
Pavlin Radoslavovf1377ce2014-02-05 17:37:24 -080025
Ray Milkey4ae02822014-03-24 17:00:40 -070026 /**
27 * Callback interface for control change events.
28 */
29 public interface ControlChangeCallback {
Nick Karanatsios8abe7172014-02-19 20:31:48 -080030 /**
Ray Milkey4ae02822014-03-24 17:00:40 -070031 * Called whenever the control changes from the point of view of the
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070032 * registry. The callee can check whether they have control or not using
33 * the hasControl parameter.
Ray Milkey4ae02822014-03-24 17:00:40 -070034 *
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070035 * @param dpid The switch that control has changed for
Ray Milkey4ae02822014-03-24 17:00:40 -070036 * @param hasControl Whether the listener now has control or not
Nick Karanatsios8abe7172014-02-19 20:31:48 -080037 */
Ray Milkey4ae02822014-03-24 17:00:40 -070038 void controlChanged(long dpid, boolean hasControl);
39 }
40
41 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070042 * 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 Milkey4ae02822014-03-24 17:00:40 -070046 *
47 * @param dpid Switch to request control for
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070048 * @param cb Callback that will be used to notify caller of control changes
Ray Milkey4ae02822014-03-24 17:00:40 -070049 * @throws RegistryException Errors contacting the registry service
50 */
51 public void requestControl(long dpid, ControlChangeCallback cb)
Ray Milkey269ffb92014-04-03 14:43:30 -070052 throws RegistryException;
Ray Milkey4ae02822014-03-24 17:00:40 -070053
54 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070055 * 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 Milkey4ae02822014-03-24 17:00:40 -070059 *
60 * @param dpid Switch to release control of
61 */
62 public void releaseControl(long dpid);
63
64 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070065 * Check whether the controller has control of the switch This call doesn't
66 * block.
Ray Milkey4ae02822014-03-24 17:00:40 -070067 *
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'Connorc67f9fa2014-08-07 18:17:46 -070074 * Check whether this instance is the leader for the cluster. This call
75 * doesn't block.
Ray Milkey4ae02822014-03-24 17:00:40 -070076 *
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070077 * @return true if the instance is the leader for the cluster, otherwise
78 * false.
Ray Milkey4ae02822014-03-24 17:00:40 -070079 */
80 public boolean isClusterLeader();
81
82 /**
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070083 * Gets the unique ID used to identify this ONOS instance in the cluster.
Ray Milkey4ae02822014-03-24 17:00:40 -070084 *
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070085 * @return ONOS Instance ID.
Ray Milkey4ae02822014-03-24 17:00:40 -070086 */
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070087 public OnosInstanceId getOnosInstanceId();
Ray Milkey4ae02822014-03-24 17:00:40 -070088
89 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070090 * Register a controller to the ONOS cluster. Must be called before the
91 * registry can be used to take control of any switches.
Ray Milkey4ae02822014-03-24 17:00:40 -070092 *
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070093 * @param controllerId A unique string ID identifying this controller in the
94 * cluster
Ray Milkey4ae02822014-03-24 17:00:40 -070095 * @throws RegistryException for errors connecting to registry service,
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070096 * controllerId already registered
Ray Milkey4ae02822014-03-24 17:00:40 -070097 */
98 public void registerController(String controllerId)
Ray Milkey269ffb92014-04-03 14:43:30 -070099 throws RegistryException;
Ray Milkey4ae02822014-03-24 17:00:40 -0700100
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'Connorc67f9fa2014-08-07 18:17:46 -0700110 * 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 Milkey4ae02822014-03-24 17:00:40 -0700113 *
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 Milkey269ffb92014-04-03 14:43:30 -0700144 *
Ray Milkey4ae02822014-03-24 17:00:40 -0700145 * @param range range to use for the identifier
146 * @return Id Block.
147 */
148 public IdBlock allocateUniqueIdBlock(long range);
Pavlin Radoslavov52163ed2014-03-19 11:39:34 -0700149
Ray Milkey4ae02822014-03-24 17:00:40 -0700150 /**
151 * Get a globally unique ID.
152 *
153 * @return a globally unique ID.
154 */
155 public long getNextUniqueId();
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -0800156}