blob: 7f550408eb64ade37eb5a32309d1d93c3ecb25cb [file] [log] [blame]
alshabib1f44e8e2014-08-14 15:19:57 -07001package net.onrc.onos.of.ctl.debugcounter;
2
3
4
5import java.util.List;
6
7import net.onrc.onos.of.ctl.debugcounter.DebugCounter.DebugCounterInfo;
8
tom0eb04ca2014-08-25 14:34:51 -07009//CHECKSTYLE:OFF
alshabib1f44e8e2014-08-14 15:19:57 -070010public interface IDebugCounterService {
11
12 /**
13 * Different counter types. Counters that are meant to be counted-on-demand
14 * need to be separately enabled/disabled.
15 */
16 public enum CounterType {
17 ALWAYS_COUNT,
18 COUNT_ON_DEMAND
19 }
20
21 /**
22 * Debug Counter Qualifiers.
23 */
24 public static final String CTR_MDATA_WARN = "warn";
25 public static final String CTR_MDATA_ERROR = "error";
26 public static final String CTR_MDATA_DROP = "drop";
27
28 /**
29 * A limit on the maximum number of counters that can be created.
30 */
31 public static final int MAX_COUNTERS = 5000;
32
33 /**
34 * Exception thrown when MAX_COUNTERS have been registered.
35 */
36 public class MaxCountersRegistered extends CounterException {
37 private static final long serialVersionUID = 3173747663719376745L;
38 String errormsg;
39 public MaxCountersRegistered(String errormsg) {
40 this.errormsg = errormsg;
41 }
42 @Override
43 public String getMessage() {
44 return this.errormsg;
45 }
46 }
47 /**
48 * Exception thrown when MAX_HIERARCHY has been reached.
49 */
50 public class MaxHierarchyRegistered extends CounterException {
51 private static final long serialVersionUID = 967431358683523871L;
52 private String errormsg;
53 public MaxHierarchyRegistered(String errormsg) {
54 this.errormsg = errormsg;
55 }
56 @Override
57 public String getMessage() {
58 return this.errormsg;
59 }
60 }
61 /**
62 * Exception thrown when attempting to register a hierarchical counter
63 * where higher levels of the hierarchy have not been pre-registered.
64 */
65 public class MissingHierarchicalLevel extends CounterException {
66 private static final long serialVersionUID = 517315311533995739L;
67 private String errormsg;
68 public MissingHierarchicalLevel(String errormsg) {
69 this.errormsg = errormsg;
70 }
71 @Override
72 public String getMessage() {
73 return this.errormsg;
74 }
75 }
76
77 public class CounterException extends Exception {
78 private static final long serialVersionUID = 2219781500857866035L;
79 }
80
81 /**
82 * maximum levels of hierarchy.
83 * Example of moduleName/counterHierarchy:
84 * switch/00:00:00:00:01:02:03:04/pktin/drops where
85 * moduleName ==> "switch" and
86 * counterHierarchy of 3 ==> "00:00:00:00:01:02:03:04/pktin/drops"
87 */
88 public static final int MAX_HIERARCHY = 3;
89
90 /**
91 * All modules that wish to have the DebugCounterService count for them, must
92 * register their counters by making this call (typically from that module's
93 * 'startUp' method). The counter can then be updated, displayed, reset etc.
94 * using the registered moduleName and counterHierarchy.
95 *
96 * @param moduleName the name of the module which is registering the
97 * counter eg. linkdiscovery or controller or switch
98 * @param counterHierarchy the hierarchical counter name specifying all
99 * the hierarchical levels that come above it.
100 * For example: to register a drop counter for
101 * packet-ins from a switch, the counterHierarchy
102 * can be "00:00:00:00:01:02:03:04/pktin/drops"
103 * It is necessary that counters in hierarchical levels
104 * above have already been pre-registered - in this
105 * example: "00:00:00:00:01:02:03:04/pktin" and
106 * "00:00:00:00:01:02:03:04"
107 * @param counterDescription a descriptive string that gives more information
108 * of what the counter is measuring. For example,
109 * "Measures the number of incoming packets seen by
110 * this module".
111 * @param counterType One of CounterType. On-demand counter types
112 * need to be explicitly enabled/disabled using other
113 * methods in this API -- i.e. registering them is
114 * not enough to start counting.
115 * @param metaData variable arguments that qualify a counter
116 * eg. warn, error etc.
117 * @return IDebugCounter with update methods that can be
118 * used to update a counter.
119 * @throws MaxCountersRegistered
120 * @throws MaxHierarchyRegistered
121 * @throws MissingHierarchicalLevel
122 */
123 public IDebugCounter registerCounter(String moduleName, String counterHierarchy,
124 String counterDescription, CounterType counterType,
125 String... metaData)
126 throws CounterException;
127
128 /**
129 * Flush all thread-local counter values (from the current thread)
130 * to the global counter store. This method is not intended for use by any
alshabib3b554cf2014-08-18 11:19:50 -0500131 * module. It's typical usage is from core and it is meant
alshabib1f44e8e2014-08-14 15:19:57 -0700132 * to flush those counters that are updated in the packet-processing pipeline,
133 * typically with the 'updateCounterNoFlush" methods in IDebugCounter.
134 */
135 public void flushCounters();
136
137 /**
138 * Resets the value of counters in the hierarchy to zero. Note that the reset
139 * applies to the level of counter hierarchy specified AND ALL LEVELS BELOW it
140 * in the hierarchy.
141 * For example: If a hierarchy exists like "00:00:00:00:01:02:03:04/pktin/drops"
142 * specifying a reset hierarchy: "00:00:00:00:01:02:03:04"
143 * will reset all counters for the switch dpid specified;
144 * while specifying a reset hierarchy: ""00:00:00:00:01:02:03:04/pktin"
145 * will reset the pktin counter and all levels below it (like drops)
146 * for the switch dpid specified.
147 */
148 void resetCounterHierarchy(String moduleName, String counterHierarchy);
149
150 /**
151 * Resets the values of all counters in the system.
152 */
153 public void resetAllCounters();
154
155 /**
156 * Resets the values of all counters belonging
157 * to a module with the given 'moduleName'.
158 */
159 public void resetAllModuleCounters(String moduleName);
160
161 /**
162 * This method applies only to CounterType.COUNT_ON_DEMAND. It is used to
163 * enable counting on the counter. Note that this step is necessary to start
164 * counting for these counter types - merely registering the counter is not
165 * enough (as is the case for CounterType.ALWAYS_COUNT). Newly
166 * enabled counters start from an initial value of zero.
167 *
168 * Enabling a counter in a counterHierarchy enables only THAT counter. It
169 * does not enable any other part of the counterHierarchy. For example, if
170 * a hierarchy exists like "00:00:00:00:01:02:03:04/pktin/drops", where the
171 * 'pktin' and 'drops' counters are CounterType.COUNT_ON_DEMAND, then enabling
172 * the 'pktin' counter by specifying the counterHierarchy as
173 * "00:00:00:00:01:02:03:04/pktin" does NOT enable the 'drops' counter.
174 */
175 public void enableCtrOnDemand(String moduleName, String counterHierarchy);
176
177 /**
178 * This method applies only to CounterType.COUNT_ON_DEMAND. It is used to
179 * enable counting on the counter. Note that disabling a counter results in a loss
180 * of the counter value. When re-enabled the counter will restart from zero.
181 *
182 * Disabling a counter in a counterHierarchy disables only THAT counter. It
183 * does not disable any other part of the counterHierarchy. For example, if
184 * a hierarchy exists like "00:00:00:00:01:02:03:04/pktin/drops", where the
185 * 'pktin' and 'drops' counters are CounterType.COUNT_ON_DEMAND, then disabling
186 * the 'pktin' counter by specifying the counterHierarchy as
187 * "00:00:00:00:01:02:03:04/pktin" does NOT disable the 'drops' counter.
188 */
189 public void disableCtrOnDemand(String moduleName, String counterHierarchy);
190
191 /**
192 * Get counter value and associated information for the specified counterHierarchy.
193 * Note that information on the level of counter hierarchy specified
194 * AND ALL LEVELS BELOW it in the hierarchy will be returned.
195 *
196 * For example,
197 * if a hierarchy exists like "00:00:00:00:01:02:03:04/pktin/drops", then
198 * specifying a counterHierarchy of "00:00:00:00:01:02:03:04/pktin" in the
199 * get call will return information on the 'pktin' as well as the 'drops'
200 * counters for the switch dpid specified.
201 *
202 * @return A list of DebugCounterInfo or an empty list if the counter
203 * could not be found
204 */
205 public List<DebugCounterInfo> getCounterHierarchy(String moduleName,
206 String counterHierarchy);
207
208 /**
209 * Get counter values and associated information for all counters in the
210 * system.
211 *
212 * @return the list of values/info or an empty list
213 */
214 public List<DebugCounterInfo> getAllCounterValues();
215
216 /**
217 * Get counter values and associated information for all counters associated
218 * with a module.
219 *
220 * @param moduleName
221 * @return the list of values/info or an empty list
222 */
223 public List<DebugCounterInfo> getModuleCounterValues(String moduleName);
224
225 /**
226 * Convenience method to figure out if the the given 'counterHierarchy' corresponds
227 * to a registered counterHierarchy for 'moduleName'. Note that the counter may or
228 * may not be enabled for counting, but if it is registered the method will
229 * return true.
230 *
231 * @param param
232 * @return false if moduleCounterHierarchy is not a registered counter
233 */
234 public boolean containsModuleCounterHierarchy(String moduleName,
235 String counterHierarchy);
236
237 /**
238 * Convenience method to figure out if the the given 'moduleName' corresponds
239 * to a registered moduleName or not. Note that the module may or may not have
240 * a counter enabled for counting, but if it is registered the method will
241 * return true.
242 *
243 * @param param
244 * @return false if moduleName is not a registered counter
245 */
246 public boolean containsModuleName(String moduleName);
247
248 /**
249 * Returns a list of moduleNames registered for debug counters or an empty
250 * list if no counters have been registered in the system.
251 */
252 public List<String> getModuleList();
253
254 /**
255 * Returns a list of all counters registered for a specific moduleName
256 * or a empty list.
257 */
258 public List<String> getModuleCounterList(String moduleName);
259
260
261}