use of com.inceptai.dobby.model.PingStats in project dobby-android by InceptAi.
the class FakePingAnalyzer method generateFakeGatewayStats.
private PingStats generateFakeGatewayStats() {
DobbyLog.v("FAKE Generating fake gateway http latency for mode " + getPingStatsModeName(FakePingAnalyzer.pingStatsMode));
if (FakePingAnalyzer.pingStatsMode == PingStatsMode.HTTP_DOWNLOAD_FUNCTIONALITY_NOT_AVAILABLE) {
return null;
}
FakePingConfig fakePingConfig = new FakePingConfig(FakePingAnalyzer.pingStatsMode);
PingStats gatewayLatencyStats = generateIndividualPingStats(ipLayerInfo.gateway, fakePingConfig.gatewayLatencyRangeMs, fakePingConfig.gatewayLossRangePercent);
gatewayLatencyStats.lossRatePercent = 0.0;
return gatewayLatencyStats;
}
use of com.inceptai.dobby.model.PingStats in project dobby-android by InceptAi.
the class FakePingAnalyzer method generateFakePingStats.
public HashMap<String, PingStats> generateFakePingStats() {
DobbyLog.v("FAKE Generating fake ping for mode " + getPingStatsModeName(FakePingAnalyzer.pingStatsMode));
if (FakePingAnalyzer.pingStatsMode == PingStatsMode.PING_FUNCTIONALITY_NOT_AVAILABLE) {
return null;
}
HashMap<String, PingStats> pingStatsHashMap = new HashMap<>();
FakePingConfig fakePingConfig = new FakePingConfig(FakePingAnalyzer.pingStatsMode);
PingStats gatewayPingStats = generateIndividualPingStats(ipLayerInfo.gateway, fakePingConfig.gatewayLatencyRangeMs, fakePingConfig.gatewayLossRangePercent);
PingStats dns1PingStats = generateIndividualPingStats(ipLayerInfo.dns1, fakePingConfig.dns1LatencyRangeMs, fakePingConfig.dns1LossRangePercent);
PingStats dns2PingStats = generateIndividualPingStats(ipLayerInfo.dns2, fakePingConfig.dns2LatencyRangeMs, fakePingConfig.dns2LossRangePercent);
PingStats externalServer1PingStats = generateIndividualPingStats(ipLayerInfo.referenceExternalAddress1, fakePingConfig.externalServer1LatencyRangeMs, fakePingConfig.externalServer1LossRangePercent);
PingStats externalServer2PingStats = generateIndividualPingStats(ipLayerInfo.referenceExternalAddress2, fakePingConfig.externalServer2LatencyRangeMs, fakePingConfig.externalServer2LossRangePercent);
PingStats publicDns1PingStats = generateIndividualPingStats(ipLayerInfo.publicDns1, fakePingConfig.publicDns1LatencyRangeMs, fakePingConfig.publicDns1LossRangePercent);
PingStats publicDns2PingStats = generateIndividualPingStats(ipLayerInfo.publicDns2, fakePingConfig.publicDns2LatencyRangeMs, fakePingConfig.publicDns2LossRangePercent);
pingStatsHashMap.put(ipLayerInfo.gateway, gatewayPingStats);
pingStatsHashMap.put(ipLayerInfo.dns1, dns1PingStats);
pingStatsHashMap.put(ipLayerInfo.dns2, dns2PingStats);
pingStatsHashMap.put(ipLayerInfo.referenceExternalAddress1, externalServer1PingStats);
pingStatsHashMap.put(ipLayerInfo.referenceExternalAddress2, externalServer2PingStats);
pingStatsHashMap.put(ipLayerInfo.publicDns1, publicDns1PingStats);
pingStatsHashMap.put(ipLayerInfo.publicDns2, publicDns2PingStats);
return pingStatsHashMap;
}
use of com.inceptai.dobby.model.PingStats in project dobby-android by InceptAi.
the class DataInterpreter method interpret.
public static PingGrade interpret(HashMap<String, PingStats> pingStatsHashMap, IPLayerInfo ipLayerInfo) {
PingGrade pingGrade = new PingGrade();
if (pingStatsHashMap == null || ipLayerInfo == null) {
return pingGrade;
}
//Get external server stats
pingGrade.primaryDns = ipLayerInfo.dns1;
HashMap<String, PingStats> externalServerStats = new HashMap<>();
if (ipLayerInfo.referenceExternalAddress1 != null) {
externalServerStats.put(ipLayerInfo.referenceExternalAddress1, pingStatsHashMap.get(ipLayerInfo.referenceExternalAddress1));
}
if (ipLayerInfo.referenceExternalAddress2 != null) {
externalServerStats.put(ipLayerInfo.referenceExternalAddress2, pingStatsHashMap.get(ipLayerInfo.referenceExternalAddress2));
}
//Get alternative DNS stats
PingStats alternativeDnsStats1 = pingStatsHashMap.get(ipLayerInfo.publicDns1);
PingStats alternativeDnsStats2 = pingStatsHashMap.get(ipLayerInfo.publicDns2);
PingStats lowerAlternativeDnsStats = new PingStats(ipLayerInfo.publicDns1);
if (alternativeDnsStats1.avgLatencyMs > 0) {
lowerAlternativeDnsStats = alternativeDnsStats1;
pingGrade.alternativeDns = ipLayerInfo.publicDns1;
}
if (alternativeDnsStats2.avgLatencyMs > 0) {
if (alternativeDnsStats1.avgLatencyMs < 0 || alternativeDnsStats2.avgLatencyMs < alternativeDnsStats1.avgLatencyMs) {
lowerAlternativeDnsStats = alternativeDnsStats2;
pingGrade.alternativeDns = ipLayerInfo.publicDns2;
}
}
//Router stats
PingStats routerStats = pingStatsHashMap.get(ipLayerInfo.gateway);
//Primary DNS stats
PingStats primaryDnsStats = pingStatsHashMap.get(ipLayerInfo.dns1);
double avgExternalServerLatencyMs = 0.0;
double avgExternalServerLossPercent = 0.0;
int count = 0;
for (PingStats pingStats : externalServerStats.values()) {
if (pingStats.avgLatencyMs > 0.0) {
avgExternalServerLatencyMs += pingStats.avgLatencyMs;
avgExternalServerLossPercent += pingStats.lossRatePercent;
count++;
}
}
if (count > 0) {
avgExternalServerLatencyMs /= (double) count;
avgExternalServerLossPercent /= (double) count;
} else {
avgExternalServerLossPercent = -1.0;
avgExternalServerLatencyMs = 0.0;
}
pingGrade.externalServerLatencyMetric = getPingGradeLowerIsBetter(avgExternalServerLatencyMs, avgExternalServerLossPercent, PING_LATENCY_EXTSERVER_STEPS_MS);
pingGrade.dnsServerLatencyMetric = getPingGradeLowerIsBetter(primaryDnsStats.avgLatencyMs, primaryDnsStats.lossRatePercent, PING_LATENCY_DNS_STEPS_MS);
pingGrade.routerLatencyMetric = getPingGradeLowerIsBetter(routerStats.avgLatencyMs, routerStats.lossRatePercent, PING_LATENCY_ROUTER_STEPS_MS);
pingGrade.alternativeDnsMetric = getPingGradeLowerIsBetter(lowerAlternativeDnsStats.avgLatencyMs, lowerAlternativeDnsStats.lossRatePercent, PING_LATENCY_DNS_STEPS_MS);
//putting in the values
pingGrade.routerLatencyMs = getEffectivePingLatency(routerStats.avgLatencyMs, routerStats.lossRatePercent);
pingGrade.alternativeDnsLatencyMs = getEffectivePingLatency(lowerAlternativeDnsStats.avgLatencyMs, lowerAlternativeDnsStats.lossRatePercent);
pingGrade.dnsServerLatencyMs = getEffectivePingLatency(primaryDnsStats.avgLatencyMs, primaryDnsStats.lossRatePercent);
pingGrade.externalServerLatencyMs = getEffectivePingLatency(avgExternalServerLatencyMs, avgExternalServerLossPercent);
return pingGrade;
}
use of com.inceptai.dobby.model.PingStats in project dobby-android by InceptAi.
the class PingAnalyzer method initializePingStats.
private void initializePingStats(IPLayerInfo ipLayerInfo) {
if (ipLayerInfo == null) {
return;
}
ipLayerPingStats.put(ipLayerInfo.gateway, new PingStats(ipLayerInfo.gateway));
ipLayerPingStats.put(ipLayerInfo.dns1, new PingStats(ipLayerInfo.dns1));
ipLayerPingStats.put(ipLayerInfo.dns2, new PingStats(ipLayerInfo.dns2));
ipLayerPingStats.put(ipLayerInfo.referenceExternalAddress1, new PingStats(ipLayerInfo.referenceExternalAddress1));
ipLayerPingStats.put(ipLayerInfo.referenceExternalAddress2, new PingStats(ipLayerInfo.referenceExternalAddress2));
ipLayerPingStats.put(ipLayerInfo.publicDns1, new PingStats(ipLayerInfo.publicDns1));
ipLayerPingStats.put(ipLayerInfo.publicDns2, new PingStats(ipLayerInfo.publicDns2));
}
use of com.inceptai.dobby.model.PingStats in project dobby-android by InceptAi.
the class PingAnalyzer method performGatewayDownloadTest.
//Perform download tests with router
private PingStats performGatewayDownloadTest() {
DobbyLog.v("PA: Starting download latency tests");
if (ipLayerInfo == null || ipLayerInfo.gateway == null || ipLayerInfo.gateway.equals("0.0.0.0")) {
return null;
}
PingStats downloadLatencyStats = new PingStats(ipLayerInfo.gateway);
String gatewayURLToDownload = "http://" + ipLayerInfo.gateway;
List<Double> latencyMeasurementsMs = new ArrayList<>();
for (int i = 0; i < MAX_GATEWAY_DOWNLOAD_TRIES; i++) {
String dataFromUrl = Utils.EMPTY_STRING;
long startTime = System.currentTimeMillis();
try {
dataFromUrl = Utils.getDataFromUrlWithTimeouts(gatewayURLToDownload, MAX_STRING_LENGTH, READ_TIMEOUT_LATENCY_TEST_MS, CONNECTION_TIMEOUT_LATENCY_TEST_MS);
if (dataFromUrl.length() > 0) {
latencyMeasurementsMs.add(Double.valueOf(System.currentTimeMillis() - startTime));
}
} catch (Utils.HTTPReturnCodeException e) {
DobbyLog.v("PA HTTP Return code: " + e.httpReturnCode);
latencyMeasurementsMs.add(Double.valueOf(System.currentTimeMillis() - startTime));
} catch (IOException e) {
String errorString = "PA Exception while performing latencyMs test: " + e;
DobbyLog.v(errorString);
//latencyMeasurementsMs.add(MAX_LATENCY_GATEWAY_MS);
}
}
//Compute avg, min, max
if (latencyMeasurementsMs.size() > 0) {
try {
Collections.sort(latencyMeasurementsMs);
downloadLatencyStats.avgLatencyMs = Utils.computePercentileFromSortedList(latencyMeasurementsMs, 50);
downloadLatencyStats.maxLatencyMs = Utils.computePercentileFromSortedList(latencyMeasurementsMs, 100);
downloadLatencyStats.minLatencyMs = Utils.computePercentileFromSortedList(latencyMeasurementsMs, 0);
downloadLatencyStats.updatedAt = System.currentTimeMillis();
} catch (IllegalArgumentException e) {
String errorString = "PA Got exception while computing average: " + e;
DobbyLog.v(errorString);
}
}
DobbyLog.v("GW server latency is : " + downloadLatencyStats.toString());
return downloadLatencyStats;
}
Aggregations