From: Alina Quereilhac Date: Tue, 25 Mar 2014 13:56:08 +0000 (+0100) Subject: Ns3 linux example X-Git-Tag: nepi-3.1.0~93 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=1e77723c376f90f713798fc03deef740b25737b4;p=nepi.git Ns3 linux example --- diff --git a/examples/linux/ns3/ping.py b/examples/linux/ns3/ping.py new file mode 100644 index 00000000..041771ec --- /dev/null +++ b/examples/linux/ns3/ping.py @@ -0,0 +1,96 @@ +#!/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 + +ec = ExperimentController(exp_id = "ns3-p2p-ping") + +# Simulation will run in the local machine +node = ec.register_resource("LinuxNode") +ec.set(node, "hostname", "localhost") + +# Add a simulation resource +simu = ec.register_resource("LinuxNS3Simulation") +ec.set(simu, "verbose", True) +ec.register_connection(simu, node) + +## Add a ns-3 node with its protocol stack +nsnode1 = ec.register_resource("ns3::Node") +ec.register_connection(nsnode1, simu) + +ipv4 = ec.register_resource("ns3::Ipv4L3Protocol") +ec.register_connection(nsnode1, ipv4) +arp = ec.register_resource("ns3::ArpL3Protocol") +ec.register_connection(nsnode1, arp) +icmp = ec.register_resource("ns3::Icmpv4L4Protocol") +ec.register_connection(nsnode1, icmp) + +# Add a point to point net device to the node +dev1 = ec.register_resource("ns3::PointToPointNetDevice") +ec.set(dev1, "ip", "10.0.0.1") +ec.set(dev1, "prefix", "30") +ec.register_connection(nsnode1, dev1) +queue1 = ec.register_resource("ns3::DropTailQueue") +ec.register_connection(dev1, queue1) + +## Add another ns-3 node with its protocol stack +nsnode2 = ec.register_resource("ns3::Node") +ec.register_connection(nsnode2, simu) + +ipv4 = ec.register_resource("ns3::Ipv4L3Protocol") +ec.register_connection(nsnode2, ipv4) +arp = ec.register_resource("ns3::ArpL3Protocol") +ec.register_connection(nsnode2, arp) +icmp = ec.register_resource("ns3::Icmpv4L4Protocol") +ec.register_connection(nsnode2, icmp) + +# Add a point to point net device to the node +dev2 = ec.register_resource("ns3::PointToPointNetDevice") +ec.set(dev2, "ip", "10.0.0.2") +ec.set(dev2, "prefix", "30") +ec.register_connection(nsnode2, dev2) +queue2 = ec.register_resource("ns3::DropTailQueue") +ec.register_connection(dev2, queue2) + +# Add a point to point channel +chan = ec.register_resource("ns3::PointToPointChannel") +ec.set(chan, "Delay", "0s") +ec.register_connection(chan, dev1) +ec.register_connection(chan, dev2) + +### create pinger +ping = ec.register_resource("ns3::V4Ping") +ec.set (ping, "Remote", "10.0.0.2") +ec.set (ping, "Interval", "1s") +ec.set (ping, "Verbose", True) +ec.set (ping, "StartTime", "0s") +ec.set (ping, "StopTime", "20s") +ec.register_connection(ping, nsnode1) + +ec.deploy() + +ec.wait_finished([ping]) + +stdout = ec.trace(simu, "stdout") + +ec.shutdown() + +print "PING OUTPUT", stdout diff --git a/examples/linux/ping.py b/examples/linux/ping.py index aa803642..6b5a249b 100644 --- a/examples/linux/ping.py +++ b/examples/linux/ping.py @@ -22,9 +22,12 @@ from nepi.execution.ec import ExperimentController ec = ExperimentController(exp_id = "ping-exp") +hostname = ## Add a string with the target hostname +username = ## Add a string with the username to SSH hostname + node = ec.register_resource("LinuxNode") -ec.set(node, "hostname", "planetlab2.cs.aueb.gr") -ec.set(node, "username", "inria_pres") +ec.set(node, "hostname", hostname) +ec.set(node, "username", username) ec.set(node, "cleanHome", True) ec.set(node, "cleanProcesses", True) @@ -38,5 +41,4 @@ ec.wait_finished(app) print ec.trace(app, "stdout") - ec.shutdown() diff --git a/examples/openvswitch/ovs_ping_exp.py b/examples/planetlab/openvswitch/ovs_ping_exp.py similarity index 100% rename from examples/openvswitch/ovs_ping_exp.py rename to examples/planetlab/openvswitch/ovs_ping_exp.py diff --git a/src/nepi/resources/linux/ns3/ns3simulation.py b/src/nepi/resources/linux/ns3/ns3simulation.py index f4a5a6b8..69cdf184 100644 --- a/src/nepi/resources/linux/ns3/ns3simulation.py +++ b/src/nepi/resources/linux/ns3/ns3simulation.py @@ -340,6 +340,11 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): def pygccxml_version(self): return "pygccxml-1.0.0" + @property + def dce_repo(self): + #return "http://code.nsnam.org/ns-3-dce" + return "http://code.nsnam.org/epmancini/ns-3-dce" + @property def _build(self): # If the user defined local sources for ns-3, we uncompress the sources @@ -398,9 +403,12 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): # Get dce source code " ( " " mkdir -p ${SRC}/dce && " - " hg clone http://code.nsnam.org/ns-3-dce ${SRC}/dce/ns-3-dce" + " hg clone %(dce_repo)s ${SRC}/dce/ns-3-dce" " ) " - ) + ) % { + 'dce_repo': self.dce_repo + } + return ( # NS3 installation diff --git a/src/nepi/resources/ns3/ns3base.py b/src/nepi/resources/ns3/ns3base.py index f38915fb..8a06e4bd 100644 --- a/src/nepi/resources/ns3/ns3base.py +++ b/src/nepi/resources/ns3/ns3base.py @@ -55,7 +55,7 @@ class NS3Base(ResourceManager): def trace(self, name, attr = TraceAttr.ALL, block = 512, offset = 0): filename = self._trace_filename.get(name) if not filename: - self.error("Can resolve trace %s. Did you enabled it?" % name) + self.error("Can not resolve trace %s. Did you enabled it?" % name) return "" return self.simulation.trace(filename, attr, block, offset) diff --git a/src/nepi/resources/ns3/ns3dceapplication.py b/src/nepi/resources/ns3/ns3dceapplication.py index 5d34e848..4fcc53be 100644 --- a/src/nepi/resources/ns3/ns3dceapplication.py +++ b/src/nepi/resources/ns3/ns3dceapplication.py @@ -59,11 +59,15 @@ class NS3BaseDceApplication(NS3BaseApplication): raise RuntimeError("DceApplication not connected to DCE enabled node") return nodes[0] + + def _instantiate_object(self): + pass def _connect_object(self): node = self.node if node.uuid not in self.connected: self._connected.add(node.uuid) + self.simulation.invoke(self.simulation.dce_application_helper_uuid, "ResetArguments") @@ -81,9 +85,16 @@ class NS3BaseDceApplication(NS3BaseApplication): apps_uuid = self.simulation.invoke(self.simulation.dce_application_helper_uuid, "InstallInNode", self.node.uuid) - #start_time = self.get("StartTime") - #time_uuid = self.simulation.create("Time", start_time) - #self.simulation.invoke(apps_uuid, "Start", time_uuid) + app_uuid = self.simulation.invoke(apps_uuid, "Get", 0) + + if self.has_changed("StartTime"): + self.simulation.ns3_set(app_uuid, "StartTime", self.get("StartTime")) + + if self.has_changed("StopTime"): + self.simulation.ns3_set(app_uuid, "StopTime", self.get("StopTime")) + + self._uuid = self.simulation.invoke(self.simulation.dce_application_helper_uuid, + "GetDCEApplication", app_uuid) def do_stop(self): if self.state == ResourceState.STARTED: @@ -97,6 +108,16 @@ class NS3BaseDceApplication(NS3BaseApplication): self.debug("---- RESCHEDULING START ----" ) self.ec.schedule(reschedule_delay, self.start) else: + self._configure_traces() super(NS3BaseApplication, self).do_start() self._start_time = self.simulation.start_time + def _configure_traces(self): + pid = self.simulation.invoke(self.uuid, "GetPid") + node_id = self.simulation.invoke(self.node.uuid, "GetId") + self._trace_filename["stdout"] = "files-%s/var/log/%s/stdout" % (node_id, pid) + self._trace_filename["stderr"] = "files-%s/var/log/%s/stderr" % (node_id, pid) + self._trace_filename["status"] = "files-%s/var/log/%s/status" % (node_id, pid) + self._trace_filename["cmdline"] = "files-%s/var/log/%s/cmdline" % (node_id, pid) + + diff --git a/test/resources/linux/ns3/ns3simulation.py b/test/resources/linux/ns3/ns3simulation.py index d5cec09b..9817ce94 100644 --- a/test/resources/linux/ns3/ns3simulation.py +++ b/test/resources/linux/ns3/ns3simulation.py @@ -146,7 +146,8 @@ class LinuxNS3ClientTest(unittest.TestCase): #self.fedora_host = "nepi2.pl.sophia.inria.fr" self.fedora_host = "planetlabpc1.upf.edu" #self.fedora_host = "peeramide.irisa.fr" - self.fedora_user = "inria_nepi" + #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): @@ -689,7 +690,7 @@ class LinuxNS3ClientTest(unittest.TestCase): """ - ec = ExperimentController(exp_id = "test-ns3-dce") + ec = ExperimentController(exp_id = "test-ns3-routing") node = ec.register_resource("LinuxNode") ec.set(node, "hostname", self.fedora_host) @@ -821,6 +822,10 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.wait_finished([udp_perf_client]) stderr = ec.trace(simu, "stderr") + print " CMDLINE", ec.trace(udp_perf, "cmdline") + print " STATUS ", ec.trace(udp_perf, "status") + print " OUT ", ec.trace(udp_perf, "stdout") + print " ERROR ", ec.trace(udp_perf, "stderr") expected = "DceApplication:StartApplication" self.assertTrue(stderr.find(expected) > -1)