Esempio n. 1
0
class Operator(Expression):
    def __init__(self, function, operands):
        self.function = function
        self.operands = operands

    function = attr(Function)
    operands = ref_list(inv=Expression.parent)
Esempio n. 2
0
class ConnectivityMatrix:
    "The Connectivity matrix from the topology simulator."
    plan = ref(inv=Plan.connectivityMatrix)

    rfSimId = attr(str)

    connectivity = ref_list()
    descend(connectivity)
Esempio n. 3
0
class CastaliaModel:
    '''
    The top-level model, contains a 
    '''
    # omnetpp sections
    omnetpp = ref_list(inv=Section.castalia_model)

    # node types
    nodeTypes = refs(inv=NodeType.castalia_model)

    #main network definition
    network = attr(Network)
Esempio n. 4
0
class VectorlEnvironment(Environment):
    vectorl_id = attr(str, nullable=False)
    json_name('vectrol_id')(vectorl_id)
    required(vectorl_id)

    mapping = ref_list(inv=VLMapping.env)
    descend(mapping)

    def variable_for(self, pm):
        "Return vectorl variable name for a physical measure, or None"
        for vlm in self.mapping:
            if pm == vlm.sensor:
                return vlm.variable
        return None
Esempio n. 5
0
class ACL:
    eclass = ref()
    rules = ref_list(inv=ACEntry.acl)

    def allow(self, role, priv):
        self.rules.append(ACEntry(role, priv, True))

    def deny(self, role, priv):
        self.rules.append(ACEntry(role, priv, False))

    def match(self, roles, priv):
        for rule in self.rules:
            if rule.matches(roles, priv):
                return rule.allow  # return first matching rule!
        return None
Esempio n. 6
0
class ConstraintUnique(Named):
    '''
	Declare a uniqueness constraint on a number of attributes.
	'''

    entity = ref()
    fields = ref_list(inv=Field.constraints)
    primary_key = attr(bool, default=False)

    def __init__(self, name, entity, keys, primary_key=False):
        super().__init__(name)
        self.entity = entity
        self.primary_key = primary_key
        assert len(keys) > 0
        for key in keys:
            if isinstance(key, str):
                key = entity.get_field(key)
            self.fields.append(key)

    def names(self):
        return [f.name for f in self.fields]
Esempio n. 7
0
class Section:
    '''
    A config section in the omnetpp.ini file
    '''

    # the section name, or None for the general section
    name = attr(str, nullable=True, default=None)

    # the supersections (and subsections)
    extends = ref_list()
    extended_by = refs(inv=extends)

    # the top-level model
    castalia_model = ref()

    # module declarations for this section
    modules = attr(list)

    def __init__(self, cm, name, extends=[]):
        self.name = name
        self.castalia_model = cm
        self.extends = extends
        self.modules = []
Esempio n. 8
0
class Table:
    """
    Describes a table with columns
    """
    def __init__(self,
                 name,
                 columns=[],
                 filename=None,
                 format=None,
                 node_mapping=None):
        self.name = name
        self.columns = columns
        # just for easy access to columns by name
        #self.col = {self.columns[i].name: self.columns[i] for i in list(range(len(self.columns)))}
        self.col = {col.name: col for col in self.columns}
        self.filename = filename
        self.format = format
        self.node_mapping = node_mapping

    # the name for this table
    name = attr(str, nullable=False)

    # the columns contained in this table
    columns = ref_list(inv=Column.table)
Esempio n. 9
0
class CastaliaModule:
    '''
    This class represents a castalia module or collection of modules.
    Subclasses of this class can have additional 'parameter' attributes

    A module is defined by a path and an index. Also, it can have a parent 
    and a list of submodules. 

    The full_name of a module is determined by its name and index, and those
    of its parents.

    Examples.

    net = CastaliaModule(None, 'SN')  ->           SN   (the root network module)
    CastaliaModule(net, 'node', slice(10,15))  ->   SN.node[10..14]

    node_group = CastaliaModule(None, 'SN.node', slice(2,5))  ->  SN.node[2..4]
    node_group_radio = CastaliaModule(node_group, 'Radio')    ->  SN.node[2..4].Radio

    '''
    # module tree
    parent = ref()
    submodules = ref_list(inv=parent)

    # The name and index of this submodule in the parent
    subname = attr(str, nullable=False)

    # the index can be a number or a range.
    index = attr(type=(int, slice), nullable=True, default=None)

    def __base_name(self):
        if self.parent is None:
            return self.subname
        else:
            return '.'.join([self.parent.full_name, self.subname])

    @property
    def full_name(self):
        '''
        The pathname for this submodule in the NED tree.
        '''
        if self.index is None:
            return self.__base_name()
        else:
            return "%s[%s]" % (self.__base_name(), index_to_text(self.index))

    def submodule(self, name, index=None):
        '''
        Create a new generic submodule for this module.
        '''
        return CastaliaModule(self, name, index)

    def __getattr__(self, name):
        '''
        This method will be called only if there is no proper attribute 
        by the given name. It will look into the ad-hoc submodules and
        parameters for a match, and will fail if none is found.

        Note: parameter names are looked up first, so if there is a name collision
        the parameter will be returned.
        '''
        assert isinstance(name, str)
        param_map = object.__getattr__(self, '_CastaliaModule__param_map')
        if name in param_map:
            return param_map[name]
        else:
            # look for submodule by this name
            for s in self.submodules:
                if s.subname == name:
                    return s
        raise AttributeError("Castalia moduel '%s' has no member '%s'" %
                             (self.__class__.__name__, name))

    def base(self):
        '''
        Return a CastaliaModule M.

        The type of M is always CastaliaModule.
        
        M has no parent.
        
        The name of the module is equal to the full_name of self,
        without the index, and the index of M is equal to the index of self.

        Therefore, M.full_name == self.full_name
        '''
        return CastaliaModule(None, self.__base_name(), self.index)

    def set(self, pname, pvalue):
        '''
        Set a generic parameter for this module.
        '''
        self.__param_map[pname] = pvalue

    def all_parameters(self):
        for pname, pvalue in self.__param_map.items():
            yield pname, pvalue
        for param in self.__model_class__.all_attributes:
            if Param.has(param):
                yield param.name, getattr(self, param.name, None)

    def __init__(self, parent, name, index=None):
        self.__param_map = {}

        self.parent = parent
        self.subname = name
        self.index = index