Files

59 lines
1.5 KiB
Python
Raw Permalink Normal View History

#
2024-06-17 16:17:10 +02:00
# SPDX-License-Identifier: GPL-2.0-only
#
2009-02-10 17:15:06 +00:00
try:
from ns import ns
except ModuleNotFoundError:
raise SystemExit(
"Error: ns3 Python module not found;"
" Python bindings may not be enabled"
" or your PYTHONPATH might not be properly configured"
)
2009-02-10 17:15:06 +00:00
2020-02-02 17:00:30 +05:30
# // Default Network Topology
# //
# // 10.1.1.0
# // n0 -------------- n1
# // point-to-point
# //
2024-05-15 00:01:33 -03:00
ns.LogComponentEnable("UdpEchoClientApplication", ns.LOG_LEVEL_INFO)
ns.LogComponentEnable("UdpEchoServerApplication", ns.LOG_LEVEL_INFO)
2009-02-10 17:15:06 +00:00
2024-05-15 00:01:33 -03:00
nodes = ns.NodeContainer()
2009-02-10 17:15:06 +00:00
nodes.Create(2)
2024-05-15 00:01:33 -03:00
pointToPoint = ns.PointToPointHelper()
pointToPoint.SetDeviceAttribute("DataRate", ns.StringValue("5Mbps"))
pointToPoint.SetChannelAttribute("Delay", ns.StringValue("2ms"))
2009-02-10 17:15:06 +00:00
devices = pointToPoint.Install(nodes)
2024-05-15 00:01:33 -03:00
stack = ns.InternetStackHelper()
2009-02-10 17:15:06 +00:00
stack.Install(nodes)
2024-05-15 00:01:33 -03:00
address = ns.Ipv4AddressHelper()
address.SetBase(ns.Ipv4Address("10.1.1.0"), ns.Ipv4Mask("255.255.255.0"))
2009-02-10 17:15:06 +00:00
interfaces = address.Assign(devices)
2009-02-10 17:15:06 +00:00
2024-05-15 00:01:33 -03:00
echoServer = ns.UdpEchoServerHelper(9)
2009-02-10 17:15:06 +00:00
serverApps = echoServer.Install(nodes.Get(1))
serverApps.Start(ns.Seconds(1))
serverApps.Stop(ns.Seconds(10))
2009-02-10 17:15:06 +00:00
address = interfaces.GetAddress(1).ConvertTo()
2024-05-15 00:01:33 -03:00
echoClient = ns.UdpEchoClientHelper(address, 9)
echoClient.SetAttribute("MaxPackets", ns.UintegerValue(1))
echoClient.SetAttribute("Interval", ns.TimeValue(ns.Seconds(1)))
2024-05-15 00:01:33 -03:00
echoClient.SetAttribute("PacketSize", ns.UintegerValue(1024))
2009-02-10 17:15:06 +00:00
clientApps = echoClient.Install(nodes.Get(0))
clientApps.Start(ns.Seconds(2))
clientApps.Stop(ns.Seconds(10))
2009-02-10 17:15:06 +00:00
2024-05-15 00:01:33 -03:00
ns.Simulator.Run()
ns.Simulator.Destroy()