Exemple #1
0
###Copy cdes source to the current session's folder
    try:
        shutil.copytree(cdes_dir, cdes_scen_dir)
    # Directories are the same
    except shutil.Error as e:
        logging.error(
            "CDES_Loader(): Main(): Directory not copied. Error: %s" % e)
        exit()
    # Any error saying that the directory doesn't exist
    except OSError as e:
        logging.error(
            "CDES_Loader(): Main(): Directory not copied. Error: %s" % e)
        exit()

###Get node states
    sr = SessionReader(session_number)
    # First check to make sure the session is in a running state
    state = sr.get_session_state()
    if state == None:
        logging.error(
            "CDES_Loader(): Main(): Session " + str(session_number) +
            " does not exist, make sure core-daemon is running. \n You can start it by running /etc/init.d/core-daemon start"
        )
        exit()
    while "4 RUNTIME_STATE" not in state:
        logging.warning(
            "CDES_Loader(): Main(): Session " + str(session_number) +
            " Is not yet in the running state... waiting and then trying again"
        )
        if state == None:
            logging.error(
Exemple #2
0
from COREIfx.session_reader import SessionReader
from Trigger.trigger import Trigger
from Trigger.timer_trigger import TimerTrigger

__author__ = "Jaime C. Acosta"
__license__ = "GPL 3.0"

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    logging.debug("Trigger(): Main(): instantiated")
    
    if len(sys.argv) < 3:
        logging.error("Usage: python test_trigger.py <session-number> <cc-decision-node-number>")
        exit()       

    sr = SessionReader(sys.argv[1])
    cc_dec_node = sys.argv[2]
    conditional_conns = sr.relevant_session_to_JSON()
    omqueue = multiprocessing.Queue()
    otqueue = multiprocessing.Queue()

    tp = TimerTrigger("trigger", omqueue, otqueue, conditional_conns, cc_dec_node)
    tp = multiprocessing.Process(target=tp.process_data)
    tp.start()

    numItems = 1000
    for i in range(1,numItems):
        omqueue.put(str(i) + "\n")
        time.sleep(1)

    # Get output and print to screen
Exemple #3
0
    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()

    sr = SessionReader(sys.argv[1])
    conditional_conns = sr.relevant_session_to_JSON()
    print("CONDITIONAL CONNS: " + str(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_dec_nic, disable_others]
    # Get output and print to screen
    for i in range(60):
        omqueue.put([cc_dec_node, "eth0", True])
        omqueue.put([cc_dec_node, "eth1", False])
        time.sleep(10)
Exemple #4
0
    def cdes_run(self,
                 session_number=None,
                 monitor_cmd=None,
                 conditional_conns=None):
        logging.debug("Controller(): cdes_run(): Instantiated")
        if monitor_cmd == None:
            logging.error(
                "Controller(): cdes_run(): No monitor command was passed in, quitting"
            )
            exit()

        cmd = os.path.abspath(monitor_cmd)
        if session_number == None:
            logging.error(
                "Controller(): cdes_run(): No session number was passed in, quitting"
            )
            exit()
        sr = SessionReader(session_number)

        if conditional_conns == None:
            conditional_conns = sr.relevant_session_to_JSON()

        imonitor_queues = []
        omonitor_queues = []
        otrigger_queues = []
        oswapper_queues = []

        monitor_processes = []
        trigger_processes = []
        swapper_processes = []

        for cc_dec_node in conditional_conns.keys():
            logging.debug("Controller(): cdes_run(): In loop")
            # For knowning when to quit
            imonitor_queue = multiprocessing.Queue()
            omonitor_queue = multiprocessing.Queue()
            otrigger_queue = multiprocessing.Queue()
            oswapper_queue = multiprocessing.Queue()

            imonitor_queues.append(imonitor_queue)
            omonitor_queues.append(omonitor_queue)
            otrigger_queues.append(otrigger_queue)
            oswapper_queues.append(oswapper_queue)

            m = Monitor("monitor", imonitor_queue, omonitor_queue, cmd)
            mp = multiprocessing.Process(target=m.run_monitor)
            mp.start()
            monitor_processes.append(mp)

            #If the user defined a custom Trigger, load it now
            #get cc_dec name
            cc_dec_name = conditional_conns[cc_dec_node]["name"]
            filepath = os.path.realpath(__file__)
            file_dir = os.path.dirname(filepath)
            custom_file_path = os.path.join(file_dir, "Trigger", cc_dec_name,
                                            "MyTrigger.py")
            if os.path.exists(custom_file_path):
                DynLoadedClass = imp.load_source('MyTrigger', custom_file_path)
                tp = DynLoadedClass.MyTrigger("trigger", omonitor_queue,
                                              otrigger_queue,
                                              conditional_conns, cc_dec_node)
            else:
                tp = TimerTrigger("trigger", omonitor_queue, otrigger_queue,
                                  conditional_conns, cc_dec_node)
            tpm = multiprocessing.Process(target=tp.process_data)
            tpm.start()
            trigger_processes.append(tpm)

            short_session_number = self.short_session_id(session_number)
            sw = Swapper("swapper", otrigger_queue, oswapper_queue,
                         conditional_conns, session_number,
                         short_session_number, cc_dec_node)
            swp = multiprocessing.Process(target=sw.update_connection)
            swp.start()
            swapper_processes.append(swp)

        # Keep looping until the scenario is no longer in a Run state
        state = sr.get_session_state()
        if state == None:
            logging.error("Controller(): cdes_run(): Session " +
                          str(session_number) + " no longer exists, exitting")
            exit()
        while "4 RUNTIME_STATE" in state:
            logging.debug("Controller(): cdes_run(): Session " +
                          str(session_number) +
                          " session Still running, continuing operations")
            if state == None:
                logging.error("Controller(): cdes_run(): Session " +
                              str(session_number) +
                              " no longer exists, exitting")
                break
            time.sleep(5)
            state = sr.get_session_state()

        # Logic to terminate all processes goes here
        for cc in range(0, len(monitor_processes)):
            logging.debug(
                "Controller(): cdes_run(): Cleaning up and exiting " +
                str(session_number))
            imonitor_queues[cc].put("exit")
            logging.debug(
                "Controller(): cdes_run(): Waiting for Monitor process to fininsh to gracefully exit"
            )
            monitor_processes[cc].join()
            logging.debug(
                "Controller(): cdes_run(): Done. Terminating Monitor.")
            monitor_processes[cc].terminate()
            logging.debug(
                "Controller(): cdes_run(): Done. Terminating Trigger.")
            trigger_processes[cc].terminate()
            logging.debug(
                "Controller(): cdes_run(): Done. Terminating Swapper.")
            swapper_processes[cc].terminate()
            logging.debug("Controller(): cdes_run(): Done.")
import xml.etree.ElementTree as ET
import logging
import os
import json
import sys, traceback
from COREIfx import msg_ifx
from COREIfx.imnparser import imnparser
from pyparsing import nestedExpr, originalTextFor
from COREIfx.session_reader import SessionReader

__author__ = "Jaime C. Acosta"
__license__ = "GPL 3.0"

if __name__ == "__main__":

    logging.basicConfig(level=logging.DEBUG)
    logging.debug("SessionReader(): instantiated")
    
    if len(sys.argv) < 2:
        logging.error("Usage: python test_session_reader.py <session-number>")
        exit()       
    
    sr = SessionReader(sys.argv[1])
    logging.debug("Printing All")
    state = sr.get_session_state
    logging.debug("Current session state: " + str(state))
    if state == None:
        logging.debug("Exiting since session data is not available: " + str(state))
        exit()
    logging.debug(json.dumps(sr.relevant_session_to_JSON(), indent=3))