1 __author__ = "Reinaldo Penno"
2 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
3 __license__ = "New-style BSD"
5 __email__ = "repenno@cisco.com"
13 def __init__(self, verbose=False):
14 self.verbose = verbose
17 self.start = time.time()
20 def __exit__(self, *args):
21 self.end = time.time()
22 self.secs = self.end - self.start
23 self.msecs = self.secs * 1000 # millisecs
25 print ("elapsed time: %f ms" % self.msecs)
27 # Parametrized single PUT of list + one element.
30 "service-functions": {
33 "ip-mgmt-address": "20.0.0.10",
41 putheaders = {'content-type': 'application/json'}
42 getheaders = {'Accept': 'application/json'}
43 ODLIP = "127.0.0.1:8080"
44 DELURL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/"
45 GETURL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/"
46 PUTURL = "http://" + ODLIP + "/restconf/config/service-function:service-functions/"
48 # You probably need to adjust this number based on your OS constraints.
49 # Maximum number of incremental PUT list elements
51 # Maximum number of GET requests
53 # We will present PUT reports every 10000 PUTs
55 # We will present GET reports every 10000 PUTs
60 s = requests.Session()
61 print ("Starting GET Performance. Total of %d requests \n" % numgetreq)
62 for numreq in range(0, numgetreq, numgetstep):
65 for i in range(numreq, numreq + numgetstep):
66 r = s.get(GETURL, stream=False )
67 if (r.status_code == 200):
69 print ("=> %d elapsed requests" % (numreq + numgetstep))
70 print ("=> %d requests/s in the last %d reqs" % ((numgetstep)/t.secs, numgetstep))
71 print ("=> %d successful GET requests in the last %d reqs " % (success, numgetstep))
74 # Based on default parameters performs a single PUT. Always overwrite existing elements
76 s = requests.Session()
77 print ("Starting PUT Performance. Total of %d requests\n" % numputreq)
78 for numreq in range(0, numputreq, numputstep):
81 for i in range(numreq, numreq + numputstep):
82 r = s.put(PUTURL, data = (JSONPUT % i), headers=putheaders, stream=False )
83 if (r.status_code == 200):
85 print ("=> %d elapsed requests" % (numreq + numputstep))
86 print ("=> %d requests/s in the last %d reqs" % ((numputstep)/t.secs, numputstep))
87 print ("=> %d successful PUT requests in the last %d reqs " % (success, numputstep))
90 # Delete all service functions
92 print ("Deleting all Service Functions")
93 r = requests.delete(DELURL, headers=getheaders)
94 if (r.status_code == 200) or (r.status_code == 500):
95 print ("Deleted all Service Functions \n")
98 print ("Delete Failed \n")
102 if __name__ == "__main__":