package org.opendaylight.affinity.analytics.northbound;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
-import java.util.HashMap;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@XmlAccessorType(XmlAccessType.NONE)
public class AllStatistics {
@XmlElement
- private Map<Byte, Statistics> data;
+ private List<ProtocolStatistics> stats;
- public AllStatistics() {
- super();
- this.data = new HashMap<Byte, Statistics>();
+ // To satisfy JAXB
+ @SuppressWarnings("unused")
+ private AllStatistics() {
}
- public void addStat(Byte proto, Statistics stat) {
- this.data.put(proto, stat);
+ public AllStatistics(Map<Byte, Long> byteCounts, Map<Byte, Double> bitRates) {
+ this.stats = new ArrayList<ProtocolStatistics>();
+ for (Byte protocol : byteCounts.keySet()) {
+ long byteCount = byteCounts.get(protocol);
+ double bitRate = bitRates.get(protocol);
+ this.stats.add(new ProtocolStatistics(protocol, new Statistics(byteCount, bitRate)));
+ }
+ }
+
+ public List<ProtocolStatistics> getStats() {
+ return this.stats;
+ }
+
+ public void setStats(List<ProtocolStatistics> stats) {
+ this.stats = stats;
}
}
package org.opendaylight.affinity.analytics.northbound;
-import java.lang.Long;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Map;
-import java.util.HashMap;
-import java.util.ArrayList;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
Host dstHost = handleHostAvailability(containerName, dstIP);
Map<Byte, Long> byteCounts = analyticsManager.getAllByteCounts(srcHost, dstHost);
Map<Byte, Double> bitRates = analyticsManager.getAllBitRates(srcHost, dstHost);
- AllStatistics allStats = new AllStatistics();
- for (Byte protocol : byteCounts.keySet())
- allStats.addStat(protocol, new Statistics(byteCounts.get(protocol), bitRates.get(protocol)));
- return allStats;
+ return new AllStatistics(byteCounts, bitRates);
}
/**
AffinityLink al = handleAffinityLinkAvailability(containerName, affinityLinkName);
Map<Byte, Long> byteCounts = analyticsManager.getAllByteCounts(al);
Map<Byte, Double> bitRates = analyticsManager.getAllBitRates(al);
- AllStatistics allStats = new AllStatistics();
- for (Byte protocol : byteCounts.keySet())
- allStats.addStat(protocol, new Statistics(byteCounts.get(protocol), bitRates.get(protocol)));
- return allStats;
+ return new AllStatistics(byteCounts, bitRates);
}
/**
Map<Byte, Long> byteCounts = analyticsManager.getAllByteCounts(srcString, dstString);
Map<Byte, Double> bitRates = analyticsManager.getAllBitRates(srcString, dstString);
- AllStatistics allStats = new AllStatistics();
- for (Byte protocol : byteCounts.keySet())
- allStats.addStat(protocol, new Statistics(byteCounts.get(protocol), bitRates.get(protocol)));
- return allStats;
+ return new AllStatistics(byteCounts, bitRates);
}
/**
--- /dev/null
+/*
+ * Copyright (c) 2013 Plexxi, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.affinity.analytics.northbound;
+
+import java.net.InetAddress;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class HostStatistics {
+ @XmlElement
+ private String hostIP;
+ @XmlElement
+ private Long byteCount;
+
+ // To satisfy JAXB
+ @SuppressWarnings("unused")
+ private HostStatistics() {
+ }
+
+ public HostStatistics(InetAddress hostIP, Long byteCount) {
+ this.hostIP = hostIP.toString();
+ this.byteCount = byteCount;
+ }
+
+ public String getHostIP() {
+ return this.hostIP;
+ }
+
+ public void setHostIP(String hostIP) {
+ this.hostIP = hostIP;
+ }
+
+ public Long getByteCount() {
+ return this.byteCount;
+ }
+
+ public void setByteCount(Long byteCount) {
+ this.byteCount = byteCount;
+ }
+}
package org.opendaylight.affinity.analytics.northbound;
import java.net.InetAddress;
-import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import org.opendaylight.controller.sal.core.Host;
@XmlAccessorType(XmlAccessType.NONE)
public class IncomingHostData {
@XmlElement
- Map<String, Long> data;
- // TODO: There is a better way to serialize a map
+ List<HostStatistics> stats;
@SuppressWarnings("unused") // To satisfy JAXB
private IncomingHostData() {}
public IncomingHostData(Map<Host, Long> hostData) {
- this.data = new HashMap<String, Long>();
+ this.stats = new ArrayList<HostStatistics>();
for (Host h : hostData.keySet())
- this.data.put(h.getNetworkAddress().toString(), hostData.get(h));
+ this.stats.add(new HostStatistics(h.getNetworkAddress(), hostData.get(h)));
}
- public Map<String, Long> getData() {
- return this.data;
+ public List<HostStatistics> getStats() {
+ return this.stats;
+ }
+
+ public void setStats(List<HostStatistics> stats) {
+ this.stats = stats;
}
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Plexxi, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.affinity.analytics.northbound;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class ProtocolStatistics {
+ @XmlElement
+ private byte protocol;
+ @XmlElement
+ private Statistics stat;
+
+ // To satisfy JAXB
+ @SuppressWarnings("unused")
+ private ProtocolStatistics() {
+ }
+
+ public ProtocolStatistics(byte protocol, Statistics stat) {
+ super();
+ this.protocol = protocol;
+ this.stat = stat;
+ }
+
+ public long getProtocol() {
+ return this.protocol;
+ }
+
+ public void setProtocol(Byte protocol) {
+ this.protocol = protocol;
+ }
+
+ public Statistics getStat() {
+ return this.stat;
+ }
+
+ public void setStat(Statistics stat) {
+ this.stat = stat;
+ }
+}
def all_stats_hosts(src, dst):
url = "http://localhost:8080/affinity/nb/v2/analytics/default/hoststats/%s/%s/all" % (src, dst)
- data = rest_method(url, "GET")['data']['entry']
- if (type(data) == type({})):
- host = data['key']
- byte_count = data['value']
- print("%s bytes from host %s" % (byte_count, host))
- else:
- for entry in data:
- protocol = entry['key']
- byte_count = entry['value']['byteCount']
- bit_rate = entry['value']['bitRate']
- print("%s bytes from protocol %s" % (byte_count, protocol))
- print("%s bit/s from protocol %s" % (bit_rate, protocol))
+ data = rest_method(url, "GET")['stats']
+ for entry in data:
+ print("%s bytes from protocol %s" % (entry['stat']['byteCount'], entry['protocol']))
+ print("%s bit/s from protocol %s" % (entry['stat']['bitRate'], entry['protocol']))
### Affinity link statistics
def all_stats_link(al):
url = "http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/%s/all" % al
- data = rest_method(url, "GET")['data']['entry']
- if (type(data) == type({})):
- host = data['key']
- byte_count = data['value']
- print("%s bytes from host %s" % (byte_count, host))
- else:
- for entry in data:
- protocol = entry['key']
- byte_count = entry['value']['byteCount']
- bit_rate = entry['value']['bitRate']
- print("%s bytes from protocol %s" % (byte_count, protocol))
- print("%s bit/s from protocol %s" % (bit_rate, protocol))
+ data = rest_method(url, "GET")['stats']
+ for entry in data:
+ print("%s bytes from protocol %s" % (entry['stat']['byteCount'], entry['protocol']))
+ print("%s bit/s from protocol %s" % (entry['stat']['bitRate'], entry['protocol']))
### Subnet statistics
def all_stats_subnet(src_sub, dst_sub):
url = "http://localhost:8080/affinity/nb/v2/analytics/default/subnetstats/%s/%s/all" % (src_sub, dst_sub)
- data = rest_method(url, "GET")['data']['entry']
- if (type(data) == type({})):
- host = data['key']
- byte_count = data['value']
- print("%s bytes from host %s" % (byte_count, host))
- else:
- for entry in data:
- protocol = entry['key']
- byte_count = entry['value']['byteCount']
- bit_rate = entry['value']['bitRate']
- print("%s bytes from protocol %s" % (byte_count, protocol))
- print("%s bit/s from protocol %s" % (bit_rate, protocol))
+ data = rest_method(url, "GET")['stats']
+ for entry in data:
+ print("%s bytes from protocol %s" % (entry['stat']['byteCount'], entry['protocol']))
+ print("%s bit/s from protocol %s" % (entry['stat']['bitRate'], entry['protocol']))
def incoming_hosts(subnet):
url = "http://localhost:8080/affinity/nb/v2/analytics/default/subnetstats/incoming/%s" % subnet
- data = rest_method(url, "GET")['data']['entry']
+ data = rest_method(url, "GET")
+ data = rest_method(url, "GET")['stats']
if (type(data) == type({})):
- host = data['key']
- byte_count = data['value']
- print("%s bytes from host %s" % (byte_count, host))
- else:
- for entry in data:
- host = entry['key']
- byte_count = entry['value']
- print("%s bytes from host %s" % (byte_count, host))
+ data = [data]
+ for entry in data:
+ print("%s bytes from host %s" % (entry['byteCount'], entry['hostIP']))
def incoming_hosts_protocol(subnet, protocol):
url = "http://localhost:8080/affinity/nb/v2/analytics/default/subnetstats/incoming/%s/%s" % (subnet, protocol)
data = rest_method(url, "GET")['data']['entry']
if (type(data) == type({})):
- host = data['key']
- byte_count = data['value']
- print("%s bytes from host %s" % (byte_count, host))
- else:
- for entry in data:
- host = entry['key']
- byte_count = entry['value']
- print("%s bytes from host %s" % (byte_count, host))
+ data = [data]
+ for entry in data:
+ print("%s bytes from host %s" % (entry['byteCount'], entry['hostIP']))
def run_interactive_mode():
# Demo mode
while True:
+
request = raw_input("> ")
request = request.split()
request_type = request[0]