* Fix demo3.py 96/5396/1
authorSuchi Raman <suchi.raman@plexxi.com>
Tue, 18 Feb 2014 19:23:56 +0000 (14:23 -0500)
committerSuchi Raman <suchi.raman@plexxi.com>
Tue, 18 Feb 2014 19:23:56 +0000 (14:23 -0500)
Signed-off-by: Suchi Raman <suchi.raman@plexxi.com>
analytics/implementation/src/main/java/org/opendaylight/affinity/analytics/internal/AnalyticsManager.java
scripts/affinity.py
scripts/demo3.py
scripts/flow-stats.py
scripts/stats.py

index a3e65f447edc052f7dc6d559da4d4746594351f7..edf47029facde98a55259868559f0e2c1c231d3c 100644 (file)
@@ -206,10 +206,12 @@ public class AnalyticsManager implements IReadServiceListener, IAnalyticsManager
                     this.hostsToStats.get(src).get(dst) != null) {
                     if (protocol == null) {
                         byteCount += this.hostsToStats.get(src).get(dst).getByteCount();
-                        //                        log.info("Source and destination: {} and {}.", src, dst);
                     } else
                         byteCount += this.hostsToStats.get(src).get(dst).getByteCount(protocol);
                 }
+                if (src != null && dst != null) {
+                    log.info("Source and destination: {} and {}, byteCount = {}.", src.getNetworkAddress(), dst.getNetworkAddress(), byteCount);
+                }
             }
         }
         return byteCount;
index d96a16593e79df2591570a5f6451ea17a32aa50e..e702235d9ad225f1128875ec0a757bb2984c8932 100644 (file)
@@ -102,11 +102,11 @@ def client_ws_example():
 #    put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/addsubnet/ipprefix/10.0.0.1/mask/31'
 #    rest_method(put_url, "PUT")
 
-    print "add subnet to webservers"
+    print "add endpoint to webservers"
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/add/ip/10.0.0.1'
     rest_method(put_url, "PUT")
 
-    print "add ip to external"    
+    print "add ip to clients"    
     put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/clients/add/ip/10.0.0.3'
     rest_method(put_url, "PUT")
 
@@ -248,7 +248,7 @@ def main():
     print "get_all_affinity_links..."
     get_all_affinity_links()
 
-    test_tap_2()
+#    test_tap_2()
     list_all_hosts()
     return
 
@@ -276,8 +276,8 @@ def add_static_host_tap(al, ipaddr):
 #init_urllib()
 h = httplib2.Http(".cache")
 h.add_credentials('admin', 'admin')
-#if __name__ == "__main__":
-#    main()
+if __name__ == "__main__":
+    main()
 
 
     
index 829fa104f0fbe38f8afde7e50bbd5ee4cac9e058..ae0bbaedd2de954a9462bd66469882d151e3584d 100644 (file)
@@ -27,8 +27,8 @@ global rate_high
 global prefix
 
 link_name = "inflows"
-rate_low = (100 * 10**3)  # 100 kbps
-rate_high = (1 * 10**6) # 1 Mbps
+rate_high = (100 * 10**6)  # 100 mbps
+rate_low = (10 * 10**6) # 10 mbps
 prefix = "10.0.0.254/8"
 
 # If True, SIG_INT has been captured
@@ -56,12 +56,12 @@ class WaypointMonitor(Thread):
 
     def set_high_threshold(self, s):
         self.stat.set_high_threshold(s)
-        print "Set high threshold for flow rate to %d bps" % s
+        print "Set high threshold for flow rate to %3.3f Mbps" % (int(s) * (1.0/1000000))
         print("-------------------------")
 
     def set_low_threshold(self, s):
         self.stat.set_low_threshold(s)
-        print "Set low threshold for flow rate to %d bps" % s
+        print "Set low threshold for flow rate to %3.3f Mbps" % (int(s) * (1.0/1000000))
         print("-------------------------")
 
     def run(self):
