Example #1
0
def example(options):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create emane network node
    emane_network = session.create_emane_network(model=EmaneIeee80211abgModel,
                                                 geo_reference=(47.57917,
                                                                -122.13232,
                                                                2.00000))
    emane_network.setposition(x=80, y=50)

    # create nodes
    for i in range(options.nodes):
        node = session.create_wireless_node()
        node.setposition(x=150 * (i + 1), y=150)
        interface = prefixes.create_interface(node)
        session.add_link(node.id, emane_network.id, interface_one=interface)

    # instantiate session
    session.instantiate()

    # start a shell on the first node
    node = session.get_node(2)
    node.client.term("bash")

    # shutdown session
    input("press enter to exit...")
    coreemu.shutdown()
Example #2
0
def example(options):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create emane network node
    emane_network = session.create_emane_network(
        model=EmaneIeee80211abgModel,
        geo_reference=(47.57917, -122.13232, 2.00000)
    )
    emane_network.setposition(x=80, y=50)

    # create nodes
    for i in xrange(options.nodes):
        node = session.create_wireless_node()
        node.setposition(x=150 * (i + 1), y=150)
        interface = prefixes.create_interface(node)
        session.add_link(node.objid, emane_network.objid, interface_one=interface)

    # instantiate session
    session.instantiate()

    # start a shell on the first node
    node = session.get_object(2)
    node.client.term("bash")

    # shutdown session
    raw_input("press enter to exit...")
    coreemu.shutdown()
Example #3
0
def main(args):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu({"distributed_address": args.address})
    session = coreemu.create_session()

    # initialize distributed
    server_name = "core2"
    session.distributed.add_server(server_name, args.server)

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create local node, switch, and remote nodes
    options = NodeOptions()
    node_one = session.add_node(options=options)
    options.server = server_name
    node_two = session.add_node(options=options)

    # create node interfaces and link
    interface_one = prefixes.create_interface(node_one)
    interface_two = prefixes.create_interface(node_two)
    session.add_link(node_one.id, node_two.id, interface_one, interface_two)

    # instantiate session
    session.instantiate()

    # pause script for verification
    input("press enter for shutdown")

    # shutdown session
    coreemu.shutdown()
Example #4
0
def example(args):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create emane network node
    session.set_location(47.57917, -122.13232, 2.00000, 1.0)
    options = NodeOptions()
    options.set_position(80, 50)
    emane_network = session.add_node(_type=NodeTypes.EMANE, options=options)
    session.emane.set_model(emane_network, EmaneIeee80211abgModel)

    # create nodes
    options = NodeOptions(model="mdr")
    for i in range(args.nodes):
        node = session.add_node(options=options)
        node.setposition(x=150 * (i + 1), y=150)
        interface = prefixes.create_interface(node)
        session.add_link(node.id, emane_network.id, interface_one=interface)

    # instantiate session
    session.instantiate()

    # shutdown session
    input("press enter to exit...")
    coreemu.shutdown()
Example #5
0
def example(args):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create switch network node
    switch = session.add_node(_type=NodeTypes.SWITCH)

    # create nodes
    for _ in range(args.nodes):
        node = session.add_node()
        interface = prefixes.create_interface(node)
        session.add_link(node.id, switch.id, interface_one=interface)

    # instantiate session
    session.instantiate()

    # get nodes to run example
    first_node = session.get_node(2)
    last_node = session.get_node(args.nodes + 1)
    first_node_address = prefixes.ip4_address(first_node)
    logging.info("node %s pinging %s", last_node.name, first_node_address)
    output = last_node.cmd(f"ping -c {args.count} {first_node_address}")
    logging.info(output)

    # shutdown session
    coreemu.shutdown()
Example #6
0
def grpc_server():
    coremu = CoreEmu()
    grpc_server = CoreGrpcServer(coremu)
    thread = threading.Thread(target=grpc_server.listen, args=("localhost:50051",))
    thread.daemon = True
    thread.start()
    time.sleep(0.1)
    yield grpc_server
    coremu.shutdown()
    grpc_server.server.stop(None)
Example #7
0
def session():
    # use coreemu and create a session
    coreemu = CoreEmu()
    session_fixture = coreemu.create_session()
    session_fixture.set_state(EventTypes.CONFIGURATION_STATE)
    assert os.path.exists(session_fixture.session_dir)

    # return created session
    yield session_fixture

    # shutdown coreemu
    coreemu.shutdown()
Example #8
0
def example(nodes):
    # ip generator for example
    prefixes = IpPrefixes("192.168.10.0/24")
    node_list = []

    # create emulator instance for creating sessions and utility methods
    coreemu = globals().get("coreemu", CoreEmu())
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create nodes
    node_options = NodeOptions()
    x = 0
    for i in range(nodes):
        node_options.set_position(x, 100)
        x = x+70
        session.add_node(node_options=node_options)
        node_list.append(node)
    # create switch network node
    wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
    session.mobility.set_model(wlan, BasicRangeModel)
    for node in node_list:
        interface = prefixes.create_interface(node)
        session.add_link(node.id, wlan.id, interface_one=interface)


    # instantiate session
    session.instantiate()
    def __init__(self, yml_nodes=None, yml_links=None, netmask="10.0.0.0/24"):
        """
        Constructor for the Topology class - Creates a topology and starts the emulation, if no parameters were provided then an empty topolgy is created.

        :param yml_nodes: a list containing the nodes parsed from the topology configuration file, defaults to None
        :type yml_nodes: list(YML_node), optional

        :param yml_links: a list containing the links parsed from the topology configuration file, defaults to None
        :type yml_links: list(parser.YML_link), optional

        :param netmask: the netmask tells the emulator what sort of IP addresses the virtual nodes should be assigned, defaults to 10.0.0.0/24
        :type netmask: str
        """

        Topology.prefixes = IpPrefixes(
            ip4_prefix=netmask)  #prefixes  # CORE prefixes
        self.coreemu = globals().get("coreemu",
                                     CoreEmu())  # CORE container for sessions
        self.session = self.coreemu.create_session()  # CORE session
        self.flag_physical_node = False
        self.netmask = netmask
        self.interfaceDict = {}
        self.inter_nodes = []  # Nodes from coreNode types
        self.physical_links = {}
        self.list_physical_links = []

        self.session.set_state(EventTypes.CONFIGURATION_STATE)

        self.interNodeObjects = []
        self.interLinkObjects = []

        if (yml_nodes and yml_links):
            self._init_topology(yml_nodes, yml_links)
        else:
            self.session.instantiate()
