From bc7ce8a19164aa080fd96a9d355aa96e4dc3152e Mon Sep 17 00:00:00 2001 From: Katrina LaCurts Date: Mon, 9 Dec 2013 15:18:30 -0500 Subject: [PATCH] NB API for packet count statistics. analytics.py demonstrates how to use it. Signed-off-by: Katrina LaCurts --- .../analytics/northbound/AllStatistics.java | 6 ++- .../northbound/AnalyticsNorthbound.java | 37 ++++++++++---- .../analytics/northbound/Statistics.java | 24 ++++++++- scripts/analytics.py | 51 +++++-------------- 4 files changed, 68 insertions(+), 50 deletions(-) diff --git a/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AllStatistics.java b/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AllStatistics.java index 964e3df..87037f1 100644 --- a/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AllStatistics.java +++ b/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AllStatistics.java @@ -28,12 +28,14 @@ public class AllStatistics { private AllStatistics() { } - public AllStatistics(Map byteCounts, Map bitRates) { + public AllStatistics(Map byteCounts, Map packetCounts, Map durations, Map bitRates) { this.stats = new ArrayList(); for (Byte protocol : byteCounts.keySet()) { long byteCount = byteCounts.get(protocol); + long packetCount = packetCounts.get(protocol); + double duration = durations.get(protocol); double bitRate = bitRates.get(protocol); - this.stats.add(new ProtocolStatistics(protocol, new Statistics(byteCount, bitRate))); + this.stats.add(new ProtocolStatistics(protocol, new Statistics(byteCount, packetCount, duration, bitRate))); } } diff --git a/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AnalyticsNorthbound.java b/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AnalyticsNorthbound.java index d539cfc..5ddaa5a 100644 --- a/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AnalyticsNorthbound.java +++ b/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/AnalyticsNorthbound.java @@ -121,9 +121,11 @@ public class AnalyticsNorthbound { Host srcHost = handleHostAvailability(containerName, srcNetworkAddr); Host dstHost = handleHostAvailability(containerName, dstNetworkAddr); long byteCount = analyticsManager.getByteCount(srcHost, dstHost); + long packetCount = analyticsManager.getPacketCount(srcHost, dstHost); + double duration = analyticsManager.getDuration(srcHost, dstHost); double bitRate = analyticsManager.getBitRate(srcHost, dstHost); - return new Statistics(byteCount, bitRate); + return new Statistics(byteCount, packetCount, duration, bitRate); } /** @@ -157,9 +159,11 @@ public class AnalyticsNorthbound { Host srcHost = handleHostAvailability(containerName, srcIP); Host dstHost = handleHostAvailability(containerName, dstIP); long byteCount = analyticsManager.getByteCount(srcHost, dstHost, IPProtocols.getProtocolNumberByte(protocol)); + long packetCount = analyticsManager.getPacketCount(srcHost, dstHost, IPProtocols.getProtocolNumberByte(protocol)); + double duration = analyticsManager.getDuration(srcHost, dstHost, IPProtocols.getProtocolNumberByte(protocol)); double bitRate = analyticsManager.getBitRate(srcHost, dstHost, IPProtocols.getProtocolNumberByte(protocol)); - return new Statistics(byteCount, bitRate); + return new Statistics(byteCount, packetCount, duration, bitRate); } /** @@ -191,8 +195,10 @@ public class AnalyticsNorthbound { Host srcHost = handleHostAvailability(containerName, srcIP); Host dstHost = handleHostAvailability(containerName, dstIP); Map byteCounts = analyticsManager.getAllByteCounts(srcHost, dstHost); + Map packetCounts = analyticsManager.getAllPacketCounts(srcHost, dstHost); + Map durations = analyticsManager.getAllDurations(srcHost, dstHost); Map bitRates = analyticsManager.getAllBitRates(srcHost, dstHost); - return new AllStatistics(byteCounts, bitRates); + return new AllStatistics(byteCounts, packetCounts, durations, bitRates); } /** @@ -221,9 +227,11 @@ public class AnalyticsNorthbound { AffinityLink al = handleAffinityLinkAvailability(containerName, affinityLinkName); long byteCount = analyticsManager.getByteCount(al); + long packetCount = analyticsManager.getPacketCount(al); + double duration = analyticsManager.getDuration(al); double bitRate = analyticsManager.getBitRate(al); - return new Statistics(byteCount, bitRate); + return new Statistics(byteCount, packetCount, duration, bitRate); } /** @@ -254,9 +262,11 @@ public class AnalyticsNorthbound { AffinityLink al = handleAffinityLinkAvailability(containerName, affinityLinkName); long byteCount = analyticsManager.getByteCount(al, IPProtocols.getProtocolNumberByte(protocol)); + long packetCount = analyticsManager.getPacketCount(al, IPProtocols.getProtocolNumberByte(protocol)); + double duration = analyticsManager.getDuration(al, IPProtocols.getProtocolNumberByte(protocol)); double bitRate = analyticsManager.getBitRate(al, IPProtocols.getProtocolNumberByte(protocol)); - return new Statistics(byteCount, bitRate); + return new Statistics(byteCount, packetCount, duration, bitRate); } /** @@ -285,8 +295,10 @@ public class AnalyticsNorthbound { AffinityLink al = handleAffinityLinkAvailability(containerName, affinityLinkName); Map byteCounts = analyticsManager.getAllByteCounts(al); + Map packetCounts = analyticsManager.getAllPacketCounts(al); + Map durations = analyticsManager.getAllDurations(al); Map bitRates = analyticsManager.getAllBitRates(al); - return new AllStatistics(byteCounts, bitRates); + return new AllStatistics(byteCounts, packetCounts, durations, bitRates); } /** @@ -327,9 +339,11 @@ public class AnalyticsNorthbound { if (dstString.equals("null/null")) dstString = null; long byteCount = analyticsManager.getByteCount(srcString, dstString); + long packetCount = analyticsManager.getPacketCount(srcString, dstString); + double duration = analyticsManager.getDuration(srcString, dstString); double bitRate = analyticsManager.getBitRate(srcString, dstString); - return new Statistics(byteCount, bitRate); + return new Statistics(byteCount, packetCount, duration, bitRate); } /** @@ -372,10 +386,13 @@ public class AnalyticsNorthbound { if (dstString.equals("null/null")) dstString = null; long byteCount = analyticsManager.getByteCount(srcString, dstString, IPProtocols.getProtocolNumberByte(protocol)); + long packetCount = analyticsManager.getByteCount(srcString, dstString, IPProtocols.getProtocolNumberByte(protocol)); + double duration = analyticsManager.getDuration(srcString, dstString, IPProtocols.getProtocolNumberByte(protocol)); double bitRate = analyticsManager.getBitRate(srcString, dstString, IPProtocols.getProtocolNumberByte(protocol)); - return new Statistics(byteCount, bitRate); + return new Statistics(byteCount, packetCount, duration, bitRate); } + /** * @param containerName: Name of the Container * @param srcIP: Source IP prefix @@ -415,8 +432,10 @@ public class AnalyticsNorthbound { dstString = null; Map byteCounts = analyticsManager.getAllByteCounts(srcString, dstString); + Map packetCounts = analyticsManager.getAllPacketCounts(srcString, dstString); + Map durations = analyticsManager.getAllDurations(srcString, dstString); Map bitRates = analyticsManager.getAllBitRates(srcString, dstString); - return new AllStatistics(byteCounts, bitRates); + return new AllStatistics(byteCounts, packetCounts, durations, bitRates); } /** diff --git a/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/Statistics.java b/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/Statistics.java index 5e91112..b025d60 100644 --- a/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/Statistics.java +++ b/analytics/northbound/src/main/java/org/opendaylight/affinity/analytics/northbound/Statistics.java @@ -19,6 +19,10 @@ public class Statistics { @XmlElement private long byteCount; @XmlElement + private long packetCount; + @XmlElement + private double duration; + @XmlElement private double bitRate; // To satisfy JAXB @@ -26,9 +30,11 @@ public class Statistics { private Statistics() { } - public Statistics(long byteCount, double bitRate) { + public Statistics(long byteCount, long packetCount, double duration, double bitRate) { super(); this.byteCount = byteCount; + this.packetCount = packetCount; + this.duration = duration; this.bitRate = bitRate; } @@ -40,6 +46,22 @@ public class Statistics { this.byteCount = byteCount; } + public long getPacketCount() { + return this.packetCount; + } + + public void setPacketCount(long packetCount) { + this.packetCount = packetCount; + } + + public double getDuration() { + return this.duration; + } + + public void setDuration(double duration) { + this.duration = duration; + } + public double getBitRate() { return this.bitRate; } diff --git a/scripts/analytics.py b/scripts/analytics.py index 02bc1a6..3bebdaf 100644 --- a/scripts/analytics.py +++ b/scripts/analytics.py @@ -54,93 +54,69 @@ class Flow: def rest_method(url, rest_type, payload=None): if (rest_type == "GET"): resp = requests.get(url, auth=('admin', 'admin')) - print "status:", resp.status_code return resp.json() elif (rest_type == "PUT"): headers = {'content-type': 'application/json'} resp = requests.put(url, auth=('admin', 'admin'), data=json.dumps(payload), headers=headers) - print "status:", resp.status_code, resp.text elif (rest_type == "DELETE"): resp = requests.delete(url, auth=('admin', 'admin')) - print "status:", resp.status_code - ### Host Statistics def stats_hosts(src, dst): url = "http://localhost:8080/affinity/nb/v2/analytics/default/hoststats/%s/%s" % (src, dst) data = rest_method(url, "GET") - print("%s bytes between %s and %s" % (data["byteCount"], src, dst)) - print("%s bit/s between %s and %s" % (data["bitRate"], src, dst)) + print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"])) def stats_hosts_protocol(src, dst, protocol): url = "http://localhost:8080/affinity/nb/v2/analytics/default/hoststats/%s/%s/%d" % (src, dst, protocol) data = rest_method(url, "GET") - print("%s bytes between %s and %s for protocol %d" % (data["byteCount"], src, dst, protocol)) - print("%s bit/s between %s and %s on protocol %d" % (data["bitRate"], src, dst, protocol)) + print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"])) 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")['stats'] + 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'])) + stat = entry["stat"] + print("protocol %s: %s bytes (%s packets) over %s seconds (%s bit/s)" % (entry["protocol"], stat["byteCount"], stat["packetCount"], stat["duration"], stat["bitRate"])) ### Affinity link statistics def stats_link(al): url = "http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/%s" % al data = rest_method(url, "GET") - print("%s bytes on link %s" % (data['byteCount'], al)) - print("%s bit/s on link %s" % (data['bitRate'], al)) + print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"])) def stats_link_protocol(al, protocol): url = "http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/%s/%s" % (al, protocol) data = rest_method(url, "GET") - print("%s bytes on link %s for protocol %s" % (data['byteCount'], al, protocol)) - print("%s bit/s on link %s for protocol %s" % (data['bitRate'], al, protocol)) + print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"])) def all_stats_link(al): url = "http://localhost:8080/affinity/nb/v2/analytics/default/affinitylinkstats/%s/all" % al 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'])) + stat = entry["stat"] + print("protocol %s: %s bytes (%s packets) over %s seconds (%s bit/s)" % (entry["protocol"], stat["byteCount"], stat["packetCount"], stat["duration"], stat["bitRate"])) ### Subnet statistics def stats_subnet(src_sub, dst_sub): url = "http://localhost:8080/affinity/nb/v2/analytics/default/subnetstats/%s/%s" % (src_sub, dst_sub) data = rest_method(url, "GET") - if (src_sub == "null/null"): - print("%s bytes into %s" % (data['byteCount'], dst_sub)) - print("%s bit/s into %s" % (data['bitRate'], dst_sub)) - elif (dst_sub == "null/null"): - print("%s bytes out of %s" % (data['byteCount'], src_sub)) - print("%s bit/s out of %s" % (data['bitRate'], src_sub)) - else: - print("%s bytes between %s and %s" % (data['byteCount'], src_sub, dst_sub)) - print("%s bit/s between %s and %s" % (data['bitRate'], src_sub, dst_sub)) + print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"])) def stats_subnet_protocol(src_sub, dst_sub, protocol): url = "http://localhost:8080/affinity/nb/v2/analytics/default/subnetstats/%s/%s/%s" % (src_sub, dst_sub, protocol) data = rest_method(url, "GET") - if (src_sub == "null/null"): - print("%s bytes into %s from protocol %s" % (data['byteCount'], dst_sub, protocol)) - print("%s bit/s into %s from protocol %s" % (data['bitRate'], dst_sub, protocol)) - elif (dst_sub == "null/null"): - print("%s bytes out of %s from protocol %s" % (data['byteCount'], src_sub, protocol)) - print("%s bit/s out of %s from protocol %s" % (data['bitRate'], src_sub, protocol)) - else: - print("%s bytes between %s and %s from protocol %s" % (data['byteCount'], src_sub, dst_sub, protocol)) - print("%s bit/s between %s and %s from protocol %s" % (data['bitRate'], src_sub, dst_sub, protocol)) + print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"])) 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")['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'])) + stat = entry["stat"] + print("protocol %s: %s bytes (%s packets) over %s seconds (%s bit/s)" % (entry["protocol"], stat["byteCount"], stat["packetCount"], stat["duration"], stat["bitRate"])) def incoming_hosts(subnet): url = "http://localhost:8080/affinity/nb/v2/analytics/default/subnetstats/incoming/%s" % subnet @@ -186,7 +162,6 @@ def get_flows(): return flows def add_flow(flow, flow_name): - print "adding flow %s" % flow_name url = "http://localhost:8080/controller/nb/v2/flowprogrammer/default/node/OF/%s/staticFlow/%s" % (flow.node_id, flow_name) rest_method(url, "PUT", flow.get_json(flow_name)) -- 2.36.6