-
Notifications
You must be signed in to change notification settings - Fork 1
/
scenario_main.py
executable file
·52 lines (47 loc) · 1.76 KB
/
scenario_main.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
#!/usr/bin/env python
# Mini-Simulator based on ns-2 mobility traces
#
# Author: Mateus Sousa (mateus-n00b)
# Date: 12/04/2018 - Salvador, Brazil
#
# TODO: Develop a lot of things
# - simulate the mobility
# - create/Destroy edges according to the distance among the nodes
# - use the networkx to models the network
# - create main function
#
#
import networkx as nx
import mobility as mob
import metrics
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-t","--trace",dest="trace",type="str",default=None,
help="ns-2 mobility trace file")
parser.add_option("-o","--output",dest="results",type="str",default="statistics.dat",
help="ns-2 mobility trace file",nargs=1)
opt, args = parser.parse_args()
# Global vars
MAX_TRANGE = 300.0 # maximum transmission range
try:
STATISTICS_FILE = open(opt.results,"w")
print "The output will be saved at => {}".format(STATISTICS_FILE.name)
except Exception as error:
print error
exit(-1)
# mob_files = ['/tmp/mobility25','/tmp/mobility50','/tmp/mobility75','/tmp/mobility100',
# '/tmp/highway25','/tmp/highway50','/tmp/highway75','/tmp/highway100']
if opt.trace:
# for f in mob_files:
nodelist,sim_time = mob.build_topo(trace=opt.trace)
print "simulation time = {0}".format(sim_time)
# print nodelist['1'].get_velocityAt('149.00') #
# print nodelist['0'].get_positionAt('0.00') #
# n_nodes = len(nodelist)
STATISTICS_FILE.write("{0}\nsim_time = {1}\n".format(opt.trace,sim_time))
metrics.average_distance(nodelist=nodelist,output_file=STATISTICS_FILE,
MAX_TRANGE=MAX_TRANGE,sim_time=sim_time)
STATISTICS_FILE.close() # Close statistics file
else:
print "[-] Invalid entry! Try -h|--help for help."
exit(-1)