- Undo some in progress changes. 05/4805/1
authorSuchi Raman <suchi.raman@plexxi.com>
Sun, 26 Jan 2014 15:50:52 +0000 (10:50 -0500)
committerSuchi Raman <suchi.raman@plexxi.com>
Sun, 26 Jan 2014 15:50:52 +0000 (10:50 -0500)
- fix URL in api call

Signed-off-by: Suchi Raman <suchi.raman@plexxi.com>
scripts/affinity_control.py
scripts/analytics.py
scripts/demo.py
scripts/stats.py

index d1936288a1c99e2c02423fef2a451aa963ad677c..bc8b670305c435dd2511888fab31b22e33ca895f 100644 (file)
@@ -78,20 +78,12 @@ class AffinityControl:
 
     # Disable waypoint
     def disable_waypoint(self, link_name):
-        resp, content = self.http.request(self.url_prefix + "link/%s/unsetwaypoint" % link_name, "PUT")
+        resp, content = self.http.request(self.url_prefix + "link/%s/disable" % link_name, "PUT")
         if (resp.status != 201):
             print "Waypoint could not be disabled for link %s" % link_name
             return
         print "Waypoint disabled for link %s" % link_name
 
-    # Disable isolate 
-    def disable_isolate(self, link_name):
-        resp, content = self.http.request(self.url_prefix + "link/%s/unsetisolate" % link_name, "PUT")
-        if (resp.status != 201):
-            print "Isolate could not be disabled for link %s" % link_name
-            return
-        print "Isolate disabled for link %s" % link_name
-
     # Enable all affinity rules
     def enable_affinity(self):
         resp, content = self.http.request(self.flatl2url_prefix + "enableaffinity", "PUT")
index 49b11d218776bb2e77d959f5ac5538f63c3dd13f..1c6297c17caaeeb2db6f1f11dfcd932cb614213d 100644 (file)
@@ -68,7 +68,6 @@ def stats_hosts(src, dst, do_print=True):
     data = rest_method(url, "GET")
     if (do_print):
         print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"]))
-    print data
     return data
 
 def stats_hosts_protocol(src, dst, protocol, do_print=True):
@@ -76,7 +75,6 @@ def stats_hosts_protocol(src, dst, protocol, do_print=True):
     data = rest_method(url, "GET")
     if (do_print):
         print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"]))
-    print data
     return data
 
 def all_stats_hosts(src, dst, do_print=True):
@@ -91,7 +89,6 @@ def all_stats_hosts(src, dst, do_print=True):
     except:
         data = {}
     finally:
-        print data
         return data
 
 ### Affinity link statistics
@@ -101,7 +98,6 @@ def stats_link(al, do_print=True):
     data = rest_method(url, "GET")
     if (do_print):
         print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"]))
-    print data
     return data
 
 def stats_link_protocol(al, protocol, do_print=True):
@@ -109,7 +105,6 @@ def stats_link_protocol(al, protocol, do_print=True):
     data = rest_method(url, "GET")
     if (do_print):
         print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"]))
-    print data
     return data
 
 def all_stats_link(al, do_print=True):
@@ -124,7 +119,6 @@ def all_stats_link(al, do_print=True):
     except:
         data = {}
     finally:
-        print data
         return data
 
 ### Subnet statistics
@@ -134,7 +128,6 @@ def stats_subnet(src_sub, dst_sub, do_print=True):
     data = rest_method(url, "GET")
     if (do_print):
         print("%s bytes (%s packets) over %s seconds (%s bit/s)" % (data["byteCount"], data["packetCount"], data["duration"], data["bitRate"]))
-    print data
     return data
 
 def stats_subnet_protocol(src_sub, dst_sub, protocol, do_print=True):
index 24bacf7a6d501d7ec4468cac0e9642ee2c162a06..60f239f66c18a1fa8fbdf8d7086240616ce79ec0 100644 (file)
@@ -58,27 +58,23 @@ class WaypointMonitor(Thread):
         self.waypoint_address = waypoint_ip
         print "Registered waypoint for %s.  Any large flows will be redirected to %s." % (self.stat, waypoint_ip)
 
-    def set_flow_thresholds(self, high, low):
-        self.stat.set_flow_thresholds(high, low)
-        print "Set threshold for large flows to %d, %d bytes" % (high,  low)
+    def set_large_flow_threshold(self, s):
+        self.stat.set_large_flow_threshold(s)
+        print "Set threshold for large flows to %d bytes" % s
         print("-------------------------")
 
     def run(self):
         global sigint
         did_waypoint = False
         while not sigint:
-            print "**** Stat refresh ****"
-            _, is_big, is_small = self.stat.refresh()
-            print "is_big is ", is_big
-            print "is_small is ", is_small
-
+            _, is_big = self.stat.refresh()
             if is_big and not did_waypoint:
                 print "Large flow detected (%d bytes, %d packets, %3.3f bit/s)" % (self.stat.get_bytes(), self.stat.get_packets(), self.stat.get_bit_rate())
