Trying to make LinuxNS3Simulator to deploy remotely ....
[nepi.git] / test / resources / linux / ns3 / ns3simulation.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
6 #    This program is free software: you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20
21
22 #
23 # Network topology
24 #
25 #       n0    n1   n2   n3
26 #       |     |    |    |
27 #       -----------------
28 #
29 #  node n0 sends IGMP traffic to node n3
30
31
32 from nepi.execution.ec import ExperimentController 
33
34 import os
35 import time
36 import unittest
37
38 class LinuxNS3ClientTest(unittest.TestCase):
39     def test_runtime_attr_modify(self):
40         ssh_key = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
41
42         ec = ExperimentController(exp_id = "test-ns3-simu")
43         
44         node = ec.register_resource("LinuxNode")
45         #ec.set(node, "hostname", "roseval.pl.sophia.inria.fr")
46         #ec.set(node, "username", "alina")
47         ec.set(node, "hostname", "peeramide.irisa.fr")
48         #ec.set(node, "hostname", "planetlab2.upc.es")
49         ec.set(node, "username", "inria_alina")
50         ec.set(node, "identity", ssh_key)
51         ec.set(node, "cleanProcesses", True)
52
53         simu = ec.register_resource("LinuxNS3Simulation")
54         ec.set(simu, "verbose", True)
55         ec.register_connection(simu, node)
56
57         nsnode1 = ec.register_resource("ns3::Node")
58         ec.register_connection(nsnode1, simu)
59
60         ipv41 = ec.register_resource("ns3::Ipv4L3Protocol")
61         ec.register_connection(nsnode1, ipv41)
62
63         arp1 = ec.register_resource("ns3::ArpL3Protocol")
64         ec.register_connection(nsnode1, arp1)
65         
66         icmp1 = ec.register_resource("ns3::Icmpv4L4Protocol")
67         ec.register_connection(nsnode1, icmp1)
68
69         p1 = ec.register_resource("ns3::PointToPointNetDevice")
70         ec.set(p1, "ip", "10.0.0.1")
71         ec.set(p1, "prefix", "30")
72         ec.register_connection(nsnode1, p1)
73         q1 = ec.register_resource("ns3::DropTailQueue")
74         ec.register_connection(p1, q1)
75
76         nsnode2 = ec.register_resource("ns3::Node")
77         ec.register_connection(nsnode2, simu)
78
79         ipv42 = ec.register_resource("ns3::Ipv4L3Protocol")
80         ec.register_connection(nsnode2, ipv42)
81
82         arp2 = ec.register_resource("ns3::ArpL3Protocol")
83         ec.register_connection(nsnode2, arp2)
84         
85         icmp2 = ec.register_resource("ns3::Icmpv4L4Protocol")
86         ec.register_connection(nsnode2, icmp2)
87
88         p2 = ec.register_resource("ns3::PointToPointNetDevice")
89         ec.set(p2, "ip", "10.0.0.2")
90         ec.set(p2, "prefix", "30")
91         ec.register_connection(nsnode2, p2)
92         q2 = ec.register_resource("ns3::DropTailQueue")
93         ec.register_connection(p2, q2)
94
95         # Create channel
96         chan = ec.register_resource("ns3::PointToPointChannel")
97         ec.set(chan, "Delay", "0s")
98         ec.register_connection(chan, p1)
99         ec.register_connection(chan, p2)
100
101         ### create pinger
102         ping = ec.register_resource("ns3::V4Ping")
103         ec.set (ping, "Remote", "10.0.0.2")
104         ec.set (ping, "Interval", "1s")
105         ec.set (ping, "Verbose", True)
106         ec.set (ping, "StartTime", "0s")
107         ec.set (ping, "StopTime", "20s")
108         ec.register_connection(ping, nsnode1)
109
110         ec.deploy()
111
112         #time.sleep(60)
113         ec.wait_started([ping])
114         #ec.wait_finised([ping])
115
116         ec.shutdown()
117
118 if __name__ == '__main__':
119     unittest.main()
120