NB API for packet count statistics. analytics.py demonstrates how to use it.
[affinity.git] / analytics / northbound / src / main / java / org / opendaylight / affinity / analytics / northbound / AllStatistics.java
1 /*
2  * Copyright (c) 2013 Plexxi, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.affinity.analytics.northbound;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Map;
14
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlRootElement;
19
20 @XmlRootElement
21 @XmlAccessorType(XmlAccessType.NONE)
22 public class AllStatistics {
23     @XmlElement
24     private List<ProtocolStatistics> stats;
25
26     // To satisfy JAXB
27     @SuppressWarnings("unused")
28     private AllStatistics() {
29     }
30
31     public AllStatistics(Map<Byte, Long> byteCounts, Map<Byte, Long> packetCounts, Map<Byte, Double> durations, Map<Byte, Double> bitRates) {
32         this.stats = new ArrayList<ProtocolStatistics>();
33         for (Byte protocol : byteCounts.keySet()) {
34             long byteCount = byteCounts.get(protocol);
35             long packetCount = packetCounts.get(protocol);
36             double duration = durations.get(protocol);
37             double bitRate = bitRates.get(protocol);
38             this.stats.add(new ProtocolStatistics(protocol, new Statistics(byteCount, packetCount, duration, bitRate)));
39         }
40     }
41
42     public List<ProtocolStatistics> getStats() {
43         return this.stats;
44     }
45
46     public void setStats(List<ProtocolStatistics> stats) {
47         this.stats = stats;
48     }
49 }