-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrics_main.py
More file actions
72 lines (58 loc) · 1.93 KB
/
metrics_main.py
File metadata and controls
72 lines (58 loc) · 1.93 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
import threading
import time
from IMRManager import IMRManager
from TopoManager import TopoManager
from NetworkProbe import NetworkProbe
from config import POLLING_INTERVAL, TMA_URL
import logging
import signal
import sys
DEBUG = True
logging.basicConfig(level=logging.DEBUG if DEBUG else logging.INFO)
class PollingThread(threading.Thread):
def __init__(self):
self._stopevent = threading.Event()
threading.Thread.__init__(self)
def run(self):
while not self._stopevent.isSet():
reroute_event.set()
time.sleep(POLLING_INTERVAL)
def stop(self):
self._stopevent.set()
class ReroutingThread(threading.Thread):
def __init__(self):
self._stopevent = threading.Event()
threading.Thread.__init__(self)
def run(self):
while not self._stopevent.isSet():
reroute_event.wait()
if self._stopevent.isSet():
return
logging.info("Re-routing Intents...")
reroute_event.clear()
topoManager.retrieve_topo_from_ONOS()
iMRManager.reroute_intents(topoManager)
networkProbe.send_availability_metric(topoManager.get_net_full_topology())
def stop(self):
self._stopevent.set()
reroute_event.set()
def handler_stop_signals(signum, frame):
pollingThread.stop()
reroutingThread.stop()
logging.info('Killing all the threads...')
sys.exit(0)
if __name__ == "__main__":
topoManager = TopoManager()
networkProbe = NetworkProbe(TMA_URL)
iMRManager = IMRManager()
reroute_event = threading.Event()
pollingThread = PollingThread()
reroutingThread = ReroutingThread()
pollingThread.start()
reroutingThread.start()
signal.signal(signal.SIGINT, handler_stop_signals)
logging.info('Press any key to exit')
raw_input('')
logging.info('Killing all the threads...')
pollingThread.stop()
reroutingThread.stop()