A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
simple-routing-ping6.py
Go to the documentation of this file.
2# Copyright (c) 2008-2009 Strasbourg University
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License version 2 as
6# published by the Free Software Foundation;
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16#
17# Author: David Gross <gdavid.devel@gmail.com>
18# Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19#
20
21#
22# Network topology:
23#
24# n0 r n1
25# | _ |
26# ====|_|====
27# router
28#
29
30from ns import ns
31
32
33def main(argv):
34 cmd = ns.CommandLine()
35
36 cmd.Parse(argv)
37
38 # Create nodes
39 print("Create nodes")
40
41 all = ns.NodeContainer(3)
42 net1 = ns.NodeContainer()
43 net1.Add(all.Get(0))
44 net1.Add(all.Get(1))
45 net2 = ns.NodeContainer()
46 net2.Add(all.Get(1))
47 net2.Add(all.Get(2))
48
49 # Create IPv6 Internet Stack
50 internetv6 = ns.InternetStackHelper()
51 internetv6.Install(all)
52
53 # Create channels
54 csma = ns.csma.CsmaHelper()
55 csma.SetChannelAttribute("DataRate", ns.DataRateValue(ns.DataRate(5000000)))
56 csma.SetChannelAttribute("Delay", ns.TimeValue(ns.MilliSeconds(2)))
57 d1 = csma.Install(net1)
58 d2 = csma.Install(net2)
59
60 # Create networks and assign IPv6 Addresses
61 print("Addressing")
62 ipv6 = ns.Ipv6AddressHelper()
63 ipv6.SetBase(ns.Ipv6Address("2001:1::"), ns.Ipv6Prefix(64))
64 i1 = ipv6.Assign(d1)
65 i1.SetForwarding(1, True)
66 i1.SetDefaultRouteInAllNodes(1)
67 ipv6.SetBase(ns.Ipv6Address("2001:2::"), ns.Ipv6Prefix(64))
68 i2 = ipv6.Assign(d2)
69 i2.SetForwarding(0, True)
70 i2.SetDefaultRouteInAllNodes(0)
71
72 # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r
73 print("Application")
74 packetSize = 1024
75 maxPacketCount = 5
76 interPacketInterval = ns.Seconds(1.)
77 # ping = ns.PingHelper(i2.GetAddress(1, 1).ConvertTo())
78 ping = ns.PingHelper(i2.GetAddress(1, 1).ConvertTo())
79
80 # ping6.SetLocal(i1.GetAddress(0, 1))
81 # ping6.SetRemote(i2.GetAddress(1, 1))
82
83 ping.SetAttribute("Count", ns.UintegerValue(maxPacketCount))
84 ping.SetAttribute("Interval", ns.TimeValue(interPacketInterval))
85 ping.SetAttribute("Size", ns.UintegerValue(packetSize))
86
87 apps = ping.Install(ns.NodeContainer(net1.Get(0)))
88 apps.Start(ns.Seconds(2.0))
89 apps.Stop(ns.Seconds(20.0))
90
91 print("Tracing")
92 ascii = ns.AsciiTraceHelper()
93 csma.EnableAsciiAll(ascii.CreateFileStream("simple-routing-ping6.tr"))
94 csma.EnablePcapAll("simple-routing-ping6", True)
95
96 # Run Simulation
97 ns.Simulator.Run()
98 ns.Simulator.Destroy()
99
100
101if __name__ == '__main__':
102 import sys
103
104 main(sys.argv)