From fbc7c758e1464d3af686062505fde706fc92b47c Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Sun, 2 Feb 2014 21:23:06 +0100 Subject: [PATCH] Ignoring 'abstract' RMs upon ResourceFactory discover --- src/nepi/execution/resource.py | 3 + src/nepi/resources/ns3/classes/__init__.py | 0 src/nepi/resources/ns3/ns3application.py | 2 +- src/nepi/resources/ns3/ns3base.py | 9 +- src/nepi/resources/ns3/ns3channel.py | 4 +- src/nepi/resources/ns3/ns3errormodel.py | 46 ++++++++ src/nepi/resources/ns3/ns3errorratemodel.py | 46 ++++++++ ...s3ipv4protocol.py => ns3ipv4l3protocol.py} | 13 +-- src/nepi/resources/ns3/ns3netdevice.py | 102 ++++++++++++++++++ src/nepi/resources/ns3/ns3node.py | 11 +- ...s3delay.py => ns3propagationdelaymodel.py} | 2 +- ...{ns3loss.py => ns3propagationlossmodel.py} | 0 src/nepi/resources/ns3/ns3queue.py | 4 +- src/nepi/resources/ns3/ns3wifimac.py | 46 ++++++++ .../ns3/{ns3device.py => ns3wifiphy.py} | 35 +++--- ...ager.py => ns3wifiremotestationmanager.py} | 6 +- .../ns3/resource_manager_generator.py | 72 ++++++------- 17 files changed, 319 insertions(+), 82 deletions(-) create mode 100644 src/nepi/resources/ns3/classes/__init__.py create mode 100644 src/nepi/resources/ns3/ns3errormodel.py create mode 100644 src/nepi/resources/ns3/ns3errorratemodel.py rename src/nepi/resources/ns3/{ns3ipv4protocol.py => ns3ipv4l3protocol.py} (80%) create mode 100644 src/nepi/resources/ns3/ns3netdevice.py rename src/nepi/resources/ns3/{ns3delay.py => ns3propagationdelaymodel.py} (97%) rename src/nepi/resources/ns3/{ns3loss.py => ns3propagationlossmodel.py} (100%) create mode 100644 src/nepi/resources/ns3/ns3wifimac.py rename src/nepi/resources/ns3/{ns3device.py => ns3wifiphy.py} (58%) rename src/nepi/resources/ns3/{ns3manager.py => ns3wifiremotestationmanager.py} (89%) diff --git a/src/nepi/execution/resource.py b/src/nepi/execution/resource.py index d0d9079a..059a7585 100644 --- a/src/nepi/execution/resource.py +++ b/src/nepi/execution/resource.py @@ -1060,6 +1060,9 @@ def find_types(): continue if issubclass(attr, ResourceManager): + if find(attr.get_rtype().lower(), "abstract") > -1: + continue + types.append(attr) if not modname in sys.modules: diff --git a/src/nepi/resources/ns3/classes/__init__.py b/src/nepi/resources/ns3/classes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/nepi/resources/ns3/ns3application.py b/src/nepi/resources/ns3/ns3application.py index 736dd654..f53d5053 100644 --- a/src/nepi/resources/ns3/ns3application.py +++ b/src/nepi/resources/ns3/ns3application.py @@ -22,7 +22,7 @@ from nepi.resources.ns3.ns3base import NS3Base @clsinit_copy class NS3BaseApplication(NS3Base): - _rtype = "ns3::Application" + _rtype = "abstract::ns3::Application" def _connect_object(self): node = self.node diff --git a/src/nepi/resources/ns3/ns3base.py b/src/nepi/resources/ns3/ns3base.py index f8d7d12d..f36ffce2 100644 --- a/src/nepi/resources/ns3/ns3base.py +++ b/src/nepi/resources/ns3/ns3base.py @@ -20,13 +20,13 @@ from nepi.execution.resource import ResourceManager, clsinit_copy, \ ResourceState, reschedule_delay -from nepi.execute.attributes import Flags +from nepi.execution.attribute import Flags from nepi.resources.ns3.ns3simulator import NS3Simulator -from nepi.resources.ns3.ns3node import NS3BaseNode @clsinit_copy class NS3Base(ResourceManager): - _rtype = "ns3::Object" + _rtype = "abstract::ns3::Object" + _backend_type = "ns3" def __init__(self): super(NS3Base, self).__init__() @@ -53,6 +53,7 @@ class NS3Base(ResourceManager): @property def node(self): + from nepi.resources.ns3.ns3node import NS3BaseNode nodes = self.get_connected(NS3BaseNode.get_rtype()) if nodes: return nodes[0] return None @@ -104,8 +105,8 @@ class NS3Base(ResourceManager): # self.simulator.node.mkdir(self.run_home) self._instantiate_object() - self._configure_object() self._connect_object() + self._configure_object() self.info("Provisioning finished") diff --git a/src/nepi/resources/ns3/ns3channel.py b/src/nepi/resources/ns3/ns3channel.py index fe628c85..063e31b3 100644 --- a/src/nepi/resources/ns3/ns3channel.py +++ b/src/nepi/resources/ns3/ns3channel.py @@ -19,14 +19,14 @@ from nepi.execution.resource import clsinit_copy from nepi.resources.ns3.ns3base import NS3Base -from nepi.resources.ns3.ns3device import NS3BaseNetDevice @clsinit_copy class NS3BaseChannel(NS3Base): - _rtype = "ns3::Channel" + _rtype = "abstract::ns3::Channel" @property def devices(self): + from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice return self.get_connected(NS3BaseNetDevice.get_rtype()) @property diff --git a/src/nepi/resources/ns3/ns3errormodel.py b/src/nepi/resources/ns3/ns3errormodel.py new file mode 100644 index 00000000..656b580a --- /dev/null +++ b/src/nepi/resources/ns3/ns3errormodel.py @@ -0,0 +1,46 @@ +# +# NEPI, a framework to manage network experiments +# Copyright (C) 2014 INRIA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Author: Alina Quereilhac + +from nepi.execution.resource import clsinit_copy +from nepi.resources.ns3.ns3base import NS3Base + +@clsinit_copy +class NS3BaseErrorModel(NS3Base): + _rtype = "abstract::ns3::ErrorModel" + + @property + def device(self): + from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice + devices = self.get_connected(NS3BaseNetDevice.get_rtype()) + if devices: return devices[0] + return None + + @property + def others_to_wait(self): + others = set() + device = self.device + if device: others.add(device) + return others + + def _connect_object(self): + device = self.device + if device and device.uuid not in self.connected: + self.simulator.invoke(device.uuid, "SetReceiveErrorModel", self.uuid) + self._connected.add(device.uuid) + diff --git a/src/nepi/resources/ns3/ns3errorratemodel.py b/src/nepi/resources/ns3/ns3errorratemodel.py new file mode 100644 index 00000000..3de95682 --- /dev/null +++ b/src/nepi/resources/ns3/ns3errorratemodel.py @@ -0,0 +1,46 @@ +# +# NEPI, a framework to manage network experiments +# Copyright (C) 2014 INRIA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Author: Alina Quereilhac + +from nepi.execution.resource import clsinit_copy +from nepi.resources.ns3.ns3base import NS3Base +from nepi.resources.ns3.ns3wifiphy import NS3BaseWifiPhy + +@clsinit_copy +class NS3BaseErrorRateModel(NS3Base): + _rtype = "abstract::ns3::ErrorRateModel" + + @property + def phy(self): + phys = self.get_connected(NS3BaseWifiPhy.get_rtype()) + if phys: return phys[0] + return None + + @property + def others_to_wait(self): + others = set() + phy = self.phy + if phy: others.add(phy) + return others + + def _connect_object(self): + phy = self.phy + if phy and phy.uuid not in self.connected: + self.simulator.invoke(phy.uuid, "SetErrorRateModel", self.uuid) + self._connected.add(phy.uuid) + diff --git a/src/nepi/resources/ns3/ns3ipv4protocol.py b/src/nepi/resources/ns3/ns3ipv4l3protocol.py similarity index 80% rename from src/nepi/resources/ns3/ns3ipv4protocol.py rename to src/nepi/resources/ns3/ns3ipv4l3protocol.py index 81ce0ac5..21554222 100644 --- a/src/nepi/resources/ns3/ns3ipv4protocol.py +++ b/src/nepi/resources/ns3/ns3ipv4l3protocol.py @@ -21,20 +21,13 @@ from nepi.execution.resource import clsinit_copy from nepi.resources.ns3.ns3base import NS3Base @clsinit_copy -class NS3BaseIpV4Protocol(Ns3Base): - _rtype = "ns3::IpV4Protocol" - - def do_provision(self): - # create run dir for ns3 object - # self.simulator.node.mkdir(self.run_home) - - self._instantiate_object() +class NS3BaseIpv4L3Protocol(NS3Base): + _rtype = "abstract::ns3::Ipv4L3Protocol" + def _configure_object(self): uuid_list_routing = simulator.create("Ipv4ListRouting") simulator.invoke(self.uuid, "SetRoutingProtocol", uuid_list_routing) uuid_static_routing = simulator.create("Ipv4StaticRouting") simulator.invoke(self.uuid, "SetRoutingProtocol", uuid_static_routing, 1) - super(NS3BaseIpV4Protocol, self).do_provision() - diff --git a/src/nepi/resources/ns3/ns3netdevice.py b/src/nepi/resources/ns3/ns3netdevice.py new file mode 100644 index 00000000..4978c7e0 --- /dev/null +++ b/src/nepi/resources/ns3/ns3netdevice.py @@ -0,0 +1,102 @@ +# +# NEPI, a framework to manage network experiments +# Copyright (C) 2014 INRIA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Author: Alina Quereilhac + +from nepi.execution.attribute import Attribute, Flags +from nepi.execution.resource import clsinit_copy +from nepi.resources.ns3.ns3base import NS3Base + +@clsinit_copy +class NS3BaseNetDevice(NS3Base): + _rtype = "abstract::ns3::NetDevice" + + @classmethod + def _register_attributes(cls): + mac = Attribute("mac", "MAC address for device", + flags = Flags.ExecReadOnly) + + ip = Attribute("ip", "IP address for device", + flags = Flags.ExecReadOnly) + + prefix = Attribute("prefix", "Network prefix for device", + flags = Flags.ExecReadOnly) + + cls._register_attribute(mac) + cls._register_attribute(ip) + cls._register_attribute(prefix) + + @property + def channel(self): + from nepi.resources.ns3.ns3channel import NS3Channel + channels = self.get_connected(NS3BaseChannel.get_rtype()) + if channels: return channels[0] + return None + + @property + def others_to_wait(self): + others = set() + node = self.node + if node: others.add(node) + + channel = self.channel + if channel: others.add(channel) + return others + + def _configure_object(self): + # Set Mac + mac = self.get("mac") + if mac: + mac_uuid = self.simulator.create("Mac48Address", mac) + else: + mac_uuid = self.simulator.invoke("singleton::Mac48Address", "Allocate") + self.simulator.invoke(self.uuid, "SetAddress", mac_uuid) + + # Set IP address + ip = self.get("ip") + prefix = self.get("prefix") + + i = ipaddr.IPAddress(ip) + if i.version == 4: + # IPv4 + ipv4 = self.node.ipv4 + ifindex_uuid = self.simulator.invoke(ipv4.uuid, "AddInterface", + self.uuid) + ipv4_addr_uuid = self.simulator.create("Ipv4Address", ip) + ipv4_mask_uuid = self.simulator.create("Ipv4Mask", "/%s" % str(prefix)) + inaddr_uuid = self.simulator.create("Ipv4InterfaceAddress", + ipv4_addr_uuid, ipv4_mask_uuid) + self.simulator.invoke(ipv4.uuid, "AddAddress", ifindex_uuid, + inaddr_uuid) + self.simulator.invoke(ipv4.uuid, "SetMetric", ifindex_uuid, 1) + self.simulator.invoke(ipv4.uuid, "SetUp", ifindex_uuid) + else: + # IPv6 + # TODO! + pass + + def _connect_object(self): + node = self.node + if node and node.uuid not in self.connected: + self.simulator.invoke(node.uuid, "AddDevice", self.uuid) + self._connected.add(node.uuid) + + channel = self.channel + if channel and channel.uuid not in self.connected: + self.simulator.invoke(self.uuid, "Attach", channel.uuid) + self._connected.add(channel.uuid) + diff --git a/src/nepi/resources/ns3/ns3node.py b/src/nepi/resources/ns3/ns3node.py index 0e78bb09..7d0380ca 100644 --- a/src/nepi/resources/ns3/ns3node.py +++ b/src/nepi/resources/ns3/ns3node.py @@ -21,8 +21,15 @@ from nepi.execution.resource import clsinit_copy from nepi.resources.ns3.ns3base import NS3Base @clsinit_copy -class NS3BaseNode(Ns3Base): - _rtype = "ns3::Node" +class NS3BaseNode(NS3Base): + _rtype = "abstract::ns3::Node" + + @property + def ipv4(self): + from nepi.resources.ns3.ns3ipv4l3protocol import NS3BaseIpv4L3Protocol + ipv4s = self.get_connected(NS3BaseIpv4L3Protocol.get_rtype()) + if ipv4s: return ipv4s[0] + return None @property def others_to_wait(self): diff --git a/src/nepi/resources/ns3/ns3delay.py b/src/nepi/resources/ns3/ns3propagationdelaymodel.py similarity index 97% rename from src/nepi/resources/ns3/ns3delay.py rename to src/nepi/resources/ns3/ns3propagationdelaymodel.py index e72c974e..58842b70 100644 --- a/src/nepi/resources/ns3/ns3delay.py +++ b/src/nepi/resources/ns3/ns3propagationdelaymodel.py @@ -23,7 +23,7 @@ from nepi.resources.ns3.ns3channel import NS3BaseChannel @clsinit_copy class NS3BasePropagationDelayModel(NS3Base): - _rtype = "ns3::PropagationDelayModel" + _rtype = "abstract::ns3::PropagationDelayModel" @property def simulator(self): diff --git a/src/nepi/resources/ns3/ns3loss.py b/src/nepi/resources/ns3/ns3propagationlossmodel.py similarity index 100% rename from src/nepi/resources/ns3/ns3loss.py rename to src/nepi/resources/ns3/ns3propagationlossmodel.py diff --git a/src/nepi/resources/ns3/ns3queue.py b/src/nepi/resources/ns3/ns3queue.py index 4a2b66bb..55ed57f4 100644 --- a/src/nepi/resources/ns3/ns3queue.py +++ b/src/nepi/resources/ns3/ns3queue.py @@ -19,14 +19,14 @@ from nepi.execution.resource import clsinit_copy from nepi.resources.ns3.ns3base import NS3Base -from nepi.resources.ns3.ns3device import NS3BaseNetDevice @clsinit_copy class NS3BaseQueue(NS3Base): - _rtype = "ns3::Queue" + _rtype = "abstract::ns3::Queue" @property def device(self): + from nepi.resources.ns3.ns3device import NS3BaseNetDevice devices = self.get_connected(NS3BaseNetDevice.get_rtype()) if devices: return devices[0] return None diff --git a/src/nepi/resources/ns3/ns3wifimac.py b/src/nepi/resources/ns3/ns3wifimac.py new file mode 100644 index 00000000..6cc4c166 --- /dev/null +++ b/src/nepi/resources/ns3/ns3wifimac.py @@ -0,0 +1,46 @@ +# +# NEPI, a framework to manage network experiments +# Copyright (C) 2014 INRIA +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Author: Alina Quereilhac + +from nepi.execution.resource import clsinit_copy +from nepi.resources.ns3.ns3base import NS3Base + +@clsinit_copy +class NS3BaseWifiMac(NS3Base): + _rtype = "abstract::ns3::WifiMac" + + @property + def device(self): + from nepi.resources.ns3.ns3device import NS3BaseNetDevice + devices = self.get_connected(NS3BaseNetDevice.get_rtype()) + if devices: return devices[0] + return None + + @property + def others_to_wait(self): + others = set() + device = self.device + if device: others.add(device) + return others + + def _connect_object(self): + device = self.device + if device and device.uuid not in self.connected: + self.simulator.invoke(device.uuid, "SetMac", self.uuid) + self._connected.add(device.uuid) + diff --git a/src/nepi/resources/ns3/ns3device.py b/src/nepi/resources/ns3/ns3wifiphy.py similarity index 58% rename from src/nepi/resources/ns3/ns3device.py rename to src/nepi/resources/ns3/ns3wifiphy.py index 98d72022..a1f01b74 100644 --- a/src/nepi/resources/ns3/ns3device.py +++ b/src/nepi/resources/ns3/ns3wifiphy.py @@ -19,36 +19,33 @@ from nepi.execution.resource import clsinit_copy from nepi.resources.ns3.ns3base import NS3Base -from nepi.resources.ns3.ns3channel import NS3Channel @clsinit_copy -class NS3BaseNetDevice(NS3Base): - _rtype = "ns3::NetDevice" +class NS3BaseWifiPhy(NS3Base): + _rtype = "abstract::ns3::WifiPhy" @property - def channel(self): - channels = self.get_connected(NS3BaseChannel.get_rtype()) - if channels: return channels[0] + def device(self): + from nepi.resources.ns3.ns3device import NS3BaseNetDevice + devices = self.get_connected(NS3BaseNetDevice.get_rtype()) + if devices: return devices[0] return None @property def others_to_wait(self): others = set() - node = self.node - if node: others.add(node) - - channel = self.channel - if channel: others.add(channel) + device = self.device + if device: others.add(device) return others def _connect_object(self): - node = self.node - if node and node.uuid not in self.connected: - self.simulator.invoke(node.uuid, "AddDevice", self.uuid) - self._connected.add(node.uuid) + device = self.device + if device and device.uuid not in self.connected: + self.simulator.invoke(device.uuid, "SetPhy", self.uuid) + self.simulator.invoke(self.uuid, "SetDevice", device.uuid) + self._connected.add(device.uuid) - channel = self.channel - if channel and channel.uuid not in self.connected: - self.simulator.invoke(self.uuid, "Attach", channel.uuid) - self._connected.add(channel.uuid) + node = device.node + if node: + self.simulator.invoke(self.uuid, "SetMobility", node.uuid) diff --git a/src/nepi/resources/ns3/ns3manager.py b/src/nepi/resources/ns3/ns3wifiremotestationmanager.py similarity index 89% rename from src/nepi/resources/ns3/ns3manager.py rename to src/nepi/resources/ns3/ns3wifiremotestationmanager.py index f5c8c015..480250d1 100644 --- a/src/nepi/resources/ns3/ns3manager.py +++ b/src/nepi/resources/ns3/ns3wifiremotestationmanager.py @@ -19,15 +19,15 @@ from nepi.execution.resource import clsinit_copy from nepi.resources.ns3.ns3base import NS3Base -from nepi.resources.ns3.ns3device import NS3BaseDevice +from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice @clsinit_copy class NS3BaseWifiRemoteStationManager(NS3Base): - _rtype = "ns3::WifiRemoteStationManager" + _rtype = "abstract::ns3::WifiRemoteStationManager" @property def device(self): - devices = self.get_connected(NS3BaseDevice.get_rtype()) + devices = self.get_connected(NS3BaseNetDevice.get_rtype()) if devices: return devices[0] return None diff --git a/src/nepi/resources/ns3/resource_manager_generator.py b/src/nepi/resources/ns3/resource_manager_generator.py index 4042bf87..e8ff1a73 100644 --- a/src/nepi/resources/ns3/resource_manager_generator.py +++ b/src/nepi/resources/ns3/resource_manager_generator.py @@ -24,48 +24,44 @@ import os import re def select_base_class(ns3, tid): + base_class_import = base_class = None + rtype = tid.GetName() - type_id = ns3.TypeId() - appbase = type_id.LookupByName("ns3::Application") - devicebase = type_id.LookupByName("ns3::NetDevice") - channelbase = type_id.LookupByName("ns3::Channel") - queuebase = type_id.LookupByName("ns3::Queue") - lossbase = type_id.LookupByName("ns3::PropagationLossModel") - delaybase = type_id.LookupByName("ns3::PropagationDelayModel") - managerbase = type_id.LookupByName("ns3::WifiRemoteStationManager") - - if tid.IsChiledOf(appbase): - base_class_import = "from nepi.resources.ns3.ns3application import NS3BaseApplication" - base_class = "NS3BaseApplication" - elif tid.IsChiledOf(devicebase): - base_class_import = "from nepi.resources.ns3.ns3device import NS3BaseNetDevice" - base_class = "NS3BaseNetDevice" - elif tid.IsChiledOf(channelbase): - base_class_import = "from nepi.resources.ns3.ns3channel import NS3BaseChannel" - base_class = "NS3BaseChannel" - elif tid.IsChiledOf(queuebase): - base_class_import = "from nepi.resources.ns3.ns3queue import NS3BaseQueue" - base_class = "NS3BaseQueue" - elif tid.IsChiledOf(lossbase): - base_class_import = "from nepi.resources.ns3.ns3loss import NS3BasePropagationLossModel" - base_class = "NS3BasePropagationLossDelay" - elif tid.IsChiledOf(delaybase): - base_class_import = "from nepi.resources.ns3.ns3delay import NS3BasePropagationDelayModel" - base_class = "NS3BasePropagationDelayModel" - elif tid.IsChiledOf(managerbase): - base_class_import = "from nepi.resources.ns3.ns3manager import NS3BaseWifiRemoteStationManager" - base_class = "NS3BaseWifiRemoteStationManager" - elif rtype == "ns3::Node": + 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 NS3BaseIpV4Protocol" - base_class = "NS3BaseIpV4Protocol" + base_class_import = "from nepi.resources.ns3.ns3ipv4protocol 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", + "ns3::NetDevice", + "ns3::Channel", + "ns3::Queue", + "ns3::PropagationLossModel", + "ns3::PropagationDelayModel", + "ns3::WifiRemoteStationManager", + "ns3::WifiPhy", + "ns3::WifiMac", + "ns3::ErrorModel", + "ns3::ErrorRateModel"] + + for base in bases: + tid_base = type_id.LookupByName(base) + 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_module, base_class) + return (base_class_import, base_class) def create_ns3_rms(): @@ -123,11 +119,11 @@ def create_ns3_rms(): replace('::', ''). \ replace("-","_").lower() + ".py" - #f = open(os.path.join(d, "classes", fname), "w") - #print os.path.join(d, fname) - #print template - #f.write(template) - #f.close() + f = open(os.path.join(d, "classes", fname), "w") + print os.path.join(d, fname) + print template + f.write(template) + f.close() def template_attributes(ns3, tid): d = os.path.dirname(os.path.realpath(__file__)) -- 2.43.0