Fixed getDestinationHostFromFlow to deal with NW_DST field (+ removed print statement... 41/1441/1
authorKatrina LaCurts <katrina.lacurts@plexxi.com>
Wed, 25 Sep 2013 20:50:36 +0000 (16:50 -0400)
committerKatrina LaCurts <katrina.lacurts@plexxi.com>
Wed, 25 Sep 2013 20:50:36 +0000 (16:50 -0400)
Signed-off-by: Katrina LaCurts <katrina.lacurts@plexxi.com>
analytics/implementation/src/main/java/org/opendaylight/affinity/analytics/internal/AnalyticsManager.java
analytics/implementation/src/main/java/org/opendaylight/affinity/analytics/internal/HostStats.java
analytics/integrationtest/src/test/java/org/opendaylight/affinity/analytics/internal/AnalyticsManagerIT.java
scripts/analytics.py

index 0f93c90bb78c576a6c6fc642451f2c06f2cadf2f..9d8820672fedd7f1ea6f97b1c87efa6c1aaf9f1c 100644 (file)
@@ -124,28 +124,45 @@ public class AnalyticsManager implements IReadServiceListener, IAnalyticsManager
      * exists.  Returns null otherwise.
      */
     protected Host getDestinationHostFromFlow(Flow flow, Set<HostNodeConnector> hosts) {
-        Host dstHost = null;
         Match match = flow.getMatch();
+        MatchField dst = null;
 
-        // Flow has to have DL_DST field
+        // Flow has to have DL_DST field or NW_DST field to proceed
         if (match.isPresent(MatchType.DL_DST)) {
-            MatchField dlDst = match.getField(MatchType.DL_DST);
+            dst = match.getField(MatchType.DL_DST);
+        } else if (match.isPresent(MatchType.NW_DST)) {
+            dst = match.getField(MatchType.NW_DST);
+        } else { 
+            return null;
+        }
 
-            // Check cache
-            Host cacheHit = this.destinationHostCache.get(dlDst);
-            if (cacheHit != null) {
-                return cacheHit;
-            }
+        // Check cache
+        Host cacheHit = this.destinationHostCache.get(dst);
+        if (cacheHit != null) {
+            return cacheHit;
+        }
 
-            // Find the destination host by comparing the MAC address
-            // strings (comparing MAC address bytes, surprisingly, did
-            // not work).
-            String dstMac = MatchType.DL_DST.stringify(dlDst.getValue());
-            for (HostNodeConnector h : hosts) {
+        // Find the destination host
+        Host dstHost = null;
+        for (HostNodeConnector h : hosts) {
+            
+            // DL_DST => compare on MAC address strings
+            if (match.isPresent(MatchType.DL_DST)) {
+                String dstMac = MatchType.DL_DST.stringify(dst.getValue());
                 String hostMac = ((EthernetAddress) h.getDataLayerAddress()).getMacAddress();
                 if (dstMac.equals(hostMac)) {
                     dstHost = h;
-                    this.destinationHostCache.put(dlDst, dstHost); // Add to cache
+                    this.destinationHostCache.put(dst, dstHost); // Add to cache
+                    break;
+                }
+            }
+          
+            // NW_DST => compare on IP address (of type InetAddress)
+            else if (match.isPresent(MatchType.NW_DST)) {
+                InetAddress hostIP = h.getNetworkAddress();
+                if (dst.getValue().equals(hostIP)) {
+                    dstHost = h;
+                    this.destinationHostCache.put(dst, dstHost); // Add to cache
                     break;
                 }
             }
@@ -158,6 +175,7 @@ public class AnalyticsManager implements IReadServiceListener, IAnalyticsManager
      * exists.  Returns null otherwise.
      */
     protected Host getSourceHostFromFlow(Flow flow, Set<HostNodeConnector> hosts) {
+
         Host srcHost = null;
         Match match = flow.getMatch();
 
@@ -245,11 +263,17 @@ public class AnalyticsManager implements IReadServiceListener, IAnalyticsManager
 
     @Override
     public void nodeFlowStatisticsUpdated(Node node, List<FlowOnNode> flowStatsList) {
+
         Set<HostNodeConnector> allHosts = this.hostTracker.getAllHosts();
         for (FlowOnNode f : flowStatsList) {
             Host srcHost = getSourceHostFromFlow(f.getFlow(), allHosts);
             Host dstHost = getDestinationHostFromFlow(f.getFlow(), allHosts);
 
+            if (srcHost == null || dstHost == null) {
+                log.debug("Error: source or destination is null in nodeFlowStatisticsUpdated");
+                continue;
+            }
+
             if (this.hostsToStats.get(srcHost) == null) {
                 this.hostsToStats.put(srcHost, new HashMap<Host, HostStats>());
             }
index 479045552872636a0c4057d0c4a3d7bd5eb41720..84c711b90e0ca085dd9b92bc3fa0989cfc1009ae 100644 (file)
@@ -37,7 +37,11 @@ public class HostStats {
     }
 
     public void setStatsFromFlow(FlowOnNode flow) {
-        this.byteCount = flow.getByteCount();
+        // Prevent stats from getting overwritten by zero-byte flows.
+        // TODO: Figure out why this happens
+        if (flow.getByteCount() > this.byteCount) {
+            this.byteCount = flow.getByteCount();
+        }
         this.duration = flow.getDurationSeconds() + .000000001 * flow.getDurationNanoseconds();
     }
 
index 765335320202b9ce386affbe03dea45128ea9a4f..01cae683fc2be02c58d2f7c5178c8dc1d5be91ad 100644 (file)
@@ -108,14 +108,12 @@ public class AnalyticsManagerIT {
 
     @Before
     public void areWeReady() {
-        System.out.println(">>> Running");
         assertNotNull(bc);
         boolean debugit = false;
         Bundle b[] = bc.getBundles();
         for (int i = 0; i < b.length; i++) {
             int state = b[i].getState();
             if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
-                System.out.println(">>> " + b[i].getSymbolicName() + " " + stateToString(state));
                 log.debug("Bundle:" + b[i].getSymbolicName() + " state:" + stateToString(state));
                 debugit = true;
             }
index d0abab7200b7568c076b1ebf99b0c39b3368a024..2f57731bb9cd29ee6e2436192f2b44ab6628553e 100644 (file)
@@ -28,8 +28,10 @@ class HostStats:
     def refresh(self):
         resp, content = self.http.request("http://localhost:8080/affinity/nb/v2/analytics/default/hoststats/" + self.src + "/" + self.dst, "GET")
         if (resp.status == 404):
+            print "404 error"
             return
         if (resp.status == 503):
+            print "503 error"
             return
         self.host_stats = json.loads(content)
 
@@ -37,6 +39,7 @@ class HostStats:
         try:
             bytes = long(self.host_stats["byteCount"])
         except Exception as e:
+            print "exception:", e
             bytes = 0
         return bytes