From: Alina Quereilhac Date: Sun, 28 Dec 2014 15:23:36 +0000 (+0100) Subject: Adding first netns example X-Git-Tag: nepi-3.2.0~27 X-Git-Url: http://git.onelab.eu/?p=nepi.git;a=commitdiff_plain;h=d63e92a55dd47a6c8350add9bed45dce73435c46 Adding first netns example --- diff --git a/examples/netns/local_switch_ping.py b/examples/netns/local_switch_ping.py new file mode 100644 index 00000000..efec85ba --- /dev/null +++ b/examples/netns/local_switch_ping.py @@ -0,0 +1,77 @@ +#!/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 +# +# +# This example must be executed as root: +# $ sudo PYTHONPATH=$PYTHONPATH:src python examples/netns/local_switch_ping.py + +from nepi.execution.ec import ExperimentController + +ec = ExperimentController(exp_id = "netns-local-p2p-ping") + +# Simulation will executed in the local machine +node = ec.register_resource("linux::Node") +ec.set(node, "hostname", "localhost") + +# Add an emulation resource +emu = ec.register_resource("linux::netns::Emulation") +ec.set(emu, "verbose", True) +ec.register_connection(emu, node) + +# Add two emulated nodes +netnsnode1 = ec.register_resource("netns::Node") +ec.register_connection(netnsnode1, emu) + +iface1 = ec.register_resource("netns::NodeInterface") +ec.register_connection(iface1, netnsnode1) + +ip1 = ec.register_resource("netns::IPv4Address") +ec.set(ip1, "ip", "10.0.0.1") +ec.set(ip1, "prefix", "30") +ec.register_connection(ip1, iface1) + +netnsnode2 = ec.register_resource("netns::Node") +ec.register_connection(netnsnode2, emu) + +iface2 = ec.register_resource("netns::NodeInterface") +ec.register_connection(iface2, netnsnode2) + +ip2 = ec.register_resource("netns::IPv4Address") +ec.set(ip2, "ip", "10.0.0.2") +ec.set(ip2, "prefix", "30") +ec.register_connection(ip2, iface2) + +switch = ec.register_resource("netns::Switch") +ec.register_connection(iface1, switch) +ec.register_connection(iface2, switch) + +ping = ec.register_resource("netns::Application") +ec.set(ping, "command", "ping -c20 10.0.0.2") +ec.register_connection(ping, netnsnode1) + +ec.deploy() + +ec.wait_finished([ping]) + +stdout = ec.trace(ping, "stdout") + +ec.shutdown() + +print "PING OUTPUT", stdout