-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim_all_in_one_energy.py
101 lines (83 loc) · 3.4 KB
/
sim_all_in_one_energy.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
#! /usr/bin/python
#coding=utf-8
import sys
import os, subprocess
import string
import time
#import sim_ndw
import sim_tongji
import sim_tongji_energy
def set_fun(name, val):
head = open("Ndw.h", "r")
head_new = open("Ndw_new.h", "w")
for line in head:
head_set = line.split()
if(len(head_set) > 0 ):
if(head_set[0] == name):
#print head_set
head_set[2] = str(val) + ","
#print head_set
line = '\t' + ' '.join(head_set) + '\n'
#continue
head_new.write(line)
os.rename("Ndw_new.h","Ndw.h")
name = "TIMER_PERIOD_REPO"
val = [5,10,20,50,100,150,200]
cs_name = "CS_STALE_COUNT"
cs_val = [0,1,2,3,4,5]
pit_name = "PIT_STALE_COUNT"
pit_val = [0,1,2,3,4,5]
ISOTIMEFORMAT='%Y-%m-%d %X'
def time_sim():
res_file = open("time_sim_result.txt", "w")
res_file.write('\ntime_sim_result.txt\n'+time.strftime(ISOTIMEFORMAT, time.localtime(time.time()))+'\n\n')
res_file.write("发送间隔(ms) 发送请求数量 收到回应数量 丢包率 接收时延(大致/ms) 消耗能量" + '\n')
print ("发送间隔(ms) 发送请求数量 收到回应数量 丢包率 接收时延(大致/ms) 消耗能量" + '\n')
for i in range(len(val)):
set_fun(name, val[i])
os.system('make micaz sim > /dev/null 2>&1')
res_file.write(str(val[i]) + '\t\t\t\t')
#sim_ndw.sim()
os.system('python sim_ndw.py')
os.system('python sim_ndw_energy.py > /dev/null 2>&1')
print (str(val[i]) + '\t\t\t\t'),
tongji_item = sim_tongji.tongji()
tongji_item_energy = sim_tongji_energy.tongji()
res_file.write(tongji_item +'\t\t\t'+tongji_item_energy +'\n')
def cs_sim():
res_file = open("cs_sim_result.txt", "w")
res_file.write('\ncs_sim_result.txt\n'+time.strftime(ISOTIMEFORMAT, time.localtime(time.time()))+'\n\n')
res_file.write("CS缓存时间(s) 发送请求数量 收到回应数量 丢包率 接收时延(大致/ms) 消耗能量" + '\n')
print ("CS缓存时间(s) 发送请求数量 收到回应数量 丢包率 接收时延(大致/ms) 消耗能量" + '\n')
for i in range(len(cs_val)):
set_fun(cs_name, cs_val[i])
os.system('make micaz sim > /dev/null 2>&1')
res_file.write(str(cs_val[i]) + '\t\t\t\t')
#sim_ndw.sim()
os.system('python sim_ndw.py')
os.system('python sim_ndw_energy.py > /dev/null 2>&1')
print (str(cs_val[i]) + '\t\t\t\t'),
tongji_item = sim_tongji.tongji()
tongji_item_energy = sim_tongji_energy.tongji()
res_file.write(tongji_item +'\t\t\t'+tongji_item_energy +'\n')
def pit_sim():
res_file = open("pit_sim_result.txt", "w")
res_file.write('\npit_sim_result.txt\n'+time.strftime(ISOTIMEFORMAT, time.localtime(time.time()))+'\n\n')
res_file.write("PIT缓存时间(s) 发送请求数量 收到回应数量 丢包率 接收时延(大致/ms) 消耗能量" + '\n')
print ("PIT缓存时间(s) 发送请求数量 收到回应数量 丢包率 接收时延(大致/ms) 消耗能量" + '\n')
for i in range(len(pit_val)):
set_fun(pit_name, pit_val[i])
os.system('make micaz sim > /dev/null 2>&1')
os.system('python sim_ndw_energy.py > /dev/null 2>&1')
res_file.write(str(pit_val[i]) + '\t\t\t\t')
#sim_ndw.sim()
os.system('python sim_ndw.py')
print (str(pit_val[i]) + '\t\t\t\t'),
tongji_item = sim_tongji.tongji()
tongji_item_energy = sim_tongji_energy.tongji()
res_file.write(tongji_item +'\t\t\t'+tongji_item_energy +'\n')
if __name__ == '__main__':
time_sim()
cs_sim()
pit_sim()
print "----------ALL END--------------"