Code for demo-ing AffinityLink statistics 40/1440/1
authorKatrina LaCurts <katrina.lacurts@plexxi.com>
Wed, 25 Sep 2013 17:58:04 +0000 (13:58 -0400)
committerKatrina LaCurts <katrina.lacurts@plexxi.com>
Wed, 25 Sep 2013 17:58:04 +0000 (13:58 -0400)
Signed-off-by: Katrina LaCurts <katrina.lacurts@plexxi.com>
scripts/analytics.py

index 958f532bdb86d9bc0dd40bc4b561c76f5b620de4..d0abab7200b7568c076b1ebf99b0c39b3368a024 100644 (file)
@@ -95,9 +95,10 @@ def main():
     subnet_control = SubnetControl()
     subnet_control.add_subnet("defaultSubnet", "10.0.0.254/8")
 
-    test_mode = True
+    demo_mode = True
 
-    if (test_mode):
+    # Test mode
+    if (not demo_mode):
 
         src = "10.0.0.1"
         dst = "10.0.0.2"
@@ -108,7 +109,50 @@ def main():
         print("%f mbit/s between %s and %s" % (host_stat.get_bit_rate(), src, dst))
         sys.exit()
 
+    print "Usage: [host | link] [bytes | rate] [src dst | link-name]"
+
     # Demo mode
+    while True:
+        request = raw_input("> ")
+        try:
+            request = request.split()
+            request_type = request[0]
+
+            if (request_type == "quit"):
+                sys.exit()
+
+            action = request[1]
+
+            if (request_type == "host"):
+                src, dst = request[2:4]
+                if (action == "bytes"):
+                    host_stat = HostStats(src, dst)
+                    print("%d bytes between %s and %s" % (host_stat.get_bytes(), src, dst))
+                elif (action == "rate"):
+                    host_stat = HostStats(src, dst)
+                    print("%f bit/s between %s and %s" % (host_stat.get_bit_rate(), src, dst))
+                else:
+                    raise Exception
+
+            elif (request_type == "link"):
+                link = request[2]
+                h = httplib2.Http(".cache")
+                h.add_credentials("admin", "admin")
+                resp, content = h.request("http://localhost:8080/controller/nb/v2/analytics/default/affinitylinkstats/" + link, "GET")
+                al_stats = json.loads(content)
+
+                if (action == "bytes"):
+                    print("%d bytes on %s" % (long(al_stats["byteCount"]), link))
+                elif (action == "rate"):
+                    print("%f bit/s on %s" % (float(al_stats["bitRate"]), link))
+                else:
+                    raise Exception
+
+            else:
+                raise Exception
+        except Exception as e:
+            print "Error"
+
 
 if __name__ == "__main__":
     main()