source: examples/scaling_tests/daisychain/likes_python/base/QUERY.py @ ecb1628

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since ecb1628 was 7e3f5e2, checked in by Mei <mei@…>, 12 years ago

1) converted daisychain scaling tests

  • Property mode set to 100755
File size: 5.0 KB
RevLine 
[7e3f5e2]1#!/usr/bin/env python
2
3"""
4Run the queries described in README
5
6cmd: env keystore=`pwd` ./query.py
7
8"""
9
10import os
11import sys
12import ABAC
13import time
14import datetime
15import math
16
17debug=0
18
19ctxt = ABAC.Context()
20
21cred_count = 2 + 2 * #VAL#
22
23def get_msec(e_time) :
24    msec_delta=0
25    if( int(e_time.seconds) !=0 ) :
26        msec_delta= int(e_time.seconds) *1000
27    if( int(e_time.microseconds) !=0) :
28        msec_delta = msec_delta + int(e_time.microseconds)/1000
29    return msec_delta
30
31def get_micro(e_time) :
32    micro_delta=0
33    if( int(e_time.seconds) !=0 ) :
34        micro_delta= int(e_time.seconds) *1000000
35    if( int(e_time.microseconds) !=0) :
36        micro_delta = micro_delta + int(e_time.microseconds)
37    return micro_delta
38
39def extract_delta(starttime, endtime) :
40    """ given a start time, and a endtime, extract delta """
41    elapsed_time = (endtime - starttime)
42# Only handle in seconds/microseconds
43    if ( int(elapsed_time.days) != 0 ) :
44        sys.stderr,write("%s is longer than a day !!!" % msg)
45        exit(1)
46    return elapsed_time
47
48
49# Keystore is the directory containing the principal credentials.
50# Load existing principals and/or policy credentials
51if (os.environ.has_key("keystore")) :
52    keystore=os.environ["keystore"]
53    starttime = datetime.datetime.now()
54    ctxt.load_directory(keystore)
55    endtime = datetime.datetime.now()
56    elapsed_load=extract_delta(starttime, endtime)
57    elapsed_msec=get_msec(elapsed_load)
58    sys.stderr.write("%d %d LOAD(msec)\n" % (cred_count,elapsed_msec))
59else:
60    print("keystore is not set...")
61    exit(1)
62
63##########################################################################
64# dump the loaded principals/policies
65#
66
67fd=os.open("creds_dump",os.O_WRONLY|os.O_CREAT)
68credentials = ctxt.credentials()
69for cred in credentials:
70    string="%s <- %s" % (cred.head().string(), cred.tail().string())
71    os.write(fd,string) 
72    os.write(fd,"\n")
73os.close(fd)
74
75##########################################################################
76# Does JohnX likes John0 ?
77# role = [keyid:JohnX].role:after
78# p [Keyid:john0]
79def goodQuery() :
80    aid="John%s_ID.pem"% #VAL#
81    aID=ABAC.ID(aid)
82    bID=ABAC.ID("John0_ID.pem")
83
84    print "\n===good============ johnN.likes <- john0 "
85    starttime = datetime.datetime.now()
86    (success, credentials) = ctxt.query("%s.likes" % aID.keyid(), bID.keyid())
87    if success:
88        print "success"
89    else:
90        print "failure"
91    endtime = datetime.datetime.now()
92    if(debug):
93        print "good query start-> %s\n" % starttime
94        print "good query end  -> %s\n" % endtime
95    for cred in credentials:
96        print "%s <- %s" % (cred.head().string(), cred.tail().string())
97    return extract_delta(starttime, endtime)
98   
99
100##########################################################################
101# Does John0 likes JohnX ?
102# role = [keyid:JohnX].role:after
103# p [Keyid:john0]
104def badQuery() :
105    bid="John%s_ID.pem"% #VAL#
106    bID=ABAC.ID(bid)
107    aID=ABAC.ID("John0_ID.pem")
108
109    print "\n===bad============ john0.likes <- johnX "
110    starttime = datetime.datetime.now()
111    (success, credentials) = ctxt.query("%s.likes" % aID.keyid(), bID.keyid())
112    if success:
113        print "success"
114    else:
115        print "failure"
116    endtime = datetime.datetime.now()
117    for cred in credentials:
118        print "%s <- %s" % (cred.head().string(), cred.tail().string())
119    return extract_delta(starttime, endtime)
120       
121##############################################################
122
123#skip the first one
124e_time=goodQuery()
125elapsed_micro=get_micro(e_time)
126sys.stderr.write("%d %d GOOD_f(micro)\n" % (cred_count,elapsed_micro))
127
128tlist=[]
129k=100
130while(k):
131    e_time=goodQuery()
132    elapsed_micro=get_micro(e_time)
133    k=k-1
134    tlist.append(elapsed_micro)
135    if(k==99):
136       sys.stderr.write("%d %d GOOD_s(micro)\n" % (cred_count,elapsed_micro))
137
138    if(debug):
139        sys.stderr.write("%d %d GOOD_%d(micro)\n" % (cred_count,elapsed_micro,k))
140
141sum=0
142for i in tlist:
143    sum=sum+i
144ave=sum/100
145dlist = [(x-ave) for x in tlist ]
146slist = [ (x-ave)*(x-ave) for x in tlist]
147sum=0
148for i in slist:
149    sum=sum+i
150sd=math.sqrt(sum/99)
151sys.stderr.write("%d %d %d GOOD_t(micro)\n" % (cred_count,ave,sd))
152sys.stderr.write("%d 100 %s GOOD_list(micro)\n" % (cred_count,tlist))
153
154
155###############################################################
156
157e_time=badQuery()
158elapsed_micro=get_micro(e_time)
159sys.stderr.write("%d %d BAD_f(micro)\n" % (cred_count,elapsed_micro))
160
161tlist=[]
162k=100
163while(k):
164    e_time=badQuery()
165    elapsed_micro=get_micro(e_time)
166    tlist.append(elapsed_micro)
167    k=k-1
168    if(k==99):
169        sys.stderr.write("%d %d BAD_s(micro)\n" % (cred_count,elapsed_micro))
170
171    if(debug):
172        sys.stderr.write("%d %d BAD_%d(micro)\n" % (cred_count,elapsed_micro,k))
173
174sum=0
175for i in tlist:
176    sum=sum+i
177ave=sum/100
178dlist = [(x-ave) for x in tlist ]
179slist = [ (x-ave)*(x-ave) for x in tlist]
180sum=0
181for i in slist:
182    sum=sum+i
183sd=math.sqrt(sum/99)
184sys.stderr.write("%d %d %d BAD_t(micro)\n" % (cred_count,ave, sd))
185sys.stderr.write("%d 100 %s BAD_list(micro)\n" % (cred_count,tlist))
Note: See TracBrowser for help on using the repository browser.