-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathloraMesh.py
106 lines (91 loc) · 3.58 KB
/
loraMesh.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
#!/usr/bin/env python3
import sys
from lib.common import *
from lib.discrete_event import *
from lib.mac import *
from lib.packet import *
from lib.node import *
from lib.config import Config
VERBOSE = True
random.seed(conf.SEED)
conf = Config()
if VERBOSE:
def verboseprint(*args, **kwargs):
print(*args, **kwargs)
else:
def verboseprint(*args, **kwargs):
pass
nodeConfig = getParams(conf, sys.argv)
conf.updateRouterDependencies()
env = simpy.Environment()
bc_pipe = BroadcastPipe(env)
# simulation variables
nodes = []
messages = []
packets = []
delays = []
packetsAtN = [[] for _ in range(conf.NR_NODES)]
messageSeq = {"val": 0}
totalPairs = 0
symmetricLinks = 0
asymmetricLinks = 0
noLinks = 0
graph = Graph(conf)
for i in range(conf.NR_NODES):
node = MeshNode(conf, nodes, env, bc_pipe, i, conf.PERIOD, messages, packetsAtN, packets, delays, nodeConfig[i], messageSeq, verboseprint)
nodes.append(node)
graph.addNode(node)
totalPairs, symmetricLinks, asymmetricLinks, noLinks = setupAsymmetricLinks(conf, nodes)
if conf.MOVEMENT_ENABLED:
env.process(runGraphUpdates(env, graph, nodes, conf.ONE_MIN_INTERVAL))
conf.updateRouterDependencies()
# start simulation
print("\n====== START OF SIMULATION ======")
env.run(until=conf.SIMTIME)
# compute statistics
print("\n====== END OF SIMULATION ======")
print("*******************************")
print(f"\nRouter Type: {conf.SELECTED_ROUTER_TYPE}")
print('Number of messages created:', messageSeq["val"])
sent = len(packets)
if conf.DMs:
potentialReceivers = sent
else:
potentialReceivers = sent*(conf.NR_NODES-1)
print('Number of packets sent:', sent, 'to', potentialReceivers, 'potential receivers')
nrCollisions = sum([1 for p in packets for n in nodes if p.collidedAtN[n.nodeid] == True])
print("Number of collisions:", nrCollisions)
nrSensed = sum([1 for p in packets for n in nodes if p.sensedByN[n.nodeid] == True])
print("Number of packets sensed:", nrSensed)
nrReceived = sum([1 for p in packets for n in nodes if p.receivedAtN[n.nodeid] == True])
print("Number of packets received:", nrReceived)
meanDelay = np.nanmean(delays)
print('Delay average (ms):', round(meanDelay, 2))
txAirUtilization = sum([n.txAirUtilization for n in nodes])/conf.NR_NODES/conf.SIMTIME*100
print('Average Tx air utilization:', round(txAirUtilization, 2), '%')
if nrSensed != 0:
collisionRate = float((nrCollisions)/nrSensed)
print("Percentage of packets that collided:", round(collisionRate*100, 2))
else:
print("No packets sensed.")
nodeReach = sum([n.usefulPackets for n in nodes])/(messageSeq["val"]*(conf.NR_NODES-1))
print("Average percentage of nodes reached:", round(nodeReach*100, 2))
if nrReceived != 0:
usefulness = sum([n.usefulPackets for n in nodes])/nrReceived # nr of packets that delivered to a packet to a new receiver out of all packets sent
print("Percentage of received packets containing new message:", round(usefulness*100, 2))
else:
print('No packets received.')
delayDropped = sum(n.droppedByDelay for n in nodes)
print("Number of packets dropped by delay/hop limit:", delayDropped)
if conf.MODEL_ASYMMETRIC_LINKS == True:
print("Asymmetric links:", round(asymmetricLinks / totalPairs * 100, 2), '%')
print("Symmetric links:", round(symmetricLinks / totalPairs * 100, 2), '%')
print("No links:", round(noLinks / totalPairs * 100, 2), '%')
if conf.MOVEMENT_ENABLED == True:
movingNodes = sum([1 for n in nodes if n.isMoving == True])
print("Number of moving nodes:", movingNodes)
gpsEnabled = sum([1 for n in nodes if n.gpsEnabled == True])
print("Number of moving nodes w/ GPS:", gpsEnabled)
graph.save()
if conf.PLOT:
plotSchedule(conf, packets, messages)