blob: 7d41a4e1b49a08687aebbdc1020c8b85fa0b62e7 [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;
Sho SHIMIZU9257b0c2014-08-13 15:00:10 -07008import net.onrc.onos.core.util.IdBlockAllocator;
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -07009import net.onrc.onos.core.util.OnosInstanceId;
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -080010
Jonathan Hart7bf62172013-02-28 13:17:18 -080011/**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070012 * 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 Milkey269ffb92014-04-03 14:43:30 -070015 * <p/>
Ray Milkey4ae02822014-03-24 17:00:40 -070016 * The OVS/OF1.{2,3} fault tolerance model is a switch connects to multiple
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070017 * controllers, and the controllers send role requests to tell the switch their
18 * role in controlling the switch.
Ray Milkey269ffb92014-04-03 14:43:30 -070019 * <p/>
Ray Milkey4ae02822014-03-24 17:00:40 -070020 * 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'Connorc67f9fa2014-08-07 18:17:46 -070022 * mechanism that enables them to decide who should control a each switch. The
23 * registry service provides this mechanism.
Jonathan Hart7bf62172013-02-28 13:17:18 -080024 */
Sho SHIMIZU9257b0c2014-08-13 15:00:10 -070025public interface IControllerRegistryService extends IFloodlightService, IdBlockAllocator {
Pavlin Radoslavovf1377ce2014-02-05 17:37:24 -080026
Ray Milkey4ae02822014-03-24 17:00:40 -070027 /**
28 * Callback interface for control change events.
29 */
30 public interface ControlChangeCallback {
Nick Karanatsios8abe7172014-02-19 20:31:48 -080031 /**
Ray Milkey4ae02822014-03-24 17:00:40 -070032 * Called whenever the control changes from the point of view of the
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070033 * registry. The callee can check whether they have control or not using
34 * the hasControl parameter.
Ray Milkey4ae02822014-03-24 17:00:40 -070035 *
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070036 * @param dpid The switch that control has changed for
Ray Milkey4ae02822014-03-24 17:00:40 -070037 * @param hasControl Whether the listener now has control or not
Nick Karanatsios8abe7172014-02-19 20:31:48 -080038 */
Ray Milkey4ae02822014-03-24 17:00:40 -070039 void controlChanged(long dpid, boolean hasControl);
40 }
41
42 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070043 * 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 Milkey4ae02822014-03-24 17:00:40 -070047 *
48 * @param dpid Switch to request control for
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070049 * @param cb Callback that will be used to notify caller of control changes
Ray Milkey4ae02822014-03-24 17:00:40 -070050 * @throws RegistryException Errors contacting the registry service
51 */
52 public void requestControl(long dpid, ControlChangeCallback cb)
Ray Milkey269ffb92014-04-03 14:43:30 -070053 throws RegistryException;
Ray Milkey4ae02822014-03-24 17:00:40 -070054
55 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070056 * 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 Milkey4ae02822014-03-24 17:00:40 -070060 *
61 * @param dpid Switch to release control of
62 */
63 public void releaseControl(long dpid);
64
65 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070066 * Check whether the controller has control of the switch This call doesn't
67 * block.
Ray Milkey4ae02822014-03-24 17:00:40 -070068 *
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'Connorc67f9fa2014-08-07 18:17:46 -070075 * Check whether this instance is the leader for the cluster. This call
76 * doesn't block.
Ray Milkey4ae02822014-03-24 17:00:40 -070077 *
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070078 * @return true if the instance is the leader for the cluster, otherwise
79 * false.
Ray Milkey4ae02822014-03-24 17:00:40 -070080 */
81 public boolean isClusterLeader();
82
83 /**
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070084 * Gets the unique ID used to identify this ONOS instance in the cluster.
Ray Milkey4ae02822014-03-24 17:00:40 -070085 *
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070086 * @return ONOS Instance ID.
Ray Milkey4ae02822014-03-24 17:00:40 -070087 */
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070088 public OnosInstanceId getOnosInstanceId();
Ray Milkey4ae02822014-03-24 17:00:40 -070089
90 /**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070091 * Register a controller to the ONOS cluster. Must be called before the
92 * registry can be used to take control of any switches.
Ray Milkey4ae02822014-03-24 17:00:40 -070093 *
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070094 * @param controllerId A unique string ID identifying this controller in the
95 * cluster
Ray Milkey4ae02822014-03-24 17:00:40 -070096 * @throws RegistryException for errors connecting to registry service,
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070097 * controllerId already registered
Ray Milkey4ae02822014-03-24 17:00:40 -070098 */
99 public void registerController(String controllerId)
Ray Milkey269ffb92014-04-03 14:43:30 -0700100 throws RegistryException;
Ray Milkey4ae02822014-03-24 17:00:40 -0700101
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'Connorc67f9fa2014-08-07 18:17:46 -0700111 * 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 Milkey4ae02822014-03-24 17:00:40 -0700114 *
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 Milkey4ae02822014-03-24 17:00:40 -0700137 * Get a globally unique ID.
138 *
139 * @return a globally unique ID.
140 */
141 public long getNextUniqueId();
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -0800142}