blob: 0d50884582554ecb6d56975a93e3932061363d5f [file] [log] [blame]
Jian Li60804322015-12-02 14:46:31 -08001/*
Jian Lie044d1a2016-01-25 09:01:20 -08002 * Copyright 2015-2016 Open Networking Laboratory
Jian Li60804322015-12-02 14:46:31 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jian Li6b86a762016-01-29 09:30:40 -080016package org.onosproject.cpman.impl;
Jian Li60804322015-12-02 14:46:31 -080017
Jian Lie044d1a2016-01-25 09:01:20 -080018import com.google.common.collect.ImmutableMap;
19import com.google.common.collect.ImmutableSet;
20import com.google.common.collect.Sets;
Jian Li60804322015-12-02 14:46:31 -080021import org.onlab.metrics.MetricsService;
Jian Li6b86a762016-01-29 09:30:40 -080022import org.onosproject.cpman.ControlMetricType;
Jian Li60804322015-12-02 14:46:31 -080023import org.onosproject.net.DeviceId;
24import org.onosproject.net.device.DeviceService;
25
Jian Li60804322015-12-02 14:46:31 -080026import java.util.Map;
27import java.util.Optional;
28import java.util.Set;
29import java.util.concurrent.ConcurrentHashMap;
30
31/**
32 * Singleton class to provide various control plane metrics to other components.
33 */
34public final class ControlMetricsFactory {
Jian Li60804322015-12-02 14:46:31 -080035 private MetricsService metricsService;
36 private boolean enableMonitor = false;
Jian Li1a424692016-02-03 16:21:18 -080037 private Boolean isInitialized = false;
Jian Lie044d1a2016-01-25 09:01:20 -080038
Jian Li60804322015-12-02 14:46:31 -080039 // define a set of MetricsAggregators
Jian Lie044d1a2016-01-25 09:01:20 -080040 private MetricsAggregator cpuLoad;
41 private MetricsAggregator totalCpuTime;
42 private MetricsAggregator sysCpuTime;
43 private MetricsAggregator userCpuTime;
44 private MetricsAggregator cpuIdleTime;
45 private MetricsAggregator memoryUsed;
46 private MetricsAggregator memoryFree;
Jian Li7d180c52016-02-01 21:53:08 -080047 private MetricsAggregator memoryUsedRatio;
48 private MetricsAggregator memoryFreeRatio;
Jian Lie044d1a2016-01-25 09:01:20 -080049 private Map<String, MetricsAggregator> diskReadBytes;
50 private Map<String, MetricsAggregator> diskWriteBytes;
51 private Map<String, MetricsAggregator> nwIncomingBytes;
52 private Map<String, MetricsAggregator> nwOutgoingBytes;
53 private Map<String, MetricsAggregator> nwIncomingPackets;
54 private Map<String, MetricsAggregator> nwOutgoingPackets;
55
56 private Map<DeviceId, MetricsAggregator> inboundPacket;
57 private Map<DeviceId, MetricsAggregator> outboundPacket;
58 private Map<DeviceId, MetricsAggregator> flowmodPacket;
59 private Map<DeviceId, MetricsAggregator> flowrmvPacket;
60 private Map<DeviceId, MetricsAggregator> requestPacket;
61 private Map<DeviceId, MetricsAggregator> replyPacket;
62 private Set<DeviceId> deviceIds = Sets.newConcurrentHashSet();
63 private Set<String> diskPartitions = Sets.newConcurrentHashSet();
64 private Set<String> nwInterfaces = Sets.newConcurrentHashSet();
Jian Li60804322015-12-02 14:46:31 -080065
Jian Lic5cb4a12016-02-03 23:24:42 -080066 /**
Jian Li1a424692016-02-03 16:21:18 -080067 * Initializes the control metrics factory instance using the given
68 * metric service and device service. Makes sure that we only initialize
69 * control metrics factory instance once.
Jian Lic5cb4a12016-02-03 23:24:42 -080070 *
71 * @param metricsService metric service
72 * @param deviceService device service
Jian Lic5cb4a12016-02-03 23:24:42 -080073 */
Jian Li1a424692016-02-03 16:21:18 -080074 public void initialization(MetricsService metricsService, DeviceService deviceService) {
75 synchronized (isInitialized) {
76 if (!isInitialized) {
77 this.metricsService = metricsService;
78 registerMetrics();
79 deviceService.getDevices().forEach(d->deviceIds.add(d.id()));
80 addAllControlMessageMetrics(deviceIds);
81 isInitialized = true;
Jian Li60804322015-12-02 14:46:31 -080082 }
83 }
Jian Lie044d1a2016-01-25 09:01:20 -080084 }
85
86 /**
Jian Li60804322015-12-02 14:46:31 -080087 * Adds control metrics of a new device.
88 *
Jian Lic5cb4a12016-02-03 23:24:42 -080089 * @param deviceId device identifier
Jian Li60804322015-12-02 14:46:31 -080090 */
Jian Lie044d1a2016-01-25 09:01:20 -080091 public void addControlMessageMetricsByDeviceId(DeviceId deviceId) {
Jian Li60804322015-12-02 14:46:31 -080092 MetricsAggregator inbound = new MetricsAggregator(metricsService,
Jian Li1a424692016-02-03 16:21:18 -080093 ControlMetricType.INBOUND_PACKET, Optional.of(deviceId));
Jian Li60804322015-12-02 14:46:31 -080094 MetricsAggregator outbound = new MetricsAggregator(metricsService,
Jian Li1a424692016-02-03 16:21:18 -080095 ControlMetricType.OUTBOUND_PACKET, Optional.of(deviceId));
Jian Li60804322015-12-02 14:46:31 -080096 MetricsAggregator flowmod = new MetricsAggregator(metricsService,
Jian Li1a424692016-02-03 16:21:18 -080097 ControlMetricType.FLOW_MOD_PACKET, Optional.of(deviceId));
Jian Li60804322015-12-02 14:46:31 -080098 MetricsAggregator flowrmv = new MetricsAggregator(metricsService,
Jian Li1a424692016-02-03 16:21:18 -080099 ControlMetricType.FLOW_REMOVED_PACKET, Optional.of(deviceId));
Jian Li60804322015-12-02 14:46:31 -0800100 MetricsAggregator request = new MetricsAggregator(metricsService,
Jian Li1a424692016-02-03 16:21:18 -0800101 ControlMetricType.REQUEST_PACKET, Optional.of(deviceId));
Jian Li60804322015-12-02 14:46:31 -0800102 MetricsAggregator reply = new MetricsAggregator(metricsService,
Jian Li1a424692016-02-03 16:21:18 -0800103 ControlMetricType.REPLY_PACKET, Optional.of(deviceId));
Jian Li60804322015-12-02 14:46:31 -0800104
Jian Lie044d1a2016-01-25 09:01:20 -0800105 inboundPacket.putIfAbsent(deviceId, inbound);
106 outboundPacket.putIfAbsent(deviceId, outbound);
107 flowmodPacket.putIfAbsent(deviceId, flowmod);
108 flowrmvPacket.putIfAbsent(deviceId, flowrmv);
109 requestPacket.putIfAbsent(deviceId, request);
110 replyPacket.putIfAbsent(deviceId, reply);
Jian Li60804322015-12-02 14:46:31 -0800111
112 deviceIds.add(deviceId);
113 }
114
115 /**
Jian Lie044d1a2016-01-25 09:01:20 -0800116 * Adds control metrics of a disk.
117 *
118 * @param partitionName disk partition name
119 */
120 public void addDiskMetricsByPartition(String partitionName) {
121 MetricsAggregator readBytes = new MetricsAggregator(metricsService,
Jian Li1a424692016-02-03 16:21:18 -0800122 ControlMetricType.DISK_READ_BYTES, partitionName);
Jian Lie044d1a2016-01-25 09:01:20 -0800123 MetricsAggregator writeBytes = new MetricsAggregator(metricsService,
124 ControlMetricType.DISK_WRITE_BYTES, partitionName);
125
126 diskReadBytes.putIfAbsent(partitionName, readBytes);
127 diskWriteBytes.putIfAbsent(partitionName, writeBytes);
128
129 diskPartitions.add(partitionName);
130 }
131
132 /**
133 * Adds control metrics of a ethernet interface.
134 *
135 * @param interfaceName network interface name
136 */
137 public void addNetworkMetricsByInterface(String interfaceName) {
138 MetricsAggregator incomingBytes = new MetricsAggregator(metricsService,
Jian Li1a424692016-02-03 16:21:18 -0800139 ControlMetricType.NW_INCOMING_BYTES, interfaceName);
Jian Lie044d1a2016-01-25 09:01:20 -0800140 MetricsAggregator outgoingBytes = new MetricsAggregator(metricsService,
141 ControlMetricType.NW_OUTGOING_BYTES, interfaceName);
142 MetricsAggregator incomingPackets = new MetricsAggregator(metricsService,
143 ControlMetricType.NW_INCOMING_PACKETS, interfaceName);
144 MetricsAggregator outgoingPackets = new MetricsAggregator(metricsService,
145 ControlMetricType.NW_OUTGOING_PACKETS, interfaceName);
146
147 nwIncomingBytes.putIfAbsent(interfaceName, incomingBytes);
148 nwOutgoingBytes.putIfAbsent(interfaceName, outgoingBytes);
149 nwIncomingPackets.putIfAbsent(interfaceName, incomingPackets);
150 nwOutgoingPackets.putIfAbsent(interfaceName, outgoingPackets);
151
152 nwInterfaces.add(interfaceName);
153 }
154
155 /**
Jian Li60804322015-12-02 14:46:31 -0800156 * Removes control metrics of an existing device.
157 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800158 * @param deviceId device identifier
Jian Li60804322015-12-02 14:46:31 -0800159 */
Jian Lie044d1a2016-01-25 09:01:20 -0800160 public void removeControlMessageMetricsByDeviceId(DeviceId deviceId) {
161 inboundPacket.remove(deviceId);
162 outboundPacket.remove(deviceId);
163 flowmodPacket.remove(deviceId);
164 flowrmvPacket.remove(deviceId);
165 requestPacket.remove(deviceId);
166 replyPacket.remove(deviceId);
Jian Li60804322015-12-02 14:46:31 -0800167
168 deviceIds.remove(deviceId);
169 }
170
Jian Lie044d1a2016-01-25 09:01:20 -0800171 /**
172 * Removes control metrics of a disk.
173 *
174 * @param partitionName disk partition name
175 */
176 public void removeDiskMetricsByResourceName(String partitionName) {
177 diskReadBytes.remove(partitionName);
178 diskWriteBytes.remove(partitionName);
179
180 diskPartitions.remove(partitionName);
181 }
182
183 /**
184 * Removes control metrics of a network interface.
185 *
186 * @param interfaceName network interface name
187 */
188 public void removeNetworkInterfacesByResourceName(String interfaceName) {
189 nwIncomingBytes.remove(interfaceName);
190 nwOutgoingBytes.remove(interfaceName);
191 nwIncomingPackets.remove(interfaceName);
192 nwOutgoingPackets.remove(interfaceName);
193
194 nwInterfaces.remove(interfaceName);
195 }
196
197 /**
Jian Lic5cb4a12016-02-03 23:24:42 -0800198 * Returns all device identifiers.
Jian Lie044d1a2016-01-25 09:01:20 -0800199 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800200 * @return a collection of device identifiers
Jian Lie044d1a2016-01-25 09:01:20 -0800201 */
Jian Li60804322015-12-02 14:46:31 -0800202 public Set<DeviceId> getDeviceIds() {
Jian Lie044d1a2016-01-25 09:01:20 -0800203 return ImmutableSet.copyOf(this.deviceIds);
204 }
205
206 /**
207 * Returns all disk partition names.
208 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800209 * @return a collection of disk partitions.
Jian Lie044d1a2016-01-25 09:01:20 -0800210 */
211 public Set<String> getDiskPartitions() {
212 return ImmutableSet.copyOf(this.diskPartitions);
213 }
214
215 /**
216 * Returns all network interface names.
217 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800218 * @return a collection of network interfaces.
Jian Lie044d1a2016-01-25 09:01:20 -0800219 */
220 public Set<String> getNetworkInterfaces() {
221 return ImmutableSet.copyOf(this.nwInterfaces);
Jian Li60804322015-12-02 14:46:31 -0800222 }
223
224 /**
225 * Adds control metrics for all devices.
226 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800227 * @param deviceIds a set of device identifiers
Jian Li60804322015-12-02 14:46:31 -0800228 */
Jian Lie044d1a2016-01-25 09:01:20 -0800229 public void addAllControlMessageMetrics(Set<DeviceId> deviceIds) {
230 deviceIds.forEach(v -> addControlMessageMetricsByDeviceId(v));
Jian Li60804322015-12-02 14:46:31 -0800231 }
232
233 /**
234 * Returns monitoring status.
235 *
236 * @return monitoring status
237 */
238 public boolean isMonitor() {
239 return this.enableMonitor;
240 }
241
242 /**
243 * Enable control plane monitoring.
244 */
245 protected void startMonitor() {
246 this.enableMonitor = true;
247 }
248
249 /**
250 * Disable control plane monitoring.
251 */
252 protected void stopMonitor() {
253 this.enableMonitor = false;
254 }
255
256 /**
257 * Registers new control metrics.
258 */
259 protected void registerMetrics() {
Jian Lie044d1a2016-01-25 09:01:20 -0800260 /* CPU */
261 cpuLoad = new MetricsAggregator(metricsService, ControlMetricType.CPU_LOAD);
262 totalCpuTime = new MetricsAggregator(metricsService, ControlMetricType.TOTAL_CPU_TIME);
263 sysCpuTime = new MetricsAggregator(metricsService, ControlMetricType.SYS_CPU_TIME);
264 userCpuTime = new MetricsAggregator(metricsService, ControlMetricType.USER_CPU_TIME);
265 cpuIdleTime = new MetricsAggregator(metricsService, ControlMetricType.CPU_IDLE_TIME);
Jian Li60804322015-12-02 14:46:31 -0800266
Jian Lie044d1a2016-01-25 09:01:20 -0800267 /* Memory */
268 memoryFree = new MetricsAggregator(metricsService, ControlMetricType.MEMORY_FREE);
269 memoryUsed = new MetricsAggregator(metricsService, ControlMetricType.MEMORY_USED);
Jian Li7d180c52016-02-01 21:53:08 -0800270 memoryFreeRatio = new MetricsAggregator(metricsService,
271 ControlMetricType.MEMORY_FREE_RATIO);
272 memoryUsedRatio = new MetricsAggregator(metricsService,
273 ControlMetricType.MEMORY_USED_RATIO);
Jian Lie044d1a2016-01-25 09:01:20 -0800274
275 /* Disk I/O */
276 diskReadBytes = new ConcurrentHashMap<>();
277 diskWriteBytes = new ConcurrentHashMap<>();
278
279 /* Network I/O */
280 nwIncomingBytes = new ConcurrentHashMap<>();
281 nwOutgoingBytes = new ConcurrentHashMap<>();
282 nwIncomingPackets = new ConcurrentHashMap<>();
283 nwOutgoingPackets = new ConcurrentHashMap<>();
284
285 /* OpenFlow Messages */
286 inboundPacket = new ConcurrentHashMap<>();
287 outboundPacket = new ConcurrentHashMap<>();
288 flowmodPacket = new ConcurrentHashMap<>();
289 flowrmvPacket = new ConcurrentHashMap<>();
290 requestPacket = new ConcurrentHashMap<>();
291 replyPacket = new ConcurrentHashMap<>();
Jian Li60804322015-12-02 14:46:31 -0800292 }
293
294 /**
295 * Unregisters all control metrics.
296 */
297 protected void unregisterMetrics() {
Jian Lie044d1a2016-01-25 09:01:20 -0800298 /* Disk I/O */
299 diskReadBytes.clear();
300 diskWriteBytes.clear();
Jian Li60804322015-12-02 14:46:31 -0800301
Jian Lie044d1a2016-01-25 09:01:20 -0800302 /* Network I/O */
303 nwIncomingBytes.clear();
304 nwOutgoingBytes.clear();
305 nwIncomingPackets.clear();
306 nwOutgoingPackets.clear();
307
308 /* OpenFlow Message */
309 inboundPacket.clear();
310 outboundPacket.clear();
311 flowmodPacket.clear();
312 flowrmvPacket.clear();
313 requestPacket.clear();
314 replyPacket.clear();
Jian Li60804322015-12-02 14:46:31 -0800315 }
316
Jian Lic5cb4a12016-02-03 23:24:42 -0800317 /**
318 * Returns CPU load metric aggregator.
319 *
320 * @return metric aggregator
321 */
Jian Lie044d1a2016-01-25 09:01:20 -0800322 public MetricsAggregator cpuLoadMetric() {
323 return cpuLoad;
Jian Li60804322015-12-02 14:46:31 -0800324 }
325
Jian Lic5cb4a12016-02-03 23:24:42 -0800326 /**
327 * Returns total CPU time metric aggregator.
328 *
329 * @return metric aggregator
330 */
Jian Lie044d1a2016-01-25 09:01:20 -0800331 public MetricsAggregator totalCpuTimeMetric() {
332 return totalCpuTime;
Jian Li60804322015-12-02 14:46:31 -0800333 }
334
Jian Lic5cb4a12016-02-03 23:24:42 -0800335 /**
336 * Returns system CPU time metric aggregator.
337 *
338 * @return metric aggregator
339 */
Jian Lie044d1a2016-01-25 09:01:20 -0800340 public MetricsAggregator sysCpuTimeMetric() {
341 return sysCpuTime;
Jian Li60804322015-12-02 14:46:31 -0800342 }
343
Jian Lic5cb4a12016-02-03 23:24:42 -0800344 /**
345 * Returns user CPU time metric aggregator.
346 *
347 * @return metric aggregator
348 */
Jian Lie044d1a2016-01-25 09:01:20 -0800349 public MetricsAggregator userCpuTime() {
350 return userCpuTime;
Jian Li60804322015-12-02 14:46:31 -0800351 }
352
Jian Lic5cb4a12016-02-03 23:24:42 -0800353 /**
354 * Returns CPU idle time metric aggregator.
355 *
356 * @return metric aggregator
357 */
Jian Lie044d1a2016-01-25 09:01:20 -0800358 public MetricsAggregator cpuIdleTime() {
359 return cpuIdleTime;
Jian Li60804322015-12-02 14:46:31 -0800360 }
361
Jian Lic5cb4a12016-02-03 23:24:42 -0800362 /**
363 * Returns free memory ratio metric aggregator.
364 *
365 * @return metric aggregator
366 */
Jian Li7d180c52016-02-01 21:53:08 -0800367 public MetricsAggregator memoryFreeRatio() {
368 return memoryFreeRatio;
Jian Li60804322015-12-02 14:46:31 -0800369 }
370
Jian Lic5cb4a12016-02-03 23:24:42 -0800371 /**
372 * Returns used memory ratio metric aggregator.
373 *
374 * @return metric aggregator
375 */
Jian Li7d180c52016-02-01 21:53:08 -0800376 public MetricsAggregator memoryUsedRatio() {
377 return memoryUsedRatio;
Jian Li60804322015-12-02 14:46:31 -0800378 }
379
Jian Lic5cb4a12016-02-03 23:24:42 -0800380 /**
381 * Returns disk read bytes metric aggregator.
382 *
383 * @param resourceName name of disk resource
384 * @return metric aggregator
385 */
386 public MetricsAggregator diskReadBytes(String resourceName) {
387 return diskReadBytes.get(resourceName);
Jian Li60804322015-12-02 14:46:31 -0800388 }
389
Jian Lic5cb4a12016-02-03 23:24:42 -0800390 /**
391 * Returns disk write bytes metric aggregator.
392 *
393 * @param resourceName name of disk resource
394 * @return metric aggregator
395 */
396 public MetricsAggregator diskWriteBytes(String resourceName) {
397 return diskWriteBytes.get(resourceName);
Jian Li60804322015-12-02 14:46:31 -0800398 }
399
Jian Lic5cb4a12016-02-03 23:24:42 -0800400 /**
401 * Returns incoming bytes metric aggregator.
402 *
403 * @param interfaceName name of network interface
404 * @return metric aggregator
405 */
Jian Lie044d1a2016-01-25 09:01:20 -0800406 public MetricsAggregator nwIncomingBytes(String interfaceName) {
407 return nwIncomingBytes.get(interfaceName);
Jian Li60804322015-12-02 14:46:31 -0800408 }
409
Jian Lic5cb4a12016-02-03 23:24:42 -0800410 /**
411 * Returns outgoing bytes metric aggregator.
412 *
413 * @param interfaceName name of network interface
414 * @return metric aggregator
415 */
Jian Lie044d1a2016-01-25 09:01:20 -0800416 public MetricsAggregator nwOutgoingBytes(String interfaceName) {
417 return nwOutgoingBytes.get(interfaceName);
Jian Li60804322015-12-02 14:46:31 -0800418 }
419
Jian Lic5cb4a12016-02-03 23:24:42 -0800420 /**
421 * Returns incoming packets metric aggregator.
422 *
423 * @param interfaceName name of network interface
424 * @return metric aggregator
425 */
Jian Lie044d1a2016-01-25 09:01:20 -0800426 public MetricsAggregator nwIncomingPackets(String interfaceName) {
427 return nwIncomingPackets.get(interfaceName);
Jian Li60804322015-12-02 14:46:31 -0800428 }
429
Jian Lic5cb4a12016-02-03 23:24:42 -0800430 /**
431 * Returns outgoing packets metric aggregator.
432 *
433 * @param interfaceName name of network interface
434 * @return metric aggregator
435 */
Jian Lie044d1a2016-01-25 09:01:20 -0800436 public MetricsAggregator nwOutgoingPackets(String interfaceName) {
437 return nwOutgoingPackets.get(interfaceName);
Jian Li60804322015-12-02 14:46:31 -0800438 }
439
Jian Lic5cb4a12016-02-03 23:24:42 -0800440 /**
441 * Returns inbound packet metric aggregator of all devices.
442 *
443 * @return metric aggregator
444 */
Jian Lie044d1a2016-01-25 09:01:20 -0800445 public Map<DeviceId, MetricsAggregator> inboundPacket() {
446 return ImmutableMap.copyOf(inboundPacket);
447 }
448
Jian Lic5cb4a12016-02-03 23:24:42 -0800449 /**
450 * Returns outgoing packet metric aggregator of all devices.
451 *
452 * @return metric aggregator
453 */
Jian Lie044d1a2016-01-25 09:01:20 -0800454 public Map<DeviceId, MetricsAggregator> outboundPacket() {
455 return ImmutableMap.copyOf(outboundPacket);
456 }
457
Jian Lic5cb4a12016-02-03 23:24:42 -0800458 /**
459 * Returns flow-mod packet metric aggregator of all devices.
460 *
461 * @return metric aggregator
462 */
Jian Lie044d1a2016-01-25 09:01:20 -0800463 public Map<DeviceId, MetricsAggregator> flowmodPacket() {
464 return ImmutableMap.copyOf(flowmodPacket);
465 }
466
Jian Lic5cb4a12016-02-03 23:24:42 -0800467 /**
468 * Returns flow-removed packet metric aggregator of all devices.
469 *
470 * @return metric aggregator
471 */
Jian Lie044d1a2016-01-25 09:01:20 -0800472 public Map<DeviceId, MetricsAggregator> flowrmvPacket() {
473 return ImmutableMap.copyOf(flowrmvPacket);
474 }
475
Jian Lic5cb4a12016-02-03 23:24:42 -0800476 /**
477 * Returns request packet metric aggregator of all devices.
478 *
479 * @return metric aggregator
480 */
Jian Lie044d1a2016-01-25 09:01:20 -0800481 public Map<DeviceId, MetricsAggregator> requestPacket() {
482 return ImmutableMap.copyOf(requestPacket);
483 }
484
Jian Lic5cb4a12016-02-03 23:24:42 -0800485 /**
486 * Returns reply packet metric aggregator of all devices.
487 *
488 * @return metric aggregator
489 */
Jian Lie044d1a2016-01-25 09:01:20 -0800490 public Map<DeviceId, MetricsAggregator> replyPacket() {
491 return ImmutableMap.copyOf(replyPacket);
492 }
493
Jian Lic5cb4a12016-02-03 23:24:42 -0800494 /**
495 * Returns inbound packet metric aggregator of a specified device.
496 *
497 * @param deviceId device identifier
498 * @return metric aggregator
499 */
Jian Lie044d1a2016-01-25 09:01:20 -0800500 public MetricsAggregator inboundPacket(DeviceId deviceId) {
501 return inboundPacket.get(deviceId);
502 }
503
Jian Lic5cb4a12016-02-03 23:24:42 -0800504 /**
505 * Returns outbound packet metric aggregator of a specified device.
506 *
507 * @param deviceId device identifier
508 * @return metric aggregator
509 */
Jian Lie044d1a2016-01-25 09:01:20 -0800510 public MetricsAggregator outboundPacket(DeviceId deviceId) {
511 return outboundPacket.get(deviceId);
512 }
513
Jian Lic5cb4a12016-02-03 23:24:42 -0800514 /**
515 * Returns flow-mod packet metric aggregator of a specified device.
516 *
517 * @param deviceId device identifier
518 * @return metric aggregator
519 */
Jian Lie044d1a2016-01-25 09:01:20 -0800520 public MetricsAggregator flowmodPacket(DeviceId deviceId) {
521 return flowmodPacket.get(deviceId);
522 }
523
Jian Lic5cb4a12016-02-03 23:24:42 -0800524 /**
525 * Returns flow-removed packet metric aggregator of a specified device.
526 *
527 * @param deviceId device identifier
528 * @return metric aggregator
529 */
Jian Lie044d1a2016-01-25 09:01:20 -0800530 public MetricsAggregator flowrmvPacket(DeviceId deviceId) {
531 return flowrmvPacket.get(deviceId);
532 }
533
Jian Lic5cb4a12016-02-03 23:24:42 -0800534 /**
535 * Returns request packet metric aggregator of a specified device.
536 *
537 * @param deviceId device identifier
538 * @return metric aggregator
539 */
Jian Lie044d1a2016-01-25 09:01:20 -0800540 public MetricsAggregator requestPacket(DeviceId deviceId) {
541 return requestPacket.get(deviceId);
542 }
543
Jian Lic5cb4a12016-02-03 23:24:42 -0800544 /**
545 * Returns reply packet metric aggregator of a specified device.
546 *
547 * @param deviceId device identifier
548 * @return metric aggregator
549 */
Jian Lie044d1a2016-01-25 09:01:20 -0800550 public MetricsAggregator replyPacket(DeviceId deviceId) {
551 return replyPacket.get(deviceId);
Jian Li60804322015-12-02 14:46:31 -0800552 }
Jian Li1a424692016-02-03 16:21:18 -0800553
554 /**
555 * Returns an instance of control metrics factory.
556 *
557 * @return instance of control metrics factory
558 */
559 public static ControlMetricsFactory getInstance() {
560 return SingletonHelper.INSTANCE;
561 }
562
563 private static class SingletonHelper {
564 private static final ControlMetricsFactory INSTANCE = new ControlMetricsFactory();
565 }
Jian Li60804322015-12-02 14:46:31 -0800566}