blob: cfc47c88803fa21e4d9f929b062a7f95305f848d [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/**
11 * A registry service that allows ONOS to register controllers and switches
12 * in a way that is global to the entire ONOS cluster. The registry is the
Ray Milkey4ae02822014-03-24 17:00:40 -070013 * arbiter 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
Jonathan Hart7bf62172013-02-28 13:17:18 -080016 * controllers, and the controllers send role requests to determine what their
17 * role is 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
Jonathan Hart7bf62172013-02-28 13:17:18 -080021 * mechanism that enables them to decide who should control a each switch.
22 * The 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
32 * registry. The callee can check whether they have control or not
33 * using the hasControl parameter.
34 *
35 * @param dpid The switch that control has changed for
36 * @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 /**
42 * Request for control of a switch. This method does not block. When
43 * control for a switch changes, the controlChanged method on the
44 * callback object will be called. This happens any time the control
45 * changes while the request is still active (until releaseControl is
46 * called)
47 *
48 * @param dpid Switch to request control for
49 * @param cb Callback that will be used to notify caller of control
50 * changes
51 * @throws RegistryException Errors contacting the registry service
52 */
53 public void requestControl(long dpid, ControlChangeCallback cb)
Ray Milkey269ffb92014-04-03 14:43:30 -070054 throws RegistryException;
Ray Milkey4ae02822014-03-24 17:00:40 -070055
56 /**
57 * Stop trying to take control of a switch. This removes the entry
58 * for this controller requesting this switch in the registry.
59 * If the controller had control when this is called, another controller
60 * will now gain control of the switch. This call doesn't block.
61 *
62 * @param dpid Switch to release control of
63 */
64 public void releaseControl(long dpid);
65
66 /**
67 * Check whether the controller has control of the switch
68 * This call doesn't block.
69 *
70 * @param dpid Switch to check control of
71 * @return true if controller has control of the switch.
72 */
73 public boolean hasControl(long dpid);
74
75 /**
76 * Check whether this instance is the leader for the cluster.
77 * This call doesn't block.
78 *
79 * @return true if the instance is the leader for the cluster,
80 * otherwise false.
81 */
82 public boolean isClusterLeader();
83
84 /**
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070085 * Gets the unique ID used to identify this ONOS instance in the cluster.
Ray Milkey4ae02822014-03-24 17:00:40 -070086 *
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070087 * @return ONOS Instance ID.
Ray Milkey4ae02822014-03-24 17:00:40 -070088 */
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070089 public OnosInstanceId getOnosInstanceId();
Ray Milkey4ae02822014-03-24 17:00:40 -070090
91 /**
92 * Register a controller to the ONOS cluster. Must be called before
93 * the registry can be used to take control of any switches.
94 *
95 * @param controllerId A unique string ID identifying this controller
Ray Milkey269ffb92014-04-03 14:43:30 -070096 * in the cluster
Ray Milkey4ae02822014-03-24 17:00:40 -070097 * @throws RegistryException for errors connecting to registry service,
Ray Milkey269ffb92014-04-03 14:43:30 -070098 * controllerId already registered
Ray Milkey4ae02822014-03-24 17:00:40 -070099 */
100 public void registerController(String controllerId)
Ray Milkey269ffb92014-04-03 14:43:30 -0700101 throws RegistryException;
Ray Milkey4ae02822014-03-24 17:00:40 -0700102
103 /**
104 * Get all controllers in the cluster.
105 *
106 * @return Collection of controller IDs
107 * @throws RegistryException on error
108 */
109 public Collection<String> getAllControllers() throws RegistryException;
110
111 /**
112 * Get all switches in the cluster, along with which controller is
113 * in control of them (if any) and any other controllers that have
114 * requested control.
115 *
116 * @return Map of all switches.
117 */
118 public Map<String, List<ControllerRegistryEntry>> getAllSwitches();
119
120 /**
121 * Get the controller that has control of a given switch.
122 *
123 * @param dpid Switch to find controller for
124 * @return controller ID
125 * @throws RegistryException Errors contacting registry service
126 */
127 public String getControllerForSwitch(long dpid) throws RegistryException;
128
129 /**
130 * Get all switches controlled by a given controller.
131 *
132 * @param controllerId ID of the controller
133 * @return Collection of dpids
134 */
135 public Collection<Long> getSwitchesControlledByController(String controllerId);
136
137 /**
138 * Get a unique Id Block.
139 *
140 * @return Id Block.
141 */
142 public IdBlock allocateUniqueIdBlock();
143
144 /**
145 * Get next unique id and retrieve a new range of ids if needed.
Ray Milkey269ffb92014-04-03 14:43:30 -0700146 *
Ray Milkey4ae02822014-03-24 17:00:40 -0700147 * @param range range to use for the identifier
148 * @return Id Block.
149 */
150 public IdBlock allocateUniqueIdBlock(long range);
Pavlin Radoslavov52163ed2014-03-19 11:39:34 -0700151
152
Ray Milkey4ae02822014-03-24 17:00:40 -0700153 /**
154 * Get a globally unique ID.
155 *
156 * @return a globally unique ID.
157 */
158 public long getNextUniqueId();
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -0800159}