@@ -69,21 +69,20 @@ class WaypointMonitor(Thread):
         high_rate_set = False
         while not sigint:
             is_high, is_low = self.stat.refresh()
-            print "Rate is: %f" % (self.stat.get_ewma_rate())
             if is_high and not high_rate_set:
-                print "Fast flow detected (%3.3f bit/s)" % (self.stat.get_ewma_rate())
                 ac = AffinityControl()
-#                ac.add_waypoint(link_name, self.waypoint_address)
-##                ac.add_isolate(link_name)
-##                ac.enable_affinity()
                 high_rate_set = True
-#                time.sleep(3)            
+#                ac.add_waypoint(link_name, self.waypoint_address)
+                ac.add_isolate(link_name)
+                ac.enable_affinity()
+                print "Adding isolate affinity to link: %s" % (link_name)
+#                time.sleep(3)
             elif is_low and high_rate_set: 
-                print "Flow rate below threshold (%3.3f bit/s)" % (self.stat.get_ewma_rate())
-##               ac.remove_isolate(link_name)
-##               ac.disable_affinity()
                 high_rate_set = False
-            time.sleep(1)
+                ac.remove_isolate(link_name)
+                ac.enable_affinity()
+                print "Adding isolate affinity to link: %s" % (link_name)
+            time.sleep(10)
 
 def main():
 
index 9a441c1eb42f194b6273d1885188c7a83df56a82..f7b7ba48a027236468975b85c1a7fbb181312848 100644 (file)
@@ -28,6 +28,7 @@ def get_flow_stats():
         print "# flows =  %d" % len(flows)
         for f in flows: 
             print f["flow"]["match"], "priority = ", f["flow"]["priority"]
+            print "seconds = ", f["durationSeconds"], "packets = ", f["packetCount"], "bytes = ", f["byteCount"] 
             print "\t Actions:"
             for a in f["flow"]["actions"]:
                 print "\t \t", a 
index 4bf6fbdd97606866e7302f624892f6393dc0b64d..a72e233010f89adf81eba303f9502d785b029f9b 100644 (file)
@@ -31,7 +31,6 @@ class Stats:
 
         self.large_flow_threshold = 5 * 10**6 # in bytes
         self.rate_threshold = 1 * 10**6 # bits/sec
-        print "Created stats"
 
     def __str__(self):
         if (self.stat_type == Stats.TYPE_HOST):
@@ -122,8 +121,8 @@ class Stats:
         if (self.prev_t == None or self.prev_bytes == None): 
             new_bitrate = 0
         else:
-            new_bitrate = (self.get_bytes() - self.prev_bytes)/(self.get_duration() - self.prev_t)
-            print "Rate is now %f" % (new_bitrate)
+            new_bitrate = 8.0 * (self.get_bytes() - self.prev_bytes)/(self.get_duration() - self.prev_t)
+#            print "Rate is now %f" % (new_bitrate)
 
         # Calculate ewma rate from instantaneous rate and check if it crosses threshold.
         if (self.rate_ewma == None): 
@@ -132,18 +131,16 @@ class Stats:
             self.rate_ewma = alpha * new_bitrate + (1 - alpha) * self.rate_ewma
 
         if (self.rate_ewma > self.rate_high_threshold): 
-            print "Rate exceeded %f" % (self.rate_ewma)
+            print "High rate: %3.3f Mbps" % (self.rate_ewma/1000000.0)
             is_high = True
         
-        if (self.rate_ewma < self.rate_high_threshold): 
-            print "Rate dropped %f" % (self.rate_ewma)
+        if (self.rate_ewma < self.rate_low_threshold): 
+            print "Low rate: %3.3f Mbps" % (self.rate_ewma/1000000.0)
             is_low = True
         
         # Update the time and bytes snapshots
         self.prev_t = self.get_duration()
         self.prev_bytes = self.get_bytes()
-#        print "calc_ewma_rate: [high=%s:low=%s] rate=%f" % (is_high, is_low, self.rate_ewma)
-        print "calc_ewma_rate: rate=%f" % (self.rate_ewma)
         return [is_high, is_low]