From: Alina Quereilhac Date: Sat, 19 Apr 2014 09:55:35 +0000 (+0200) Subject: ns-3 CCN tests X-Git-Tag: nepi-3.1.0~85 X-Git-Url: http://git.onelab.eu/?p=nepi.git;a=commitdiff_plain;h=df7b32bd237adac72e5c956911720ab52567bb9b ns-3 CCN tests --- diff --git a/src/nepi/execution/ec.py b/src/nepi/execution/ec.py index 44b95780..1d337e88 100644 --- a/src/nepi/execution/ec.py +++ b/src/nepi/execution/ec.py @@ -696,6 +696,41 @@ class ExperimentController(object): rm = self.get_resource(guid) return rm.start() + def get_start_time(self, guid): + """ Returns the start time of the RM as a timestamp """ + rm = self.get_resource(guid) + return rm.start_time + + def get_stop_time(self, guid): + """ Returns the stop time of the RM as a timestamp """ + rm = self.get_resource(guid) + return rm.stop_time + + def get_discover_time(self, guid): + """ Returns the discover time of the RM as a timestamp """ + rm = self.get_resource(guid) + return rm.discover_time + + def get_provision_time(self, guid): + """ Returns the provision time of the RM as a timestamp """ + rm = self.get_resource(guid) + return rm.provision_time + + def get_ready_time(self, guid): + """ Returns the deployment time of the RM as a timestamp """ + rm = self.get_resource(guid) + return rm.ready_time + + def get_release_time(self, guid): + """ Returns the release time of the RM as a timestamp """ + rm = self.get_resource(guid) + return rm.release_time + + def get_failed_time(self, guid): + """ Returns the time failure occured for the RM as a timestamp """ + rm = self.get_resource(guid) + return rm.failed_time + def set_with_conditions(self, name, value, guids1, guids2, state, time = None): """ Modifies the value of attribute with name 'name' on all RMs diff --git a/src/nepi/execution/resource.py b/src/nepi/execution/resource.py index d32a3dd9..c56aa5bf 100644 --- a/src/nepi/execution/resource.py +++ b/src/nepi/execution/resource.py @@ -614,6 +614,14 @@ class ResourceManager(Logger): attr = self._attrs[name] return attr.has_flag(flag) + def has_attribute(self, name): + """ Returns true if the RM has an attribute with name + + :param name: name of the attribute + :type name: string + """ + return name in self._attrs + def enable_trace(self, name): """ Explicitly enable trace generation diff --git a/src/nepi/resources/linux/application.py b/src/nepi/resources/linux/application.py index 4a90392c..9da05af7 100644 --- a/src/nepi/resources/linux/application.py +++ b/src/nepi/resources/linux/application.py @@ -107,19 +107,19 @@ class LinuxApplication(ResourceManager): "cleanHome is set to True (This will delete all sources). ", flags = Flags.Design) files = Attribute("files", - "Space-separated list of regular miscellaneous files to be uploaded " + "semi-colon separated list of regular miscellaneous files to be uploaded " "to ${SHARE} directory. " "Files are globally available for all experiments unless " "cleanHome is set to True (This will delete all files). ", flags = Flags.Design) libs = Attribute("libs", - "Space-separated list of libraries (e.g. .so files) to be uploaded " + "semi-colon separated list of libraries (e.g. .so files) to be uploaded " "to ${LIB} directory. " "Libraries are globally available for all experiments unless " "cleanHome is set to True (This will delete all files). ", flags = Flags.Design) bins = Attribute("bins", - "Space-separated list of binary files to be uploaded " + "semi-colon separated list of binary files to be uploaded " "to ${BIN} directory. " "Binaries are globally available for all experiments unless " "cleanHome is set to True (This will delete all files). ", diff --git a/src/nepi/resources/linux/ns3/ns3dceapplication.py b/src/nepi/resources/linux/ns3/ns3dceapplication.py index bf1a6e36..ca32b6f9 100644 --- a/src/nepi/resources/linux/ns3/ns3dceapplication.py +++ b/src/nepi/resources/linux/ns3/ns3dceapplication.py @@ -41,12 +41,26 @@ class NS3LinuxDceApplication(NS3BaseDceApplication): "binaries to the ${BIN_DCE} directory. ", flags = Flags.Design) + depends = Attribute("depends", + "Space-separated list of packages required to run the application", + flags = Flags.Design) + + files = Attribute("files", + "Semi-colon separated list of 'key=value' pairs to set as " + "DCE files (AddFile). The key should be a path to a local file " + "and the key is the path to be set in DCE for that file" , + flags = Flags.Design) + + stdinfile = Attribute("stdinFile", + "File to set as StdinFile. The value shoudl be either an empty " + "or a path to a local file ", + flags = Flags.Design) + starttime = Attribute("StartTime", "Time at which the application will start", default = "+0.0ns", flags = Flags.Reserved | Flags.Construct) - stoptime = Attribute("StopTime", "Time at which the application will stop", default = "+0.0ns", @@ -54,19 +68,53 @@ class NS3LinuxDceApplication(NS3BaseDceApplication): cls._register_attribute(sources) cls._register_attribute(build) + cls._register_attribute(depends) + cls._register_attribute(files) cls._register_attribute(stoptime) cls._register_attribute(starttime) + cls._register_attribute(stdinfile) def _instantiate_object(self): command = [] - + + # Install package dependencies required to run the binary + depends = self.get("depends") + if depends: + dcmd = self.simulation.install_dependencies(depends = depends) + if dcmd: + command.append(dcmd) + + # Upload sources to generate the binary sources = self.get("sources") if sources: - self.info("Uploading sources %s " % sources) scmd = self.simulation.upload_extra_sources(sources = sources) if scmd: command.append(scmd) + # Upload files to the remote machine. These files will + # be added to the DceApplication by invoking dce.AddFile() + files = self.get("files") or "" + if files: + upfiles = [] + for files in map(str.strip, files.split(";")): + localpath, dcepath = env.split("=") + upfiles.append(localpath) + + if upfiles: + fcmd = self.siumlation.upload_files(files = upfiles) + if fcmd: + command.append(fcmd) + + # Upload files to the remote machine. These files will + # be added to the DceApplication by invoking dce.AddFile() + stdinfile = self.get("stdinFile") + if stdinfile and stdinfile != "": + stdincmd = self.siumlation.upload_files(files = stdinfile) + if stdincmd: + command.append(stdincmd) + + + # Upload instructions to build the binary build = self.get("build") if build: bcmd = self.simulation.build(build = build) diff --git a/src/nepi/resources/ns3/ns3dceapplication.py b/src/nepi/resources/ns3/ns3dceapplication.py index b2dc4652..acaf0e6e 100644 --- a/src/nepi/resources/ns3/ns3dceapplication.py +++ b/src/nepi/resources/ns3/ns3dceapplication.py @@ -21,6 +21,8 @@ from nepi.execution.attribute import Attribute, Flags, Types from nepi.execution.resource import clsinit_copy, ResourceState, reschedule_delay from nepi.resources.ns3.ns3application import NS3BaseApplication +import os + @clsinit_copy class NS3BaseDceApplication(NS3BaseApplication): _rtype = "abstract::ns3::DceApplication" @@ -41,9 +43,15 @@ class NS3BaseDceApplication(NS3BaseApplication): "Semi-colon separated list of arguments for the application", flags = Flags.Design) + environment = Attribute("environment", + "Semi-colon separated list of 'key=value' pairs to set as " + "DCE environment variables.", + flags = Flags.Design) + cls._register_attribute(binary) cls._register_attribute(stack_size) cls._register_attribute(arguments) + cls._register_attribute(environment) @property def node(self): @@ -71,21 +79,56 @@ class NS3BaseDceApplication(NS3BaseApplication): # Preventing concurrent access to the DceApplicationHelper # from different DceApplication RMs with self.simulation.dce_application_lock: - self.simulation.invoke(self.simulation.dce_application_helper_uuid, + self.simulation.invoke( + self.simulation.dce_application_helper_uuid, "ResetArguments") - self.simulation.invoke(self.simulation.dce_application_helper_uuid, + self.simulation.invoke( + self.simulation.dce_application_helper_uuid, + "ResetEnvironment") + + self.simulation.invoke( + self.simulation.dce_application_helper_uuid, "SetBinary", self.get("binary")) - self.simulation.invoke(self.simulation.dce_application_helper_uuid, + self.simulation.invoke( + self.simulation.dce_application_helper_uuid, "SetStackSize", self.get("stackSize")) arguments = self.get("arguments") or "" for arg in map(str.strip, arguments.split(";")): - self.simulation.invoke(self.simulation.dce_application_helper_uuid, - "AddArgument", arg) - - apps_uuid = self.simulation.invoke(self.simulation.dce_application_helper_uuid, + self.simulation.invoke( + self.simulation.dce_application_helper_uuid, + "AddArgument", arg) + + environment = self.get("environment") or "" + for env in map(str.strip, environment.split(";")): + key, val = env.split("=") + self.simulation.invoke( + self.simulation.dce_application_helper_uuid, + "AddEnvironment", key, val) + + if self.has_attribute("files"): + files = self.get("files") or "" + for files in map(str.strip, files.split(";")): + remotepath, dcepath = env.split("=") + localpath = "${SHARE}/" + os.path.basename(remotepath) + self.simulation.invoke( + self.simulation.dce_application_helper_uuid, + "AddFile", localpath, dcepath) + + if self.has_attribute("stdinFile"): + stdinfile = self.get("stdinFile") + if stdinfile: + if stdinfile != "": + stdinfile = "${SHARE}/" + os.path.basename(stdinfile) + + self.simulation.invoke( + self.simulation.dce_application_helper_uuid, + "SetStdinFile", stdinfile) + + apps_uuid = self.simulation.invoke( + self.simulation.dce_application_helper_uuid, "InstallInNode", self.node.uuid) self._uuid = self.simulation.invoke(apps_uuid, "Get", 0) diff --git a/test/resources/linux/ns3/ns3dceapplication.py b/test/resources/linux/ns3/ns3dceapplication.py index 21b046ea..a4901aee 100644 --- a/test/resources/linux/ns3/ns3dceapplication.py +++ b/test/resources/linux/ns3/ns3dceapplication.py @@ -133,15 +133,13 @@ def add_wifi_channel(ec): class LinuxNS3DceApplicationTest(unittest.TestCase): def setUp(self): - #elf.fedora_host = "nepi2.pl.sophia.inria.fr" - #self.fedora_host = "planetlabpc1.upf.edu" - self.fedora_host = "peeramide.irisa.fr" + #self.fedora_host = "nepi2.pl.sophia.inria.fr" + self.fedora_host = "planetlabpc1.upf.edu" self.fedora_user = "inria_nepi" - #self.fedora_user = "inria_alina" self.fedora_identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME']) - def test_dce_application(self): - ec = ExperimentController(exp_id = "test-linux-ns3-dce") + def test_dce_ping(self): + ec = ExperimentController(exp_id = "test-dce-ping") node = ec.register_resource("LinuxNode") ec.set(node, "hostname", self.fedora_host) @@ -176,14 +174,12 @@ class LinuxNS3DceApplicationTest(unittest.TestCase): ### create applications ping = ec.register_resource("ns3::LinuxDceApplication") - """ ec.set (ping, "sources", "http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2") ec.set (ping, "build", "tar xvjf ${SRC}/iputils-s20101006.tar.bz2 && " "cd iputils-s20101006/ && " "sed -i 's/CFLAGS=/CFLAGS+=/g' Makefile && " "make CFLAGS=-fPIC LDFLAGS=-pie ping && " "cp ping ${BIN_DCE} ") - """ ec.set (ping, "binary", "ping") ec.set (ping, "stackSize", 1<<20) ec.set (ping, "arguments", "-c 10;-s 1000;10.0.0.2") @@ -213,6 +209,162 @@ class LinuxNS3DceApplicationTest(unittest.TestCase): ec.shutdown() + def test_dce_ccn(self): + ec = ExperimentController(exp_id = "test-dce-ccn") + + 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) + + nsnode1 = add_ns3_node(ec, simu) + ec.set(nsnode1, "enableDCE", True) + p2p1 = add_point2point_device(ec, nsnode1, "10.0.0.1", "30") + ec.set(p2p1, "DataRate", "5Mbps") + + nsnode2 = add_ns3_node(ec, simu) + ec.set(nsnode2, "enableDCE", True) + p2p2 = add_point2point_device(ec, nsnode2, "10.0.0.2", "30") + ec.set(p2p2, "DataRate", "5Mbps") + + # Create channel + chan = ec.register_resource("ns3::PointToPointChannel") + ec.set(chan, "Delay", "2ms") + + ec.register_connection(chan, p2p1) + ec.register_connection(chan, p2p2) + + ### create applications + ccnd1 = ec.register_resource("ns3::LinuxDceApplication") + ec.set(ccnd1, "depends", "libpcap0.8-dev openjdk-6-jdk ant1.8 autoconf " + "libssl-dev libexpat-dev libpcap-dev libecryptfs0 libxml2-utils auto" + "make gawk gcc g++ git-core pkg-config libpcre3-dev openjdk-6-jre-lib") + ec.set (ccnd1, "sources", "http://www.ccnx.org/releases/ccnx-0.7.2.tar.gz") + ec.set (ccnd1, "build", "tar xvjf ${SRC}/iputils-s20101006.tar.bz2 && " + "tar zxf ${SRC}/ccnx-0.7.2.tar.gz && " + "cd ccnx-0.7.2 && " + " INSTALL_BASE=${BIN_DCE} ./configure && " + " make MORE_LDLIBS=-pie && " + " make install ") + ec.set (ccnd1, "binary", "ccndstart") + ec.set (ccnd1, "stackSize", 1<<20) + ec.set (ccnd1, "StartTime", "1s") + ec.set (ccnd1, "StopTime", "20s") + ec.register_connection(ccnd1, nsnode1) + + ccnkill1 = ec.register_resource("ns3::LinuxDceApplication") + ec.set (ccnkill1, "binary", "ccnsmoketest") + ec.set (ccnkill1, "arguments", "kill") + ec.set (ccnkill1, "stdinFile", "") + ec.set (ccnkill1, "stackSize", 1<<20) + ec.set (ccnkill1, "StartTime", "110s") + ec.set (ccnkill1, "StopTime", "120s") + ec.register_connection(ccnkill1, nsnode1) + + repofile = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "repoFile1") + + ccnr = ec.register_resource("ns3::LinuxDceApplication") + ec.set (ccnr, "binary", "ccnr") + ec.set (ccnr, "environment", "CCNR_DIRECTORY=/REPO/") + ec.set (ccnr, "files", "%s=/REPO/repoFile1" % repofile) + ec.set (ccnr, "stackSize", 1<<20) + ec.set (ccnr, "StartTime", "2s") + ec.set (ccnr, "StopTime", "120s") + ec.register_connection(ccnr, nsnode1) + + ccndc1 = ec.register_resource("ns3::LinuxDceApplication") + ec.set (ccndc1, "binary", "ccndc") + ec.set (ccndc1, "arguments", "-v;add;ccnx:/;udp;10.0.0.2") + ec.set (ccndc1, "stackSize", 1<<20) + ec.set (ccndc1, "StartTime", "2s") + ec.set (ccndc1, "StopTime", "120s") + ec.register_connection(ccndc1, nsnode1) + + ccnd2 = ec.register_resource("ns3::LinuxDceApplication") + ec.set (ccnd2, "binary", "ccndstart") + ec.set (ccnd2, "stackSize", 1<<20) + ec.set (ccnd2, "StartTime", "1s") + ec.set (ccnd2, "StopTime", "120s") + ec.register_connection(ccnd2, nsnode2) + + ccndc2 = ec.register_resource("ns3::LinuxDceApplication") + ec.set (ccndc2, "binary", "ccndc") + ec.set (ccndc2, "arguments", "-v;add;ccnx:/;udp;10.0.0.1") + ec.set (ccndc2, "stackSize", 1<<20) + ec.set (ccndc2, "StartTime", "2s") + ec.set (ccndc2, "StopTime", "120s") + ec.register_connection(ccndc2, nsnode2) + + ccnpeek = ec.register_resource("ns3::LinuxDceApplication") + ec.set (ccnpeek, "binary", "ccnpeek") + ec.set (ccnpeek, "arguments", "ccnx:/test/bunny.ts") + ec.set (ccnpeek, "stdinFile", "") + ec.set (ccnpeek, "stackSize", 1<<20) + ec.set (ccnpeek, "StartTime", "4s") + ec.set (ccnpeek, "StopTime", "120s") + ec.register_connection(ccnpeek, nsnode2) + + ccncat = ec.register_resource("ns3::LinuxDceApplication") + ec.set (ccncat, "binary", "ccncat") + ec.set (ccncat, "arguments", "ccnx:/test/bunny.ts") + ec.set (ccncat, "stdinFile", "") + ec.set (ccncat, "stackSize", 1<<20) + ec.set (ccncat, "StartTime", "4s") + ec.set (ccncat, "StopTime", "120s") + ec.register_connection(ccncat, nsnode2) + + ccnkill2 = ec.register_resource("ns3::LinuxDceApplication") + ec.set (ccnkill2, "binary", "ccnsmoketest") + ec.set (ccnkill2, "arguments", "kill") + ec.set (ccnkill2, "stdinFile", "") + ec.set (ccnkill2, "stackSize", 1<<20) + ec.set (ccnkill2, "StartTime", "110s") + ec.set (ccnkill2, "StopTime", "120s") + ec.register_connection(ccnkill2, nsnode2) + + ec.deploy() + + ec.wait_finished([ping]) + + print ec.trace(ccncat, "cmdline") + """ + expected = "ping -c 10 -s 1000 10.0.0.2" + cmdline = ec.trace(ping, "cmdline") + self.assertTrue(cmdline.find(expected) > -1, cmdline) + """ + + print ec.trace(cccat, "status") + """ + expected = "Start Time: NS3 Time: 1s (" + status = ec.trace(ping, "status") + self.assertTrue(status.find(expected) > -1, status) + """ + + print len(ec.trace(ccncat, "stdout")) + """ + expected = "10 packets transmitted, 10 received, 0% packet loss, time 9002ms" + stdout = ec.trace(ping, "stdout") + self.assertTrue(stdout.find(expected) > -1, stdout) + """ + + stderr = ec.trace(simu, "stderr") + expected = "DceApplication:StartApplication" + self.assertTrue(stderr.find(expected) > -1, stderr) + + ec.shutdown() + + if __name__ == '__main__': unittest.main() diff --git a/test/resources/linux/ns3/ns3simulation.py b/test/resources/linux/ns3/ns3simulation.py index cf4a7d95..81146856 100644 --- a/test/resources/linux/ns3/ns3simulation.py +++ b/test/resources/linux/ns3/ns3simulation.py @@ -132,11 +132,8 @@ def add_wifi_channel(ec): class LinuxNS3SimulationTest(unittest.TestCase): def setUp(self): - #elf.fedora_host = "nepi2.pl.sophia.inria.fr" - #self.fedora_host = "planetlabpc1.upf.edu" - self.fedora_host = "peeramide.irisa.fr" + self.fedora_host = "nepi2.pl.sophia.inria.fr" self.fedora_user = "inria_nepi" - #self.fedora_user = "inria_alina" self.fedora_identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME']) def test_local_p2p_ping(self): diff --git a/test/resources/linux/ns3/repoFile1 b/test/resources/linux/ns3/repoFile1 new file mode 100644 index 00000000..0899dbda Binary files /dev/null and b/test/resources/linux/ns3/repoFile1 differ