Repository navigation
Expand file tree
/
Copy pathTimer.py
More file actions
96 lines (45 loc) · 2.65 KB
/
Copy pathTimer.py
File metadata and controls
96 lines (45 loc) · 2.65 KB
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
import datetime
import random
""" EITHER MAKE A THREAD FOR ROUTING & TRIGGERED UPDATE OR MAKE FOR LOOP """
"""Maintains router and RTE timers"""
class Timer:
"""All it needs to do is tell caller that it can now send a unsolicited message"""
def unsolisotedMessageTimer(self):
next_routing_update_time = self.setNextRoutingUpdateTime() # Initialize var
while (1):
now = datetime.datetime.now() # Current time
if (now >= next_routing_update_time): # If current time >= the next unsolicited message time
return True
"""All it needs to do is tell caller that it can now send a unsolicited message"""
def triggeredMessageTimer(self):
next_triggerd_update = self.setNextTriggeredUpdateTime() # Initialize var
while (1):
now = datetime.datetime.now() # Current time
if (now >= next_triggerd_update): # If current time >= the next available time for a triggerd update
return True
"""
Helper methods
"""
"""Set 'next_routing_update_time' to when the next router update can be generated"""
def setNextRoutingUpdateTime(self):
min_margin = 0
max_margin = 5
offset_time = self.getOffsetTime(min_margin, max_margin)
#self.next_routing_update_time = getDeltaDateTime(30 + offset_time)
return datetime.datetime.now() + self.getDeltaDateTime(30 + offset_time)
"""Set 'next_triggerd_update' to when the next triggered update can be generated"""
def setNextTriggeredUpdateTime(self):
min_margin = 1
max_margin = 5
offset_time = self.getOffsetTime(min_margin, max_margin)
#self.next_routing_update_time = getDeltaDateTime(offset_time)
return datetime.datetime.now() + self.getDeltaDateTime(offset_time)
"""Return a random time inteval from min_margin to max_margin in seconds"""
def getOffsetTime(self, min_margin, max_margin):
return random.randint(min_margin, max_margin)
"""Return 'timeDelta' in 'datetime' syntax"""
def getDeltaDateTime(self, timeDelta):
return datetime.timedelta(seconds = timeDelta)
#t = Timer()
#print(t.triggeredMessageTimer())
#print(t.unsolisotedMessageTimer())