From: Alina Quereilhac Date: Sun, 2 Feb 2014 22:01:17 +0000 (+0100) Subject: Fixing ns-3 RM generation script X-Git-Tag: nepi-3.1.0~120^2~15 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=0a8ad989a65fef39f9227f38325a7c732b7a9cd9;p=nepi.git Fixing ns-3 RM generation script --- diff --git a/src/nepi/execution/attribute.py b/src/nepi/execution/attribute.py index a82274a0..1e3bdde8 100644 --- a/src/nepi/execution/attribute.py +++ b/src/nepi/execution/attribute.py @@ -154,6 +154,9 @@ class Attribute(object): if self.type in [Types.Double, Types.Integer] and self.range: (min, max) = self.range + + value = float(value) + valid = (value >= min and value <= max) valid = valid and self.is_valid_value(value) diff --git a/src/nepi/execution/resource.py b/src/nepi/execution/resource.py index 059a7585..b4a0c882 100644 --- a/src/nepi/execution/resource.py +++ b/src/nepi/execution/resource.py @@ -1060,7 +1060,7 @@ def find_types(): continue if issubclass(attr, ResourceManager): - if find(attr.get_rtype().lower(), "abstract") > -1: + if attr.get_rtype().lower().find("abstract") > -1: continue types.append(attr) diff --git a/src/nepi/resources/ns3/resource_manager_generator.py b/src/nepi/resources/ns3/resource_manager_generator.py index e8ff1a73..fd5e7003 100644 --- a/src/nepi/resources/ns3/resource_manager_generator.py +++ b/src/nepi/resources/ns3/resource_manager_generator.py @@ -23,23 +23,37 @@ from nepi.resources.ns3.ns3wrapper import load_ns3_module import os import re -def select_base_class(ns3, tid): - base_class_import = base_class = None +def discard(ns3, tid): + rtype = tid.GetName() + + words = ["variable", "object", "probe", "adaptor", "wrapper", + "container", "derived", "simple"] + for word in words: + if rtype.lower().find(word) > -1: + return True + bases = ["ns3::Scheduler", "ns3::SimulatorImpl"] + type_id = ns3.TypeId() + for base in bases: + tid_base = type_id.LookupByName(base) + if tid.IsChildOf(tid_base): + return True + + return False + +def select_base_class(ns3, tid): + base_class_import = "from nepi.resources.ns3.ns3base import NS3Base" + base_class = "NS3Base" + rtype = tid.GetName() if rtype == "ns3::Node": base_class_import = "from nepi.resources.ns3.ns3node import NS3BaseNode" base_class = "NS3BaseNode" elif rtype == "ns3::Ipv4L3Protocol": - base_class_import = "from nepi.resources.ns3.ns3ipv4protocol import NS3BaseIpv4L3Protocol" + base_class_import = "from nepi.resources.ns3.ns3ipv4l3protocol import NS3BaseIpv4L3Protocol" base_class = "NS3BaseIpv4L3Protocol" else: - base_class_import = "from nepi.resources.ns3.ns3base import NS3Base" - base_class = "NS3Base" - - - if not base_class: type_id = ns3.TypeId() bases = ["ns3::Application", @@ -59,7 +73,7 @@ def select_base_class(ns3, tid): if tid.IsChildOf(tid_base): base_class = "NS3Base" + base.replace("ns3::", "") base_module = "ns3" + base.replace("ns3::", "").lower() - base_class_import = "from nepi.resources.ns3.ns3application import %s " % ( + base_class_import = "from nepi.resources.ns3.%s import %s " % ( base_module, base_class) return (base_class_import, base_class) @@ -76,6 +90,9 @@ def create_ns3_rms(): for i in xrange(tid_count): tid = type_id.GetRegistered(i) + if discard(ns3, tid): + continue + if tid.MustHideFromDocumentation() or \ not tid.HasConstructor() or \ not tid.IsChildOf(base): @@ -94,9 +111,9 @@ def create_ns3_rms(): (base_class_import, base_class) = select_base_class(ns3, tid) - rtype = tid.GetName() category = tid.GetGroupName() + rtype = tid.GetName() classname = rtype.replace("ns3::", "NS3").replace("::","") uncamm_rtype = re.sub('([a-z])([A-Z])', r'\1-\2', rtype).lower() short_rtype = uncamm_rtype.replace("::","-") @@ -142,7 +159,7 @@ def template_attributes(ns3, tid): attr_flags = "None" flags = attr_info.flags if (flags & ns3.TypeId.ATTR_SET) != ns3.TypeId.ATTR_SET: - attr_flags = "Types.ExecReadOnly" + attr_flags = "Flags.ExecReadOnly" attr_name = attr_info.name checker = attr_info.checker @@ -151,7 +168,7 @@ def template_attributes(ns3, tid): attr_value = value.SerializeToString(checker) attr_allowed = "None" attr_range = "None" - attr_type = "Types.STRING" + attr_type = "Types.String" if isinstance(value, ns3.ObjectVectorValue): continue @@ -160,19 +177,20 @@ def template_attributes(ns3, tid): elif isinstance(value, ns3.WaypointValue): continue elif isinstance(value, ns3.BooleanValue): - attr_type = "Types.BOOL" + attr_type = "Types.Bool" attr_value = "True" if attr_value == "true" else "False" elif isinstance(value, ns3.EnumValue): - attr_type = "Types.ENUM" - attr_allowed = "[%s]"% checker.GetUnderlyingTypeInformation().replace("|", ",") + attr_type = "Types.Enumerate" + allowed = checker.GetUnderlyingTypeInformation().split("|") + attr_allowed = "[%s]" % ",".join(map(lambda x: "\"%s\"" % x, allowed)) elif isinstance(value, ns3.DoubleValue): - attr_type = "Types.DOUBLE" + attr_type = "Types.Double" # TODO: range elif isinstance(value, ns3.UintegerValue): - attr_type = "Types.INTEGER" + attr_type = "Types.Integer" # TODO: range - attr_id = attr_name.lower() + attr_id = "attr_" + attr_name.lower().replace("-", "_") attributes += template.replace("", attr_id) \ .replace("", attr_name) \ .replace("", attr_help) \