author | Tom Henderson <tomh@tomh.org> |
Mon, 28 Sep 2015 20:27:25 -0700 | |
changeset 11676 | 05ea1489e509 |
parent 11023 | f05440962bc6 |
permissions | -rw-r--r-- |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
1 |
# |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
2 |
# Copyright (c) 2008-2009 Strasbourg University |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
3 |
# |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
4 |
# This program is free software; you can redistribute it and/or modify |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
5 |
# it under the terms of the GNU General Public License version 2 as |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
6 |
# published by the Free Software Foundation; |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
7 |
# |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
8 |
# This program is distributed in the hope that it will be useful, |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
11 |
# GNU General Public License for more details. |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
12 |
# |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
13 |
# You should have received a copy of the GNU General Public License |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
14 |
# along with this program; if not, write to the Free Software |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
16 |
# |
5788
b0ffdd417829
Update e-mail address of David.
Sebastien Vincent <sebastien.vincent@turnserver.org>
parents:
5369
diff
changeset
|
17 |
# Author: David Gross <gdavid.devel@gmail.com> |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
18 |
# Sebastien Vincent <vincent@clarinet.u-strasbg.fr> |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
19 |
# |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
20 |
|
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
21 |
# |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
22 |
# Network topology: |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
23 |
# |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
24 |
# n0 r n1 |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
25 |
# | _ | |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
26 |
# ====|_|==== |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
27 |
# router |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
28 |
# |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
29 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
30 |
import ns.applications |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
31 |
import ns.core |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
32 |
import ns.csma |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
33 |
import ns.internet |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
34 |
import ns.network |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
35 |
|
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
36 |
def main(argv): |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
37 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
38 |
cmd = ns.core.CommandLine(); |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
39 |
|
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
40 |
cmd.Parse(argv); |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
41 |
|
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
42 |
# Create nodes |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
43 |
print "Create nodes" |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
44 |
n0 = ns.network.Node(); |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
45 |
r = ns.network.Node(); |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
46 |
n1 = ns.network.Node(); |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
47 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
48 |
net1 = ns.network.NodeContainer(); |
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
49 |
net1.Add(n0); |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
50 |
net1.Add(r); |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
51 |
net2 = ns.network.NodeContainer(); |
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
52 |
net2.Add(r); |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
53 |
net2.Add(n1); |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
54 |
all = ns.network.NodeContainer(); |
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
55 |
all.Add(n0); |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
56 |
all.Add(r); |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
57 |
all.Add(n1); |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
58 |
|
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
59 |
# Create IPv6 Internet Stack |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
60 |
internetv6 = ns.internet.InternetStackHelper(); |
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
61 |
internetv6.Install(all); |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
62 |
|
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
63 |
# Create channels |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
64 |
csma = ns.csma.CsmaHelper(); |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
65 |
csma.SetChannelAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000))); |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
66 |
csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.MilliSeconds(2))); |
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
67 |
d1 = csma.Install(net1); |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
68 |
d2 = csma.Install(net2); |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
69 |
|
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
70 |
# Create networks and assign IPv6 Addresses |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
71 |
print "Addressing" |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
72 |
ipv6 = ns.internet.Ipv6AddressHelper(); |
11023 | 73 |
ipv6.SetBase(ns.network.Ipv6Address("2001:1::"), ns.network.Ipv6Prefix(64)); |
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
74 |
i1 = ipv6.Assign(d1); |
11023 | 75 |
i1.SetForwarding(1, True); |
76 |
i1.SetDefaultRouteInAllNodes(1); |
|
77 |
ipv6.SetBase(ns.network.Ipv6Address("2001:2::"), ns.network.Ipv6Prefix(64)); |
|
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
78 |
i2 = ipv6.Assign(d2); |
11023 | 79 |
i2.SetForwarding(0, True); |
80 |
i2.SetDefaultRouteInAllNodes(0); |
|
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
81 |
|
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
82 |
# Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
83 |
print "Application" |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
84 |
packetSize = 1024; |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
85 |
maxPacketCount = 5; |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
86 |
interPacketInterval = ns.core.Seconds(1.); |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
87 |
ping6 = ns.applications.Ping6Helper(); |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
88 |
|
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
89 |
ping6.SetLocal(i1.GetAddress(0, 1)); |
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
90 |
ping6.SetRemote(i2.GetAddress(1, 1)); |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
91 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
92 |
ping6.SetAttribute("MaxPackets", ns.core.UintegerValue(maxPacketCount)); |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
93 |
ping6.SetAttribute("Interval", ns.core.TimeValue(interPacketInterval)); |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
94 |
ping6.SetAttribute("PacketSize", ns.core.UintegerValue(packetSize)); |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
95 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
96 |
apps = ping6.Install(ns.network.NodeContainer(net1.Get(0))); |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
97 |
apps.Start(ns.core.Seconds(2.0)); |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
98 |
apps.Stop(ns.core.Seconds(20.0)); |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
99 |
|
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
100 |
print "Tracing" |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
101 |
ascii = ns.network.AsciiTraceHelper() |
6213
3051b31392c6
Fix a couple of Python examples
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5788
diff
changeset
|
102 |
csma.EnableAsciiAll(ascii.CreateFileStream("simple-routing-ping6.tr")) |
3051b31392c6
Fix a couple of Python examples
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
5788
diff
changeset
|
103 |
csma.EnablePcapAll("simple-routing-ping6", True) |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
104 |
|
4754
77c878bc3e84
Fix Python coding style.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
4753
diff
changeset
|
105 |
# Run Simulation |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
106 |
ns.core.Simulator.Run() |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
107 |
ns.core.Simulator.Destroy() |
4753
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
108 |
|
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
109 |
if __name__ == '__main__': |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
110 |
import sys |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
111 |
main(sys.argv) |
81146e4a3993
Add IPv6 python example.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
diff
changeset
|
112 |