-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsimulate.py
executable file
·126 lines (98 loc) · 4.16 KB
/
simulate.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
#!/usr/bin/python
# Copyright (C) 2016 Karl Janson, Siavoosh Payandeh Azad, Behrad Niazmand
import os
import sys
import shutil
from math import ceil
import logging
import time
from Scripts.include.Logger import *
from Scripts.include.helper_func import *
from Scripts.include.file_lists import *
from Scripts.include.Help_note import print_help
from Scripts.include.write_do_file import write_do_file
from Scripts.include import package
from Scripts.include.arg_parser import arg_parser, report_parogram_arguments
from Scripts.include.stats import statistics
try:
from Scripts.include.viz_traffic import viz_traffic
Viz = True
except:
print_msg(MSG_INFO, "Can not include the visualizer! Some library is missing. Turning off the visualization!")
Viz = False
from Scripts.include.file_gen import gen_network_and_tb, gen_wave_do
"""
Main program
"""
def main(argv):
print "Project Root:", package.PROJECT_ROOT
# Check if the temporary folder exists. If it does, clear it, if not, create it.
if os.path.exists(package.SIMUL_DIR):
try:
shutil.rmtree(package.SIMUL_DIR)
except OSError as e:
print_msg(MSG_ERROR, "Error " + str(e[0]) + ": " + e[1])
sys.exit(1)
try:
os.makedirs(package.SIMUL_DIR)
os.makedirs(package.LOG_DIR)
os.makedirs(package.TRACE_DIR)
except OSError as e:
print_msg(MSG_ERROR, "Error " + str(e[0]) + ": " + e[1])
sys.exit(1)
# Just for getting a copy of the current console
sys.stdout = Logger()
# setup Logging
logging.basicConfig(filename=LOG_DIR+'/Logging_Log_'+str(time.time())+'.log', level=logging.DEBUG)
logging.info('Starting logging...')
# Parse the arguments given to the system
try:
package.program_argv = arg_parser(argv, package.program_argv, logging)
except ValueError as e:
print_msg(MSG_ERROR, str(e))
sys.exit(1)
DEBUG = package.program_argv['debug']
report_parogram_arguments(package.program_argv, DEBUG)
if package.program_argv['credit_based_FC']:
flow_control_type = package.CREDIT_BASED_SUFFIX
net_file_name, net_tb_file_name = gen_network_and_tb(package.program_argv, flow_control_type)
# Generate wave.do
wave_do_file_name = gen_wave_do(package.program_argv, flow_control_type)
# Generate simulate.do
if DEBUG: print_msg(MSG_DEBUG, "Generating simulation.do")
try:
write_do_file(package.program_argv, net_file_name, net_tb_file_name, wave_do_file_name, logging)
except IOError as e:
print_msg(MSG_ERROR, "Generate simulate.do file: Error " + str(e[0]) + ": " + e[1])
sys.exit(1)
# Running modelsim
if DEBUG: print_msg(MSG_DEBUG, "Running Modelsim...")
os.chdir(package.SIMUL_DIR)
if package.program_argv['command-line'] or package.program_argv['lat']:
novopt = '-novopt ' if package.program_argv['verilog'] else ''
return_value = os.system("vsim -c " + novopt + "-do " + package.SIMUL_DO_SCRIPT)
else:
return_value = os.system("vsim -do " + package.SIMUL_DO_SCRIPT)
if return_value != 0:
logging.error("Error while running Modelsim")
print_msg(MSG_ERROR, "Error while running Modelsim")
sys.exit(1)
# Latency calculation
logging.info('starting latency calculation...')
if package.program_argv['lat']:
# Read sent packets
statistics(True)
# Run latency calculation script
latency_command = "python " + package.SCRIPTS_DIR + "/include/" + package.LATENCY_CALCULATION_PATH + " -S " + package.SIMUL_DIR+"/"+package.SENT_TXT_PATH + " -R " + package.SIMUL_DIR+"/"+package.RECEIVED_TXT_PATH
if DEBUG: print_msg(MSG_DEBUG, "Running latency calculator script:\n\t" + latency_command)
return_value = os.system(latency_command)
if return_value != 0:
print_msg(MSG_ERROR, "Error while running latency calculation script")
sys.exit(1)
else:
statistics(False)
if package.program_argv["trace"] and Viz == True:
viz_traffic(package.program_argv["network_dime"])
logging.info('Logging finished...')
if __name__ == "__main__":
main(sys.argv)