Ejemplo n.º 1
0
def eval_input(source):
    result = restricted_eval(source, models())

    if isinstance(result, AvroraRadioModel):
        return result
    else:
        raise RuntimeError(f"The medium model ({source}) is not valid.")
Ejemplo n.º 2
0
def create_specific(source):
    """Creates a source period model from the :source: string"""
    result = restricted_eval(source, models())

    if isinstance(result, numbers.Number):
        return FixedPeriodModel(result)
    elif isinstance(result, PeriodModel):
        return result
    else:
        raise RuntimeError(f"The source ({source}) is not valid.")
Ejemplo n.º 3
0
def eval_input(source):
    result = restricted_eval(source, models())

    if result in models():
        raise RuntimeError(f"The fault model ({source}) is not valid. (Did you forget the brackets after the name?)")

    if not isinstance(result, FaultModel):
        raise RuntimeError(f"The fault model ({source}) is not valid.")

    return result
Ejemplo n.º 4
0
def eval_input(source):
    result = MODEL_NAME_MAPPING.get(source, None)
    if result is not None:
        return result()

    result = restricted_eval(source, models())

    if isinstance(result, NoiseModel):
        return result
    else:
        raise RuntimeError(f"The source ({source}) is not valid.")
Ejemplo n.º 5
0
def eval_input(source):
    result = restricted_eval(source, models())

    if result in models():
        raise RuntimeError(
            f"The source ({source}) is not valid. (Did you forget the brackets after the name?)"
        )

    if not isinstance(result, Attacker):
        raise RuntimeError(
            f"The source ({source}) is not a valid instance of an Attacker.")

    return result
Ejemplo n.º 6
0
def try_create_specific(name):
    # The format of this name should be:
    # <Topology><optional arguments><Source><number><Sink><Number>

    import re

    from data.testbed.indriya import Indriya
    from data.testbed.fitiotlab import Euratech
    from data.testbed.fitiotlab import Rennes
    from data.testbed.twist import Twist
    from data.testbed.flocklab import FlockLab

    available_topologies = [
        Bag, Line, Grid, Circle, Random, SimpleTree, Ring, Euratech, Rennes,
        Indriya, Twist, FlockLab
    ]

    match = re.match(r"^([A-Za-z]+)(\(.*\))?Source([0-9]+)Sink([0-9]+)$", name)
    if not match:
        raise RuntimeError(f"Unable to parse configuration name {name}")

    (topology_name, topology_args, source_id, sink_id) = match.groups()

    if topology_args is None:
        topology_args = "()"

    topology_classes = [
        t for t in available_topologies if t.__name__ == topology_name
    ]

    if len(topology_classes) == 0:
        raise RuntimeError(f"Unable to find a topology called {topology_name}")
    if len(topology_classes) != 1:
        raise RuntimeError(f"Too many topologies called {topology_name}?")

    topology = restricted_eval(f"{topology_name}{topology_args}",
                               topology_classes)

    class NewConfiguration(Configuration):
        def __init__(self, *args, **kwargs):
            super().__init__(topology,
                             source_ids={int(source_id)},
                             sink_ids={int(sink_id)},
                             space_behind_sink=False)

    NewConfiguration.__name__ = name

    return NewConfiguration
Ejemplo n.º 7
0
def eval_input(source):
    # Need to allow restricted_eval access to the attacker classes
    all_models = models() + Attacker.models()

    result = restricted_eval(source, all_models)

    # If we have just been passed a single attacker, then make it an attacker configuration
    if isinstance(result, Attacker.Attacker):
        result = SingleAttacker(result)

    if result in all_models:
        raise RuntimeError(
            f"The source ({source}) is not valid. (Did you forget the brackets after the name?)"
        )

    if not isinstance(result, AttackerConfiguration):
        raise RuntimeError(
            f"The source ({source}) is not a valid instance of an Attacker.")

    return result