Adding CCNPoke
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Thu, 29 May 2014 11:06:50 +0000 (13:06 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Thu, 29 May 2014 11:06:50 +0000 (13:06 +0200)
src/nepi/resources/linux/ns3/ccn/__init__.py [new file with mode: 0644]
src/nepi/resources/linux/ns3/ccn/ns3ccndceapplication.py
src/nepi/resources/linux/ns3/ccn/ns3ccnpokedceapplication.py [new file with mode: 0644]
src/nepi/resources/ns3/ns3ccndceapplication.py
test/resources/linux/ns3/ccn/ns3dceccn.py
test/resources/linux/ns3/ccn/ns3dceccnpeek.py [new file with mode: 0644]

diff --git a/src/nepi/resources/linux/ns3/ccn/__init__.py b/src/nepi/resources/linux/ns3/ccn/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index f7b10a4..ef3e8a7 100644 (file)
@@ -101,15 +101,6 @@ class LinuxNS3CCNDceApplication(NS3BaseCCNDceApplication):
             if fcmd:
                 command.append(fcmd)
 
-        # Upload CCN files (e.g. repo)
-        stdin_file = self.get("stdinFile")
-        if stdin_file:
-            stdincmd = self.simulation.upload_extra_sources(sources = stdin_file, 
-                    src_dir = self.simulation.app_home)
-
-            if stdincmd:
-                command.append(stdincmd)
-
         if command:
             deploy_command = ";".join(command)
             prefix = "%d_deploy" % self.guid 
diff --git a/src/nepi/resources/linux/ns3/ccn/ns3ccnpokedceapplication.py b/src/nepi/resources/linux/ns3/ccn/ns3ccnpokedceapplication.py
new file mode 100644 (file)
index 0000000..40a83a6
--- /dev/null
@@ -0,0 +1,65 @@
+#
+#    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 <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+
+from nepi.execution.attribute import Attribute, Flags, Types
+from nepi.execution.resource import clsinit_copy, ResourceState, \
+        reschedule_delay
+from nepi.resources.linux.ns3.ccn.ns3ccndceapplication \
+        import LinuxNS3CCNDceApplication
+
+import os
+import tempfile
+
+@clsinit_copy
+class LinuxNS3DceCCNPoke(LinuxNS3CCNDceApplication):
+    _rtype = "ns3::LinuxDceCCNPoke"
+
+    @classmethod
+    def _register_attributes(cls):
+        content_name = Attribute("contentName",
+                "Content name for the requested content object. ",
+                flags = Flags.Design)
+        content = Attribute("content",
+                "Content to poke (as a text string). ",
+                flags = Flags.Design)
+
+        cls._register_attribute(content_name)
+        cls._register_attribute(content)
+
+    def _instantiate_object(self):
+        if not self.get("binary"):
+            self.set("binary", "ccnpoke")
+            
+        if self.get("contentName"):
+            self.set("arguments", self.get("contentName"))
+
+        # Create temporary local file to store content
+        content = self.get("content")
+        f = tempfile.NamedTemporaryFile(delete=False)
+        f.write(content)
+        f.close()
+
+        localpath = f.name
+        dcepath = os.path.join("/tmp", os.path.basename(localpath))
+
+        self.set("files", "%s=%s" % (localpath, dcepath))
+        self.set("stdinFile", dcepath)
+
+        super(LinuxNS3DceCCNPoke, self)._instantiate_object()
+
index bbf5832..4d199c9 100644 (file)
@@ -96,10 +96,6 @@ class NS3BaseCCNDceApplication(NS3BaseDceApplication):
                     if stdinfile:
                         # stdinfile might be an empty text that should be set as
                         # stdin
-                        if stdinfile != "":
-                            stdinfile = os.path.join(self.simulation.app_home, 
-                                os.path.basename(stdinfile))
-       
                         self.simulation.invoke(
                                 self.ccn_client_helper_uuid, 
                                 "SetStdinFile", stdinfile)
index 63b7400..a96d653 100644 (file)
@@ -60,7 +60,7 @@ def add_point2point_device(ec, node, address = None,  prefix = None):
 
     return dev
 
-class LinuxNS3PingDceApplicationTest(unittest.TestCase):
+class LinuxNS3CCNDceApplicationTest(unittest.TestCase):
     def setUp(self):
         #self.fedora_host = "nepi2.pl.sophia.inria.fr"
         #self.fedora_host = "planetlabpc1.upf.edu"
@@ -71,7 +71,7 @@ class LinuxNS3PingDceApplicationTest(unittest.TestCase):
         self.fedora_identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
 
     def test_dce_ccn(self):
-        ec = ExperimentController(exp_id = "test-dceccn")
+        ec = ExperimentController(exp_id = "test-dce-ccn")
         
         node = ec.register_resource("LinuxNode")
         ec.set(node, "hostname", self.fedora_host)
diff --git a/test/resources/linux/ns3/ccn/ns3dceccnpeek.py b/test/resources/linux/ns3/ccn/ns3dceccnpeek.py
new file mode 100644 (file)
index 0000000..8307883
--- /dev/null
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+#
+#    NEPI, a framework to manage network experiments
+#    Copyright (C) 2013 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 <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+
+
+from nepi.execution.ec import ExperimentController 
+from nepi.execution.trace import TraceAttr
+
+import os
+import time
+import unittest
+
+def add_ns3_node(ec, simu):
+    node = ec.register_resource("ns3::Node")
+    ec.register_connection(node, simu)
+
+    ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
+    ec.register_connection(node, ipv4)
+    
+    arp = ec.register_resource("ns3::ArpL3Protocol")
+    ec.register_connection(node, arp)
+    
+    icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
+    ec.register_connection(node, icmp)
+
+    udp = ec.register_resource("ns3::UdpL4Protocol")
+    ec.register_connection(node, udp)
+
+    tcp = ec.register_resource("ns3::TcpL4Protocol")
+    ec.register_connection(node, tcp)
+
+    return node
+
+class LinuxNS3CCNPeekDceApplicationTest(unittest.TestCase):
+    def setUp(self):
+        #self.fedora_host = "nepi2.pl.sophia.inria.fr"
+        #self.fedora_host = "planetlabpc1.upf.edu"
+        #self.fedora_user = "inria_nepi"
+        #self.fedora_identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
+        self.fedora_host = "mimas.inria.fr"
+        self.fedora_user = "aquereil"
+        self.fedora_identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
+
+    def test_dce_ccn(self):
+        ec = ExperimentController(exp_id = "test-dce-ccnpeek")
+        
+        node = ec.register_resource("LinuxNode")
+        ec.set(node, "hostname", self.fedora_host)
+        ec.set(node, "username", self.fedora_user)
+        ec.set(node, "identity", self.fedora_identity)
+        #ec.set(node, "cleanProcesses", True)
+        #ec.set(node, "cleanHome", True)
+
+        simu = ec.register_resource("LinuxNS3Simulation")
+        ec.set(simu, "verbose", True)
+        ec.set(simu, "enableDCE", True)
+        ec.set(simu, "buildMode", "debug")
+        ec.set(simu, "nsLog", "DceApplication")
+        ec.register_connection(simu, node)
+
+        nsnode = add_ns3_node(ec, simu)
+
+        ### create applications
+        ccnd = ec.register_resource("ns3::LinuxDceCCND")
+        ec.set (ccnd, "stackSize", 1<<20)
+        ec.set (ccnd, "StartTime", "1s")
+        ec.register_connection(ccnd, nsnode)
+
+        ccnpoke = ec.register_resource("ns3::LinuxDceCCNPoke")
+        ec.set (ccnpoke, "contentName", "ccnx:/chunk0")
+        ec.set (ccnpoke, "content", "DATA")
+        ec.set (ccnpoke, "stackSize", 1<<20)
+        ec.set (ccnpoke, "StartTime", "2s")
+        ec.register_connection(ccnpoke, nsnode)
+
+        ccnpeek = ec.register_resource("ns3::LinuxDceCCNPeek")
+        ec.set (ccnpeek, "contentName", "ccnx:/chunk0")
+        ec.set (ccnpeek, "stackSize", 1<<20)
+        ec.set (ccnpeek, "StartTime", "4s")
+        ec.set (ccnpeek, "StopTime", "20s")
+        ec.register_connection(ccnpeek, nsnode)
+
+        ec.deploy()
+
+        ec.wait_finished([ccnpeek])
+
+        expected = "ccnpeek ccnx:/chunk0"
+        cmdline = ec.trace(ccnpeek, "cmdline")
+        self.assertTrue(cmdline.find(expected) > -1, cmdline)
+
+        expected = "Start Time: NS3 Time:          4s ("
+        status = ec.trace(ccnpeek, "status")
+        self.assertTrue(status.find(expected) > -1, status)
+
+        expected = "DATA"
+        stdout = ec.trace(ccnpeek, "stdout")
+        self.assertTrue(stdout.find(expected) > -1, stdout)
+
+        ec.shutdown()
+
+if __name__ == '__main__':
+    unittest.main()