From 516e88bb06c01895ddfc7a11b742c9b447026ba8 Mon Sep 17 00:00:00 2001
From: Ryan Izard <rizard@g.clemson.edu>
Date: Tue, 6 Oct 2015 14:08:50 -0400
Subject: [PATCH] Fix potential divide by zero. Increased latency parameters to
 threshold=0.50, history=10. Maybe it's just because my control plane is over
 a VPN and over the public internet, but the link latencies are fluctuating a
 bit. TODO evaluate whether or not we should completely clear the
 average/history each time we accept a new latency value. This would lessen
 the number of latency updates.

---
 .../linkdiscovery/internal/LinkDiscoveryManager.java          | 4 ++--
 .../floodlightcontroller/linkdiscovery/internal/LinkInfo.java | 2 +-
 src/main/resources/floodlightdefault.properties               | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java
index c617d282e..9f1209d75 100644
--- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java
@@ -214,8 +214,8 @@ IFloodlightModule, IInfoProvider {
 	/*
 	 * Latency tracking
 	 */
-	protected static int LATENCY_HISTORY_SIZE = 5;
-	protected static double LATENCY_UPDATE_THRESHOLD = 0.30;
+	protected static int LATENCY_HISTORY_SIZE = 10;
+	protected static double LATENCY_UPDATE_THRESHOLD = 0.50;
 
 	/**
 	 * Flag to indicate if automatic port fast is enabled or not. Default is set
diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkInfo.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkInfo.java
index a892787b1..ee7a1fce4 100644
--- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkInfo.java
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkInfo.java
@@ -104,7 +104,7 @@ public class LinkInfo {
 		if (newLatency != null) {
 			/* check threshold */
 			if ((((double) Math.abs(newLatency.getValue() - currentLatency.getValue())) 
-					/ currentLatency.getValue()
+					/ (currentLatency.getValue() == 0 ? 1 : currentLatency.getValue())
 					) 
 					>= latencyUpdateThreshold) {
 				/* perform update */
diff --git a/src/main/resources/floodlightdefault.properties b/src/main/resources/floodlightdefault.properties
index d18409ce6..a838b1318 100644
--- a/src/main/resources/floodlightdefault.properties
+++ b/src/main/resources/floodlightdefault.properties
@@ -24,7 +24,7 @@ net.floodlightcontroller.forwarding.Forwarding.match=vlan, mac, ip, transport
 net.floodlightcontroller.core.internal.FloodlightProvider.openflowPort=6653
 net.floodlightcontroller.core.internal.FloodlightProvider.role=ACTIVE
 net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-history-size=10
-net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-update-threshold=0.3
+net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager.latency-update-threshold=0.5
 net.floodlightcontroller.core.internal.OFSwitchManager.defaultMaxTablesToReceiveTableMissFlow=2
 net.floodlightcontroller.core.internal.OFSwitchManager.maxTablesToReceiveTableMissFlowPerDpid={"00:00:00:00:00:00:00:01":"1","2":"1"}
 net.floodlightcontroller.core.internal.OFSwitchManager.clearTablesOnInitialHandshakeAsMaster=YES
-- 
GitLab