-#                print "   ICMP: %d bytes, %d packets" % (self.stat.get_bytes(1), self.stat.get_packets(1))
-#                print "   UDP: %d bytes, %d packets" % (self.stat.get_bytes(17), self.stat.get_packets(17))
-#                print "   TCP: %d bytes, %d packets" % (self.stat.get_bytes(6), self.stat.get_packets(6))
-#                print "   other (tbd): %d bytes, %d packets" % (self.stat.get_bytes(-1), self.stat.get_packets(-1))
-#                print("-------------------------")
+                print "   ICMP: %d bytes, %d packets" % (self.stat.get_bytes(1), self.stat.get_packets(1))
+                print "   UDP: %d bytes, %d packets" % (self.stat.get_bytes(17), self.stat.get_packets(17))
+                print "   TCP: %d bytes, %d packets" % (self.stat.get_bytes(6), self.stat.get_packets(6))
+                print "   other: %d bytes, %d packets" % (self.stat.get_bytes(-1), self.stat.get_packets(-1))
+                print("-------------------------")
                 ac = AffinityControl()
                 # First AG: Sources sending data into this subnet
                 src_ag_name = "sources"
@@ -102,17 +98,10 @@ class WaypointMonitor(Thread):
 #                ac.enable_waypoint(link_name)
                 ac.enable_affinity()
                 did_waypoint = True
-                time.sleep(30)
-            # Below low water mark. 
-            elif (is_small and did_waypoint): 
-                print "Disable affinity configuration."
-                ac = AffinityControl()
-                link_name = "inflows"
-                ac.disable_affinity() # Clear all openflow rules
-                ac.disable_waypoint(link_name) # Clear waypoint configuration
-                ac.disable_isolate(link_name)  # Clear isolate configuration
-                did_waypoint = False # Reset, so that we can detect again.
-            time.sleep(5)
+                raw_input("[Press Enter to disable affinity rules] ")
+                ac.disable_affinity()
+#                ac.disable_waypoint(link_name)
+            time.sleep(1)
 
 def main():
 
@@ -130,7 +119,7 @@ def main():
 
     m = WaypointMonitor(Stats.TYPE_SUBNET, subnet="10.0.0.0/31")
     m.set_waypoint("10.0.0.2")
-    m.set_flow_thresholds(200, 50) # 2000 bytes
+    m.set_large_flow_threshold(2000) # 2000 bytes
     m.start()
 
     # Register signal-handler to catch SIG_INT
index d252c9aba11f382662f82b05969871ae66050db9..096da966255752967a054b7fa0acd76171d2be16 100644 (file)
@@ -25,23 +25,8 @@ class Stats:
 
         self.stats = {}
         self.protocol_stats = {}
-        self.last_value = {}
-        self.last_transfer = {}
-        
-        # Initialize last value read
-        self.last_value["None"] = 0
-        self.last_transfer["None"] = 0
-
-        protocols = [1, 6, 17] # ICMP, TCP, UDP
-        for protocol in protocols: 
-            self.last_value[protocol] = 0
-            self.last_transfer[protocol] = 0
-        
         self.rate_ewma = None
-        self.flow_high_threshold = 5 * 10**6 # in bytes
-        self.flow_low_threshold = 5 * 10**3 # in bytes
-
-        self.flow_bytes = 0 # Last value of bytes transferred for this flow. 
+        self.large_flow_threshold = 5 * 10**6 # in bytes
 
     def __str__(self):
         if (self.stat_type == Stats.TYPE_HOST):
@@ -65,18 +50,14 @@ class Stats:
             self.stats = analytics.stats_subnet("null/null", self.subnet, True)
             self.protocol_stats = analytics.all_stats_subnet("null/null", self.subnet, True)
         try:
-            self.reset_bytes()
             is_fast = self.handle_rate_ewma()
             is_big = self.check_large_flow()
-            is_small = self.check_small_flow()
-            return [is_fast, is_big, is_small]
+            return [is_fast, is_big]
         except:
-            return [False, False, False]
+            return [False, False]
 
-            
-    def set_flow_thresholds(self, high, low):
-        self.flow_high_threshold = high;
-        self.flow_low_threshold = low;
+    def set_large_flow_threshold(self, s):
+        self.large_flow_threshold = s;
 
     # Return all hosts that transferred a particular percentage of data into this entity.  Right now only supports subnets.
     def get_large_incoming_hosts(self):
@@ -115,12 +96,7 @@ class Stats:
 
     # Returns true if this is a large flow
     def check_large_flow(self):
-        if (self.get_bytes() > self.flow_high_threshold):
-            return True
-        return False
-
-    def check_small_flow(self):
-        if (self.get_bytes() < self.flow_low_threshold):
+        if (self.get_bytes() > self.large_flow_threshold):
             return True
         return False
 
@@ -128,34 +104,13 @@ class Stats:
     def get_bytes(self, protocol=None):
         try:
             if (protocol == None):
-                bytes = long(self.last_transfer["None"]) 
+                bytes = long(self.stats["byteCount"])
             else:
-                bytes = long(self.last_transfer[protocol]) 
+                bytes = long(self.protocol_stats[protocol]["byteCount"])
         except Exception as e:
             bytes = 0
-            print "get_bytes exception"
         return bytes
 
-    # Bytes
-    def reset_bytes(self, protocol=None):
-        try:
-            if (protocol == None):
-                bytes = long(self.stats["byteCount"]) 
-                lv = self.last_value["None"]
-                self.last_value["None"] = bytes
-                self.last_transfer["None"] = (bytes - lv)
-            else:
-                bytes = long(self.protocol_stats[protocol]["byteCount"]) 
-                lv = self.last_value[protocol]
-                self.last_value[protocol] = bytes
-                self.last_transfer[protocol] = (bytes - lv)
-        except Exception as e:
-            bytes = 0
-            lv = 0
-            print "reset_bytes exception"
-        print "*** lv = %d, bytes = %d" % (lv, bytes)
-        return (bytes - lv)
-
     # Packets
     def get_packets(self, protocol=None):
         try: