source: tests/scaling_tests/daisychain/likes_python/base/QUERY.py @ 6cd69a0

abac0-leakabac0-mei
Last change on this file since 6cd69a0 was 3c30b59, checked in by Mei <mei@…>, 11 years ago

1) add in new refactored regression testing directory
2) undo the abac.hh/ABAC.hh api changes
3) merged with Ted's changes to attribute format/nickname/issuer processing

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