Example #10
0
def main():
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create emane network node, emane determines connectivity based on
    # location, so the session and nodes must be configured to provide one
    session.set_location(47.57917, -122.13232, 2.00000, 1.0)
    options = NodeOptions()
    options.set_position(80, 50)
    emane_network = session.add_node(_type=NodeTypes.EMANE,
                                     options=options,
                                     _id=100)
    session.emane.set_model(emane_network, EmaneIeee80211abgModel)

    # create nodes
    options = NodeOptions(model="mdr")
    for i in range(NODES):
        node = session.add_node(options=options)
        node.setposition(x=150 * (i + 1), y=150)
        interface = prefixes.create_interface(node)
        session.add_link(node.id, emane_network.id, interface_one=interface)

    # instantiate session
    session.instantiate()

    # OSPF MDR requires some time for routes to be created
    logging.info("waiting %s seconds for OSPF MDR to create routes",
                 EMANE_DELAY)
    time.sleep(EMANE_DELAY)

    # get nodes to run example
    first_node = session.get_node(1)
    last_node = session.get_node(NODES)
    address = prefixes.ip4_address(first_node)
    logging.info("node %s pinging %s", last_node.name, address)
    output = last_node.cmd(f"ping -c 3 {address}")
    logging.info(output)

    # shutdown session
    coreemu.shutdown()
Example #11
0
def create_session(topo_path, _id, dtn_software):
    coreemu = CoreEmu()
    session = coreemu.create_session(_id=_id)
    session.set_state(EventTypes.CONFIGURATION_STATE)

    ServiceManager.add_services('/root/.core/myservices')

    session.open_xml(topo_path)

    for obj in session.objects.itervalues():
        if type(obj) is CoreNode:
            session.services.add_services(obj, obj.type,
                                          ['pidstat', 'bwm-ng', dtn_software])

    session.instantiate()

    return session
Example #12
0
    def __init__(self, env_config, silent=True):
        if not silent:
            load_logging_config()

        self.envParser = EnvParser(env_config)

        if self.envParser.ip4_prefix:
            self.prefix = IpPrefixes(ip4_prefix=self.envParser.ip4_prefix)
        else:
            self.prefix = IpPrefixes(ip6_prefix=self.envParser.ip6_prefix)

        self.nodes = {}  # pc nodes
        self.networks = []  # switches nodes

        # create emulator instance for creating sessions and utility methods
        self.coreemu = CoreEmu()
        self.session = self.coreemu.create_session()

        # must be in configuration state for nodes to start, when using "node_add" below
        self.session.set_state(EventTypes.CONFIGURATION_STATE)

        # create nodes
        for node in self.envParser.nodes:
            self.nodes[int(node["id"])] = {"obj": self.session.add_node(_type=NodeTypes.DEFAULT), "nets": [],
                                           "ip": None, "curr_net": None}

        # create networks
        for net in self.envParser.networks:
            self.networks.append(self.session.add_node(_type=NodeTypes.SWITCH))
            for node in net["nodes"]:
                interface = self.prefix.create_interface(self.nodes[node["id"]]["obj"],
                                                         name=self.envParser.dev_prefix + str(net["id"]))
                self.nodes[node["id"]]["ip"] = self.prefix.ip4_address(self.nodes[node["id"]]["obj"])
                self.session.add_link(self.nodes[node["id"]]["obj"].id, self.networks[-1].id, interface_one=interface)
                self.nodes[node["id"]]["nets"].append({
                    "net": net["id"]
                })
        # certs
        shutil.rmtree('certs', True)
        self.__create_root_ca()
        for node in self.nodes:
            self.__create_node_cert(node)
        # instantiate session
        self.start()
Example #13
0
def main(args):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu({
        "controlnet":
        "core1:172.16.1.0/24 core2:172.16.2.0/24 core3:172.16.3.0/24 "
        "core4:172.16.4.0/24 core5:172.16.5.0/24",
        "distributed_address":
        args.address,
    })
    session = coreemu.create_session()

    # initialize distributed
    server_name = "core2"
    session.distributed.add_server(server_name, args.server)

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create local node, switch, and remote nodes
    options = NodeOptions(model="mdr")
    options.set_position(0, 0)
    node1 = session.add_node(CoreNode, options=options)
    emane_net = session.add_node(EmaneNet)
    session.emane.set_model(emane_net, EmaneIeee80211abgModel)
    options.server = server_name
    node2 = session.add_node(CoreNode, options=options)

    # create node interfaces and link
    interface1_data = prefixes.create_iface(node1)
    interface2_data = prefixes.create_iface(node2)
    session.add_link(node1.id, emane_net.id, iface1_data=interface1_data)
    session.add_link(node2.id, emane_net.id, iface1_data=interface2_data)

    # instantiate session
    session.instantiate()

    # pause script for verification
    input("press enter for shutdown")

    # shutdown session
    coreemu.shutdown()
