-
Notifications
You must be signed in to change notification settings - Fork 1
/
sim.py
42 lines (29 loc) · 768 Bytes
/
sim.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
from TOSSIM import *
import sys
nrNodes = 10
t = Tossim([]);
r = t.radio();
f = open("topo.txt","r")
lines = f.readline()
for line in lines
s = line.split()
if(len(s) > 0)
if s[0] == "gain":
r.add(int(s[1]),int(s[2]),float(s[3]))
t.addChannel("Console",sys.stdout);
noise = open("meyer-heavy.txt", "r")
for line in noise:
str1 = line.strip()
if str1:
val = int(str1)
for i in range(1, nrNodes):
t.getNode(i).addNoiseTraceReading(val)
for i in range(1, nrNodes):
print "Creating noise model for ",i;
t.getNode(i).createNoiseModel()
for i in range(1, nrNodes):
time = randint(t.ticksPerSecond(),10*t.ticksPerSecond())
t.getNode(i).bootAtTime(time);
for i in range (2000):
t.runNextEvent();
print 'simulation completed'