// Host pair statistics
long getByteCount(Host src, Host dst);
long getByteCount(Host src, Host dst, Byte protocol);
+ long getPacketCount(Host src, Host dst);
+ long getPacketCount(Host src, Host dst, Byte protocol);
double getDuration(Host src, Host dst);
double getDuration(Host src, Host dst, Byte protocol);
double getBitRate(Host src, Host dst);
double getBitRate(Host src, Host dst, Byte protocol);
Map<Byte, Long> getAllByteCounts(Host src, Host dst);
+ Map<Byte, Long> getAllPacketCounts(Host src, Host dst);
+ Map<Byte, Double> getAllDurations(Host src, Host dst);
Map<Byte, Double> getAllBitRates(Host src, Host dst);
// AffinityLink statistics
long getByteCount(AffinityLink al);
long getByteCount(AffinityLink al, Byte protocol);
+ long getPacketCount(AffinityLink al);
+ long getPacketCount(AffinityLink al, Byte protocol);
double getDuration(AffinityLink al);
double getDuration(AffinityLink al, Byte protocol);
double getBitRate(AffinityLink al);
double getBitRate(AffinityLink al, Byte protocol);
Map<Byte, Long> getAllByteCounts(AffinityLink al);
+ Map<Byte, Long> getAllPacketCounts(AffinityLink al);
+ Map<Byte, Double> getAllDurations(AffinityLink al);
Map<Byte, Double> getAllBitRates(AffinityLink al);
// Subnet statistics
long getByteCount(String srcSubnet, String dstSubnet);
long getByteCount(String srcSubnet, String dstSubnet, Byte protocol);
+ long getPacketCount(String srcSubnet, String dstSubnet);
+ long getPacketCount(String srcSubnet, String dstSubnet, Byte protocol);
double getDuration(String srcSubnet, String dstSubnet);
double getDuration(String srcSubnet, String dstSubnet, Byte protocol);
double getBitRate(String srcSubnet, String dstSubnet);
double getBitRate(String srcSubnet, String dstSubnet, Byte protocol);
Map<Byte, Long> getAllByteCounts(String srcSubnet, String dstSubnet);
+ Map<Byte, Long> getAllPacketCounts(String srcSubnet, String dstSubnet);
+ Map<Byte, Double> getAllDurations(String srcSubnet, String dstSubnet);
Map<Byte, Double> getAllBitRates(String srcSubnet, String dstSubnet);
// Miscellaneous
return srcHost;
}
+ /* Return all protocols used between two sets */
+ protected Set<Byte> getProtocols(Set<Host> srcSet, Set<Host> dstSet) {
+ Set<Byte> protocols = new HashSet<Byte>();
+ for (Host src : srcSet) {
+ for (Host dst : dstSet) {
+ if (this.hostsToStats.get(src) != null &&
+ this.hostsToStats.get(src).get(dst) != null) {
+ protocols.addAll(this.hostsToStats.get(src).get(dst).getProtocols());
+ }
+ }
+ }
+ return protocols;
+ }
+
/* Return the number of bytes transferred between two sets,
* per-protocol (across all protocols if protocol is null).*/
protected long getByteCount(Set<Host> srcSet, Set<Host> dstSet, Byte protocol) {
return byteCount;
}
- /* Return all protocols used between two sets */
- protected Set<Byte> getProtocols(Set<Host> srcSet, Set<Host> dstSet) {
- Set<Byte> protocols = new HashSet<Byte>();
+ /* Returns a map of protocol -> byte counts between two sets */
+ protected Map<Byte, Long> getAllByteCounts(Set<Host> srcSet, Set<Host> dstSet) {
+ Map<Byte, Long> byteCounts = new HashMap<Byte, Long>();
+ Set<Byte> protocols = getProtocols(srcSet, dstSet);
+ for (Byte protocol : protocols)
+ byteCounts.put(protocol, getByteCount(srcSet, dstSet, protocol));
+ return byteCounts;
+ }
+
+ /* Returns the packet count between two sets, per-protocol (across
+ * all protocols if protocol is null). */
+ protected long getPacketCount(Set<Host> srcSet, Set<Host> dstSet, Byte protocol) {
+ long packetCount = 0;
for (Host src : srcSet) {
for (Host dst : dstSet) {
if (this.hostsToStats.get(src) != null &&
this.hostsToStats.get(src).get(dst) != null) {
- protocols.addAll(this.hostsToStats.get(src).get(dst).getProtocols());
+ if (protocol == null)
+ packetCount += this.hostsToStats.get(src).get(dst).getPacketCount();
+ else
+ packetCount += this.hostsToStats.get(src).get(dst).getPacketCount(protocol);
}
}
}
- return protocols;
+ return packetCount;
}
- /* Returns a map of all byte counts between two sets */
- protected Map<Byte, Long> getAllByteCounts(Set<Host> srcSet, Set<Host> dstSet) {
- Map<Byte, Long> byteCounts = new HashMap<Byte, Long>();
+ /* Returns a map of protocol -> packet counts between two sets */
+ protected Map<Byte, Long> getAllPacketCounts(Set<Host> srcSet, Set<Host> dstSet) {
+ Map<Byte, Long> packetCounts = new HashMap<Byte, Long>();
Set<Byte> protocols = getProtocols(srcSet, dstSet);
for (Byte protocol : protocols)
- byteCounts.put(protocol, getByteCount(srcSet, dstSet, protocol));
- return byteCounts;
+ packetCounts.put(protocol, getPacketCount(srcSet, dstSet, protocol));
+ return packetCounts;
}
/* Returns the duration of communication between two sets (max
return maxDuration;
}
+ /* Returns a map of protocol -> (max) duration over that protocol. */
+ protected Map<Byte, Double> getAllDurations(Set<Host> srcSet, Set<Host> dstSet) {
+ Map<Byte, Double> durations = new HashMap<Byte, Double>();
+ Set<Byte> protocols = getProtocols(srcSet, dstSet);
+ for (Byte protocol : protocols)
+ durations.put(protocol, getDuration(srcSet, dstSet, protocol));
+ return durations;
+ }
+
/* Returns the bit rate between two sets */
protected double getBitRate(Set<Host> srcSet, Set<Host> dstSet, Byte protocol) {
double duration = getDuration(srcSet, dstSet, protocol);
return (totalBytes * 8.0) / duration;
}
+ /* Returns all bit rates between two sets */
protected Map<Byte, Double> getAllBitRates(Set<Host> srcSet, Set<Host> dstSet) {
Map<Byte, Double> bitRates = new HashMap<Byte, Double>();
Set<Byte> protocols = getProtocols(srcSet, dstSet);
return bitRates;
}
- /* These are all basic getters/setters, most of which are required
- * by IAnalyticsManager */
- public long getByteCount(Host src, Host dst) {
- return getByteCount(src, dst, null);
- }
-
- public long getByteCount(Host src, Host dst, Byte protocol) {
- Set<Host> srcSet = new HashSet<Host>(Arrays.asList(src));
- Set<Host> dstSet = new HashSet<Host>(Arrays.asList(dst));
- return getByteCount(srcSet, dstSet, protocol);
- }
-
- public Map<Byte, Long> getAllByteCounts(Host src, Host dst) {
- Set<Host> srcSet = new HashSet<Host>(Arrays.asList(src));
- Set<Host> dstSet = new HashSet<Host>(Arrays.asList(dst));
- return getAllByteCounts(srcSet, dstSet);
- }
-
- public double getDuration(Host src, Host dst) {
- return getDuration(src, dst, null);
- }
-
- public double getDuration(Host src, Host dst, Byte protocol) {
- Set<Host> srcSet = new HashSet<Host>(Arrays.asList(src));
- Set<Host> dstSet = new HashSet<Host>(Arrays.asList(dst));
- return getDuration(srcSet, dstSet, protocol);
- }
-
- public double getBitRate(Host src, Host dst) {
- return getBitRate(src, dst, null);
- }
-
- public double getBitRate(Host src, Host dst, Byte protocol) {
- Set<Host> srcSet = new HashSet<Host>(Arrays.asList(src));
- Set<Host> dstSet = new HashSet<Host>(Arrays.asList(dst));
- return getBitRate(srcSet, dstSet, protocol);
- }
-
- public Map<Byte, Double> getAllBitRates(Host src, Host dst) {
- Set<Host> srcSet = new HashSet<Host>(Arrays.asList(src));
- Set<Host> dstSet = new HashSet<Host>(Arrays.asList(dst));
- return getAllBitRates(srcSet, dstSet);
- }
-
- public long getByteCount(AffinityLink al) {
- return getByteCount(al, null);
- }
-
- public long getByteCount(AffinityLink al, Byte protocol) {
- Set<Host> srcSet = new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getToGroup()));
- Set<Host> dstSet = new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getFromGroup()));
- return getByteCount(srcSet, dstSet, protocol);
- }
-
- public Map<Byte, Long> getAllByteCounts(AffinityLink al) {
- Set<Host> srcSet = new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getToGroup()));
- Set<Host> dstSet = new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getFromGroup()));
- return getAllByteCounts(srcSet, dstSet);
- }
-
- public double getDuration(AffinityLink al) {
- return getDuration(al, null);
- }
-
- public double getDuration(AffinityLink al, Byte protocol) {
- Set<Host> srcSet = new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getToGroup()));
- Set<Host> dstSet = new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getFromGroup()));
- return getDuration(srcSet, dstSet, protocol);
- }
-
- public double getBitRate(AffinityLink al) {
- return getBitRate(al, null);
- }
-
- public double getBitRate(AffinityLink al, Byte protocol) {
- Set<Host> srcSet = new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getToGroup()));
- Set<Host> dstSet = new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getFromGroup()));
- return getBitRate(srcSet, dstSet, protocol);
- }
-
- public Map<Byte, Double> getAllBitRates(AffinityLink al) {
- Set<Host> srcSet = new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getToGroup()));
- Set<Host> dstSet = new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getFromGroup()));
- return getAllBitRates(srcSet, dstSet);
- }
-
- public long getByteCount(String srcSubnet, String dstSubnet) {
- return getByteCount(srcSubnet, dstSubnet, null);
- }
-
- public long getByteCount(String srcSubnet, String dstSubnet, Byte protocol) {
- Set<Host> srcSet = getSrcHosts(srcSubnet, dstSubnet);
- Set<Host> dstSet = getSrcHosts(dstSubnet, srcSubnet); // reverse arguments
- return getByteCount(srcSet, dstSet, protocol);
- }
-
- public Map<Byte, Long> getAllByteCounts(String srcSubnet, String dstSubnet) {
- Set<Host> srcSet = getSrcHosts(srcSubnet, dstSubnet);
- Set<Host> dstSet = getSrcHosts(dstSubnet, srcSubnet); // reverse arguments
- return getAllByteCounts(srcSet, dstSet);
- }
-
- public double getDuration(String srcSubnet, String dstSubnet) {
- return getDuration(srcSubnet, dstSubnet, null);
- }
-
- public double getDuration(String srcSubnet, String dstSubnet, Byte protocol) {
- Set<Host> srcSet = getSrcHosts(srcSubnet, dstSubnet);
- Set<Host> dstSet = getSrcHosts(dstSubnet, srcSubnet); // reverse arguments
- return getDuration(srcSet, dstSet, protocol);
- }
-
- public double getBitRate(String srcSubnet, String dstSubnet) {
- return getBitRate(srcSubnet, dstSubnet, null);
- }
+ /* Because the generic stats API relies on having two Set<Host>
+ * arguments, the next series of functions converts various
+ * Objects into Set<Host>. */
- public double getBitRate(String srcSubnet, String dstSubnet, Byte protocol) {
- Set<Host> srcSet = getSrcHosts(srcSubnet, dstSubnet);
- Set<Host> dstSet = getSrcHosts(dstSubnet, srcSubnet); // reverse arguments
- return getBitRate(srcSet, dstSet, protocol);
+ /* Host -> Set<Host> */
+ private Set<Host> getSet(Host h) {
+ return new HashSet<Host>(Arrays.asList(h));
}
- public Map<Byte, Double> getAllBitRates(String srcSubnet, String dstSubnet) {
- Set<Host> srcSet = getSrcHosts(srcSubnet, dstSubnet);
- Set<Host> dstSet = getSrcHosts(dstSubnet, srcSubnet); // reverse arguments
- return getAllBitRates(srcSet, dstSet);
+ /* AffinityLink -> Set of source Hosts */
+ private Set<Host> getSrcSet(AffinityLink al) {
+ return new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getToGroup()));
}
- public Map<Host, Long> getIncomingHostByteCounts(String subnet) {
- return getIncomingHostByteCounts(subnet, null);
+ /* AffinityLink -> Set of destination Hosts */
+ private Set<Host> getDstSet(AffinityLink al) {
+ return new HashSet<Host>(this.affinityManager.getAllElementsByHost(al.getToGroup()));
}
- public Map<Host, Long> getIncomingHostByteCounts(String subnet, Byte protocol) {
- Set<HostNodeConnector> allHosts = this.hostTracker.getAllHosts();
- return getIncomingHostByteCounts(subnet, protocol, allHosts);
+ /* srcSubnet, dstSubnet -> Set of Hosts in srcSubnet. If
+ * srcSubnet is null, will return all hosts *not* in dstSubnet. */
+ private Set<Host> getSrcSet(String srcSubnet, String dstSubnet) {
+ if (srcSubnet == null && dstSubnet == null) {
+ log.debug("Source and destination subnets cannot both be null.");
+ return new HashSet<Host>();
+ }
+ if (srcSubnet == null)
+ return getHostsNotInSubnet(dstSubnet);
+ else
+ return getHostsInSubnet(srcSubnet);
}
+ /* srcSubnet, dstSubnet -> Set of Hosts in dstSubnet. This has
+ * the same logic as the previous method, so just flip the
+ * arguments. */
+ private Set<Host> getDstSet(String srcSubnet, String dstSubnet) {
+ return getSrcSet(dstSubnet, srcSubnet);
+ }
+
+ /* Basic getters for host pair statistics */
+ public long getByteCount(Host src, Host dst) { return getByteCount(src, dst, null); }
+ public long getByteCount(Host src, Host dst, Byte protocol) { return getByteCount(getSet(src), getSet(dst), protocol); }
+ public Map<Byte, Long> getAllByteCounts(Host src, Host dst) { return getAllByteCounts(getSet(src), getSet(dst)); }
+ public long getPacketCount(Host src, Host dst) { return getPacketCount(src, dst, null); }
+ public long getPacketCount(Host src, Host dst, Byte protocol) { return getPacketCount(getSet(src), getSet(dst), protocol); }
+ public Map<Byte, Long> getAllPacketCounts(Host src, Host dst) { return getAllPacketCounts(getSet(src), getSet(dst)); }
+ public double getDuration(Host src, Host dst) { return getDuration(src, dst, null); }
+ public double getDuration(Host src, Host dst, Byte protocol) { return getDuration(getSet(src), getSet(dst), protocol); }
+ public Map<Byte, Double> getAllDurations(Host src, Host dst) { return getAllDurations(getSet(src), getSet(dst)); }
+ public double getBitRate(Host src, Host dst) { return getBitRate(src, dst, null); }
+ public double getBitRate(Host src, Host dst, Byte protocol) { return getBitRate(getSet(src), getSet(dst), protocol); }
+ public Map<Byte, Double> getAllBitRates(Host src, Host dst) { return getAllBitRates(getSet(src), getSet(dst)); }
+
+ /* Basic getters for affinity link statistics */
+ public long getByteCount(AffinityLink al) { return getByteCount(al, null); }
+ public long getByteCount(AffinityLink al, Byte protocol) { return getByteCount(getSrcSet(al), getDstSet(al), protocol); }
+ public Map<Byte, Long> getAllByteCounts(AffinityLink al) { return getAllByteCounts(getSrcSet(al), getDstSet(al)); }
+ public long getPacketCount(AffinityLink al) { return getPacketCount(al, null); }
+ public long getPacketCount(AffinityLink al, Byte protocol) { return getPacketCount(getSrcSet(al), getDstSet(al), protocol); }
+ public Map<Byte, Long> getAllPacketCounts(AffinityLink al) { return getAllPacketCounts(getSrcSet(al), getDstSet(al)); }
+ public double getDuration(AffinityLink al) { return getDuration(al, null); }
+ public double getDuration(AffinityLink al, Byte protocol) { return getDuration(getSrcSet(al), getDstSet(al), protocol); }
+ public Map<Byte, Double> getAllDurations(AffinityLink al) { return getAllDurations(getSrcSet(al), getDstSet(al)); }
+ public double getBitRate(AffinityLink al) { return getBitRate(al, null); }
+ public double getBitRate(AffinityLink al, Byte protocol) { return getBitRate(getSrcSet(al), getDstSet(al), protocol); }
+ public Map<Byte, Double> getAllBitRates(AffinityLink al) { return getAllBitRates(getSrcSet(al), getDstSet(al)); }
+
+ /* Basic getters for subnet statistics */
+ public long getByteCount(String srcSub, String dstSub) { return getByteCount(srcSub, dstSub, null); }
+ public long getByteCount(String srcSub, String dstSub, Byte protocol) { return getByteCount(getSrcSet(srcSub, dstSub), getDstSet(srcSub, dstSub), protocol); }
+ public Map<Byte, Long> getAllByteCounts(String srcSub, String dstSub) { return getAllByteCounts(getSrcSet(srcSub, dstSub), getDstSet(srcSub, dstSub)); }
+ public long getPacketCount(String srcSub, String dstSub) { return getPacketCount(srcSub, dstSub, null); }
+ public long getPacketCount(String srcSub, String dstSub, Byte protocol) { return getPacketCount(getSrcSet(srcSub, dstSub), getDstSet(srcSub, dstSub), protocol); }
+ public Map<Byte, Long> getAllPacketCounts(String srcSub, String dstSub) { return getAllPacketCounts(getSrcSet(srcSub, dstSub), getDstSet(srcSub, dstSub)); }
+ public double getDuration(String srcSub, String dstSub) { return getDuration(srcSub, dstSub, null); }
+ public double getDuration(String srcSub, String dstSub, Byte protocol) { return getDuration(getSrcSet(srcSub, dstSub), getDstSet(srcSub, dstSub), protocol); }
+ public Map<Byte, Double> getAllDurations(String srcSub, String dstSub) { return getAllDurations(getSrcSet(srcSub, dstSub), getDstSet(srcSub, dstSub)); }
+ public double getBitRate(String srcSub, String dstSub) { return getBitRate(srcSub, dstSub, null); }
+ public double getBitRate(String srcSub, String dstSub, Byte protocol) { return getBitRate(getSrcSet(srcSub, dstSub), getDstSet(srcSub, dstSub), protocol); }
+ public Map<Byte, Double> getAllBitRates(String srcSub, String dstSub) { return getAllBitRates(getSrcSet(srcSub, dstSub), getDstSet(srcSub, dstSub)); }
+
/* Returns all hosts that transferred data into this subnet. */
public Map<Host, Long> getIncomingHostByteCounts(String subnet, Byte protocol, Set<HostNodeConnector> allHosts) {
Map<Host, Long> hosts = new HashMap<Host, Long>();
return hosts;
}
- private Set<Host> getHostsNotInSubnet(String subnet) {
- return getHostsNotInSubnet(subnet, this.hostTracker.getAllHosts());
+ public Map<Host, Long> getIncomingHostByteCounts(String subnet) {
+ return getIncomingHostByteCounts(subnet, null);
}
+ public Map<Host, Long> getIncomingHostByteCounts(String subnet, Byte protocol) {
+ Set<HostNodeConnector> allHosts = this.hostTracker.getAllHosts();
+ return getIncomingHostByteCounts(subnet, protocol, allHosts);
+ }
+
+ /* Hosts in allHosts that are not part of the subnet. This is
+ * useful when we need statistics about, e.g., all data into a
+ * particular subnet (so data from hosts outside of that
+ * subnet).*/
protected Set<Host> getHostsNotInSubnet(String subnet, Set<HostNodeConnector> allHosts) {
Set<Host> hostsInSubnet = getHostsInSubnet(subnet, allHosts);
Set<HostNodeConnector> otherHosts = new HashSet<HostNodeConnector>(allHosts); // copy constructor
return hostsNotInSubnet;
}
- // Handles null subnets
- private Set<Host> getSrcHosts(String srcSubnet, String dstSubnet) {
- if (srcSubnet == null && dstSubnet == null) {
- log.debug("Source and destination subnets cannot both be null.");
- return new HashSet<Host>();
- }
- if (srcSubnet == null)
- return getHostsNotInSubnet(dstSubnet);
- else
- return getHostsInSubnet(srcSubnet);
- }
-
- private Set<Host> getHostsInSubnet(String subnet) {
- return getHostsInSubnet(subnet, this.hostTracker.getAllHosts());
+ private Set<Host> getHostsNotInSubnet(String subnet) {
+ return getHostsNotInSubnet(subnet, this.hostTracker.getAllHosts());
}
+ /* Returns the set of hosts that are part of this subnet. */
protected Set<Host> getHostsInSubnet(String subnet, Set<HostNodeConnector> allHosts) {
InetAddress ip;
Short mask;
return hosts;
}
- // Match on subnetes
+ // Match on subnets
InetAddress targetSubnet = getSubnet(ip, mask);
for (HostNodeConnector host : allHosts) {
InetAddress hostSubnet = getSubnet(host.getNetworkAddress(), mask);
return hosts;
}
+ private Set<Host> getHostsInSubnet(String subnet) {
+ return getHostsInSubnet(subnet, this.hostTracker.getAllHosts());
+ }
+
+ /* Get the subnet associated with this IP and mask. */
private InetAddress getSubnet(InetAddress ip, Short mask) {
byte[] prefix = ip.getAddress();
InetAddress newIP = null;
public class HostStats {
private Map<Byte, Long> byteCounts;
+ private Map<Byte, Long> packetCounts;
private Map<Byte, Double> durations;
public HostStats() {
this.byteCounts = new HashMap<Byte, Long>();
+ this.packetCounts = new HashMap<Byte, Long>();
this.durations = new HashMap<Byte, Double>();
}
return byteCount;
}
- // Returns the map of byte counts
- public Map<Byte, Long> getAllByteCounts() {
- return this.byteCounts;
+ // Returns the total packet count across all protocols
+ public long getPacketCount() {
+ long totalPacketCount = 0;
+ for (Byte protocol : this.packetCounts.keySet())
+ totalPacketCount += this.packetCounts.get(protocol);
+ return totalPacketCount;
}
+ // Returns the packet count for a particular protocol
+ public long getPacketCount(Byte protocol) {
+ Long packetCount = this.packetCounts.get(protocol);
+ if (packetCount == null)
+ packetCount = (long) 0;
+ return packetCount;
+ }
+
// Returns the maximum duration across all protocols
public double getDuration() {
if (this.durations.isEmpty())
return (byteCount * 8)/duration;
}
- // Sets byte count and duration given a flow
+ // Sets byte count, packet count, and duration given a flow
public void setStatsFromFlow(FlowOnNode flow) {
MatchField protocolField = flow.getFlow().getMatch().getField(MatchType.NW_PROTO);
Byte protocolNumber;
// Prevent stats from getting overwritten by zero-byte flows.
Long currentByteCount = this.byteCounts.get(protocolNumber);
Long thisByteCount = flow.getByteCount();
+ Long thisPacketCount = flow.getPacketCount();
if (thisByteCount > 0 && (currentByteCount == null || currentByteCount <= thisByteCount)) {
this.byteCounts.put(protocolNumber, thisByteCount);
+ this.packetCounts.put(protocolNumber, thisPacketCount);
this.durations.put(protocolNumber, flow.getDurationSeconds() + .000000001 * flow.getDurationNanoseconds());
}
}
f.setMatch(match);\r
FlowOnNode fon = new FlowOnNode(f);\r
fon.setByteCount(200);\r
+ fon.setPacketCount(6);\r
fon.setDurationSeconds(1);\r
fon.setDurationNanoseconds(100000000);\r
flowStatsListn1.add(fon);\r
f.setMatch(match);\r
fon = new FlowOnNode(f);\r
fon.setByteCount(64);\r
+ fon.setPacketCount(5);\r
fon.setDurationSeconds(1);\r
fon.setDurationNanoseconds(0);\r
flowStatsListn1.add(fon);\r
f.setMatch(match);\r
fon = new FlowOnNode(f);\r
fon.setByteCount(76);\r
+ fon.setPacketCount(4);\r
fon.setDurationSeconds(2);\r
fon.setDurationNanoseconds(0);\r
flowStatsListn1.add(fon);\r
f.setMatch(match);\r
fon = new FlowOnNode(f);\r
fon.setByteCount(300);\r
+ fon.setPacketCount(3);\r
fon.setDurationSeconds(1);\r
fon.setDurationNanoseconds(200000000);\r
flowStatsListn2.add(fon);\r
f.setMatch(match);\r
fon = new FlowOnNode(f);\r
fon.setByteCount(27);\r
+ fon.setPacketCount(4);\r
fon.setDurationSeconds(1);\r
fon.setDurationNanoseconds(0);\r
flowStatsListn1.add(fon);\r
f.setMatch(match);\r
fon = new FlowOnNode(f);\r
fon.setByteCount(234);\r
+ fon.setPacketCount(2);\r
fon.setDurationSeconds(2);\r
fon.setDurationNanoseconds(0);\r
flowStatsListn2.add(fon);\r
f.setMatch(match);\r
fon = new FlowOnNode(f);\r
fon.setByteCount(54);\r
+ fon.setPacketCount(1);\r
fon.setDurationSeconds(3);\r
fon.setDurationNanoseconds(100000000);\r
flowStatsListn2.add(fon);\r
\r
// Host pairs - basic stats\r
Assert.assertTrue(am.getByteCount(hnc1, hnc3) == 200 + 64);\r
+ Assert.assertTrue(am.getPacketCount(hnc1, hnc3) == 6 + 5);\r
Assert.assertTrue(am.getDuration(hnc1, hnc3) == 1.1);\r
Assert.assertTrue(am.getBitRate(hnc1, hnc3) == ((200 + 64) * 8.0) / 1.1);\r
Assert.assertTrue(am.getByteCount(hnc1, hnc4) == 76);\r
+ Assert.assertTrue(am.getPacketCount(hnc1, hnc4) == 4);\r
Assert.assertTrue(am.getDuration(hnc1, hnc4) == 2.0);\r
Assert.assertTrue(am.getBitRate(hnc1, hnc4) == (76 * 8.0) / 2.0);\r
Assert.assertTrue(am.getByteCount(hnc2, hnc4) == 300);\r
+ Assert.assertTrue(am.getPacketCount(hnc2, hnc4) == 3);\r
Assert.assertTrue(am.getDuration(hnc2, hnc4) == 1.2);\r
Assert.assertTrue(am.getBitRate(hnc2, hnc4) == (300 * 8.0) / 1.2);\r
Assert.assertTrue(am.getByteCount(hnc1, hnc5) == 27);\r
+ Assert.assertTrue(am.getPacketCount(hnc1, hnc5) == 4);\r
Assert.assertTrue(am.getDuration(hnc1, hnc5) == 1.0);\r
Assert.assertTrue(am.getBitRate(hnc1, hnc5) == (27 * 8.0) / 1.0);\r
Assert.assertTrue(am.getByteCount(hnc2, hnc5) == 234 + 54);\r
+ Assert.assertTrue(am.getPacketCount(hnc2, hnc5) == 2 + 1);\r
Assert.assertTrue(am.getDuration(hnc2, hnc5) == 3.1);\r
Assert.assertTrue(am.getBitRate(hnc2, hnc5) == ((234 + 54) * 8.0) / 3.1);\r
\r
// Host pairs - per-protocol stats\r
Assert.assertTrue(am.getByteCount(hnc1, hnc3, IPProtocols.ICMP.byteValue()) == 64);\r
+ Assert.assertTrue(am.getPacketCount(hnc1, hnc3, IPProtocols.ICMP.byteValue()) == 5);\r
Assert.assertTrue(am.getDuration(hnc1, hnc3, IPProtocols.ICMP.byteValue()) == 1.0);\r
Assert.assertTrue(am.getBitRate(hnc1, hnc3, IPProtocols.ICMP.byteValue()) == (64 * 8.0) / 1.0);\r
Assert.assertTrue(am.getByteCount(hnc1, hnc3, IPProtocols.UDP.byteValue()) == 200);\r
+ Assert.assertTrue(am.getPacketCount(hnc1, hnc3, IPProtocols.UDP.byteValue()) == 6);\r
Assert.assertTrue(am.getDuration(hnc1, hnc3, IPProtocols.UDP.byteValue()) == 1.1);\r
Assert.assertTrue(am.getBitRate(hnc1, hnc3, IPProtocols.UDP.byteValue()) == (200 * 8.0) / 1.1);\r
Assert.assertTrue(am.getByteCount(hnc1, hnc3, IPProtocols.TCP.byteValue()) == 0);\r
+ Assert.assertTrue(am.getPacketCount(hnc1, hnc3, IPProtocols.TCP.byteValue()) == 0);\r
Assert.assertTrue(am.getDuration(hnc1, hnc3, IPProtocols.TCP.byteValue()) == 0.0);\r
Assert.assertTrue(am.getBitRate(hnc1, hnc3, IPProtocols.TCP.byteValue()) == 0.0);\r
Assert.assertTrue(am.getByteCount(hnc1, hnc4, IPProtocols.TCP.byteValue()) == 76);\r
+ Assert.assertTrue(am.getPacketCount(hnc1, hnc4, IPProtocols.TCP.byteValue()) == 4);\r
Assert.assertTrue(am.getDuration(hnc1, hnc4, IPProtocols.TCP.byteValue()) == 2.0);\r
Assert.assertTrue(am.getBitRate(hnc1, hnc4, IPProtocols.TCP.byteValue()) == (76 * 8.0) / 2.0);\r
Assert.assertTrue(am.getByteCount(hnc2, hnc4, IPProtocols.TCP.byteValue()) == 300);\r
+ Assert.assertTrue(am.getPacketCount(hnc2, hnc4, IPProtocols.TCP.byteValue()) == 3);\r
Assert.assertTrue(am.getDuration(hnc2, hnc4, IPProtocols.TCP.byteValue()) == 1.2);\r
Assert.assertTrue(am.getBitRate(hnc2, hnc4, IPProtocols.TCP.byteValue()) == (300 * 8.0) / 1.2);\r
Assert.assertTrue(am.getByteCount(hnc1, hnc5, IPProtocols.UDP.byteValue()) == 27);\r
+ Assert.assertTrue(am.getPacketCount(hnc1, hnc5, IPProtocols.UDP.byteValue()) == 4);\r
Assert.assertTrue(am.getDuration(hnc1, hnc5, IPProtocols.UDP.byteValue()) == 1.0);\r
Assert.assertTrue(am.getBitRate(hnc1, hnc5, IPProtocols.UDP.byteValue()) == (27 * 8.0) / 1.0);\r
Assert.assertTrue(am.getByteCount(hnc2, hnc5, IPProtocols.ICMP.byteValue()) == 54);\r
+ Assert.assertTrue(am.getPacketCount(hnc2, hnc5, IPProtocols.ICMP.byteValue()) == 1);\r
Assert.assertTrue(am.getDuration(hnc2, hnc5, IPProtocols.ICMP.byteValue()) == 3.1);\r
Assert.assertTrue(am.getBitRate(hnc2, hnc5, IPProtocols.ICMP.byteValue()) == (54 * 8.0) / 3.1);\r
Assert.assertTrue(am.getByteCount(hnc2, hnc5, IPProtocols.TCP.byteValue()) == 234);\r
+ Assert.assertTrue(am.getPacketCount(hnc2, hnc5, IPProtocols.TCP.byteValue()) == 2);\r
Assert.assertTrue(am.getDuration(hnc2, hnc5, IPProtocols.TCP.byteValue()) == 2.0);\r
Assert.assertTrue(am.getBitRate(hnc2, hnc5, IPProtocols.TCP.byteValue()) == (234 * 8.0) / 2.0);\r
\r
// Host pairs - all stats\r
- Map<Byte, Long> byteCounts = am.getAllByteCounts(hnc1, hnc3);\r
- Map<Byte, Double> bitRates = am.getAllBitRates(hnc1, hnc3);\r
- Assert.assertTrue(byteCounts.get(IPProtocols.ICMP.byteValue()) == am.getByteCount(hnc1, hnc3, IPProtocols.ICMP.byteValue()));\r
- Assert.assertTrue(byteCounts.get(IPProtocols.UDP.byteValue()) == am.getByteCount(hnc1, hnc3, IPProtocols.UDP.byteValue()));\r
- Assert.assertTrue(byteCounts.get(IPProtocols.TCP.byteValue()) == null);\r
- Assert.assertTrue(bitRates.get(IPProtocols.ICMP.byteValue()) == am.getBitRate(hnc1, hnc3, IPProtocols.ICMP.byteValue()));\r
- Assert.assertTrue(bitRates.get(IPProtocols.UDP.byteValue()) == am.getBitRate(hnc1, hnc3, IPProtocols.UDP.byteValue()));\r
- Assert.assertTrue(bitRates.get(IPProtocols.TCP.byteValue()) == null);\r
- byteCounts = am.getAllByteCounts(hnc1, hnc4);\r
- bitRates = am.getAllBitRates(hnc1, hnc4);\r
- Assert.assertTrue(byteCounts.get(IPProtocols.TCP.byteValue()) == am.getByteCount(hnc1, hnc4, IPProtocols.TCP.byteValue()));\r
- Assert.assertTrue(bitRates.get(IPProtocols.TCP.byteValue()) == am.getBitRate(hnc1, hnc4, IPProtocols.TCP.byteValue()));\r
- byteCounts = am.getAllByteCounts(hnc2, hnc4);\r
- bitRates = am.getAllBitRates(hnc2, hnc4);\r
- Assert.assertTrue(byteCounts.get(IPProtocols.TCP.byteValue()) == am.getByteCount(hnc2, hnc4, IPProtocols.TCP.byteValue()));\r
- Assert.assertTrue(bitRates.get(IPProtocols.TCP.byteValue()) == am.getBitRate(hnc2, hnc4, IPProtocols.TCP.byteValue()));\r
- byteCounts = am.getAllByteCounts(hnc1, hnc5);\r
- bitRates = am.getAllBitRates(hnc1, hnc5);\r
- Assert.assertTrue(byteCounts.get(IPProtocols.UDP.byteValue()) == am.getByteCount(hnc1, hnc5, IPProtocols.UDP.byteValue()));\r
- Assert.assertTrue(bitRates.get(IPProtocols.UDP.byteValue()) == am.getBitRate(hnc1, hnc5, IPProtocols.UDP.byteValue()));\r
- byteCounts = am.getAllByteCounts(hnc2, hnc5);\r
- bitRates = am.getAllBitRates(hnc2, hnc5);\r
- Assert.assertTrue(byteCounts.get(IPProtocols.ICMP.byteValue()) == am.getByteCount(hnc2, hnc5, IPProtocols.ICMP.byteValue()));\r
- Assert.assertTrue(byteCounts.get(IPProtocols.TCP.byteValue()) == am.getByteCount(hnc2, hnc5, IPProtocols.TCP.byteValue()));\r
- Assert.assertTrue(bitRates.get(IPProtocols.ICMP.byteValue()) == am.getBitRate(hnc2, hnc5, IPProtocols.ICMP.byteValue()));\r
- Assert.assertTrue(bitRates.get(IPProtocols.TCP.byteValue()) == am.getBitRate(hnc2, hnc5, IPProtocols.TCP.byteValue()));\r
+ Set<Byte> allProtocols = new HashSet<Byte>(Arrays.asList(IPProtocols.ICMP.byteValue(), IPProtocols.UDP.byteValue(), IPProtocols.TCP.byteValue()));\r
+ for (Host h1 : allHosts) {\r
+ for (Host h2 : allHosts) {\r
+ Map<Byte, Long> byteCounts = am.getAllByteCounts(h1, h2);\r
+ Map<Byte, Long> packetCounts = am.getAllPacketCounts(h1, h2);\r
+ Map<Byte, Double> durations = am.getAllDurations(h1, h2);\r
+ Map<Byte, Double> bitRates = am.getAllBitRates(h1, h2);\r
+ for (Byte protocol : allProtocols) {\r
+ if (byteCounts.get(protocol) == null) {\r
+ Assert.assertTrue(am.getByteCount(h1, h2, protocol) == 0);\r
+ Assert.assertTrue(am.getPacketCount(h1, h2, protocol) == 0);\r
+ Assert.assertTrue(am.getDuration(h1, h2, protocol) == 0.0);\r
+ Assert.assertTrue(am.getBitRate(h1, h2, protocol) == 0.0);\r
+ }\r
+ else {\r
+ Assert.assertTrue(byteCounts.get(protocol) == am.getByteCount(h1, h2, protocol));\r
+ Assert.assertTrue(packetCounts.get(protocol) == am.getPacketCount(h1, h2, protocol));\r
+ Assert.assertTrue(durations.get(protocol) == am.getDuration(h1, h2, protocol));\r
+ Assert.assertTrue(bitRates.get(protocol) == am.getBitRate(h1, h2, protocol));\r
+ }\r
+ }\r
+ }\r
+ }\r
\r
// Host groups - basic stats\r
Set<Host> srcHosts = new HashSet<Host>(Arrays.asList(hnc1, hnc2));\r
Set<Host> dstHosts = new HashSet<Host>(Arrays.asList(hnc3, hnc4));\r
Assert.assertTrue(am.getByteCount(srcHosts, dstHosts, null) == 64 + 200 + 76 + 300);\r
+ Assert.assertTrue(am.getPacketCount(srcHosts, dstHosts, null) == 6 + 5 + 4 + 3);\r
Assert.assertTrue(am.getDuration(srcHosts, dstHosts, null) == 2.0);\r
Assert.assertTrue(am.getBitRate(srcHosts, dstHosts, null) == ((64 + 200 + 76 + 300) * 8.0) / 2.0);\r
\r
// Host groups - per-protocol stats\r
Assert.assertTrue(am.getByteCount(srcHosts, dstHosts, IPProtocols.ICMP.byteValue()) == 64);\r
+ Assert.assertTrue(am.getPacketCount(srcHosts, dstHosts, IPProtocols.ICMP.byteValue()) == 5);\r
Assert.assertTrue(am.getDuration(srcHosts, dstHosts, IPProtocols.ICMP.byteValue()) == 1.0);\r
Assert.assertTrue(am.getBitRate(srcHosts, dstHosts, IPProtocols.ICMP.byteValue()) == (64 * 8.0) / 1.0);\r
Assert.assertTrue(am.getByteCount(srcHosts, dstHosts, IPProtocols.TCP.byteValue()) == 76 + 300);\r
+ Assert.assertTrue(am.getPacketCount(srcHosts, dstHosts, IPProtocols.TCP.byteValue()) == 4 + 3);\r
Assert.assertTrue(am.getDuration(srcHosts, dstHosts, IPProtocols.TCP.byteValue()) == 2.0);\r
Assert.assertTrue(am.getBitRate(srcHosts, dstHosts, IPProtocols.TCP.byteValue()) == ((76 + 300) * 8.0) / 2.0);\r
Assert.assertTrue(am.getByteCount(srcHosts, dstHosts, IPProtocols.UDP.byteValue()) == 200);\r
+ Assert.assertTrue(am.getPacketCount(srcHosts, dstHosts, IPProtocols.UDP.byteValue()) == 6);\r
Assert.assertTrue(am.getDuration(srcHosts, dstHosts, IPProtocols.UDP.byteValue()) == 1.1);\r
Assert.assertTrue(am.getBitRate(srcHosts, dstHosts, IPProtocols.UDP.byteValue()) == (200 * 8.0) / 1.1);\r
\r
// Host groups - all stats\r
- byteCounts = am.getAllByteCounts(srcHosts, dstHosts);\r
- bitRates = am.getAllBitRates(srcHosts, dstHosts);\r
+ Map<Byte, Long> byteCounts = am.getAllByteCounts(srcHosts, dstHosts);\r
+ Map<Byte, Long> packetCounts = am.getAllPacketCounts(srcHosts, dstHosts);\r
+ Map<Byte, Double> durations = am.getAllDurations(srcHosts, dstHosts);\r
+ Map<Byte, Double> bitRates = am.getAllBitRates(srcHosts, dstHosts);\r
Assert.assertTrue(byteCounts.get(IPProtocols.ICMP.byteValue()) == am.getByteCount(srcHosts, dstHosts, IPProtocols.ICMP.byteValue()));\r
Assert.assertTrue(byteCounts.get(IPProtocols.UDP.byteValue()) == am.getByteCount(srcHosts, dstHosts, IPProtocols.UDP.byteValue()));\r
Assert.assertTrue(byteCounts.get(IPProtocols.TCP.byteValue()) == am.getByteCount(srcHosts, dstHosts, IPProtocols.TCP.byteValue()));\r
Assert.assertTrue(byteCounts.get(IPProtocols.ANY.byteValue()) == null);\r
+ Assert.assertTrue(packetCounts.get(IPProtocols.ICMP.byteValue()) == am.getPacketCount(srcHosts, dstHosts, IPProtocols.ICMP.byteValue()));\r
+ Assert.assertTrue(packetCounts.get(IPProtocols.UDP.byteValue()) == am.getPacketCount(srcHosts, dstHosts, IPProtocols.UDP.byteValue()));\r
+ Assert.assertTrue(packetCounts.get(IPProtocols.TCP.byteValue()) == am.getPacketCount(srcHosts, dstHosts, IPProtocols.TCP.byteValue()));\r
+ Assert.assertTrue(packetCounts.get(IPProtocols.ANY.byteValue()) == null);\r
+ Assert.assertTrue(durations.get(IPProtocols.ICMP.byteValue()) == am.getDuration(srcHosts, dstHosts, IPProtocols.ICMP.byteValue()));\r
+ Assert.assertTrue(durations.get(IPProtocols.UDP.byteValue()) == am.getDuration(srcHosts, dstHosts, IPProtocols.UDP.byteValue()));\r
+ Assert.assertTrue(durations.get(IPProtocols.TCP.byteValue()) == am.getDuration(srcHosts, dstHosts, IPProtocols.TCP.byteValue()));\r
+ Assert.assertTrue(durations.get(IPProtocols.ANY.byteValue()) == null);\r
Assert.assertTrue(bitRates.get(IPProtocols.ICMP.byteValue()) == am.getBitRate(srcHosts, dstHosts, IPProtocols.ICMP.byteValue()));\r
Assert.assertTrue(bitRates.get(IPProtocols.UDP.byteValue()) == am.getBitRate(srcHosts, dstHosts, IPProtocols.UDP.byteValue()));\r
Assert.assertTrue(bitRates.get(IPProtocols.TCP.byteValue()) == am.getBitRate(srcHosts, dstHosts, IPProtocols.TCP.byteValue()));\r
// Correct flow over-writing\r
fon = new FlowOnNode(f); // 10.0.0.2 -> 10.0.0.5, ICMP\r
fon.setByteCount(300);\r
+ fon.setPacketCount(7);\r
fon.setDurationSeconds(4);\r
fon.setDurationNanoseconds(100000000);\r
flowStatsListn2.add(fon);\r
am.nodeFlowStatisticsUpdated(n2, flowStatsListn2, allHosts);\r
Assert.assertTrue(am.getByteCount(hnc2, hnc5) == 300 + 234);\r
+ Assert.assertTrue(am.getPacketCount(hnc2, hnc5) == 2 + 7);\r
Assert.assertTrue(am.getBitRate(hnc2, hnc5) == ((300 + 234) * 8.0) / 4.1);\r
Assert.assertTrue(am.getByteCount(hnc2, hnc5, IPProtocols.ICMP.byteValue()) == 300);\r
+ Assert.assertTrue(am.getPacketCount(hnc2, hnc5, IPProtocols.ICMP.byteValue()) == 7);\r
} catch (ConstructionException e) {\r
Assert.assertTrue(false);\r
} catch (UnknownHostException e) {\r