-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexperiments.py
5497 lines (4892 loc) · 256 KB
/
experiments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## Imports
from subprocess import Popen
import subprocess
from pathlib import Path
import matplotlib.pyplot as plt
import matplotlib
import time
import math
import os
import glob
from datetime import datetime
import argparse
from enum import Enum
import json
import multiprocessing
import random
from shutil import copyfile
import re
import mmap
#############
## Notes:
## (1) The nodes get started by a MsgStart message, which is currently sent by clients
## (2) The nodes will stop if there is no activity for 'numViews' views,
## in the sense that no client transactions are processed, only dummy transactions
## So for performance measurement of the nodes themselves, one can set 'numClTrans'
## to 1, and nodes will only process dummy transactions
## TODO: to set it to 0, I have to find a way to stop clients cleanly
## (3) View-changes on timeouts are not implemented yet, currently nodes simply stop when
## they timeout.
## TODO: once they are implemented, I have to find a way to stop nodes cleanly
## (4) If 'sleepTime' is too high and 'newViews' too low, then the nodes will give up before
## they process all the clients' requests because they'll think they've been idle for too
## long. Therefore, at the moment for throughput vs. latency measurement, it's better to
## set 'newViews' to 0, in which case the nodes keep going for ever (until they timeout).
## The experiments will be stopped after 'cutOffBound' in that case.
####
## Parameters
sgxmode = "SIM"
#sgxmode = "HW"
srcsgx = "source /opt/intel/sgxsdk/environment" # this is where the sdk is supposed to be installed
faults = [1] #[1,2,4,10] #[1,2,4,10,20,30,40] #[1,2,4,6,8,10,12,14,20,30] # list of numbers of faults
#faults = [1,10,20,30,40,50]
#faults = [40]
repeats = 100 #10 #50 #5 #100 #2 # number of times to repeat each experiment
repeatsL2 = 1
#
numViews = 30 # number of views in each run
cutOffBound = 60 # stop experiment after some time
#
numClients = 1 # number of clients
numNonChCls = 1 # number of clients for the non-chained versions
numChCls = 1 # number of clients for the chained versions
numClTrans = 1 # number of transactions sent by each clients
sleepTime = 0 # time clients sleep between 2 sends (in microseconds)
timeout = 5 # timeout before changing changing leader (in seconds)
#
opdist = 0
#
numTrans = 400 # number of transactions
payloadSize = 0 #256 #0 #256 #128 # total size of a transaction
useMultiCores = True
numMakeCores = multiprocessing.cpu_count() # number of cores to use to make
#
runBase = False #True
runCheap = False #True
runQuick = False #True
runComb = False #True
runFree = False #True
runOnep = False #True
runOnepB = False #True
runOnepC = False #True
runOnepD = False #True
runChBase = False #True
runChComb = False #True
# Debug versions
runQuickDbg = False #True
runChCombDbg = False #True
#
plotView = True # to plot the numbers of handling messages + network
plotHandle = False # to plot the numbers of just handling messages, without the network
plotCrypto = False # to plot the numbers of do crypto
debugPlot = True #False # to print debug info when plotting
showTitle = True # to print the title of the figure
plotThroughput = True
plotLatency = True
expmode = "" # "TVL"
showLegend1 = True
showLegend2 = False
plotBasic = True
plotChained = True
displayPlot = True # to display a plot once it is generated
showYlabel = True
displayApp = "shotwell"
logScale = True
barPlot = False #True
# to recompile the code
recompile = True
# To set some plotting parameters for specific experiments
whichExp = ""
# For some experiments we start with f nodes dead
deadNodes = False #True
# if deadNodes then we go with less views and give ourselves more time
if deadNodes:
numViews = numViews // timeout
cutOffBound = cutOffBound * 2
# For some experiments we remove the outliers
quantileSize = 20
# don't change, those are hard coded in the C++ code:
statsdir = "stats" # stats directory (don't change, hard coded in C++)
params = "App/params.h" # (don't change, hard coded in C++)
config = "App/config.h" # (don't change, hard coded in C++)
addresses = "config" # (don't change, hard coded in C++)
ipsOfNodes = {} # dictionnary mapping node ids to IPs
# to copy all files to AWS instances
copyAll = True
# set to True to randomize regions before assiging nodes to them (especially for low number of nodes)
randomizeRegions = False #True
## Global variables
completeRuns = 0 # number of runs that successfully completed
abortedRuns = 0 # number of runs that got aborted
aborted = [] # list of aborted runs
allLocalPorts = [] # list of all port numbers used in local experiments
dateTimeObj = datetime.now()
timestampStr = dateTimeObj.strftime("%d-%b-%Y-%H:%M:%S.%f")
pointsFile = statsdir + "/points-" + timestampStr
abortedFile = statsdir + "/aborted-" + timestampStr
plotFile = statsdir + "/plot-" + timestampStr + ".png"
clientsFile = statsdir + "/clients-" + timestampStr
tvlFile = statsdir + "/tvl-" + timestampStr + ".png"
debugFile = statsdir + "/debug-" + timestampStr
# Names
baseHS = "Basic HotStuff"
cheapHS = "Damysus-C"
quickHS = "Damysus-A"
combHS = "Basic-Damysus"
freeHS = "Light-Damysus"
onepHS = "Basic-OneShot"
onepbHS = "Basic-OneShot(2)"
onepcHS = "Basic-OneShot(3)"
onepdHS = "Basic-OneShot(4)"
baseChHS = "Chained HotStuff"
combChHS = "Chained-Damysus"
# Markers
baseMRK = "P"
cheapMRK = "o"
quickMRK = "*"
combMRK = "X"
freeMRK = "s"
onepMRK = "+"
onepbMRK = "+"
onepcMRK = "+"
onepdMRK = "+"
baseChMRK = "d"
combChMRK = ">"
# Line styles
baseLS = ":"
cheapLS = "--"
quickLS = "-."
combLS = "-"
freeLS = "-"
onepLS = "-"
onepbLS = "-"
onepcLS = "-"
onepdLS = "-"
baseChLS = ":"
combChLS = "-"
# Markers
baseCOL = "black"
cheapCOL = "blue"
quickCOL = "green"
combCOL = "red"
freeCOL = "purple"
onepCOL = "brown"
onepbCOL = "pink"
onepcCOL = "cyan"
onepdCOL = "yellow"
baseChCOL = "darkorange"
combChCOL = "magenta"
## AWS parameters
instType = "t2.micro"
pem = "aws.pem"
# Region - North Virginia (us-east-1)
region_USEAST1 = "us-east-1"
imageID_USEAST1 = "ami-00d7b3d79694d6c0c" #"ami-09acfeca0b09f521f"
secGroup_USEAST1 = "sg-0266789e1c3d42c86"
# Region - Ohio (us-east-2)
region_USEAST2 = "us-east-2"
imageID_USEAST2 = "ami-0d9352c87302e23ea" #"ami-0182bc3b30beedfa4"
secGroup_USEAST2 = "sg-0d89fb07bbd3d7700"
subnetID_USEAST2_1 = "subnet-bc5baad7" # us-east-2a
subnetID_USEAST2_2 = "subnet-30624c4a" # us-east-2b
subnetID_USEAST2_3 = "subnet-25891f69" # us-east-2c
# Region - North California (us-west-1)
region_USWEST1 = "us-west-1"
imageID_USWEST1 = "ami-0dfa74c225fb8c20b" #"ami-0c9bcbfb9feca56c7"
secGroup_USWEST1 = "sg-0f7addd92bbae0cc2"
# Region - Oregon (us-west-2)
region_USWEST2 = "us-west-2"
imageID_USWEST2 = "ami-08ec50c7363bc5c50" #"ami-087b7bf2921249dc8"
secGroup_USWEST2 = "sg-02435aae297812913"
# Region - Singapore (ap-southeast-1)
region_APSEAST1 = "ap-southeast-1"
imageID_APSEAST1 = "ami-07a6e7819f6d63dfe" #"ami-087f6cdc8a0780f6f"
secGroup_APSEAST1 = "sg-01de5d6a5bd5576b8"
# Region - Sydney (ap-southeast-2)
region_APSEAST2 = "ap-southeast-2"
imageID_APSEAST2 = "ami-066ec398d3ccac032" #"ami-085ea5cb0e80ebfd1"
secGroup_APSEAST2 = "sg-02b6c7b19d8c78ce6"
# Region - Ireland (eu-west-1)
region_EUWEST1 = "eu-west-1"
imageID_EUWEST1 = "ami-0464c84f3209ab9a1" #"ami-00477ebbb8f6355a4"
secGroup_EUWEST1 = "sg-00033137d10223166"
# Region - London (eu-west-2)
region_EUWEST2 = "eu-west-2"
imageID_EUWEST2 = "ami-05537b7b067e11d64" #"ami-00ceb682affe4d8d8"
secGroup_EUWEST2 = "sg-0da2a5dfe0d929307"
# Region - Paris (eu-west-3)
region_EUWEST3 = "eu-west-3"
imageID_EUWEST3 = "ami-0ec36d6c70d7509e7" #"ami-0186f01a534d9ff40"
secGroup_EUWEST3 = "sg-03d07bde43685b6bf"
# Region - Frankfurt (eu-central-1)
region_EUCENT1 = "eu-central-1"
imageID_EUCENT1 = "ami-0f435b368fd581c26" #"ami-048124818d35d6e15"
secGroup_EUCENT1 = "sg-0b8b49fa3c6b6c77f"
# Region - Canada Central (ca-central-1)
region_CACENT1 = "ca-central-1"
imageID_CACENT1 = "ami-059fd80230a4c4512" #"ami-006e2b38fa3f30a8e"
secGroup_CACENT1 = "sg-0ce99bc9e1b8a252c"
# Regions around the world
WregionsNAME = "w"
Wregions = [(region_USEAST2, imageID_USEAST2, secGroup_USEAST2),
(region_APSEAST2, imageID_APSEAST2, secGroup_APSEAST2),
(region_EUWEST2, imageID_EUWEST2, secGroup_EUWEST2),
(region_CACENT1, imageID_CACENT1, secGroup_CACENT1)]
# US regions
USregionsNAME = "us"
USregions = [(region_USEAST1, imageID_USEAST1, secGroup_USEAST1),
(region_USEAST2, imageID_USEAST2, secGroup_USEAST2),
(region_USWEST1, imageID_USWEST1, secGroup_USWEST1),
(region_USWEST2, imageID_USWEST2, secGroup_USWEST2)]
# EU regions
EUregionsNAME = "eu"
EUregions = [(region_EUWEST1, imageID_EUWEST1, secGroup_EUWEST1),
(region_EUWEST2, imageID_EUWEST2, secGroup_EUWEST2),
(region_EUWEST3, imageID_EUWEST3, secGroup_EUWEST3),
(region_EUCENT1, imageID_EUCENT1, secGroup_EUCENT1)]
# One region
ONEregionsNAME = "one"
ONEregions = [(region_USEAST2, imageID_USEAST2, secGroup_USEAST2)]
# All regions
ALLregionsNAME = "all"
ALLregions = [(region_USEAST1, imageID_USEAST1, secGroup_USEAST1),
(region_USEAST2, imageID_USEAST2, secGroup_USEAST2),
(region_USWEST1, imageID_USWEST1, secGroup_USWEST1),
(region_USWEST2, imageID_USWEST2, secGroup_USWEST2),
(region_EUWEST1, imageID_EUWEST1, secGroup_EUWEST1),
(region_EUWEST2, imageID_EUWEST2, secGroup_EUWEST2),
(region_EUWEST3, imageID_EUWEST3, secGroup_EUWEST3),
(region_EUCENT1, imageID_EUCENT1, secGroup_EUCENT1),
(region_APSEAST1, imageID_APSEAST1, secGroup_APSEAST1),
(region_APSEAST2, imageID_APSEAST2, secGroup_APSEAST2),
(region_CACENT1, imageID_CACENT1, secGroup_CACENT1)]
# All regions -- same as ALLregions but in a different order
ALL2regionsNAME = "all2"
ALL2regions = [(region_USEAST1, imageID_USEAST1, secGroup_USEAST1),
(region_EUWEST1, imageID_EUWEST1, secGroup_EUWEST1),
(region_APSEAST1, imageID_APSEAST1, secGroup_APSEAST1),
(region_CACENT1, imageID_CACENT1, secGroup_CACENT1),
(region_USEAST2, imageID_USEAST2, secGroup_USEAST2),
(region_EUWEST2, imageID_EUWEST2, secGroup_EUWEST2),
(region_APSEAST2, imageID_APSEAST2, secGroup_APSEAST2),
(region_USWEST1, imageID_USWEST1, secGroup_USWEST1),
(region_EUWEST3, imageID_EUWEST3, secGroup_EUWEST3),
(region_USWEST2, imageID_USWEST2, secGroup_USWEST2),
(region_EUCENT1, imageID_EUCENT1, secGroup_EUCENT1)]
## regions = (USregionsNAME, USregions)
#regions = (EUregionsNAME, EUregions)
## regions = (WregionsNAME, Wregions)
regions = (ONEregionsNAME, ONEregions)
#regions = (ALLregionsNAME, ALLregions)
## regions = (ALL2regionsNAME, ALL2regions)
sshOpt1 = "StrictHostKeyChecking=no"
sshOpt2 = "ConnectTimeout=10"
# Files
instFile = "instances"
descrFile = "description"
## Docker parameters
runDocker = False # to run the code within docker contrainers
docker = "docker"
dockerBase = "damysus" # name of the docker container
networkLat = 0 # network latency in ms
networkVar = 0 # variation of the network latency
rateMbit = 0 # bandwidth
dockerMem = 0 # memory used by containers (0 means no constraints)
dockerCpu = 0 # cpus used by containers (0 means no constraints)
startRport = 8760
startCport = 9760
## Cluster parameters
clusterFile = "nodes"
clusterNet = "damysusNet" # "bridge"
mybridge = "damysusNet" # "bridge"
## Code
class Protocol(Enum):
BASE = "BASIC_BASELINE" # basic baseline
CHEAP = "BASIC_CHEAP" # Checker only
QUICK = "BASIC_QUICK" # Accumulator only
COMB = "BASIC_CHEAP_AND_QUICK" # Damysus (Checker + Accumulator)
FREE = "BASIC_FREE" # hash & signature-free Damysus
ONEP = "BASIC_ONEP" # 1+1/2 phase Damysus (case 1)
ONEPB = "BASIC_ONEPB" # 1+1/2 phase Damysus (case 2)
ONEPC = "BASIC_ONEPC" # 1+1/2 phase Damysus (case 3)
ONEPD = "BASIC_ONEPD" # 1+1/2 phase Damysus (case 4)
CHBASE = "CHAINED_BASELINE" # chained baseline
CHCOMB = "CHAINED_CHEAP_AND_QUICK" # chained Damysus
## Debug versions
QUICKDBG = "BASIC_QUICK_DEBUG"
CHCOMBDBG = "CHAINED_CHEAP_AND_QUICK_DEBUG" # chained Damysus - debug version
## generates a local config file
def genLocalConf(n,filename):
open(filename, 'w').close()
host = "127.0.0.1"
global allLocalPorts
print("ips:" , ipsOfNodes)
f = open(filename,'a')
for i in range(n):
host = ipsOfNodes.get(i,host)
rport = startRport+i
cport = startCport+i
allLocalPorts.append(rport)
allLocalPorts.append(cport)
f.write("id:"+str(i)+" host:"+host+" port:"+str(rport)+" port:"+str(cport)+"\n")
f.close()
# End of genLocalConf
def findPublicDnsName(j):
for res in j["Reservations"]:
for inst in res["Instances"]:
priv = inst["PrivateIpAddress"]
pub = inst["PublicIpAddress"]
dns = inst["PublicDnsName"]
status = inst["State"]["Name"]
if status == "running":
return (priv,pub,dns)
else:
RuntimeError('instance is not yet running')
raise RuntimeError('Failed to find public dns name')
def getPublicDnsName(region,i):
while True:
try:
g = open(descrFile,'w')
subprocess.run(["aws","ec2","describe-instances","--region",region,"--instance-ids",i], stdout=g)
g.close()
g = open(descrFile,'r')
output = json.load(g)
#print(output)
g.close()
(priv,pub,dns) = findPublicDnsName(output)
return (priv,pub,dns)
# g = open(descrFile,'w')
# subprocess.run(["aws","ssm","get-connection-status","--target",i], stdout=g)
# g.close()
# g = open(descrFile,'r')
# output = json.load(g)
# g.close()
# if output["Status"] == "connected":
# return (priv,pub,dns)
# else:
# print("oops, not yet connected:", i)
except KeyError:
print("oops, cannot get address yet:", i)
time.sleep(1)
except RuntimeError as e:
print("oops, error:", i, e.args)
time.sleep(1)
def startInstances(numRepInstances,numClInstances):
print(">> starting",str(numRepInstances),"replica instance(s)")
print(">> starting",str(numClInstances),"client instance(s)")
regs = regions[1]
if randomizeRegions:
random.shuffle(regs)
numInstances = numRepInstances + numClInstances
numRegions = min(numInstances,len(regs))
k, r = divmod(numInstances,numRegions)
#print(str(numInstances),str(numRegions),str(k),str(r))
allInstances = []
print("all regions:", str(regs[0:numRegions]))
for i in range(numRegions):
iFile = instFile + str(i)
f = open(iFile,'w')
reg = regs[i]
(region,imageID,secGroup) = reg
count = k+1 if i >= numRegions - r else k # the last r regions all run 1 more instance
print("starting", str(count), "instance(s) here:", str(reg))
#subprocess.run(["aws","ec2","run-instances","--region",region,"--image-id",imageID,"--count",str(numRepInstances+numClInstances),"--instance-type",instType,"--security-group-ids",secGroup,"--subnet-id",subnetID1_1], stdout=f)
#subprocess.run(["aws","ec2","run-instances","--region",region,"--image-id",imageID,"--count",str(numRepInstances+numClInstances),"--instance-type",instType,"--security-group-ids",secGroup], stdout=f)
print("aws ec2 run-instances --region " + region + " --image-id " + imageID + " --count " + str(count) + " --instance-type " + instType + " --security-group-ids " + secGroup)
subprocess.run(["aws","ec2","run-instances","--region",region,"--image-id",imageID,"--count",str(count),"--instance-type",instType,"--security-group-ids",secGroup], stdout=f)
f.close()
f = open(iFile,'r')
instances = json.load(f)
allInstances.append((region,instances))
f.close()
# we erase the content of the file
open(addresses,'w').close()
# List of quadruples generated when lauching AWS EC2 instances:
# id/private ip/public ip/public dns
instanceRepIds = []
instanceClIds = []
n = 0 # total number of instances
r = 0 # number of replicas
c = 0 # number of clients
for (region,instances) in allInstances:
for inst in instances["Instances"]:
id = inst["InstanceId"]
(priv,pub,dns) = getPublicDnsName(region,id)
print("public dns name:",dns)
if n < numRepInstances:
instanceRepIds.append((r,id,priv,pub,dns,region))
h = open(addresses,'a')
rport = startRport+r
cport = startCport+r
#h.write("id:"+str(r)+" host:"+str(priv)+" port:"+str(rport)+" port:"+str(cport)+"\n")
h.write("id:"+str(r)+" host:"+str(pub)+" port:"+str(rport)+" port:"+str(cport)+"\n")
h.close()
r += 1
else:
instanceClIds.append((c,id,priv,pub,dns,region))
c += 1
n += 1
if not(n == (numRepInstances + numClInstances)):
raise RuntimeError("incorrect number of instances started", n)
return (instanceRepIds, instanceClIds)
# End of startInstances
def copyToAddr(sshAdr):
s1 = "scp -i " + pem + " -o " + sshOpt1 + " "
s2 = " " + sshAdr+":/home/ubuntu/xhotstuff/"
scp = "until " + s1 + addresses + s2 + "; do sleep 1; done"
subprocess.run(scp, shell=True, check=True)
if copyAll:
subprocess.run("tar cvzf App.tar.gz --exclude='*.o' App", shell=True, check=True)
subprocess.run("tar cvzf Enclave.tar.gz --exclude='*.o' Enclave", shell=True, check=True)
subprocess.run(s1 + "Makefile" + s2 + "", shell=True, check=True)
subprocess.run(s1 + "App.tar.gz" + s2 + "", shell=True, check=True)
subprocess.run(s1 + "Enclave.tar.gz" + s2 + "", shell=True, check=True)
cmd = "\"\"cd xhotstuff && tar xvzf App.tar.gz && tar xvzf Enclave.tar.gz\"\"" # && make clean
p = Popen(["ssh","-i",pem,"-o",sshOpt1,"-ntt",sshAdr,cmd])
p.communicate()
else:
subprocess.run(["scp","-i",pem,"-o",sshOpt1,params,sshAdr+":/home/ubuntu/xhotstuff/App/"])
def copyToInstances(instances):
procs = []
for (n,i,priv,pub,dns,region) in instances:
sshAdr = "ubuntu@" + dns
p = multiprocessing.Process(target=copyToAddr(sshAdr))
p.start()
procs.append(p)
for p in procs:
p.join()
# End of copyToInstances
def makeInstances(instanceIds,protocol):
ncores = 1
if useMultiCores:
ncores = numMakeCores
print(">> making",str(len(instanceIds)),"instance(s) using",str(ncores),"core(s)")
make0 = "make -j "+str(ncores)
make = make0 + " SGX_MODE="+sgxmode if needsSGX(protocol) else make0 + " server client"
# copying
procs = []
for (n,i,priv,pub,dns,region) in instanceIds:
sshAdr = "ubuntu@" + dns
p = Popen(["scp","-i",pem,"-o",sshOpt1,params,sshAdr+":/home/ubuntu/xhotstuff/App/"])
procs.append(("R",n,i,priv,pub,dns,region,p))
print("COPYNIG:",i)
for (tag,n,i,priv,pub,dns,region,p) in procs:
while (p.poll() is None):
time.sleep(1)
print("copy done:",i)
# then making - we reset procs
procs = []
for (n,i,priv,pub,dns,region) in instanceIds:
sshAdr = "ubuntu@" + dns
#subprocess.run(["scp","-i",pem,"-o",sshOpt1,params,sshAdr+":/home/ubuntu/xhotstuff/App/"])
#copyToAddr(sshAdr)
cmd = "\"\"" + srcsgx + " && cd xhotstuff && mkdir -p stats && make clean && " + make + "\"\""
p = Popen(["ssh","-i",pem,"-o",sshOpt1,"-ntt",sshAdr,cmd])
print("MAKING:",i)
print("the commandline is {}".format(p.args))
procs.append(("R",n,i,priv,pub,dns,region,p))
for (tag,n,i,priv,pub,dns,region,p) in procs:
while (p.poll() is None):
time.sleep(1)
print("process done:",i)
print("all instances are made")
# End of makeInstances
def copyClientStats(instanceClIds):
for (n,i,priv,pub,dns,region) in instanceClIds:
sshAdr = "ubuntu@" + dns
subprocess.run(["scp","-i",pem,"-o",sshOpt1,sshAdr+":/home/ubuntu/xhotstuff/stats/*","stats/"])
# End of copyClientStats
def executeInstances(instanceRepIds,instanceClIds,protocol,constFactor,numClTrans,sleepTime,numViews,cutOffBound,numFaults,instance):
print(">> connecting to",str(len(instanceRepIds)),"replica instance(s)")
print(">> connecting to",str(len(instanceClIds)),"client instance(s)")
procsRep = []
procsCl = []
newtimeout = int(math.ceil(timeout+math.log(numFaults,2)))
server = "./sgxserver" if needsSGX(protocol) else "./server"
client = "./sgxclient" if needsSGX(protocol) else "./client"
for (n,i,priv,pub,dns,region) in instanceRepIds:
# we give some time for the nodes to connect gradually
if (n%10 == 5):
time.sleep(2)
sshAdr = "ubuntu@" + dns
srun2 = server + " " + str(n) + " " + str(numFaults) + " " + str(constFactor) + " " + str(numViews) + " " + str(newtimeout) + " " + str(opdist)
srun = "screen -d -m " + srun2
cmd = "\"\"" + srcsgx + " && cd xhotstuff && rm -f stats/* && " + srun2 + "\"\""
p = Popen(["ssh","-i",pem,"-o",sshOpt1,"-ntt",sshAdr,cmd])
print("the commandline is {}".format(p.args))
procsRep.append(("R",n,i,priv,pub,dns,region,p))
print("started", len(procsRep), "replicas")
# we give some time for the replicas to connect before starting the clients
wait = 5 + int(math.ceil(math.log(numFaults,2)))
time.sleep(wait)
for (n,i,priv,pub,dns,region) in instanceClIds:
sshAdr = "ubuntu@" + dns
crun2 = client + " " + str(n) + " " + str(numFaults) + " " + str(constFactor) + " " + str(numClTrans) + " " + str(sleepTime) + " " + str(instance)
crun = "screen -d -m " + crun2
cmd = "\"\"" + srcsgx + " && cd xhotstuff && rm -f stats/* && " + crun2 + "\"\""
p = Popen(["ssh","-i",pem,"-o",sshOpt1,"-ntt",sshAdr,cmd])
print("the commandline is {}".format(p.args))
procsCl.append(("C",n,i,priv,pub,dns,region,p))
print("started", len(procsCl), "clients")
totalTime = 0
if expmode == "TVL":
while totalTime < cutOffBound:
copyClientStats(instanceClIds)
files = glob.glob(statsdir+"/client-throughput-latency-"+str(instance)+"*")
time.sleep(1)
totalTime += 1
if 0 < len(files):
print("found clients stats", files)
for (tag,n,i,priv,pub,dns,region,p) in procsRep + procsCl:
p.kill()
break
else:
n = 0
# we stop processes using Python instead of inside the C++ code
remaining = procsRep.copy()
while 0 < len(remaining) and totalTime < cutOffBound:
print("remaining processes at time (", totalTime, "):", remaining)
rem = remaining.copy()
for (tag,n,i,priv,pub,dns,region,p) in rem:
cmdF = "find xhotstuff/" + statsdir + " -name done-" + str(n) + "* | wc -l"
addr = "ubuntu@" + dns
outF = int(subprocess.run("ssh -i " + pem + " -o " + sshOpt1 + " -ntt " + addr + " " + cmdF, shell=True, capture_output=True, text=True).stdout)
#print("attempting to retrieve 'done' file for" , str(n), ":", outF)
if 0 < int(outF):
print("process done:" , str(n))
remaining.remove((tag,n,i,priv,pub,dns,region,p))
n += 1
if (p.poll() is None):
p.kill()
#time.sleep(1)
totalTime += len(rem)
# for (tag,n,i,priv,pub,dns,region,p) in procsRep + procsCl:
# # We stop the execution if it takes too long (cutOffBound)
# while (p.poll() is None) and totalTime < cutOffBound:
# time.sleep(1)
# totalTime += 1
# n += 1
# print("processes stopped:", n, "/", len(procsRep + procsCl), "-", p.args)
global completeRuns
global abortedRuns
global aborted
if totalTime < cutOffBound:
completeRuns += 1
print("all", len(procsRep)+len(procsCl), "all processes are done")
else:
abortedRuns += 1
conf = (protocol,numFaults,instance)
aborted.append(conf)
f = open(abortedFile, 'a')
f.write(str(conf)+"\n")
f.close()
print("------ reached cutoff bound ------")
## cleanup
for (tag,n,i,priv,pub,dns,region,p) in procsRep + procsCl:
# we print the nodes that haven't finished yet
if (p.poll() is None):
print("killing process still running:",(tag,n,i,priv,pub,dns,region,p.poll()))
p.kill()
# End of executeInstances
def terminateInstance(region,i):
while True:
try:
subprocess.run(["aws","ec2","terminate-instances","--region",region,"--instance-ids",i], check=True)
print("terminated:", i)
return True
except CalledProcessError:
print("oops, cannot terminate yet:", i)
sleep(1)
# End of terminateInstance
def terminateInstances(instanceIds):
print(">> terminating",str(len(instanceIds)),"instance(s)")
for (n,i,priv,pub,dns,region) in instanceIds:
terminateInstance(region,i)
# End of terminateInstances
def terminateAllInstancesRegs(regions):
for (region,imageID,secGroup) in regions:
f = open(instFile,'w')
subprocess.run(["aws","ec2","describe-instances","--region",region,"--filters","Name=image-id,Values="+imageID], stdout=f)
f.close()
f = open(instFile,'r')
instances = json.load(f)
#print(instances)
f.close()
l = instances["Reservations"]
print("terminating" , str(len(l)), "reservations")
tot = 0
for res in l:
r = res["Instances"]
print("terminating" , str(len(r)), "instances")
for inst in r:
tot += 1
i = inst["InstanceId"]
print(i)
terminateInstance(region,i)
print("terminated" , str(tot), "instances")
# End of terminateAllInstancesRegs
def terminateAllInstances():
terminateAllInstancesRegs(regions[1])
# End of terminateAllInstances
def terminateAllInstancesAllRegs():
terminateAllInstancesRegs(ALLregions)
# End of terminateAllInstancesAllRegs
def testAWS():
global numMakeCores
numMakeCores = 1
numRepInstances = 1
numClInstances = 0
protocol = Protocol.CHEAP
constFactor = 2
numFaults = 1
instance = 0
(instanceRepIds, instanceClIds) = startInstances(numRepInstances,numClInstances)
makeInstances(instanceRepIds+instanceClIds,protocol)
executeInstances(instanceRepIds,instanceClIds,protocol,constFactor,numClTrans,sleepTime,numViews,cutOffBound,numFaults,instance)
terminateInstances(instanceRepIds + instanceClIds)
# End of testAWS
def executeAWS(instanceRepIds,instanceClIds,protocol,constFactor,numClTrans,sleepTime,numViews,cutOffBound,numFaults,numDeadNodes):
print("<<<<<<<<<<<<<<<<<<<<",
"protocol="+protocol.value,
";regions="+regions[0],
";payload="+str(payloadSize),
"(factor="+str(constFactor)+")",
"#faults="+str(numFaults),
"[complete-runs="+str(completeRuns),"aborted-runs="+str(abortedRuns)+"]")
print("aborted runs so far:", aborted)
numReps = (constFactor * numFaults) + 1
print("initial number of nodes:", numReps)
if deadNodes:
numReps = numReps - numFaults
print("number of nodes to actually run:", numReps)
instanceRepIds = instanceRepIds[0:numReps]
mkParams(protocol,constFactor,numFaults,numTrans,payloadSize)
#time.sleep(5)
makeInstances(instanceRepIds+instanceClIds,protocol)
for instance in range(repeats):
#inst = instance * instance2
#reps = repeats * repeatsL2
clearStatsDir()
# execute the experiment
executeInstances(instanceRepIds,instanceClIds,protocol,constFactor,numClTrans,sleepTime,numViews,cutOffBound,numFaults,instance)
procs = []
# copy the stats over
for (n,i,priv,pub,dns,region) in instanceRepIds:
sshAdr = "ubuntu@" + dns
p = Popen(["scp","-i",pem,"-o",sshOpt1,sshAdr+":/home/ubuntu/xhotstuff/stats/*","stats/"])
procs.append((n,i,priv,pub,dns,region,p))
for (n,i,priv,pub,dns,region,p) in procs:
while (p.poll() is None):
time.sleep(1)
print("stats done:",i)
(throughputView,latencyView,handle,cryptoSign,cryptoVerif,cryptoNumSign,cryptoNumVerif) = computeStats(protocol,numFaults,numDeadNodes,instance,repeats)
# End of executeAWS
def runAWS():
global numMakeCores
numMakeCores = 1
# Creating stats directory
Path(statsdir).mkdir(parents=True, exist_ok=True)
# terminating all instances
terminateAllInstances()
printNodePointParams()
for numFaults in faults:
for instance2 in range(repeatsL2):
# starts the instances
maxNumReps = (3 * numFaults) + 1
(instanceRepIds, instanceClIds) = startInstances(maxNumReps,numClients)
copyToInstances(instanceRepIds + instanceClIds)
numDeadNodes = numFaults
# ------
# HotStuff-like baseline
if runBase:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.BASE,constFactor=3,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# Cheap-HotStuff (TEE locked/prepared blocks)
if runCheap:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.CHEAP,constFactor=2,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# Quick-HotStuff (Accumulator)
if runQuick:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.QUICK,constFactor=3,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# Quick-HotStuff (Accumulator) - debug version
if runQuickDbg:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.QUICKDBG,constFactor=3,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# Combines Cheap&Quick-HotStuff
if runComb:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.COMB,constFactor=2,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# Free
if runFree:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.FREE,constFactor=2,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# Onep
if runOnep:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.ONEP,constFactor=2,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# OnepB
if runOnepB:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.ONEPB,constFactor=2,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# OnepC
if runOnepC:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.ONEPC,constFactor=2,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# OnepD
if runOnepD:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.ONEPD,constFactor=2,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# Chained HotStuff-like baseline
if runChBase:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.CHBASE,constFactor=3,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# Chained Cheap&Quick
if runChComb:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.CHCOMB,constFactor=2,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# Chained Cheap&Quick - debug version
if runChCombDbg:
executeAWS(instanceRepIds=instanceRepIds,instanceClIds=instanceClIds,protocol=Protocol.CHCOMBDBG,constFactor=2,numClTrans=numClTrans,sleepTime=sleepTime,numViews=numViews,cutOffBound=cutOffBound,numFaults=numFaults,numDeadNodes=numDeadNodes)
# ------
# We now terminate all instances just in case
#terminateAllInstances()
# terminates the instances
terminateInstances(instanceRepIds + instanceClIds)
print("num complete runs=", completeRuns)
print("num aborted runs=", abortedRuns)
print("aborted runs:", aborted)
createPlot(pointsFile)
# End of runAWS
# nodes contains the nodes' information
def startRemoteContainers(nodes,numReps,numClients):
print("running in docker mode, starting" , numReps, "containers for the replicas and", numClients, "for the clients")
global ipsOfNodes
lr = list(map(lambda x: (True, x, str(x)), list(range(numReps)))) # replicas
lc = list(map(lambda x: (False, x, "c" + str(x)), list(range(numClients)))) # clients
lall = lr + lc
instanceRepIds = []
instanceClIds = []
for (isRep, n, i) in lall:
#
# we cycle through the nodes
node = nodes[0]
nodes = nodes[1:]
nodes.append(node)
#
# We stop and remove the Doker instance if it is still exists
instance = dockerBase + i
stop_cmd = docker + " stop " + instance
rm_cmd = docker + " rm " + instance
sshAdr = node["user"] + "@" + node["host"]
s1 = Popen(["ssh","-i",node["key"],"-o",sshOpt1,"-ntt",sshAdr,stop_cmd + "; " + rm_cmd])
print("the commandline is {}".format(s1.args))
s1.communicate()
#
# We start the Docker instance
# TODO: make sure to cover all the ports
opt1 = "--expose=8000-9999"
opt2 = "--network=" + clusterNet
opt3 = "--cap-add=NET_ADMIN"
opt4 = "--name " + instance
opts = " ".join([opt1, opt2, opt3, opt4])
run_cmd = docker + " run -td " + opts + " " + dockerBase
s2 = Popen(["ssh","-i",node["key"],"-o",sshOpt1,"-ntt",sshAdr,run_cmd])
print("the commandline is {}".format(s2.args))
s2.communicate()
#
exec_cmd = docker + " exec -t " + instance + " bash -c \"" + srcsgx + "; mkdir " + statsdir + "\""
s3 = Popen(["ssh","-i",node["key"],"-o",sshOpt1,"-ntt",sshAdr,exec_cmd])
print("the commandline is {}".format(s3.args))
s3.communicate()
#
# Set the network latency
if 0 < networkLat:
print("----changing network latency to " + str(networkLat) + "ms")
correlation=100
dist="normal" #"uniform"
tc_cmd = "tc qdisc add dev eth0 root netem delay " + str(networkLat) + "ms " + str(networkVar) + "ms " + str(correlation) +"% distribution " + dist
lat_cmd = docker + " exec -t " + instance + " bash -c \"" + tc_cmd + "\""
s4 = Popen(["ssh","-i",node["key"],"-o",sshOpt1,"-ntt",sshAdr,lat_cmd])
print("the commandline is {}".format(s4.args))
s4.communicate()
#
# Extract the IP address of the container
address = instance + "_addr"
ip_cmd = "cd " + node["dir"] + "; " + docker + " inspect " + instance + " | jq '.[].NetworkSettings.Networks." + clusterNet + ".IPAddress' > " + address
s5 = Popen(["ssh","-i",node["key"],"-o",sshOpt1,"-ntt",sshAdr,ip_cmd])
print("the commandline is {}".format(s5.args))
s5.communicate()
#
s6 = Popen(["scp","-i",node["key"],"-o",sshOpt1,sshAdr+":"+node["dir"]+"/"+address,address])
print("the commandline is {}".format(s6.args))
s6.communicate()
#
rm_cmd = "cd " + node["dir"] + "; rm " + address
s7 = Popen(["ssh","-i",node["key"],"-o",sshOpt1,"-ntt",sshAdr,rm_cmd])
print("the commandline is {}".format(s7.args))
s7.communicate()
#
with open(address, 'r') as f:
data = f.read()
#print(data)
srch = re.search('\"(.+?)\"', data)
if srch:
out = srch.group(1)
print("----container's address:" + out)
if isRep:
ipsOfNodes.update({n:out})
instanceRepIds.append((n,i,node))
else:
instanceClIds.append((n,i,node))
else:
print("----container's address: UNKNOWN")
subprocess.run(["rm " + address], shell=True, check=True)
genLocalConf(numReps,addresses)
for (n,i,node) in instanceRepIds + instanceClIds:
#
dockerInstance = dockerBase + i
sshAdr = node["user"] + "@" + node["host"]
#
s1 = Popen(["scp","-i",node["key"],"-o",sshOpt1,addresses,sshAdr+":"+node["dir"]+"/"+addresses])
print("the commandline is {}".format(s1.args))
s1.communicate()
#
cp_cmd = docker + " cp " + node["dir"]+"/"+addresses + " " + dockerInstance + ":/app/"
s2 = Popen(["ssh","-i",node["key"],"-o",sshOpt1,"-ntt",sshAdr,cp_cmd])