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