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# SPDX-License-Identifier: GPL-2.0-only
5#
6# Author: David Gross <gdavid.devel@gmail.com>
7# Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
8#
9
10#
11# Network topology:
12#
13# n0 r n1
14# | _ |
15# ====|_|====
16# router
17#
18
19try:
20 from ns import ns
21except ModuleNotFoundError:
22 raise SystemExit(
23 "Error: ns3 Python module not found;"
24 " Python bindings may not be enabled"
25 " or your PYTHONPATH might not be properly configured"
26 )
27
28
29def main(argv):
30 cmd = ns.CommandLine()
31
32 cmd.Parse(argv)
33
34 # Create nodes
35 print("Create nodes")
36
37 all = ns.NodeContainer(3)
38 net1 = ns.NodeContainer()
39 net1.Add(all.Get(0))
40 net1.Add(all.Get(1))
41 net2 = ns.NodeContainer()
42 net2.Add(all.Get(1))
43 net2.Add(all.Get(2))
44
45 # Create IPv6 Internet Stack
46 internetv6 = ns.InternetStackHelper()
47 internetv6.Install(all)
48
49 # Create channels
50 csma = ns.CsmaHelper()
51 csma.SetChannelAttribute("DataRate", ns.DataRateValue(ns.DataRate(5000000)))
52 csma.SetChannelAttribute("Delay", ns.TimeValue(ns.MilliSeconds(2)))
53 d1 = csma.Install(net1)
54 d2 = csma.Install(net2)
55
56 # Create networks and assign IPv6 Addresses
57 print("Addressing")
58 ipv6 = ns.Ipv6AddressHelper()
59 ipv6.SetBase(ns.Ipv6Address("2001:1::"), ns.Ipv6Prefix(64))
60 i1 = ipv6.Assign(d1)
61 i1.SetForwarding(1, True)
62 i1.SetDefaultRouteInAllNodes(1)
63 ipv6.SetBase(ns.Ipv6Address("2001:2::"), ns.Ipv6Prefix(64))
64 i2 = ipv6.Assign(d2)
65 i2.SetForwarding(0, True)
66 i2.SetDefaultRouteInAllNodes(0)
67
68 # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r
69 print("Application")
70 packetSize = 1024
71 maxPacketCount = 5
72 interPacketInterval = ns.Seconds(1.0)
73 # ping = ns.PingHelper(i2.GetAddress(1, 1).ConvertTo())
74 ping = ns.PingHelper(i2.GetAddress(1, 1).ConvertTo())
75
76 # ping6.SetLocal(i1.GetAddress(0, 1))
77 # ping6.SetRemote(i2.GetAddress(1, 1))
78
79 ping.SetAttribute("Count", ns.UintegerValue(maxPacketCount))
80 ping.SetAttribute("Interval", ns.TimeValue(interPacketInterval))
81 ping.SetAttribute("Size", ns.UintegerValue(packetSize))
82
83 apps = ping.Install(ns.NodeContainer(net1.Get(0)))
84 apps.Start(ns.Seconds(2.0))
85 apps.Stop(ns.Seconds(20.0))
86
87 print("Tracing")
88 ascii = ns.AsciiTraceHelper()
89 csma.EnableAsciiAll(ascii.CreateFileStream("simple-routing-ping6.tr"))
90 csma.EnablePcapAll("simple-routing-ping6", True)
91
92 # Run Simulation
93 ns.Simulator.Run()
94 ns.Simulator.Destroy()
95
96
97if __name__ == "__main__":
98 import sys
99
100 main(sys.argv)