blob: 5af1ac182337116b532a692a506694c4495862cc [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;
8
Jonathan Hart7bf62172013-02-28 13:17:18 -08009/**
10 * A registry service that allows ONOS to register controllers and switches
11 * in a way that is global to the entire ONOS cluster. The registry is the
Ray Milkey4ae02822014-03-24 17:00:40 -070012 * arbiter for allowing controllers to control switches.
Ray Milkey269ffb92014-04-03 14:43:30 -070013 * <p/>
Ray Milkey4ae02822014-03-24 17:00:40 -070014 * The OVS/OF1.{2,3} fault tolerance model is a switch connects to multiple
Jonathan Hart7bf62172013-02-28 13:17:18 -080015 * controllers, and the controllers send role requests to determine what their
16 * role is in controlling the switch.
Ray Milkey269ffb92014-04-03 14:43:30 -070017 * <p/>
Ray Milkey4ae02822014-03-24 17:00:40 -070018 * The ONOS fault tolerance model allows only a single controller to have
19 * control of a switch (MASTER role) at once. Controllers therefore need a
Jonathan Hart7bf62172013-02-28 13:17:18 -080020 * mechanism that enables them to decide who should control a each switch.
21 * The registry service provides this mechanism.
Jonathan Hart7bf62172013-02-28 13:17:18 -080022 */
Jonathan Hartd82f20d2013-02-21 18:04:24 -080023public interface IControllerRegistryService extends IFloodlightService {
Pavlin Radoslavovf1377ce2014-02-05 17:37:24 -080024
Ray Milkey4ae02822014-03-24 17:00:40 -070025 /**
26 * Callback interface for control change events.
27 */
28 public interface ControlChangeCallback {
Nick Karanatsios8abe7172014-02-19 20:31:48 -080029 /**
Ray Milkey4ae02822014-03-24 17:00:40 -070030 * Called whenever the control changes from the point of view of the
31 * registry. The callee can check whether they have control or not
32 * using the hasControl parameter.
33 *
34 * @param dpid The switch that control has changed for
35 * @param hasControl Whether the listener now has control or not
Nick Karanatsios8abe7172014-02-19 20:31:48 -080036 */
Ray Milkey4ae02822014-03-24 17:00:40 -070037 void controlChanged(long dpid, boolean hasControl);
38 }
39
40 /**
41 * Request for control of a switch. This method does not block. When
42 * control for a switch changes, the controlChanged method on the
43 * callback object will be called. This happens any time the control
44 * changes while the request is still active (until releaseControl is
45 * called)
46 *
47 * @param dpid Switch to request control for
48 * @param cb Callback that will be used to notify caller of control
49 * changes
50 * @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 /**
56 * Stop trying to take control of a switch. This removes the entry
57 * for this controller requesting this switch in the registry.
58 * If the controller had control when this is called, another controller
59 * will now gain control of the switch. This call doesn't block.
60 *
61 * @param dpid Switch to release control of
62 */
63 public void releaseControl(long dpid);
64
65 /**
66 * Check whether the controller has control of the switch
67 * This call doesn't block.
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 /**
75 * Check whether this instance is the leader for the cluster.
76 * This call doesn't block.
77 *
78 * @return true if the instance is the leader for the cluster,
79 * otherwise false.
80 */
81 public boolean isClusterLeader();
82
83 /**
84 * Get the unique ID used to identify this controller in the cluster.
85 *
86 * @return controller ID.
87 */
88 public String getControllerId();
89
90 /**
91 * Register a controller to the ONOS cluster. Must be called before
92 * the registry can be used to take control of any switches.
93 *
94 * @param controllerId A unique string ID identifying this controller
Ray Milkey269ffb92014-04-03 14:43:30 -070095 * in the cluster
Ray Milkey4ae02822014-03-24 17:00:40 -070096 * @throws RegistryException for errors connecting to registry service,
Ray Milkey269ffb92014-04-03 14:43:30 -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 /**
111 * Get all switches in the cluster, along with which controller is
112 * in control of them (if any) and any other controllers that have
113 * requested control.
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 /**
137 * Get a unique Id Block.
138 *
139 * @return Id Block.
140 */
141 public IdBlock allocateUniqueIdBlock();
142
143 /**
144 * Get next unique id and retrieve a new range of ids if needed.
Ray Milkey269ffb92014-04-03 14:43:30 -0700145 *
Ray Milkey4ae02822014-03-24 17:00:40 -0700146 * @param range range to use for the identifier
147 * @return Id Block.
148 */
149 public IdBlock allocateUniqueIdBlock(long range);
Pavlin Radoslavov52163ed2014-03-19 11:39:34 -0700150
151
Ray Milkey4ae02822014-03-24 17:00:40 -0700152 /**
153 * Get a globally unique ID.
154 *
155 * @return a globally unique ID.
156 */
157 public long getNextUniqueId();
Umesh Krishnaswamyb56bb292013-02-12 20:28:27 -0800158}