#!/usr/bin/python3
import math
import sys
###############################################################################
# CONFIGS TO SET:
CONFIG_FILE = "Enclave/Enclave.config.xml"
###############################################################################
'''
Generate a manifest file with:
N: number of clients
M: number of servers
T: number of threads for each server
B: msg_size
'''
def generate_config(N, M, T, B):
cf = open(CONFIG_FILE, 'w+')
clients_per_server = math.ceil(N/M)
# Base heap of 2 MB per thread
heap_size = 2000000 * T
# Note: This assumes priv_out = 1 , i.e. only 1 token per client in an epoch
# Storage and Ingestion data stored per_client = 52 bytes
heap_size += clients_per_server * (B + 60)
# 4 Buffers of clients_per_server items of B size each
heap_size += (clients_per_server * B * 5)
# 3 x WN
heap_size += (5 * T * (clients_per_server * math.ceil(math.log(clients_per_server,2)) * 8))
# 60 MB
#heap_size += 60000000
heap_size_page_aligned = math.ceil(heap_size/4096) * 4096
hex_heap_size = hex(heap_size_page_aligned)
enclave_config = '''
0
0
0x40000
{H}
32
1
0
0
0xFFFFFFFF
'''.format(H = str(hex_heap_size))
#print (enclave_config)
cf.write(enclave_config)
cf.close()
if __name__ == "__main__":
if(len(sys.argv)!=5):
print("Incorrect usage!\n")
print("./gen_enclave_config.py expects 4 parameters.")
print("Usage: ./gen_enclave_config.py ")
exit()
n = int(sys.argv[1])
m = int(sys.argv[2])
t = int(sys.argv[3])
b = int(sys.argv[4])
generate_config(n, m, t, b)