From c7aa07353fb951c845b82ff33e88bbe6f9bfced8 Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Sat, 19 Jul 2014 23:46:45 +0200 Subject: [PATCH] Adding synthetic network stack to ns-3 node RM --- src/nepi/resources/ns3/ns3node.py | 34 +++++++---- src/nepi/resources/ns3/ns3wrapper.py | 69 ++++++++++++++-------- src/nepi/resources/ns3/ns3wrapper_debug.py | 13 ---- 3 files changed, 69 insertions(+), 47 deletions(-) diff --git a/src/nepi/resources/ns3/ns3node.py b/src/nepi/resources/ns3/ns3node.py index aadcf40b..48a7c16d 100644 --- a/src/nepi/resources/ns3/ns3node.py +++ b/src/nepi/resources/ns3/ns3node.py @@ -111,6 +111,17 @@ class NS3BaseNode(NS3Base): if self.get("enableStack"): uuid_stack_helper = self.simulation.create("InternetStackHelper") self.simulation.invoke(uuid_stack_helper, "Install", self.uuid) + + # Retrieve IPV4 object + ipv4_uuid = self.simulation.invoke(self.uuid, "retrieveObject", + "ns3::Ipv4L3Protocol") + + # Add IPv4 RM to the node + ipv4 = self.ec.register_resource("ns3::Ipv4L3Protocol") + self.ec.register_connection(self.guid, ipv4) + ipv4rm = self.ec.get_resource(ipv4) + ipv4rm._uuid = ipv4_uuid + ipv4rm.set_started() else: ### node.AggregateObject(PacketSocketFactory()) uuid_packet_socket_factory = self.simulation.create("PacketSocketFactory") @@ -121,17 +132,18 @@ class NS3BaseNode(NS3Base): self._add_dce(dceapplications) def _connect_object(self): - ipv4 = self.ipv4 - if ipv4: - self.simulation.invoke(self.uuid, "AggregateObject", ipv4.uuid) - self._connected.add(ipv4.uuid) - ipv4._connected.add(self.uuid) - - arp = self.arp - if arp: - self.simulation.invoke(self.uuid, "AggregateObject", arp.uuid) - self._connected.add(arp.uuid) - arp._connected.add(self.uuid) + if not self.get("enableStack"): + ipv4 = self.ipv4 + if ipv4: + self.simulation.invoke(self.uuid, "AggregateObject", ipv4.uuid) + self._connected.add(ipv4.uuid) + ipv4._connected.add(self.uuid) + + arp = self.arp + if arp: + self.simulation.invoke(self.uuid, "AggregateObject", arp.uuid) + self._connected.add(arp.uuid) + arp._connected.add(self.uuid) mobility = self.mobility if mobility: diff --git a/src/nepi/resources/ns3/ns3wrapper.py b/src/nepi/resources/ns3/ns3wrapper.py index 3306b30d..eea32d06 100644 --- a/src/nepi/resources/ns3/ns3wrapper.py +++ b/src/nepi/resources/ns3/ns3wrapper.py @@ -268,12 +268,6 @@ class NS3Wrapper(object): result = self.is_finished elif operation == "isAppRunning": result = self._is_app_running(uuid) - elif operation == "addStaticRoute": - ### DEBUG - self.debuger.dump_add_static_route(uuid, args) - ######## - - result = self._add_static_route(uuid, *args) else: newuuid = self.make_uuid() @@ -281,27 +275,34 @@ class NS3Wrapper(object): self.debuger.dump_invoke(newuuid, uuid, operation, args, kwargs) ######## - if uuid.startswith(SINGLETON): - obj = self._singleton(uuid) + if operation == "addStaticRoute": + result = self._add_static_route(uuid, *args) + + elif operation == "retrieveObject": + result = self._retrieve_object(uuid, *args, **kwargs) + else: - obj = self.get_object(uuid) - - method = getattr(obj, operation) + if uuid.startswith(SINGLETON): + obj = self._singleton(uuid) + else: + obj = self.get_object(uuid) + + method = getattr(obj, operation) - # arguments starting with 'uuid' identify ns-3 C++ - # objects and must be replaced by the actual object - realargs = self.replace_args(args) - realkwargs = self.replace_kwargs(kwargs) + # arguments starting with 'uuid' identify ns-3 C++ + # objects and must be replaced by the actual object + realargs = self.replace_args(args) + realkwargs = self.replace_kwargs(kwargs) - result = method(*realargs, **realkwargs) + result = method(*realargs, **realkwargs) - # If the result is an object (not a base value), - # then keep track of the object a return the object - # reference (newuuid) - if not (result is None or type(result) in [ - bool, float, long, str, int]): - self._objects[newuuid] = result - result = newuuid + # If the result is an object (not a base value), + # then keep track of the object a return the object + # reference (newuuid) + if not (result is None or type(result) in [ + bool, float, long, str, int]): + self._objects[newuuid] = result + result = newuuid ### DEBUG self.logger.debug("RET INVOKE %s%s = %s -> %s(%s, %s) " % ( @@ -632,3 +633,25 @@ class NS3Wrapper(object): return ifindex return ifindex + def _retrieve_object(self, uuid, typeid, search = False): + obj = self.get_object(uuid) + + type_id = self.ns3.TypeId() + tid = type_id.LookupByName(typeid) + nobj = obj.GetObject(tid) + + newuuid = None + if search: + # search object + for ouuid, oobj in self._objects.iteritems(): + if nobj == oobj: + newuuid = ouuid + break + else: + newuuid = self.make_uuid() + self._objects[newuuid] = nobj + + return newuuid + + + diff --git a/src/nepi/resources/ns3/ns3wrapper_debug.py b/src/nepi/resources/ns3/ns3wrapper_debug.py index 99a6e5bb..ff8d0de8 100644 --- a/src/nepi/resources/ns3/ns3wrapper_debug.py +++ b/src/nepi/resources/ns3/ns3wrapper_debug.py @@ -160,19 +160,6 @@ wrapper = NS3Wrapper() command = "wrapper.shutdown()\n\n" self.dump_to_script(command) - def dump_add_static_route(self, uuid, args): - if not self.enabled: - return - - command = ("args = %(args)s\n" - "wrapper._add_static_route(%(uuid)s, *args)\n\n" - ) % dict({ - "uuid": self.format_value(uuid), - "args": self.format_args(args), - }) - - self.dump_to_script(command) - def format_value(self, value): if isinstance(value, str) and value.startswith("uuid"): return value.replace("-", "") -- 2.47.0