Ejemplo n.º 1
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()
Ejemplo n.º 2
0
#
# run iperf to measure the effective throughput between two nodes when
# n nodes are connected to a virtual wlan; run test for testsec
# and repeat for minnodes <= n <= maxnodes with a step size of
# nodestep

import datetime
from builtins import range

import parser
from core import load_logging_config
from core.emulator.coreemu import CoreEmu
from core.emulator.emudata import IpPrefixes
from core.emulator.enumerations import NodeTypes, EventTypes

load_logging_config()


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)