forked from ARL-UTEP-OC/cdes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_swapper.py
49 lines (42 loc) · 1.54 KB
/
test_swapper.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
import multiprocessing
import logging
import subprocess
import shlex
import threading
import time
import sys
import os
from COREIfx.session_reader import SessionReader
from COREIfx import msg_ifx
from Swapper.swapper import Swapper
__author__ = "Jaime C. Acosta"
__license__ = "GPL 3.0"
def short_session_id(session_number):
logging.debug("Controller(): short_session_id(): Instantiated")
snum = int(session_number)
ans = (snum >> 8) ^ (snum & ((1 << 8) - 1))
return ("%x" % ans)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
logging.debug("Swapper(): instantiated")
#Assuming we're using CC_NodeTest.imn
cc_dec_node = "13"
if len(sys.argv) < 2:
logging.error("Usage: python test_swapper.py <session-number>")
exit()
#conditional_conns = {"4": {"cc_gw": "1", "cc_nodes": {"5": False, "2": False} } }
sr = SessionReader(sys.argv[1])
conditional_conns = sr.relevant_session_to_JSON()
omqueue = multiprocessing.Queue()
otqueue = multiprocessing.Queue()
sw = Swapper("swapper", omqueue, otqueue, conditional_conns, sys.argv[1], short_session_id(int(sys.argv[1])), cc_dec_node)
sw = multiprocessing.Process(target=sw.update_connection)
sw.start()
#[cc_dec, cc_gw, active_node_number, disable_others]
# Get output and print to screen
for i in range(60):
omqueue.put([cc_dec_node, "2", "3", True])
time.sleep(10)
omqueue.put([cc_dec_node, "2", "6", True])
time.sleep(10)
logging.debug("Swapper(): Completed")