Test-Perf:
    Adding system validation and utility functions to be called from
    performance or scale tests.

Change-Id: Ic6dae70aa4535a506a1e619de402c4188f5f0e08
diff --git a/src/test/utils/Perf.py b/src/test/utils/Perf.py
new file mode 100644
index 0000000..516b47d
--- /dev/null
+++ b/src/test/utils/Perf.py
@@ -0,0 +1,73 @@
+import os
+import subprocess
+import requests
+import json
+import time
+from CordTestUtils import log_test as log, getstatusoutput, get_controller
+from OnosCtrl import OnosCtrl
+
+class perf(object):
+    def  __init__(self, controller, interface = 'eth0'):
+         self.controller = controller
+         self.interface = interface
+
+    def  know_cpu_freq(self):
+         freq = open('/proc/cpuinfo/','r')
+         freqs = freq.read()
+         freq.seek(0)
+         cpuentry = freq.readline()
+         cpusplit = cpuentry.split()
+
+         while cpusplit[0] != "cpu":
+              while cpusplit[0] != "MHz":
+                    cpuline = freq.readline()
+                    cpusplit = cpuline.split()
+         freq.close()
+         cpu_mhz = cpusplit[3]
+         return cpu_mhz
+
+    def  retrieve_cpu_stats(self):
+         cpu = open('/proc/stat/','r').readlines()[0]
+         return map(float, cpu.split()[1:5])
+
+    def  validate_cpu_performance(self, interval):
+         time_stamp1 = retrieve_cpu_stats()
+         time.sleep(interval)
+         time_stamp2 = retrieve_cpu_stats()
+         diff = [time_stamp2[i] - time_stamp1[i] for i in range(len(time_stamp1))]
+         try:
+             return 1.0 - (diff[-1:].pop()/(sum(diff)*1.0))
+         except:
+             return 0.0
+
+    def  memory_usage(self):
+         cmd_run = subprocess.check_output(['free','-b'])
+         memory = cmd_run.split()
+         total = int(memory[7])
+         used = int(memory[8])
+         free = int(memory[9])
+         return total, used, free
+
+    def  rx_network_stats(self, intf):
+         for entry in open('/proc/net/dev', 'r'):
+             if intf in entry:
+                stat = entry.split('%s:' % intf)[1].split()
+                rx_bytes = stat[0]
+                rx_packets = stat[1]
+                rx_errors = stat[2]
+                rx_drops = stat[3]
+         return int(rx_bytes), int(rx_packets), int(rx_errors), int(rx_drops)
+
+    def  tx_network_stats(self, intf):
+         for entry in open('/proc/net/dev', 'r'):
+             if intf in entry:
+                stat = entry.split('%s:' % intf)[1].split()
+                tx_bytes = stat[8]
+                tx_packets = stat[9]
+                tx_errors = stat[10]
+                tx_drops = stat[11]
+         return int(tx_bytes), int(tx_packets), int(tx_errors), int(tx_drops)
+
+    def  check_node_uptime(self):
+         return float(open('/proc/uptime','r').read().split(' ')[0])
+