Example #14
0
File: wlan.py Project: gsomlo/core
def example(options):
    # ip generator for example
    prefixes = IpPrefixes("10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create wlan network node
    wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
    session.mobility.set_model(wlan, BasicRangeModel)

    # create nodes
    wireless_nodes = []
    for _ in xrange(options.nodes):
        node = session.add_node()
        interface = prefixes.create_interface(node)
        session.add_link(node.objid, wlan.objid, interface_one=interface)
        wireless_nodes.append(node)

    # link all created nodes with the wireless network
    session.wireless_link_all(wlan, wireless_nodes)

    # instantiate session
    session.instantiate()

    # get nodes for example run
    first_node = session.get_object(2)
    last_node = session.get_object(options.nodes + 1)

    print "starting iperf server on node: %s" % first_node.name
    first_node.cmd(["iperf", "-s", "-D"])
    address = prefixes.ip4_address(first_node)
    print "node %s connecting to %s" % (last_node.name, address)
    last_node.client.icmd(["iperf", "-t", str(options.time), "-c", address])
    first_node.cmd(["killall", "-9", "iperf"])

    # shutdown session
    coreemu.shutdown()
Example #15
0
def example(options):
    # ip generator for example
    prefixes = IpPrefixes("10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create wlan network node
    wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
    session.set_wireless_model(wlan, BasicRangeModel)

    # create nodes
    wireless_nodes = []
    for _ in xrange(options.nodes):
        node = session.add_node()
        interface = prefixes.create_interface(node)
        session.add_link(node.objid, wlan.objid, interface_one=interface)
        wireless_nodes.append(node)

    # link all created nodes with the wireless network
    session.wireless_link_all(wlan, wireless_nodes)

    # instantiate session
    session.instantiate()

    # get nodes for example run
    first_node = session.get_object(2)
    last_node = session.get_object(options.nodes + 1)

    print "starting iperf server on node: %s" % first_node.name
    first_node.cmd(["iperf", "-s", "-D"])
    address = prefixes.ip4_address(first_node)
    print "node %s connecting to %s" % (last_node.name, address)
    last_node.client.icmd(["iperf", "-t", str(options.time), "-c", address])
    first_node.cmd(["killall", "-9", "iperf"])

    # shutdown session
    coreemu.shutdown()
Example #16
0
def session():
    # use coreemu and create a session
    coreemu = CoreEmu(config={"emane_prefix": "/usr"})
    session_fixture = coreemu.create_session()
    session_fixture.set_state(EventTypes.CONFIGURATION_STATE)
    assert os.path.exists(session_fixture.session_dir)

    # return created session
    yield session_fixture

    # clear session configurations
    session_fixture.location.reset()
    session_fixture.services.reset()
    session_fixture.mobility.config_reset()
    session_fixture.emane.config_reset()

    # shutdown coreemu
    coreemu.shutdown()

    # clear services, since they will be reloaded
    ServiceManager.services.clear()
Example #17
0
def session():
    # use coreemu and create a session
    coreemu = CoreEmu()
    session_fixture = coreemu.create_session()
    session_fixture.set_state(EventTypes.CONFIGURATION_STATE)
    assert os.path.exists(session_fixture.session_dir)

    # return created session
    yield session_fixture

    # clear session configurations
    session_fixture.location.reset()
    session_fixture.services.reset()
    session_fixture.mobility.config_reset()
    session_fixture.emane.config_reset()

    # shutdown coreemu
    coreemu.shutdown()

    # clear services, since they will be reloaded
    ServiceManager.services.clear()
Example #18
0
    def __init__(self, server_address, handler_class, config=None):
        """
        Server class initialization takes configuration data and calls
        the socketserver constructor.

        :param tuple[str, int] server_address: server host and port to use
        :param class handler_class: request handler
        :param dict config: configuration setting
        """
        self.coreemu = CoreEmu(config)
        self.config = config
        socketserver.TCPServer.__init__(self, server_address, handler_class)
Example #19
0
def example(args):
    # ip generator for example
    prefixes = IpPrefixes("10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create wlan network node
    wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
    session.mobility.set_model(wlan, BasicRangeModel)

    # create nodes, must set a position for wlan basic range model
    options = NodeOptions(model="mdr")
    options.set_position(0, 0)
    for _ in range(args.nodes):
        node = session.add_node(options=options)
        interface = prefixes.create_interface(node)
        session.add_link(node.id, wlan.id, interface_one=interface)

    # instantiate session
    session.instantiate()

    # get nodes for example run
    first_node = session.get_node(2)
    last_node = session.get_node(args.nodes + 1)

    logging.info("starting iperf server on node: %s", first_node.name)
    first_node.cmd("iperf -s -D")
    address = prefixes.ip4_address(first_node)
    logging.info("node %s connecting to %s", last_node.name, address)
    output = last_node.cmd(f"iperf -t {args.time} -c {address}")
    logging.info(output)
    first_node.cmd("killall -9 iperf")

    # shutdown session
    coreemu.shutdown()
Example #20
0
def example(options):
    # ip generator for example
    prefixes = IpPrefixes("10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create wlan network node
    wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
    session.mobility.set_model(wlan, BasicRangeModel)

    # create nodes, must set a position for wlan basic range model
    node_options = NodeOptions()
    node_options.set_position(0, 0)
    for _ in range(options.nodes):
        node = session.add_node(node_options=node_options)
        interface = prefixes.create_interface(node)
        session.add_link(node.id, wlan.id, interface_one=interface)

    # instantiate session
    session.instantiate()

    # get nodes for example run
    first_node = session.get_node(2)
    last_node = session.get_node(options.nodes + 1)

    print("starting iperf server on node: %s" % first_node.name)
    first_node.cmd(["iperf", "-s", "-D"])
    address = prefixes.ip4_address(first_node)
    print("node %s connecting to %s" % (last_node.name, address))
    last_node.client.icmd(["iperf", "-t", str(options.time), "-c", address])
    first_node.cmd(["killall", "-9", "iperf"])

    # shutdown session
    coreemu.shutdown()
Example #21
0
def example(options):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create switch network node
    switch = session.add_node(_type=NodeTypes.SWITCH)

    # create nodes
    for _ in range(options.nodes):
        node = session.add_node()
        interface = prefixes.create_interface(node)
        session.add_link(node.id, switch.id, interface_one=interface)

    # instantiate session
    session.instantiate()

    # get nodes to run example
    first_node = session.get_node(2)
    last_node = session.get_node(options.nodes + 1)

    print("starting iperf server on node: %s" % first_node.name)
    first_node.cmd(["iperf", "-s", "-D"])
    first_node_address = prefixes.ip4_address(first_node)
    print("node %s connecting to %s" % (last_node.name, first_node_address))
    last_node.client.icmd(
        ["iperf", "-t",
         str(options.time), "-c", first_node_address])
    first_node.cmd(["killall", "-9", "iperf"])

    # shutdown session
    coreemu.shutdown()
Example #22
0
def main(args):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu(
        {"controlnet": "172.16.0.0/24", "distributed_address": args.address}
    )
    session = coreemu.create_session()

    # initialize distributed
    server_name = "core2"
    session.distributed.add_server(server_name, args.server)

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create local node, switch, and remote nodes
    node1 = session.add_node(CoreNode)
    switch = session.add_node(SwitchNode)
    options = NodeOptions()
    options.server = server_name
    node2 = session.add_node(CoreNode, options=options)

    # create node interfaces and link
    interface1_data = prefixes.create_iface(node1)
    interface2_data = prefixes.create_iface(node2)
    session.add_link(node1.id, switch.id, iface1_data=interface1_data)
    session.add_link(node2.id, switch.id, iface1_data=interface2_data)

    # instantiate session
    session.instantiate()

    # pause script for verification
    input("press enter for shutdown")

    # shutdown session
    coreemu.shutdown()
Example #23
0
def example(options):
    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create switch network node
    switch = session.add_node(_type=NodeTypes.SWITCH)

    # create nodes
    for _ in xrange(options.nodes):
        node = session.add_node()
        interface = prefixes.create_interface(node)
        session.add_link(node.objid, switch.objid, interface_one=interface)

    # instantiate session
    session.instantiate()

    # get nodes to run example
    first_node = session.get_object(2)
    last_node = session.get_object(options.nodes + 1)

    print "starting iperf server on node: %s" % first_node.name
    first_node.cmd(["iperf", "-s", "-D"])
    first_node_address = prefixes.ip4_address(first_node)
    print "node %s connecting to %s" % (last_node.name, first_node_address)
    last_node.client.icmd(["iperf", "-t", str(options.time), "-c", first_node_address])
    first_node.cmd(["killall", "-9", "iperf"])

    # shutdown session
    coreemu.shutdown()
Example #24
0
File: wlan.py Project: umr-ds/core
def main():
    # ip generator for example
    prefixes = IpPrefixes("10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create wlan network node
    wlan = session.add_node(WlanNode, _id=100)
    session.mobility.set_model(wlan, BasicRangeModel)

    # create nodes, must set a position for wlan basic range model
    options = NodeOptions(model="mdr")
    options.set_position(0, 0)
    for _ in range(NODES):
        node = session.add_node(CoreNode, options=options)
        interface = prefixes.create_iface(node)
        session.add_link(node.id, wlan.id, iface1_data=interface)

    # instantiate session
    session.instantiate()

    # get nodes for example run
    first_node = session.get_node(1, CoreNode)
    last_node = session.get_node(NODES, CoreNode)
    address = prefixes.ip4_address(first_node.id)
    logging.info("node %s pinging %s", last_node.name, address)
    output = last_node.cmd(f"ping -c 3 {address}")
    logging.info(output)

    # shutdown session
    coreemu.shutdown()
Example #25
0
def example(nodes):
    # ip generator for example
    prefixes = IpPrefixes("192.168.10.0/24")
    node_list = []

    # create emulator instance for creating sessions and utility methods
    core_emu = globals().get("coreemu", CoreEmu())
    session = core_emu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create nodes
    node_options = NodeOptions()
    x = 0
    for i in range(nodes):
        y = 200
        x = x + 100
        if (i - 1) % 2 == 0:  #node id starts at 1
            y = 400
        node_options.set_position(x, y)
        node = session.add_node(node_options=node_options)
        node_list.append(node)

    # create switch network node
    wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
    session.mobility.set_model(wlan, BasicRangeModel)
    for node in node_list:
        interface = prefixes.create_interface(node)
        session.add_link(node.id, wlan.id, interface_one=interface)

    # instantiate session
    session.instantiate()

    for node_num in range(2, 2 + nodes - 1):
        n = session.get_node(node_num)
        print("starting swarmdag on node: %s" % n.name)
        n.cmd([swarmdag_path, ">", "swarmdag.txt"])
Example #26
0
    destination.cmd(["iperf", "-s", "-D"])
    source.client.icmd(["iperf", "-t", "10", "-c", dst_address])
    destination.cmd(["killall", "-9", "iperf"])


if __name__ == '__main__':

    framework.start()

    print "Starting Experiment"

    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create switch network node
    switch = session.add_node(_type=NodeTypes.SWITCH)

    print "Everything is set up now."

    # create nodes
    for _ in xrange(2):
        node = session.add_node()
        interface = prefixes.create_interface(node)
        link_opts = LinkOptions()
Example #27
0
# required imports

import netaddr, dataclasses, fabric, lxml, pyproj
from core.emulator.coreemu import CoreEmu
from core.emulator.data import IpPrefixes, NodeOptions
from core.emulator.enumerations import EventTypes
from core.nodes.base import CoreNode
from core.nodes.network import SwitchNode

# ip nerator for example
ip_prefixes = IpPrefixes(ip4_prefix="10.0.0.0/24")

# create emulator instance for creating sessions and utility methods
coreemu = CoreEmu()
session = coreemu.create_session()

print(session)

# must be in configuration state for nodes to start, when using "node_add" below
session.set_state(EventTypes.CONFIGURATION_STATE)

# create switch
options = NodeOptions(x=200, y=200)
switch = session.add_node(SwitchNode, options=options)

# create nodes
options = NodeOptions(x=100, y=100)
n1 = session.add_node(CoreNode, options=options)
options = NodeOptions(x=300, y=100)
n2 = session.add_node(CoreNode, options=options)
Example #28
0
def global_coreemu(patcher):
    coreemu = CoreEmu(config={"emane_prefix": "/usr"})
    yield coreemu
    coreemu.shutdown()
Example #29
0
class Env():
    def __init__(self, env_config, silent=True):
        if not silent:
            load_logging_config()

        self.envParser = EnvParser(env_config)

        if self.envParser.ip4_prefix:
            self.prefix = IpPrefixes(ip4_prefix=self.envParser.ip4_prefix)
        else:
            self.prefix = IpPrefixes(ip6_prefix=self.envParser.ip6_prefix)

        self.nodes = {}  # pc nodes
        self.networks = []  # switches nodes

        # create emulator instance for creating sessions and utility methods
        self.coreemu = CoreEmu()
        self.session = self.coreemu.create_session()

        # must be in configuration state for nodes to start, when using "node_add" below
        self.session.set_state(EventTypes.CONFIGURATION_STATE)

        # create nodes
        for node in self.envParser.nodes:
            self.nodes[int(node["id"])] = {"obj": self.session.add_node(_type=NodeTypes.DEFAULT), "nets": [],
                                           "ip": None, "curr_net": None}

        # create networks
        for net in self.envParser.networks:
            self.networks.append(self.session.add_node(_type=NodeTypes.SWITCH))
            for node in net["nodes"]:
                interface = self.prefix.create_interface(self.nodes[node["id"]]["obj"],
                                                         name=self.envParser.dev_prefix + str(net["id"]))
                self.nodes[node["id"]]["ip"] = self.prefix.ip4_address(self.nodes[node["id"]]["obj"])
                self.session.add_link(self.nodes[node["id"]]["obj"].id, self.networks[-1].id, interface_one=interface)
                self.nodes[node["id"]]["nets"].append({
                    "net": net["id"]
                })
        # certs
        shutil.rmtree('certs', True)
        self.__create_root_ca()
        for node in self.nodes:
            self.__create_node_cert(node)
        # instantiate session
        self.start()

    def get_node_ip(self, node):
        return self.nodes[node]["ip"]

    def run_command(self, node, command, wait=True):
        print(*command)
        self.nodes[node]["obj"].client.cmd(command, wait)

    def run_icommand(self, node, command):
        self.nodes[node]["obj"].client.icmd(command)

    def run_terminal(self, node):
        self.nodes[node]["obj"].client.term()

    def change_net(self, node, net):
        self.nodes[node]["obj"].cmd(
            ["ip", 'l', 'set', self.envParser.dev_prefix + str(self.nodes[node]['curr_net']), 'down'])
        self.nodes[node]["obj"].cmd(["ip", 'l', 'set', self.envParser.dev_prefix + str(net), 'up'])
        self.nodes[node]["curr_net"] = net

    '''options:
        delay TIME [ JITTER [CORRELATION]] [distribution {uniform|normal|pareto|paretonormal} ]
        corrupt PERCENT [CORRELATION]
        duplicate PERCENT [CORRELATION]
        loss random PERCENT [CORRELATION]
        loss state P13 [P31 [P32 [P23 P14]]
        loss gemodel PERCENT [R [1-H [1-K]]
        reorder PRECENT [CORRELATION] [ gap DISTANCE ]
   '''

    def add_net_params(self, nodes, net, params):
        for node in nodes:
            for param in params:
                self.nodes[node]["obj"].client.cmd(
                    ["tc", 'qdisc', 'add', 'dev', self.envParser.dev_prefix + str(net), 'root', 'netem', param] +
                    params[param])
        return

    '''
        Use add on first setting a params, later use set
    '''

    def set_net_params(self, nodes, net, params):
        for node in nodes:
            for param in params:
                self.nodes[node]["obj"].cmd(
                    ["tc", 'qdisc', 'change', 'dev', self.envParser.dev_prefix + str(net), 'root', 'netem', param] +
                    params[param])
        return

    def start(self):
        self.session.instantiate()
        for node in self.nodes.values():
            for net in node['nets']:
                node["obj"].cmd(["ip", 'l', 'set', self.envParser.dev_prefix + str(net['net']), 'down'])
            node["obj"].cmd(["ip", 'l', 'set', self.envParser.dev_prefix + str(node['nets'][0]['net']), 'up'])
            node['curr_net'] = node['nets'][0]['net']



    def finish(self):
        # remove certs
        shutil.rmtree('certs')
        # shutdown session
        self.coreemu.shutdown()

    # XXX: every cert's related things are store in "certs" directory just for now
    def __create_root_ca(self):
        try:
            os.mkdir('certs')
        except FileExistsError:
            pass
        os.system("openssl genrsa -out certs/rootCA.key 4096")
        os.system(
            "openssl req -x509 -new -nodes -key certs/rootCA.key -sha256 -days 1024 -subj \"/C=PL/ST=CA/O=DTN_TEST_ENV, Inc./CN=ROOT_CA\" -out certs/rootCA.crt")

    def __create_node_cert(self, nodeId):
        os.system("openssl genrsa -out certs/node" + str(nodeId) + ".key 2048")
        os.system("openssl req -new -sha256 -key certs/node" + str(
            nodeId) + ".key -subj \"/C=PL/ST=CA/O=DTN_TEST_ENV, Inc./CN=node" + str(
            nodeId) + "\" -out certs/node" + str(nodeId) + ".csr")
        os.system("openssl x509 -req -in certs/node" + str(
            nodeId) + ".csr -CA certs/rootCA.crt -CAkey certs/rootCA.key -CAcreateserial -out certs/node" + str(
            nodeId) + ".crt -days 500 -sha256")
Example #30
0
from core.nodes.base import CoreNode
from core.nodes.network import WlanNode
import time
import logging
from pyroute2 import IPRoute
import signal
import os
import net_events

log = logging.getLogger()
log.setLevel(logging.INFO)

SWARMDAG_PATH = '/home/jasonatran/go/src/github.com/ANRGUSC/swarmdag/build'
NUM_NODES = 8
prefixes = IpPrefixes("192.168.10.0/24")
session = CoreEmu().create_session()
ip = IPRoute()  # for IP routes on host


def cleanup_session(signum, frame):
    print("shutting down Core nodes...")
    session.shutdown()
    if len(ip.link_lookup(ifname='veth0')) == 1:
        #  `sudo ip link del veth0 type veth peer name veth1`
        ip.link("delete",
                ifname="veth0",
                kind="veth",
                peer={"ifname": "veth1"})
    exit()

Example #31
0
def main():

 # ip generator
 prefixes = IpPrefixes(ip4_prefix="10.42.0.0/16")

 # create emulator instance for creating sessions and utility methods
 cli = False 
 coreemu = globals().get("coreemu")
 if not coreemu:
    config = {"custom_services_dir": "/home/whoward3/coreScripts/myServices"}
    coreemu = CoreEmu(config=config)
    cli = True
 session = coreemu.create_session()

 # create client node options
 nodeOptions = NodeOptions()
 nodeOptions.services = ["Node"]

 # create attacker node options
 attackerOptions = NodeOptions()
 attackerOptions.services = ["Attacker"]
 
 # must be in configuration state for nodes to start, when using "add_node" below
 session.set_state(EventTypes.CONFIGURATION_STATE)
 switches = 5 #random.randint(2,10)
 node = []
 switch = []
 
 i = 0
 # create switches
 for _ in range(switches):
    y = random.randint(200,700)
    x = random.randint(200,700)
    switch.append(session.add_node(_type=NodeTypes.SWITCH))
    switch[i].setposition(x=x,y=y)
    i=i+1

 i = 0
 # create client nodes
 for _ in range(switches*5):
    y = random.randint(150,750)
    x = random.randint(150,750)
    if(i % 3 == 0 and i < (switches*5)):
      node.append(session.add_node(node_options=nodeOptions))
    else:
      node.append(session.add_node(node_options=nodeOptions)) 
    node[i].setposition(x=x,y=y)
    nodeInterface = prefixes.create_interface(node[i])

    # create interfaces to connect client nodes to switches
    if(i%switches==0):
     routerInterface = prefixes.create_interface(switch[0])
     session.add_link(node[i].id, switch[0].id, nodeInterface, routerInterface)
    elif(i%switches==1):
     routerInterface = prefixes.create_interface(switch[1])
     session.add_link(node[i].id, switch[1].id, nodeInterface, routerInterface)
    elif(i%switches==2):
     routerInterface = prefixes.create_interface(switch[2])
     session.add_link(node[i].id, switch[2].id, nodeInterface, routerInterface)
    elif(i%switches==3):
     routerInterface = prefixes.create_interface(switch[3])
     session.add_link(node[i].id, switch[3].id, nodeInterface, routerInterface)
    elif(i%switches==4):
     routerInterface = prefixes.create_interface(switch[4])
     session.add_link(node[i].id, switch[4].id, nodeInterface, routerInterface)
    elif(i%switches==5):
     routerInterface = prefixes.create_interface(switch[5])
     session.add_link(node[i].id, switch[5].id, nodeInterface, routerInterface)
    elif(i%switches==6):
     routerInterface = prefixes.create_interface(switch[6])
     session.add_link(node[i].id, switch[6].id, nodeInterface, routerInterface)
    elif(i%switches==7):
     routerInterface = prefixes.create_interface(switch[7])
     session.add_link(node[i].id, switch[7].id, nodeInterface, routerInterface)
    elif(i%switches==8):
     routerInterface = prefixes.create_interface(switch[8])
     session.add_link(node[i].id, switch[8].id, nodeInterface, routerInterface)
    elif(i%switches==9):
     routerInterface = prefixes.create_interface(switch[9])
     session.add_link(node[i].id, switch[9].id, nodeInterface, routerInterface)
    i=i+1

 # create interfaces to connect switches
 if(switches >= 2):
  switchA = prefixes.create_interface(switch[0])
  switchB = prefixes.create_interface(switch[1])
  session.add_link(switch[0].id,switch[1].id,switchA,switchB)
 if(switches >= 3):
  switchA = prefixes.create_interface(switch[1])
  switchB = prefixes.create_interface(switch[2])
  session.add_link(switch[1].id,switch[2].id,switchA,switchB)
 if(switches >= 4):
  switchA = prefixes.create_interface(switch[2])
  switchB = prefixes.create_interface(switch[3])
  session.add_link(switch[2].id,switch[3].id,switchA,switchB)
 if(switches >= 5):
  switchA = prefixes.create_interface(switch[3])
  switchB = prefixes.create_interface(switch[4])
  session.add_link(switch[3].id,switch[4].id,switchA,switchB)
 if(switches >= 6):
  switchA = prefixes.create_interface(switch[4])
  switchB = prefixes.create_interface(switch[5])
  session.add_link(switch[4].id,switch[5].id,switchA,switchB)
 if(switches >= 7):
  switchA = prefixes.create_interface(switch[5])
  switchB = prefixes.create_interface(switch[6])
  session.add_link(switch[5].id,switch[6].id,switchA,switchB)
 if(switches >= 8):
  switchA = prefixes.create_interface(switch[6])
  switchB = prefixes.create_interface(switch[7])
  session.add_link(switch[6].id,switch[7].id,switchA,switchB)
 if(switches >= 9):
  switchA = prefixes.create_interface(switch[7])
  switchB = prefixes.create_interface(switch[8])
  session.add_link(switch[7].id,switch[8].id,switchA,switchB)
 if(switches >= 10):
  switchA = prefixes.create_interface(switch[8])
  switchB = prefixes.create_interface(switch[9])
  session.add_link(switch[8].id,switch[9].id,switchA,switchB)

 # instantiate session
 session.instantiate()

 print("Session Instantiated, CLI = "+str(cli))

 # if the cli is being used terminate the session after 360 (canaries terminate after 340 + 20 seccond initalization delay) secconds 
 if(cli):
    stop_time = datetime.datetime.now() + datetime.timedelta(0,360)
    while datetime.datetime.now() < stop_time:
       pass
    coreemu.delete_session(session.id)
    print("Session Terminated by Timer")
Example #32
0
    def network_initializer(self, switches, composition, attackers):

        # check that switches is 2 <= s <= 10
        if (2 <= switches and switches <= 10):
            return "Error: Can only initalize a network of 2 to 10 switches in size"

        # ip generator
        prefixes = IpPrefixes(ip4_prefix="10.42.0.0/16")

        # create emulator instance for creating sessions and utility methods
        cli = False
        coreemu = globals().get("coreemu")

        # if not using the GUI provide path to the custom services directory
        if not coreemu:
            config = {"custom_services_dir": "../canaryServices"}
            coreemu = CoreEmu(config=config)
            cli = True
        session = coreemu.create_session()

        # create client node options
        node_options = NodeOptions()
        node_options.services = ["Node"]

        # create attacker node options
        attacker_options = NodeOptions()
        attacker_options.services = ["Attacker"]

        # must be in configuration state for nodes to start, when using
        # "add_node" below
        session.set_state(EventTypes.CONFIGURATION_STATE)
        node = []
        switch = []

        i = 0
        # create switches
        for _ in range(switches):
            y = random.randint(200, 700)
            x = random.randint(200, 700)
            switch.append(session.add_node(_type=NodeTypes.SWITCH))
            switch[i].setposition(x=x, y=y)
            i = i + 1

        # create list of randomly selected nodes for attacker deployment
        nodes = []
        if (attackers == "-1"):
            print("Generating attacker list...")
            for _ in range(switches * 5):
                while (True):
                    rnd = random.randint(0, switches * 5)
                    if (rnd not in nodes):
                        nodes.append(rnd)
                        break
            slc = (len(nodes) * composition)
            attackers = nodes[:int(slc)]
        else:
            nodes = [i for i in range(switches * 5)]
            if (attackers):
                attackers = attackers.split(',')
                attackers = [int(i) for i in attackers]
            else:
                attackers = []
        print("Nodes: " + str(nodes))
        print("Attackers: " + str(attackers))

        i = 0
        # create client nodes
        for _ in range(switches * 5):
            y = random.randint(150, 750)
            x = random.randint(150, 750)
            if (i in attackers):
                node.append(session.add_node(node_options=attacker_options))
            else:
                node.append(session.add_node(node_options=node_options))
            node[i].setposition(x=x, y=y)
            node_interface = prefixes.create_interface(node[i])

            # create interfaces to connect client nodes to switches
            if (i % switches == 0):
                switch_interface = prefixes.create_interface(switch[0])
                session.add_link(node[i].id, switch[0].id, node_interface,
                                 switch_interface)
            elif (i % switches == 1):
                switch_interface = prefixes.create_interface(switch[1])
                session.add_link(node[i].id, switch[1].id, node_interface,
                                 switch_interface)
            elif (i % switches == 2):
                switch_interface = prefixes.create_interface(switch[2])
                session.add_link(node[i].id, switch[2].id, node_interface,
                                 switch_interface)
            elif (i % switches == 3):
                switch_interface = prefixes.create_interface(switch[3])
                session.add_link(node[i].id, switch[3].id, node_interface,
                                 switch_interface)
            elif (i % switches == 4):
                switch_interface = prefixes.create_interface(switch[4])
                session.add_link(node[i].id, switch[4].id, node_interface,
                                 switch_interface)
            elif (i % switches == 5):
                switch_interface = prefixes.create_interface(switch[5])
                session.add_link(node[i].id, switch[5].id, node_interface,
                                 switch_interface)
            elif (i % switches == 6):
                switch_interface = prefixes.create_interface(switch[6])
                session.add_link(node[i].id, switch[6].id, node_interface,
                                 switch_interface)
            elif (i % switches == 7):
                switch_interface = prefixes.create_interface(switch[7])
                session.add_link(node[i].id, switch[7].id, node_interface,
                                 switch_interface)
            elif (i % switches == 8):
                switch_interface = prefixes.create_interface(switch[8])
                session.add_link(node[i].id, switch[8].id, node_interface,
                                 switch_interface)
            elif (i % switches == 9):
                switch_interface = prefixes.create_interface(switch[9])
                session.add_link(node[i].id, switch[9].id, node_interface,
                                 switch_interface)
            i = i + 1

        # create interfaces to connect switches
        if (switches >= 2):
            switch_a = prefixes.create_interface(switch[0])
            switch_b = prefixes.create_interface(switch[1])
            session.add_link(switch[0].id, switch[1].id, switch_a, switch_b)
        if (switches >= 3):
            switch_a = prefixes.create_interface(switch[1])
            switch_b = prefixes.create_interface(switch[2])
            session.add_link(switch[1].id, switch[2].id, switch_a, switch_b)
        if (switches >= 4):
            switch_a = prefixes.create_interface(switch[2])
            switch_b = prefixes.create_interface(switch[3])
            session.add_link(switch[2].id, switch[3].id, switch_a, switch_b)
        if (switches >= 5):
            switch_a = prefixes.create_interface(switch[3])
            switch_b = prefixes.create_interface(switch[4])
            session.add_link(switch[3].id, switch[4].id, switch_a, switch_b)
        if (switches >= 6):
            switch_a = prefixes.create_interface(switch[4])
            switch_b = prefixes.create_interface(switch[5])
            session.add_link(switch[4].id, switch[5].id, switch_a, switch_b)
        if (switches >= 7):
            switch_a = prefixes.create_interface(switch[5])
            switch_b = prefixes.create_interface(switch[6])
            session.add_link(switch[5].id, switch[6].id, switch_a, switch_b)
        if (switches >= 8):
            switch_a = prefixes.create_interface(switch[6])
            switch_b = prefixes.create_interface(switch[7])
            session.add_link(switch[6].id, switch[7].id, switch_a, switch_b)
        if (switches >= 9):
            switch_a = prefixes.create_interface(switch[7])
            switch_b = prefixes.create_interface(switch[8])
            session.add_link(switch[7].id, switch[8].id, switch_a, switch_b)
        if (switches >= 10):
            switch_a = prefixes.create_interface(switch[8])
            switch_b = prefixes.create_interface(switch[9])
            session.add_link(switch[8].id, switch[9].id, switch_a, switch_b)

        # instantiate session
        session.instantiate()
        print("Session Instantiated, CLI = " + str(cli))

        # if the cli is being used terminate the session after 360 (canaries
        # terminate after 340 + 20 seccond initalization delay) seconds
        if (cli):
            stop_time = datetime.datetime.now() + datetime.timedelta(0, 360)
            while datetime.datetime.now() < stop_time:
                pass
            coreemu.delete_session(session.id)
            print("Session Terminated by Timer")
Example #33
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('--is_virtual',
                        dest='is_virtual',
                        help='with Kronos',
                        default="False")

    args = parser.parse_args()

    if args.is_virtual == "True":
        is_virtual = True
    else:
        is_virtual = False

    # Kronos specific parameters
    total_num_dilated_executables = 6  # (2 plcs + 2 communication modules + 2 hmis )
    run_time_secs = 5
    rel_cpu_speed = 1.0
    num_insns_per_round = 1000000

    plc_spec_directory = os.path.dirname(os.path.realpath(__file__))
    plc1_spec_file = f"{plc_spec_directory}/plc1_system_specification.prototxt"
    plc2_spec_file = f"{plc_spec_directory}/plc2_system_specification.prototxt"

    NUM_PLCS = 2
    NUM_HMIS = 2

    # ip generator for example
    prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")

    # create emulator instance for creating sessions and utility methods
    coreemu = CoreEmu()
    session = coreemu.create_session()

    # must be in configuration state for nodes to start, when using "node_add" below
    session.set_state(EventTypes.CONFIGURATION_STATE)

    # create switch network node
    switch = session.add_node(SwitchNode, _id=100)

    # create nodes
    for _ in range(NUM_PLCS + NUM_HMIS):
        node = session.add_node(CoreNode)
        interface = prefixes.create_iface(node)
        session.add_link(node.id,
                         switch.id,
                         iface1_data=interface,
                         options=LinkOptions(delay=1000))  # delay in us

    # instantiate session
    session.instantiate()

    node_ifaces = []

    # get nodes to run example
    plc1_node = session.get_node(1, CoreNode)
    node_ifaces.extend(
        [x.localname for x in plc1_node.get_ifaces(control=False)])

    plc2_node = session.get_node(2, CoreNode)
    node_ifaces.extend(
        [x.localname for x in plc2_node.get_ifaces(control=False)])

    hmi1_node = session.get_node(3, CoreNode)
    node_ifaces.extend(
        [x.localname for x in hmi1_node.get_ifaces(control=False)])

    hmi2_node = session.get_node(4, CoreNode)
    node_ifaces.extend(
        [x.localname for x in hmi2_node.get_ifaces(control=False)])

    print("node-ifaces ", node_ifaces)
    plc1_ip_address = prefixes.ip4_address(plc1_node.id)
    plc2_ip_address = prefixes.ip4_address(plc2_node.id)

    print(f"PLC-1 IP: {plc1_ip_address}, PLC-2 IP: {plc2_ip_address}")

    # Clear any existing log files
    if os.path.exists("/tmp/pc_grpc_server_log.txt"):
        os.remove("/tmp/pc_grpc_server_log.txt")
    if os.path.exists("/tmp/plc1_log.txt"):
        os.remove("/tmp/plc1_log.txt")
    if os.path.exists("/tmp/plc2_log.txt"):
        os.remove("/tmp/plc2_log.txt")
    if os.path.exists("/tmp/comm_module1_log.txt"):
        os.remove("/tmp/comm_module1_log.txt")
    if os.path.exists("/tmp/comm_module2_log.txt"):
        os.remove("/tmp/comm_module2_log.txt")
    if os.path.exists("/tmp/hmi1.txt"):
        os.remove("/tmp/hmi1.txt")
    if os.path.exists("/tmp/hmi2.txt"):
        os.remove("/tmp/hmi2.txt")

    fd1 = os.open("/tmp/pc_grpc_server_log.txt", os.O_RDWR | os.O_CREAT)

    pendulum_sim = PendulumSystemSimulator()
    if args.is_virtual == "True":
        is_virtual = True
    else:
        is_virtual = False

    # Create an emulation driver. Register pendulum system simulator with it.
    emulation = EmulationDriver(
        number_dilated_nodes=total_num_dilated_executables,
        is_virtual=is_virtual,
        n_insns_per_round=num_insns_per_round,
        rel_cpu_speed=rel_cpu_speed,
        physical_system_sim_driver=pendulum_sim)

    # Start pc_grpc_server, all PLCs and all communication modules here
    emulation.start_grpc_server(plc_spec_directory, fd1)

    if is_virtual:
        emulation.add_interfaces_to_vt_control(node_ifaces)

    # Retrieve command strings to run PLCs/HMIs/Communication Modules
    plc1_cmd = emulation.get_plc_exec_command(
        path_to_plc_specification_file=plc1_spec_file,
        log_file_path="/tmp/plc1_log.txt")
    plc2_cmd = emulation.get_plc_exec_command(
        path_to_plc_specification_file=plc2_spec_file,
        log_file_path="/tmp/plc2_log.txt")

    comm_module1_cmd = emulation.wrap_command(
        get_comm_module_start_command(plc1_spec_file, plc1_ip_address,
                                      "/tmp/comm_module1_log.txt"))
    comm_module2_cmd = emulation.wrap_command(
        get_comm_module_start_command(plc2_spec_file, plc2_ip_address,
                                      "/tmp/comm_module2_log.txt"))

    hmi1_cmd = emulation.wrap_command(
        get_example_hmi_start_command(plc1_ip_address, "/tmp/hmi1.txt"))
    hmi2_cmd = emulation.wrap_command(
        get_example_hmi_start_command(plc2_ip_address, "/tmp/hmi2.txt"))

    print("Starting PLCs ...")
    plc1_node.cmd(plc1_cmd, wait=False)
    plc2_node.cmd(plc2_cmd, wait=False)
    print("Starting PLC Modbus Comm modules ...")
    plc1_node.cmd(comm_module1_cmd, wait=False)
    plc2_node.cmd(comm_module2_cmd, wait=False)
    print("Starting HMI ...")
    hmi1_node.cmd(hmi1_cmd, wait=False)
    hmi2_node.cmd(hmi2_cmd, wait=False)

    # Wait until all processes have started and registered themselves
    emulation.wait_for_initialization()

    # Register an interrupt signal handler.
    signal.signal(signal.SIGINT, handler)

    total_time_elapsed = 0.0
    while total_time_elapsed <= run_time_secs:

        emulation.run_for(0.01)
        total_time_elapsed += 0.01
        if is_virtual:
            print("Time Elapsed: ", total_time_elapsed)
        if stop == True:
            break

    print("Stopping Emulation ...")
    sys.stdout.flush()
    emulation.stop_exp()

    os.close(fd1)

    # shutdown session
    coreemu.shutdown()

    print("Emulation finished ! ")