From 7e3f07daf215038b5472497aad558d23ed69ddec Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Tue, 27 May 2014 19:43:02 +0200 Subject: [PATCH] Added ns3::LinuxDcePing --- .../linux/ns3/ns3ccndceapplication.py | 117 ++++++++ .../linux/ns3/ns3pingdceapplication.py | 249 ++++++++++++++++++ test/resources/linux/ns3/ns3pingdce.py | 138 ++++++++++ 3 files changed, 504 insertions(+) create mode 100644 src/nepi/resources/linux/ns3/ns3ccndceapplication.py create mode 100644 src/nepi/resources/linux/ns3/ns3pingdceapplication.py create mode 100644 test/resources/linux/ns3/ns3pingdce.py diff --git a/src/nepi/resources/linux/ns3/ns3ccndceapplication.py b/src/nepi/resources/linux/ns3/ns3ccndceapplication.py new file mode 100644 index 00000000..f7b10a48 --- /dev/null +++ b/src/nepi/resources/linux/ns3/ns3ccndceapplication.py @@ -0,0 +1,117 @@ +# +# 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, Types +from nepi.execution.resource import clsinit_copy, ResourceState, reschedule_delay +from nepi.resources.ns3.ns3ccndceapplication import NS3BaseCCNDceApplication + +@clsinit_copy +class LinuxNS3CCNDceApplication(NS3BaseCCNDceApplication): + _rtype = "ns3::LinuxCCNDceApplication" + + @classmethod + def _register_attributes(cls): + sources = Attribute("sources", + "Path to tar.gz file with sources for the application execute in DCE. " + "Sources will be uploaded to ${SRC} and it is the responsibility of " + "the build instructions (in the build attribute) to copy the compiled " + "binaries to the ${BIN_DCE} directory", + flags = Flags.Design) + + build = Attribute("build", + "Instructions to compile sources DCE-compatible way. " + "Note that sources will be uploaded to ${SRC} and the " + "build instructions are responsible for copying the " + "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) + + cls._register_attribute(sources) + cls._register_attribute(build) + cls._register_attribute(depends) + cls._register_attribute(files) + 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: + scmd = self.simulation.upload_extra_sources(sources = sources) + if scmd: + command.append(scmd) + + # Upload instructions to build the binary + build = self.get("build") + if build: + bcmd = self.simulation.build(build = build) + if bcmd: + command.append(bcmd) + + # Upload CCN files (e.g. repo) + files = self.get("files") + if files: + upload = [] + for file in map(str.strip, files.split(";")): + localpath, dcepath = files.split("=") + upload.append(localpath) + + sources = ";".join(upload) + fcmd = self.simulation.upload_extra_sources(sources = sources, + src_dir = self.simulation.app_home) + + 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 + self.simulation.execute_deploy_command(deploy_command, prefix=prefix) + diff --git a/src/nepi/resources/linux/ns3/ns3pingdceapplication.py b/src/nepi/resources/linux/ns3/ns3pingdceapplication.py new file mode 100644 index 00000000..6534b1e7 --- /dev/null +++ b/src/nepi/resources/linux/ns3/ns3pingdceapplication.py @@ -0,0 +1,249 @@ +# +# 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, Types +from nepi.execution.resource import clsinit_copy, ResourceState, reschedule_delay +from nepi.resources.linux.ns3.ns3dceapplication import LinuxNS3DceApplication + +@clsinit_copy +class LinuxDcePing(LinuxNS3DceApplication): + _rtype = "ns3::LinuxDcePing" + + @classmethod + def _register_attributes(cls): + count = Attribute("count", + "Sets ping -c option. Determines the number of ECHO_REQUEST " + "packates to send before stopping.", + type = Types.Integer, + flags = Flags.Design) + + mark = Attribute("mark", + "Sets ping -m option. Uses 'mark' to tag outgoing packets. ", + flags = Flags.Design) + + interval = Attribute("interval", + "Sets ping -i option. Leaves interval seconds between " + "successive ECHO_REUQEST packets. ", + flags = Flags.Design) + + address = Attribute("address", + "Sets ping -I option. Sets ECHO_REQUEST packets souce address " + "to the specified interface address ", + flags = Flags.Design) + + preload = Attribute("preload", + "Sets ping -l option. Sends preload amount of packets " + "without waiting for a reply ", + flags = Flags.Design) + + numeric = Attribute("numeric", + "Sets ping -n option. Disables resolution of host addresses into " + "symbolic names. ", + type = Types.Bool, + default = False, + flags = Flags.Design) + + pattern = Attribute("pattern", + "Sets ping -p option. Species a up to 16 ''pad'' bytes to fill " + "out sent packets. ", + flags = Flags.Design) + + printtmp = Attribute("printTimestamp", + "Sets ping -D option. Prints timestamp befor each line as: " + "unix time + microseconds as in gettimeofday ", + type = Types.Bool, + default = False, + flags = Flags.Design) + + tos = Attribute("tos", + "Sets ping -Q option. Sets Quality of Service related bits in ICMP " + "datagrams. tos can be either a decimal or hexadecime number ", + flags = Flags.Design) + + quiet = Attribute("quiet", + "Sets ping -q option. Disables ping standard output ", + type = Types.Bool, + default = False, + flags = Flags.Design) + + rec_route = Attribute("recordRoute", + "Sets ping -R option. Includes the RECORD_ROUTE option in the " + "ECHO REQUEST packet and displays route buffer on the Disables " + "ping standard output.", + type = Types.Bool, + default = False, + flags = Flags.Design) + + route_bypass = Attribute("routeBypass", + "Sets ping -r option. Bypasses normal routing tables and sends " + "ECHO REQUEST packets directly yo a host on an attached interface. ", + type = Types.Bool, + default = False, + flags = Flags.Design) + + packetsize = Attribute("packetSize", + "Sets ping -s option. Specifies the number of data bytes to be " + "sent. Defaults to 56. ", + flags = Flags.Design) + + sendbuff = Attribute("sendBuff", + "Sets ping -S option. Specifies the number of packets to buffer. " + "Defaults to one. ", + flags = Flags.Design) + + ttl = Attribute("ttl", + "Sets ping -t option. Specifies the IP Time to Live for the " + "packets. ", + flags = Flags.Design) + + timestamp = Attribute("timestamp", + "Sets ping -T option. Sets special IP timestamp options. ", + flags = Flags.Design) + + hint = Attribute("hint", + "Sets ping -M option. Selects Path MTU Discovery strategy. ", + flags = Flags.Design) + + full_latency = Attribute("fullLatency", + "Sets ping -U option. Calculates round trip time taking into " + "account the full user-to-user latency instead of only the " + "network round trip time. ", + type = Types.Bool, + default = False, + flags = Flags.Design) + + verbose = Attribute("verbose", + "Sets ping -v option. Verbose output. ", + type = Types.Bool, + default = False, + flags = Flags.Design) + + flood = Attribute("flood", + "Sets ping -f option. Flood ping. ", + type = Types.Bool, + default = False, + flags = Flags.Design) + + deadline = Attribute("deadline", + "Sets ping -w option. Specify a timeout, in seconds, before ping " + "exits regardless of how many packets have been sent or received.", + flags = Flags.Design) + + timeout = Attribute("timeout", + "Sets ping -W option. Time to wait for a respone in seconds .", + flags = Flags.Design) + + target = Attribute("target", + "The host to ping .", + flags = Flags.Design) + + cls._register_attribute(count) + cls._register_attribute(mark) + cls._register_attribute(interval) + cls._register_attribute(address) + cls._register_attribute(preload) + cls._register_attribute(numeric) + cls._register_attribute(pattern) + cls._register_attribute(printtmp) + cls._register_attribute(tos) + cls._register_attribute(quiet) + cls._register_attribute(rec_route) + cls._register_attribute(route_bypass) + cls._register_attribute(packetsize) + cls._register_attribute(sendbuff) + cls._register_attribute(ttl) + cls._register_attribute(timestamp) + cls._register_attribute(hint) + cls._register_attribute(full_latency) + cls._register_attribute(verbose) + cls._register_attribute(flood) + cls._register_attribute(deadline) + cls._register_attribute(timeout) + cls._register_attribute(target) + + def _instantiate_object(self): + self.set("sources", self._sources) + self.set("build", self._build) + self.set("binary", "ping") + self.set("arguments", self._arguments) + + super(LinuxDcePing, self)._instantiate_object() + + @property + def _sources(self): + return "http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2" + + @property + def _build(self): + return ("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} && cd - ") + + @property + def _arguments(self): + args = [] + + if self.get("count"): + args.append("-c %s" % self.get("count")) + if self.get("mark"): + args.append("-m %s" % self.get("mark")) + if self.get("interval"): + args.append("-i %s" % self.get("interval")) + if self.get("address"): + args.append("-I %s" % self.get("address")) + if self.get("preload"): + args.append("-l %s" % self.get("preload")) + if self.get("numeric") == True: + args.append("-n") + if self.get("pattern"): + args.append("-p %s" % self.get("pattern")) + if self.get("tos"): + args.append("-Q %s" % self.get("tos")) + if self.get("quiet"): + args.append("-q %s" % self.get("quiet")) + if self.get("recordRoute") == True: + args.append("-R") + if self.get("routeBypass") == True: + args.append("-r") + if self.get("packetSize"): + args.append("-s %s" % self.get("packetSize")) + if self.get("sendBuff"): + args.append("-S %s" % self.get("sendBuff")) + if self.get("ttl"): + args.append("-t %s" % self.get("ttl")) + if self.get("timestamp"): + args.append("-T %s" % self.get("timestamp")) + if self.get("hint"): + args.append("-M %s" % self.get("hint")) + if self.get("fullLatency") == True: + args.append("-U") + if self.get("verbose") == True: + args.append("-v") + if self.get("flood") == True: + args.append("-f") + if self.get("deadline"): + args.append("-w %s" % self.get("deadline")) + if self.get("timeout"): + args.append("-W %s" % self.get("timeout")) + args.append(self.get("target")) + + return ";".join(args) + diff --git a/test/resources/linux/ns3/ns3pingdce.py b/test/resources/linux/ns3/ns3pingdce.py new file mode 100644 index 00000000..ffa19bb3 --- /dev/null +++ b/test/resources/linux/ns3/ns3pingdce.py @@ -0,0 +1,138 @@ +#!/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 . +# +# Author: Alina Quereilhac + + +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 + +def add_point2point_device(ec, node, address = None, prefix = None): + dev = ec.register_resource("ns3::PointToPointNetDevice") + if address: + ec.set(dev, "ip", address) + if prefix: + ec.set(dev, "prefix", prefix) + ec.register_connection(node, dev) + + queue = ec.register_resource("ns3::DropTailQueue") + ec.register_connection(dev, queue) + + return dev + +class LinuxNS3PingDceApplicationTest(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_ping(self): + ec = ExperimentController(exp_id = "test-dce-ping") + + 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) + p2p1 = add_point2point_device(ec, nsnode1, "10.0.0.1", "30") + ec.set(p2p1, "DataRate", "5Mbps") + + nsnode2 = add_ns3_node(ec, simu) + 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 + ping = ec.register_resource("ns3::LinuxDcePing") + ec.set (ping, "stackSize", 1<<20) + ec.set (ping, "target", "10.0.0.2") + ec.set (ping, "count", "10") + ec.set (ping, "packetSize", "1000") + ec.set (ping, "StartTime", "1s") + ec.set (ping, "StopTime", "20s") + ec.register_connection(ping, nsnode1) + + ec.deploy() + + ec.wait_finished([ping]) + + expected = "ping -c 10 -s 1000 10.0.0.2" + cmdline = ec.trace(ping, "cmdline") + self.assertTrue(cmdline.find(expected) > -1, cmdline) + + expected = "Start Time: NS3 Time: 1s (" + status = ec.trace(ping, "status") + self.assertTrue(status.find(expected) > -1, status) + + 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() -- 2.43.0