A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
first.py
Go to the documentation of this file.
1
#
2
# SPDX-License-Identifier: GPL-2.0-only
3
#
4
5
try
:
6
from
ns
import
ns
7
except
ModuleNotFoundError:
8
raise
SystemExit(
9
"Error: ns3 Python module not found;"
10
" Python bindings may not be enabled"
11
" or your PYTHONPATH might not be properly configured"
12
)
13
14
# // Default Network Topology
15
# //
16
# // 10.1.1.0
17
# // n0 -------------- n1
18
# // point-to-point
19
# //
20
21
ns.LogComponentEnable(
"UdpEchoClientApplication"
, ns.LOG_LEVEL_INFO)
22
ns.LogComponentEnable(
"UdpEchoServerApplication"
, ns.LOG_LEVEL_INFO)
23
24
nodes = ns.NodeContainer()
25
nodes.Create(2)
26
27
pointToPoint = ns.PointToPointHelper()
28
pointToPoint.SetDeviceAttribute(
"DataRate"
, ns.StringValue(
"5Mbps"
))
29
pointToPoint.SetChannelAttribute(
"Delay"
, ns.StringValue(
"2ms"
))
30
31
devices = pointToPoint.Install(nodes)
32
33
stack = ns.InternetStackHelper()
34
stack.Install(nodes)
35
36
address = ns.Ipv4AddressHelper()
37
address.SetBase(ns.Ipv4Address(
"10.1.1.0"
), ns.Ipv4Mask(
"255.255.255.0"
))
38
39
interfaces = address.Assign(devices)
40
41
echoServer = ns.UdpEchoServerHelper(9)
42
43
serverApps = echoServer.Install(nodes.Get(1))
44
serverApps.Start(ns.Seconds(1.0))
45
serverApps.Stop(ns.Seconds(10.0))
46
47
address = interfaces.GetAddress(1).ConvertTo()
48
echoClient = ns.UdpEchoClientHelper(address, 9)
49
echoClient.SetAttribute(
"MaxPackets"
, ns.UintegerValue(1))
50
echoClient.SetAttribute(
"Interval"
, ns.TimeValue(ns.Seconds(1.0)))
51
echoClient.SetAttribute(
"PacketSize"
, ns.UintegerValue(1024))
52
53
clientApps = echoClient.Install(nodes.Get(0))
54
clientApps.Start(ns.Seconds(2.0))
55
clientApps.Stop(ns.Seconds(10.0))
56
57
ns.Simulator.Run()
58
ns.Simulator.Destroy()
examples
tutorial
first.py
Generated on Fri Nov 8 2024 13:58:58 for ns-3 by
1.11.0